views:

376

answers:

2

I have many "can't encode" and "can't decode" problems with python when I run my applications from console. But in Eclipse Pydev IDE, default character encoding is set to utf-8 and I'm fine.

I searched around for setting default encoding, and people say that python deletes the sys.setdefaultencoding function on startup and we can not use it.

So whats the best solution for it ?

A: 

See http://blog.ianbicking.org/illusive-setdefaultencoding.html.

djc
reload(sys) and then using sys.setdefaultencoding worked for me
Ali Nadalizadeh
Changing the default encoding is restricted for a reason. Dictionary hashes break, existing code that assumes 'ascii' is the default encoding breaks. Here is a discussion: http://faassen.n--tree.net/blog/view/weblog/2005/08/02/0
Mark Tolonen
+1  A: 

One solution is to make sure Eclipse / Pydev does not run with utf-8 as default console encoding. Under the eclipse run dialog settings ("run configurations" iirc) you can choose the default encoding on the common tab. Change it to US-ASCII if you want to have these errors 'early' (in other words: in your Pydev environment).

Also see this link.

ChristopheD