# 类似文件的缓冲区
from io import StringIO
cache_file = StringIO()
print(cache_file.write('hello world'))
print(cache_file.seek(0))
print(cache_file.read())
print(cache_file.close()) # 释放缓冲区
# 类似文件的缓冲区
from io import BytesIO
bytes_file = BytesIO()
bytes_file.write(b'ni hao')
bytes_file.seek(0)
print(bytes_file.read())
bytes_file.close()