import sys
def readfile(filename):
f = file(filename)
while True:
line = f.readline()
if len(line) == 0:
break
print line
f.close
#print "sys.argv[0]------",sys.argv[0]
#print "sys.argv[1]------",sys.argv[1]
#print "sys.argv[2]------",sys.argv[2]
if len(sys.argv) < 2:
print "no action specified"
sys.exit()
if sys.argv[1].startswith('--'):
option = sys.argv[1][2:]
if option == 'version':
print "Version 1.2"
elif option == 'help':
print '''--version\n--help'''
else:
print "unknow option"
sys.exit()
else:
for filename in sys.argv[1:]:
readfile(filename)
11-13行原文未注释,事实上若传递参数不足2个,则会报超出列表池错误(很明显因为只获取到了argv[0])