Calling functions before that are def'ed
Daniel Dittmar
daniel at dittmar.net
Mon Sep 22 17:46:36 EDT 2003
Charles Larry wrote:
> Is there a way to define functions after the main part of a Python
> script?
>
> Example:
>
> #!/usr/local/bin/python
>
> # this code yields a NameError
>
> print_message("hello world")
>
> def print_message(msg):
> print msg
#!/usr/local/bin/python
def main ():
print_message("hello world")
def print_message(msg):
print msg
if __name__ == "__main__":
main ()
def statements are really executable statements and not declarations, so
the order is important.
Daniel
More information about the Python-list
mailing list