
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2014-03-27 13:42 bybrandon-rhodes, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| 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 iscoming from stdin or from a list of files on the command line. But ifinput(mode='rb') is specified, then its behavior becomes inconsistent:lines from stdin are delivered as already-decoded strings, but datafrom 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 fromstdin.Otherwise the "rb" mode is rather useless since you can windup getting text from it anyway depending on how you are invoked. | |||
| msg215001 -(view) | Author: Josh Rosenberg (josh.r)*![]() | 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)![]() | Date: 2014-05-14 18:12 | |
New changeset7e640fefc9c1 by Serhiy Storchaka in branch '3.4':Issue#21075: fileinput.FileInput now reads bytes from standard stream ifhttp://hg.python.org/cpython/rev/7e640fefc9c1New changeset4041d4077a85 by Serhiy Storchaka in branch 'default':Issue#21075: fileinput.FileInput now reads bytes from standard stream ifhttp://hg.python.org/cpython/rev/4041d4077a85 | |||
| msg218559 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2014-05-14 18:17 | |
Thank you Sam for your contribution. | |||
| msg257362 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2016-01-02 20:45 | |
New changesetded1336bff49 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 | |