0

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???

5
  • 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? Commented Jan 20, 2014 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... Commented Jan 20, 2014 at 17:29
  • 1
    Learn 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. Commented Jan 20, 2014 at 17:33
  • 1
    Why 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. Commented Jan 20, 2014 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 [stackoverflow.com/questions/455580/… Commented Jan 20, 2014 at 19:59

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.