I like Unicode more than I used to...

Alex Martelli aleax at aleax.it
Mon Feb 24 08:00:19 EST 2003


gabor wrote:
   ...
> is there a way to specify in python some kind of default-encoding? i
> mean can i somehow tell him that when printing unicode strings, i always
> want to use utf-8, so that .encode('utf-8') isn't necessary?

Yes, on a site-wide basis: see the file site.py in your site-packages
directory.  You can either change the blocks guarded by "if 0:" in
that file itself, or add a sitecustomize.py file in the same
directory that calls sys.setdefaultencoding('utf-8') with the
same effect.

Of course, if you do that you're likely to write programs that
will only run on your site (or other similarly customized) and
not be suitable for general distribution to other sites.  But
if that's OK with you, Python lets you do it.


Alex





More information about the Python-list mailing list