[stdlib-sig] argparse -- binary IO via standard streams

Michael Foord michael at voidspace.org.uk
Tue Jun 5 12:56:01 CEST 2012


On 5 Jun 2012, at 11:18, Moritz Klammler wrote:

> Hello,
> 
> in Python 3, this is a TypeError:
> 
>>>> sys.stdout.write(b"hello, world\n")
> 
> At the moment, argparse.FileType.__call__("-") unconditionally returns
> sys.stdout even if mode is binary so writing binary data will fail if
> the user selects to write it to stdout.
> 
> I'm not sure if this is the best possible solution but at least the
> following patch to argparse.py would fix the aforementioned problem.


Please post patches to the bug tracker so they don't get lost.

http://bugs.python.org

All the best,

Michael Foord

> 
> Moritz
> 
> 
> 1154c1154,1157
> <                 return _sys.stdin
> ---
>>                if 'b' in self._mode:
>>                    return _sys.stdin.buffer
>>                else:
>>                    return _sys.stdin
> 1156c1159,1162
> <                 return _sys.stdout
> ---
>>                if 'b' in self._mode:
>>                    return _sys.stdout.buffer
>>                else:
>>                    return _sys.stdout
> 
> -- 
> Fingerprint:  80C1 EC79 B554 3D84 0A35 A728 7057 B288 CE61 2235
> Public key:   http://openpgp.klammler.eu
> _______________________________________________
> stdlib-sig mailing list
> stdlib-sig at python.org
> http://mail.python.org/mailman/listinfo/stdlib-sig


--
http://www.voidspace.org.uk/


May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing 
http://www.sqlite.org/different.html







More information about the stdlib-sig mailing list