You can define a property that accesses the original attribute for read and write access:
class Circle(Shape): def __init__(self, height, foo_args, shape='circle'): Shape.__init__(self, shape, height)
If you want this behavior to be very common, and you find that handling properties with setter and getter is too unmanageable, you can take the step above and build your own descriptor class :
class AttrMap(object): def __init__(self, name): self.name = name def __get__(self, obj, typ):
With this you can do
class Circle(Shape): diameter = AttrMap('height') def __init__(self, height, foo_args, shape='circle'): Shape.__init__(self, shape, height)
and the diameter descriptor redirects all calls to it by the specified attribute (here: height ).
glglgl
source share