python实现在内存中读写str和二进制数据

# 利用python在内存中读写str和二进制数据
from io import StringIO
from io import BytesIO


f = StringIO()
print(f.write('hello '))  # 6
print(f.write('world!'))  # 6
print(f.getvalue())  # hello world!

f = BytesIO()
print(f.write('中文'.encode('utf-8')))  # 6
print(f.getvalue())  # b'\xe4\xb8\xad\xe6\x96\x87'

猜你喜欢

转载自blog.csdn.net/xiao_xia_ming/article/details/81948711
今日推荐