Adding method to object
manatlan at online.fr
Wed Dec 3 20:39:31 CET 2003
Sean Ross wrote:
> "marco" <marc.lentz at ctrceal.caisse-epargne.fr> wrote in message
> news:bql820$uka$1 at s1.read.news.oleane.net...
>>>>Is it possible to do the same thing for an attribut, instead of a
>>>>i'd like to wrap an newAttribute to an oldAttribute one :
>>>>i've got an instance "n" of an "xmlNode" class
>>>>i'd like to use "n.parentNode" instead of "n.parent" ...
>>># try this ...
>>>n.parentNode = n.parent
>>but ... it s not dynamic ....
>>if n.parent change .... n.parentNode will not change ... it must be
>>re-affected ... not ?
> You're right. Sorry about that. Maybe you could use a property?
> n.__class__.parentNode = property(lambda self: self.parent, ... etc ... )
> This way you can get/set/del n.parent using n.parentNode, and changes
> to n.parent will be reflect in n.parentNode.
> There's probably another way, but I can't think of it at the moment...
> Hope that's a little more helpful than the last suggestion,
perfect ! it works like a charm
thanx a lot !
More information about the Python-list