【发布时间】:2019-10-10 17:49:34
【问题描述】:
我正在尝试将日期保存到单独文件(“file.txt”)中的数组(log[])中。 我该怎么做?
我已经打开了文件本身,但我不知道如何打开该文件中的 log[] 并将数据附加到它。
x = input("Please Enter Name: ")
y = input("Please Enter Phone Number: ")
z = input("Please Enter Room Number: ")
with open("log.txt", "a") as f:
with open("log[]", "a") as g:
g.write("Name: " + x)
g.write("Phone Number: " + y)
g.write("Room Number: " + z)
when doing this, it opened up a new file called log[] and saved it into there, not the actual array in log.txt. Then log.txt displayed that the login crashed
【问题讨论】:
-
你能说出你希望在文件中写什么吗?
-
我正在尝试将三个值保存到文件上的数组中,然后能够调用它们
-
有助于编写或标记语言。
-
您没有阅读来自
log.txt的任何内容。您只是将从输入读取的值附加到log[]