You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Please add argument to override stdin/out/err in the input builtin #75784
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2017-09-27.06:34:07.094>labels= ['3.7', 'expert-IO']
title='Please add argument to override stdin/out/err in the input builtin'updated_at=<Date2022-01-20.18:29:21.436>user='https://github.com/wt'
This would certainly make overriding the the files in specific calls to input easier. A reasonable use case is collecting a piece over /dev/tty explicitly so that a redirected stdin could be used to pipe data into a program while overriding using /dev/tty to collect some piece of data. Here's some code illustrating what I'd like:
FWIW, I have actually already implemented this fully (including tests). I am just trying to see what I need to do to allow release since I am work on my employer's time.
In the interest of getting feedback, does the signature provided above look sane?
This is probably a topic for the python-ideas mailing list. For example, rather than complicating input, it might be better to propose adding a redirect_stdin to contextlib to parallel the two existing redirect context managers. I don't remember why that was not added when the others were, but there was probably a reason, so a discussion about what the best solution is for the use case is in order, and python-ideas is the place for that.
I'm not sure that I ever got a definitive issue, but I didn't have time to
push it forward. I still think the idea has merit. I'd love to see it
implemented, but I don't have the time to pursue it right now.
Activity
wt commentedon Sep 27, 2017
I would really love to add a few params to input so that it's signature looked more like so:
This would certainly make overriding the the files in specific calls to input easier. A reasonable use case is collecting a piece over /dev/tty explicitly so that a redirected stdin could be used to pipe data into a program while overriding using /dev/tty to collect some piece of data. Here's some code illustrating what I'd like:
FWIW, I have actually already implemented this fully (including tests). I am just trying to see what I need to do to allow release since I am work on my employer's time.
In the interest of getting feedback, does the signature provided above look sane?
wt commentedon Sep 27, 2017
This might also allow simplification of the getpass.unix_getpass() logic. I am not 100% sure about that yet though.
bitdancer commentedon Sep 27, 2017
This is probably a topic for the python-ideas mailing list. For example, rather than complicating input, it might be better to propose adding a redirect_stdin to contextlib to parallel the two existing redirect context managers. I don't remember why that was not added when the others were, but there was probably a reason, so a discussion about what the best solution is for the use case is in order, and python-ideas is the place for that.
serhiy-storchaka commentedon Sep 27, 2017
input() is a convenient function for simple user interaction. If you need to read a data from different file object just use its readline() method.
wt commentedon Sep 29, 2017
Added a PR to facilitate discussion on python-ideas.
csabella commentedon Mar 18, 2019
For reference, here's the link to the Python ideas thread:
https://mail.python.org/pipermail/python-ideas/2017-September/047230.html
tonybaloney commentedon May 6, 2019
The discussion on python-ideas has some unresolved questions. Wren, did you get a definitive answer on this idea?
iritkatriel commentedon Jan 17, 2022
See also bpo-1927.
wt commentedon Jan 20, 2022
I'm not sure that I ever got a definitive issue, but I didn't have time to
push it forward. I still think the idea has merit. I'd love to see it
implemented, but I don't have the time to pursue it right now.
Thanks,
wt
On Mon, Jan 17, 2022 at 10:23 AM Irit Katriel <report@bugs.python.org>
wrote:
iritkatriel commentedon Oct 29, 2022
Thank you.