首页
学习
活动
专区
圈层
工具
发布

python 字符串IO

io.StringIO

s = io.StringIO() s.write('Hello World\n') 12 print('This is a test', file=s) 15 Get all of the data written so far s.getvalue() 'Hello World\nThis is a test\n'

Wrap a file interface around an existing string s = io.StringIO('Hello\nWorld\n') s.read(4) 'Hell' s.read() 'o\nWorld\n'

s = io.BytesIO() s.write(b'binary data') s.getvalue() b'binary data'

下一篇
举报
领券