python r只读 w可写 a追加
1 可写
ff = open('aa.txt','w')
ff.write('hello,world')
ff.close()
2 追加
ff = open('aa.txt','w')
ff.write('hello,world')
ff.close()
ff = open('aa.txt','a')
for i in range(0,10):
ff.write(str(i))
ff.close()
3 读取
ff = open('aa.txt','w')
ff.write('hello,world\nooxx')
ff.close()
ff = open('aa.txt','r')
for i in ff.readlines():
print i
ff.close()
4 删除文件
import os
file = 'aa.txt'
os.remove(file)
1 可写
ff = open('aa.txt','w')
ff.write('hello,world')
ff.close()
2 追加
ff = open('aa.txt','w')
ff.write('hello,world')
ff.close()
ff = open('aa.txt','a')
for i in range(0,10):
ff.write(str(i))
ff.close()
3 读取
ff = open('aa.txt','w')
ff.write('hello,world\nooxx')
ff.close()
ff = open('aa.txt','r')
for i in ff.readlines():
print i
ff.close()
4 删除文件
import os
file = 'aa.txt'
os.remove(file)