用a模式(append)打开文件,
f = open('test.txt','a')
f.write('c1')
f.close()
执行的python脚本:
#!/usr/local/python
# coding=UTF-8
import os
file = open( "test.html", "r" )
fileadd = open("test.txt","r")
content = file.read()
contentadd = fileadd.read()
file.close()
fileadd.close()
pos = content.find( "" )
if pos != -1:
content = content[:pos] + contentadd + content[pos:]
file = open( "test.html", "w" )
file.write( content )
file.close()
print "OK"
f = file('a.txt','a') #open for 'a'ppending
fi.write(c1)
f.close
#打开python的IDE,可以用help(file)查看file的内容
#有r、w、a,即读、写、附加3中
open第二个参数修改为追加就可以啦
f = open('test.txt','a')