将文件粘贴到已有 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 (将#修改为@)