[Python-au] output of dis.dis(lambda x: x)
Pete Ryland
pdr at pdr.cx
Thu Apr 19 10:42:12 UTC 2007
On 19/04/07, Andrew McNamara <andrewm at object-craft.com.au> wrote:
> Not really - I'd just suggest wrapping it in a function and using a
> try/finally block like this:
>
> def dis_str(code):
> out = cStringIO.StringIO()
> old_stdout = sys.stdout
> try:
> sys.stdout = out
> dis.dis(code)
> finally:
> sys.stdout = old_stdout
> return out.getvalue()
Perhaps worth doing:
def dis_str(*args, **kargs):
...
dis.dis(*args, **kargs)
...
Pete
More information about the python-au
mailing list