Message391000
The example for StringIO currently manually closes the object rather than using a context manager. Since this is likely the first code that a new user encounters and context managers reduce error-prone situations, I think it would be helpful to show usage as a context manager.
https://docs.python.org/3/library/io.html#io.StringIO.getvalue
Something like:
import io
with io.StringIO() as output:
output.write('First line.\n')
print('Second line.', file=output)
# Retrieve file contents -- this will be
# 'First line.\nSecond line.\n'
contents = output.getvalue()
# Context manager will automatically close
# object and discard memory buffer --
# .getvalue() will now raise an exception. |
|
Date |
User |
Action |
Args |
2021-04-13 20:02:35 | John Hagen | set | recipients:
+ John Hagen, docs@python |
2021-04-13 20:02:35 | John Hagen | set | messageid: <1618344155.0.0.639710984937.issue43834@roundup.psfhosted.org> |
2021-04-13 20:02:34 | John Hagen | link | issue43834 messages |
2021-04-13 20:02:34 | John Hagen | create | |
|