[Pythonmac-SIG] How to print unicode to OS-X Terminal.app

Christopher Barker Chris.Barker at noaa.gov
Thu Feb 14 21:10:51 CET 2008

Kent Johnson wrote:
> You can, with sys.setdefaultencoding(). See here for discussion of how:
> http://blog.ianbicking.org/illusive-setdefaultencoding.html

 > and here for arguments that this is a bad idea (mostly because it makes
 > your code non-portable):
 > http://faassen.n--tree.net/blog/view/weblog/2005/08/02/0

Thanks for the links.

I'm nervous about messing with sys.setdefaultencoding() too - partly 
because I have no idea what all the implications are.

It sure would be nice to be able to just change it for "print" though. 
Even if it's going to us ascii, it really should use "replace" or 
"ignore" -- it's much better to get something, rather than an error. 
It's just a handy utility function after all.

Maybe I can re-map print to something like:

TerminalEncoding = "utf-8"
def uni_print(object):

but print is a statement, rather than a function, so I don't know how to 
do that. I may start using a utility function like that for my code, though.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the Pythonmac-SIG mailing list