我想将值写入文件中。我在不同的 if
语句中获得两个值。如何修改它以获取同一输出文本文件中的两个值?
if row == 0 and col == 1:
print ertek
with open("Output.txt", "w") as kiiras:
kiiras.write("data1: %s" % ertek)
kiiras.write("\n")
if type(pattern_colour) is tuple and row == 2:
tipus = thecell.value
tipus = tipus.encode('ascii', 'ignore').decode('ascii')
print tipus
text_file = open("Output.txt", "w")
text_file.write("data2: %s" % tipus)
最佳答案
这可能是你的打开方式w
的问题,打开文件时应该尝试使用a
方式,避免覆盖,
我链接了这个问题,因为它比我的解释要好得多 python open built-in function: difference between modes a, a+, w, w+, and r+?
关于python - 将行添加到现有文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55138161/