基本的python操作文件

import os,sys
spath=r"D:\Python27\test\python\bb.txt"
f=open(spath,"w") # Opens file for writing.Creates this file doesn't exist.
f.write("First line 1.\n")
f.writelines("First line 2.\n")
f.write("First line 3.")
f.close()

f=open(spath,"r") # Opens file for reading

for line in f:
    print line

f.close()