extending class
Andrea Crotti
andrea.crotti.0 at gmail.com
Fri Sep 23 05:12:10 EDT 2011
I wanted to add a couple of parameters to a class from a given library
(paste-script), but without changing the original code.
So I thought, I create a wrapper class which adds what I need, and then
dispatch all the calls to the super class.
My following attempt gives, however, a recursion error, but why?
class PSIVar(object):
"""Extend var implementation from the paste-script, to add the
ability of correlating variables
>>> v = var("name", "desc")
>>> v.name == 'name'
True
>>> v1 = PSIVar(v)
>>> v1.name == 'name'
True
"""
def __init__(self, first_var, other=None, fun=None):
# this is of type defined there
self.first_var = first_var
if other is not None:
self.other = other
self.fun = fun
assert callable(self.fun)
# now try to dispatch every method call to the other class
# must probably call the super class
def __getattribute__(self, attr):
return self.first_var.__getattribute__(attr)
More information about the Python-list
mailing list