newb __init__ inheritance
clp2 at rebertia.com
Sun Mar 11 11:38:27 CET 2012
On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie <hyperboogie at gmail.com> wrote:
> thank you everyone...
> Still things are not working as expected... what am I doing wrong?
> # cat test.py
> class A():
You should be subclassing `object`, but that's a minor point which
isn't the cause of your problem.
> def __init__(self):
This creates a *local variable* named "z". You want an *attribute*
named "z", so you should be doing:
self.z = 1
instead. Same problem elsewhere; you must *always* explicitly use
`self` when referencing an attribute of the current object. Python !=
Java or C++.
More information about the Python-list