Create an alias to an attribute on superclass
Sean DiZazzo
sean.dizazzo at gmail.com
Thu Feb 1 13:56:50 EST 2018
On Thursday, February 1, 2018 at 10:23:06 AM UTC-8, Sean DiZazzo wrote:
> Hi!
>
> I basically just want to create an alias to an attribute on an item's superclass. So that after I create the subclass object, I can access the alias attribute to get the value back.
>
> <pre>
> class Superclass(object):
> def __init__(self, value):
> """
> I want to pass x by reference, so that any time
> x on the subclass is updated, so is the alias here
> """
> self.alias = value
>
> class Subclass(Superclass):
> def __init__(self, x):
> self.x = x
> Superclass.__init__(self, self.x)
>
> def __repr__(self):
> return "x: %s\nalias: %s" % (self.x, self.alias)
>
>
> if __name__ == "__main__":
> foo = Subclass(1)
> print foo.alias
>
> foo.x = 6
> # Should return 6 !!!
> print foo.alias
>
> </pre>
Yep. Thats it. Thank you guys!!
More information about the Python-list
mailing list