Python 文件读取
1.如何写入一个文件?
try:
file = open(‘test.txt’, ‘w’)
except:
raise
file.write("%s Exception during filter operation.\n")
file.close()
如果没有test.txt,就自动创建一个test.txt。
2.如何在文件结尾处写入?
try:
file = open(‘test.txt’, ‘a’)
except:
raise
file.write("%s Exception during filter operation.\n")
file.close()
如果没有test.txt,就自动创建一个test.txt。