How to do this?
Dan Sommers
me at privacy.net
Sat Jul 30 11:38:21 EDT 2005
On Fri, 29 Jul 2005 22:34:23 +0800,
"flyaflya" <flyaflyaa at gmail.com> wrote:
> the codes as follow:
> class Base:
> def fun(self):
> print "base_fun"
> def fun2(self):
> print "base_fun2"
> class Foo:
> def __init__(self, base):
> self.__base = base
> def fun3(self):
> print "foo_fun3"
> b = Base()
> foo = Foo(b)
> my aim is:when "foo.fun3()" be called,it run as usually, but when
> "foo.fun()" or "foo.fun2() be called, as Foo hasn't attribute "fun()" and
> "fun2()", foo will call "self.__base.fun()" or "self.__base.fun2()".
> when a attr can't be find in foo, it's will try to search 'self.__base". I
> think this maybe need to use "__getattr__" and "__setattr__" ,but I cant do
> it successfully. can someone help me?
class Foo(Base):
def fun3(self):
print "fun_foo3"
HTH,
Dan
--
Dan Sommers
<http://www.tombstonezero.net/dan/>
More information about the Python-list
mailing list