擅长:python、mysql、java
<p>最兼容的方法是使用<code>six</code>模块或类似的兼容性填充程序:</p>
<pre><code>import six
s = six.u('\u0300')
</code></pre>
<p><code>six</code>在PyPI上可用,并且被广泛地使用和测试</p>
<p>另一种选择是:</p>
<pre><code>from __future__ import unicode_literals
s = '\u0300'
</code></pre>
<p>但是,这可能与Python2的许多期望相冲突,即字符串项可以包含字节。当<code>unicode_literals</code>打开时,字符串文本将被静默地几乎神奇地升级为Unicode字符串。Python文化通常倾向于显式的而不是隐式的</p>