Sujet : Dynamically modifying "__setattr__" De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram) Groupes :comp.lang.python Date : 28. Sep 2023, 10:44:01 Autres entêtes Organisation : Stefan Ram Message-ID :<setattr-20230928104008@ram.dialup.fu-berlin.de>
I wanted to postpone the introduction of a custom __setattr__ to a point later at runtime where I then wanted to use "self.__setattr__ = self.setattr" to set this attribute. But this did not have the effect desired to print "setattr called" as can be seen below.
main.py
class A: def __init__( self ): self.__setattr__ = self.setattr def setattr( self, key, value ): print( 'setattr called.' )