判断文件是否存在
import os
filename = '~/lcj/test.txt'
if os.path.exists(filename):
message = 'OK, the "%s" file exists.'
else:
message = "Sorry, I cannot find the "%s" file."
print message % filename
读取文件指定行内容
filename = '~/lcj/test.txt'
row_num = 10
content = linecache.getline(filename,row_num)
一次性读取所有的内容放在一个大字符串中
all_the_text=open('test.txt').read()