我正在使用文件处理的追加方法在文件中写入数据,但它没有显示在文件中。 此外,在读取文件时显示空字节错误。
with open("filename.txt",'a') as f_ro_panel:
f_ro_panel.write('\n'+str(vl)+'\t'+str(op_minute)+'\t'+str(bcc)+\
'\t'+str(temp)+'\t'+str(tds2)+'\t'+str(tds1)+'\t'+str(pfr)+\
'\t'+str(rfr)+'\t'+str(rwpc)+'\t'+str(hppc)+'\t'+str(twv)+\
'\t'+str(rwv)+'\t'+str(uvst)+'\t'+str(tsc)+'\t'+str(tlv))
f_ro_panel.close()
这是编写的代码。
阅读时我正在使用这个程序
with open("filename.txt", 'rU') as my_file:
reader = csv.reader(my_file, delimiter='\t')
my_list = list(reader)
ListLen = len(my_list)
my_file.close()
如有任何帮助,我们将不胜感激。
最佳答案
您可以检查的几件事:
- 变量 v1、op_minute 已分配给它们正确的值
- 检查您是否能够在不附加任何内容的情况下读取文件的当前内容(如果文件已经包含一些数据)。分隔符可能存在一些问题。
我尝试运行您的代码,它对我来说运行良好。
关于python - 在追加文件时,数据没有写入文件,而在读取文件时,它在 python 中显示空字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48822567/