Python 3 and b'\x92'.decode('latin1')
<p>I'm getting results I didn't expect from decoding b'\x92' with the latin1 codec. See the session below:</p>

<pre><code>Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
&gt;&gt;&gt; b'\xa3'.decode('latin1').encode('ascii', 'namereplace')
b'\\N{POUND SIGN}'
&gt;&gt;&gt; b'\x92'.decode('latin1').encode('ascii', 'namereplace')
b'\\x92'
&gt;&gt;&gt; ord(b'\x92'.decode('latin1'))
146
</code></pre>

<p>The result decoding b'\xa3' gave me exactly what I was expecting. But the two results for b'\x92' were not what I expected. I was expecting b'\x92'.decode('latin1') to result in U+2018, but it seems to be returning U+0092.</p>

<p>What am I missing?</p>

<p>The error I made was to expect that the character 0x92 decoded to "RIGHT SINGLE QUOTATION MARK" in latin-1, it doesn't. The confusion was caused because it was present in a file that was specified as being in latin1 encoding. It now appears that the file was actually encoded in windows-1252. This is apparently a common source of confusion:</p>

<p><a href="http://www.i18nqa.com/debug/table-iso8859-1-vs-windows-1252.html" rel="nofollow">http://www.i18nqa.com/debug/table-iso8859-1-vs-windows-1252.html</a></p>

<p>If the character is decoded with the correct encoding, then the expected result is obtained.</p>

<pre><code>&gt;&gt;&gt; b'\x92'.decode('windows-1252').encode('ascii', 'namereplace')
b'\\N{RIGHT SINGLE QUOTATION MARK}'
</code></pre>

python python-3.x unicode python-unicode