擅长:python、mysql、java
<p>有多个字符看起来像分号。自从你
提到<code>'\x03~'</code>和utf-16be编码,您一定是指
希腊问号。(下面,我将<code>'\x03~'</code>表示为<code>b'\x03~'</code>以使这个答案有效
在Python2.7和Python3中。)</p>
<pre><code>In [207]: b'\x03~'.decode('utf-16be')
Out[207]: u'\u037e'
In [208]: import unicodedata as UDAT
In [209]: UDAT.name(u'\u037e')
Out[209]: 'GREEK QUESTION MARK'
In [206]: u'\N{GREEK QUESTION MARK}' == u';'
Out[206]: True
In [198]: u'\N{GREEK QUESTION MARK}'.encode('utf-16be')
Out[198]: b'\x03~'
</code></pre>
<p>因此,用utf-16be编码的unicode U+037E(希腊问号)是<code>b'\x03~'</code>,而不是<code>b'\x03'</code>。你知道吗</p>
<hr/>
<p>请注意,这与U+003B(分号)不同:</p>
<pre><code>In [211]: u';'.encode('utf-16be')
Out[211]: b'\x00;'
In [212]: UDAT.name(u';')
Out[212]: 'SEMICOLON'
In [214]: hex(ord(u';'))
Out[214]: '0x3b'
In [216]: u'\u003b' == u'\N{SEMICOLON}'
Out[216]: True
In [217]: u'\N{GREEK QUESTION MARK}' == u'\N{SEMICOLON}'
Out[217]: False
</code></pre>