How to refer to the function object itself in the function per se?
James Stroud
jstroud at ucla.edu
Sat Mar 11 17:36:05 EST 2006
Sullivan WxPyQtKinter wrote:
If I would like to refer to the function object in order
> to call it recursively, what shall I do then?
I think the question is too simple. You can just refer to the function
by its name. Here is an example:
py> def f(start, end):
... if start >= end:
... print 'start is end:', start
... else:
... print "start increasing to:", start
... f(start+1, end)
... print 'leaving f() where start is', start
...
py> f(1,10)
start increasing to: 1
start increasing to: 2
start increasing to: 3
start increasing to: 4
start increasing to: 5
start increasing to: 6
start increasing to: 7
start increasing to: 8
start increasing to: 9
start is end: 10
leaving f() where start is 10
leaving f() where start is 9
leaving f() where start is 8
leaving f() where start is 7
leaving f() where start is 6
leaving f() where start is 5
leaving f() where start is 4
leaving f() where start is 3
leaving f() where start is 2
leaving f() where start is 1
James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
http://www.jamesstroud.com/
More information about the Python-list
mailing list