Adding method to object

marco manatlan at online.fr
Wed Dec 3 14:39:31 EST 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
> 
> method
> 
>>?
>>
>>>>i'd like to wrap an newAttribute to an oldAttribute one :
>>>>example:
>>>>i've got an instance "n" of an "xmlNode" class
>>>>i'd like to use "n.parentNode" instead of "n.parent" ...
>>>
>>>[snip]
>>>
>>># try this ...
>>>n.parentNode = n.parent
>>
>>i'll try,
>>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,
> Sean
> 
> 
> 

perfect ! it works like a charm
thanx a lot !




More information about the Python-list mailing list