【问题标题】:Python - is there a way to make all strings unicode in a project by default?Python - 有没有办法让项目中的所有字符串默认为 unicode?
【发布时间】:2016-06-01 02:42:45
【问题描述】:

而不是在每个字符串前面输入 u?

...还有一些文字让 stackoverflow 开心

【问题讨论】:

  • 你可以只使用 python3

标签: python unicode internationalization


【解决方案1】:

是的,使用from __future__ import unicode_literals

>>> from __future__ import unicode_literals
>>> s = 'hi'
>>> type(s)
<type 'unicode'>

在 Python 3 中,字符串默认为 unicode 字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    相关资源
    最近更新 更多