problem using using list with function
sholden at holdenweb.com
Thu Oct 11 01:01:13 CEST 2001
"adam griffin" <dokkenrox at earthlink.net> wrote in message
news:vq3x7.5769$0Z6.380412 at newsread1.prod.itd.earthlink.net...
> I think I figured out my problem. I had the function definition at the end
> of my script when I put it at the beginning it worked. is this the only
> place you can put definitions?
A function has to be defined before a call to it is executed. You can think
of the "def" statement as assigning the functional meaning to the function
name. If calls to the function appear inside other functions you will be OK,
as functions don't get executed when they are compiled.
For this, and other, reasons, the main part of a module is often coded as a
"main()" function, and the code finally executed with
if __name__ == "__main__":
at the end of the script. The other reasons include making it easy to run
tests on a module really designed to be imported, but it's a good paradigm.
More information about the Python-list