Classes and threading
Adam W.
awasilenko at gmail.com
Tue May 18 23:39:20 EDT 2010
I thought I knew how classes worked, but this code sample is making my
second guess myself:
import threading
class nThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self,args):
print self.name
print self.args
pants = nThread(args=('fruit'),name='charlie')
pants.start()
Traceback (most recent call last):
File "C:\Users\Adam\Desktop\PyTiVo\task_master.py", line 13, in
<module>
pants = nThread(args=('fruit'),name='charlie')
TypeError: __init__() got an unexpected keyword argument 'args'
Shouldn't __init__ still handle these (as per
http://docs.python.org/library/threading.html#thread-objects ), even
if its subclassed? I thought this was the whole idea of inheritance
and overdriving.
And sort of related, why does this crash IDLE GUI but not the command
line?:
import threading
class nThread(threading.Thread):
def run(self):
print 2+2
pants = nThread()
pants.start()
More information about the Python-list
mailing list