好的,我是python的初学者,在学习python 3的练习13中,我无法通过键入代码来使代码工作,所以我复制了代码并尝试运行它,但它仍然不能工作这里是代码
from sys import argv
# read the WYSS section for how to run this
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)`错误是
Traceback (most recent call last):
File "d:\projects\first\app.py", line 114, in <module>
script, first, second, third = argv
ValueError: not enough values to unpack (expected 4, got 1)`(它在第114行,因为我从这本书中写的每个代码都在上面做了注释)
我认为我的python扩展或者其他什么东西出了问题,所以我使用了repl.it,我得到了同样的错误,那么我需要知道什么才能运行代码呢?或者像这样的粘贴盒在这里,https://pastebin.ubuntu.com/p/b9kKNbZ5hF/
发布于 2020-09-03 19:20:39
当你从命令行调用程序时,你需要传入参数,例子‘学习Python 3的艰难方式’给出了:
$ python ex13.py apple orange grapefruit其中,使用3个参数调用脚本,代码的结果输出为:
The script is called: ex13.py
Your first variable is: apple
Your second variable is: orange
Your third variable is: grapefruit事实上,如果你进一步阅读了这一章,你会看到他们讨论了你发布的确切错误以及发生错误的原因。
https://stackoverflow.com/questions/63722256
复制相似问题