This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2015年07月28日 02:08 by garyp, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 850 | closed | iamalbert, 2017年03月27日 17:09 | |
| Messages (5) | |||
|---|---|---|---|
| msg247497 - (view) | Author: Gary Peck (garyp) | Date: 2015年07月28日 02:08 | |
argparse.FileType should support a "newline" argument that corresponds to the "newline" parameter to open(). In addition to more closely mirroring the open() API, this is also needed to properly use argparse.FileType with csv.reader() or csv.writer() (which require the file being passed in to have been opened with newline=''). |
|||
| msg247939 - (view) | Author: paul j3 (paul.j3) * (Python triager) | Date: 2015年08月03日 17:03 | |
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. |
|||
| msg291941 - (view) | Author: Berker Peksag (berker.peksag) * (Python committer) | Date: 2017年04月20日 04:11 | |
I agree with paul j3. It would be nice to keep the current FileType API as is. The argparse documentation already encourages people to write their own custom types and I think this is a good use case for following the advice. Thanks for the report! |
|||
| msg404959 - (view) | Author: Mitar (mitar) * | Date: 2021年10月25日 11:08 | |
I think the issue is that it is hard to subclass it. Ideally, call to open would be made through a new _open method which would then call it, and one could easily subclass that method if/when needed. |
|||
| msg404977 - (view) | Author: paul j3 (paul.j3) * (Python triager) | Date: 2021年10月25日 16:12 | |
Adding `newline` to `FileType` requires modifying both the `__init__` and `__call__` methods. That's nearly the whole class. I'd copy and edit, and forget about subclassing. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:19 | admin | set | github: 68927 |
| 2021年10月25日 16:12:12 | paul.j3 | set | messages: + msg404977 |
| 2021年10月25日 11:08:34 | mitar | set | nosy:
+ mitar messages: + msg404959 |
| 2017年04月20日 04:11:59 | berker.peksag | set | status: open -> closed versions: + Python 3.7, - Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6 nosy: + berker.peksag messages: + msg291941 resolution: rejected stage: resolved |
| 2017年03月27日 17:09:26 | iamalbert | set | pull_requests: + pull_request750 |
| 2015年08月03日 17:03:35 | paul.j3 | set | nosy:
+ paul.j3 messages: + msg247939 |
| 2015年07月28日 02:08:44 | garyp | create | |