filename = 'guest.txt'
name = input("请输入你的名字: ")
with open(filename, 'w') as file_object:
file_object.write(name)
with open(filename) as file_object: #不知道为什么不可以直接在写入之后直接输出???
lines = file_object.readlines()
print(lines)
结果
请输入你的名字: Li ming
['Li ming']Process finished with exit code 0