开发者

How to encode for a dict

I have the开发者_如何学运维 following dict:

dict = {"es-ES": "Capítulo "}.

However, when I try to use the dict, I get the following error:

SyntaxError: Non-ASCII character '\xc3' in file..

I looked into the massive Python unicode docs ( http://docs.python.org/howto/unicode.html ), but haven't been able to figure this out yet. How would I 'encode' the dict so I could call dict['es-ES']? Thank you.


Add the following line:

# -*- coding: utf-8 -*-

(Assuming you are using UTF-8), to the top of your Python file and you will be able to use Unicode without issue. See the Python docs on unicode.

* Also, don't use dict as a variable name - you'll shadow the built-in type of the same name

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