在以下代碼中,文件被正確創(chuàng)建和關(guān)閉,沒有錯(cuò)誤消息,但當(dāng)它嘗試寫入文件時(shí),沒有任何反應(yīng)。沒有錯(cuò)誤消息,也沒有 0 寫入文件:if message.content == "MMO start": dir = r'C:\\Users\\User\Desktop\MMOProfiles' MessageAuthor = str(message.author) newpath = os.path.join(dir,MessageAuthor) doesExist = os.path.exists(newpath) if doesExist == False: await message.channel.send("Creating profile") os.makedirs(newpath,1) newpath = os.path.join(newpath,"Level.txt") open(newpath,"x") newpath.close() open(newpath,"w") newpath.write("0") newpath.close() if doesExist == True: await message.channel.send("You already have a profile")感謝所有幫助,謝謝。
1 回答

慕村225694
TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊
newpath = os.path.join(newpath,"Level.txt") type(newpath)
斯特
您正在嘗試寫入字符串,而不是文件處理程序
做
f = open(newpath,"w") f.write("0") f.close()
添加回答
舉報(bào)
0/150
提交
取消