pickle字符串时\n换行符和文本\n出现问题

2024-10-04 05:25:46 发布

您现在位置:Python中文网/ 问答频道 /正文

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文件中保存的内容。什么是阻止这一切的最简单的方法?在


Tags: thetotxtinputloadopenpostpickle