1. 写入多行
函数write()不会在你写入的文本末尾添加换行符,因此如果你写入多行时没有指定换行符,
文件看起来可能不是你希望的那样:
file='../data/write1.txt'
with open(file,'w') as file_object:
file_object.write("1 is one")
file_object.write("2 is two")
加入换行符后:
file='../data/write1.txt'
with open(file,'w') as file_object:
file_object.write("1 is one \n")
file_object.write("2 is two\n")