import sys
try:
def readfile(filename):
f = open(filename)
for line in f:
print line,
print ' Completed reading %s ' % f.name
except IOError,e:
print e
except Exception,e:
print e
#此处也可以添加else,finally语句块。形成try....except.....else......finally
def helpinfo():
print '''
This is help information
'''
if __name__ == '__main__':
if len(sys.argv)<2:
print 'No action specified'
sys.exit()
for filename in sys.argv[1:]:
print '-'*20+'Split Line'+'-'*20
if filename.startswith('--'):
option = filename[2:]
if option=='help':
helpinfo()
elif option =='version':
print 'version 1.0'
else:
print 'Unknown option.'
sys.exit()
else:
readfile(filename)
版权声明:本文为博主原创文章,未经博主允许不得转载。