The minute you think of giving up, think of the reason why you held on so long!
分类: Python/Ruby
2013-02-04 11:51:53
python读取文件内容:
1. 使用argv
# coding:utf-8 #!/usr/bin/python from sys import argv script, filename = argv txt = open(filename, 'r') print "你要查看的文件是:%r" %filename print "" print "文件内容如下:" print txt.read() txt.close()执行脚本:# python readfile_1.py /home/a.test
2. 使用raw_input
# coding:utf-8 #!/usr/bin/python prompt = "-->" print "输入你要查看的文件:" filename = raw_input(prompt) print "" print "文件内容如下:" txt = open(filename, 'r') print txt.read() txt.close()执行脚本: # python readfile_2.py