How do I make a constant global variable in Python Please
Remco Gerlich
scarblac-spamtrap at pino.selwerd.nl
Mon Apr 17 12:37:20 EDT 2000
Jeff Massung wrote in comp.lang.python:
> Along the same lines... is there a way to say a variable must be declared
> before use? I know Perl has something like this. I just want to avoid
> something like this following:
No, simply because there is no way to declare a variable.
> ate = 1
> while ate:
> # do something here
> ...
> are = 1
>
> This will loop infinitely just because of a typo (that if the above were
> added I would get an error saying that "are" wasn't declared).
It's happened a few times to me, but you notice that sort of error almost
immediately, in my experience.
Note that it would loop too if it said "ate = 1" as you seemed to intend -
you need to test to find errors anyway...
Also, this problem only occurs with assignment. If you try to use a new
variable in an expression, an exception will be raised, because the variable
can't be found.
ate = 1
x = are
gives an exception.
Python has no declarations, and nothing is a 'constant' as in other languages.
--
Remco Gerlich, scarblac at pino.selwerd.nl
This is no way to be
Man ought to be free -- Ted Bundy
That man should be me
More information about the Python-list
mailing list