gpt4 book ai didi

python - 如何在 Spyder 中使用 argv

转载 作者:太空狗 更新时间:2023-10-29 17:35:42 26 4
gpt4 key购买 nike

我在 Spyder 中运行下面的代码。我已经将它输入到一个 py 文件中,然后简单地点击运行按钮。

当我尝试运行它时出现错误:

ValueError:需要多于 1 个值才能解包

如这里所示,您应该在运行程序之前为 argv 变量提供输入,但我不知道如何做到这一点是 spyder?

http://learnpythonthehardway.org/book/ex13.html

from sys import argv

script, first, second, third = argv

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

最佳答案

要将 argv 传递给 Spyder 中的脚本,您需要转到菜单项

运行 > 每个文件的配置

或按 Ctrl+F6 键,然后查找名为

的选项

命令行选项

在随后出现的对话框中,最后输入您要传​​递给脚本的命令行参数,在本例中可能是

一二三

关于python - 如何在 Spyder 中使用 argv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26679272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com