<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.5730.11" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial size=2><SPAN
class=227023609-18042007>Hello,</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=227023609-18042007></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=227023609-18042007>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.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=227023609-18042007>as a workaround i
tried this:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=227023609-18042007></SPAN></FONT><FONT
face=Arial size=2><SPAN class=227023609-18042007></SPAN></FONT> </DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=227023609-18042007>import dis,
cStringIO, sys</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=227023609-18042007>old_stdout =
sys.stdout</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=227023609-18042007>out =
cStringIO.StringIO()<BR>sys.stdout = out</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2><SPAN
class=227023609-18042007>dis.dis(lambda x: x)</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=227023609-18042007>sys.stdout =
old_stdout</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2><SPAN
class=227023609-18042007></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN
class=227023609-18042007></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=227023609-18042007>after that i get the
disassembled result by using out.getvalue()</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=227023609-18042007></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=227023609-18042007>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.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=227023609-18042007></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=227023609-18042007>Does anyone has
a better solution??</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=227023609-18042007></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=227023609-18042007>kind
regards</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=227023609-18042007>Jens</SPAN></FONT><FONT face=Arial size=2><SPAN
class=227023609-18042007></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=227023609-18042007></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN
class=227023609-18042007></SPAN></FONT> </DIV>
<P style="FONT-SIZE: 0.7em; TEXT-ALIGN: left" align=left>-- <BR>Jens
Göpfert - TraceTronic GmbH <BR>Heidelberger Straße 24<BR>01189 Dresden<BR><A
href="mailto:jens.goepfert@tracetronic.de">jens.goepfert@tracetronic.de</A>
<BR><A href="http://www.tracetronic.de/">www.tracetronic.de</A> <BR></P>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>