Is there an easy way to make unicode work in python?

后端 未结 5 2245
难免孤独
难免孤独 2021-01-04 09:22

I\'m trying to deal with unicode in python 2.7.2. I know there is the .encode(\'utf-8\') thing but 1/2 the time when I add it, I get errors, and 1/2 the time wh

5条回答
  •  [愿得一人]
    2021-01-04 10:00

    This is a very old question but just wanted to add one partial suggestion. While I sympathise with the OP's pain - having gone through it a lot myself - here's one (partial) answer to make things "easier". Put this at the top of any Python 2.7 script:

    from __future__ import unicode_literals

    This will at least ensure that your own literal strings default to unicode rather than str.

提交回复
热议问题