def write_csv_file(filename):
with open(filename, "w") as csv_file:
file_name = csv_file
write = input("please enter the number of times you would like to enter "
"a text into then file onto a different line: ")
write = int(write)
for write in range(write):
x = input("please enter what you would like to add: ")
file_name.write(x)
exit()
xxx = input("please enter the name of the file you would like to print into: ")
print(write_csv_file(xxx))
答案 0 :(得分:1)
只需在write方法中添加一个换行符;
file_name.write(f'{x}\n')
\n
部分表示换行/换行。
答案 1 :(得分:1)
def write_csv_file(filename):
with open(filename, "w") as csv_file:
file_name = csv_file
write = input("please enter the number of times you would like to enter "
"a text into then file onto a different line: ")
write = int(write)
for write in range(write):
x = input("please enter what you would like to add: ")
file_name.write(x)
file_name.write('\n')
exit()
xxx = input("please enter the name of the file you would like to print into: ")
print(write_csv_file(xxx))
在编写文本后添加file_name.write('\n')
。
\n
表示新行或换行符。