python - Decoding a String that Contains Encoded Characters -


I have some strings that I am sticking to as test data in my script. String comes from email that contains encoded characters and is throwing a SyntaxError So far, I am not able to locate the solution to this issue. When I get the print repr (string) , I get this string: total value for 1 load \ xe2 \ x80 \ x93 approximately $ 75,200 \ N '' The total value for the second load is \ xe2 \ x80 \ x93 approximately $ 74,300 \ n '

And when I run my script, this error pins:

  SyntaxError: non-ASCII characters in the file '\ xe2' & lt; File name & gt; On line & lt; Line number & gt; but no encoding is declared; When I print lines with only encoded characters, I get:  
     'Total value for second load' ??? About. $ 74,300 '  

When I copy it by email, the data looks like this:

 ' Total value for first load 'is approx. $ 75,200 '' total value for second load '' approx. $ 74,300 '  

From my searches, I believe this is encoded with UTF-8, but on the basis of this fact I do not know that some characters are encoded, But most of them (probably?) Are not those I have tried the "solution" which I have found so far Adding # - * -coding: utf-8 - * - at the top of my script and the script has still been hanged ... it does nothing: ( < P> If someone can provide some information about how to deal with this scenario, then it will be amazing.

I have defined decoding and string.encode () and The string was using different encodings based on the .decode () , which I could get on Google, but it did not solve the problem I really like a Python solution because I need to paste the data into textfield in a GUI to work on the project, and then that data will be processed. Other solutions have suggested to paste data into something like words, or notepad, save it as plain text, copy / paste it again, this file is slightly more. C know the python way to deal with this problem?

  & gt; & gt; & Gt; Msg = 'total value of first load \ xe2 \ x80 \ x93 access x $ 75,200 \ n '& gt; & Gt; & Gt; Print msg.decode ("utf-8") total value for total load is approx. $ 75,200   

Make sure you use some of the waste which can support these characters (the IE DOS terminal may not be!)

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -