Encoding for Multilingual .py Files

前端 未结 2 612
礼貌的吻别
礼貌的吻别 2021-02-14 01:20

I am writing a .py file that contains strings from multiple charactersets, including English, Spanish, and Russian. For example, I have something like:

string_en         


        
2条回答
  •  情话喂你
    2021-02-14 01:59

    There are two aspects to proper encoding of strings in your use case:

    1. For Python to understand that you are using UTF-8 encoding, you must include in the first or second line of your code, a line that looks like # coding=utf-8. See PEP 0263 for details.

    2. Your editor also must use UTF-8. This requires to configure it, and depends on the editor you are using. Configuration of Emacs and Vim are addressed in the same PEP, Eclipse can default to the filesystem encoding, which itself can be derived from your locale settings, etc.

提交回复
热议问题