python - 艰难地学习 Python 练习 13 错误

标签 python python-2.7

每次运行此程序时,我都会收到“ValueError:需要超过 1 个变量”。但我正在按照 Zed 所说的方式运行 ex13.py first 2nd 3rd。我不需要在终端中在文件名之前输入 python,因为我的计算机可以识别 python 文件。我使用的是 Windows 7 并使用 python 2.7。任何帮助,将不胜感激。我尝试过此线程中最受欢迎的答案:ValueError: need more than 1 value to unpack ,但我仍然遇到同样的错误。任何帮助将不胜感激

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\Ian\lpthw\ex13.py”,第 3 行,位于 脚本,第一,第二,第三 = argv ValueError:需要超过 1 个值才能解压

最佳答案

这是 Winston Ewert 在评论中所说的。您必须告诉您的系统python在哪里,否则它将无法正确运行您的脚本。例如,在 Linux/Unix 中,您可以使用指向 python 可执行文件的 shebang 来实现这一点,例如 #!/usr/bin/python,或者只是运行 python your_script 等脚本。尝试从命令运行它,例如使用 python ex13.py first 2nd 3rd ,您会发现它有效。

<小时/>

当您使用 Windows 时,以下是如何在 Windows 上正确配置 Python 的方法:

3.3. Configuring Python

3.3.1. Excursus: Setting environment variables

3.3.2. Finding the Python executable

3.3.3. Finding modules

3.3.4. Executing scripts

~ Official Documentation

关于python - 艰难地学习 Python 练习 13 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24422502/

相关文章:

Python for 循环初始化函数引用

python - 如何强制 'mkproject' (virtualenvwrapper) 默认使用 python3?

python - 为多个类定义方法

python - 如何将分类数据从 numpy 数组加载到指标或嵌入列中?

python - 为什么要在 python 包的 __init__ 中使用 __all__?

python - pycrypto 适用于 python2.7 而不是 python3.6

python - 我们如何在一行中使用空格输入原始输入,然后将它们转换为整数并将它们添加到列表中?

使用 .iat 时出现 Python Pandas TypeError

python - 导入错误 : cannot import name 'rcParams' from 'matplotlib'

python - 值错误 : invalid literal for int( ) with base 10: '262,400,000'