您可以尝试像这样清理它:
for key in mydict.keys(): if type(key) is not str: try: mydict[str(key)] = mydict[key] except: try: mydict[repr(key)] = mydict[key] except: pass del mydict[key]
这将尝试将不是字符串的任何键转换为字符串。任何无法转换为字符串或不能表示为字符串的键都将被删除。

您可以尝试像这样清理它:
for key in mydict.keys(): if type(key) is not str: try: mydict[str(key)] = mydict[key] except: try: mydict[repr(key)] = mydict[key] except: pass del mydict[key]
这将尝试将不是字符串的任何键转换为字符串。任何无法转换为字符串或不能表示为字符串的键都将被删除。