1

I'm trying to pass a list as an argument to a threaded function. This list can vary in it's length, but I can't figure out how to do it. Below is the code I'm using. For now, I just want to be able to get the list into the threaded function and print it on-screen.

#!/usr/bin/python
import threading
import Queue as queue


def generateRange(starting_chars=(*args)):
    print str(starting_chars)


for i in range(32,126):
    q = queue.Queue()
    theArgs = [i,32,32]
    threads = [ threading.Thread(target=generateRange,args=theArgs) ]
    # generateRange([i,32,32]) 
    for th in threads:
        th.daemon = True
        th.start()

I'm getting this error:

    File "./test.py", line 6
    def generateRange(starting_chars=(*args)):
                                      ^
SyntaxError: invalid syntax

What am I doing wrong?

2 Answers 2

1

You can change the syntax to this, otherwise args will not be defined:

def generateRange(*starting_chars):
    print str(starting_chars)
Sign up to request clarification or add additional context in comments.

Comments

1

I don't know why you specifically want the argument to be named 'starting_chars' but:

def generateRange(*starting_chars):
    print str(starting_chars)

or

def generateRange(*args):
    print str(args)

should work fine

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.