Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

StringIO

from io import StringIO
sio = StringIO("")
sio
<_io.StringIO at 0x7ff1ec50e940>
sio.write("hello world")
11
sio.getvalue()
'hello world'

BytesIO

  1. You can write anything into a BytesIO. For example, you can pass a BytesIO to pandas.DataFrame.to_parquet to write a pandas DataFrame to the BytesIO in the Parquet format. For more details, please refer to Pandas IO.

from io import BytesIO
bio = BytesIO()
bio
<_io.BytesIO at 0x7ff1ec5340e0>
bio.write(b"hello world")
bio
<_io.BytesIO at 0x7ff1ec5340e0>
bio.getvalue()
b'hello world'