Class property with value and class
Diez B. Roggisch
deets at nospam.web.de
Tue Dec 19 06:34:41 EST 2006
manstey wrote:
> Hi,
>
> Is is possible to have two classes, ClassA and ClassB, and
> setattr(ClassA, 'xx',ClassB), AND to then have ClassA.xx store an
> integer value as well, which is not part of ClassB?
>
> e.g. If ClassB has two properties, name and address:
>
> ClassA.xx=10
> ClassA.xx.name = 'John'
> ClassA.xx.address = 'Sydney'.
>
> etc? I've no idea if this is possible or desirable.
It's neither of both options. If you must, you can subclass int, and have
additional properties. But then you can't do it like above, but instead
must do:
ClassA.xx = MyAddressInt(10)
Diez
More information about the Python-list
mailing list