I only code in English but I have to deal with python unicode all the time. Sometimes its hard to remove unicode character from and dict. How can I change python default character encoding to ASCII???
Asked
Active
Viewed 631 times
0
-
Which problems specifically are you having? And are you that your problem is the choice of default encoding, not that encoding discipline (the difference between text and bytes) is enforced at all? – Jan 20 '14 at 17:26
-
The A in ASCII, stands for American, so could be a you'll get one or two problems that will cost you a few £s, doing that... – Tony Hopkinson Jan 20 '14 at 17:29
-
1Learn to deal with Unicode. It's not going away, and there are non-ASCII characters--punctuation, mostly, but the occasional accented vowel as well--that are can appear in English text. – chepner Jan 20 '14 at 17:33
-
1Why don't you tell us about a specific problem your are having, and we can help you deal with that specific problem. Don't try to crack this nut with a sledgehammer, you are going about it the wrong way. – Martijn Pieters Jan 20 '14 at 17:37
-
My problem was to pass unserialized mogodb query result with unicode to template in django because I could not use serializers ,json,simplejson and cjson.But this helped [http://stackoverflow.com/questions/455580/json-datetime-between-python-and-javascript] – Praveen Singh Yadav Jan 20 '14 at 19:59
1 Answers
3
That would be the wrong thing to do. As in very wrong. To start with, it would only give you an UnicodeDecodeError instead of removing the characters. Learn proper encoding and decoding to/from unicode so that you can filter out tthe values using rules like errors="ignore"
You can't just ignore the characters taht are part of your data, just because you 'dislike" then. It is text, and in an itnerconected World, text is not composed of only 26 glyphs.
I'd suggest you get started by reading this document: http://www.joelonsoftware.com/articles/Unicode.html

jsbueno
- 99,910
- 10
- 151
- 209