encode

Delete every non utf-8 symbols from string

Delete every non utf-8 symbols from string Question: I have a big amount of files and parser. What I Have to do is strip all non utf-8 symbols and put data in mongodb. Currently I have code like this. with open(fname, “r”) as fp: for line in fp: line = line.strip() line = line.decode(‘utf-8’, ‘ignore’) …

Total answers: 4

How can I print the raw unicode in python?

How can I print the raw unicode in python? Question: I am novice in Python, so maybe I can’t express it well… I got a string ‘xb9xfe’ I want it print in this very fashion ‘xb9xfe’, not converting to a Chinese character ‘哈’. What is the proper way to do it? Asked By: novice3 || …

Total answers: 2

decode 7-bit GSM

decode 7-bit GSM Question: I found this post on how to encode ascii data to 7-bit GSM character set, how would I decode 7-bit GSM character again (reverse it back to ascii)? Asked By: johannes || Source Answers: For Python2: import binascii gsm = (“@£$¥èéùìòÇnØørÅåΔ_ΦΓΛΩΠΨΣΘΞx1bÆæßÉ !”#¤%&'()*+,-./0123456789:;<=>?” “¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑÜ`¿abcdefghijklmnopqrstuvwxyzäöñüà”) ext = (“““““““““““^“““““““““`{}““`\““““““[~]`” “|““““““““““““““““““€“““““““““““““”) def gsm_encode(plaintext): result = …

Total answers: 5

Python & MySql: Unicode and Encoding

Python & MySql: Unicode and Encoding Question: I am parsing json data and trying to store some of the json data into Mysql database. I am currently getting following unicode error. My question is how should I handle this. Should I handle it from the database side, and if so how can I modify my …

Total answers: 2

Python Unicode Encode Error

Python Unicode Encode Error Question: I’m reading and parsing an Amazon XML file and while the XML file shows a ‘ , when I try to print it I get the following error: ‘ascii’ codec can’t encode character u’u2019′ in position 16: ordinal not in range(128) From what I’ve read online thus far, the error …

Total answers: 9

Python UnicodeDecodeError – Am I misunderstanding encode?

Python UnicodeDecodeError – Am I misunderstanding encode? Question: Any thoughts on why this isn’t working? I really thought ‘ignore’ would do the right thing. >>> ‘add x93Monitoringx93 to list ‘.encode(‘latin-1′,’ignore’) Traceback (most recent call last): File “<interactive input>”, line 1, in ? UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0x93 in position 4: ordinal not in …

Total answers: 4