[Python-au] output of dis.dis(lambda x: x)

Jens Göpfert jens.goepfert at tracetronic.de
Wed Apr 18 09:54:55 UTC 2007


Hello,
 
for disassembling some python code i use the dis-function of the dis-module. i need the result as a python string, but the dis-function only sends the output to stdout.
as a workaround i tried this:
 
import dis, cStringIO, sys
 
old_stdout = sys.stdout
 
out = cStringIO.StringIO()
sys.stdout = out
 
dis.dis(lambda x: x)
 
sys.stdout = old_stdout
 
 
after that i get the disassembled result by using out.getvalue()
 
until now it works for me, but its not a nice way, because i already redirect the sys.stdout in my application to a log-window, thats why i have to save the previously value of sys.stdout in old_stdout.
 
Does anyone has a better solution??
 
kind regards
Jens
 
 

--  
Jens Göpfert - TraceTronic GmbH 
Heidelberger Straße 24
01189 Dresden
jens.goepfert at tracetronic.de 
www.tracetronic.de <http://www.tracetronic.de/>  


 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://starship.python.net/pipermail/python-au/attachments/20070418/40dfee70/attachment.htm 


More information about the python-au mailing list