logo

txt文件读写问题:以下函数写出来的东西没有换行,且第二次运行并没有在后面追加,而是覆盖了之前的,为什么?

2018-11-15 23:35
Z
rgim

temp=[12,45,78]

i=1

while True:

if i==1:

w=open('data_base.txt','+')

te=str(temp[0])+' '+str(temp[1])+' '+str(temp[2])+'\n'

w.write('\n'+te+'\n')

w.write('\n')

w.write('\n'+te+'\n')

w.write('\n')

w.write('\n'+te+'\n')

w.write('\n')

w.close()

i=0

print('运行结束了')

ea1b8b4e-7634-46ae-8bc5-0bea86fb8f09.jpg
2018-11-16 12:03
I
网红小智智 星瞳科技

https://python3-cookbook.readthedocs.io/zh_CN/latest/c05/p01_read_write_text_data.html

at模式