Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What do you call "special characters"? What is the encoding of the data you have? Before proceeding, it is important for that you do understand what are encodings, what is unicode, and that the wrold, and data you get around is not restricted to the 26 letters primarily used in the English language. <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="nofollow">Check this article</a> to learn about it. </p> <p>That said, Python can encode your data in an encoding of your choice - even ASCII, so you only get the characters 32-127, and no "stranger" characters at all - like ã, ç, É - or you can encode your data in utf-8 to be able to use the whole array of characters we use around the planet. However, if you can only "encode" Unicode data (Python tries to implicit convert a byte string to unicode before if you use the encode string method) - so you do have to know the encoding of your data source anyway. Once your data is decoded into unicode (inside your running program), you can encode it to your desired output (e.g. ASCII or "quopri_codec" ), and set the "errors" keyword parameter to "ignore" or "xmlcharrefreplace" on your call to encode. </p> <p>To understand it better, check the <a href="http://docs.python.org/library/codecs.html" rel="nofollow">codecs documentation</a> from Python </p> <p>For example, assuming your input data is incoded in iso8859_15 (aka latin1 or cp1252 put or take 2 char definitions),a nd that you really mean to suppress any non-English character:</p> <pre><code>s = client.service.GetData('data1') s = s.decode("iso88159_15").encode("ASCII", errors="ignore") sr = '&lt;root&gt;%s&lt;/root&gt;' % s root = ET.fromstring(sr) </code></pre> <p>Otoh, since you are encoding xml, putting xml references to the chars you don't want to deal with should not hurt - (as probably encoding to utf-8 would not hurt either):</p> <pre><code>s = s.decode("iso88159_15").encode("ASCII", errors="xmlcharrefreplace") </code></pre>
    singulars
    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. This table or related slice is empty.
    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