<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="" dir="ltr">
<div id="divtagdefaultwrapper" style="" dir="ltr">
<p style="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; font-size: 12pt;">
Steven and Amit,</p>
<p style="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; font-size: 12pt;">
<br>
</p>
<p style="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; font-size: 12pt;">
I originally configured the mailing list for digest delivery and can't reply directly to his message. However, I now seen it, I will update the PR with the suggested name changes as soon as my "make test" finishes. FWIW,<span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;"> I've
 changed to direct message delivery.</span></p>
<p style="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; font-size: 12pt;">
<span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;"><br>
</span></p>
<p style="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; font-size: 12pt;">
With regard to ferr (the corresponding variable in the builtin_input c function before the change), I saw this code:</p>
<p style="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; font-size: 12pt;">
<br>
</p>
<p style="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; font-size: 12pt;">
</p>
<div style="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; font-size: 12pt;">
<span style="font-family: Consolas, Courier, monospace;">    /* First of all, flush stderr */</span></div>
<div style="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; font-size: 12pt;">
<span style="font-family: Consolas, Courier, monospace;">    tmp = _PyObject_CallMethodId(ferr, &PyId_flush, NULL);</span></div>
<div style="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; font-size: 12pt;">
<span style="font-family: Consolas, Courier, monospace;">    if (tmp == NULL)</span></div>
<div style="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; font-size: 12pt;">
<span style="font-family: Consolas, Courier, monospace;">        PyErr_Clear();</span></div>
<div style="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; font-size: 12pt;">
<span style="font-family: Consolas, Courier, monospace;">    else</span></div>
<div style="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; font-size: 12pt;">
<span style="font-family: Consolas, Courier, monospace;">        Py_DECREF(tmp);</span></div>
<br>
<p style="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; font-size: 12pt;">
</p>
<p style="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; font-size: 12pt;">
And I assumed that it was important to be able to override a stderr as a result.</p>
<p style="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; font-size: 12pt;">
<br>
</p>
<p style="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; font-size: 12pt;">
I think there are few options here to resolve that:</p>
<p style=""></p>
<ol style="margin-bottom: 0px; margin-top: 0px;">
<li style="">Remove the errfile parameter and just do what happened before.</li><li style="">Remove the errfile and the above code (FWIW, I am not sure I understand the importance of flushing stderr before taking input).</li><li style="">Document the explicit purpose of the errfile. Amit, you'd responded with something about this (again digest reply, sorry). I am not sure how to concisely do that given Amit's descriptions.
<span>😊</span></li></ol>
<div><br>
</div>
<div>I am honestly leaning toward 2 unless I can figure out why the flushing of stderr is actually needed.</div>
<p></p>
<p style="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; font-size: 12pt;">
<br>
</p>
<p style="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; font-size: 12pt;">
<span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">wt</span></p>
<p style="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; font-size: 12pt;">
<span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;"><br>
</span></p>
</div>
<hr style="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; font-size: 12pt; display: inline-block; width: 98%;" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr" style="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; font-size: 12pt;">
<font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Amit Green <amit.mixie@gmail.com><br>
<b>Sent:</b> Friday, September 29, 2017 8:13:21 AM<br>
<b>To:</b> Wren Turkal<br>
<b>Cc:</b> python-ideas@python.org<br>
<b>Subject:</b> Re: [Python-ideas] allow overriding files used for the input builtin</font>
<div> </div>
</div>
<div style="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; font-size: 12pt;">
<div dir="ltr">
<div>
<div>
<div>Yes, infile, outfile & errfile would be consistent with python naming convention (also mentioned by Steven D'Aprano above)<br>
<br>
</div>
One of python's greatest strength is its library, the consistency of the library, and how well documented the library is (in fact, I think the library is a greater strength than even the very nice syntax of python in general).<br>
<br>
</div>
By "consistency of the library" I mean: functions do pretty much what you expect, they use consistent error mechanism & the documentation pretty much accurately documents what the function does -- especially as to showing its results & how it handles errors.<br>
<br>
</div>
Regarding this though, this then brings up the question (above from Steven D'Aprano) -- what would the the "errfile" parameter do?<br>
<ul>
<li>As a general principle of consistency python library functions, and python itself, do not output to errfile, but instead throw errors.</li><li>(There are very minor exceptions such as exceptions thrown in __del__ functions; which are caught by python & then printed to standard error).</li></ul>
<p>I would thus think you don't want the errfile parameter -- unless it would be for catching these __del__ method that get triggered by input failing (for example your 'infile' parameter when called, allocated an object, which gets deallocated & throws an
 exception inside of its __del__ method).</p>
<p>If this is the purpose, then (back to 'how well documented the library is') -- it should be documented this is the purpose of the "errfile" parameter ;-)</p>
<p>[A secondary reason you might want to redirect "errfile" is that the passed in input or output file's, themselves do output to standard error ...]<br>
</p>
<p><br>
</p>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Sep 29, 2017 at 10:50 AM, Wren Turkal <span dir="ltr">
<<a href="mailto:w00t@fb.com" target="_blank">w00t@fb.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div id="m_-348553151314392222divtagdefaultwrapper" 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;" dir="ltr">
<p>I am happy to rename the args. What do you think about infile, outfile, and errfile?</p>
<p><br>
</p>
<p>FWIW, I did consider "in", "out", and "err", but "in" is a keyword, and I didn't think those quite captured the full meaning.</p>
<p><br>
</p>
<p>wt</p>
</div>
<hr style="display:inline-block;width:98%">
<div id="m_-348553151314392222divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> Amit Green <<a href="mailto:amit.mixie@gmail.com" target="_blank">amit.mixie@gmail.com</a>><br>
<b>Sent:</b> Thursday, September 28, 2017 11:18:18 PM<br>
<b>To:</b> Wren Turkal<br>
<b>Cc:</b> <a href="mailto:python-ideas@python.org" target="_blank">python-ideas@python.org</a><br>
<b>Subject:</b> Re: [Python-ideas] allow overriding files used for the input builtin</font>
<div> </div>
</div>
<div>
<div class="h5">
<div>
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>I'm fine with the idea in general of extra keyword parameters to the input function.<br>
<br>
</div>
A few points:<br>
<br>
</div>
Your example code, needs try/catch to match what the input with parameters does -- and yes, its way nicer to be able to use it the example you have shown than play games with try/catch (Personally I also refuse to ever change sys.stdin, or sys.stdout, as I
 consider that a bad coding style).<br>
<br>
</div>
Mostly though I would like to ask, please do not name keyword arguments with names like 'fin' & 'fout'.  This is almost unreadable and make's code almost indecipherable to others the first time they see the function & its keyword arguments (First impressions
 are very important).<br>
