Using property in classic class may not work

Neil Hodgson nhodgson at eb2.net.au
Wed Apr 16 20:21:56 EDT 2003


Bengt Richter wrote:

> I may be fooling myself here, but a quick experiment suggests being
> able to define a new class that inherits from both a classic class
> that you can't touch and a new-style one that you can give a property, e.g.:
> 
>  Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
>  Type "help", "copyright", "credits" or "license" for more information.
>  >>> class Old3rdParty:
>  ...     def oldMethod(self): print 'oldMethod was called'
>  ...
>  >>> class NewPropertyCarrier(object):
>  ...     def __init__(self, v): self.prop = v
>  ...     def _get_p(self): return self._v
>  ...     def _set_p(self, v): self._v = v
>  ...     prop = property(_get_p, _set_p)
>  ...
>  >>> class Derived(Old3rdParty, NewPropertyCarrier):
>  ...     pass
>  ...
>  >>> d = Derived(123)

    Thanks. Good idea. I implemented this but it still upsets wxPython.

    Neil





More information about the Python-list mailing list