<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt">I actually didn't have a definite use case in mind, it was pure curiosity that arose while writing a few simple test functions. After having considered it more, I can't come up with a case where it would really be necessary, so I apologize for that. It makes sense why it wouldn't be possible without a disassembler now. Thanks for the info!<br><div>&nbsp;</div>_______________________<br>Samuel Huckins<br><br><div>Homepage - http://samuelhuckins.com<br>Tech blog - http://dancingpenguinsoflight.com/<br>Photos - http://www.flickr.com/photos/samuelhuckins/<br>AIM - samushack | Gtalk - samushack | Skype - shuckins<div><br></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font
 size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> bob gailer &lt;bgailer@gmail.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> wormwood_3 &lt;wormwood_3@yahoo.com&gt;<br><b><span style="font-weight: bold;">Cc:</span></b> tutor@python.org<br><b><span style="font-weight: bold;">Sent:</span></b> Sunday, December 28, 2008 9:07:12 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [Tutor] Printing the code of a function<br></font><br>



  

wormwood_3 wrote:
<blockquote type="cite">
  
  <div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">Hello
all,<br>
  <br>
This might be trivially easy, but I was having a hard time searching on
it since all the component terms are overloaded:-) I am wondering if
there is a way to print out the code of a defined function. </div>
</blockquote>
<br>
Python does not store the source when compiling things. So the short
answer is NO.<br>
<br>
There are some "disassemblers" for Python but I have no experience with
them. They will not be able to reconstruct the exact source.<br>
<br>
But ... why do you want to do this? Perhaps if we had more information
about the "use case" we could steer you to a solution.<br>
<br>
<blockquote type="cite">
  <div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">So
if I have:<br>
  <br>
def foo():<br>
&nbsp;&nbsp;&nbsp; print "Show me the money."<br>
  <br>
then I would like to do something like:<br>
  <br>
&gt;&gt;&gt; foo.show_code<br>
def foo():<br>
&nbsp;&nbsp;&nbsp; print "Show me the money."<br>
  <br>
I checked out everything in dir(foo), but everything that looked
promising (namely foo.func_code), didn't end up being anything close.<br>
  <br>
Thanks for any help!<br>
  <br>
Cordially,<br>
Sam<br>
  <div>&nbsp;</div>
_______________________<br>
Samuel Huckins<br>
  <br>
  <div>Homepage - <a rel="nofollow" class="moz-txt-link-freetext" target="_blank" href="http://samuelhuckins.com">http://samuelhuckins.com</a><br>
Tech blog - <a rel="nofollow" class="moz-txt-link-freetext" target="_blank" href="http://dancingpenguinsoflight.com/">http://dancingpenguinsoflight.com/</a><br>
Photos - <a rel="nofollow" class="moz-txt-link-freetext" target="_blank" href="http://www.flickr.com/photos/samuelhuckins/">http://www.flickr.com/photos/samuelhuckins/</a><br>
AIM - samushack | Gtalk - samushack | Skype - shuckins
  <div><br>
  </div>
  </div>
  </div>
  <pre><hr size="4" width="90%">
_______________________________________________
Tutor maillist  -  <a rel="nofollow" class="moz-txt-link-abbreviated" ymailto="mailto:Tutor@python.org" target="_blank" href="mailto:Tutor@python.org">Tutor@python.org</a>
<a rel="nofollow" class="moz-txt-link-freetext" target="_blank" href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a>
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature">-- <br>Bob Gailer<br>Chapel Hill NC <br>919-636-4239</pre>
</div></div></div></div></body></html>