将文件列表写入文件 - 写入的文件未找到
问题描述:
我正在使用Python 3.将文件列表写入文件 - 写入的文件未找到
这是一个脚本,我正在编写过程中。它要求输入姓名/生日,接受输入,并将其附加到列表中。该列表然后写入另一个文件。
我已经做了这方面的研究,并找不到它为什么不工作。
这里是我的代码:
print("""Enter the name and birthday of the person like this:
Adam 1/29
""")
all_birthdays = [ "none so far" ]
while True:
birthday = input("> ").upper()
if birthday == "":
break
if birthday == "LIST":
print(all_birthdays)
if birthday not in all_birthdays:
all_birthdays.append(birthday)
else:
print("This name/birthday is already known")
birthday_list = open('test.txt','w')
for bday in all_birthdays
birthday_list.write("%s\n" %bday)
第二个编辑:我添加的代码(最底层的for循环和创建文件)。它的工作,但我似乎无法找到任何地方的文件。任何帮助?我如何找到并打开它? Writing a list to a file with Python
您错过了()函数调用的括号。添加这些括号后,代码对我来说工作正常。 – Dartmouth
达特茅斯意味着'上部'函数调用。 – martineau