<br>
</div>
Both a function name & its keyword parameters need to be as understandable as possible when a user encounters them for the first time.<br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Sep 29, 2017 at 1:53 AM, Wren Turkal <span dir="ltr">
<<a href="mailto:w00t@fb.com" target="_blank">w00t@fb.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div id="m_-348553151314392222m_-7469814740547824775divtagdefaultwrapper" 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;" 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://urldefense.proofpoint.com/v2/url?u=https-3A__bugs.python.org_issue31603&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=OAN5uLR4JWXbIgcvx315Zw&m=K1-OD0dhslOiAqYQdEyr0Oppl8TaroBPvXr8h_Z8XxM&s=sjDmBcI00MbWPPjuLMPlBnZHoFZOHoTxaCo2KCYlEd4&e=" class="m_-348553151314392222m_-7469814740547824775OWAAutoLink" id="m_-348553151314392222m_-7469814740547824775LPlnk789029" target="_blank">https://bugs.python.org/iss<wbr>ue31603</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="m_-348553151314392222m_-7469814740547824775Signature">
<div id="m_-348553151314392222m_-7469814740547824775divtagdefaultwrapper" 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>
</div>
<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_python-2Dideas&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=OAN5uLR4JWXbIgcvx315Zw&m=K1-OD0dhslOiAqYQdEyr0Oppl8TaroBPvXr8h_Z8XxM&s=dvbtuL0kPe5UxakqosCnQQCIxlKprMP6JTqx4ZLXx4g&e=" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__python.org_psf_codeofconduct_&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=OAN5uLR4JWXbIgcvx315Zw&m=K1-OD0dhslOiAqYQdEyr0Oppl8TaroBPvXr8h_Z8XxM&s=px67QeYtdnaejiTP9VcY5IuSiJ4pk3XEXcbDzZWbsnI&e=" rel="noreferrer" target="_blank">
http://python.org/psf/codeofco<wbr>nduct/</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</body>
</html>