Ho questa classe:Cosa sta causando "metodo non associato __init __() deve essere chiamato con istanza come primo argomento" da questo codice Python?
from threading import Thread
import time
class Timer(Thread):
def __init__(self, interval, function, *args, **kwargs):
Thread.__init__()
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.start()
def run(self):
time.sleep(self.interval)
return self.function(*self.args, **self.kwargs)
e chiamo con questo script:
import timer
def hello():
print \"hello, world
t = timer.Timer(1.0, hello)
t.run()
e ottenere questo errore e io non riesco a capire perché: unbound method __init__() must be called with instance as first argument
Sarebbe 'super (Thread, self) .__ init __()' - ma super ha anche i suoi problemi:/ –
@ THC4k: Super non ha problemi, l'ereditarietà multipla ha problemi. E se usi l'ereditarietà multipla, allora super è molto meglio delle chiamate dirette. – nikow
super è solo una ricetta per il disastro, specialmente nell'ereditarietà multipla, specialmente se esistono estensioni che necessitano di essere ricaricate. – dashesy