#coding:utf8
import codecs
import io
# A file-like binary stream.
data = io.BytesIO('我是美国人。\n你是中国人。\n'.encode('utf8'))
# Get the UTF-8 StreamReader class and instantiate it on the data.
f = codecs.getreader('utf8')(data)
print(f.read(2))
f.seek(0)
for line in f:
print(line,end='')
您可以获取特定编码的StreamReader并将其传递给流。它将只返回完全解码的代码点。你知道吗
输出:
相关问题 更多 >
编程相关推荐