James A. Donald wrote: > I am contemplating getting into Python, which is used by engineers I > admire - google and Bram Cohen, but was horrified to read > > "no variable or argument declarations are necessary." > > Surely that means that if I misspell a variable name, my program will > mysteriously fail to work with no error message. > > If you don't declare variables, you can inadvertently re-use an > variable used in an enclosing context when you don't intend to, or > inadvertently reference a new variable (a typo) when you intended to > reference an existing variable. > > What can one do to swiftly detect this type of bug?
A variable has to be assigned to before it is used, otherwise a NameError exception is thrown.. >>> a + 1 Traceback (most recent call last): File "<interactive input>", line 1, in ? NameError: name 'a' is not defined >>> a = 1 >>> a + 1 2 Typos in variable names are easily discovered unless the typo happens to exist in the current context. Will McGugan -- http://www.willmcgugan.com "".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz") -- http://mail.python.org/mailman/listinfo/python-list