Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 488 Bytes

21.IO模块.md

File metadata and controls

32 lines (21 loc) · 488 Bytes

IO模块

1.StringIO

# 类似文件的缓冲区
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())  # 释放缓冲区

2.BytesIO

# 类似文件的缓冲区
from io import BytesIO

bytes_file = BytesIO()
bytes_file.write(b'ni hao')
bytes_file.seek(0)
print(bytes_file.read())
bytes_file.close()