threading problem
Steven Bethard
steven.bethard at gmail.com
Thu Dec 9 19:12:16 EST 2004
Egor Bolonev wrote:
> hi all
>
> my program terminates with error i dont know why it tells 'TypeError:
> run() takes exactly 1 argument (10 given)'
[snip]
> threading.Thread(target = run, args = (os.path.join('c:\\',
> path))).start()
I believe the args argument to threading.Thread is supposed to be a
sequence.
>>> import os
>>> path = 'directory'
>>> os.path.join('c:\\', path)
'c:\\directory'
>>> (os.path.join('c:\\', path))
'c:\\directory'
>>> (os.path.join('c:\\', path),)
('c:\\directory',)
I think if you change the call to look like:
threading.Thread(target=run, args=(os.path.join('c:\\', path),)).start()
or
threading.Thread(target=run, args=[os.path.join('c:\\', path)]).start()
then you should be okay. You're probably getting the 10 argument
message because your string is 10 characters long and threading.Thread
is treating each character in your string as an argument:
>>> def f(arg):
... print arg
...
>>> def g(func, args):
... func(*args)
...
>>> g(f, 'abcdefghij')
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 2, in g
TypeError: f() takes exactly 1 argument (10 given)
Steve
More information about the Python-list
mailing list