Nп/п : 63 из 100
 От   : Stefan Ram                          2:5075/128        28 сен 23 09:44:01
 К    : All                                                   28 сен 23 12:47:01
 Тема : Dynamically modifying "__setattr__"
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <setattr-20230928104008@ram.dialup.fu-berlin.de>
44e18fc5
@REPLYADDR Stefan Ram <ram@zedat.fu-berlin.de>
@REPLYTO 2:5075/128 Stefan Ram
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID:
<setattr-20230928104008@ram.dialup.fu-berlin.de>
@TZUTC: 0000
@TID: FIDOGATE-5.12-ge4e8b94
  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.` )

a = A()
a.x = 1

  transcript

  Any idea how to achieve something like this?


--- FIDOGATE 5.12-ge4e8b94
 * Origin: Stefan Ram (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



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх