Make os.pipe() return a namedtuple.

Could we do that? Is there is reason it's not already a namedtuple? I always forget what the read-end and what the write-end of the pipe is, and I use it quite regularly. Jonathan

On 29Jun2015 16:51, Jonathan Slenders <jonathan@slenders.be> wrote:
The ordering is the same as for the default process file descriptors. A normal process has stdin as fd 0 and stdout as fd 1. So the return from pipe() has the read end as index 0 and the write end as fd 1. Cheers, Cameron Simpson <cs@zip.com.au>

On Tue, Jun 30, 2015 at 10:12:42AM +1000, Cameron Simpson wrote:
Yeah, I always forget which is fd 0 and which is fd 1 too. Having nice descriptive names rather than using numbered indexes is generally better practice, and I don't think there is any serious downside to using a namedtuple. A minor enhancement like this shouldn't require an extended discussion here on python-ideas. Jonathan, would you be so kind as to raise an enhancement request on the bug tracker? I don't think it's too late for 3.5. -- Steve

On Mon, Jun 29, 2015 at 8:50 PM, Steven D'Aprano <steve@pearwood.info> wrote:
Jonathan, would you be so kind as to raise an enhancement request on the bug tracker? I don't think it's too late for 3.5.
3.5 is feature-frozen without a special exemption from Larry Hastings, and I think the window for those is already past too. 3.6 is open for development already, though. -- Zach

On 30Jun2015 11:50, Steven D'Aprano <steve@pearwood.info> wrote:
Shrug. I use the rationale above. stdin==0 is extremely easy to remember. However, I have no cogent objection to a named tuple myself.
But... what shall we call the attributes? Sure an extended bikeshed is required here:-) Cheers, Cameron Simpson <cs@zip.com.au> I will be a speed bump on the information super-highway. - jvogel@math.rutgers.edu (jeff vogel)

Steven D'Aprano <steve@pearwood.info> writes:
I definitely prefer to use, and promote, the explicit names “stdin”, “stdout”, and “stderr” rather than the file descriptor numbers. On the point of confusing them though: I find it easy enough to remember that the two streams for output stay together, and the input one comes first at 0.
+1, let's just get the standard names there as attributes of a namedtuple. One more set of magic numbers to relegate to implementation detail, encapsulated where they belong! -- \ Fry: “Take that, poor people!” Leela: “But Fry, you’re not | `\ rich.” Fry: “No, but I will be someday, and then people like | _o__) me better watch out!” —Futurama | Ben Finney

On Tue, Jun 30, 2015 at 12:10 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
Except that this isn't about stdin/stdout - that just happens to make a neat mnemonic. This is about a pipe, which has a reading end and a writing end. If you pass one of those to another process to use as its stdout, you'll be reading from the reading end; calling it "stdin" would be confusing, since you're getting what the process wrote to stdout. How about just "read" and "write"? Yep, Cameron was right... ChrisA

If we use "read" and write as names. It means that often we end up writing code like this: os.write(our_pipe.write, data) os.read(our_pipe.read) Is that ok? I mean, it's not confusing that the os.read is a method, while pip.read is an attribute. Jonathan 2015-06-30 8:07 GMT+02:00 Cameron Simpson <cs@zip.com.au>:

On Tue, Jun 30, 2015 at 12:03 AM, Chris Angelico <rosuav@gmail.com> wrote:
It also appears to be the way that everyone is already naming their variables: https://codesearch.debian.net/perpackage-results/os%5C.pipe%20filetype%3Apyt... I see returns named "r, w", "rout, wout", "rfd, wfd", "rfd, self.writepipe", "readfd, writefd", "p2cread, p2cwrite", etc. Maybe readfd/writefd or read_fileno/write_fileno would be a little better than plain read/write, both to remind the user that these are fds rather than file objects and to make the names nouns instead of verbs. But really read/write is fine too. -n -- Nathaniel J. Smith -- http://vorpus.org

I created an issue: http://bugs.python.org/issue24536 readfd/writefd sounds like a good choice, but it's still open for discussion. 2015-06-30 9:11 GMT+02:00 Nathaniel Smith <njs@pobox.com>:

On Mon, Jun 29, 2015 at 7:51 AM, Jonathan Slenders <jonathan@slenders.be> wrote:
Sounds like a good idea to me. -n -- Nathaniel J. Smith -- http://vorpus.org

On 29Jun2015 16:51, Jonathan Slenders <jonathan@slenders.be> wrote:
The ordering is the same as for the default process file descriptors. A normal process has stdin as fd 0 and stdout as fd 1. So the return from pipe() has the read end as index 0 and the write end as fd 1. Cheers, Cameron Simpson <cs@zip.com.au>

On Tue, Jun 30, 2015 at 10:12:42AM +1000, Cameron Simpson wrote:
Yeah, I always forget which is fd 0 and which is fd 1 too. Having nice descriptive names rather than using numbered indexes is generally better practice, and I don't think there is any serious downside to using a namedtuple. A minor enhancement like this shouldn't require an extended discussion here on python-ideas. Jonathan, would you be so kind as to raise an enhancement request on the bug tracker? I don't think it's too late for 3.5. -- Steve

On Mon, Jun 29, 2015 at 8:50 PM, Steven D'Aprano <steve@pearwood.info> wrote:
Jonathan, would you be so kind as to raise an enhancement request on the bug tracker? I don't think it's too late for 3.5.
3.5 is feature-frozen without a special exemption from Larry Hastings, and I think the window for those is already past too. 3.6 is open for development already, though. -- Zach

On 30Jun2015 11:50, Steven D'Aprano <steve@pearwood.info> wrote:
Shrug. I use the rationale above. stdin==0 is extremely easy to remember. However, I have no cogent objection to a named tuple myself.
But... what shall we call the attributes? Sure an extended bikeshed is required here:-) Cheers, Cameron Simpson <cs@zip.com.au> I will be a speed bump on the information super-highway. - jvogel@math.rutgers.edu (jeff vogel)

Steven D'Aprano <steve@pearwood.info> writes:
I definitely prefer to use, and promote, the explicit names “stdin”, “stdout”, and “stderr” rather than the file descriptor numbers. On the point of confusing them though: I find it easy enough to remember that the two streams for output stay together, and the input one comes first at 0.
+1, let's just get the standard names there as attributes of a namedtuple. One more set of magic numbers to relegate to implementation detail, encapsulated where they belong! -- \ Fry: “Take that, poor people!” Leela: “But Fry, you’re not | `\ rich.” Fry: “No, but I will be someday, and then people like | _o__) me better watch out!” —Futurama | Ben Finney

On Tue, Jun 30, 2015 at 12:10 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
Except that this isn't about stdin/stdout - that just happens to make a neat mnemonic. This is about a pipe, which has a reading end and a writing end. If you pass one of those to another process to use as its stdout, you'll be reading from the reading end; calling it "stdin" would be confusing, since you're getting what the process wrote to stdout. How about just "read" and "write"? Yep, Cameron was right... ChrisA

If we use "read" and write as names. It means that often we end up writing code like this: os.write(our_pipe.write, data) os.read(our_pipe.read) Is that ok? I mean, it's not confusing that the os.read is a method, while pip.read is an attribute. Jonathan 2015-06-30 8:07 GMT+02:00 Cameron Simpson <cs@zip.com.au>:

On Tue, Jun 30, 2015 at 12:03 AM, Chris Angelico <rosuav@gmail.com> wrote:
It also appears to be the way that everyone is already naming their variables: https://codesearch.debian.net/perpackage-results/os%5C.pipe%20filetype%3Apyt... I see returns named "r, w", "rout, wout", "rfd, wfd", "rfd, self.writepipe", "readfd, writefd", "p2cread, p2cwrite", etc. Maybe readfd/writefd or read_fileno/write_fileno would be a little better than plain read/write, both to remind the user that these are fds rather than file objects and to make the names nouns instead of verbs. But really read/write is fine too. -n -- Nathaniel J. Smith -- http://vorpus.org

I created an issue: http://bugs.python.org/issue24536 readfd/writefd sounds like a good choice, but it's still open for discussion. 2015-06-30 9:11 GMT+02:00 Nathaniel Smith <njs@pobox.com>:

On 30.06.2015 09:07, Cameron Simpson wrote:
+1 for "read" and "write" for me. And -1 on "stdin" and "stdout" for the same reason as outlined above.
This is common found code: if not hasattr(src, 'read'): src = open(src) same for write. I think read_fd and write_fd is better. Niki

On Mon, Jun 29, 2015 at 7:51 AM, Jonathan Slenders <jonathan@slenders.be> wrote:
Sounds like a good idea to me. -n -- Nathaniel J. Smith -- http://vorpus.org
participants (9)
-
Ben Finney
-
Cameron Simpson
-
Chris Angelico
-
Jonathan Slenders
-
Joseph Jevnik
-
Nathaniel Smith
-
Niki Spahiev
-
Steven D'Aprano
-
Zachary Ware