newbie class question

vida00 at gmail.com vida00 at gmail.com
Wed Nov 23 17:06:29 EST 2005


Hi,
I scouted the ng for someone w/ a similar problem and couldn't find
one, so I might be thinking about this probable non-issue in a wrong
way.

What I am trying to accomplish should be pretty self explanatory when
looking at the following:

>>> class heh(object):
...     def __init__(self):
...         self.foo='hello'
...     def change(self):
...         self.foo+=' world'
...     def show(self):
...         return self.foo
...
...     class hih(object):
...         def __init(self):
...             self.foo=heh.foo()
...         def show(self):
...             return self.foo
...
>>> x=heh()
>>> x.show()
'hello'
>>> x.change()
>>> x.show()
'hello world'
>>> y=x.hih()
>>> y.show()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 13, in show
AttributeError: 'hih' object has no attribute 'foo'

so, how do I reference heh.foo in its current state (i.e. 'hello
world', not 'hello') from hih?

Thanks,

-Josh.




More information about the Python-list mailing list