[Pythonmac-SIG] Unicode

Dougal Graham dougalg at gmail.com
Thu Mar 15 05:14:03 CET 2007

Thanks for the quick reply! As I'm sure you can tell, I'm still fairly
new to Python. Do you know of a tutorial on how to properly manage
unicode in Python, then?

I ran into trouble when trying to run a command containing unicode
characters through commands.getoutput()...

On 3/15/07, Bob Ippolito <bob at redivi.com> wrote:
> On 3/14/07, Dougal Graham <dougalg at gmail.com> wrote:
> > Hi there,
> >
> > I am having a problem with figuring out how to set utf-8 as the
> > default encoding for python. I have found various references to
> > sitecustomize.py, but I'm not sure where to put that file. I just
> > recently updated to python 2.5 using the .dmg file from python.org.
> >
> You really don't want to do that. The default encoding should always
> be ASCII, setting it to anything else breaks some invariants.
> The site-packages folder is one place to put stuff. It lives in
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages
> However, don't do it in this case. The reason you haven't been able to
> find a good resource that tells you how to do it is because it's not
> the correct thing to do.
> Here's Frederik's thoughts on the setting (and he is certainly an
> authority on Python's unicode implementation).
> """
> sys.setdefaultencoding() was added for experimentation during Unicode
> development, and should not be used in production code. All sorts of
> ugliness can happen if you mess around with the conversion rules
> (especially if you use a variable-width encoding). It's not that hard
> to write encoding-aware code, really.
> """
> -bob

Dougal Graham
Home: (709) 753-2831
Cell: (709) 351-0587

More information about the Pythonmac-SIG mailing list