我的 python 3 脚本接收许多参数,数量事先未知。 我知道如何使用 argparse 或 argv[x] 单独读取它们,但如何将它们全部作为一个字符串获取?
例如与
python3 p.py first -second and more -and maybe another okay thisisthelast one
我想得到一个字符串:
first -second and more -and maybe another okay thisisthelast one
可以使用python3的sys模块。
import sys
print(*sys.argv[1:])
示例输出:
python3 test.py hello -v
hello -v