python 3.0 文件操作基本流程

1、r

data = open('孙悟空','r',encoding = 'utf-8').read()

print(data)

#该操作为文件的读操作,

2、w

f = open('孙悟空','w',encoding = 'utf-8')

f.write('hello world')

f.write('karen')  #不换行写入两个,不覆盖  ==>hello worldkaren

#该操作为文件的写操作,覆盖原来内容重新编辑

f = open('孙悟空2','w',encoding = 'utf-8')

f.write('hello world')

扫描二维码关注公众号,回复: 95944 查看本文章

#也可创建新的文件进行写操作

3、 f = open('孙悟空','a',encoding = 'utf-8')

f.append('hello world')

#不影响原内容的情况下继续编辑

4、

impor time;time.sleep(50)   #延时缓冲区

open() 打开文件

f.fileno() 文件描述符

f.close() 关闭文件

猜你喜欢

转载自www.cnblogs.com/Karenbest/p/8976518.html