Can't refer to base class attribute?



I've got a Base class with an attribute "foo" (of type Foo), and a
Derived class (derived from Base). In Derived's constructor, I try to
refer to Base.foo, but python complains:
AttributeError: class Base has no attribute 'foo'

Any ideas? (code below)

=== CODE ===
#!/usr/bin/python

class Foo:
def __init__ (self):
self.x = 3

class Base:
def __init__ (self):
self.foo = Foo()

class Derived(Base):
def __init__(self):
Base.__init__(self)
Base.foo.x = 5

Derived()
=== EOF ===

.



Relevant Pages

  • Re: Overriding newbie question.
    ... public virtual int MyMethod ... class Bar: Foo ... The other fundemental thing is this will only work if the method is being called on a derived class object. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: derived class can not access base class protected member?
    ... I am not invoking foo in derived class, the error occurs when I invoke ... void goo() ... Because foois defined as PRIVATE in the base class ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Function Returning a local object???
    ... >>are themselves class objects or worse still objectsof a derived class, ... >>when foo returns such a class by value. ... the compiler will emit code similar to: ... >>(I've read enough to know that the copy constructor is only invloved ...
    (comp.lang.cpp)
  • Re: [CLOS] Ensuring a method exists
    ... (defgeneric foo (a b) ... (defclass base () ... I'd like to ensure that if somebody writes a derived class: ... to define the foo method? ...
    (comp.lang.lisp)
  • Re: Function Returning a local object???
    ... because I can imagine the return value of foo() ... > derived class class whose member variables are themselves class ... > objects or worse still objectsof a derived class, ... the constructor, destructor and copy constructor if you don't defined ...
    (comp.lang.cpp)