Ian Bicking: the old part of his blog

Illusive setdefaultencoding comment 000

Elusive indeed. I just spent the better part of a day trying to figure out why using zipfile.writestr(string) on UTF-8 encoded strings was giving me a UnicodeDecodeError (I'm still relatively new at python). It was actually binascii.crc32(bytes) that was complaining. Since I don't have root access, I can't edit lib/site-packages/sitecustomize.py. I tried putting sys.setdefaultencoding('utf-8') in a file in my working directory. At first, it wouldn't let me access sys.setdefaultencoding, but then I added '.' to my PYTHONPATH and that finally did it. But what happens when I'm zipping up Latin-1 encoded files? I would like to be able to set the default encoding from within my program. I wonder what would be the danger in allowing that? Right now, the only way to do that are the three methods mentioned above. None of these sound satisfactory to me.

Comment on Re: The Illusive setdefaultencoding
by Justin