newbie: declare function before definition?

Emile van Sebille emile at fenx.com
Fri Apr 5 10:02:13 EST 2002


David Kramer
> 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?

How about:

#!/usr/remote/bin/python

def MyFuncBefore ():
    print "In Before"

def main():
    print "Before"
    MyFuncBefore()
    print "After"
    MyFuncAfter()

def MyFuncAfter ():
    print "In After"

if __name__ == '__main__':
    main()

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list