0

Pretty simple code:

import threading

def test(word):
    print(word)

threading.Thread(target = test, args = "hello").start()

I get the following error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\phil\AppData\Local\Programs\Python\Python39\lib\threading.py", line 950, in _bootstrap_inner
    self.run()
  File "C:\Users\phil\AppData\Local\Programs\Python\Python39\lib\threading.py", line 888, in run
    self._target(*self._args, **self._kwargs)
TypeError: test() takes 1 positional argument but 4 were given

The 4 given arguments are the number of letters in the word "hello". This is what I don't understand, since the word "hello" is only one argument. If i replace "hello" with "A", it works, because "A" is only one letter.

2
  • Hmm, very odd, I thought that "hello" had 5 letters in it. Never mind. Did you mean: args = ("hello",)? Commented Jun 27, 2021 at 14:31
  • This works, thank you! Indeed the word "hello" has 5 letters, I wrote the code with "test" instead, which has 4 letters, but replaced it with "hello" to not confuse you, because "test" is also the name of the function. Commented Jun 27, 2021 at 14:34

1 Answer 1

1
import threading

def test(word):
    print(word)

threading.Thread(target=test, args=("hello",)).start()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.