Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To represent a unicode string as a string of bytes is known as <b>encoding</b>. Use <code>u'...'.encode(encoding)</code>.</p> <p>Example:</p> <pre> >>> u'æøå'.encode('utf8') '\xc3\x83\xc2\xa6\xc3\x83\xc2\xb8\xc3\x83\xc2\xa5' >>> u'æøå'.encode('latin1') '\xc3\xa6\xc3\xb8\xc3\xa5' >>> u'æøå'.encode('ascii') UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128) </pre> <p>You typically encode a unicode string whenever you need to use it for IO, for instance transfer it over the network, or save it to a disk file.</p> <p>To convert a string of bytes to a unicode string is known as <b>decoding</b>. Use <code>unicode('...', encoding)</code> or '...'.decode(encoding).</p> <p>Example:</p> <pre> >>> u'æøå' u'\xc3\xa6\xc3\xb8\xc3\xa5' # the interpreter prints the unicode object like so >>> unicode('\xc3\xa6\xc3\xb8\xc3\xa5', 'latin1') u'\xc3\xa6\xc3\xb8\xc3\xa5' >>> '\xc3\xa6\xc3\xb8\xc3\xa5'.decode('latin1') u'\xc3\xa6\xc3\xb8\xc3\xa5' </pre> <p>You typically decode a string of bytes whenever you receive string data from the network or from a disk file.</p> <p>I believe there are some changes in unicode handling in python 3, so the above is probably not correct for python 3.</p> <p>Some good links:</p> <ul> <li><a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="noreferrer">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)</a></li> <li><a href="http://docs.python.org/howto/unicode.html" rel="noreferrer">Unicode HOWTO</a></li> </ul>
    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. 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