【python】对文件的读写文件

来源:互联网 发布:virtualbox装ubuntu 编辑:程序博客网 时间:2024/04/29 07:19

 hello,这我的第一篇学习博客。。大笑


对文件的读操作: 

    f  = open('./a.txt','w')

    print f.read()

   f.close()


2,try:

f = open('lujin','w')

print f.read()

finally:

if  f:

f.close()

3,

with open('./rw.txt','r') as f:
   print f.read()
   

4,写文件

#w表示文本文件,wb表示二进制文件

import   read

 import time

f=open('./b.txt','w')

f.write(" i am kaiser!")

f.close()

time.sleep(10)


try:

  f = open('./c.txt','r')

print f.read()

finally:

if f:

  f.close()


  








0 0
原创粉丝点击