python bytesio


Author: yifei / Created: May 30, 2017, 9:46 a.m. / Modified: May 30, 2017, 9:47 a.m. / Edit

basic usage

import io
f = io.StringIO()
f.write('hello')
f.getvalue()
f.read(4)

StringIO should be used for strings or unicodes, BytesIO should be used for binary data

把一个字符串作为一个内存中的文件,除了文件的read/write/readline等操作外,支持 getvalue 操作


评论区