0
使用此程序时,我试图将条目添加到空文本文件中。下面是我的代码:使用While循环在Python中添加/添加文件
###Adding to an Empty File
filename = 'guest_book.txt'
message = input("Please enter your name for our records: ") # retrieving input
while message != 'finished': # checking for value that will end the program
with open(filename, 'a') as f:
f.write(message)
程序正确建立,但一旦我输入一个名字,什么也不会发生,且该文本文件保持为空。有任何想法吗?
我的输出量混乱了,所以我不得不增加了一些带()方法。否则,这工作!谢谢! –