Akira Li added the comment: > This is not related to Python. Terms "character", "string", "text", "file" > can have different meaning in different domains. In Python we use Python > terminology. There is no such thing as sys.stdin in Posix-compatible shell, > because Posix-compatible shell has no the sys module and doesn't use a dot to > access attributes.
I use Python terminology (text - Unicode string, binary data - bytes). Though text vs. binary data distinction is language independent ( it doesn't matter how Unicode type is called in a particular language). Python can be used to implement `tar`, `gpg`, `ssh`, `7z`, etc. I don't see what POSIX has anything to do with that fact. It is very simple actually: text -> encode <character encoding> -> bytes bytes -> decode <character encoding> -> text In most cases text should be human readable. It doesn't make sense to encode/decode input/output of gpg-like utilities using a character encoding. *Therefore* the notion of sys.stdin being a bytes stream (io.BufferedReader) can be useful in this case. The lines produced by FileInput are often (after optional processing) written to sys.stdout. If binary mode is used then FileInput(mode='rb') yields bytes therefore it is also useful to consider sys.stdout a binary stream (io.BufferedWriter) in this case. It introduces a nice symmetry: text FileInput mode -> text streams binary FileInput mode -> binary streams By design, FileInput treats stdin as any other file. It even supports a special name for it: '-'. A file may be in binary mode; stdin should be able too. sys.stdout is used outside of FileInput therefore no changes in FileInput itself are necessary but sys.stdin is used inside FileInput that is why the change is needed. > Correct solution in this case would be to use the workaround "sys.stdin = sys.stdin.detach()" conditionally, only in Python versions which have a bug. Do you mean every Python 3 version before Python 3.4.1? Correct solution is to avoid blaming users (your fault -> you change your programs) for our mistakes and fix the bug in Python itself. The patch is attached. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22709> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com