[issue15805] Add stdout redirection tool to contextlib
Vajrasky Kok
report at bugs.python.org
Thu Oct 10 10:44:00 CEST 2013
Vajrasky Kok added the comment:
Nice.
My only complain is the dis.dis example. We don't have to use redirect_stdout context manager.
+ # How to capture disassembly to a string
+
+ import dis
+ import io
+
+ f = io.StringIO()
+ with redirect_stdout(f):
+ dis.dis('x**2 - y**2')
+ s = f.getvalue()
dis.dis supports file object natively. We can do this instead:
dis.dis('x**2 - y**2', file=f)
----------
nosy: +vajrasky
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15805>
_______________________________________
More information about the Python-bugs-list
mailing list