我正在阅读如何学习Python的艰难之路,它使用2.最近发现的使用Python的Invent,它使用3.
我可以下载python 3,并在阅读Invent With Python时使用它,然后当我想阅读如何学习Python的艰难之路时切换回python 2.如果是这样,我如何选择使用哪个版本?
免责声明:我已阅读位于Python错误的线程:"ValueError:需要超过1个值才能解压缩",并且没有一个答案解释了如何实际运行代码.
我正在阅读艰难的学习Python,我正在练习13.
以下是我试图在IDLE中运行的代码(不知道它实际上是什么),用于Python 2.7:
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
Run Code Online (Sandbox Code Playgroud)
运行时,我收到错误:
"Traceback(最近一次调用最后一次):文件"C:\ Python\LPTHW\examples_LPTHW\ex13.py",第3行,在脚本中,第一,第二,第三= argv ValueError:需要多于1个值来解包"
我试过通过Windows命令提示符运行该程序,但无济于事.我也通过在IDLE和命令提示符下键入:"python ex13.py first 2nd 3rd"运行程序,也得到了同样的错误.
如何运行此代码,以及我做错了什么?
编辑:@John Machin,我制作的程序与您发布的程序完全一样,保存为.py,然后进入保存文件的正确目录,使用"python yourcode.py BC D"运行程序收到以下消息"python未被识别为内部或外部命令..."当我通过键入它的名称(除了这个之外的所有其他程序都可以运行)运行程序时,我收到错误消息"SyntaxError:invalid syntax第2行:print len(argv),repr(argv)".
编辑2(使用新代码):@ John Machin,我将你的程序逐字复制到gedit并像往常一样制作.py文件.我打开了终端(命令提示符)并键入:
python ex13c.py B C D
Run Code Online (Sandbox Code Playgroud)
并收到:
'python' is not recognized as an internal or external command, operable …Run Code Online (Sandbox Code Playgroud)