lvalues and the lgb rule
Michael P. Soulier
msoulier at storm.ca
Fri Jul 6 23:27:05 CEST 2001
This has probably been dealt with, but I didn't see it in the python faq,
so I'm asking.
In Python, previously unused lvalues cause that variable to be dynamically
x = 1 # if x did not previously exist, following the LGB rule, it is
# declared dynamically here
Now, while this is great for scripting, it can cause major headaches with
large programs if you're a bad typist. It can declare new variables
accidentally, when you wanted to assign to an existing one...
myvar = 5
myver = othervar
...so here my typo of myver instead of myvar dynamically creates myver instead
of assigning othervar to myvar. It can also accidentally obscure globals.
So, while the simple answer would be, "don't do that", we all know that
accidents happen. So, I was wondering if there is a way to force declarations
of variables to catch this kind of thing. Is there, or is there anything in
the works, to assign with very large programs?
Thanks for your time,
Michael P. Soulier <msoulier at storm.ca>
"With sufficient thrust, pigs fly just fine. However, this is not necessarily a
good idea. It is hard to be sure where they are going to land, and it could be
dangerous sitting under them as they fly overhead." -- RFC 1925
More information about the Python-list