文件章的疑问
filename = "learn_python.txt"
while True:
print("Please input your name,If you want to quit, input 'q'\n")
guest_name = input("What is your name?>")
if guest_name == "q":
break
else:
print("Welcome!"+ guest_name)
with open(filename,"w") as f:
f.write(guest_name + "\n")
with open(filename,encoding='UTF-8') as file_object:
lines = file_object.readlines()
for line in lines:
line = line.strip()
print(f)
结果是
<_io.TextIOWrapper name='learn_python.txt' mode='w' encoding='UTF-8'>