logo

写入txt问题:txt文件,里面写了456,运行下面代码,可以读出456,但是写入不了东西.请问该怎么办?

2018-11-15 18:05
Z
rgim
c=open('2.txt','+')
i=0
while(True):
    if i==0:
        c=open('2.txt','+')
        a=c.read()
        print(a)
        c.write('123')
        c.close() 
        print('程序运行了')
        i=1
5cc94258-7c18-4851-9583-5b31d340e7ce.jpg
2018-11-15 18:17
I
网红小智智 星瞳科技

要重新插拔OpenMV,或者是重启OpenMV。

电脑上,U盘里的文件才会显示出来。

2018-11-15 23:02
Z
rgim

@kidswong999 谢谢上面的回答,现在能写进去了,但是我调用一下函数,写进去的东西并不能换行,请问是什么原因呢

I
网红小智智 星瞳科技

新的问题,单独发帖

Z
rgim

@kidswong999

def write():

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

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

w.write(te)

w.write('\n')

print(te)

print('\n')

w.close()

2019-06-19 12:18
B
ziet

@kidswong999 怎么写进去的