python中argv变量的问题
此为转发和一些解决方案
**
1
**
在练习python语言中遇到的一些问题:
程序1:from sys import argv
first = argv
print “You want to search with tabel:”, first
打印1:命令行输入:python test2.py first
You want to search with tabel:[‘test2.py’, ‘first’ ]
程序2: from sys import argv
script, first = argv
print “You want to search with tabel:”, first
打印3:命令行输入:python test2.py first
You want to search with tabel: first
我只想打印出You want to search with tabel: first(即打印2),为什么程序1不能实现我想要的功能?为什么一定要将script赋值于argv?请详细说明一下。
谢谢。关于“注意这种用法当且仅当argv的长度为2时才成立,如果多加一个命令行参数就会出错。”这句话还是不太理解。
我写了一个程序如下:
程序3:
from sys import argv
script, first, second, third = argv
print “You want to search with tabel:”, first
pri