newbie: declare function before definition?
Andrew Koenig
ark at research.att.com
Fri Apr 5 10:23:26 EST 2002
David> It appears to me that in Python, functions need to be defined
David> before they are called (physically in the file, I mean). This
David> means any piddly little utility functions have to be before my
David> main routine, and the reader has to wade through them before
David> getting to the main routine.
Not really.
If you call a function, it must be defined at the point the call
is executed. However, if that call is in another function, it
is not executed until you call that other function.
So, for example:
def f():
g()
def g():
print "I am in g"
There is no problem with f calling g, as long as you don't attempt
to execute f until after you have defined g.
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list