Invalid syntax near *args in Python 2.7

时间:2015-10-29 15:50:58

标签: python python-2.7 args

I keep getting invalid syntax at *args.

Here's a snippet of the code:

cmd, *args = sys.argv[1:]
globals()[cmd](*args)

I'm trying to pass multiple arguments to the functions in code.

1 个答案:

答案 0 :(得分:3)

You're trying to use Extended Iterable Unpacking, which is available starting from Python 3.

You'd replace it with

cmd = sys.argv[1]
args = sys.argv[2:]
globals()[cmd](*args)

to make it work in Python 2.