postoption=input("Press 1 to leave a post, and 2 to close The Wall.")
if postoption=="2":
print("Wall closed.")
elif postoption=="1":
wally=pickle.load(open("The Wall.txt","rb"))
usernamey=pickle.load(open("username1.txt","rb"))
wu="\n",(wally),"\n",(usernamey)
apost=input("Enter your post below: \n")
pwickle=pickle.dump((wu, apost), open("The Wall.txt","wb"))
print(pwickle)
else:
print("Wall closed.")
此代码将留下“\n”而不是新行,因为它正在重新读取保存在 .txt 文件中的内容。阻止这种情况的最简单方法是什么?