Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the notation</p> <pre><code>u'Capit\xe1n\n' </code></pre> <p>the "\xe1" represents just one byte. "\x" tells you that "e1" is in hexadecimal. When you write</p> <pre><code>Capit\xc3\xa1n </code></pre> <p>into your file you have "\xc3" in it. Those are 4 bytes and in your code you read them all. You can see this when you display them:</p> <pre><code>&gt;&gt;&gt; open('f2').read() 'Capit\\xc3\\xa1n\n' </code></pre> <p>You can see that the backslash is escaped by a backslash. So you have four bytes in your string: "\", "x", "c" and "3".</p> <p>Edit:</p> <p>As others pointed out in their answers you should just enter the characters in the editor and your editor should then handle the conversion to UTF-8 and save it.</p> <p>If you actually have a string in this format you can use the <code>string_escape</code> codec to decode it into a normal string:</p> <pre><code>In [15]: print 'Capit\\xc3\\xa1n\n'.decode('string_escape') Capitán </code></pre> <p>The result is a string that is encoded in UTF-8 where the accented character is represented by the two bytes that were written <code>\\xc3\\xa1</code> in the original string. If you want to have a unicode string you have to decode again with UTF-8.</p> <p>To your edit: you don't have UTF-8 in your file. To actually see how it would look like:</p> <pre><code>s = u'Capit\xe1n\n' sutf8 = s.encode('UTF-8') open('utf-8.out', 'w').write(sutf8) </code></pre> <p>Compare the content of the file <code>utf-8.out</code> to the content of the file you saved with your editor.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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