que tienen esta clase:¿Qué causa que se llame al "método independiente __init __() con la instancia como primer argumento" de este código 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)
y estoy llamando con este script:
import timer
def hello():
print \"hello, world
t = timer.Timer(1.0, hello)
t.run()
y obtiene este error y no puedo entender por qué: unbound method __init__() must be called with instance as first argument
Eso sería 'super (Thread, self) .__ init __()' - pero súper tiene sus propios problemas también:/ –
@ THC4k: Super no tiene problemas, la herencia múltiple tiene problemas. Y si usa herencia múltiple, entonces super es mucho mejor que las llamadas directas. – nikow
super es solo una receta para el desastre, especialmente en la herencia múltiple, más especialmente si hay extensiones que necesiten recargarse. – dashesy