追加写入:

# -*- coding:utf-8 -*-

# a 指定打开文件的模式,a为追加  r为只读

a=open('test.txt', 'a')

a.write('追加写入')

a.close()

 

f=open('test.txt', 'r')

print f.read()

覆盖写入:

a=open('test.txt', 'w')