python 初级问题 ,怎么用pyhton2.7自带的IDLE输出下列代码
fromsysimportargvscript,first,second,third=argvprint"Thescriptiscalled:",scriptprint"...
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
#按住F5运行,shell里显示的是这个
>>>
Traceback (most recent call last):
File "C:\Python27\ex13.py", line 4, in <module>
script, first, second, third, = argv
ValueError: need more than 1 value to unpack
>>> 展开
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
#按住F5运行,shell里显示的是这个
>>>
Traceback (most recent call last):
File "C:\Python27\ex13.py", line 4, in <module>
script, first, second, third, = argv
ValueError: need more than 1 value to unpack
>>> 展开
5个回答
展开全部
script=raw_input("The script is called:" )
first=raw_input("Your first variable is:" )
second=raw_input( "Your second variable is:")
third=raw_input( "Your third variable is:")
first=raw_input("Your first variable is:" )
second=raw_input( "Your second variable is:")
third=raw_input( "Your third variable is:")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
显示的错误是没有输入参数, script, first, second, third, = argv
应该是分别把多个参数分别赋值给前面的四个变量,IDLE不支持命令行参数的设置
你用命令行方式下python ex13.py parm1 parm2 parm3即可。
应该是分别把多个参数分别赋值给前面的四个变量,IDLE不支持命令行参数的设置
你用命令行方式下python ex13.py parm1 parm2 parm3即可。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
sys.argv是传递给python脚本的命令行参数【字符串】列表
argv[0]为该脚本自身路径,其余为命令行参数
你交互式运行没有参数“script,first,second,thrid=argv”这句自然会报错
请在命令行下:
python your_script.py arg_1 arg_2 arg_3
有位仁兄回答过了,我粘过来了,他说的没错。
argv[0]为该脚本自身路径,其余为命令行参数
你交互式运行没有参数“script,first,second,thrid=argv”这句自然会报错
请在命令行下:
python your_script.py arg_1 arg_2 arg_3
有位仁兄回答过了,我粘过来了,他说的没错。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
script, first, second, third = argv这句话是错的,因为这句话的赋值方式是需要元组的,但是argv是一个list,所以这句话会失败,你需要使用下标操作显示的指定argv的4个元素,script, first, second, third = argv[0], argv[1], argv[2], argv[3]
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询