[Tutor] Printing the code of a function

wormwood_3 wormwood_3 at yahoo.com
Mon Dec 29 05:45:41 CET 2008


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!

 _______________________
Samuel Huckins


Homepage - http://samuelhuckins.com
Tech blog - http://dancingpenguinsoflight.com/
Photos - http://www.flickr.com/photos/samuelhuckins/
AIM - samushack | Gtalk - samushack | Skype - shuckins




________________________________
From: bob gailer <bgailer at gmail.com>
To: wormwood_3 <wormwood_3 at yahoo.com>
Cc: tutor at python.org
Sent: Sunday, December 28, 2008 9:07:12 PM
Subject: Re: [Tutor] Printing the code of a function

wormwood_3 wrote: 
Hello
all,

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. 
Python does not store the source when compiling things. So the short
answer is NO.

There are some "disassemblers" for Python but I have no experience with
them. They will not be able to reconstruct the exact source.

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.


So
if I have:

def foo():
    print "Show me the money."

then I would like to do something like:

>>> foo.show_code
def foo():
    print "Show me the money."

I checked out everything in dir(foo), but everything that looked
promising (namely foo.func_code), didn't end up being anything close.

Thanks for any help!

Cordially,
Sam

 
_______________________
Samuel Huckins


Homepage - http://samuelhuckins.com
Tech blog - http://dancingpenguinsoflight.com/
Photos - http://www.flickr.com/photos/samuelhuckins/
AIM - samushack | Gtalk - samushack | Skype - shuckins 


________________________________

_______________________________________________
Tutor maillist  -  Tutor at python.org http://mail.python.org/mailman/listinfo/tutor 


-- 
Bob Gailer
Chapel Hill NC 
919-636-4239
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081228/9814d49d/attachment-0001.htm>


More information about the Tutor mailing list