如何解决将文件粘贴到已有 6 行文本的文档时如何添加换行符
这类似于我之前的问题。现在我无法将 .mnu
文件中的内容粘贴到 .fld
文件(已经有 6 行数据)。我正在尝试添加新行但出现错误。我要在最后添加 + '\n'
吗?还是不行。
#find all .mnu files
files = glob(".mnu")
for file in files:
with open(file,"r") as myfile:
contents = myfile.read()
#write to new file
with open('2021.fld','a' as secondfile:
for line in files:
secondfile.write(contents)
上述代码有效,但我试图将其粘贴到 .fld
文件中的新行 (7)。
错误:
Traceback (most recent call last):
file "./readwrite.py",line 11 in <module>
secondfile.write(contents) + '\n'
TypeError: unsupported operand type(s) for +: 'nonetype' and 'str'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。