a8215196 发表于 2018-2-27 11:55:08

新人想学自动化,刚学习简单的python遇到了问题

from sys import argv

script, first, second, third = argv

print ("The script is called:", script)
print ("Your first variable is:", first)
print ("Your second variable is:", second)
print ("Your third variable is:", third)

运行后C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe D:/python/笨方法学python/case13.py
Traceback (most recent call last):
File "D:/python/笨方法学python/case13.py", line 3, in <module>
    script, first, second, third = argv
ValueError: not enough values to unpack (expected 4, got 1)


上网百度过 说要在命令行 运行pythoncase13.py arg 1 arg2 arg 3
但是返回报错找不到文件

海海豚 发表于 2018-2-27 13:28:20

你安装的是python2,还是3?
把script, first, second, third = argv
改成script, first, second, third = argv,argv,argv,argv 试一下呢

a8215196 发表于 2018-2-27 16:46:47

海海豚 发表于 2018-2-27 13:28
你安装的是python2,还是3?
把script, first, second, third = argv
改成script, first, second, third = ...

python 3

zhu_angel 发表于 2018-2-27 16:56:13

可以参考下下面的地址哦~~~
https://www.zhihu.com/question/50655848/answer/122024168
页: [1]
查看完整版本: 新人想学自动化,刚学习简单的python遇到了问题