variable declaration

Peter Otten __peter__ at web.de
Mon Jan 31 03:09:34 EST 2005


Alexander Zatvornitskiy wrote:

> epsilon=0
> S=0
> while epsilon<10:
>   S=S+epsilon
>   epselon=epsilon+1
> print S
> 
> It will print zero, and it is not easy to find such a bug!

pychecker may help you find misspelled variable names. You have to move the
code into a function, though:

$ cat epsilon.py
def loop():
    epsilon=0
    S=0
    while epsilon<10:
        S=S+epsilon
        epselon=epsilon+1
        print S

$ pychecker epsilon.py
Processing epsilon...

Warnings...

epsilon.py:6: Local variable (epselon) not used

Peter




More information about the Python-list mailing list