On Mon, 29 Dec 2008 09:18:43 -0000
"Alan Gauld" <alan.ga...@btinternet.com> wrote:

> 
> "wormwood_3" <wormwoo...@yahoo.com> 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 though! I guess checking
> for the next line with equivalent indentation might work.
> 
> But I'm not sure how much good it would do you... unless you
> were writing a debugger maybe?
> 
> Alan G

I would do it so by parsing source file:

* (convert indents to tabs (easier to parse))
* search for a line that start with (n indents) + "def func_name"
* record all following lines that start with (n+1 indents) or more
* stop where a line starts with (n indents) or less

denis

------
la vida e estranya
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to