Riferendosi alla first answer sui metodi legati e non legati di pitone qui, ho una domanda:override un metodo statico in python
class Test:
def method_one(self):
print "Called method_one"
@staticmethod
def method_two():
print "Called method_two"
@staticmethod
def method_three():
Test.method_two()
class T2(Test):
@staticmethod
def method_two():
print "T2"
a_test = Test()
a_test.method_one()
a_test.method_two()
a_test.method_three()
b_test = T2()
b_test.method_three()
produce uscita:
Called method_one
Called method_two
Called method_two
Called method_two
C'è un modo per scavalcare un metodo statico in python?
Mi aspettavo che b_test.method_three()
stampi "T2", ma non lo fa (stampa invece "Called method_two").
Grazie mille! Questo è quello che volevo. – Emma
Davvero utile. Nel mio caso, avevo bisogno di accedere alla classe di un'istanza. L'ho fatto in questo modo: 'instance .__ class __. My_method()' – Caumons