【发布时间】:2020-04-26 09:31:17
【问题描述】:
我正在尝试将用户输入写入 python 中的文件,但它不起作用。这是我的代码:
filename='guest_book.txt'
while True:
with open(filename,'a') as file_object:
name=input('Please enter your name')
file_object.write(name)
file.object.write('visit the website')
print('Hello')
【问题讨论】:
-
请添加更多上下文
-
会发生什么(输出,完整的错误消息),应该发生/显示什么?编辑问题以显示它。
-
您似乎试图将代码重新输入问题框中,而不是复制粘贴。在这样做的过程中,您引入了实际代码与您发布的内容之间的差异。相反,请从您实际运行的文件中复制粘贴代码。
-
while True?这就像无限/永无止境,要求您输入名称。file.object.write('visit the website')也应该是file_object.write('visit the website')
标签: python python-3.x file