2

In Python, the defaultencoding is stored in 'unicode_default_encoding', and I find out all Python source code, there are 2 functions with it.

  1. _PyUnicode_Init() //strcpy(unicode_default_encoding, "ascii");
  2. setencoding() in site.py

So nobody modifies the defaultencoding. Then why is my defaultencoding 'utf-8'?

Bart
  • 19,692
  • 7
  • 68
  • 77
  • 3
    Do you have the file `lib/site-packages/sitecustomize.py` in your python install folder or is the file `sitecustomize.py` anywhere in the python search path? It's used to change the default encoding. See http://stackoverflow.com/a/7105835/637284 – halex Oct 18 '12 at 07:28
  • Are you're using Eclipse? Eclipse Pydev IDE, default character encoding is set to utf-8. So it might be a matter of environment. Some dev tools changes defaults to make it "better" for the user. – JackLeo Oct 18 '12 at 12:01
  • There's no sitecustomize.py in my python and I just run python in shell without any IDE – user1488229 Oct 18 '12 at 12:08

1 Answers1

0

Looks the settings in site.py will affect the default encoding.

Check out http://blog.ianbicking.org/illusive-setdefaultencoding.html

Edit site.py (in the standard library) directly. Seems like a bad idea. Though maybe I'll just delete the del sys.setdefaultencoding line... anyway, site.py might appear in other places on your computer as well (e.g., /etc/pythonX.Y/site.py).

jinghli
  • 617
  • 4
  • 11