【发布时间】:2020-01-02 16:59:23
【问题描述】:
我正在同时致力于 Python 2 和 3 的支持,但我有一些奇怪的事情我至今无法理解。
我正在使用python-future 模块来实现这种转换。当我在newstr 对象上使用__mod__ 函数时,我的输出是unicode,而我希望它是newstr。我错过了什么吗?
>>> from builtins import str # provided by the future module to allow smooth transition from Py2 to Py3
>>> str('%s %s') % (u'Hello', u'World')
u'Hello World'
>>> type(str('%s %s') % (u'Hello', u'World'))
<type 'unicode'>
【问题讨论】:
标签: python python-2.x python-2to3