from sys import argv
script,filename = argv
print 'start to open file specified:'
content = open(filename)
print 'start to read file specified:'
print content.read()
content.close()
print 'input new filename :'
filename_new = raw_input(">>>>")
content_new = open(filename_new)
print content_new.read()
content_new.close()
上面的文件名称为:readFile.py
结果如下:
read.txt内容如下:
this is an example of python reading files.
please check your input.
believe in yourself.
you can do it.
是的,我能行!