Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The ASCII encoding only includes the bytes with values <code>&lt;= 127</code>. The range of characters represented by these bytes is identical in most encodings; in other words, "A" is <code>chr(65)</code> in ASCII, in latin-1, in UTF-8, and so on.</p> <p>The one half symbol, however, is not part of the ASCII character set, so when Python tries to encode this symbol into ASCII, it can do nothing but fail.</p> <p><strong>Update:</strong> Here's what happens (I assume we're talking CPython):</p> <p><code>float(u'\xbd')</code> leads to <code>PyFloat_FromString</code> in <a href="http://svn.python.org/view/python/branches/release26-maint/Objects/floatobject.c?revision=72566&amp;view=markup" rel="nofollow noreferrer">floatobject.c</a> being called. This function, giving a unicode object, in turn calls <code>PyUnicode_EncodeDecimal</code> in <a href="http://svn.python.org/view/python/branches/release26-maint/Objects/unicodeobject.c?revision=74576&amp;view=markup" rel="nofollow noreferrer">unicodeobject.c</a> being called. From skimming over the code, I get it that this function turns the unicode object into a string by replacing every character with a unicode codepoint <code>&lt;256</code> with the byte of that value, i.e. the one half character, having the codepoint 189, is turned into <code>chr(89)</code>.</p> <p>Then, <code>PyFloat_FromString</code> does its work as usual. At this moment, it's working with a regular string, which happens to be containing a non-ASCII range byte. It doesn't care about this; it just finds a byte that's not a digit, a period or the like, so it raises the value error.</p> <p>The argument to this exception is a string </p> <pre><code>"invalid literal for float(): " + evil_string </code></pre> <p>That's fine; an exception message is, after all, a string. It's only when you try to decode this string, using the default encoding ASCII, that this turns into a problem.</p>
 

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