import os,sys
def readfile(filename):
'''Print a file to the standard output.'''
print '==================%s : %s==================' % (filename, os.path.abspath(filename))
fd = file(filename)
while True:
try:
text = fd.next()
except:
break
print text, # comma is for ignoring '\n'
# while True:
# line = fd.readline()
# if len(line) == 0:
# break
# print line, # notice comma
fd.close()
if __name__ == "__main__":
# os.chdir(os.path.expanduser("~"))
if len(sys.argv) < 2:
print 'please use command: '
sys.exit()
# for argvs in sys.argv[:]:
# print argvs
if sys.argv[1].startswith('--'):
option = sys.argv[1][2:]
if option == 'version':
print 'Version 1.0'
elif option == 'help':
print '''
Options include:
--version : Display version number
--help : Display help
python wpr.py filename : parse the file'''
else:
print 'Unknown option.'
sys.exit()
else:
for filename in sys.argv[1:]:
readfile(filename)
# print os.getcwd()
|
luther@gliethttp:~/python$ python wpr.py luther.txt
==================luther.txt : /home/luther/python/luther.txt==================
luther.gliethttp 2008年12月16日11点6分
阅读(5654) | 评论(0) | 转发(0) |