C
Charles Larry
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
I know functions can be put in separate files and imported, but I want
everything in a single file. Am I stuck with defining all the
functions first? If so, how come at compile-time Python can't look
ahead in the program and discover the existence of functions referred
to but not yet defined?
Regards,
Charles
script?
Example:
#!/usr/local/bin/python
# this code yields a NameError
print_message("hello world")
def print_message(msg):
print msg
I know functions can be put in separate files and imported, but I want
everything in a single file. Am I stuck with defining all the
functions first? If so, how come at compile-time Python can't look
ahead in the program and discover the existence of functions referred
to but not yet defined?
Regards,
Charles