----------------------------------------------------------------------------------
@MSGID: <knpkfiF3oulU1@mid.individual.net>
7c5ff012
@REPLY: <setattr-20230928104008@ram.dialup.fu-berlin.de>
44e18fc5
@REPLYADDR Greg Ewing
<greg.ewing@canterbury.ac.nz>
@REPLYTO 2:5075/128 Greg Ewing
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID:
<knpkfiF3oulU1@mid.individual.net>
@RFC-References:
<setattr-20230928104008@ram.dialup.fu-berlin.de>
@TZUTC: 1300
@PID: Mozilla/5.0 (Macintosh; Intel Mac OS X
10.12; rv:91.0) Gecko/20100101 Thunderbird/91.3.2
@TID: FIDOGATE-5.12-ge4e8b94
On 28/09/23 10:44 pm, Stefan Ram wrote:
> class A:
> def __init__( self ):
> self.__setattr__ = self.setattr
> def setattr( self, key, value ):
> print( `setattr called.` )
>
> Any idea how to achieve something like this?
class A:
def __init__(self):
self.x = 17
self.setattr = self.custom_setattr
def __setattr__(self, key, value):
self.setattr(key, value)
def setattr(self, key, value):
object.__setattr__(self, key, value)
def custom_setattr(self, key, value):
print(`custom_setattr:`, key, `=`, value)
a = A()
a.x = 1
print(`a.x =`, a.x)
--
Greg
--- Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
* Origin: usenet.network (2:5075/128)
SEEN-BY: 50/109 301/1 467/888 4500/1 5000/111
5001/100 5005/49 5020/715 830
SEEN-BY: 5020/848 1042 4441 12000 5030/49 1081
5054/8 5061/133 5075/128
SEEN-BY: 5080/102 5083/1 444
@PATH: 5075/128 5020/1042 4441