My.writelines()函数在python中不起作用

My.writelines()函数在python中不起作用,python,Python,代码: 输出如下所示: 或: writelines不会为您提供换行符,因此如果字符串中尚未包含换行符,则必须添加它们 你可以做: ApplesAndroidCoffee Process finished with exit code 0 那么您的预期输出是什么?注意:“将行列表写入流。不会添加行分隔符,因此通常提供的每一行末尾都有行分隔符。” ApplesAndroidCoffee Process finished with exit code 0 f.writelines(line

代码:

输出如下所示:

或:


writelines
不会为您提供换行符,因此如果字符串中尚未包含换行符,则必须添加它们

你可以做:

ApplesAndroidCoffee

Process finished with exit code 0

那么您的预期输出是什么?注意:“将行列表写入流。不会添加行分隔符,因此通常提供的每一行末尾都有行分隔符。”
ApplesAndroidCoffee

Process finished with exit code 0
f.writelines(line + '\n' for line in l)