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 2014年03月27日 13:42 by brandon-rhodes, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| 21075-fileinput-stdin.diff | sam.kimbrel, 2014年04月15日 16:37 | review | ||
| Messages (6) | |||
|---|---|---|---|
| msg214952 - (view) | Author: Brandon Rhodes (brandon-rhodes) * | Date: 2014年03月27日 13:42 | |
In Python 3, fileinput.input() returns str lines whether the data is coming from stdin or from a list of files on the command line. But if input(mode='rb') is specified, then its behavior becomes inconsistent: lines from stdin are delivered as already-decoded strings, but data from files is delivered (correctly) as bytes. The solution may be that, if a "b" is anywhere in the mode, then input() should read from the bytes stdin.buffer data source instead of from stdin. Otherwise the "rb" mode is rather useless since you can wind up getting text from it anyway depending on how you are invoked. |
|||
| msg215001 - (view) | Author: Josh Rosenberg (josh.r) * (Python triager) | Date: 2014年03月27日 23:26 | |
There is a similar, (unfixed?) bug, #14156, in argparse as well. Seems like a common failing in the move to Python 3; std*.buffer was introduced, but none of the places that use it were updated, so they all became str only. |
|||
| msg216331 - (view) | Author: Sam Kimbrel (sam.kimbrel) * | Date: 2014年04月15日 16:37 | |
Patch attached that checks for 'b' in self._mode and sets self._file to sys.stdin.buffer as appropriate. |
|||
| msg218558 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2014年05月14日 18:12 | |
New changeset 7e640fefc9c1 by Serhiy Storchaka in branch '3.4': Issue #21075: fileinput.FileInput now reads bytes from standard stream if http://hg.python.org/cpython/rev/7e640fefc9c1 New changeset 4041d4077a85 by Serhiy Storchaka in branch 'default': Issue #21075: fileinput.FileInput now reads bytes from standard stream if http://hg.python.org/cpython/rev/4041d4077a85 |
|||
| msg218559 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年05月14日 18:17 | |
Thank you Sam for your contribution. |
|||
| msg257362 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2016年01月02日 20:45 | |
New changeset ded1336bff49 by R David Murray in branch '3.5': #22709: Use stdin as-is if it does not have a buffer attribute. https://hg.python.org/cpython/rev/ded1336bff49 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:00 | admin | set | github: 65274 |
| 2016年01月02日 20:45:09 | python-dev | set | messages: + msg257362 |
| 2014年05月14日 18:17:41 | serhiy.storchaka | set | status: open -> closed versions: + Python 3.3 messages: + msg218559 resolution: fixed stage: resolved |
| 2014年05月14日 18:12:34 | python-dev | set | nosy:
+ python-dev messages: + msg218558 |
| 2014年05月14日 17:27:41 | serhiy.storchaka | set | assignee: serhiy.storchaka nosy: + serhiy.storchaka |
| 2014年04月16日 06:44:30 | vstinner | set | nosy:
+ vstinner |
| 2014年04月15日 16:37:44 | sam.kimbrel | set | files:
+ 21075-fileinput-stdin.diff nosy: + sam.kimbrel messages: + msg216331 keywords: + patch |
| 2014年03月27日 23:26:29 | josh.r | set | nosy:
+ josh.r messages: + msg215001 |
| 2014年03月27日 13:42:43 | brandon-rhodes | create | |