Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Possible solutions</h2> <p>Either write like this:</p> <pre><code>a = {"a": u"çö"} b = "çö" b.decode('utf-8') == a['a'] </code></pre> <p>Or like this (you may also skip the <code>.decode('utf-8')</code> on both sides):</p> <pre><code>a = {"a": "çö"} b = "çö" b.decode('utf-8') == a['a'].decode('utf-8') </code></pre> <p>Or like this (my recommendation):</p> <pre><code>a = {"a": u"çö"} b = u"çö" b == a['a'] </code></pre> <h2>Explanation</h2> <p><em>Updated based on Tim's comment.</em> In your original code, <code>b.decode('utf-8') == u'çö'</code> and <code>a['a'] == 'çö'</code>, so you're actually making the following comparison:</p> <pre><code>u'çö' == 'çö' </code></pre> <p>One of the objects is of type <code>unicode</code>, the other is of type <code>str</code>, so in order to execute the comparison, the <code>str</code> is converted to <code>unicode</code> and then the two <code>unicode</code> objects are compared. It works fine in the case of purely ASCII strings, for example: <code>u'a' == 'a'</code>, since <code>unicode('a') == u'a'</code>.</p> <p>However, it fails in case of <code>u'çö' == 'çö'</code>, since <code>unicode('çö')</code> returns the following error: <em>UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)</em>, and therefore the whole comparison returns False and issues the following warning: <em>UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal</em>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload