[issue24739] allow argparse.FileType to accept newline argument

paul j3 report at bugs.python.org
Mon Aug 3 19:03:35 CEST 2015


paul j3 added the comment:

argparse.FileType serves 2 purposes

- handling filenames for simple quick shell-like scripts

- as a model for custom 'types', specifically one that uses a class to generate the desired type callable.

Other bug-issues show that it hasn't aged well.  It doesn't work nicely with the newer open/close context paradigm.  It needs changes to handle 'rb' and 'wb' modes.

I suppose it could be modified to accept the full range of parameters that the modern 'open' takes:

    open(file, mode='r', buffering=-1, encoding=None,
        errors=None, newline=None, closefd=True, opener=None) 

either explicitly, or as a pass through **kwargs.

But it is also something that you could easily subclass or modify for your own purposes.

Or just accept the filenames as strings, and do your own open/close after parsing.  This gives you more control over when and how the files are opened.

----------
nosy: +paul.j3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24739>
_______________________________________


More information about the Python-bugs-list mailing list