Re: [Tutor] Printing the code of a function

2008-12-29 Thread Kent Johnson
On Sun, Dec 28, 2008 at 8:49 PM, 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. If the source code is av

Re: [Tutor] Printing the code of a function

2008-12-29 Thread spir
On Mon, 29 Dec 2008 09:18:43 - "Alan Gauld" wrote: > > "wormwood_3" wrote > > > I am wondering if there is a way to print out the code of a defined > > function. > > Its not reliable but I think you can use > > func.func_code.filename > func.func_code.firstlineno > > To find the first

Re: [Tutor] Printing the code of a function

2008-12-29 Thread Alan Gauld
"wormwood_3" wrote I am wondering if there is a way to print out the code of a defined function. Its not reliable but I think you can use func.func_code.filename func.func_code.firstlineno To find the first line of code in the original source file. Its up to you to figure out the last line

Re: [Tutor] Printing the code of a function

2008-12-28 Thread wormwood_3
kype - shuckins From: bob gailer To: wormwood_3 Cc: tutor@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 al

Re: [Tutor] Printing the code of a function

2008-12-28 Thread bob gailer
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 thing

Re: [Tutor] Printing the code of a function

2008-12-28 Thread Michiel Overtoom
wormwood_3 wrote: > I am wondering if there is a way to > print out the code of a defined function. When Python compiles source code, it doesn't store the source code itself; only the compiled intermediate code. With the 'dis' package you can disassemble that: def foo(): print "Show me

[Tutor] Printing the code of a function

2008-12-28 Thread wormwood_3
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. So if I have: def foo(): print "Show me the money." then I would like to do so