Python Gotcha's?

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Thu Apr 5 13:13:54 EDT 2012


Miki Tebeka <miki.tebeka at gmail.com> writes:

[...]
> (Note that I want over http://wiki.python.org/moin/PythonWarts already).

The "local variable and scoping" is, imho, something to be really
careful about. Here is an example:

class A(object):
    def __init__(self):
        self.x = 0
    def r(self):
        return x # forgot self

a = A()
x = 1
print a.r() # prints 1

I know there is "no remedy". It's just really tricky.

-- Alain.



More information about the Python-list mailing list