If a command line program is unsure of stdout's encoding, what encoding should it output?

Posted by mackstann on Stack Overflow See other posts from Stack Overflow or by mackstann
Published on 2011-02-16T07:22:30Z Indexed on 2011/02/16 7:25 UTC
Read the original article Hit count: 161

Filed under:
|
|
|
|

I have a command line program written in Python, and when I pipe it through another program on the command line, sys.stdout.encoding is None. This makes sense, I suppose -- the output could be another program, or a file you're redirecting it into, or whatever, and it doesn't know what encoding is desired. But neither do I! This program will be used by many different people (humor me) in different ways. Should I play it safe and output only ascii (replacing non-ascii chars with question marks)? Or should I output UTF-8, since it's so widespread these days?

© Stack Overflow or respective owner

Related posts about python

Related posts about linux