<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Hi there,</p>
<p><br>
</p>
<p>I have posted an idea for improvement with a PR of an implementation to <a href="https://bugs.python.org/issue31603" class="OWAAutoLink" id="LPlnk789029" previewremoved="true">https://bugs.python.org/issue31603</a>.</p>
<p><br>
</p>
<p>The basic idea is to add fin, fout, and ferr file object parameters and default to using what is used today when the args are not specified. I believe this would be useful to allow captures input and send output to specific files when using input. The input
 builtin has some logic to use readline if it's available. It would be nice to be able to use this same logic no matter what files are being used for input/output.</p>
<p><br>
</p>
<p>This is meant to turn code like the following:</p>
<p><span style="font-family: Consolas, Courier, monospace;">orig_stdin </span><span style="font-family: Consolas, Courier, monospace;">= sys.stdin</span></p>
<p><span style="font-family: Consolas, Courier, monospace;">orig_stdout = sys.stdout</span></p>
<p><span style="font-family: Consolas, Courier, monospace;">with open('/dev/tty', 'r+') as f:</span></p>
<p><span style="font-family: Consolas, Courier, monospace;">    sys.stdin = f</span></p>
<p><span style="font-family: Consolas, Courier, monospace;">    sys.stdout = f</span></p>
<p><span style="font-family: Consolas, Courier, monospace;">    name = </span><span style="font-family: Consolas, Courier, monospace;">input('Name? ')</span></p>
<p><span style="font-family: Consolas, Courier, monospace;">sys.stdin = orig_stdin</span></p>
<p><span style="font-family: Consolas, Courier, monospace;">sys.stdout = orig_stdout</span></p>
<p><span style="font-family: Consolas, Courier, monospace;">print(name)</span></p>
<p><br>
</p>
<p>into something more like this:</p>
<p><span style="font-family: Consolas, Courier, monospace;">with open('/dev/tty', 'r+') as f:</span></p>
<p><span style="font-family: Consolas, Courier, monospace;">    name = input('Name? ', fin=f, fout=f)</span></p>
<p><span style="font-family: Consolas, Courier, monospace;">print(name)</span></p>
<p><br>
</p>
<p>It's nice that it makes the assignment to a global variable to change the file used for input/output to no longer be needed.</p>
<p><br>
</p>
<p>I had this idea the other day, and I realized that it would be super easy to implement, so I went ahead the threw up a PR also.</p>
<p><br>
</p>
<p>Would love to see if anyone else is interested in this. I think it's pretty cool that the core logic really didn't need to be changed other than plumbing in the new args.</p>
<p><br>
</p>
<p>FWIW, this change introduces no regressions and adds a few more tests to test the new functionality. Honestly, I think this functionality could probably be used to simplify some of the other tests as well, but I wanted to gauge what folks thought of the
 change before going farther.</p>
<p><br>
</p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<p>Wren Turkal</p>
<p>Existential Production Engineer of the Ages</p>
<p>Facebook, Inc.</p>
</div>
</div>
</div>
</body>
</html>