我已打开文件“ a +”模式以附加数据,如下所示
with open("/home/harsha/apple.txt","a+") as fo:
header="apple"
fo.write(header)
输出看起来像这样
[empty]
apple
apple
我希望输出看起来像这样
apple
apple
apple
答案 0 :(得分:0)
这是简单的代码修改,您可以发现对此有用:
with open("apple.txt","a+") as fo:
header="apple\n"
fo.write(header)