Python 文件操作

基本的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()
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章