◐ Shell
clean mode source ↗

Message 199372 - Python tracker

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)