Re: [Python-ideas] changing sys.stdout encoding

On 06/07/2012 03:00 PM, Mike Meyer wrote:
This is how it seems to be done in Perl: binmode(STDOUT, ":encoding(sjis)"); which seems quite a bit simpler than Python. I don't know if it meets your "so much easier" criterion. A quick trial showed that it works as advertised when called before any output. The description of binmode() in "man perlfunc" sounds like encoding can be changed on-the-fly but my attempt to do so had no effect, so I don't know if I'm misinterpreting the text or wrote bad Perl code (haven't used it in ages and not interested in relearning it right now.) TCL appears to have on-the-fly encoding changes: | encoding system ?encoding? | Set the system encoding to encoding. If encoding is omitted | then the command returns the current system encoding. The system | encoding is used whenever Tcl passes strings to system calls. http://www.tcl.tk/man/tcl8.4/TclCmd/encoding.htm I'll see if I can find out about some other languages if there continues to be any interest.
"Proper encoding"? If you said, "Proper default encoding" I'd agree with you. And I'd buy your claim if no one had ever invented output redirection and if print output always went to a console with a (relatively) fixed encoding. But that is not the case.
How exactly do you suggest one accurately quantify "commonness"? And what is the threshold for justification? It seems to me the strongest argument is the credibility one that I already made: 1) Programs that accept data input on stdin and write data on stdout have a long history and are widely used. I hope this is self evident. 2) Encodings other than utf-8 are widely used. I pointed to the commonness of non-utf8 encoding in Japanese web pages. Additionally, Google for "ftp readme の site:.jp" turns up lots of text files. Once past the first few pages of Google results (where the web pages are mostly utf8) hardly any utf8 files are to be found. 3) An effect of globalization means that many more programmers today are dealing with files that have non-native encoding that come from or go to customers, vendors, partners and colleagues in other parts of the world. The number of encodings in wide use even within a single country (again Japan: utf8, sjis, euc-jp, iso202jp) implies pretty strongly that tools for use only in that region will often need multi-encoding capabilities. I think connecting the dots above leads to a pretty high-probability conclusion.
iconv, recode and their ilk are obvious examples of applications.
Did you miss the paragraph right below the one you quote? The one in which I said,

On Fri, Jun 8, 2012 at 11:39 PM, Rurpy <rurpy@yahoo.com> wrote:
On 06/07/2012 03:00 PM, Mike Meyer wrote:
On Thu, Jun 7, 2012 at 4:48 PM, Rurpy <rurpy-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
how do other programming languages deal with wanting to change the encoding of the standard IO streams?
This is how it seems to be done in Perl:
binmode(STDOUT, ":encoding(sjis)");
which seems quite a bit simpler than Python.
Agreed, in isolation. But in my limited experience, and from reading http://perldoc.perl.org/functions/binmode.html ... I think you probably need to hold at least as many concepts in your head simultaneously to get it to work.
which sort of belies simple
TCL appears to have on-the-fly encoding changes:
So if you call rename, the system encoding is used for the filename, but does that mean it is used for sysout? -jJ

On Fri, Jun 8, 2012 at 11:39 PM, Rurpy <rurpy@yahoo.com> wrote:
On 06/07/2012 03:00 PM, Mike Meyer wrote:
On Thu, Jun 7, 2012 at 4:48 PM, Rurpy <rurpy-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:
how do other programming languages deal with wanting to change the encoding of the standard IO streams?
This is how it seems to be done in Perl:
binmode(STDOUT, ":encoding(sjis)");
which seems quite a bit simpler than Python.
Agreed, in isolation. But in my limited experience, and from reading http://perldoc.perl.org/functions/binmode.html ... I think you probably need to hold at least as many concepts in your head simultaneously to get it to work.
which sort of belies simple
TCL appears to have on-the-fly encoding changes:
So if you call rename, the system encoding is used for the filename, but does that mean it is used for sysout? -jJ
participants (2)
-
Jim Jewett
-
Rurpy