我最近切换到python的3.7.3版本,并且一直在尝试更新代码以适应新版本。
在切换之前,pickle可以很好地转储和加载我发送的字典,但是现在它一直给我一个TypeError: can't pickle TaskStepMethWrapper objects
错误
搜索TaskStepMethWrapper可能表明它可能与asyncio有关,但是当我使用python 3.6时并没有显示此错误。
在这里输入我的代码
def load_guildlist(self):
with open("guildlist.dadbot","rb") as sl:
return pickle.loads(sl.read())
#edits the guildlist into an external file
def edit_guildlist(self,dictionary):
with open("guildlist.dadbot","wb") as sl:
#attempt to force the passing of a dictionary
pickle.dump(dict(dictionary),sl)
#Registers the guild into the guildlist
async def on_guild_join(self,guild):
#Setup an initial prefix for flexible changing later
#Check to see if guildlist is empty or not(may only ever run once)
try:
self.guildlist = self.load_guildlist()
except EOFError:
self.guildlist = {}
self.edit_guildlist(self.guildlist)
#Stores a random prefix for the guild so it can be changed later
#Should allow for guilds to have prefix preferences
#Also sets guild preferences and statuses
if guild not in self.guildlist:
#New guild
self.guildlist[guild]={}
self.guildlist[guild]["prefix"] = genPrefix()
self.guildlist[guild]["voice_channel"] = "all"
self.edit_guildlist(self.guildlist)
在这里进行追溯:
Ignoring exception in on_guild_join
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/discord/client.py", line 251, in _run_event
await coro(*args, **kwargs)
File "main.py", line 68, in on_guild_join
self.edit_guildlist(self.guildlist)
File "main.py", line 48, in edit_guildlist
pickle.dump(dict(dictionary),sl)
TypeError: can't pickle TaskStepMethWrapper objects
Ignoring exception in on_message
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/discord/client.py", line 251, in _run_event
await coro(*args, **kwargs)
File "main.py", line 80, in on_message
self.guildlist = self.load_guildlist()
File "main.py", line 42, in load_guildlist
return pickle.loads(sl.read())
EOFError: Ran out of input