Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
from sys import argv script, first, second, third = argv
输入第二行后,我收到此错误:
Traceback(最近一次调用最后一次):文件“”,第 1 行,在 ValueError 中:需要超过 1 个值才能解压
sys.argv是脚本的命令行参数。您的错误表明您尝试解压缩的变量数超过元组中的条目数,即 1。
sys.argv
您要么没有传递足够的参数,要么正在从解释器运行命令。
from sys import argv a, b, c, d = argv print "The script is called:", a print "Your first variable is:", b print "Your second variable is:", c print "Your third variable is:", d
将此代码另存为:s.py
从终端运行此文件,如下所示: