首先是字节串转字符串,也就是str:
b = b'some byte array'
str(b, encoding = "utf-8")
#or
bytes.decode(b)
然后是字符串转为字节串:
s = 'some string'
bytes(s, encoding = "utf8")
#or
str.encode(s)
fastq.gz文件读取
with gzip.open(fq,'r') as fastq:
try:
while True:
line1 = next(fastq).decode() # 字节转字符串
line2 = next(fastq).decode()
line3 = next(fastq).decode()
line4 = next(fastq).decode()
except:
pass