判斷文件是否存在
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()