3 ms·
It seems simple to me - if you want bytes, open the file in binary mode, if you want strings open it in text mode. The only glitch is with stdin/stdout. They'r
by mark-r 11y ago
It seems simple to me - if you want bytes, open the file in binary mode, if you want strings open it in text mode.
The only glitch is with stdin/stdout. They're opened on your behalf before your program even starts, and the assumption is that you'll be reading and writing text in the default OS encoding. This doesn't mesh well with the Unix pipe paradigm.
- pdonis 11y agoIf you need binary reads/writes for stdin/stdout, you can use the underlying binary buffer objects (the "buffer" attributes on sys.stdin/stdout).