首页 > 代码库 > asdasf

asdasf

import sys


def readfile(filename):

f=file(filename)

#file方法类似open,打开一个文件

while True:

line=f.readline()

if len(line) == 0:

break

#?

print line,

f.close()


print sys.argv

#?


if len(sys.argv) < 2:

print ‘No action specified.‘

sys.exit()

if sys.argv[1].startswith(‘--‘):

#判断字符串是否以指定字符或子字符串开头

#判断命令行参数是否是以--开始的,如果是则是相关命令的参数,如果不是就是文件名了


option=sys.argv[1][2:]

#这是一个二维数组,把argv[1]这个参数的下标为[2]即第三个字符开始直到结束的字符串

#fetch sys.argv[1] but without the first two characters 

if option==‘version‘:

print ‘Version 1.2‘

elif option==‘help‘:

print ‘‘‘/

this program prints files to the standard output.

Any number of files can be specified.

Options include:

--version : Print the version number

--help  : Display this help ‘‘‘

else:

print ‘Unknow option.‘

sys.exit()

else:

for filename in sys.argv[1:]:

#?

readfile(filename)


asdasf