Should I use Unicode string by default?

前端 未结 6 826
星月不相逢
星月不相逢 2021-02-07 03:38

Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are U

6条回答
  •  星月不相逢
    2021-02-07 04:00

    It can be tricky to consistently use unicode strings in Python 2.x - be it because somebody inadvertently uses the more natural str(blah) where they meant unicode(blah), forgetting the u prefix on string literals, third-party module incompatibilities - whatever. So in Python 2.x, use unicode only if you have to, and are prepared to provide good unit test coverage.

    If you have the option of using Python 3.x however, you don't need to care - strings will be unicode with no extra effort.

提交回复
热议问题