newbie: declare function before definition?
David Kramer
david at thekramers.net
Fri Apr 5 09:57:24 EST 2002
Disclaimer: 16 years programming experience, 1 week experience with
Python.
It appears to me that in Python, functions need to be defined before they
are called (physically in the file, I mean). This means any piddly little
utility functions have to be before my main routine, and the reader has to
wade through them before getting to the main routine.
In some other languages, one can declare a function, and define it later,
and the compiler is happy. Is there a way to do this in Python?
Here is an example of what I'm talking about:
[dkramer at fbsddev02 devel]$ cat deftest1
#!/usr/remote/bin/python
def MyFuncBefore ():
print "In Before"
print "Before"
MyFuncBefore()
print "After"
MyFuncAfter()
def MyFuncAfter ():
print "In After"
[dkramer at fbsddev02 devel]$ deftest1
Before
In Before
After
Traceback (most recent call last):
File "./deftest1", line 9, in ?
MyFuncAfter()
NameError: name 'MyFuncAfter' is not defined
-------------------------------------------------------------------
DDDD David Kramer http://thekramers.net
DK KD
DKK D As a SysAdmin, yes, I CAN read your e-mail,
DK KD but I DON'T get that bored!
DDDD
More information about the Python-list
mailing list