I am running into problems with script evaluation order - specifically, the Python interpreter seems to read and execute scripts line by line. This is a problem if you are used to Perl, where the whole script is parsed first (Perl also auto-vivifies variables, but that's a different problem for a different day). Here is a test script:
#!/usr/bin/python
import sys
class test:
variable = "is this a variable" + other_argument
if sys.argv[1:]:
argument = sys.argv[1]
other_argument = sys.argv[2]
instance = test()
print instance.variable
else:
sys.exit()
I am only beginning to get my head around OO programming, so please bear
with me. In Perl, I would define all of my subs (functions or classes)
at the end of the program, because the Perl parser will read the whole
program, and then execute it. So I'm having trouble from the start
because I can't do that - the interpreter whines about undefined calls
when things are defined further down the page. In my example though - I
want to use variables from one code block in another, but whichever one
is first, something is undefined. I'm not necessarily looking for a
fix, but pointers as to technique to avoid this would be appreciated.
Thanks.
--
yours,
William
signature.asc
Description: Digital signature
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
