Answers for "python string io"

0

python import stringIO

try:
    from StringIO import StringIO ## for Python 2
except ImportError:
    from io import StringIO ## for Python 3
Posted by: Guest on August-23-2020
1

python 3 stringio usage

import io

output = io.StringIO()
output.write('First line.n')
print('Second line.', file=output)

# Retrieve file contents -- this will be
# 'First line.nSecond line.n'
contents = output.getvalue()

# Close object and discard memory buffer --
# .getvalue() will now raise an exception.
output.close()
Posted by: Guest on September-23-2020

Python Answers by Framework

Browse Popular Code Answers by Language