字典与unicode中的键

Koi*_*irN 10 python unicode

在Python中是否可以使用Unicode字符作为字典的键?我用Unicode作为键的西里尔字.当尝试通过键获取值时,我得到以下回溯:

 Traceback (most recent call last):
 File "baseCreator.py", line 66, in <module>
    createStoresTable()
 File "baseCreator.py", line 54, in createStoresTable
    region_id = regions[region]
 KeyError: u'\u041c\u0438\u043d\u0441\u043a/\u041c\u043e\u0441\u043a\u043e\u0432\u0441\u043a\u0438\u0439\xa0'
Run Code Online (Sandbox Code Playgroud)

Woo*_*ble 7

是的,这是可能的.您获得的错误意味着您正在使用的密钥不存在于您的字典中.

要调试,试试print你的字典; 你会看到每个键的repr,它应该显示实际的键是什么样的.