From steve at pearwood.info Thu Jan 1 00:14:19 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 1 Jan 2015 10:14:19 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> Message-ID: <20141231231419.GG24472@ando.pearwood.info> On Wed, Dec 31, 2014 at 11:50:04AM +0100, Andrew Barnert wrote: > On Dec 31, 2014, at 0:47, Steven D'Aprano wrote: > > What's wrong with asking the Finder to move the file? Under what > > circumstances would that be unacceptable? Are there scenarios on OS X > > where the Finder isn't available but the trash is? > > I already answered this briefly earlier in the thread, but in more detail: [...] Thank you for the detailed and extensive answer! -- Steven From ram at rachum.com Thu Jan 1 11:37:55 2015 From: ram at rachum.com (Ram Rachum) Date: Thu, 1 Jan 2015 12:37:55 +0200 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20141231231419.GG24472@ando.pearwood.info> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> Message-ID: Hi everyone, I'm a complete ignoramus when it comes to Mac, so I can't say anything about that, but as I understand the discussion, there are problems with implementing this on Mac. Okay. So maybe this should be available only on Windows and Linux? (If it's not a problem to do on Linux.) As much as I don't like having functionality that's only available on certain OSs, it makes more sense than depriving Windows users of functionality that they could be using just because Mac doesn't support it. (And of course, Python has lots of OS-specific modules.) So maybe we can add a function to the `os` module that sends a file to the recycle bin, and a constant that will say whether the current OS supports this? Then we could have code like this: if os.RECYCLE_BIN_SUPPORT: os.recycle(my_file) else: os.remove(my_file) What do you think? Thanks, Ram. On Thu, Jan 1, 2015 at 1:14 AM, Steven D'Aprano wrote: > On Wed, Dec 31, 2014 at 11:50:04AM +0100, Andrew Barnert wrote: > > On Dec 31, 2014, at 0:47, Steven D'Aprano wrote: > > > > What's wrong with asking the Finder to move the file? Under what > > > circumstances would that be unacceptable? Are there scenarios on OS X > > > where the Finder isn't available but the trash is? > > > > I already answered this briefly earlier in the thread, but in more > detail: > [...] > > Thank you for the detailed and extensive answer! > > > -- > Steven > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Jan 1 11:46:37 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Jan 2015 21:46:37 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> Message-ID: On Thu, Jan 1, 2015 at 9:37 PM, Ram Rachum wrote: > As much as I don't like having functionality that's only available on > certain OSs, it makes more sense than depriving Windows users of > functionality that they could be using just because Mac doesn't support it. > (And of course, Python has lots of OS-specific modules.) Most OS-specific stuff is in the os module, but path handling is inherently platform-specific to some extent, so either place would be reasonable. > So maybe we can add a function to the `os` module that sends a file to the > recycle bin, and a constant that will say whether the current OS supports > this? Then we could have code like this: > > if os.RECYCLE_BIN_SUPPORT: > os.recycle(my_file) > else: > os.remove(my_file) > > What do you think? Or: try: delete = os.recycle except AttributeError: delete = os.remove delete(my_file) ChrisA From steve at pearwood.info Thu Jan 1 13:35:26 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 1 Jan 2015 23:35:26 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> Message-ID: <20150101123526.GC15262@ando.pearwood.info> On Thu, Jan 01, 2015 at 12:37:55PM +0200, Ram Rachum wrote: > So maybe we can add a function to the `os` module that sends a file to the > recycle bin, and a constant that will say whether the current OS supports > this? Then we could have code like this: The os module is for low-level operating-system functions. "Send to trash" is neither low-level nor part of the OS per se, it is part of the desktop environment. I'm not convinced that this needs to be in the standard library, but if it is, I think that the os module is completely the wrong place for it. I think, in order of preference: 1) shutil 2) pathlib is the right place. (The actual implementation for the move_to_trash function could come from another, platform-specific, module.) > if os.RECYCLE_BIN_SUPPORT: > os.recycle(my_file) > else: > os.remove(my_file) "Recycle" is not a good name for the function, because it doesn't recycle the file. It does the opposite of recycle: it prevents the file from being deleted and over-written. I think an explicit name like move_to_trash is better than something misleading like "recycle". No need for a special flag to check if the function exists, just check for the function: try: f = shutil.send_to_trash except AttributeError: f = os.remove f(my_file) But I'm still not sure that this needs to be in the standard library. For such a specialist need, what's wrong with using a third party solution? -- Steven From ram at rachum.com Thu Jan 1 13:43:09 2015 From: ram at rachum.com (Ram Rachum) Date: Thu, 1 Jan 2015 14:43:09 +0200 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150101123526.GC15262@ando.pearwood.info> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> <20150101123526.GC15262@ando.pearwood.info> Message-ID: I take your point about it not being in the `os` module, I have no issue with it being in shutil or pathlib. I also agree about the name, "recycle" doesn't really make sense. Regarding your question: "But I'm still not sure that this needs to be in the standard library. For such a specialist need, what's wrong with using a third party solution?" Well, I can use a third-party solution for everything, but it would be nicer for me if it was in the standard library because then I could count on it always being there and the API not changing. I could say the same thing you said about the `webbrowser` module, that opening a new browser tab is quite a specialist need, but I do enjoy having it available in the standard library and I feel the same about sending a file to trash, which I think is a basic feature that's we've all been taking for granted for the last decade or two. Happy new year, Ram. On Thu, Jan 1, 2015 at 2:35 PM, Steven D'Aprano wrote: > On Thu, Jan 01, 2015 at 12:37:55PM +0200, Ram Rachum wrote: > > > So maybe we can add a function to the `os` module that sends a file to > the > > recycle bin, and a constant that will say whether the current OS supports > > this? Then we could have code like this: > > The os module is for low-level operating-system functions. "Send to > trash" is neither low-level nor part of the OS per se, it is part of the > desktop environment. > > I'm not convinced that this needs to be in the standard library, but if > it is, I think that the os module is completely the wrong place for it. > I think, in order of preference: > > 1) shutil > 2) pathlib > > is the right place. > > (The actual implementation for the move_to_trash function could come > from another, platform-specific, module.) > > > > if os.RECYCLE_BIN_SUPPORT: > > os.recycle(my_file) > > else: > > os.remove(my_file) > > > "Recycle" is not a good name for the function, because it doesn't > recycle the file. It does the opposite of recycle: it prevents the file > from being deleted and over-written. I think an explicit name like > move_to_trash is better than something misleading like "recycle". > > No need for a special flag to check if the function exists, just check > for the function: > > try: > f = shutil.send_to_trash > except AttributeError: > f = os.remove > f(my_file) > > > But I'm still not sure that this needs to be in the standard library. > For such a specialist need, what's wrong with using a third party > solution? > > > -- > Steven > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From liam.marsh.home at gmail.com Thu Jan 1 13:47:54 2015 From: liam.marsh.home at gmail.com (Liam Marsh) Date: Thu, 1 Jan 2015 13:47:54 +0100 Subject: [Python-ideas] pep 397 In-Reply-To: References: Message-ID: "I suspect you don't need any changes to the language to make this work" - you are right, this problem does not affect the language itself, but the idlelib library.... - I was thinking of an "pyidle" executable next to the "py" and "pyw" executables. I am also trying to create a small script to do this... 2014-12-30 23:38 GMT+01:00 Chris Angelico : > On Wed, Dec 31, 2014 at 7:31 AM, Liam Marsh > wrote: > > the pep 397 says that any python script is able to choose the language > > version which will run it, between all the versions installed on the > > computer, using on windows a launcher in the "C:\windows" folder. > > > > can the idle version be chosen like this too, or can the idle "run" > command > > do it? > > I don't know of a way off-hand. However, if the information is already > there in the shebang (as per PEP 397), it ought to be possible to rig > up a launcher/chooser script. This might be something to discuss on > python-list at python.org, rather than here; there are a lot more people > on python-list than there are here on -ideas, and I suspect you don't > need any changes to the language to make this work. > > It's also entirely possible that someone there already knows exactly > what you need to do! > > ChrisA > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From markus at unterwaditzer.net Thu Jan 1 13:47:15 2015 From: markus at unterwaditzer.net (Markus Unterwaditzer) Date: Thu, 1 Jan 2015 13:47:15 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150101123526.GC15262@ando.pearwood.info> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> <20150101123526.GC15262@ando.pearwood.info> Message-ID: <20150101124715.GA7009@chromebot.lan> On Thu, Jan 01, 2015 at 11:35:26PM +1100, Steven D'Aprano wrote: > On Thu, Jan 01, 2015 at 12:37:55PM +0200, Ram Rachum wrote: > > > So maybe we can add a function to the `os` module that sends a file to the > > recycle bin, and a constant that will say whether the current OS supports > > this? Then we could have code like this: > > The os module is for low-level operating-system functions. "Send to > trash" is neither low-level nor part of the OS per se, it is part of the > desktop environment. > > I'm not convinced that this needs to be in the standard library, but if > it is, I think that the os module is completely the wrong place for it. > I think, in order of preference: > > 1) shutil > 2) pathlib > > is the right place. Maybe the right way to do this is to create a new module, stdlib or not, for desktop-related APIs. Besides a `recycle` function this might, for example, include a subset of pyxdg's functionality. -- Markus From rosuav at gmail.com Thu Jan 1 14:27:18 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Jan 2015 00:27:18 +1100 Subject: [Python-ideas] pep 397 In-Reply-To: References: Message-ID: On Thu, Jan 1, 2015 at 11:47 PM, Liam Marsh wrote: > "I suspect you don't > need any changes to the language to make this work" > > - you are right, this problem does not affect the language itself, but the > idlelib library.... > - I was thinking of an "pyidle" executable next to the "py" and "pyw" > executables. > I am also trying to create a small script to do this... A small script ought to be able to handle it. All it needs to do is: 1) Read in the first line of the file. 2) See if it can be parsed according to PEP 397 3) Invoke IDLE. Since this is primarily for your own personal use, rather than being a part of the language or standard library, you could make a few assumptions - for instance, assume an ASCII-compatible file encoding, assume that it won't get any arguments other than the script to open, anything else that'll make your life easier. Knock something together, and if you have trouble with the details, python-list will undoubtedly be willing to help out. All the best! ChrisA From abarnert at yahoo.com Thu Jan 1 16:37:52 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Thu, 1 Jan 2015 16:37:52 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> Message-ID: On Jan 1, 2015, at 11:37, Ram Rachum wrote: > Hi everyone, > > I'm a complete ignoramus when it comes to Mac, so I can't say anything about that, but as I understand the discussion, there are problems with implementing this on Mac. Okay. So maybe this should be available only on Windows and Linux? (If it's not a problem to do on Linux.) On Linux, it's not exactly like Mac, but it's similar. Linux has no notion of trash at all; desktop environments like GNOME do. And if you want it to work exactly like the way GNOME does, you call the API via GObject; otherwise you have to implement a complicated approximation based on rename that won't be fully functional. Really, on all three platforms, the answer is the same: you call an API from your desktop manager. The only difference is that Windows merges desktop and kernel together to the point where they can't be separated--so Python is already using Win32, unlike Cocoa or GObject. > As much as I don't like having functionality that's only available on certain OSs, it makes more sense than depriving Windows users of functionality that they could be using just because Mac doesn't support it. No one is "depriving" Windows users of anything. Python comes with pip, send2trash installs without needing a compiler (at least I hope so; if not, someone can write a new third-party module that does). Not everything needs to be in the stdlib. So far, there aren't many third-party modules mentioned in the stdlib docs, but that's only because we didn't have preinstalled pip, wheels, etc. until 3.4. > (And of course, Python has lots of OS-specific modules.) > > So maybe we can add a function to the `os` module that sends a file to the recycle bin, and a constant that will say whether the current OS supports this? Then we could have code like this: > > if os.RECYCLE_BIN_SUPPORT: > os.recycle(my_file) > else: > os.remove(my_file) > > What do you think? There's no such flag for anything else platform-contingent. EAFP. > > > Thanks, > Ram. > > On Thu, Jan 1, 2015 at 1:14 AM, Steven D'Aprano wrote: >> On Wed, Dec 31, 2014 at 11:50:04AM +0100, Andrew Barnert wrote: >> > On Dec 31, 2014, at 0:47, Steven D'Aprano wrote: >> >> > > What's wrong with asking the Finder to move the file? Under what >> > > circumstances would that be unacceptable? Are there scenarios on OS X >> > > where the Finder isn't available but the trash is? >> > >> > I already answered this briefly earlier in the thread, but in more detail: >> [...] >> >> Thank you for the detailed and extensive answer! >> >> >> -- >> Steven >> _______________________________________________ >> Python-ideas mailing list >> Python-ideas at python.org >> https://mail.python.org/mailman/listinfo/python-ideas >> Code of Conduct: http://python.org/psf/codeofconduct/ > > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From abarnert at yahoo.com Thu Jan 1 16:54:59 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Thu, 1 Jan 2015 16:54:59 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150101124715.GA7009@chromebot.lan> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> <20150101123526.GC15262@ando.pearwood.info> <20150101124715.GA7009@chromebot.lan> Message-ID: <78E3056F-D649-4777-9755-6CBEF5598CA1@yahoo.com> On Jan 1, 2015, at 13:47, Markus Unterwaditzer wrote: > On Thu, Jan 01, 2015 at 11:35:26PM +1100, Steven D'Aprano wrote: >> On Thu, Jan 01, 2015 at 12:37:55PM +0200, Ram Rachum wrote: >> >>> So maybe we can add a function to the `os` module that sends a file to the >>> recycle bin, and a constant that will say whether the current OS supports >>> this? Then we could have code like this: >> >> The os module is for low-level operating-system functions. "Send to >> trash" is neither low-level nor part of the OS per se, it is part of the >> desktop environment. >> >> I'm not convinced that this needs to be in the standard library, but if >> it is, I think that the os module is completely the wrong place for it. >> I think, in order of preference: >> >> 1) shutil >> 2) pathlib >> >> is the right place. > > Maybe the right way to do this is to create a new module, stdlib or not, for > desktop-related APIs. Besides a `recycle` function this might, for example, > include a subset of pyxdg's functionality. That's a great idea. To do something as simple as getting special directory names or creating a shortcut/alias/bookmark (as opposed to a symlink) or, yes, trashing a file in a cross-platform way requires something way too heavy-duty (like Qt or JUCE)... or copying code off some blog (that doesn't actually work on localized Windows or in a sandboxed OS X app or on non-Debianish Linux, but you won't know that until you think to test it). A third-party module can get away with 90% support. Most Mac users are on 10.8+, most apps don't fork, most Linux users who care about the desktop have a GNOME-compatible one; etc. > > -- Markus > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ From markus at unterwaditzer.net Thu Jan 1 17:00:52 2015 From: markus at unterwaditzer.net (Markus Unterwaditzer) Date: Thu, 1 Jan 2015 17:00:52 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> Message-ID: <20150101160052.GA8524@chromebot.lan> On Thu, Jan 01, 2015 at 04:37:52PM +0100, Andrew Barnert wrote: > On Jan 1, 2015, at 11:37, Ram Rachum wrote: > > > Hi everyone, > > > > I'm a complete ignoramus when it comes to Mac, so I can't say anything > > about that, but as I understand the discussion, there are problems with > > implementing this on Mac. Okay. So maybe this should be available only on > > Windows and Linux? (If it's not a problem to do on Linux.) > > On Linux, it's not exactly like Mac, but it's similar. Linux has no notion of > trash at all; desktop environments like GNOME do. And if you want it to work > exactly like the way GNOME does, you call the API via GObject; otherwise you > have to implement a complicated approximation based on rename that won't be > fully functional. Actually it seems that the trash location is standardized by the XDG Desktop Specification: https://github.com/kevva/xdg-trash http://www.ramendik.ru/docs/trashspec.html From abarnert at yahoo.com Thu Jan 1 23:59:59 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Thu, 1 Jan 2015 23:59:59 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150101160052.GA8524@chromebot.lan> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> <20150101160052.GA8524@chromebot.lan> Message-ID: On Jan 1, 2015, at 17:00, Markus Unterwaditzer wrote: > On Thu, Jan 01, 2015 at 04:37:52PM +0100, Andrew Barnert wrote: >> On Jan 1, 2015, at 11:37, Ram Rachum wrote: >> >>> Hi everyone, >>> >>> I'm a complete ignoramus when it comes to Mac, so I can't say anything >>> about that, but as I understand the discussion, there are problems with >>> implementing this on Mac. Okay. So maybe this should be available only on >>> Windows and Linux? (If it's not a problem to do on Linux.) >> >> On Linux, it's not exactly like Mac, but it's similar. Linux has no notion of >> trash at all; desktop environments like GNOME do. And if you want it to work >> exactly like the way GNOME does, you call the API via GObject; otherwise you >> have to implement a complicated approximation based on rename that won't be >> fully functional. > > Actually it seems that the trash location is standardized by the XDG Desktop > Specification: > > https://github.com/kevva/xdg-trash > http://www.ramendik.ru/docs/trashspec.html Yes, as I just said: Linux has no notion of trash; desktop environments do. The FreeDesktop standard is not Linux; it's a standard that at least two desktop environments (which also work on multiple non-Linux systems) support. On most Linux systems, you will have Gtk libraries; on most Linux systems without Gtk libraries, you will not have a FreeDesktop-compliant trash. So, using GObject is a good 90% solution (like using NSFileManager is a good 90% solution on Mac). Of course you _could_ implement that full spec yourself in Python, right? Well, read it. There are references to things "the implementation" may do, like providing a way for the administrator to disable sticky-bit checking for filesystems that don't support it. Do you know how to check whether the administrator has disabled sticky-bit checking on a filesystem? Or do you just want your code to say a file can't be trashed, or trash by moving it across the network to ~, even when the desktop and other apps have no problem trashing it properly? For that matter, do you know how every FreeDesktop-compatible system wants to report a problem to the administrator? You may meet the XDG Trash spec and still not satisfy user expectations. And it'll be a lot of work. In other words, "you have to implement a complicated approximation based on rename that won't be fully functional". Is that really a better solution than using GObject? If you're writing your own portability library like Qt or JUCE, probably; otherwise, I doubt it. From steve at pearwood.info Fri Jan 2 01:09:14 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 2 Jan 2015 11:09:14 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> <20150101123526.GC15262@ando.pearwood.info> Message-ID: <20150102000913.GD15262@ando.pearwood.info> On Thu, Jan 01, 2015 at 02:43:09PM +0200, Ram Rachum wrote: > Regarding your question: "But I'm still not sure that this needs to be in > the standard library. For such a specialist need, what's wrong with using a > third party solution?" > > Well, I can use a third-party solution for everything, but it would be > nicer for me if it was in the standard library because then I could count > on it always being there and the API not changing. Which is exactly the point. It has been said that the standard library is where good modules go to die. Do you think that the "move to trash" API is ready to die? I don't think so. I think that there is a lot more than just moving files to the trash. I've spent a little bit of time over the last day or so thinking about what sort of trash-related functionality I would like, as a Linux user: - move to trash, of course, but which trash? - return the name of the trash directory in my home directory - list trash directories on other partitions and disks - list trash directories for all users (if I have read permission) - empty one or more of those trash directories - optionally only deleting sufficiently old and/or large files - validate and/or repair the trash metadata - report how much space is used by the trash, with or without metadata - support legacy .Trash directories as well as .local/share/Trash For some operations, I would want to specify either a specific trash directory, or all trash directories for a given user (defaulting to the current user), or all trash directories for all users. (The later would only work if I was running as the root/Administrator user, of course.) The point being that the API for all this functionality isn't obvious, and it is very unlikely to be so stable that it is ready to move into the standard library. -- Steven From random832 at fastmail.us Fri Jan 2 14:24:26 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 02 Jan 2015 08:24:26 -0500 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> Message-ID: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> On Tue, Dec 30, 2014, at 18:12, Andrew Barnert wrote: > By "suitable" I mean "suitable for widespread-enough use that it should > be in the stdlib". As I said earlier in the thread, I think it's > perfectly reasonable to have a third-party library that uses a deprecated > API, requires 10.8, requires a runloop, directly or indirectly asks the > Finder to do the work for you, or doesn't quite meet Apple's HIG rules, > because all of those could be acceptable in _many_ applications; I just > don't think any of those should be in the stdlib, because none of those > are acceptable in _most_ applications. Not having one isn't acceptable either. Because what _not_ having a cross-platform wrapper gets you is windows and mac left behind by applications with badly-written direct implementations of the way you do it on Unix. Can you define "doesn't quite meet Apple's HIG" rules and link the relevant section of the HIG? From random832 at fastmail.us Fri Jan 2 14:30:43 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 02 Jan 2015 08:30:43 -0500 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150101123526.GC15262@ando.pearwood.info> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> <20150101123526.GC15262@ando.pearwood.info> Message-ID: <1420205443.2838218.208808325.450952DE@webmail.messagingengine.com> On Thu, Jan 1, 2015, at 07:35, Steven D'Aprano wrote: > The os module is for low-level operating-system functions. "Send to > trash" is neither low-level nor part of the OS per se, it is part of the > desktop environment. What is the correct place for high-level functions that need to be implemented in a different way on each OS? I think the problem is that some people view os as "low-level functions, like the ones found in unistd.h" and other people view it as "where to put stuff that needs a separate implementation per platform". The actual description in the documentation is "This module provides a portable way of using operating system dependent functionality." Nothing about low-level. From random832 at fastmail.us Fri Jan 2 14:36:24 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 02 Jan 2015 08:36:24 -0500 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> Message-ID: <1420205784.2839657.208808873.1C78CB92@webmail.messagingengine.com> On Thu, Jan 1, 2015, at 10:37, Andrew Barnert wrote: > On Linux, it's not exactly like Mac, but it's similar. Linux has no > notion of trash at all; desktop environments like GNOME do. And if you > want it to work exactly like the way GNOME does, you call the API via > GObject; otherwise you have to implement a complicated approximation > based on rename that won't be fully functional. There is an actual standard for the Trash system that all three major desktop environments implement, so your "complicated approximation based on rename" can actually be correct rather than an approximation. If that's not exactly like how GNOME does it, then GNOME is incorrect. From random832 at fastmail.us Fri Jan 2 14:43:44 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 02 Jan 2015 08:43:44 -0500 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> <20150101160052.GA8524@chromebot.lan> Message-ID: <1420206224.2842545.208810201.5532DB2B@webmail.messagingengine.com> On Thu, Jan 1, 2015, at 17:59, Andrew Barnert wrote: > Of course you _could_ implement that full spec yourself in Python, right? > Well, read it. There are references to things "the implementation" may > do, like providing a way for the administrator to disable sticky-bit > checking for filesystems that don't support it. Do you know how to check > whether the administrator has disabled sticky-bit checking on a > filesystem? A python implementation would be an independent implementation, and not bound by another implementation's (even on the same machine) implementation-specific decisions. There is therefore no reason the python implementation couldn't simply not provide such a method, and therefore any .Trash directory without the sticky bit set does not pass the checks, and all that will happen is .Trash-$uid gets used instead - no harm done. From ncoghlan at gmail.com Fri Jan 2 19:40:52 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Sat, 3 Jan 2015 04:40:52 +1000 Subject: [Python-ideas] python on mobile In-Reply-To: References: <87k31833vw.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: On 31 December 2014 at 13:42, Russell Keith-Magee wrote: > > > On Wed, Dec 31, 2014 at 11:16 AM, Stephen J. Turnbull > wrote: >> >> Fetchinson . writes: >> >> > > I'm not sure exactly what would be discussed [on mobile-sig], >> > > especially in the short term when the big ticket item is getting >> > > the patches into the main Python tree. >> >> It probably matters more that there *is* substantive discussion than >> *what* is discussed. There are probably a lot of people who are far >> more interested in "how to do 'it' *now*" than "get 'it' into the main >> Python tree 'someday'", for example. >> > > I'm not sure if a mailing list would help with this as much as a good, > simple set of docs. It's not like there's unknown territory here; once > you've got Python installed on a mobile device, the "how" is reasonably > easy. The catch is that someone with Python experience won't necessarily > have experience managing a cross-platform C/Automake build, which is what > you need to get Python installed in the first place. > One of the benefits of a SIG over python-ideas is that their remit can be broader than just CPython. distutils-sig is probably the most expansive on that front, but As far as setting one up goes, I believe the page at https://www.python.org/community/sigs/guidelines/ is still accurate (although the blurb isn't quite right when it comes to long lived topical sigs like distutils-sig, or intermittently active sigs like import-sig) Although it's a couple of months off, I would suggest a talk (if it's >> still possible to schedule), a BOF, and a sprint at Pycon North >> America in March. That should get things moving, and several of the >> "important" folks who have already expressed interest should be there, >> too. >> > > Unfortunately, due to the tyranny of distance (I'm based on the west coast > of Australia), plus work commitments, it's unlikely that I'll be attending > PyCon in Montreal. > Will you be at LCA this year? At the very least we can continue the various discussions from PyCon AU :) Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: From abarnert at yahoo.com Fri Jan 2 20:46:51 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Fri, 2 Jan 2015 20:46:51 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> Message-ID: <11C6719F-3F28-4311-966E-CFEA6CD10467@yahoo.com> On Jan 2, 2015, at 14:24, random832 at fastmail.us wrote: > On Tue, Dec 30, 2014, at 18:12, Andrew Barnert wrote: >> By "suitable" I mean "suitable for widespread-enough use that it should >> be in the stdlib". As I said earlier in the thread, I think it's >> perfectly reasonable to have a third-party library that uses a deprecated >> API, requires 10.8, requires a runloop, directly or indirectly asks the >> Finder to do the work for you, or doesn't quite meet Apple's HIG rules, >> because all of those could be acceptable in _many_ applications; I just >> don't think any of those should be in the stdlib, because none of those >> are acceptable in _most_ applications. > > Not having one isn't acceptable either. Because what _not_ having a > cross-platform wrapper gets you is windows and mac left behind by > applications with badly-written direct implementations of the way you do > it on Unix. I'm not sure what "the way you do it on Unix" means. There is no Unix/POSIX/etc. notion of trashing a file. Of course some Unix desktop environments (going back at least as far as NeXTStep) have had such a thing, but that can't be what you mean. If you're referring to XDG, I don't know of a single application that uses a badly-written direct implementation of the XDG trash spec on Mac or Windows. Do you? More importantly, which of those other options do you think is better than continuing to have no trash API? Drop 10.6-10.7 compat? Use a deprecated API and break Mac App Store compatibility? Require all scripts to have a runloop? > Can you define "doesn't quite meet Apple's HIG" rules and link the > relevant section of the HIG? Of course not, because I have no idea what exactly you'd write in place of calling the appropriate API. Give me a design or some code, and I'll tell you what it does wrong. From abarnert at yahoo.com Fri Jan 2 21:01:08 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Fri, 2 Jan 2015 21:01:08 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <1420205784.2839657.208808873.1C78CB92@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> <1420205784.2839657.208808873.1C78CB92@webmail.messagingengine.com> Message-ID: On Jan 2, 2015, at 14:36, random832 at fastmail.us wrote: > On Thu, Jan 1, 2015, at 10:37, Andrew Barnert wrote: >> On Linux, it's not exactly like Mac, but it's similar. Linux has no >> notion of trash at all; desktop environments like GNOME do. And if you >> want it to work exactly like the way GNOME does, you call the API via >> GObject; otherwise you have to implement a complicated approximation >> based on rename that won't be fully functional. > > There is an actual standard for the Trash system that all three major > desktop environments implement, so your "complicated approximation based > on rename" can actually be correct rather than an approximation. If > that's not exactly like how GNOME does it, then GNOME is incorrect. First, XDG specifications are explicitly not standards (and XDG Trash is a draft extension proposal to those specs) so there is not an actual standard. But, far more importantly, there are large areas that the spec leaves open to the implementation, or open for future expansion, that GNOME (and KDE) fills in with appropriate behavior. I gave one example earlier in the thread, which I picked by pointing my finger at one random paragraph from the spec. If you read through it, there are plenty of others. If you call the APIs via GObject or Qt on a GNOME or KDE system, you will get the exact same behavior as everything else on the system. If you implement it yourself and ignore what GNOME and KDE do, nobody's going to care that you're 100% compliant with a draft spec proposal, they're going to care that your app refuses to trash something that everything else can trash (or, worse, that your app trashes it by copying 8GB over the network). From abarnert at yahoo.com Fri Jan 2 21:05:51 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Fri, 2 Jan 2015 21:05:51 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <1420206224.2842545.208810201.5532DB2B@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> <20150101160052.GA8524@chromebot.lan> <1420206224.2842545.208810201.5532DB2B@webmail.messagingengine.com> Message-ID: <73AA04B8-4D4A-4626-8381-9A071C78EA5B@yahoo.com> On Jan 2, 2015, at 14:43, random832 at fastmail.us wrote: > On Thu, Jan 1, 2015, at 17:59, Andrew Barnert wrote: >> Of course you _could_ implement that full spec yourself in Python, right? >> Well, read it. There are references to things "the implementation" may >> do, like providing a way for the administrator to disable sticky-bit >> checking for filesystems that don't support it. Do you know how to check >> whether the administrator has disabled sticky-bit checking on a >> filesystem? > > A python implementation would be an independent implementation, and not > bound by another implementation's (even on the same machine) > implementation-specific decisions. Then a Python implementation would be a bad implementation. The whole point of XDG is to make it easier to write desktop software that's consistent with other desktop software. So if you write some Qt software and I run it on a GNOME system, Qt follows (as best it can--which is better each version) the GNOME rules, and your GNOME-based settings, rather than ignoring them and pretending it's on a KDE system. > There is therefore no reason the > python implementation couldn't simply not provide such a method, and > therefore any .Trash directory without the sticky bit set does not pass > the checks, and all that will happen is .Trash-$uid gets used instead - > no harm done. Except that if you can't create a .Trash-$uid, then you can't trash files on that filesystem even though Nautilus, etc. can. (And, needless to say, if you try to implement any other trash functionality, like listing trash contents or undeleting, you're going to be wrong there too.) From ncoghlan at gmail.com Sat Jan 3 02:36:01 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Sat, 3 Jan 2015 11:36:01 +1000 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <73AA04B8-4D4A-4626-8381-9A071C78EA5B@yahoo.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <20141230234702.GE24472@ando.pearwood.info> <20141231231419.GG24472@ando.pearwood.info> <20150101160052.GA8524@chromebot.lan> <1420206224.2842545.208810201.5532DB2B@webmail.messagingengine.com> <73AA04B8-4D4A-4626-8381-9A071C78EA5B@yahoo.com> Message-ID: On 3 Jan 2015 06:06, "Andrew Barnert" wrote: > > Except that if you can't create a .Trash-$uid, then you can't trash files on that filesystem even though Nautilus, etc. can. (And, needless to say, if you try to implement any other trash functionality, like listing trash contents or undeleting, you're going to be wrong there too.) It sounds to me that what is needed before changes to pathlib can be discussed is a reference third party module that appropriately respects desktop conventions (whether Windows, Mac OS X, GNOME, KDE, or other XDG based Linux window manager), and associated clear documentation on how to delete files in a way that integrates well with underlying platforms. The standard library isn't the place to work through that standardisation activity, although a PEP is certainly a reasonable place to track it. Guido's work on PEP 3156 and the asnycio module is a good point of reference here, as is Antoine's work on pathlib itself. Once a pathlib independent reference implementation of imperative desktop trash management exists, and there is broad acknowledgement that it is a suitable candidate for inclusion in the standard library (perhaps as part of shutil, perhaps as a new independent module, depending on API complexity), *then* it becomes feasible to discuss adding trash management support to the pathlib abstraction layer. Regards, Nick. > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Sat Jan 3 02:50:45 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 3 Jan 2015 12:50:45 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> Message-ID: <20150103015045.GB27426@ando.pearwood.info> On Fri, Jan 02, 2015 at 08:24:26AM -0500, random832 at fastmail.us wrote: > Not having one [move to trash function] isn't acceptable either. I'm not sure about that. Do other languages offer a move-to-trash functionality? Say, PHP, Javascript, Java, Ruby, Boo, Go, Lua? If Python is the odd one out that DOESN'T offer such functionality, and all the others do, then you might have a strong case. Otherwise, consider that the great bulk of scripts that are written in Python don't do any file management at all, other than perhaps reading or writing a few files. So even if Python gained this functionality, it wouldn't have any impact on most scripts and applications.[1] > Because what _not_ having a > cross-platform wrapper gets you is windows and mac left behind Really? I would expect that Windows is probably the *easiest* platform to implement this functionality, as it has a single, standard, stable API for moving files to trash. (Or so I am lead to believe.) You can probably use that API via ctypes, or via pywin32. Getting OS X right is very complicated, as Andrew has so ably explained. In Linux and other Unixes, the situation is like OS X, only more so since there's no one single authority. You have a choice of desktop environments, which may or may not provide a move-to-trash API, including no desktop environment at all. Gnome provides an API for moving to trash, but I don't know how well it supports the freedesktop standard; KDE supports the freedesktop standard, but I don't know if it provides an API that can be called. XFCE has partial support. It seems to me that "move to trash" is at least straight forward on Windows, but tricky and complicated everywhere else. Or, there is always the option of using a third-party module: https://pypi.python.org/pypi/Send2Trash [1] With one possible exception. If Andrew is correct, then the wrong implementation of move-to-trash might effect in a bad way anyone trying to put their app on the Apple Store, whether they use that move-to-trash functionality or not. -- Steve From rosuav at gmail.com Sat Jan 3 03:18:24 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 Jan 2015 13:18:24 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150103015045.GB27426@ando.pearwood.info> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> Message-ID: On Sat, Jan 3, 2015 at 12:50 PM, Steven D'Aprano wrote: > Otherwise, consider that the great bulk of scripts that are written in > Python don't do any file management at all, other than perhaps reading > or writing a few files. So even if Python gained this functionality, it > wouldn't have any impact on most scripts and applications.[1] I've always thought of a trash can as an inherently human-controlled feature. When you go in using a GUI file manager and delete a file, it lands in trash. When you use another application, it's always felt surprising - for instance, BitTorrent on Windows deletes things by moving them to trash. (Which has abysmal performance if you select a huge bunch of things and wipe them all out at once; trashing gobs of stuff across thousands of files seems to trigger an O(N*N) repeated search for which files "fall out" of trash - not to mention that this probably means a fairly arbitrary subset of the freshly-deleted is in trash, and little or nothing from previous deletions remains.) Most apps should do file management at the file system level, unless they're specifically replicating/replacing the file manager. So a "move to trash" feature is something that (a) isn't going to be needed by most apps, and especially (b) would be an attractive nuisance. A third-party module has that extra little hump of having to be consciously sought, so it can be there for those who want it but not waving itself around at those who really should be looking at os.remove(). I'm -0.5 on adding a "move to trash" function to the stdlib, ever, and a definite -1 on adding one now. ChrisA From breamoreboy at yahoo.co.uk Sat Jan 3 09:07:47 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 03 Jan 2015 08:07:47 +0000 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> Message-ID: On 03/01/2015 02:18, Chris Angelico wrote: > On Sat, Jan 3, 2015 at 12:50 PM, Steven D'Aprano wrote: >> Otherwise, consider that the great bulk of scripts that are written in >> Python don't do any file management at all, other than perhaps reading >> or writing a few files. So even if Python gained this functionality, it >> wouldn't have any impact on most scripts and applications.[1] > > I've always thought of a trash can as an inherently human-controlled > feature. As, for example, holding down the SHIFT key on Windows and skipping the recycle bin completely? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Sat Jan 3 09:10:55 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 Jan 2015 19:10:55 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> Message-ID: On Sat, Jan 3, 2015 at 7:07 PM, Mark Lawrence wrote: > On 03/01/2015 02:18, Chris Angelico wrote: >> >> On Sat, Jan 3, 2015 at 12:50 PM, Steven D'Aprano >> wrote: >>> >>> Otherwise, consider that the great bulk of scripts that are written in >>> Python don't do any file management at all, other than perhaps reading >>> or writing a few files. So even if Python gained this functionality, it >>> wouldn't have any impact on most scripts and applications.[1] >> >> >> I've always thought of a trash can as an inherently human-controlled >> feature. > > As, for example, holding down the SHIFT key on Windows and skipping the > recycle bin completely? That's a human deciding _not_ to use it; but yes, it should be under human control. ChrisA From abarnert at yahoo.com Sat Jan 3 11:28:52 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Sat, 3 Jan 2015 11:28:52 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> Message-ID: <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> On Jan 3, 2015, at 3:18, Chris Angelico wrote: > On Sat, Jan 3, 2015 at 12:50 PM, Steven D'Aprano wrote: >> Otherwise, consider that the great bulk of scripts that are written in >> Python don't do any file management at all, other than perhaps reading >> or writing a few files. So even if Python gained this functionality, it >> wouldn't have any impact on most scripts and applications.[1] > > I've always thought of a trash can as an inherently human-controlled > feature. I think this may be an accident of the fact that cmd.exe didn't include a trash command, neither did OS X, and the idea was dropped from xdg-trash; we've all been trained for a couple decades now that you can't trash from the command line. I'm not sure that's a good thing. But it is nevertheless a thing that can't be ignored. > When you go in using a GUI file manager and delete a file, it > lands in trash. When you use another application, it's always felt > surprising In some GUI applications, it does make sense to trash things via a menu or other user interaction. (Except maybe when you're using Apple's versions/history thingy or some similar mechanism.) One of the things Aquamacs adds to the standard emacs distribution is a move-to-trash command that you can use in diredit mode, for example. Although I guess you could argue that counts as "unless you're replacing the file manager", and maybe the same is true of most other such examples... But not all. When I worked on TuneUp, we had a feature to move selected duplicate tracks from quarantine to trash, which I thought was stupid and unnecessary (the quarantine folder is already effectively an app-level trash can...). But when we removed it, we got hundreds of user complaints, and a nasty blog post saying we were trying to deliberately destroy out users' music collections on behalf of the RIAA or something. And: > for instance, BitTorrent on Windows deletes things by > moving them to trash. (Which has abysmal performance if you select a > huge bunch of things and wipe them all out at once; trashing gobs of > stuff across thousands of files seems to trigger an O(N*N) repeated > search for which files "fall out" of trash - not to mention that this > probably means a fairly arbitrary subset of the freshly-deleted is in > trash, and little or nothing from previous deletions remains.) The Mac version also does the move-to-trash; it has perfectly acceptable performance. (Actually, old versions were terribly slow at trashing a torrent with a lot of top-level files or dirs, but newer versions seem to do a single operation per torrent instead, which works fine.) And I'm actually glad it does this. At least twice, I've downloaded an ISO, mounted it, then trashed the torrent with all files; if they were deleted instead of trashed, I would have had to repeat the download to update my VMs... You could argue that I'm an idiot for doing this, and you'd be right, but I'm probably not the only such idiot; in fact, that's kind of what trash is for in the first place. > Most > apps should do file management at the file system level, unless > they're specifically replicating/replacing the file manager. So a > "move to trash" feature is something that (a) isn't going to be needed > by most apps, and especially (b) would be an attractive nuisance. A > third-party module has that extra little hump of having to be > consciously sought, so it can be there for those who want it but not > waving itself around at those who really should be looking at > os.remove(). I agree with this, but it still might be nice to mention that third-party module in shutil and/or pathlib. Whether that's send2trash or a complete trash management module as Steven (I think?) envisioned or a reference to the platform APIs and the various ways to get at them, it would be useful. (In fact, some prominent reference to PyWin32, PyObjC, GObject, and PyQt/PySide for non-GUI-but-still-desktop apps in the docs might be helpful for lots of reasons.) Honestly, I think one of the big things people want is the ability to write the "trash" tool for use on the command line that all of the major desktop systems are missing. It feels like it should be a 3-line Python script, and the fact that it isn't possible looks like a weakness. But really, I don't think that's a problem. OS X comes with a Python with PyObjC; a GNOME or KDE system can install python-gobject or PySide in one apt-get/urpmi/port/etc. command; Windows' function is accessible via the built-in ctypes. I have such scripts on my Mac and Fedora boxes; the fact that they're _different_ 3-line scripts is hardly a serious problem. From rosuav at gmail.com Sat Jan 3 11:39:46 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 Jan 2015 21:39:46 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> Message-ID: On Sat, Jan 3, 2015 at 9:28 PM, Andrew Barnert wrote: > The Mac version also does the move-to-trash; it has perfectly acceptable performance. > Good. The note about performance was a mere parenthesis, and the last time I did anything like that on Windows was on XP, so it's quite possibly different on Win7/8. > I agree with this, but it still might be nice to mention that third-party module in shutil and/or pathlib. > Maybe. Is there a mention of other third-party packages in stdlib docs? It's a slippery slope; which ones deserve mention? Maybe just something like "Note that moving objects to the trash can is possible in OS-dependent ways; packages are available on PyPI to make this easier", without naming any. > Honestly, I think one of the big things people want is the ability to write the "trash" tool for use on the command line that all of the major desktop systems are missing. It feels like it should be a 3-line Python script, and the fact that it isn't possible looks like a weakness. But really, I don't think that's a problem. OS X comes with a Python with PyObjC; a GNOME or KDE system can install python-gobject or PySide in one apt-get/urpmi/port/etc. command; Windows' function is accessible via the built-in ctypes. I have such scripts on my Mac and Fedora boxes; the fact that they're _different_ 3-line scripts is hardly a serious problem. > As an explicit "trash" tool, sure. Typing "trash some_file" is under human control just as much as hitting Delete without holding Shift is. I just don't think it should be the obvious way for an application to remove files. ChrisA From abarnert at yahoo.com Sat Jan 3 12:04:24 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Sat, 3 Jan 2015 12:04:24 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> Message-ID: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> On Jan 3, 2015, at 11:39, Chris Angelico wrote: > On Sat, Jan 3, 2015 at 9:28 PM, Andrew Barnert wrote: >> I agree with this, but it still might be nice to mention that third-party module in shutil and/or pathlib. > > Maybe. Is there a mention of other third-party packages in stdlib > docs? It's a slippery slope; which ones deserve mention? Maybe just > something like "Note that moving objects to the trash can is possible > in OS-dependent ways; packages are available on PyPI to make this > easier", without naming any. The impression I get is that this is a slope that Python (or at least Nick Coghlan) wants to start sliding down--with the advent of wheels and pre-installed pip, keeping things out of the stdlib but still accessible for most users is now possible, and often desirable. But I could be putting words (or complete ideas) in people's mouths. From tomirendo at gmail.com Sat Jan 3 14:37:03 2015 From: tomirendo at gmail.com (yotam vaknin) Date: Sat, 3 Jan 2015 15:37:03 +0200 Subject: [Python-ideas] Slicing and Chainging iterables. Message-ID: I would like to purpose that in python 3 it will be easy to chain and slice Iterators just like you can add and slice lists and tuples easily. I think there could be 2 methods to do this: 1. Implementing '+' and slicing ([1:2:3]) for iterators and generators by default, Resulting in Itertool's chain(a,b) and islice(a,b,c) respectively. 2. Having itertool's chain and islice imported by default. I think since python 3 return zip,map, dict.items and so on as iterators, it makes working with those kind of objects more difficult without having these methods around. And since those methods are important enough to have for lists, it seems important enough for iterators too. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Sat Jan 3 16:28:44 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 4 Jan 2015 02:28:44 +1100 Subject: [Python-ideas] Slicing and Chainging iterables. In-Reply-To: References: Message-ID: <20150103152844.GG27426@ando.pearwood.info> On Sat, Jan 03, 2015 at 03:37:03PM +0200, yotam vaknin wrote: > I would like to purpose that in python 3 it will be easy to chain and slice > Iterators just like you can add and slice lists and tuples easily. > > I think there could be 2 methods to do this: > 1. Implementing '+' and slicing ([1:2:3]) for iterators and generators by > default, Resulting in Itertool's chain(a,b) and islice(a,b,c) respectively. > 2. Having itertool's chain and islice imported by default. The iterator protocol is intentionally simple. To create an iterator, you need to only define two methods: (1) __iter__, which returns the instance itself; (2) __next__, which returns the next item and raises StopIterator when done. With your proposal, you would have to define two or three more methods: (3) __add__ and possibly __radd__, to chain iterators; (4) __getitem__, for slicing. There is nothing stopping you from adding these methods to your own iterator classes, but with your proposal that would be compulsory for all iterators. > I think since python 3 return zip,map, dict.items and so on as iterators, > it makes working with those kind of objects more difficult without having > these methods around. And since those methods are important enough to have > for lists, it seems important enough for iterators too. It only takes a single line of code to get iterator chaining and slicing: from itertools import chain, islice And now you can chain and slice any iterator, regardless of where it came from. I don't think that is difficult. *If* iterators where instances of a concrete base class, then it would make sense to add chain and slice methods to that base class so all other iterators could inherit from it. But they aren't, iterators in Python are values which obey a protocol, not inheritence. That means that a functional approach, like itertools, is more appropriate. I can see the appeal of using + and [a:b:c] syntax instead of function syntax chain() and islice(), but I don't think the advantage is enough to out-weigh the costs. -- Steve From tomirendo at gmail.com Sat Jan 3 16:53:12 2015 From: tomirendo at gmail.com (yotam vaknin) Date: Sat, 3 Jan 2015 17:53:12 +0200 Subject: [Python-ideas] Slicing and Chainging iterables. In-Reply-To: <20150103152844.GG27426@ando.pearwood.info> References: <20150103152844.GG27426@ando.pearwood.info> Message-ID: Sorry, I probably wasn't clear enough. My idea was to add these method (__add__, __getitem__) to the already available iterators (map,zip,dict.items) and generators by default. Not to make these methods part of the iterator protocol. 2015-01-03 17:28 GMT+02:00 Steven D'Aprano : > On Sat, Jan 03, 2015 at 03:37:03PM +0200, yotam vaknin wrote: > > I would like to purpose that in python 3 it will be easy to chain and > slice > > Iterators just like you can add and slice lists and tuples easily. > > > > I think there could be 2 methods to do this: > > 1. Implementing '+' and slicing ([1:2:3]) for iterators and generators by > > default, Resulting in Itertool's chain(a,b) and islice(a,b,c) > respectively. > > 2. Having itertool's chain and islice imported by default. > > The iterator protocol is intentionally simple. To create an iterator, > you need to only define two methods: > > (1) __iter__, which returns the instance itself; > > (2) __next__, which returns the next item and raises StopIterator when > done. > > > With your proposal, you would have to define two or three more methods: > > (3) __add__ and possibly __radd__, to chain iterators; > > (4) __getitem__, for slicing. > > There is nothing stopping you from adding these methods to your own > iterator classes, but with your proposal that would be compulsory for > all iterators. > > > > I think since python 3 return zip,map, dict.items and so on as iterators, > > it makes working with those kind of objects more difficult without having > > these methods around. And since those methods are important enough to > have > > for lists, it seems important enough for iterators too. > > It only takes a single line of code to get iterator chaining and > slicing: > > from itertools import chain, islice > > And now you can chain and slice any iterator, regardless of where it > came from. I don't think that is difficult. > > *If* iterators where instances of a concrete base class, then it would > make sense to add chain and slice methods to that base class so all > other iterators could inherit from it. But they aren't, iterators in > Python are values which obey a protocol, not inheritence. That means > that a functional approach, like itertools, is more appropriate. > > I can see the appeal of using + and [a:b:c] syntax instead of function > syntax chain() and islice(), but I don't think the advantage is enough > to out-weigh the costs. > > > > -- > Steve > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From abarnert at yahoo.com Sat Jan 3 21:40:59 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Sat, 3 Jan 2015 21:40:59 +0100 Subject: [Python-ideas] Slicing and Chainging iterables. In-Reply-To: References: <20150103152844.GG27426@ando.pearwood.info> Message-ID: <9BA6ABD2-2F58-4F95-959D-F0D3ECB3F3E8@yahoo.com> On Jan 3, 2015, at 16:53, yotam vaknin wrote: > Sorry, I probably wasn't clear enough. > My idea was to add these method (__add__, __getitem__) to the already available iterators (map,zip,dict.items) and generators by default. Not to make these methods part of the iterator protocol. Well, dict.items doesn't return an iterator, it returns an iterable view. More importantly, if you add this just to generators and map and zip, it won't apply to (among other things) filter; the built-in iterators for list, tuple, set, dict, and the dict views; the special type used to iterate types that implement __getitem__ but not __iter__; any of the iterators from itertools--including the result of slicing or chaining two map iterators; files; csv readers; XML iterparse; ? I think that would make the language a lot worse. In general, code doesn't care whether it's gotten an iterator from mapping a function over a file, chaining two iterators together, or iterating a sequence. If you wrote some code that expected to get a generator, used the + operator, and then changed the calling code to filter that generator, it would break, for no good reason. If you really wanted to, you could make this general pretty easily: change the meaning of the + operator so that, after checking __add__ and __radd__, before raising a TypeError, it checks whether both operand have __iter__ methods and, if so, it returns a chain of the two. Slicing has another problem, however. First, it's a bit odd to be able to do i[5:7] but not i[5]. But, more seriously, I wouldn't expect i[5:7] to give me an iterable that, when accessed, discards the first 5 elements of i. And imagine how confusing this code would be: >>> i = iter(range(10)) >>> a = i[2:4] >>> b = i[4:6] >>> list(a) [2, 3] >>> list(b) [8, 9] Hiding the fact that i is an iterable rather than a sequence will just confuse your readers. > 2015-01-03 17:28 GMT+02:00 Steven D'Aprano : >> On Sat, Jan 03, 2015 at 03:37:03PM +0200, yotam vaknin wrote: >> > I would like to purpose that in python 3 it will be easy to chain and slice >> > Iterators just like you can add and slice lists and tuples easily. >> > >> > I think there could be 2 methods to do this: >> > 1. Implementing '+' and slicing ([1:2:3]) for iterators and generators by >> > default, Resulting in Itertool's chain(a,b) and islice(a,b,c) respectively. >> > 2. Having itertool's chain and islice imported by default. >> >> The iterator protocol is intentionally simple. To create an iterator, >> you need to only define two methods: >> >> (1) __iter__, which returns the instance itself; >> >> (2) __next__, which returns the next item and raises StopIterator when >> done. >> >> >> With your proposal, you would have to define two or three more methods: >> >> (3) __add__ and possibly __radd__, to chain iterators; >> >> (4) __getitem__, for slicing. >> >> There is nothing stopping you from adding these methods to your own >> iterator classes, but with your proposal that would be compulsory for >> all iterators. >> >> >> > I think since python 3 return zip,map, dict.items and so on as iterators, >> > it makes working with those kind of objects more difficult without having >> > these methods around. And since those methods are important enough to have >> > for lists, it seems important enough for iterators too. >> >> It only takes a single line of code to get iterator chaining and >> slicing: >> >> from itertools import chain, islice >> >> And now you can chain and slice any iterator, regardless of where it >> came from. I don't think that is difficult. >> >> *If* iterators where instances of a concrete base class, then it would >> make sense to add chain and slice methods to that base class so all >> other iterators could inherit from it. But they aren't, iterators in >> Python are values which obey a protocol, not inheritence. That means >> that a functional approach, like itertools, is more appropriate. >> >> I can see the appeal of using + and [a:b:c] syntax instead of function >> syntax chain() and islice(), but I don't think the advantage is enough >> to out-weigh the costs. >> >> >> >> -- >> Steve >> _______________________________________________ >> Python-ideas mailing list >> Python-ideas at python.org >> https://mail.python.org/mailman/listinfo/python-ideas >> Code of Conduct: http://python.org/psf/codeofconduct/ > > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From abarnert at yahoo.com Sat Jan 3 22:14:54 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Sat, 3 Jan 2015 22:14:54 +0100 Subject: [Python-ideas] Slicing and Chainging iterables. In-Reply-To: References: <20150103152844.GG27426@ando.pearwood.info> Message-ID: <892E5E24-CB4D-448F-8B76-239E80EF6C90@yahoo.com> On Jan 3, 2015, at 16:53, yotam vaknin wrote: > Sorry, I probably wasn't clear enough. > My idea was to add these method (__add__, __getitem__) to the already available iterators (map,zip,dict.items) and generators by default. Not to make these methods part of the iterator protocol. Reading this again, I think what you _really_ want is probably a generalized view protocol, where views of sequences act like (in fact, _are_) sequences, but with the main advantages of iterators (no storage or upfront computation). Like dictionary views (which is why I chose the name "view", of course). And there's no reason map _couldn't_ return a view instead of an iterator. When called on (all) sequences it would be a sequence view; when called on (any) iterators it would be an iterator view; otherwise it would be a non-sequence non-iterator (that is, reusable, but not indexable) iterable view. But in any case, it would never call the mapped function on a given mapped value until the result is requested. In other words: >>> def spam(x): ... print(x) ... return x+1 >>> m = map(spam, range(5)) >>> m >>> m[2] 2 3 >>> ms = m[2:4] >>> ms[1] 3 4 You can build view-based zip similarly, and filter, and most of the functions in itertools, and so on (although note that in some cases--like filter--a view of a sequence wouldn't be a sequence). You could also make slices into lazy views instead of copying (as NumPy already does with its arrays). In fact, Python could have designed all of its collections and higher-order functions around views instead of iterators. That's what Swift did. (Swift goes farther, with a hierarchy of kinds of indexing, based on C++, instead of just iterables and sequences.) I wrote a blog post last year (based on the first beta of Swift, which had some oddities in its implementation) examining how this could work in Python terms (http://stupidpythonideas.blogspot.com/2014/07/swift-style-map-and-filter-views.html). I think I've also got a partial implementation somewhere on Github of map, filter, and maybe a few more functions implemented as views. But it would be a pretty major change to Python to move from iterators to views. And iterators are much simpler to create than views, so the tradeoff probably wouldn't be worth it, even if it weren't for the historical/compatibility issue. (It's much the same with Haskell-style lazy lists; Python iterables can only substitute for lazy lists 90% of the time, but that doesn't mean lazy lists are a better language choice.) From sturla.molden at gmail.com Sat Jan 3 23:14:53 2015 From: sturla.molden at gmail.com (Sturla Molden) Date: Sat, 3 Jan 2015 22:14:53 +0000 (UTC) Subject: [Python-ideas] Slicing and Chainging iterables. References: Message-ID: <605337341442016047.995305sturla.molden-gmail.com@news.gmane.org> yotam vaknin wrote: > 1. Implementing '+' and slicing ([1:2:3]) for iterators and generators by > default, Resulting in Itertool's chain(a,b) and islice(a,b,c) respectively. This will break NumPy. Sturla From ncoghlan at gmail.com Sun Jan 4 07:05:23 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Sun, 4 Jan 2015 16:05:23 +1000 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> Message-ID: On 3 January 2015 at 21:04, Andrew Barnert wrote: > On Jan 3, 2015, at 11:39, Chris Angelico wrote: > >> On Sat, Jan 3, 2015 at 9:28 PM, Andrew Barnert wrote: >>> I agree with this, but it still might be nice to mention that third-party module in shutil and/or pathlib. >> >> Maybe. Is there a mention of other third-party packages in stdlib >> docs? It's a slippery slope; which ones deserve mention? Maybe just >> something like "Note that moving objects to the trash can is possible >> in OS-dependent ways; packages are available on PyPI to make this >> easier", without naming any. > > The impression I get is that this is a slope that Python (or at least Nick Coghlan) wants to start sliding down--with the advent of wheels and pre-installed pip, keeping things out of the stdlib but still accessible for most users is now possible, and often desirable. But I could be putting words (or complete ideas) in people's mouths. Your parenthetical qualification is correct - while I personally think providing authoritative recommendations of third party modules is a good idea, this is far from a universally held opinion amongst the core development team. My own caveat on the idea is that any such explicit recommendations should only cover projects that potentially *could* be included in the standard library from an API design perspective, but we don't want to include them (yet, or perhaps ever) for project governance reasons, such as their update cycles for feature releases needing to be faster than those of the standard library. The "pro" case for this approach is primarily about lowering barriers to entry: for folks just learning Python, "not in the standard library" is currently functionally equivalent in many cases to "Python can't do this". New users often won't yet have the skills needed to do their own research and evaluate competing solutions to their problem, and teaching someone how to find a module on the internet, evaluate the trustworthiness of the people publishing it, get it onto their computer, and update it appropriately over time is genuinely difficult (even with pip provided by default - that helps with the last two steps, but the first two are still genuinely difficult, in a way experienced open source developers often take for granted). Providing authoritative recommendations of third party projects in the standard library documentation helps resolve that situation without needing to resort to making the standard library larger (with the additional long term maintenance complications the latter approach entails). You see a similar dynamic operating in a slightly different way with a project like Django - when the Django developers are significantly more experienced in web development than you are, their opinionated, all-inclusive approach to web framework design is a *feature*, not a defect. It's only when you become more experienced with web service development yourself, and need to deal with problems that don't fit neatly into the SQL-backed three-tier web application model, or need to integrate with other systems which weren't built with Django in mind, that less opinionated frameworks like Flask or Pyramid become interesting - those frameworks leave many more decisions to the developers using them, which is exactly what you want in many situations as an experienced developer, but constantly asking people to make decisions they aren't yet qualified to make poses a huge barrier to entry. It's a potential problem when less experienced folks are put off by the request to make those decisions (since not understanding the questions you're being asked by your tools makes for a terrible user experience), and decide to go learn something else that places fewer demands on them, but it's even worse for everyone trying to deploy and manage the resulting software systems when folks happily make the decisions these advanced DIY integration frameworks ask of them without even realising they're not yet qualified to make them. djangopackages.com is also incredibly useful as a tool for finding peer evaluations of projects in the Django ecosystem. I'm not yet aware of any successful attempts to expand that model to other plugin ecosystems, but the core grid concept of assembling a set of criteria, providing answers across a set of related projects, and publishing the results to provide a starting point for anyone doing their own research in that topic area is a wonderful one. The "con" case is that providing default recommendations can be controversial - when there are multiple competing projects in an area, being the default recommendation of the CPython core development team can be a huge popularity boost, since reputation is to some degree transitive. If someone trusts CPython, and we trust another project enough to recommend it, then a lot of folks will use that recommendation as a substitute for doing their own research (even when they *can* do that research themselves, the default recommendation is likely to be good enough, letting them defer investigation of alternatives until after they've tried the default option). I suspect that objection could potentially be dealt with the same way we deal with any other standard library design decisions: if a module maintainer is comfortable making a recommendation based on their own expertise they can, but broader recommendations spanning several modules would require at least a discussion on python-dev, and potentially even a PEP. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From ncoghlan at gmail.com Sun Jan 4 08:23:08 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Sun, 4 Jan 2015 17:23:08 +1000 Subject: [Python-ideas] Slicing and Chainging iterables. In-Reply-To: <892E5E24-CB4D-448F-8B76-239E80EF6C90@yahoo.com> References: <20150103152844.GG27426@ando.pearwood.info> <892E5E24-CB4D-448F-8B76-239E80EF6C90@yahoo.com> Message-ID: On 4 January 2015 at 07:14, Andrew Barnert wrote: > But it would be a pretty major change to > Python to move from iterators to views. And iterators are much simpler to create than views, so the tradeoff probably wouldn't be worth it, even if it weren't for the historical/compatibility issue. (It's much the same with Haskell-style lazy lists; Python iterables can only substitute for lazy lists 90% of the time, but that doesn't mean lazy lists are a better language choice.) It's worth noting that many types implement Mapping.(keys,values,items) as iterators in Python 3 rather than as views, and generally don't receive any complaints from users. Iterators are very simple to implement, cover 90% of the use cases, and in those cases where they don't, you can usually write a custom wrapper around the original containers with view-like behaviour. Providing an operator based spelling for itertools.chain, itertools.islice and itertools.repeat is tempting enough on the surface to be suggested every few years (e.g. [1]), but it creates so many new complications on the *implementation* side that the benefits just aren't worth the cost in additional complexity. Cheers, Nick. [1] https://mail.python.org/pipermail/python-ideas/2010-April/006983.html -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From jeanpierreda at gmail.com Sun Jan 4 08:45:16 2015 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 3 Jan 2015 23:45:16 -0800 Subject: [Python-ideas] Slicing and Chainging iterables. In-Reply-To: References: <20150103152844.GG27426@ando.pearwood.info> <892E5E24-CB4D-448F-8B76-239E80EF6C90@yahoo.com> Message-ID: On Sat, Jan 3, 2015 at 11:23 PM, Nick Coghlan wrote: > On 4 January 2015 at 07:14, Andrew Barnert > wrote: >> But it would be a pretty major change to >> Python to move from iterators to views. And iterators are much simpler to create than views, so the tradeoff probably wouldn't be worth it, even if it weren't for the historical/compatibility issue. (It's much the same with Haskell-style lazy lists; Python iterables can only substitute for lazy lists 90% of the time, but that doesn't mean lazy lists are a better language choice.) > > It's worth noting that many types implement > Mapping.(keys,values,items) as iterators in Python 3 rather than as > views, and generally don't receive any complaints from users. They probably should implement keys/etc. properly. collections.abc.[Mutable]Mapping make it easy to support views if you otherwise implement a dictionary-like object. -- Devin From ncoghlan at gmail.com Sun Jan 4 09:01:57 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Sun, 4 Jan 2015 18:01:57 +1000 Subject: [Python-ideas] Slicing and Chainging iterables. In-Reply-To: References: <20150103152844.GG27426@ando.pearwood.info> <892E5E24-CB4D-448F-8B76-239E80EF6C90@yahoo.com> Message-ID: On 4 January 2015 at 17:45, Devin Jeanpierre wrote: > On Sat, Jan 3, 2015 at 11:23 PM, Nick Coghlan wrote: >> On 4 January 2015 at 07:14, Andrew Barnert >> wrote: >>> But it would be a pretty major change to >>> Python to move from iterators to views. And iterators are much simpler to create than views, so the tradeoff probably wouldn't be worth it, even if it weren't for the historical/compatibility issue. (It's much the same with Haskell-style lazy lists; Python iterables can only substitute for lazy lists 90% of the time, but that doesn't mean lazy lists are a better language choice.) >> >> It's worth noting that many types implement >> Mapping.(keys,values,items) as iterators in Python 3 rather than as >> views, and generally don't receive any complaints from users. > > They probably should implement keys/etc. properly. > collections.abc.[Mutable]Mapping make it easy to support views if you > otherwise implement a dictionary-like object. What people "should" do and what they actually do in practice often differ wildly. In this particular case, folks migrating from Python 2 will frequently rename existing iter* methods to be the Python 3 implementations of the base methods. It's technically a non-compliant implementation of the Python mapping protocol, but you'll only encounter problems if you attempt to use that container implementation with code that relies on the Python 3 view behaviour. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From wes.turner at gmail.com Sun Jan 4 10:27:43 2015 From: wes.turner at gmail.com (Wes Turner) Date: Sun, 4 Jan 2015 03:27:43 -0600 Subject: [Python-ideas] Slicing and Chainging iterables. In-Reply-To: References: Message-ID: In addition to itertools.chain and itertools.islice, this is possible with a number of third-party packages: * http://toolz.readthedocs.org/en/latest/api.html#itertoolz (concat, pluck, first, last, take) * https://github.com/kachayev/fn.py#streams-and-infinite-sequences-declaration (<< 'Stream' operator) * http://funcy.readthedocs.org/en/latest/seqs.html Stdlib docs for this: * https://docs.python.org/2/howto/functional.html#iterators * https://docs.python.org/2/tutorial/classes.html#iterators * https://docs.python.org/2/library/stdtypes.html#iterator-types * https://docs.python.org/2/reference/datamodel.html#object.__iter__ * On Sat, Jan 3, 2015 at 7:37 AM, yotam vaknin wrote: > I would like to purpose that in python 3 it will be easy to chain and > slice Iterators just like you can add and slice lists and tuples easily. > > I think there could be 2 methods to do this: > 1. Implementing '+' and slicing ([1:2:3]) for iterators and generators by > default, Resulting in Itertool's chain(a,b) and islice(a,b,c) respectively. > 2. Having itertool's chain and islice imported by default. > > I think since python 3 return zip,map, dict.items and so on as iterators, > it makes working with those kind of objects more difficult without having > these methods around. And since those methods are important enough to have > for lists, it seems important enough for iterators too. > > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From abarnert at yahoo.com Sun Jan 4 11:32:13 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Sun, 4 Jan 2015 11:32:13 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> Message-ID: <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> On Jan 4, 2015, at 7:05, Nick Coghlan wrote: > On 3 January 2015 at 21:04, Andrew Barnert > wrote: >> On Jan 3, 2015, at 11:39, Chris Angelico wrote: >> >>> On Sat, Jan 3, 2015 at 9:28 PM, Andrew Barnert wrote: >>>> I agree with this, but it still might be nice to mention that third-party module in shutil and/or pathlib. >>> >>> Maybe. Is there a mention of other third-party packages in stdlib >>> docs? It's a slippery slope; which ones deserve mention? Maybe just >>> something like "Note that moving objects to the trash can is possible >>> in OS-dependent ways; packages are available on PyPI to make this >>> easier", without naming any. >> >> The impression I get is that this is a slope that Python (or at least Nick Coghlan) wants to start sliding down--with the advent of wheels and pre-installed pip, keeping things out of the stdlib but still accessible for most users is now possible, and often desirable. But I could be putting words (or complete ideas) in people's mouths. > > Your parenthetical qualification is correct - while I personally think > providing authoritative recommendations of third party modules is a > good idea, this is far from a universally held opinion amongst the > core development team. My own caveat on the idea is that any such > explicit recommendations should only cover projects that potentially > *could* be included in the standard library from an API design > perspective, but we don't want to include them (yet, or perhaps ever) > for project governance reasons, such as their update cycles for > feature releases needing to be faster than those of the standard > library. > > The "pro" case for this approach is primarily about lowering barriers > to entry: for folks just learning Python, "not in the standard > library" is currently functionally equivalent in many cases to "Python > can't do this". New users often won't yet have the skills needed to do > their own research and evaluate competing solutions to their problem, > and teaching someone how to find a module on the internet, evaluate > the trustworthiness of the people publishing it, get it onto their > computer, and update it appropriately over time is genuinely difficult > (even with pip provided by default - that helps with the last two > steps, but the first two are still genuinely difficult, in a way > experienced open source developers often take for granted). Providing > authoritative recommendations of third party projects in the standard > library documentation helps resolve that situation without needing to > resort to making the standard library larger (with the additional long > term maintenance complications the latter approach entails). > > You see a similar dynamic operating in a slightly different way with a > project like Django - when the Django developers are significantly > more experienced in web development than you are, their opinionated, > all-inclusive approach to web framework design is a *feature*, not a > defect. It's only when you become more experienced with web service > development yourself, and need to deal with problems that don't fit > neatly into the SQL-backed three-tier web application model, or need > to integrate with other systems which weren't built with Django in > mind, that less opinionated frameworks like Flask or Pyramid become > interesting - those frameworks leave many more decisions to the > developers using them, which is exactly what you want in many > situations as an experienced developer, but constantly asking people > to make decisions they aren't yet qualified to make poses a huge > barrier to entry. It's a potential problem when less experienced folks > are put off by the request to make those decisions (since not > understanding the questions you're being asked by your tools makes for > a terrible user experience), and decide to go learn something else > that places fewer demands on them, but it's even worse for everyone > trying to deploy and manage the resulting software systems when folks > happily make the decisions these advanced DIY integration frameworks > ask of them without even realising they're not yet qualified to make > them. > > djangopackages.com is also incredibly useful as a tool for finding > peer evaluations of projects in the Django ecosystem. I'm not yet > aware of any successful attempts to expand that model to other plugin > ecosystems, but the core grid concept of assembling a set of criteria, > providing answers across a set of related projects, and publishing the > results to provide a starting point for anyone doing their own > research in that topic area is a wonderful one. > > The "con" case is that providing default recommendations can be > controversial - when there are multiple competing projects in an area, > being the default recommendation of the CPython core development team > can be a huge popularity boost, since reputation is to some degree > transitive. If someone trusts CPython, and we trust another project > enough to recommend it, then a lot of folks will use that > recommendation as a substitute for doing their own research (even when > they *can* do that research themselves, the default recommendation is > likely to be good enough, letting them defer investigation of > alternatives until after they've tried the default option). > > I suspect that objection could potentially be dealt with the same way > we deal with any other standard library design decisions: if a module > maintainer is comfortable making a recommendation based on their own > expertise they can, but broader recommendations spanning several > modules would require at least a discussion on python-dev, and > potentially even a PEP. The question here, then, is how this applies to desktop/shell functionality like moving to trash, administering trash in all the ways someone (Steven?) wanted, other features that someone else raised (aliases/bookmarks/shortcuts/desktop files), and maybe additional stuff (accessing the desktop's extension/file-type mapping). Some of that stuff is already in the stdlib (or might be confusing to novices--e.g., IIRC, on XDG desktops, some things that are done with aliases on Mac are done with desktop files, but in some cases you just use symlinks, so a Linux novice might not even realize he's not writing cross-platform code...). For a GUI app, it's not at all clear that choosing Qt or Wx or one of the platform-specific libraries automatically solves all of these problems for you, while choosing Tk doesn't. For a command-line app, it's even worse. Most Windows users probably have no idea they're asking for desktop integration rather than OS support when they ask how to move a file to the trash or create a shortcut, because Windows intentionally buries that distinction. So when they see that neither os nor shutil nor anything else in the stdlib can help them, they're not going to think, "Oh, I need to go find a platform-specific or cross-platform desktop integration library." (And they're also not going to think "Well, Perl and Ruby and Node don't have these either, so why should I expect Python to?") So, I think in this case it would be useful to recommend something. The question is _what_ to recommend (and where). I think for platform-specific code there are pretty clear winners (PyWin32, PyObjC, GObject, and PyQt/PySide, for the big four). Some might argue for including the XDG package (e.g., if you want to do the same thing as one of the XDG-utils tools, you don't need Gtk or Qt for that), and Mac users might also want a link to the ScriptingBridge guide or something (because some things that are done by API on Windows are done by scripting System Events or Finder or something else), and people using a third-tier desktop on Linux may not have Gtk or Qt libraries to bind to, etc., but I think those are minor questions compared to whether it would be useful to have pointers to these packages for novices. (I think it goes without saying that none of these packages should be added to the stdlib, right?) But for cross-platform code there really isn't an answer. (Well, PyQt/PySide would work, but it's still non-trivial to install and configure on Mac and Windows, and it's overkill.) So, maybe what we need here is for someone to first create the desktop package, and then we can worry about whether it should be added to the stdlib, recommended in the stdlib, or neither. And that still leaves open the possibility that some small subset of this functionality might be separable enough and useful enough to put in the stdlib, or in a small package linked from the stdlib. After all, the equivalent of start/open/xdg-open is already there for some platforms, and webbrowser.open and some of the stuff in shutil. I don't think moving to trash is part of such a subset (for the reasons I gave earlier), but I could be wrong. From ncoghlan at gmail.com Sun Jan 4 14:01:08 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Sun, 4 Jan 2015 23:01:08 +1000 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> Message-ID: On 4 January 2015 at 20:32, Andrew Barnert wrote: > The question here, then, is how this applies to desktop/shell functionality like moving to trash, administering trash in all the ways someone (Steven?) wanted, other features that someone else raised (aliases/bookmarks/shortcuts/desktop files), and maybe additional stuff (accessing the desktop's extension/file-type mapping). Some of that stuff is already in the stdlib (or might be confusing to novices--e.g., IIRC, on XDG desktops, some things that are done with aliases on Mac are done with desktop files, but in some cases you just use symlinks, so a Linux novice might not even realize he's not writing cross-platform code...). > > For a GUI app, it's not at all clear that choosing Qt or Wx or one of the platform-specific libraries automatically solves all of these problems for you, while choosing Tk doesn't. For a command-line app, it's even worse. Most Windows users probably have no idea they're asking for desktop integration rather than OS support when they ask how to move a file to the trash or create a shortcut, because Windows intentionally buries that distinction. So when they see that neither os nor shutil nor anything else in the stdlib can help them, they're not going to think, "Oh, I need to go find a platform-specific or cross-platform desktop integration library." (And they're also not going to think "Well, Perl and Ruby and Node don't have these either, so why should I expect Python to?") So, I think in this case it would be useful to recommend something. The question is _what_ to recommend (and where). > > I think for platform-specific code there are pretty clear winners (PyWin32, PyObjC, GObject, and PyQt/PySide, for the big four). Some might argue for including the XDG package (e.g., if you want to do the same thing as one of the XDG-utils tools, you don't need Gtk or Qt for that), and Mac users might also want a link to the ScriptingBridge guide or something (because some things that are done by API on Windows are done by scripting System Events or Finder or something else), and people using a third-tier desktop on Linux may not have Gtk or Qt libraries to bind to, etc., but I think those are minor questions compared to whether it would be useful to have pointers to these packages for novices. (I think it goes without saying that none of these packages should be added to the stdlib, right?) Right, a useful first step might be a "Tools for writing rich client applications in Python" overview page. That's out of scope for any of the current *.python.org documentation set (it doesn't fit under docs.python.org *or* packaging.python.org, nor anywhere on the main site), but if it's written in an appropriate tone (i.e. making it clear that these are default starting points, and recommendations for further evaluation, rather than universally applicable definitive conclusions), then a future "ecosystem.python.org" guide could start the same way p.p.o did, as a separate Sphinx project hosted on ReadTheDocs that was later blessed with a python.org subdomain. https://packaging.python.org/en/latest/deployment.html is an example skeleton of such a page for package deployment tools. We haven't filled that one *in* yet, but hopefully it conveys the general idea. https://packaging.python.org/en/latest/extensions.html is another one reviewing binary extensions, and some of the tools available in that space. For those curious as to "Why not the wiki?", a Sphinx project hosted on a pull request capable service like GitHub, BitBucket or Kallithea offers a much nicer workflow for reviewing of proposed changes, together with an integrated issue tracker for submitting proposals for updates (https://github.com/pypa/python-packaging-user-guide/ is the project behind packaging.python.org, for example). > But for cross-platform code there really isn't an answer. (Well, PyQt/PySide would work, but it's still non-trivial to install and configure on Mac and Windows, and it's overkill.) So, maybe what we need here is for someone to first create the desktop package, and then we can worry about whether it should be added to the stdlib, recommended in the stdlib, or neither. Just describing the problem space can be incredibly valuable for newcomers - one of the hardest things to learn as a beginner is the difference between "this is hard because I don't know what I'm doing" and "this is hard because I'm working on an unsolved problem" (with "this is deceptively easy because I'm setting myself up for problems later on" being an interesting variant that's hard to detect no matter how experienced you are). I see this is a *lot* when working with the scientific community - they actually have much higher expectations of cross-platform tooling than professional developers do. From the outside, the political, personal and commercial meta-issues that combine to make cross-platform standards development an unholy nightmare aren't immediately obvious, and nor are the trade-offs between "lowest common denominator" (or Java-style "reinvent all the wheels") functionality that works everywhere, and providing access to advanced platform specific functionality. > And that still leaves open the possibility that some small subset of this functionality might be separable enough and useful enough to put in the stdlib, or in a small package linked from the stdlib. After all, the equivalent of start/open/xdg-open is already there for some platforms, and webbrowser.open and some of the stuff in shutil. I don't think moving to trash is part of such a subset (for the reasons I gave earlier), but I could be wrong. While I think it's better to leave the question open rather than try to pre-empt an answer, I do believe we can at least say *now* isn't the right time to be adding "move to trash" functionality to the standard library - the functionality isn't mature enough within the broader ecosystem to determine an appropriate answer. Regards, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From random832 at fastmail.us Sun Jan 4 20:24:36 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sun, 04 Jan 2015 14:24:36 -0500 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150103015045.GB27426@ando.pearwood.info> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> Message-ID: <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> On Fri, Jan 2, 2015, at 20:50, Steven D'Aprano wrote: > > Because what _not_ having a > > cross-platform wrapper gets you is windows and mac left behind > > Really? I would expect that Windows is probably the *easiest* platform > to implement this functionality, as it has a single, standard, stable > API for moving files to trash. (Or so I am lead to believe.) You can > probably use that API via ctypes, or via pywin32. Why would someone who is developing on Linux and has no pre-made library function to call bother with that? If being cross-platform isn't easy, it won't happen. You see it now with the lack of any support for "call glob on arguments on windows and not on unix" [because the shell handles it on unix] whether directly, in argparse, or in fileinput - today, nothing ever calls glob, and so people calling such scripts on windows can't use wildcards (glob is also different from windows wildcards in subtle ways) > Getting OS X right is very complicated, as Andrew has so ably explained. > > In Linux and other Unixes, the situation is like OS X, only more so > since there's no one single authority. However, what authority there is does not allegedly demand that you present dialog boxes and admin elevation prompts to the user (this has been asserted, but no citation has been given). > You have a choice of desktop > environments, which may or may not provide a move-to-trash API, > including no desktop environment at all. Gnome provides an API for > moving to trash, but I don't know how well it supports the freedesktop > standard; KDE supports the freedesktop standard, but I don't know if it > provides an API that can be called. XFCE has partial support. I don't see why you need to call an API to the desktop enviroment. The entire point of the spec is to provide compatibility _between_ implementations on the same filesystem - you can quit gnome and log into KDE and see the same trash. Python would just be a separate implementation that stands by itself. From ncoghlan at gmail.com Sun Jan 4 21:25:01 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Mon, 5 Jan 2015 06:25:01 +1000 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> Message-ID: On 5 Jan 2015 05:25, wrote: > > On Fri, Jan 2, 2015, at 20:50, Steven D'Aprano wrote: > > You have a choice of desktop > > environments, which may or may not provide a move-to-trash API, > > including no desktop environment at all. Gnome provides an API for > > moving to trash, but I don't know how well it supports the freedesktop > > standard; KDE supports the freedesktop standard, but I don't know if it > > provides an API that can be called. XFCE has partial support. > > I don't see why you need to call an API to the desktop enviroment. The > entire point of the spec is to provide compatibility _between_ > implementations on the same filesystem - you can quit gnome and log into > KDE and see the same trash. That compatibility is implemented *by* the desktop environments. Yes, you could write your own, but why would you, when the whole point of providing a standard API would be to integrate more cleanly with the underlying OS. > Python would just be a separate > implementation that stands by itself. The word "just" does not belong in that sentence. Reliable cross-platform development & testing for operations that are tightly coupled to operating system services is hard, period - the associated test matrix of platforms and permission levels ensures that. Regards, Nick. -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Sun Jan 4 21:35:07 2015 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 4 Jan 2015 21:35:07 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> Message-ID: <20150104213507.708c3548@fsol> On Mon, 5 Jan 2015 06:25:01 +1000 Nick Coghlan wrote: > On 5 Jan 2015 05:25, wrote: > > > > On Fri, Jan 2, 2015, at 20:50, Steven D'Aprano wrote: > > > > You have a choice of desktop > > > environments, which may or may not provide a move-to-trash API, > > > including no desktop environment at all. Gnome provides an API for > > > moving to trash, but I don't know how well it supports the freedesktop > > > standard; KDE supports the freedesktop standard, but I don't know if it > > > provides an API that can be called. XFCE has partial support. > > > > I don't see why you need to call an API to the desktop enviroment. The > > entire point of the spec is to provide compatibility _between_ > > implementations on the same filesystem - you can quit gnome and log into > > KDE and see the same trash. > > That compatibility is implemented *by* the desktop environments. Yes, you > could write your own, but why would you, when the whole point of providing > a standard API would be to integrate more cleanly with the underlying OS. For the same reason that we ship a HTTP server while we could integrate more cleanly with Apache? :-) When there's a well-defined spec, it can be simpler to implement the spec yourself rather than pull third-party dependencies, especially when those happen to be huge as may be the case with desktop environments. Regards Antoine. From abarnert at yahoo.com Sun Jan 4 22:02:27 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Sun, 4 Jan 2015 22:02:27 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> Message-ID: <6A8A7845-7865-4746-9859-CD51FC695DDA@yahoo.com> On Jan 4, 2015, at 20:24, random832 at fastmail.us wrote: > On Fri, Jan 2, 2015, at 20:50, Steven D'Aprano wrote: > >> Getting OS X right is very complicated, as Andrew has so ably explained. >> >> In Linux and other Unixes, the situation is like OS X, only more so >> since there's no one single authority. > > However, what authority there is does not allegedly demand that you > present dialog boxes and admin elevation prompts to the user (this has > been asserted, but no citation has been given). Where has that, or anything remotely similar, been alleged or asserted? What _has_ been asserted is that an app has to fit in with the choices made by the platform implementation. And the only example given was given with a direct quote from the spec linked in the preceding email. I'm not sure how much simpler a citation you need in order to be able to follow it. The example was about platform-specific ways to allow admins to disable sticky-bit checking on network mounts. There are more such things that are left incompletely specified, or explicitly left unspecified for future development. I don't think any of them have anything to do with dialog boxes or other user interaction, and I don't recall anyone saying otherwise. (I suppose if you didn't read carefully, you might take something like "SHOULD warn the administrator" as implying a prompt saying "Go get your sys admin and drag him over to the screen" rather than, say, a syslog warning with a string the admin can see later and look up in help or google). >> You have a choice of desktop >> environments, which may or may not provide a move-to-trash API, >> including no desktop environment at all. Gnome provides an API for >> moving to trash, but I don't know how well it supports the freedesktop >> standard; KDE supports the freedesktop standard, but I don't know if it >> provides an API that can be called. XFCE has partial support. > > I don't see why you need to call an API to the desktop enviroment. The > entire point of the spec is to provide compatibility _between_ > implementations on the same filesystem - you can quit gnome and log into > KDE and see the same trash. Python would just be a separate > implementation that stands by itself. The last sentence is exactly the same thing you already got two detailed answers to that you haven't responded to in any way. So I suspect the reason you don't understand why calling an API is a good idea is that you skimmed over the explanations that would explain exactly that. Go back and read those emails. From ethan at stoneleaf.us Sun Jan 4 22:02:39 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 04 Jan 2015 13:02:39 -0800 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> Message-ID: <54A9AA6F.8020400@stoneleaf.us> On 01/04/2015 11:24 AM, random832 at fastmail.us wrote: > If being cross-platform isn't easy, it won't happen. You see it now with > the lack of any support for "call glob on arguments on windows and not > on unix" [because the shell handles it on unix] whether directly, in > argparse, or in fileinput Could you elaborate on this point? > I don't see why you need to call an API to the desktop enviroment. The > entire point of the spec is to provide compatibility _between_ > implementations on the same filesystem - you can quit gnome and log into > KDE and see the same trash. Python would just be a separate > implementation that stands by itself. If by "stands by itself" you mean "desktops can't interact with it", how would that be useful? -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From abarnert at yahoo.com Sun Jan 4 23:06:42 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Sun, 4 Jan 2015 23:06:42 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150104213507.708c3548@fsol> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <20150104213507.708c3548@fsol> Message-ID: <8AB561C3-EDFD-4F6B-8AE9-9115627AF6A4@yahoo.com> On Jan 4, 2015, at 21:35, Antoine Pitrou wrote: > On Mon, 5 Jan 2015 06:25:01 +1000 > Nick Coghlan wrote: >> On 5 Jan 2015 05:25, wrote: >>> >>> On Fri, Jan 2, 2015, at 20:50, Steven D'Aprano wrote: >> >>>> You have a choice of desktop >>>> environments, which may or may not provide a move-to-trash API, >>>> including no desktop environment at all. Gnome provides an API for >>>> moving to trash, but I don't know how well it supports the freedesktop >>>> standard; KDE supports the freedesktop standard, but I don't know if it >>>> provides an API that can be called. XFCE has partial support. >>> >>> I don't see why you need to call an API to the desktop enviroment. The >>> entire point of the spec is to provide compatibility _between_ >>> implementations on the same filesystem - you can quit gnome and log into >>> KDE and see the same trash. >> >> That compatibility is implemented *by* the desktop environments. Yes, you >> could write your own, but why would you, when the whole point of providing >> a standard API would be to integrate more cleanly with the underlying OS. > > For the same reason that we ship a HTTP server while we could integrate > more cleanly with Apache? :-) That's an interesting point--but note that Python _also_ has WSGI and various other ways to integrate more cleanly with Apache (and various other web servers). If you just want to put up a simple web service to handle a few users (e.g., as a user interface to your application), SimpleHTTPServer is sometimes the answer. But if you want to add a web service to a major Apache deployment, you generally don't want to do that by deploying SimpleHTTPServer alongside it. It's not _impossible_ to share ports, SSL certs, configs, logs, deployment scripts, monitoring tools, etc. between the two, but it's not the way you'd want to do things. (There's also the fact that SimpleHTTPServer won't be able to handle the same load as Apache?) > When there's a well-defined spec, I suppose it depends on your definition of "well-defined spec". As Nick said, XFCE only partly supports the spec, and he's not sure how completely GNOME does. As I pointed out, there are gaps in the spec for both implementation-defined and future-expansion behavior. That isn't the same as the case with HTTP/1.1. Look at http://www.freedesktop.org/wiki/Software. Notice that xdg-utils does not yet have a trash command, and there is no separate trash program or library. (As far as I know, there are at least two XDG trash programs on github which have not yet been submitted to be part of the XDG software collection, which don't appear to be 100% compatible with each other. (For example, one of them requires top trash directories to have exactly mode 41777, the other just requires them to be executable for the current user and have the sticky bit on.) Does creating a third one--and putting it in the Python stdlib forever--really sound like a good idea? (As a side note, one of the two above-mentioned trash programs is written in Node, and I don't see anyone suggesting that the functionality be moved into the Node stdlib.) From stephen at xemacs.org Sun Jan 4 23:18:07 2015 From: stephen at xemacs.org (Stephen J. Turnbull) Date: Mon, 05 Jan 2015 07:18:07 +0900 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> Message-ID: <87tx06197k.fsf@uwakimon.sk.tsukuba.ac.jp> random832 at fastmail.us writes: > I don't see why you need to call an API to the desktop enviroment. The > entire point of the spec is to provide compatibility _between_ > implementations on the same filesystem - you can quit gnome and log into > KDE and see the same trash. Python would just be a separate > implementation that stands by itself. But Python doesn't much care about similarities or differences between GNOME and KDE AFAICS -- the relationships to Mac and Windows are much more interesting. Emacs has had a policy of implementing everything itself for decades, and its mindshare has been decreasing for decades.[1] Many Emacs developers are cross-platform users, and the common cross-platform implementation is great for them. Most potential users are not, and the small differences between Emacs's behavior and the platform API mean that Emacs is not a separate implementation that stands by itself -- it's a bad implementation that spends a lot of time standing in a corner.[2] This is not the only reason for Emacs's relative loss of popularity, but it's definitely a common complaint -- and the complainers often never return to Emacs channels when it becomes clear that the Emacs way is the only way. In any case, the small platform differences and the odd problem with the spec mean that this is definitely suited for out-of-stdlib experimentation. Footnotes: [1] The former is a consequence of a policy that (official) Emacs on non-GNU systems can't have any feature that Emacs on the GNU System doesn't have -- if you want a move-to-trash command on Mac, you have to implement for GNU. [2] A traditional punishment for mischievous children, especially those who don't finish their chores or homework, where I grew up. From random832 at fastmail.us Sun Jan 4 23:50:42 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sun, 04 Jan 2015 17:50:42 -0500 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <54A9AA6F.8020400@stoneleaf.us> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> Message-ID: <1420411842.1291347.209489837.52B6E2E7@webmail.messagingengine.com> On Sun, Jan 4, 2015, at 16:02, Ethan Furman wrote: > If by "stands by itself" you mean "desktops can't interact with it", how > would that be useful? They interact with it _through the filesystem_, because it does the same things with the filesystem as all the desktop environments do and as the spec says. Just like Gnome doesn't have to interact directly with KDE - programs from each environment don't have to call the other's library APIs - for both Nautilus and Dolphin to display the same trash contents and to do the same thing when you trash a file. From random832 at fastmail.us Mon Jan 5 00:10:01 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sun, 04 Jan 2015 18:10:01 -0500 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <54A9AA6F.8020400@stoneleaf.us> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> Message-ID: <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> On Sun, Jan 4, 2015, at 16:02, Ethan Furman wrote: > On 01/04/2015 11:24 AM, random832 at fastmail.us wrote: > > > If being cross-platform isn't easy, it won't happen. You see it now with > > the lack of any support for "call glob on arguments on windows and not > > on unix" [because the shell handles it on unix] whether directly, in > > argparse, or in fileinput > > Could you elaborate on this point? On Unix, as I assume you know, the shell is responsible for interpreting the kind of wildcard patterns that glob uses (plus shell-specific extensions), and passing a list of proper filenames as the child process's argv. On Windows, this does not happen - the child process is simply passed a single string with the whole command line. Python (or the C Runtime Library that the python interpreter is linked against) converts this to a list of strings for individual arguments based on spaces and quotes, but does not interpret wildcard patterns in any of the arguments. The C Runtime Library _can_ do this automatically - this is done on MSVC by linking the "setargv.obj" library routine, which replaces a standard internal routine that does not expand wildcards, but it does a poor job because it does not know which arguments are intended to be filenames vs other strings, and there is traditionally no way to escape them [since * and ? aren't allowed in filenames, there's no reason not to allow "some directory\*.txt", all in quotes, as an argument that will be handled as a wildcard] The appropriate place to expand them would be after you know you intend to treat a list of arguments as a list of filenames, rather than at program start - after options are parsed, for example (so an option with an argument with an asterisk in it doesn't get turned into multiple arguments), or if a list is being passed in to the fileinput module. This should also only be done on windows, and not on other platforms (since on other platforms this is supposed to be handled by the shell rather than the child process). Right now, none of this is done. If you pass *.txt on the command line to a python script, it will attempt to open a file called "*.txt". ---- Another separate but related issue is the fact that windows wildcards do not behave in the same way as python glob patterns. Bracketed character classes are not supported, and left bracket is a valid character in filenames unlike ? and *. There are some subtleties around dots ("*.*" will match all filenames, even with no dot. "*." matches filenames without any dot.), they're case-insensitive (I think glob does handle this part, but not in the same way as the platform in some cases), and they can match the short-form alternate filenames [8 characters, dot, 3 characters], so "*.htm" will typically match most files ending in ".html" as well as those ending in ".htm". It might be useful to provide a way to make glob behave in the windows-specific way (using the platform-specific functions FindFirstFileEx and RtlIsNameInExpression on windows.) From rosuav at gmail.com Mon Jan 5 01:42:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 5 Jan 2015 11:42:42 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <54A9AA6F.8020400@stoneleaf.us> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> Message-ID: On Mon, Jan 5, 2015 at 8:02 AM, Ethan Furman wrote: > On 01/04/2015 11:24 AM, random832 at fastmail.us wrote: > >> If being cross-platform isn't easy, it won't happen. You see it now with >> the lack of any support for "call glob on arguments on windows and not >> on unix" [because the shell handles it on unix] whether directly, in >> argparse, or in fileinput > > Could you elaborate on this point? On Unix, a command like "python some_script.py *.txt" is parsed by the shell[1] into a bunch of extra arguments, eg "python some_script.py file_one.txt file_two.txt file_three.txt". On Windows[2], this expansion isn't done, so the script gets a literal "*.txt" as an argument. So a Unix program is usually written to accept multiple args, but a Windows program usually expects to do its own globbing. Now, what happens when you want to reference a file whose name actually includes U+002A (or \x2A, given that file names on most Linux systems consist of bytes)? On Unix, you put a backslash in front of the name, to prevent the shell from expanding it ("\*.txt"), or use some other means of calling up the program (subprocess.call(["python","some_script.py","*.txt"])). Your expectation then is that the script will NOT expand globs; but the script will see the exact same thing in sys.argv as it does on Windows, where the expectation is that it WILL expand globs (and, if I'm not mistaken, asterisks are simply disallowed in file names - though that might be a filesystem-specific rule). So somehow, your script has to know whether it's supposed to call glob or not. Or, more likely, it'll do whatever is appropriate for the platform its developer uses, and then misbehaves on the other one. ChrisA [1] Assuming you're using one of the standard shells, and assuming you haven't configured this feature away, etc, etc. Normal user expectations. [2] Again, assuming you're using the default shell; but again, normal user expectation, ergo replacement shells often replicate this. From steve at pearwood.info Mon Jan 5 01:57:30 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 5 Jan 2015 11:57:30 +1100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> Message-ID: <20150105005730.GR27426@ando.pearwood.info> On Sun, Jan 04, 2015 at 06:10:01PM -0500, random832 at fastmail.us wrote: [...] > Right now, none of this is done. If you pass *.txt on the command line > to a python script, it will attempt to open a file called "*.txt". The important thing is that shells have different behaviour. A way, perhaps not the best way, but a way, of getting close to platform independent behaviour when it comes to globbing is to use the glob module. On Windows, you will get Python's definition of globbing. On POSIX systems, the globbing module will do nothing, because the shell will most likely have already expanded the wild-cards. (I don't know of any Unix shells which behave like Windows.) Windows users are unlikely to try to use Unix-shell-specific wildcards, because they are Windows users and they won't have any expectation that they will work. Unix users will, and they will work because the shell interprets the wildcards before Python sees them. > Another separate but related issue is the fact that windows wildcards do > not behave in the same way as python glob patterns. I don't understand why you say this. As I understand it, there is no such thing as "Windows wildcards" as every application which wants to support wildcards has to implement their own. If you want to know what kinds of globbing wildcards the application supports, you have to read the application documentation. (Or guess.) I am not a Windows expert, so I may have been misinformed. Anyone care to comment? > Bracketed character classes are not supported, Applications which use the Python glob module do support them. Other applications may support them, if they so choose to implement it. > and left bracket is a valid character in > filenames unlike ? and *. And on POSIX systems, *all* wildcards are valid characters in file names. If you want to specify a file called literally "*.txt", or "spam[and eggs?].jpg", you have to escape the wildcards. Windows is no different. The glob module supports escaping of wildcards, doesn't it? If so, we have no problem. If not, that's a bug, or at least an obvious and important piece of missing functionality. > There are some subtleties around dots ("*.*" > will match all filenames, even with no dot. "*." matches filenames > without any dot.), they're case-insensitive (I think glob does handle > this part, but not in the same way as the platform in some cases), and > they can match the short-form alternate filenames [8 characters, dot, 3 > characters], so "*.htm" will typically match most files ending in > ".html" as well as those ending in ".htm". As I said, I don't believe that there is any standard Windows filename wildcard handling, so the behaviour you describe may apply to some applications but not all. Anyone like to comment? > It might be useful to provide a way to make glob behave in the > windows-specific way (using the platform-specific functions > FindFirstFileEx and RtlIsNameInExpression on windows.) This may be a good idea. Maybe glob needs to stay as it is, for backwards compatibility, and a new module osglob be created that aims to implement globbing according to the expected rules of the operating system. osglob could work like the os module and delegate to platform-specific modules posix_glob, windows_glob, osx_glob etc., with the current glob module remaining for applications which want to present a more-or-less equivalent globbing behaviour. -- Steven From rosuav at gmail.com Mon Jan 5 02:08:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 5 Jan 2015 12:08:06 +1100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <20150105005730.GR27426@ando.pearwood.info> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> Message-ID: On Mon, Jan 5, 2015 at 11:57 AM, Steven D'Aprano wrote: > On Sun, Jan 04, 2015 at 06:10:01PM -0500, random832 at fastmail.us wrote: > [...] >> Right now, none of this is done. If you pass *.txt on the command line >> to a python script, it will attempt to open a file called "*.txt". > > On Windows, you will get Python's definition of globbing. On POSIX > systems, the globbing module will do nothing, because the shell will > most likely have already expanded the wild-cards You're assuming that there are no wildcard characters actually included in the file names, which on Unix systems is perfectly possible. How can you reliably manipulate a file called *.txt when there are foo.txt and bar.txt in the same directory? With most Unix programs, you escape the asterisk to get it past the shell, the program does no globbing of its own, and you're safe. If your Python script unconditionally globs its file names, you're stuck. >> Another separate but related issue is the fact that windows wildcards do >> not behave in the same way as python glob patterns. > > I don't understand why you say this. As I understand it, there is no > such thing as "Windows wildcards" as every application which wants to > support wildcards has to implement their own. If you want to know what > kinds of globbing wildcards the application supports, you have to read > the application documentation. (Or guess.) > > I am not a Windows expert, so I may have been misinformed. Anyone care > to comment? There's a very standard interpretation, which I think is codified in the FindFirstFile API, although I'm not sure of the details. >> and left bracket is a valid character in >> filenames unlike ? and *. > > And on POSIX systems, *all* wildcards are valid characters in file > names. If you want to specify a file called literally "*.txt", or > "spam[and eggs?].jpg", you have to escape the wildcards. Windows is no > different. No, Windows *is* different, because you simply aren't allowed to have those characters in file names: >>> open("*.txt","w") Traceback (most recent call last): File "", line 1, in open("*.txt","w") OSError: [Errno 22] Invalid argument: '*.txt' Unix allows anything other than a slash or NUL, so all wildcards have to be escaped to get them past the shell; or, alternatively, you can just use a non-shell way of starting a program, like Python's own subprocess module. > The glob module supports escaping of wildcards, doesn't it? If so, we > have no problem. If not, that's a bug, or at least an obvious and > important piece of missing functionality. I'm not sure that's the solution, because then Unix users would have to double-escape everything. It can be done, of course, but this is the exact sort of complication that single-platform developers often don't even think of. Suppose you develop on Windows, and just unconditionally glob all your arguments... your program will work fine on Unix, until it's asked to deal with a file with an asterisk in it, and your user complains very loudly about how it misbehaved... and maybe destroyed a bunch of files. Oops. Not good. ChrisA From steve at pearwood.info Mon Jan 5 02:13:12 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 5 Jan 2015 12:13:12 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> Message-ID: <20150105011312.GS27426@ando.pearwood.info> On Sun, Jan 04, 2015 at 11:01:08PM +1000, Nick Coghlan wrote: > For those curious as to "Why not the wiki?", a Sphinx project hosted > on a pull request capable service like GitHub, BitBucket or Kallithea > offers a much nicer workflow for reviewing of proposed changes, > together with an integrated issue tracker for submitting proposals for > updates (https://github.com/pypa/python-packaging-user-guide/ is the > project behind packaging.python.org, for example). The concept of "proposed changes" goes completely against the grain of community-managed content. Imagine if Wikipedia required you to make pull requests. The question to be asked is not whether "pull requests" are "nicer" than a wiki, but whether this information needs to be owned by a single person (or a small group thereof), and hence use the packaging.python.org module, or owned by the whole community, and hence use the wiki model. At the moment, the wiki is horribly underused. I'm not blaming anyone for that, I'm just as much to blame as anyone else. I have made far more contributions to the ActiveState recipes than I have to the Python wiki. But I'd really like to see the wiki become the second place people look for information, after the official docs. And hopefully there won't be a need for a third place :-) Although the quality of contrabutions is variable, the PHP community has made a very interesting decision to integrate community-supplied information with official docs: http://php.net/manual/en/function.dechex.php I wonder how we might do something similar? -- Steve From donald at stufft.io Mon Jan 5 02:17:57 2015 From: donald at stufft.io (Donald Stufft) Date: Sun, 4 Jan 2015 20:17:57 -0500 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150105011312.GS27426@ando.pearwood.info> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> Message-ID: > On Jan 4, 2015, at 8:13 PM, Steven D'Aprano wrote: > > On Sun, Jan 04, 2015 at 11:01:08PM +1000, Nick Coghlan wrote: > >> For those curious as to "Why not the wiki?", a Sphinx project hosted >> on a pull request capable service like GitHub, BitBucket or Kallithea >> offers a much nicer workflow for reviewing of proposed changes, >> together with an integrated issue tracker for submitting proposals for >> updates (https://github.com/pypa/python-packaging-user-guide/ is the >> project behind packaging.python.org, for example). > > The concept of "proposed changes" goes completely against the grain of > community-managed content. Imagine if Wikipedia required you to make > pull requests. > > The question to be asked is not whether "pull requests" are "nicer" than > a wiki, but whether this information needs to be owned by a single > person (or a small group thereof), and hence use the > packaging.python.org module, or owned by the whole community, and hence > use the wiki model. > > At the moment, the wiki is horribly underused. I'm not blaming anyone > for that, I'm just as much to blame as anyone else. I have made far more > contributions to the ActiveState recipes than I have to the Python wiki. > But I'd really like to see the wiki become the second place people look > for information, after the official docs. And hopefully there won't be a > need for a third place :-) > > Although the quality of contrabutions is variable, the PHP community has > made a very interesting decision to integrate community-supplied > information with official docs: > > http://php.net/manual/en/function.dechex.php > > I wonder how we might do something similar? > On the other hand, a number of pages on the Wiki are either completely out of date because nobody cares about them or need to be locked because too many people care about it and they fight over which project should be named as recommended. Wiki content can be good for more factual based information but I think the format is relatively poor for things which are more opinion based. --- Donald Stufft PGP: 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA From ben+python at benfinney.id.au Mon Jan 5 02:22:35 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 05 Jan 2015 12:22:35 +1100 Subject: [Python-ideas] Encouraging more use of the Python wiki (was: Adding `pathlib.Path` method that would send file to recycle bin) References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> Message-ID: <85387qyqas.fsf_-_@benfinney.id.au> Donald Stufft writes: > On the other hand, a number of pages on the Wiki are either completely > out of date because nobody cares about them or need to be locked > because too many people care about it and they fight over which > project should be named as recommended. In recent years (I noticed this since about 2013), the Python wiki does not offer an ?Edit? function when I am logged in; every page presents ?Immutable Page? instead. That has prevented me from improving pages I've wanted to. And no, I haven't gone to the effort of constructing a bug report for this. Perhaps the same is true for many other logged-in users as well? -- \ ?It is well to remember that the entire universe, with one | `\ trifling exception, is composed of others.? ?John Andrew Holmes | _o__) | Ben Finney From steve at pearwood.info Mon Jan 5 02:31:23 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 5 Jan 2015 12:31:23 +1100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> Message-ID: <20150105013123.GT27426@ando.pearwood.info> On Sun, Jan 04, 2015 at 02:24:36PM -0500, random832 at fastmail.us wrote: > On Fri, Jan 2, 2015, at 20:50, Steven D'Aprano wrote: > > > Because what _not_ having a > > > cross-platform wrapper gets you is windows and mac left behind > > > > Really? I would expect that Windows is probably the *easiest* platform > > to implement this functionality, as it has a single, standard, stable > > API for moving files to trash. (Or so I am lead to believe.) You can > > probably use that API via ctypes, or via pywin32. > > Why would someone who is developing on Linux and has no pre-made library > function to call bother with that? Because they want to write cross-platform code. For my own personal scripts, I wouldn't bother. If I had a Windows system which I intended to use the script on, I would, or if I intended to make the script available to others, I might. > If being cross-platform isn't easy, it won't happen. You see it now with > the lack of any support for "call glob on arguments on windows and not > on unix" [because the shell handles it on unix] whether directly, in > argparse, or in fileinput - today, nothing ever calls glob, and so > people calling such scripts on windows can't use wildcards (glob is also > different from windows wildcards in subtle ways) I think you are mistaken that nothing uses glob: https://searchcode.com/?q=import+glob+lang%3Apython [...] > > You have a choice of desktop > > environments, which may or may not provide a move-to-trash API, > > including no desktop environment at all. Gnome provides an API for > > moving to trash, but I don't know how well it supports the freedesktop > > standard; KDE supports the freedesktop standard, but I don't know if it > > provides an API that can be called. XFCE has partial support. > > I don't see why you need to call an API to the desktop enviroment. You don't *need* to do so, but doing so guarantees that your code will match the expected behaviour as provided by the API, and avoids needing to re-invent the wheel. I would expect that for something which eventually makes it into the standard library, if it ever does, it will have multiple implementations: - call the platform API, if one exists and it is available - fall back to a Python implementation, if no such API exists That is exactly what the third party Send2Trash package does. If Gnome is installed and the GIO library is installed, it uses that, otherwise it falls back on its own (possibly inferior?) implementation. -- Steven From random832 at fastmail.us Mon Jan 5 02:33:48 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sun, 04 Jan 2015 20:33:48 -0500 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <20150105005730.GR27426@ando.pearwood.info> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> Message-ID: <1420421628.1098818.209525929.58232F93@webmail.messagingengine.com> On Sun, Jan 4, 2015, at 19:57, Steven D'Aprano wrote: > On Sun, Jan 04, 2015 at 06:10:01PM -0500, random832 at fastmail.us wrote: > > Another separate but related issue is the fact that windows wildcards do > > not behave in the same way as python glob patterns. > > I don't understand why you say this. As I understand it, there is no > such thing as "Windows wildcards" as every application which wants to > support wildcards has to implement their own. If you want to know what > kinds of globbing wildcards the application supports, you have to read > the application documentation. (Or guess.) Wildcards are built into the FindFirstFile/FindNextFile (and thereby the _tfindfirst/next) API used for enumerating directories, and users do not generally expect to be able to apply wildcards to path components other than the last one. These functions are used by applications, and generally by libraries provided in higher-level languages. > I am not a Windows expert, so I may have been misinformed. Anyone care > to comment? From random832 at fastmail.us Mon Jan 5 02:40:16 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sun, 04 Jan 2015 20:40:16 -0500 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150105013123.GT27426@ando.pearwood.info> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <20150105013123.GT27426@ando.pearwood.info> Message-ID: <1420422016.1099647.209526789.52D57044@webmail.messagingengine.com> On Sun, Jan 4, 2015, at 20:31, Steven D'Aprano wrote: > I think you are mistaken that nothing uses glob: I am very confident in saying that programs that do not use glob _to process lists of filenames given on the command line_ outnumber those that do at least 1000:1, and that the vast majority of your search consists of uses for processing things other than command line arguments. > https://searchcode.com/?q=import+glob+lang%3Apython The vast majority of results (I used https://searchcode.com/?q=glob.glob+lang%3Apython so I could see the actual call in context) are using it for hardcoded strings, not command line arguments (and to do it correctly they should do even that conditionally on os.name == 'nt' [or os2 or ce, not sure about the other non-posix values]) From ethan at stoneleaf.us Mon Jan 5 02:41:24 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 04 Jan 2015 17:41:24 -0800 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150105011312.GS27426@ando.pearwood.info> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> Message-ID: <54A9EBC4.2010305@stoneleaf.us> On 01/04/2015 05:13 PM, Steven D'Aprano wrote: > Although the quality of contributions is variable, the PHP community has > made a very interesting decision to integrate community-supplied > information with official docs: > > http://php.net/manual/en/function.dechex.php > > I wonder how we might do something similar? I hope that we do not. A separate wiki is fine, but the official docs should just have the official stuff in them. If the docs were a wiki, we'd have scads of entries on "how to program in Python", and IMNSHO the official docs should just be about programming Python in Python. -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From steve at pearwood.info Mon Jan 5 03:07:35 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 5 Jan 2015 13:07:35 +1100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: References: <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> Message-ID: <20150105020735.GU27426@ando.pearwood.info> On Mon, Jan 05, 2015 at 12:08:06PM +1100, Chris Angelico wrote: > On Mon, Jan 5, 2015 at 11:57 AM, Steven D'Aprano wrote: > > On Sun, Jan 04, 2015 at 06:10:01PM -0500, random832 at fastmail.us wrote: > > [...] > >> Right now, none of this is done. If you pass *.txt on the command line > >> to a python script, it will attempt to open a file called "*.txt". > > > > On Windows, you will get Python's definition of globbing. On POSIX > > systems, the globbing module will do nothing, because the shell will > > most likely have already expanded the wild-cards > > You're assuming that there are no wildcard characters actually > included in the file names, which on Unix systems is perfectly > possible. How can you reliably manipulate a file called *.txt when > there are foo.txt and bar.txt in the same directory? With most Unix > programs, you escape the asterisk to get it past the shell, the > program does no globbing of its own, and you're safe. If your Python > script unconditionally globs its file names, you're stuck. You seem to be right. With double wildcard expansion (by the shell and by the python script) there doesn't seem to be a straightforward way to get just the file name with the wildcard in it: [steve at ando junk]$ cat testglob.py import sys import glob for arg in sys.argv[1:]: print(arg + ":-") for name in glob.glob(arg): print(" " + name) [steve at ando junk]$ ls eggs.jpg *.jpg testglob.py [steve at ando junk]$ python3.3 testglob.py *.jpg eggs.jpg:- eggs.jpg *.jpg:- eggs.jpg *.jpg [steve at ando junk]$ python3.3 testglob.py \*.jpg *.jpg:- eggs.jpg *.jpg [steve at ando junk]$ python3.3 testglob.py \\*.jpg \*.jpg:- I guess the simple solutions are to either do a platform check first, or to provide a --no-glob command-line switch to turn globbing off. But I guess people won't think of that until its reported as a bug :-) > >> Another separate but related issue is the fact that windows wildcards do > >> not behave in the same way as python glob patterns. > > > > I don't understand why you say this. As I understand it, there is no > > such thing as "Windows wildcards" as every application which wants to > > support wildcards has to implement their own. If you want to know what > > kinds of globbing wildcards the application supports, you have to read > > the application documentation. (Or guess.) > > > > I am not a Windows expert, so I may have been misinformed. Anyone care > > to comment? > > There's a very standard interpretation, which I think is codified in > the FindFirstFile API, although I'm not sure of the details. Do all Windows apps call FindFirstFile? > >> and left bracket is a valid character in > >> filenames unlike ? and *. > > > > And on POSIX systems, *all* wildcards are valid characters in file > > names. If you want to specify a file called literally "*.txt", or > > "spam[and eggs?].jpg", you have to escape the wildcards. Windows is no > > different. > > No, Windows *is* different, because you simply aren't allowed to have > those characters in file names: I know that. The point that Random raised is that some wildcards are legal in Windows file names. Yes, and *all* wildcards are legal in POSIX filenames, so whatever problems we have with escaping are going to occur on both platforms, as you have already pointed out above. In any case, having a platform specific globbing module is looking more and more useful. Does this need a PEP? -- Steven From random832 at fastmail.us Mon Jan 5 03:41:55 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sun, 04 Jan 2015 21:41:55 -0500 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <20150105020735.GU27426@ando.pearwood.info> References: <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> Message-ID: <1420425715.1110144.209535413.2CD84ED2@webmail.messagingengine.com> On Sun, Jan 4, 2015, at 21:07, Steven D'Aprano wrote: > Do all Windows apps call FindFirstFile? Most Windows apps' only interaction with wildcards is via the system file selection dialog. Ultimately, FindFirstFile/FindNextFile is the only way to enumerate files in a directory - it's the equivalent of opendir/readdir. You're expected to pass in directory\* or *.* if you want to enumerate all files in a directory with no filtering. I think it's rare for programs not deliberately written to emulate some other behavior or ported from unix (with canned implementations of opendir, readdir, glob, and fnmatch being easier than rewriting everything to use the windows functions) to implement their own wildcard handling rather than using the Windows API - the C Runtime functions findfirst/findnext date back to early DOS C compilers (the OS functions were int 21,4E and 4F.) > I know that. The point that Random raised is that some wildcards are > legal in Windows file names. Well, more specifically, that the square bracket is both allowed in Windows filenames and not expected to be used as a wildcard, so there is no escape mechanism (since the only standard wildcards are ? and *, which are not allowed in filenames) >Yes, and *all* wildcards are legal in > POSIX filenames, so whatever problems we have with escaping are going to > occur on both platforms, as you have already pointed out above. Well, yes, except for the fact that escaping and quoting is handled by the shell on POSIX. My _main_ reason for mentioning it was to forestall objections involving applying wildcards to double-quoted strings, since double quote does _not_ normally escape wildcards on Windows. From yawar.amin at gmail.com Mon Jan 5 04:47:06 2015 From: yawar.amin at gmail.com (Yawar Amin) Date: Sun, 04 Jan 2015 22:47:06 -0500 Subject: [Python-ideas] Syntax: 'return: ...' expressions Message-ID: <54AA093A.2050508@gmail.com> Note: I'm reposting this here after posting on the /r/Python reddit as I've realised this is a better venue: http://www.reddit.com/r/Python/comments/2ra8yc/return_expressions/ I have an idea for a new syntax element that combines any number of statements and expressions into a single expression. I'm partial to calling it a 'return' expression because that should be compatible with existing code--there's guaranteed to be no existing code of the form 'return:'. But we could call it 'do' or 'val' or 'expr' or whatever. expression ::= ... | return_expr return_expr ::= "return" ":" statement* expression+ We can define all expression-oriented syntax in terms of return expressions. I.e., wrap up all statement-oriented syntax inside an expression. E.g., x = ( return: if y == 1: z = 'a' elif y == 2: z = 'b' elif y == 3: z = 'c' else: z = 'd' z ) Or a single-line example, x = return: print "Blah"; 5 I know, it's the Python programmer's dreaded multi-line expression. Note here that I'm not proposing any change to indentation rules. I'm relying on parens to relax the rules. There's precedent for using parens in new kinds of expressions--e.g. generator expressions. So the usage shouldn't look alien in Python code. Now the controversy. We can use a return expression to get a multi-line, multi-statement, lambda, as long as lambda only cares that its body is a single exprssion. Which I believe is the case, e.g. this is valid Python today: f = lambda x: ( x, x + 1, x + 2 ) Anyway, an imaginary lambda example: txtName.text.signal.map( # Need to wrap the return expr in parens to separate the lambdas. lambda s: ( return: l = len(s) l >= 5 ), # The next argument, a lambda without a return expr, happily lives # alongside. lambda err: notifications.send(err) ).subscribe( # Parens not needed here, only a single argument. lambda flag: return: pnlMain.back_color = "green" if flag else "red" # Must end with an expr, unlike a normal function. Think of it # this way: we're 'inside' a return, we _have to_ return # some value. None ) I believe 'return: ...' is an unintrusive and versatile solution. It's _not_ meant to just forcefully shoehorn full functionality into lambdas as I believe I show above; it doesn't break compatibility; it doesn't require any indent/whitespace rule changes; and it's guaranteed to not affect _any_ existing code. Regards, Yawar P.S. Relevant: https://groups.google.com/d/msg/python-ideas/kYQbvsmyM-4/ufU26RPTjLQJ 'A much better idea would be to find a way to make all compound statements into expressions, future-proofing the decision and avoiding the redundancy between "compound statement statement" and "compound statement expression".' https://groups.google.com/d/msg/python-ideas/EQQq3--DDu0/UTcfI34sVwwJ 'Something that has started to annoy me in the last couple of years is the fact that most Python control statements cannot be used as expressions. I feel this is a pretty deep limitation and personally I don't feel it's well-justified.' -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 834 bytes Desc: OpenPGP digital signature URL: From stephen at xemacs.org Mon Jan 5 05:19:16 2015 From: stephen at xemacs.org (Stephen J. Turnbull) Date: Mon, 05 Jan 2015 13:19:16 +0900 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <20150105020735.GU27426@ando.pearwood.info> References: <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> Message-ID: <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> Steven D'Aprano writes: > In any case, having a platform specific globbing module By "platform-specific", do you mean one module that handles all platforms appropriately (what this thread is about), or do you mean per-platform modules (what "platform-specific" means to me)? > is looking more and more useful. Does this need a PEP? If you're really serious about putting it in the stdlib, I would certainly think so. It's absolutely clear that the solution is going to be complicated and hard to understand. Without a PEP, nobody will know what is and what is not a bug. Likely even with a PEP a lot of people will claim the PEP is buggy no matter what it says! I would hope the different specs will partition the complainers, but I'm not even sure of that. ;-) From abarnert at yahoo.com Mon Jan 5 10:49:03 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Mon, 5 Jan 2015 10:49:03 +0100 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <54AA093A.2050508@gmail.com> References: <54AA093A.2050508@gmail.com> Message-ID: <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> On Jan 5, 2015, at 4:47, Yawar Amin wrote: > I know, it's the Python programmer's dreaded multi-line expression. Note > here that I'm not proposing any change to indentation rules. But that _is_ a new indentation rule. You're using multiple statements inside parentheses, indented as if they were a block. (This is effectively just a suggestion for brace syntax, and I'm not sure what the return adds to it that you couldn't get just from brace syntax. You also seem to have invented a rule that a sequence of statements has the value of the last statement as its value. Which requires first inventing a rule that gives values to statements. I'll assume you wanted to go with the same rule the interactive interpreter uses to display a last value--an expression statement has its expression's value, and any other kind of statement has None?) You're assuming that parentheses have an existing indentation rule that you can piggyback on, but they don't. Superficially, parenthesis continuation may look similar to block indentation, but it's not at all the same. Compare: >>> (spam, ... eggs) >>> if spam: ... eggs The first is a perfectly valid tuple display; the second raises an IndentationError. Because suites begin with a new indent, but paren continuation just concatenates the lines together. So, unless you're suggesting that any free-form sequence of statements is now legal within parens, you must be inventing a new indent rule to use within those parens. There are also problems with nesting indents and colons. Note that compound statements (like if) include either by an inline simple statement list, or an indented block of one or more statements. This means you can't have two possibly-indenting colons on the same line. Unless your new expression can only be used in simple statements, and a simple statement with your new expression can't be used in an inline simple statement list, you're changing the way colons and indents are parsed by statements. Finally, are you sure your new return: isn't ambiguous without look ahead or context? When the parser reads "if spam: return", is it starting a return simple statement, or an expression statement that starts with a return expression? Have you tried actually writing out the grammar? From rosuav at gmail.com Mon Jan 5 10:55:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 5 Jan 2015 20:55:41 +1100 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> Message-ID: On Mon, Jan 5, 2015 at 8:49 PM, Andrew Barnert wrote: > Finally, are you sure your new return: isn't ambiguous without look ahead or context? When the parser reads "if spam: return", is it starting a return simple statement, or an expression statement that starts with a return expression? Have you tried actually writing out the grammar? > The way I see it, the return-expression is "return:", whereas the simple return statement would have no colon. Your other concerns, though, are quite valid. ChrisA From abarnert at yahoo.com Mon Jan 5 11:10:40 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Mon, 5 Jan 2015 11:10:40 +0100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> References: <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: <160BFDF9-033E-43C2-AF9E-18740FB1E90A@yahoo.com> It seems to me that if you want auto-globbing support on Windows, the "right" way to do it is to link in the fancy setargv instead of the default one. This handles wildcards exactly the same way the command.com/cmd.exe builtin commands do, which I suspect is what Windows users would actually be expecting of they passed a wildcard on the command line. (I think the docs no longer guarantee that this is true, but it's probably still true, and certainly closer to true than if you try to do it manually.) The only problem is that you can't add a command-line switch that controls at runtime which implementation of setargv got linked into the msvcrt prequel at build time. There used to be a way around this for DOS/Win16 programs, but I don't think there is for NT/Win32 (short of ignoring the argv and asking for and parsing the command line instead), so this would be an all-or-nothing change. Are there programs that depend on _not_ having auto-globbing on Windows? There might be... At any rate, I can't imagine many programs want POSIX (sh-style) globbing but without other POSIX shell features (at least the different split/quoting/escape rules, if not the various kinds of expansion, etc.); the only reason anyone calls glob.glob for Windows is because it's relatively easy (compared to using win32api to call FindFirstFile, or using win32api to get the whole command line and then using shlex and os to process it, depending on which one they actually wanted) and not _too_ terrible for simple cases. If there's a way to give people something that's not only easier but better, I don't think they'd complain. Sent from a random iPhone On Jan 5, 2015, at 5:19, "Stephen J. Turnbull" wrote: > Steven D'Aprano writes: > >> In any case, having a platform specific globbing module > > By "platform-specific", do you mean one module that handles all > platforms appropriately (what this thread is about), or do you mean > per-platform modules (what "platform-specific" means to me)? > >> is looking more and more useful. Does this need a PEP? > > If you're really serious about putting it in the stdlib, I would > certainly think so. It's absolutely clear that the solution is going > to be complicated and hard to understand. Without a PEP, nobody will > know what is and what is not a bug. Likely even with a PEP a lot of > people will claim the PEP is buggy no matter what it says! I would > hope the different specs will partition the complainers, but I'm not > even sure of that. ;-) > > > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ From abarnert at yahoo.com Mon Jan 5 11:28:21 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Mon, 5 Jan 2015 11:28:21 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <54A9EBC4.2010305@stoneleaf.us> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <54A9EBC4.2010305@stoneleaf.us> Message-ID: <31C37528-4EE5-4F52-827D-425D5FB1999E@yahoo.com> On Jan 5, 2015, at 2:41, Ethan Furman wrote: > On 01/04/2015 05:13 PM, Steven D'Aprano wrote: > >> Although the quality of contributions is variable, the PHP community has >> made a very interesting decision to integrate community-supplied >> information with official docs: >> >> http://php.net/manual/en/function.dechex.php >> >> I wonder how we might do something similar? > > I hope that we do not. A separate wiki is fine, but the official docs should just have the official stuff in them. MSDN has something similar. They've gone back and forth between a half-dozen different models, and I think at present it's just (formatted) comments on each documentation page. At any rate, it's very clear what's official documentation and what's some guy saying "the docs say you can't do Foo, but here's some code that simulates Foo in most cases". I've found useful stuff there. Then again, I've also found live code (and StackOverflow questions, etc.) that's broken because someone took some sample fragment from a comment and used it inappropriately (often ignoring the very next comment that explains why you shouldn't do that if X, Y, or Z). Both PHP and MSDN have a separate page for each function/method/attribute, while Python has a page per module (broken down into sections that are usually very nicely organized, so I wouldn't want to lose that...), so I'm not sure a similar comment format would work in the first place. Maybe allowing inline comments at every section break, entry, or even paragraph would work (like the way PyGame docs have inline example-search and other links)? But that could easily lead to docs that are so cluttered with comments (or with disclosure triangles, if they start off hidden) that the actual documentation is hard to read. > If the docs were a wiki, we'd have scads of entries on "how to program in Python", In other fora (python-list, python-tutor, StackOverflow, comments on widely-followed blogs, etc.) when someone suggests writing Java-style code instead of Pythonic code they usually get quickly shouted down, often even with good explanations, so I'm not sure things would be any worse on a wiki attached to the Python docs. Also, the Python wiki is already a wiki, and isn't dominated by that kind of cruft. So I'm not sure that problem is as much of a threat. That being said, I agree with your conclusion. Docs seem to work best information that's managed like code; things that aren't quite docs but are useful may work best in other ways, but people have already found the wiki, StackOverflow, ActiveState, blogs, etc. and aren't having any problem using them. And, of all the alternate places to find elaborated documentation, the wiki seems to be among the least popular, which doesn't seem to imply that more wikification is the answer to any relevant question. From abarnert at yahoo.com Mon Jan 5 11:37:22 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Mon, 5 Jan 2015 11:37:22 +0100 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> Message-ID: On Jan 5, 2015, at 10:55, Chris Angelico wrote: > On Mon, Jan 5, 2015 at 8:49 PM, Andrew Barnert > wrote: >> Finally, are you sure your new return: isn't ambiguous without look ahead or context? When the parser reads "if spam: return", is it starting a return simple statement, or an expression statement that starts with a return expression? Have you tried actually writing out the grammar? > > The way I see it, the return-expression is "return:", whereas the > simple return statement would have no colon. Are you suggesting that "return:" would be a single token (as opposed to all the other colons in the tokenizer), or that you'd use look ahead to disambiguate? I suspect it probably _is_ possible to make something work that fits into Python's parser, but it isn't immediately obvious (at least to me) what that would be, which is why I wanted to see a grammar. (And also to know which "level" this comes at, to automatically answer questions like how it fits into things like conditional expressions and comprehension clauses and so forth.) From dw+python-ideas at hmmz.org Mon Jan 5 11:38:29 2015 From: dw+python-ideas at hmmz.org (David Wilson) Date: Mon, 5 Jan 2015 10:38:29 +0000 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: Message-ID: <20150105103828.GA22528@k3> I have no problem with this being included somehow in the standard library, but pathlib to me is all about the filesystem, whereas (as others have pointed out), the Recycle Bin and associated concepts on other OS relate pretty uniformly to the OS shell. There are many shell-related concepts that could be nicely exposed, but again I don't think any of them belong in pathlib. For example, labels/tags, owner application, icon, visibility flags, etc. David On Mon, Dec 29, 2014 at 06:54:46PM +0200, Ram Rachum wrote: > Hi guys, > > I want to have a method of?`pathlib.Path` that would send a file to the recycle > bin. (i.e. soft delete.) > > What do you think about adding this?? > > I see there's a PyPI package `Send2Trash` that does this, but it would be nice > if this was in the standard library. > > > Thanks, > Ram. > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ From rosuav at gmail.com Mon Jan 5 11:46:46 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 5 Jan 2015 21:46:46 +1100 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> Message-ID: On Mon, Jan 5, 2015 at 9:37 PM, Andrew Barnert wrote: > Are you suggesting that "return:" would be a single token (as opposed to all the other colons in the tokenizer), or that you'd use look ahead to disambiguate? Oh, I see what you mean. I'm sure this can be dealt with, though; if nothing else, requiring that this kind of expression be parenthesized would do it, as 'return' inside parens has no meaning. It'd be like a genexp. But I still don't think it's a good idea :) ChrisA From alexisl at hp.com Mon Jan 5 12:20:11 2015 From: alexisl at hp.com (Alexis Lee) Date: Mon, 5 Jan 2015 11:20:11 +0000 Subject: [Python-ideas] inspect.getclassdistance Message-ID: <20150105112011.GB7357@hp.com> Hopefully sufficiently documented to stand without introduction: def getclassdistance(srcs, dst): """srcs may be either a single class or a list of (class, distance) pairs. dst is the superclass to find. Performs a breadth-first search for dst, returning the shortest distance. """ if type(srcs) != list: srcs = [(srcs, 0)] if len(srcs) == 0: return None here, distance = srcs[0] if here == dst: return distance newSrc = srcs[1:] + [(c, distance + 1) for c in list(here.__bases__)] return classDistance(newSrc, dst) If this is already implemented and I just couldn't find it, I'm more than happy to withdraw the idea. Alexis -- Nova Engineer, HP Cloud. AKA lealexis, lxsli. From steve at pearwood.info Mon Jan 5 12:43:15 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 5 Jan 2015 22:43:15 +1100 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: <20150105112011.GB7357@hp.com> References: <20150105112011.GB7357@hp.com> Message-ID: <20150105114315.GZ27426@ando.pearwood.info> On Mon, Jan 05, 2015 at 11:20:11AM +0000, Alexis Lee wrote: > Hopefully sufficiently documented to stand without introduction: Er, not really. What does distance mean in the context of classes? When would you use this? Can you give some examples, e.g. what's the distance between int and str? > def getclassdistance(srcs, dst): > """srcs may be either a single class or a list of (class, distance) pairs. > dst is the superclass to find. > Performs a breadth-first search for dst, returning the shortest distance. > """ > if type(srcs) != list: > srcs = [(srcs, 0)] > if len(srcs) == 0: > return None Shouldn't that be an exception? > here, distance = srcs[0] > if here == dst: > return distance > newSrc = srcs[1:] + [(c, distance + 1) for c in list(here.__bases__)] > return classDistance(newSrc, dst) What's classDistance? > If this is already implemented and I just couldn't find it, I'm more > than happy to withdraw the idea. Explain it first :-) -- Steven From rosuav at gmail.com Mon Jan 5 12:51:33 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 5 Jan 2015 22:51:33 +1100 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: <20150105112011.GB7357@hp.com> References: <20150105112011.GB7357@hp.com> Message-ID: On Mon, Jan 5, 2015 at 10:20 PM, Alexis Lee wrote: > def getclassdistance(srcs, dst): > """srcs may be either a single class or a list of (class, distance) pairs. > dst is the superclass to find. > Performs a breadth-first search for dst, returning the shortest distance. > """ > > if type(srcs) != list: > srcs = [(srcs, 0)] > if len(srcs) == 0: > return None > here, distance = srcs[0] > if here == dst: > return distance > newSrc = srcs[1:] + [(c, distance + 1) for c in list(here.__bases__)] > return classDistance(newSrc, dst) I'm not 100% sure that I understand what this is doing, so here's a reimplementation of what I think it's doing. Tell me where this one's wrong, and you'll be a long way toward explaining what yours is accomplishing :) def getclassdistance(src, dst): """Measure the shortest parent chain which leads from src to dst Returns the length of the shortest such chain, or None if no chain exists.""" srcs = [(src, 0)] while srcs: here, distance = srcs.pop(0) if here is dst: return distance for c in here.__bases__: srcs.append((c, distance+1)) I'm still not sure what the value of this is, and therefore why it shouldn't just be a personal utility function (not everything needs to be in the stdlib), but if this is an iterative equivalent to your recursive function (assuming that classDistance is getclassdistance), then it's at least reasonably simple. I made a couple of other changes along the way, including requiring that the first arg be a single class (is there any reason, other than recursion, to provide a pre-populated list?), and using 'is' rather than '==' to compare classes. But since I can't test this against your use-case, I can't verify that it's doing the right job. ChrisA From abarnert at yahoo.com Mon Jan 5 13:09:37 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Mon, 5 Jan 2015 13:09:37 +0100 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: <20150105112011.GB7357@hp.com> References: <20150105112011.GB7357@hp.com> Message-ID: <3D63844A-E1EA-4708-ADF0-8AB4D8453EDD@yahoo.com> On Jan 5, 2015, at 12:20, Alexis Lee wrote: > Hopefully sufficiently documented to stand without introduction: It doesn't actually run as written (maybe you just used the wrong name in what was supposed to be a recursive call?), and I'm not sure you're doing the BFS right, but I think I can guess what you're after: You're trying to find out if dst is an ancestor of src (the option of taking a list of pairs, despite being documented, seems to be there only for internal use by recursive calls) and, if so, how long the path is between them. And: * Only actual inheritance counts; abc.register or other subclass hooks are ignored. * In case of diamond inheritance where the sides are of unequal length, the shorter one counts (even if that shorter path would never be followed by the c3 rule and therefore isn't even relevant at runtime). * More generally, you don't care about the c3 MRO path, or the actual path taken for any particular method's lookup, just the inheritance path itself. * The actual classes on the path are irrelevant to you, you just want its length. Also, it seems like it would be simpler to just create a general inheritance-BFS-walker function that yields each base as it goes, which would allow you to write this function as a one-liner. I also don't get why you're using recursion rather than a loop here, given that there's nothing interesting on the stack frames. I suspect you wrote this in Common Lisp or OCaml first and then ported it to Python? That might also explain why it's such a strange fit for the way inheritance works in Python. But, most importantly, if I'm right about what this does, I can't think of anywhere I'd want to use it. I can imagine cases (although not very Pythonic ones) where I'd want to know, say, the MRO path (as in dst.__mro__[:dst.__mro__.find(src)][::-1]), but this... When would it ever be interesting? > def getclassdistance(srcs, dst): > """srcs may be either a single class or a list of (class, distance) pairs. > dst is the superclass to find. > Performs a breadth-first search for dst, returning the shortest distance. > """ > > if type(srcs) != list: > srcs = [(srcs, 0)] > if len(srcs) == 0: > return None > here, distance = srcs[0] > if here == dst: > return distance > newSrc = srcs[1:] + [(c, distance + 1) for c in list(here.__bases__)] > return classDistance(newSrc, dst) > > If this is already implemented and I just couldn't find it, I'm more > than happy to withdraw the idea. > > > Alexis > -- > Nova Engineer, HP Cloud. AKA lealexis, lxsli. > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ From rosuav at gmail.com Mon Jan 5 13:30:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 5 Jan 2015 23:30:28 +1100 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: <3D63844A-E1EA-4708-ADF0-8AB4D8453EDD@yahoo.com> References: <20150105112011.GB7357@hp.com> <3D63844A-E1EA-4708-ADF0-8AB4D8453EDD@yahoo.com> Message-ID: On Mon, Jan 5, 2015 at 11:09 PM, Andrew Barnert wrote: > Also, it seems like it would be simpler to just create a general inheritance-BFS-walker function that yields each base as it goes, which would allow you to write this function as a one-liner. > def bfs_bases(cls): """Yield the base which are belong to us""" yield from cls.__bases__ for cls in cls.__bases__: yield from bfs_bases(cls) :) ChrisA From jdhardy at gmail.com Mon Jan 5 14:25:08 2015 From: jdhardy at gmail.com (Jeff Hardy) Date: Mon, 5 Jan 2015 13:25:08 +0000 Subject: [Python-ideas] python on mobile In-Reply-To: References: <87k31833vw.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: On Fri, Jan 2, 2015 at 6:40 PM, Nick Coghlan wrote: > On 31 December 2014 at 13:42, Russell Keith-Magee > wrote: >> >> >> >> On Wed, Dec 31, 2014 at 11:16 AM, Stephen J. Turnbull >> wrote: >>> >>> Fetchinson . writes: >>> >>> > > I'm not sure exactly what would be discussed [on mobile-sig], >>> > > especially in the short term when the big ticket item is getting >>> > > the patches into the main Python tree. >>> >>> It probably matters more that there *is* substantive discussion than >>> *what* is discussed. There are probably a lot of people who are far >>> more interested in "how to do 'it' *now*" than "get 'it' into the main >>> Python tree 'someday'", for example. >> >> >> I'm not sure if a mailing list would help with this as much as a good, >> simple set of docs. It's not like there's unknown territory here; once >> you've got Python installed on a mobile device, the "how" is reasonably >> easy. The catch is that someone with Python experience won't necessarily >> have experience managing a cross-platform C/Automake build, which is what >> you need to get Python installed in the first place. > > > One of the benefits of a SIG over python-ideas is that their remit can be > broader than just CPython. I'd like to see a mobile-sig, because I think there's enough to discuss that isn't relevant to -dev. I plan to get IronPython running on Xamarin Android/iOS sometime this year so it would be helpful to coordinate things with CPython and Jython - for example, what the values will be for things like sys.platform and os.name will be, and issues around file system emulation, supported modules, etc. that should be compatible for all implementations. Plus there's the issue of new libraries for sensors, GPS, cameras, etc. that provide Pythonic wrappers over the platform APIs. It's not just "get CPython working on mobile" but "how should Python look & feel on mobile devices". (Of course, CPython is special so it's implementation details are still fair game.) So +1 on mobile-sig from me. I'll even volunteer to get it set up & administer it, if no one else is dying to. - Jeff From alexisl at hp.com Mon Jan 5 14:44:50 2015 From: alexisl at hp.com (Alexis Lee) Date: Mon, 5 Jan 2015 13:44:50 +0000 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: <20150105114315.GZ27426@ando.pearwood.info> References: <20150105112011.GB7357@hp.com> <20150105114315.GZ27426@ando.pearwood.info> Message-ID: <20150105134450.GC7357@hp.com> Steven D'Aprano said on Mon, Jan 05, 2015 at 10:43:15PM +1100: > Er, not really. What does distance mean in the context of classes? When > would you use this? Can you give some examples, e.g. what's the distance > between int and str? Thanks for your fast response! Distance means the number of classes in the inheritance hierarchy between classes A and B. EG given a system: A <-- B1 <-- B2 <-- D ^ / '--------C-------" Given by: class A(object) class B1(A) class B2(B1) class C(A) class D(B2, C) The distances should be: dst A B1 B2 C D A 0 None None None None B1 1 0 None None None src B2 2 1 0 None None C 1 None None 0 None D 2 2 1 1 0 > > def getclassdistance(srcs, dst): > > """srcs may be either a single class or a list of (class, distance) pairs. > > dst is the superclass to find. > > Performs a breadth-first search for dst, returning the shortest distance. > > """ Maybe the above could be inferred if this last line was changed to: Performs a breadth-first search for dst, either through all the bases of src (if a single class is given) or through the bases of each class given by a pair. Returns the minimal number of jumps required to reach a base class equal to dst. > > if type(srcs) != list: > > srcs = [(srcs, 0)] > > if len(srcs) == 0: > > return None > > Shouldn't that be an exception? It certainly could be. Does TypeError sound appropriate? > > here, distance = srcs[0] > > if here == dst: > > return distance > > newSrc = srcs[1:] + [(c, distance + 1) for c in list(here.__bases__)] > > return classDistance(newSrc, dst) > > What's classDistance? Oops - the old method name. Should be getclassdistance. Alexis -- Nova Engineer, HP Cloud. AKA lealexis, lxsli. From solipsis at pitrou.net Mon Jan 5 14:58:05 2015 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 5 Jan 2015 14:58:05 +0100 Subject: [Python-ideas] inspect.getclassdistance References: <20150105112011.GB7357@hp.com> <20150105114315.GZ27426@ando.pearwood.info> <20150105134450.GC7357@hp.com> Message-ID: <20150105145805.5259c8da@fsol> On Mon, 5 Jan 2015 13:44:50 +0000 Alexis Lee wrote: > > Maybe the above could be inferred if this last line was changed to: > > Performs a breadth-first search for dst, either through all the > bases of src (if a single class is given) or through the > bases of each class given by a pair. > Returns the minimal number of jumps required to reach a base class > equal to dst. Can you explain the use case? Regards Antoine. From alexisl at hp.com Mon Jan 5 15:05:20 2015 From: alexisl at hp.com (Alexis Lee) Date: Mon, 5 Jan 2015 14:05:20 +0000 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: <3D63844A-E1EA-4708-ADF0-8AB4D8453EDD@yahoo.com> References: <20150105112011.GB7357@hp.com> <3D63844A-E1EA-4708-ADF0-8AB4D8453EDD@yahoo.com> Message-ID: <20150105140520.GD7357@hp.com> Andrew Barnert said on Mon, Jan 05, 2015 at 01:09:37PM +0100: > On Jan 5, 2015, at 12:20, Alexis Lee wrote: > You're trying to find out if dst is an ancestor of src (the option of > taking a list of pairs, despite being documented, seems to be there > only for internal use by recursive calls) and, if so, how long the > path is between them. All correct. (moved for clarity) > When would it ever be interesting? The usecase is here (comments at line 861, also see 866-894): https://review.openstack.org/#/c/142835/5/nova/api/openstack/compute/servers.py IE I receive a NeutronException of some specialised type; based on that there are multiple Nova exceptions I might want to throw. I would use getclassdistance (or rather, your walker) to sort those and throw the first, most-specific exception. EG I might be considering throwing either HTTPConflict or HTTPBadRequest, but the former is-a latter, hence it's more specific and the one which should be thrown. > * Only actual inheritance counts; abc.register or other subclass hooks are ignored. Never used abc; happy to enhance if the usecase is useful. > * In case of diamond inheritance where the sides are of unequal > length, the shorter one counts (even if that shorter path would never > be followed by the c3 rule and therefore isn't even relevant at > runtime). Yes. Although thinking about it, I actually want the longest path to count. Curses. This behaviour should be a toggle parameter. > * The actual classes on the path are irrelevant to you, you just want > its length. Yes. > * More generally, you don't care about the c3 MRO path, or the actual > path taken for any particular method's lookup, just the inheritance > path itself. Yes. MRO distance is trivial to obtain from __mro__. > Also, it seems like it would be simpler to just create a general > inheritance-BFS-walker function that yields each base as it goes, > which would allow you to write this function as a one-liner. Yes, that's fair. I'll wait for some more feedback on whether such a thing would be useful in the stdlib at all before writing that. > I also don't get why you're using recursion rather than a loop here, Just how I think. Alexis -- Nova Engineer, HP Cloud. AKA lealexis, lxsli. From p.f.moore at gmail.com Mon Jan 5 15:25:34 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 5 Jan 2015 14:25:34 +0000 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: <20150105140520.GD7357@hp.com> References: <20150105112011.GB7357@hp.com> <3D63844A-E1EA-4708-ADF0-8AB4D8453EDD@yahoo.com> <20150105140520.GD7357@hp.com> Message-ID: On 5 January 2015 at 14:05, Alexis Lee wrote: >> When would it ever be interesting? > > The usecase is here (comments at line 861, also see 866-894): > https://review.openstack.org/#/c/142835/5/nova/api/openstack/compute/servers.py Why is it not simply acceptable for you to use your code? I presume you are implying that this would be useful in the stdlib, but you'd need far more than a single use case to justify that. And you'd need to clarify why it would be useful to have it in 3.5+ and not in earlier versions - presumably the code you pointed to would need to support Python 3.4 at least, so a stdlib addition wouldn't be of any use unless there's a reasonable probability that new code would need something like this (and writing what seems to be a pretty trivial function isn't a better option). Paul From alexisl at hp.com Mon Jan 5 15:35:28 2015 From: alexisl at hp.com (Alexis Lee) Date: Mon, 5 Jan 2015 14:35:28 +0000 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: References: <20150105112011.GB7357@hp.com> <3D63844A-E1EA-4708-ADF0-8AB4D8453EDD@yahoo.com> <20150105140520.GD7357@hp.com> Message-ID: <20150105143528.GF7357@hp.com> Paul Moore said on Mon, Jan 05, 2015 at 02:25:34PM +0000: > On 5 January 2015 at 14:05, Alexis Lee wrote: > >> When would it ever be interesting? > > > > The usecase is here (comments at line 861, also see 866-894): > > https://review.openstack.org/#/c/142835/5/nova/api/openstack/compute/servers.py > > Why is it not simply acceptable for you to use your code? I presume > you are implying that this would be useful in the stdlib, but you'd > need far more than a single use case to justify that. Well, that's it basically. I thought I'd offer it - if it isn't considered generally useful (and the reactions so far imply it isn't, tbh) it's no skin off my nose. I was just surprised it wasn't already available. Alexis -- Nova Engineer, HP Cloud. AKA lealexis, lxsli. From alexisl at hp.com Mon Jan 5 15:43:39 2015 From: alexisl at hp.com (Alexis Lee) Date: Mon, 5 Jan 2015 14:43:39 +0000 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: References: <20150105112011.GB7357@hp.com> <3D63844A-E1EA-4708-ADF0-8AB4D8453EDD@yahoo.com> Message-ID: <20150105144339.GG7357@hp.com> Chris Angelico said on Mon, Jan 05, 2015 at 11:30:28PM +1100: > def bfs_bases(cls): > """Yield the base which are belong to us""" > yield from cls.__bases__ > for cls in cls.__bases__: > yield from bfs_bases(cls) Much as I appreciate the pun, that isn't properly breadth-first, alas. This is and returns the classes in tranches by distance in case you care about the specific distance rather than a distance ordering: def bfs_bases2(cls): bases = [cls] while len(bases) > 0: yield bases bases = reduce(lambda x, y: x+y, (base.__bases__ for base in bases)) Alexis -- Nova Engineer, HP Cloud. AKA lealexis, lxsli. From rosuav at gmail.com Mon Jan 5 15:47:55 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Jan 2015 01:47:55 +1100 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: <20150105144339.GG7357@hp.com> References: <20150105112011.GB7357@hp.com> <3D63844A-E1EA-4708-ADF0-8AB4D8453EDD@yahoo.com> <20150105144339.GG7357@hp.com> Message-ID: On Tue, Jan 6, 2015 at 1:43 AM, Alexis Lee wrote: > Chris Angelico said on Mon, Jan 05, 2015 at 11:30:28PM +1100: >> def bfs_bases(cls): >> """Yield the base which are belong to us""" >> yield from cls.__bases__ >> for cls in cls.__bases__: >> yield from bfs_bases(cls) > > Much as I appreciate the pun, that isn't properly breadth-first, alas. Hmm, good point. Once it's done one level (this class's bases), it then goes on to recurse depth-first. Whoops. Buggy. Your version's roughly as short, though, which was what I was aiming for - to point out how trivially simple this could be. ChrisA From skip.montanaro at gmail.com Mon Jan 5 15:49:07 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 5 Jan 2015 08:49:07 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki (was: Adding `pathlib.Path` method that would send file to recycle bin) In-Reply-To: <85387qyqas.fsf_-_@benfinney.id.au> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> Message-ID: On Sun, Jan 4, 2015 at 7:22 PM, Ben Finney wrote: > In recent years (I noticed this since about 2013), the Python wiki does > not offer an ?Edit? function when I am logged in; every page presents > ?Immutable Page? instead. Ben (and others), I just noticed this small paragraph on the FrontPage: If you want to edit a page and have just signed up, or you find that you can no longer edit a page that you could edit before, please write to the pydotorg-www mailing list, stating your account name and your intended edits and we'll add you to the EditorsGroup. I suspect that has something to do with your inability to edit. Somewhere along the way, someone must have made the executive decision that open editing no longer worked (too much spam?) and that editing needed to be a by-invitation or by-request sort of thing. I'd add you, but am getting nothing but Gateway Timeout responses at the moment. Skip From mal at egenix.com Mon Jan 5 16:27:59 2015 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 05 Jan 2015 16:27:59 +0100 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> Message-ID: <54AAAD7F.6080201@egenix.com> On 05.01.2015 15:49, Skip Montanaro wrote: > On Sun, Jan 4, 2015 at 7:22 PM, Ben Finney wrote: >> In recent years (I noticed this since about 2013), the Python wiki does >> not offer an ?Edit? function when I am logged in; every page presents >> ?Immutable Page? instead. > > Ben (and others), > > I just noticed this small paragraph on the FrontPage: > > If you want to edit a page and have just signed up, or you find that > you can no longer edit a page that you could edit before, please write > to the pydotorg-www mailing list, stating your account name and your > intended edits and we'll add you to the EditorsGroup. > > I suspect that has something to do with your inability to edit. > Somewhere along the way, someone must have made the executive decision > that open editing no longer worked (too much spam?) and that editing > needed to be a by-invitation or by-request sort of thing. This was discussed and announced on the pydotorg-www list at the time. The step was necessary, because of excessive spam and vandalim - editors were spending more time cleaning up than editing pages and were losing interest in the wiki altogether because of this. The first step was to require logins for editing. This worked for a (short) while. The second was adding more complicated textchas, the third step was requiring asking for editing rights on the pydotorg-www mailing list. Which is a little annoying and some work for the admins, but has resulted in the amount of spam to go down to zero. We usually grant the editing requests within a day. FWIW: I've maintained the wiki VM ever since it came under attack in 2013. > I'd add you, but am getting nothing but Gateway Timeout responses at the moment. If you get those, simply try to resend/reload. The wiki will notice duplicate editing requests. In my experience, the editing requests typically make it through to the wiki the first time and you get a duplicate editing warning on the second one. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 05 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From skip.montanaro at gmail.com Mon Jan 5 16:42:39 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 5 Jan 2015 09:42:39 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <54AAAD7F.6080201@egenix.com> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> Message-ID: On Mon, Jan 5, 2015 at 9:27 AM, M.-A. Lemburg wrote: >> I'd add you, but am getting nothing but Gateway Timeout responses at the moment. > > If you get those, simply try to resend/reload. The wiki will notice > duplicate editing requests. In my experience, the editing requests > typically make it through to the wiki the first time and you get > a duplicate editing warning on the second one. Unfortunately, I couldn't even get to the EditorsGroup page to edit it. Now, about an hour later, I finally succeeded. Ben, send me your wiki login and I'll add you. MAL, I thought the spam problem had mostly been solved by Martin's modification several years ago to require a certain time to pass between a new login being created and their first attempt to edit. Skip From mal at egenix.com Mon Jan 5 17:05:27 2015 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 05 Jan 2015 17:05:27 +0100 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> Message-ID: <54AAB647.6080507@egenix.com> On 05.01.2015 16:42, Skip Montanaro wrote: > On Mon, Jan 5, 2015 at 9:27 AM, M.-A. Lemburg wrote: >>> I'd add you, but am getting nothing but Gateway Timeout responses at the moment. >> >> If you get those, simply try to resend/reload. The wiki will notice >> duplicate editing requests. In my experience, the editing requests >> typically make it through to the wiki the first time and you get >> a duplicate editing warning on the second one. > > Unfortunately, I couldn't even get to the EditorsGroup page to edit > it. Now, about an hour later, I finally succeeded. Hmm, looks like the VM is overloaded again :-( > Ben, send me your wiki login and I'll add you. > > MAL, I thought the spam problem had mostly been solved by Martin's > modification several years ago to require a certain time to pass > between a new login being created and their first attempt to edit. I'm not aware of such a modification in the installation. In any case, the problem was real and the editors group solved it for good now :-) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 05 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From fetchinson at googlemail.com Mon Jan 5 17:28:37 2015 From: fetchinson at googlemail.com (Fetchinson .) Date: Mon, 5 Jan 2015 17:28:37 +0100 Subject: [Python-ideas] python on mobile In-Reply-To: References: <87k31833vw.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: > I'd like to see a mobile-sig, because I think there's enough to > discuss that isn't relevant to -dev. I plan to get IronPython running > on Xamarin Android/iOS sometime this year so it would be helpful to > coordinate things with CPython and Jython - for example, what the > values will be for things like sys.platform and os.name will be, and > issues around file system emulation, supported modules, etc. that > should be compatible for all implementations. > > Plus there's the issue of new libraries for sensors, GPS, cameras, > etc. that provide Pythonic wrappers over the platform APIs. It's not > just "get CPython working on mobile" but "how should Python look & > feel on mobile devices". (Of course, CPython is special so it's > implementation details are still fair game.) > > So +1 on mobile-sig from me. I'll even volunteer to get it set up & > administer it +1 -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From abarnert at yahoo.com Mon Jan 5 17:36:28 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Mon, 5 Jan 2015 17:36:28 +0100 Subject: [Python-ideas] inspect.getclassdistance In-Reply-To: <20150105140520.GD7357@hp.com> References: <20150105112011.GB7357@hp.com> <3D63844A-E1EA-4708-ADF0-8AB4D8453EDD@yahoo.com> <20150105140520.GD7357@hp.com> Message-ID: On Jan 5, 2015, at 15:05, Alexis Lee wrote: > Andrew Barnert said on Mon, Jan 05, 2015 at 01:09:37PM +0100: >> On Jan 5, 2015, at 12:20, Alexis Lee wrote: >> You're trying to find out if dst is an ancestor of src (the option of >> taking a list of pairs, despite being documented, seems to be there >> only for internal use by recursive calls) and, if so, how long the >> path is between them. > > All correct. > > (moved for clarity) >> When would it ever be interesting? > > The usecase is here (comments at line 861, also see 866-894): > https://review.openstack.org/#/c/142835/5/nova/api/openstack/compute/servers.py > > IE I receive a NeutronException of some specialised type; based on that > there are multiple Nova exceptions I might want to throw. I would use > getclassdistance (or rather, your walker) to sort those and throw the > first, most-specific exception. EG I might be considering throwing > either HTTPConflict or HTTPBadRequest, but the former is-a latter, hence > it's more specific and the one which should be thrown. I'm afraid I still don't understand the use case. To know that the former is-a latter, all you need is issubclass; what does the distance add? Maybe you're thinking that, in the case of two unrelated exceptions, the distance from some base class (like Exception) tells you which one is "most specific"? I don't think that's true in general (the hierarchy of Python's standard exceptions and other stdlib exceptions definitely hasn't been designed that way) but maybe your project designed its own exceptions that way on purpose. But if that's true, there ought to be a much simpler option: The "depth" of any exception class is 1 more than the depth of its deepest ancestor, with the root being 0. Do you actually have a use case where you need to know that exception class A is 2 levels deep from some arbitrary exception class B (as opposed to from the root)? >> I also don't get why you're using recursion rather than a loop here, > > Just how I think. Well, if you're you're going to suggest ideas for the Python stdlib, you may want to learn to think Pythonically. Not that recursion is never a good idea in Python, but deliberately using it in place of a for or while loop isn't. From steve at pearwood.info Mon Jan 5 18:10:55 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 6 Jan 2015 04:10:55 +1100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: <20150105171042.GA27426@ando.pearwood.info> On Mon, Jan 05, 2015 at 01:19:16PM +0900, Stephen J. Turnbull wrote: > Steven D'Aprano writes: > > > In any case, having a platform specific globbing module > > By "platform-specific", do you mean one module that handles all > platforms appropriately (what this thread is about), or do you mean > per-platform modules (what "platform-specific" means to me)? Yes to both. The model I am proposing is that of the os and os.path modules: we import os and it does the right thing for the current platform. In particular, os.path will do the right thing for the current platform, but you can import ntpath, posixpath, genericpath etc. to get behaviour for a specific platform. I think we have to leave the glob module as-is, for backwards compatibility, and add a new package, say globbing (or osglob, the name can be bike-shedded to death later *wink*) with the new behaviour. globbing will look something like this: globbing/ __init__.py posix.py nt.py generic.py (plus any other platforms that may need special treatment, if any) and the globbing/__init__.py implementation could potentially be as simple as "from foo import *" from the appropriate sub-module. The globbing.generic implementation might be as simple as: from glob import * Or perhaps the relationship should go the other way? Move the current glob.py implementation into globbing.generic, and replace it with: from globbing.generic import * These little details are to be decided later, but the aim is: * Current code that imports glob will continue to work the same as it does now, warts and all. * Code that imports globbing will do the right thing for the platform. * If you want to apply globs to something other than file names, the right module to use would probably be globbing.generic (or possible fnmatch directly). -- Steve From rosuav at gmail.com Mon Jan 5 18:14:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Jan 2015 04:14:38 +1100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <20150105171042.GA27426@ando.pearwood.info> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> <20150105171042.GA27426@ando.pearwood.info> Message-ID: On Tue, Jan 6, 2015 at 4:10 AM, Steven D'Aprano wrote: > * If you want to apply globs to something other than file names, > the right module to use would probably be globbing.generic > (or possible fnmatch directly). To clarify: Do you mean "something other than names of currently-existing files", or "something other than valid names for the local file system", or something else? For instance, suppose you write an unarchiver (in case we don't have enough of them already, of course), and you can "python unarchive.py archivename *.txt" to extract all files matching *.txt. The globbing would be done against some sort of internal index, but the names would have to be valid for the local file system, or you wouldn't be able to create them. Which module should you use? ChrisA From turnbull at sk.tsukuba.ac.jp Mon Jan 5 19:09:39 2015 From: turnbull at sk.tsukuba.ac.jp (Stephen J. Turnbull) Date: Tue, 06 Jan 2015 03:09:39 +0900 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <20150105171042.GA27426@ando.pearwood.info> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> <20150105171042.GA27426@ando.pearwood.info> Message-ID: <87fvbp14m4.fsf@uwakimon.sk.tsukuba.ac.jp> Steven D'Aprano writes: > The model I am proposing is that of the os and os.path modules: we > import os and it does the right thing for the current platform. Which is normally "nothing" on POSIX, since the shell does it for you. Or, if you're talking about what the shell does for you, while I suppose there is a basic globbing defined by POSIX, but bash and zsh go well beyond that, and they behave somewhat differently in corner cases IIRC. If the program is going to invoke a globbing function specifically, I suppose it makes sense to default to the same behavior as on the current platform, but it's not obvious that that's what the user wants. I use bash on Windows; why settle for cmd.exe if you want the power of the command line? It could even cause problems (is there a reliable way to determine what the shell is, let alone whether it implements globbing or not, on Windows?) > In particular, os.path will do the right thing for the current > platform, but you can import ntpath, posixpath, genericpath etc. to > get behaviour for a specific platform. But there *is* a RightThang for paths; the OS decides. Globbing is a user preference thing. From skip.montanaro at gmail.com Mon Jan 5 19:45:38 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 5 Jan 2015 12:45:38 -0600 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <87fvbp14m4.fsf@uwakimon.sk.tsukuba.ac.jp> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> <20150105171042.GA27426@ando.pearwood.info> <87fvbp14m4.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: On Mon, Jan 5, 2015 at 12:09 PM, Stephen J. Turnbull < turnbull at sk.tsukuba.ac.jp> wrote: > Which is normally "nothing" on POSIX, since the shell does it for > you. Or, if you're talking about what the shell does for you, while I > suppose there is a basic globbing defined by POSIX, but bash and zsh > go well beyond that, and they behave somewhat differently in corner > cases IIRC. > Indeed. I only have 2.7.2 available here at work. Here's what bash tells me on a Linux box: % ls yen{2,3}.* yen2.out yen2.png yen2.trade yen3.out yen3.png yen3.trade % ls yen[23].* yen2.out yen2.png yen2.trade yen3.out yen3.png yen3.trade Here's what /bin/sh tells me on a Solaris 10 box: $ ls yen{2,3}.* yen{2,3}.*: No such file or directory $ ls yen[23].* yen2.out yen2.png yen2.trade yen3.out yen3.png yen3.trade Here's what the glob module tells me: % python Python 2.7.2 (default, Nov 14 2012, 05:07:35) [GCC 4.4.6 [TWW]] on linux3 Type "help", "copyright", "credits" or "license" for more information. >>> import glob >>> glob.glob("yen{2,3}.*") [] >>> glob.glob("yen[23].*") ['yen3.trade', 'yen2.out', 'yen2.trade', 'yen3.out', 'yen3.png', 'yen2.png'] I only discovered this "shortcoming" (or "Bourne Shell dependency") relatively recently. I've been using bash for so long it never even occurred to me that {...} notation wasn't available in all shells. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From random832 at fastmail.us Mon Jan 5 21:33:08 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Mon, 05 Jan 2015 15:33:08 -0500 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> References: <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: <1420489988.4157893.209883497.15AB7246@webmail.messagingengine.com> On Sun, Jan 4, 2015, at 23:19, Stephen J. Turnbull wrote: > By "platform-specific", do you mean one module that handles all > platforms appropriately (what this thread is about), or do you mean > per-platform modules (what "platform-specific" means to me)? Windows technically requires calls to the actual filesystem driver for correct behavior - different filesystems may have different case folding, theoretically other different rules, etc. Plus you've got to examine both the long and short filenames - if you have foobar.html, *.htm will match it because the short filename is FOOBAR~1.HTM (it, however, _returns_ the long filename.) This means that the equivalent function to glob can't simply be the equivalent of listdir filtered by fnmatch. On Mon, Jan 5, 2015, at 05:10, Andrew Barnert wrote: > It seems to me that if you want auto-globbing support on Windows, the > "right" way to do it is to link in the fancy setargv instead of the > default one. This handles wildcards exactly the same way the > command.com/cmd.exe builtin commands do, which I suspect is what Windows > users would actually be expecting of they passed a wildcard on the > command line. (I think the docs no longer guarantee that this is true, > but it's probably still true, and certainly closer to true than if you > try to do it manually.) The problem with that is that if you do that you can no longer pass in _non_-filename arguments that contain a question mark or asterisk (and happen to match a file). Better to do it inside the program, when you actually know the argument you're looking at is intended to be a filename spec. Which, I assume, is _why_ it's not done by default when you compile a C program. A program like grep "a.*b" "Some Directory\*.txt" should handle wildcards in the filename and not in the regex. That is the user expectation on windows, and that is something that windows programs (and not unix programs) can and do deliver. Setargv doesn't, which is why you have to opt in to it (if you know your program doesn't need non-filename arguments that look like wildcards). It should be possible to write Python programs that can do the same, in a way that is relatively painless. A setargv-like solution is insufficient for that. On Mon, Jan 5, 2015, at 13:45, Skip Montanaro wrote: > I only discovered this "shortcoming" (or "Bourne Shell dependency") > relatively recently. I've been using bash for so long it never even > occurred to me that {...} notation wasn't available in all shells. Brace expansion is technically not globbing. yen{2,3}.txt will return yen2.txt yen3.txt even if one or both of those files don't exist. The reason it works with globs is that yen{2,3}.* literally expands to yen2.* yen3.* which is then globbed. From rosuav at gmail.com Mon Jan 5 22:33:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Jan 2015 08:33:41 +1100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <1420489988.4157893.209883497.15AB7246@webmail.messagingengine.com> References: <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> <1420489988.4157893.209883497.15AB7246@webmail.messagingengine.com> Message-ID: On Tue, Jan 6, 2015 at 7:33 AM, wrote: > On Mon, Jan 5, 2015, at 13:45, Skip Montanaro wrote: >> I only discovered this "shortcoming" (or "Bourne Shell dependency") >> relatively recently. I've been using bash for so long it never even >> occurred to me that {...} notation wasn't available in all shells. > > Brace expansion is technically not globbing. yen{2,3}.txt will return > yen2.txt yen3.txt even if one or both of those files don't exist. The > reason it works with globs is that yen{2,3}.* literally expands to > yen2.* yen3.* which is then globbed. Which, by the way, is the main reason I use brace expansion. Type "mv" and then fill in a file name using tab completion, then insert or delete something by editing it to have braces and a comma: mv some-long-file-name-blah-blah-blah mv some-{long-,}file-name-blah-blah-blah Et voila! Remove one word from a tab-completed file name. There's no way that a generic glob expansion tool can do everything that bash does, and I doubt anyone expects it. ChrisA From p.f.moore at gmail.com Mon Jan 5 23:20:49 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 5 Jan 2015 22:20:49 +0000 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <1420489988.4157893.209883497.15AB7246@webmail.messagingengine.com> References: <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> <1420489988.4157893.209883497.15AB7246@webmail.messagingengine.com> Message-ID: On 5 January 2015 at 20:33, wrote: > On Mon, Jan 5, 2015, at 05:10, Andrew Barnert wrote: >> It seems to me that if you want auto-globbing support on Windows, the >> "right" way to do it is to link in the fancy setargv instead of the >> default one. This handles wildcards exactly the same way the >> command.com/cmd.exe builtin commands do, which I suspect is what Windows >> users would actually be expecting of they passed a wildcard on the >> command line. (I think the docs no longer guarantee that this is true, >> but it's probably still true, and certainly closer to true than if you >> try to do it manually.) > > The problem with that is that if you do that you can no longer pass in > _non_-filename arguments that contain a question mark or asterisk (and > happen to match a file). Better to do it inside the program, when you > actually know the argument you're looking at is intended to be a > filename spec. Which, I assume, is _why_ it's not done by default when > you compile a C program. Just as a note - I find the fact that Python *doesn't* allow the C runtime to do its glob-mangling of the supplied command arguments a very useful feature, and I would not want it to be "fixed". The setargv behaviour in the MSVC runtime is full of arcane corner cases and quoting gotchas, and I wouldn't want it imposed on me by default. Paul From g.brandl at gmx.net Tue Jan 6 00:40:19 2015 From: g.brandl at gmx.net (Georg Brandl) Date: Tue, 06 Jan 2015 00:40:19 +0100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> <20150105171042.GA27426@ando.pearwood.info> <87fvbp14m4.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: On 01/05/2015 07:45 PM, Skip Montanaro wrote: > Indeed. I only have 2.7.2 available here at work. Here's what bash tells me on a > Linux box: > > % ls yen{2,3}.* > yen2.out yen2.png yen2.tradeyen3.out yen3.png yen3.trade > % ls yen[23].* > yen2.out yen2.png yen2.tradeyen3.out yen3.png yen3.trade [...] > Here's what the glob module tells me: > > % python > Python 2.7.2 (default, Nov 14 2012, 05:07:35) > [GCC 4.4.6 [TWW]] on linux3 > Type "help", "copyright", "credits" or "license" for more information. >>>> import glob >>>> glob.glob("yen{2,3}.*") > [] >>>> glob.glob("yen[23].*") > ['yen3.trade', 'yen2.out', 'yen2.trade', 'yen3.out', 'yen3.png', 'yen2.png'] > > I only discovered this "shortcoming" (or "Bourne Shell dependency") relatively > recently. I've been using bash for so long it never even occurred to me that > {...} notation wasn't available in all shells. Note that the {...} notation is not a part of globbing, it's a different mechanism (bash calls it brace expansion IIRC). With brace expansion, the different choices are *always* expanded regardless of the existence of matching filenames. Your pattern first gets expanded to "yen2.* yen3.*" and then globbing ensues (with the standard rule that if there is nothing matching e.g. yen2.* it is either given literally to the program or the command line is rejected, depending on the shell). => I wouldn't expect the Python glob module to perform brace expansion. cheers, Georg From steve at pearwood.info Tue Jan 6 00:57:10 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 6 Jan 2015 10:57:10 +1100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: References: <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> <20150105171042.GA27426@ando.pearwood.info> Message-ID: <20150105235710.GB27426@ando.pearwood.info> On Tue, Jan 06, 2015 at 04:14:38AM +1100, Chris Angelico wrote: > On Tue, Jan 6, 2015 at 4:10 AM, Steven D'Aprano wrote: > > * If you want to apply globs to something other than file names, > > the right module to use would probably be globbing.generic > > (or possible fnmatch directly). > > To clarify: Do you mean "something other than names of > currently-existing files", or "something other than valid names for > the local file system", or something else? For instance, suppose you > write an unarchiver (in case we don't have enough of them already, of > course), and you can "python unarchive.py archivename *.txt" to > extract all files matching *.txt. The globbing would be done against > some sort of internal index, but the names would have to be valid for > the local file system, or you wouldn't be able to create them. Which > module should you use? fnmatch. I've had a look inside glob.py and it calls os.listdir directly, so you cannot use glob to match things other than actual existing files. (Well, I suppose you could if you monkey-patched the module, but lets not go there.) fnmatch, on the other hand, provides the right tool for matching names other than actual file names: fnmatch.filter(names, pattern). (Well, almost the right tool -- it has a few issues too.) To summarise: - the glob module returns only actual files in the file system; - the new globbing package will do the same, except it will use platform-specific wildcards where possible; - fnmatch continues as Python's generic "match globs against arbitrary strings" module (despite the name). -- Steven From steve at pearwood.info Tue Jan 6 01:14:09 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 6 Jan 2015 11:14:09 +1100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <87fvbp14m4.fsf@uwakimon.sk.tsukuba.ac.jp> References: <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> <20150105171042.GA27426@ando.pearwood.info> <87fvbp14m4.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: <20150106001408.GC27426@ando.pearwood.info> On Tue, Jan 06, 2015 at 03:09:39AM +0900, Stephen J. Turnbull wrote: > Steven D'Aprano writes: > > > The model I am proposing is that of the os and os.path modules: we > > import os and it does the right thing for the current platform. > > Which is normally "nothing" on POSIX, since the shell does it for > you. Or, if you're talking about what the shell does for you, while I > suppose there is a basic globbing defined by POSIX, but bash and zsh > go well beyond that, and they behave somewhat differently in corner > cases IIRC. All correct. > If the program is going to invoke a globbing function specifically, I > suppose it makes sense to default to the same behavior as on the > current platform, but it's not obvious that that's what the user > wants. I use bash on Windows; why settle for cmd.exe if you want the > power of the command line? It could even cause problems (is there a > reliable way to determine what the shell is, let alone whether it > implements globbing or not, on Windows?) I see that as an application issue, not a Python issue. As the author of the application, I have some flexibility: - Currently, I can not use glob.py at all, and my Unix users will be able to use globs, but most of my Windows users won't. - If I unconditionally use glob.py, my Unix users can not reliably specify filenames containing wildcards but my Windows users may (assuming that glob supports escaping, which it currently doesn't). - I can conditionally use glob or not, depending on the platform. - Or I can provide an application switch/preference which allows the user to decide whether to use wildcards or not. I don't know of any reliable way for a Python script to determine the current shell (there may not even be a shell!). If such a way exists, that would be good functionality to have. > > In particular, os.path will do the right thing for the current > > platform, but you can import ntpath, posixpath, genericpath etc. to > > get behaviour for a specific platform. > > But there *is* a RightThang for paths; the OS decides. Globbing is a > user preference thing. Not entirely user-preference. As Random's discussion has pointed out, there are issues with the way globbing is currently handled. For example, Windows doesn't support [...] wildcards and so most Windows users will expect to be able to specify [ and ] as ordinary characters. You can't do that with glob.py. Windows users who have bash installed are a very small minority :-) -- Steven From rosuav at gmail.com Tue Jan 6 01:25:37 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Jan 2015 11:25:37 +1100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <20150105235710.GB27426@ando.pearwood.info> References: <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150105005730.GR27426@ando.pearwood.info> <20150105020735.GU27426@ando.pearwood.info> <87lhlh2723.fsf@uwakimon.sk.tsukuba.ac.jp> <20150105171042.GA27426@ando.pearwood.info> <20150105235710.GB27426@ando.pearwood.info> Message-ID: On Tue, Jan 6, 2015 at 10:57 AM, Steven D'Aprano wrote: > On Tue, Jan 06, 2015 at 04:14:38AM +1100, Chris Angelico wrote: >> On Tue, Jan 6, 2015 at 4:10 AM, Steven D'Aprano wrote: >> > * If you want to apply globs to something other than file names, >> > the right module to use would probably be globbing.generic >> > (or possible fnmatch directly). >> >> Which module should you use [to match non-existing files]? > > fnmatch. I've had a look inside glob.py and it calls os.listdir > directly, so you cannot use glob to match things other than actual > existing files. (Well, I suppose you could if you monkey-patched the > module, but lets not go there.) > > fnmatch, on the other hand, provides the right tool for matching names > other than actual file names: fnmatch.filter(names, pattern). (Well, > almost the right tool -- it has a few issues too.) Ugh. That's poor naming, then. If this new globbing module happens, I would be a strong +1 on having 'globbing.generic' (or somesuch) to do this kind of thing, if only to fix the name. ChrisA From yawar.amin at gmail.com Tue Jan 6 02:59:20 2015 From: yawar.amin at gmail.com (Yawar Amin) Date: Mon, 05 Jan 2015 20:59:20 -0500 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> Message-ID: <54AB4178.3050508@gmail.com> On 2015-01-05 04:49, Andrew Barnert wrote: > ... paren continuation just concatenates the lines together. I'll quote this first, because it's the crux of the matter and what I failed to understand up until now. IIUC now, Python never actually 'relaxes' any indentation rules--a preprocessor just concatenates split lines (i.e. lines split with parens etc.) and then passes the result on to the parser? I guess pretty much everything else is made redundant by this one point. > ... I'm not sure what the return adds to it that you couldn't get just > from brace syntax. I was trying to avoid brace syntax as un-Pythonic. > You also seem to have invented a rule that a sequence of statements > has the value of the last statement as its value. Which requires first > inventing a rule that gives values to statements. I'll assume you > wanted to go with the same rule the interactive interpreter uses to > display a last value--an expression statement has its expression's > value, and any other kind of statement has None?) No, I was trying to say that whatever's inside the 'return: ...' block is evaluated, and then the last expression inside the block becomes the value of the block as a whole. No change would be required to any existing expressions or statements, or to the result of a normal sequence of statements. > Finally, are you sure your new return: isn't ambiguous without look > ahead or context? When the parser reads "if spam: return", is it > starting a return simple statement, or an expression statement that > starts with a return expression? Have you tried actually writing out > the grammar? Having the keyword be 'return' wasn't important to me; it could just as easily be a new one like 'do' or 'begin'. It's back to the drawing board for me, I guess :-) Regards, Yawar -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 834 bytes Desc: OpenPGP digital signature URL: From ncoghlan at gmail.com Tue Jan 6 05:36:01 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Tue, 6 Jan 2015 14:36:01 +1000 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150105011312.GS27426@ando.pearwood.info> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> Message-ID: On 5 January 2015 at 11:13, Steven D'Aprano wrote: > On Sun, Jan 04, 2015 at 11:01:08PM +1000, Nick Coghlan wrote: > >> For those curious as to "Why not the wiki?", a Sphinx project hosted >> on a pull request capable service like GitHub, BitBucket or Kallithea >> offers a much nicer workflow for reviewing of proposed changes, >> together with an integrated issue tracker for submitting proposals for >> updates (https://github.com/pypa/python-packaging-user-guide/ is the >> project behind packaging.python.org, for example). > > The concept of "proposed changes" goes completely against the grain of > community-managed content. Imagine if Wikipedia required you to make > pull requests. Wikipedia's typical equivalent of pull requests is when editors revert a page to an earlier version and move the discussion of the proposed change to an earlier version. This approach can be escalated to *actual* pull requests when the editors lock a page to disrupt an ongoing edit war. The "anyone can publish by default" approach has the advantage of significantly increasing editing throughput by streamlining the handling of non-controversial cases. The downside as a reader is that it achieves this by allowing a brief window where controversial changes can be published without first establishing consensus, which means you may be presented with inaccurate information on controversial topics depending on when you check a page. I think that model works well for the task of creating a collaborative encyclopaedia (where "eventually accurate" is good enough for almost all purposes, and lowering barriers to entry for casual contribution of corrections is a high priority), but I don't believe it's appropriate for the task of delegating the CPython core development team's reputation and authority to other groups. For that, a pre-commit review process, or a more explicit topic area delegation (like the Python Packaging Authority handling packaging.python.org), makes more sense to me: if we trust folks to maintain a module or topic area *in* the standard library, we should be able to trust them to provide reasonable and balanced recommendations regarding applications and libraries that are maintained *outside* the standard library. Regards, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From ncoghlan at gmail.com Tue Jan 6 05:43:33 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Tue, 6 Jan 2015 14:43:33 +1000 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <20150105103828.GA22528@k3> References: <20150105103828.GA22528@k3> Message-ID: On 5 January 2015 at 20:38, David Wilson wrote: > I have no problem with this being included somehow in the standard > library, but pathlib to me is all about the filesystem, whereas (as > others have pointed out), the Recycle Bin and associated concepts on > other OS relate pretty uniformly to the OS shell. > > There are many shell-related concepts that could be nicely exposed, but > again I don't think any of them belong in pathlib. For example, > labels/tags, owner application, icon, visibility flags, etc. Better tools for accessing typical extended file metadata would indeed be highly desirable (thumbnails/previews are another one that comes to mind). As with the recycle bin though, the generally preferred approach for standard library additions is incorporating existing modules that have been available through PyPI for some time, or else creating a derivative of such a project that meets other constraints of standard library inclusion (e.g. ipaddress vs the project it was based on, ipaddr). Unfortunately, most of the folks that need these cross-platform integration features are likely to be using a C/C++ toolkit that provides them (e.g. Gtk, Qt, wxWidgets), which significantly reduces the incentive for anyone to create a Python-specific abstraction that would be suitable for eventual inclusion in the standard library. Regards, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From ben+python at benfinney.id.au Tue Jan 6 07:26:52 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 06 Jan 2015 17:26:52 +1100 Subject: [Python-ideas] Encouraging more use of the Python wiki References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> Message-ID: <85tx04xw43.fsf@benfinney.id.au> "M.-A. Lemburg" writes: > [editing the Python wiki] requiring asking for editing rights > on the pydotorg-www mailing list. Which is a little annoying and > some work for the admins, but has resulted in the amount of > spam to go down to zero. We usually grant the editing requests > within a day. I quite understand the motivation for this. It does need to be recognised that this will dramatically reduce the number of pople who will pass that hurdle to edit the wiki, and thus the wiki loses a lot of edits (both helpful and unhelpful) it might otherwise have. Thanks to those doing the work to maintain Python community infrastructure. -- \ ?If you can do no good, at least do no harm.? ?_Slapstick_, | `\ Kurt Vonnegut | _o__) | Ben Finney From ethan at stoneleaf.us Tue Jan 6 07:34:02 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 05 Jan 2015 22:34:02 -0800 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <85tx04xw43.fsf@benfinney.id.au> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> Message-ID: <54AB81DA.7050502@stoneleaf.us> On 01/05/2015 10:26 PM, Ben Finney wrote: > "M.-A. Lemburg" writes: >> [editing the Python wiki] requiring asking for editing rights >> on the pydotorg-www mailing list. Which is a little annoying and >> some work for the admins, but has resulted in the amount of >> spam to go down to zero. We usually grant the editing requests >> within a day. > It does need to be recognised that this will dramatically reduce the > number of pople who will pass that hurdle to edit the wiki, and thus the > wiki loses a lot of edits (both helpful and unhelpful) it might > otherwise have. At least the edits being made now are by folks who care. Better fewer edits than a site full of little but spam. > Thanks to those doing the work to maintain Python community > infrastructure. Seconded. -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From abarnert at yahoo.com Tue Jan 6 09:25:25 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Tue, 6 Jan 2015 09:25:25 +0100 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <54AB4178.3050508@gmail.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> Message-ID: <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> On Jan 6, 2015, at 2:59, Yawar Amin wrote: > On 2015-01-05 04:49, Andrew Barnert wrote: > >> You also seem to have invented a rule that a sequence of statements >> has the value of the last statement as its value. Which requires first >> inventing a rule that gives values to statements. I'll assume you >> wanted to go with the same rule the interactive interpreter uses to >> display a last value--an expression statement has its expression's >> value, and any other kind of statement has None?) > > No, I was trying to say that whatever's inside the 'return: ...' block > is evaluated, and then the last expression inside the block becomes the > value of the block as a whole. No change would be required to any > existing expressions or statements, or to the result of a normal > sequence of statements. I think you're missing another important point here: statements and expressions are different things. Blocks are made up of statements, not expressions, and statements don't have values. This is different from many other languages like C, Ruby, or JavaScript, where as many things as possible are expressions (and therefore have values), so a block is (oversimplifying a bit) just a sequence of expressions separated by semicolons and stuck inside braces, and therefore it has a last value. One type of statement, the expression statement, is just an expression on a line by itself (or between semicolons), so you _could_ invent a rule pretty easily that expression statements have the value of their expression, and all other statements have a value of None, and a block has the value of its last statement. This is basically the same rule used by the interactive REPL for displaying the repr of what you've typed and setting the _ variable, so it wouldn't be a huge stretch to add the same rule to the language itself--but it would still be a new rule, and a significant change to the internals of the interpreter, even though it would only be useful in this new context. From mal at egenix.com Tue Jan 6 09:31:50 2015 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 06 Jan 2015 09:31:50 +0100 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <85tx04xw43.fsf@benfinney.id.au> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> Message-ID: <54AB9D76.7030105@egenix.com> On 06.01.2015 07:26, Ben Finney wrote: > "M.-A. Lemburg" writes: > >> [editing the Python wiki] requiring asking for editing rights >> on the pydotorg-www mailing list. Which is a little annoying and >> some work for the admins, but has resulted in the amount of >> spam to go down to zero. We usually grant the editing requests >> within a day. > > I quite understand the motivation for this. > > It does need to be recognised that this will dramatically reduce the > number of pople who will pass that hurdle to edit the wiki, and thus the > wiki loses a lot of edits (both helpful and unhelpful) it might > otherwise have. We might lose some occasional quick typo fixes, but it seems that those genuinely interested in helping with the wiki don't have a problem asking on the list. To reduce the problem I had created a list of user names who had made good edits in the months before the change. The only nit I still have with the setup is that it's not necessarily apparent for new users how to get editing rights. There's a section on the front page, but you don't see this when looking at a random page. > Thanks to those doing the work to maintain Python community > infrastructure. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From abarnert at yahoo.com Tue Jan 6 10:29:32 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Tue, 6 Jan 2015 10:29:32 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20150105103828.GA22528@k3> Message-ID: <9A57680C-9629-4A22-91FF-E0625EA95457@yahoo.com> On Jan 6, 2015, at 5:43, Nick Coghlan wrote: > On 5 January 2015 at 20:38, David Wilson wrote: >> I have no problem with this being included somehow in the standard >> library, but pathlib to me is all about the filesystem, whereas (as >> others have pointed out), the Recycle Bin and associated concepts on >> other OS relate pretty uniformly to the OS shell. >> >> There are many shell-related concepts that could be nicely exposed, but >> again I don't think any of them belong in pathlib. For example, >> labels/tags, owner application, icon, visibility flags, etc. > > Better tools for accessing typical extended file metadata would indeed > be highly desirable (thumbnails/previews are another one that comes to > mind). As with the recycle bin though, the generally preferred > approach for standard library additions is incorporating existing > modules that have been available through PyPI for some time, or else > creating a derivative of such a project that meets other constraints > of standard library inclusion (e.g. ipaddress vs the project it was > based on, ipaddr). > > Unfortunately, most of the folks that need these cross-platform > integration features are likely to be using a C/C++ toolkit that > provides them (e.g. Gtk, Qt, wxWidgets), which significantly reduces > the incentive for anyone to create a Python-specific abstraction that > would be suitable for eventual inclusion in the standard library. I'm not sure that's really unfortunate. First, a framework like Qt or wx is maintained by people who think about nothing but desktop and GUI integration on the major platforms. They track changes pretty quickly (especially compared to the Python stdlib). A few years back, when Apple got rid of legacy-style preference files, I had a Qt app that I was able to fix just by updating to the next version of Qt, and a non-Qt app that I had to fix by reseatching, writing, and testing, a wrapper that "temporarily" (of course it's still there in 2015...) stashes the entire legacy file as an encoded string in the new-style prefs database. What are the odds a Python stdlib solution (or even a third-party Python lib with less than 1/20th the user base, community, and corporate support) would have fixed it for me automatically in time for my next release the way Qt did? Also, the fact that Qt and wx are complete frameworks means they can make assumptions that allow for simpler solutions. A Qt library knows how to check whether there's a runloop and, if there is, knows it'll be a Qt runloop, and, if not, knows how to create a short-term blocking runloop and background thread, and it also knows how to pass signals from background threads to the runloop, and so on; this means Qt could just use the (10.5+, and still not deprecated as of 10.10) NSWorkspace API for trashing on Mac, because none of its deficiencies apply to any Qt app. A library meant to be used generally across all kinds of apps can't do that. Obviously this is also a weakness, because not all cross-platform desktop-integration apps really need a full framework? but many do. And again, many simple tools don't need to be cross-platform (like my completely separate 3-line trash tools for each platform that I use), or don't need full generality (my Mac trash tool doesn't need to work on 10.6, or to be App Store compliant; my Ubuntu trash tool doesn't have to know how Unity deals with trashing over CIFS because I only have two CIFS mounts and they both do server-side automatic recycling; etc.). From ncoghlan at gmail.com Tue Jan 6 11:25:01 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Tue, 6 Jan 2015 20:25:01 +1000 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: <9A57680C-9629-4A22-91FF-E0625EA95457@yahoo.com> References: <20150105103828.GA22528@k3> <9A57680C-9629-4A22-91FF-E0625EA95457@yahoo.com> Message-ID: On 6 January 2015 at 19:29, Andrew Barnert wrote: > On Jan 6, 2015, at 5:43, Nick Coghlan wrote: >> Unfortunately, most of the folks that need these cross-platform >> integration features are likely to be using a C/C++ toolkit that >> provides them (e.g. Gtk, Qt, wxWidgets), which significantly reduces >> the incentive for anyone to create a Python-specific abstraction that >> would be suitable for eventual inclusion in the standard library. > > I'm not sure that's really unfortunate. > > First, a framework like Qt or wx is maintained by people who think about nothing but desktop and GUI integration on the major platforms. They track changes pretty quickly (especially compared to the Python stdlib). A few years back, when Apple got rid of legacy-style preference files, I had a Qt app that I was able to fix just by updating to the next version of Qt, and a non-Qt app that I had to fix by reseatching, writing, and testing, a wrapper that "temporarily" (of course it's still there in 2015...) stashes the entire legacy file as an encoded string in the new-style prefs database. What are the odds a Python stdlib solution (or even a third-party Python lib with less than 1/20th the user base, community, and corporate support) would have fixed it for me automatically in time for my next release the way Qt did? > > Also, the fact that Qt and wx are complete frameworks means they can make assumptions that allow for simpler solutions. A Qt library knows how to check whether there's a runloop and, if there is, knows it'll be a Qt runloop, and, if not, knows how to create a short-term blocking runloop and background thread, and it also knows how to pass signals from background threads to the runloop, and so on; this means Qt could just use the (10.5+, and still not deprecated as of 10.10) NSWorkspace API for trashing on Mac, because none of its deficiencies apply to any Qt app. A library meant to be used generally across all kinds of apps can't do that. Obviously this is also a weakness, because not all cross-platform desktop-integration apps really need a full framework? but many do. > > And again, many simple tools don't need to be cross-platform (like my completely separate 3-line trash tools for each platform that I use), or don't need full generality (my Mac trash tool doesn't need to work on 10.6, or to be App Store compliant; my Ubuntu trash tool doesn't have to know how Unity deals with trashing over CIFS because I only have two CIFS mounts and they both do server-side automatic recycling; etc.). Yes, there's certainly a lot of value in adopting an existing specialist toolkit when writing rich client applications. The key problem is that it isn't easy to start with the provided Tcl/Tk support in the standard library (to avoid introducing a large external dependency) and then later migrate to one of the other third party toolkits (if the basic functionality proves insufficient). While an asyncio-style pluggable solution may be one possible option for that (i.e. provide default implementations of features which may be fairly basic, but allow them to be replaced by full featured implementations backed by Gtk/Qt/wxWidgets/etc), that kind of abstraction layer design is extraordinarily difficult to design well. It's hard enough even in cases like wsgiref and asyncio that are relatively simple compared to the services a full rich client application will expect to have available. Regards, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From abarnert at yahoo.com Tue Jan 6 14:43:54 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Tue, 6 Jan 2015 14:43:54 +0100 Subject: [Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin In-Reply-To: References: <20150105103828.GA22528@k3> <9A57680C-9629-4A22-91FF-E0625EA95457@yahoo.com> Message-ID: On Jan 6, 2015, at 11:25, Nick Coghlan wrote: > On 6 January 2015 at 19:29, Andrew Barnert wrote: >> On Jan 6, 2015, at 5:43, Nick Coghlan wrote: >>> Unfortunately, most of the folks that need these cross-platform >>> integration features are likely to be using a C/C++ toolkit that >>> provides them (e.g. Gtk, Qt, wxWidgets), which significantly reduces >>> the incentive for anyone to create a Python-specific abstraction that >>> would be suitable for eventual inclusion in the standard library. >> >> I'm not sure that's really unfortunate. >> >> First, a framework like Qt or wx is maintained by people who think about nothing but desktop and GUI integration on the major platforms. They track changes pretty quickly (especially compared to the Python stdlib). A few years back, when Apple got rid of legacy-style preference files, I had a Qt app that I was able to fix just by updating to the next version of Qt, and a non-Qt app that I had to fix by reseatching, writing, and testing, a wrapper that "temporarily" (of course it's still there in 2015...) stashes the entire legacy file as an encoded string in the new-style prefs database. What are the odds a Python stdlib solution (or even a third-party Python lib with less than 1/20th the user base, community, and corporate support) would have fixed it for me automatically in time for my next release the way Qt did? >> >> Also, the fact that Qt and wx are complete frameworks means they can make assumptions that allow for simpler solutions. A Qt library knows how to check whether there's a runloop and, if there is, knows it'll be a Qt runloop, and, if not, knows how to create a short-term blocking runloop and background thread, and it also knows how to pass signals from background threads to the runloop, and so on; this means Qt could just use the (10.5+, and still not deprecated as of 10.10) NSWorkspace API for trashing on Mac, because none of its deficiencies apply to any Qt app. A library meant to be used generally across all kinds of apps can't do that. Obviously this is also a weakness, because not all cross-platform desktop-integration apps really need a full framework? but many do. >> >> And again, many simple tools don't need to be cross-platform (like my completely separate 3-line trash tools for each platform that I use), or don't need full generality (my Mac trash tool doesn't need to work on 10.6, or to be App Store compliant; my Ubuntu trash tool doesn't have to know how Unity deals with trashing over CIFS because I only have two CIFS mounts and they both do server-side automatic recycling; etc.). > > Yes, there's certainly a lot of value in adopting an existing > specialist toolkit when writing rich client applications. The key > problem is that it isn't easy to start with the provided Tcl/Tk > support in the standard library (to avoid introducing a large external > dependency) and then later migrate to one of the other third party > toolkits (if the basic functionality proves insufficient). > While an asyncio-style pluggable solution may be one possible option > for that (i.e. provide default implementations of features which may > be fairly basic, but allow them to be replaced by full featured > implementations backed by Gtk/Qt/wxWidgets/etc), that kind of > abstraction layer design is extraordinarily difficult to design well. > It's hard enough even in cases like wsgiref and asyncio that are > relatively simple compared to the services a full rich client > application will expect to have available. Yes, and even besides the difference in complexity, even the most basic elements--the API for the runloop and message maps (wx), signals/slots (Qt), event handlers (Tk), etc.--are pretty hard to abstract away. For servers, a reactor is a reactor, but for GUIs, a signal/slot system is not a message pump/message map system. And whichever abstraction you pick, adapting it to work with the other abstractions is no fun. (Look at how long the TkAqua Cocoa port took, and how much Cocoa functionality is still missing.) From ncoghlan at gmail.com Tue Jan 6 16:25:39 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Wed, 7 Jan 2015 01:25:39 +1000 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <54AB4178.3050508@gmail.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> Message-ID: On 6 January 2015 at 11:59, Yawar Amin wrote: > On 2015-01-05 04:49, Andrew Barnert wrote: >> ... paren continuation just concatenates the lines together. > > I'll quote this first, because it's the crux of the matter and what I > failed to understand up until now. IIUC now, Python never actually > 'relaxes' any indentation rules--a preprocessor just concatenates split > lines (i.e. lines split with parens etc.) and then passes the result on > to the parser? Not quite. INDENT, DEDENT and NEWLINE are possible tokens generated by the tokeniser. They're only generated to delimit statements, never inside expressions - by the time the parser itself gets involved, the original whitespace has been elided by the tokenisation process. > It's back to the drawing board for me, I guess :-) You may find http://python-notes.curiousefficiency.org/en/latest/pep_ideas/suite_expr.html an interesting read. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From p.f.moore at gmail.com Tue Jan 6 17:22:23 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 6 Jan 2015 16:22:23 +0000 Subject: [Python-ideas] Possible new itertool: comm() Message-ID: In writing a utility script today, I found myself needing to do something similar to what the Unix "comm" utility does - take two sorted iterators, and partition the values into "only in the first", "only in the second", and "in both" groups. I couldn't find an obvious implementation around, so I ended up having to write my own (see below). Would this be something useful to add to the itertools module? The reasons I think it might be worth including in the stdlib are: 1. The implementation is somewhat tricky to get right, especially the edge cases (I'm not 100% sure my implementation is completely right in this regard). So implementing it yourself each time is error-prone and time consuming. 2. The times I've needed this have been ad-hoc scripts (I'm on Windows, so while a Unix user might use a quick shell pipeline with comm, that's less convenient for me) where depending on a 3rd party distribution from PyPI is less ideal. There's plenty of room for API bikeshedding here, but the basic algorithm remains the same. What do people think? Paul def comm(it1, it2): """Partition 2 sorted iterators into common, only in 1st, and only in 2nd. >>> list(comm([1,2,3], [2,3,4])) [('<', 1), ('=', 2), ('=', 3), ('>', 4)] >>> list(comm([0,1,2,3], [2,3,4,5])) [('<', 0), ('<', 1), ('=', 2), ('=', 3), ('>', 4), ('>', 5)] >>> list(comm([0,1,2,3,6], [2,3,4,5])) [('<', 0), ('<', 1), ('=', 2), ('=', 3), ('>', 4), ('>', 5), ('<', 6)] >>> list(comm([0,1], [])) [('<', 0), ('<', 1)] >>> list(comm([], [0,1])) [('>', 0), ('>', 1)] >>> list(comm([0,1], [0,1])) [('=', 0), ('=', 1)] >>> list(comm([], [])) [] """ it1 = iter(it1) it2 = iter(it2) it1_finished = False it2_finished = False try: v1 = next(it1) except StopIteration: it1_finished = True try: v2 = next(it2) except StopIteration: it2_finished = True while not (it1_finished or it2_finished): if v1 < v2: yield ('<', v1) try: v1 = next(it1) except StopIteration: it1_finished = True elif v1 > v2: yield ('>', v2) try: v2 = next(it2) except StopIteration: it2_finished = True else: yield ('=', v1) try: v1 = next(it1) except StopIteration: it1_finished = True try: v2 = next(it2) except StopIteration: it2_finished = True if it1_finished and not it2_finished: yield ('>', v2) for v2 in it2: yield ('>', v2) if it2_finished and not it1_finished: yield ('<', v1) for v1 in it1: yield ('<', v1) if __name__ == '__main__': import doctest doctest.testmod() From graffatcolmingov at gmail.com Tue Jan 6 17:33:16 2015 From: graffatcolmingov at gmail.com (Ian Cordasco) Date: Tue, 6 Jan 2015 10:33:16 -0600 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: Message-ID: On Tue, Jan 6, 2015 at 10:22 AM, Paul Moore wrote: > In writing a utility script today, I found myself needing to do > something similar to what the Unix "comm" utility does - take two > sorted iterators, and partition the values into "only in the first", > "only in the second", and "in both" groups. > > I couldn't find an obvious implementation around, so I ended up having > to write my own (see below). > > Would this be something useful to add to the itertools module? The > reasons I think it might be worth including in the stdlib are: > > 1. The implementation is somewhat tricky to get right, especially the > edge cases (I'm not 100% sure my implementation is completely right in > this regard). So implementing it yourself each time is error-prone and > time consuming. > 2. The times I've needed this have been ad-hoc scripts (I'm on > Windows, so while a Unix user might use a quick shell pipeline with > comm, that's less convenient for me) where depending on a 3rd party > distribution from PyPI is less ideal. > > There's plenty of room for API bikeshedding here, but the basic > algorithm remains the same. > > What do people think? > > Paul > > def comm(it1, it2): > """Partition 2 sorted iterators into common, only in 1st, and only in 2nd. > > >>> list(comm([1,2,3], [2,3,4])) > [('<', 1), ('=', 2), ('=', 3), ('>', 4)] > >>> list(comm([0,1,2,3], [2,3,4,5])) > [('<', 0), ('<', 1), ('=', 2), ('=', 3), ('>', 4), ('>', 5)] > >>> list(comm([0,1,2,3,6], [2,3,4,5])) > [('<', 0), ('<', 1), ('=', 2), ('=', 3), ('>', 4), ('>', 5), ('<', 6)] > >>> list(comm([0,1], [])) > [('<', 0), ('<', 1)] > >>> list(comm([], [0,1])) > [('>', 0), ('>', 1)] > >>> list(comm([0,1], [0,1])) > [('=', 0), ('=', 1)] > >>> list(comm([], [])) > [] > """ > > it1 = iter(it1) > it2 = iter(it2) > > it1_finished = False > it2_finished = False > try: > v1 = next(it1) > except StopIteration: > it1_finished = True > try: > v2 = next(it2) > except StopIteration: > it2_finished = True > while not (it1_finished or it2_finished): > if v1 < v2: > yield ('<', v1) > try: > v1 = next(it1) > except StopIteration: > it1_finished = True > elif v1 > v2: > yield ('>', v2) > try: > v2 = next(it2) > except StopIteration: > it2_finished = True > else: > yield ('=', v1) > try: > v1 = next(it1) > except StopIteration: > it1_finished = True > try: > v2 = next(it2) > except StopIteration: > it2_finished = True > > if it1_finished and not it2_finished: > yield ('>', v2) > for v2 in it2: > yield ('>', v2) > if it2_finished and not it1_finished: > yield ('<', v1) > for v1 in it1: > yield ('<', v1) > > if __name__ == '__main__': > import doctest > doctest.testmod() > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ So my question is how well with this work with generators/iterators? Your examples use lists, but it would be impossible to use this with anything that isn't finite right? From p.f.moore at gmail.com Tue Jan 6 17:44:04 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 6 Jan 2015 16:44:04 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: Message-ID: On 6 January 2015 at 16:33, Ian Cordasco wrote: > So my question is how well with this work with generators/iterators? > Your examples use lists, but it would be impossible to use this with > anything that isn't finite right? The examples use lists because I was using doctest and needed checkable output. But I think it should work fine with any (finite) iterator. I don't see a problem with the algorithm if I use infinite iterators (the algorithm is one-pass and generates results on demand) but I haven't tested it explicitly. [pause, test...] Yep, looks OK: >>> import itertools >>> c1 = itertools.count() >>> c2 = itertools.count(3) >>> output = comm(c1, c2) >>> next(output) ('<', 0) >>> next(output) ('<', 1) >>> next(output) ('<', 2) >>> next(output) ('=', 3) Paul From rosuav at gmail.com Tue Jan 6 17:46:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 Jan 2015 03:46:21 +1100 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: Message-ID: On Wed, Jan 7, 2015 at 3:33 AM, Ian Cordasco wrote: > So my question is how well with this work with generators/iterators? > Your examples use lists, but it would be impossible to use this with > anything that isn't finite right? I think it ought to work fine on infinite iterators, based on my reading of the code. Obviously it would itself be infinite in that case. With one infinite and one finite iterator, it'll eventually get into one of the loops at the end, and forever yield from the infinite iterator; if both are infinite, it'll never break out of the primary loop, and continue consuming values from one or the other and yielding tuples: >>> def count_by(x): n = 0 while True: n += x yield n >>> it = comm(count_by(2), count_by(3)) >>> next(it) ('<', 2) >>> next(it) ('>', 3) >>> next(it) ('<', 4) >>> next(it) ('=', 6) ... etc etc etc ... ChrisA From rosuav at gmail.com Tue Jan 6 17:47:52 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 Jan 2015 03:47:52 +1100 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: Message-ID: On Wed, Jan 7, 2015 at 3:46 AM, Chris Angelico wrote: >>>> def count_by(x): > n = 0 > while True: > n += x > yield n And thanks to the magic of sloppy editing, I just rewrote itertools.count(). In my own testing, there was a print call to show what the internal iterators were yielding, but that got left out, leaving this looking a little silly. Anyhow. ChrisA From raymond.hettinger at gmail.com Tue Jan 6 18:14:01 2015 From: raymond.hettinger at gmail.com (Raymond Hettinger) Date: Tue, 6 Jan 2015 09:14:01 -0800 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: Message-ID: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> > On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: > > In writing a utility script today, I found myself needing to do > something similar to what the Unix "comm" utility does - take two > sorted iterators, and partition the values into "only in the first", > "only in the second", and "in both" groups. As far as I can tell, this would be a very rare need. Raymond From abarnert at yahoo.com Tue Jan 6 18:39:57 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Tue, 6 Jan 2015 17:39:57 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: Message-ID: On Jan 6, 2015, at 16:22, Paul Moore wrote: > 2. The times I've needed this have been ad-hoc scripts (I'm on > Windows, so while a Unix user might use a quick shell pipeline with > comm, that's less convenient for me) where depending on a 3rd party > distribution from PyPI is less ideal. Why? Current standard Windows installers include pip, and being pure Python you won't need a compiler, so what's wrong with requiring a PyPI distribution? (Of course that means you need to be able to count on a relatively recent Python 3.4+/2.7+, but it's hard to see how that's worse than something in a future version of the stdlib, which would mean you need to be able to count on 3.5+.) And I'll bet if you submit this as a pull request to more-itertools, it'll be accepted, meaning you don't even have to create or maintain a PyPI project. From steve at pearwood.info Tue Jan 6 19:00:05 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 7 Jan 2015 05:00:05 +1100 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: Message-ID: <20150106180005.GE19387@ando.pearwood.info> On Tue, Jan 06, 2015 at 04:22:23PM +0000, Paul Moore wrote: > In writing a utility script today, I found myself needing to do > something similar to what the Unix "comm" utility does - take two > sorted iterators, and partition the values into "only in the first", > "only in the second", and "in both" groups. It seems awfully specialised to me, so I'm not sure that it belongs in itertools. But for what it's worth, here's my implementation which I think is easier to understand than yours, and covers the unfortunate case where you have unorderable items such as float NANs in your data. def comm(values1, values2): """Partition 2 sorted iterators into common, only in 1st, and only in 2nd. >>> list(comm([1,2,3], [2,3,4])) [('<', 1), ('=', 2), ('=', 3), ('>', 4)] >>> list(comm([0,1,2,3], [2,3,4,5])) [('<', 0), ('<', 1), ('=', 2), ('=', 3), ('>', 4), ('>', 5)] >>> list(comm([0,1,2,3,6], [2,3,4,5])) [('<', 0), ('<', 1), ('=', 2), ('=', 3), ('>', 4), ('>', 5), ('<', 6)] >>> list(comm([0,1], [])) [('<', 0), ('<', 1)] >>> list(comm([], [0,1])) [('>', 0), ('>', 1)] >>> list(comm([0,1], [0,1])) [('=', 0), ('=', 1)] >>> list(comm([], [])) [] >>> list(comm([1,2,3,4], [2,3,float('nan'),4])) [('<', 1), ('=', 2), ('=', 3), ('?', (4, nan)), ('>', 4)] """ MISSING = object() it1 = iter(values1) it2 = iter(values2) a = next(it1, MISSING) b = next(it2, MISSING) while True: if a is MISSING: if b is MISSING: return yield ('>', b) for x in it2: yield ('>', x) return if b is MISSING: assert a is not MISSING yield ('<', a) for x in it1: yield ('<', x) return if a == b: yield ('=', a) # Or could use b. a = next(it1, MISSING) b = next(it2, MISSING) elif a < b: yield ('<', a) a = next(it1, MISSING) elif a > b: yield ('>', b) b = next(it2, MISSING) else: # Unorderable a and b, like float NANs. # Maybe we should raise instead? yield ('?', (a, b)) a = next(it1, MISSING) b = next(it2, MISSING) If you prefer this version, feel free to just use it. If you need a licence, consider it being under the MIT licence. (Over the next day or so, time permitting, I'll try to put this on ActiveState's Python recipes and make the licence more official.) -- Steve From p.f.moore at gmail.com Tue Jan 6 19:22:44 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 6 Jan 2015 18:22:44 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> References: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> Message-ID: On 6 January 2015 at 17:14, Raymond Hettinger wrote: >> On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: >> >> In writing a utility script today, I found myself needing to do >> something similar to what the Unix "comm" utility does - take two >> sorted iterators, and partition the values into "only in the first", >> "only in the second", and "in both" groups. > > As far as I can tell, this would be a very rare need. It's come up for me a few times, usually when trying to check two lists of files to see which ones have been missed by a program, and which ones the program thinks are present but no longer exist. Its use cases are about as common as those of the Unix "comm" tool :-) But I take your point, it's not *that* common. Paul From ethan at stoneleaf.us Tue Jan 6 19:28:23 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 06 Jan 2015 10:28:23 -0800 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <20150106180005.GE19387@ando.pearwood.info> References: <20150106180005.GE19387@ando.pearwood.info> Message-ID: <54AC2947.3000209@stoneleaf.us> On 01/06/2015 10:00 AM, Steven D'Aprano wrote: > a = next(it1, MISSING) > b = next(it2, MISSING) Don't forget to guard your next calls -- RunTimeError would not be a friendly way to stop iterating. ;) -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From p.f.moore at gmail.com Tue Jan 6 19:29:33 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 6 Jan 2015 18:29:33 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: Message-ID: On 6 January 2015 at 17:39, Andrew Barnert wrote: >> 2. The times I've needed this have been ad-hoc scripts (I'm on >> Windows, so while a Unix user might use a quick shell pipeline with >> comm, that's less convenient for me) where depending on a 3rd party >> distribution from PyPI is less ideal. > > Why? Current standard Windows installers include pip, and being pure Python you won't need a compiler, so what's wrong with requiring a PyPI distribution? (Of course that means you need to be able to count on a relatively recent Python 3.4+/2.7+, but it's hard to see how that's worse than something in a future version of the stdlib, which would mean you need to be able to count on 3.5+.) Well, I usually write my "little utility scripts" as simple .py files to be run with the system Python. I tend to use them on multiple machines. So unless a dependency is one of the modules I routinely install (things like requests) the process goes run script, oops, needed that distribution, pip install dist, run it again. Not a big issue certainly (and hardly a showstopper) but annoying. And it does mean I'd need to make a PyPI project for my personal utility functions, which doesn't really seem an appropriate use for PyPI, tbh. Requiring Python 3.5+ isn't a big deal, I routinely put the newest version of Python on all my machines. The ones I can't tend to be "secure", meaning I have no access to PyPI either :-( > And I'll bet if you submit this as a pull request to more-itertools, it'll be accepted, meaning you don't even have to create or maintain a PyPI project. Thanks for the suggestion, I might do that. Paul From p.f.moore at gmail.com Tue Jan 6 19:30:11 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 6 Jan 2015 18:30:11 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <54AC2947.3000209@stoneleaf.us> References: <20150106180005.GE19387@ando.pearwood.info> <54AC2947.3000209@stoneleaf.us> Message-ID: On 6 January 2015 at 18:28, Ethan Furman wrote: > On 01/06/2015 10:00 AM, Steven D'Aprano wrote: > >> a = next(it1, MISSING) >> b = next(it2, MISSING) > > Don't forget to guard your next calls -- RunTimeError would not be a friendly way to stop iterating. ;) Doesn't the second argument get used instead of raising StopIteration? Paul From solipsis at pitrou.net Tue Jan 6 19:36:55 2015 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 6 Jan 2015 19:36:55 +0100 Subject: [Python-ideas] Possible new itertool: comm() References: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> Message-ID: <20150106193655.2be8dcf0@fsol> On Tue, 6 Jan 2015 18:22:44 +0000 Paul Moore wrote: > On 6 January 2015 at 17:14, Raymond Hettinger > wrote: > >> On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: > >> > >> In writing a utility script today, I found myself needing to do > >> something similar to what the Unix "comm" utility does - take two > >> sorted iterators, and partition the values into "only in the first", > >> "only in the second", and "in both" groups. > > > > As far as I can tell, this would be a very rare need. > > It's come up for me a few times, usually when trying to check two > lists of files to see which ones have been missed by a program, and > which ones the program thinks are present but no longer exist. Why don't you use sets for such things? Your iterator is really only useful for huge or unhashable inputs. Regards Antoine. From p.f.moore at gmail.com Tue Jan 6 19:40:40 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 6 Jan 2015 18:40:40 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <20150106180005.GE19387@ando.pearwood.info> References: <20150106180005.GE19387@ando.pearwood.info> Message-ID: On 6 January 2015 at 18:00, Steven D'Aprano wrote: > But for what it's worth, here's my implementation which I > think is easier to understand than yours, Possibly - it's a trade-off between using a sentinel vs explicitly catching the exceptions. I'm on the fence, personally. > and covers the unfortunate > case where you have unorderable items such as float NANs in your data. Technically I don't think this is possible, as the input iterators need to be sorted, and that property will be violated if there are unorderable items in there... Paul From ethan at stoneleaf.us Tue Jan 6 19:43:23 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 06 Jan 2015 10:43:23 -0800 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: <20150106180005.GE19387@ando.pearwood.info> <54AC2947.3000209@stoneleaf.us> Message-ID: <54AC2CCB.5040703@stoneleaf.us> On 01/06/2015 10:30 AM, Paul Moore wrote: > On 6 January 2015 at 18:28, Ethan Furman wrote: >> On 01/06/2015 10:00 AM, Steven D'Aprano wrote: >> >>> a = next(it1, MISSING) >>> b = next(it2, MISSING) >> >> Don't forget to guard your next calls -- RunTimeError would not be a friendly way to stop iterating. ;) > > Doesn't the second argument get used instead of raising StopIteration? Yup, it sure does. Guess I should have paid more attention to that niggling feeling that I was missing something. ;) On the other hand, I figured even if I was wrong it wouldn't hurt to increase awareness about the change to generators. -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From p.f.moore at gmail.com Tue Jan 6 19:44:22 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 6 Jan 2015 18:44:22 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <20150106193655.2be8dcf0@fsol> References: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> <20150106193655.2be8dcf0@fsol> Message-ID: On 6 January 2015 at 18:36, Antoine Pitrou wrote: > On Tue, 6 Jan 2015 18:22:44 +0000 > Paul Moore wrote: >> On 6 January 2015 at 17:14, Raymond Hettinger >> wrote: >> >> On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: >> >> >> >> In writing a utility script today, I found myself needing to do >> >> something similar to what the Unix "comm" utility does - take two >> >> sorted iterators, and partition the values into "only in the first", >> >> "only in the second", and "in both" groups. >> > >> > As far as I can tell, this would be a very rare need. >> >> It's come up for me a few times, usually when trying to check two >> lists of files to see which ones have been missed by a program, and >> which ones the program thinks are present but no longer exist. > > Why don't you use sets for such things? Your iterator is really only > useful for huge or unhashable inputs. For the case described you're right. I had a case the other day where one of the problems was that one list had duplicates, and I needed to see that ([1,1,2,2] vs [1,2] needed to show [1,2] as "only in the first list" and [1,2] as "in both"). I could probably have used counters. But I was starting from thinking that I had a pair of sorted lists, and "in the Unix shell I'd use comm"...) Paul From p.f.moore at gmail.com Tue Jan 6 19:47:46 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 6 Jan 2015 18:47:46 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <54AC2CCB.5040703@stoneleaf.us> References: <20150106180005.GE19387@ando.pearwood.info> <54AC2947.3000209@stoneleaf.us> <54AC2CCB.5040703@stoneleaf.us> Message-ID: On 6 January 2015 at 18:43, Ethan Furman wrote: > Yup, it sure does. Guess I should have paid more attention to that niggling feeling that I was missing something. ;) > On the other hand, I figured even if I was wrong it wouldn't hurt to increase awareness about the change to generators. I should probably point out that when writing my code, I was conscious of the generator change and took special case of catching all of the StopIterations that might leak out. It's probably good that I was made to think carefully about it, but all those try...except blocks sure look ugly. (And Steven's version with its sentinel value doesn't look much better, with all those comparisons against a magic value - it's just a generally annoying algorithm with all the code paths for corner cases). Paul From guido at python.org Tue Jan 6 19:47:44 2015 From: guido at python.org (Guido van Rossum) Date: Tue, 6 Jan 2015 10:47:44 -0800 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> <20150106193655.2be8dcf0@fsol> Message-ID: Folks, I realize I'm sounding a bit like Raymond here, but can you all please find a different forum to discuss algorithms and coding problems and pick each other's solutions apart? The focus on python-ideas should be to quickly validate ideas for the language or the stdlib, not to discuss arbitrary snippets of code. On Tue, Jan 6, 2015 at 10:44 AM, Paul Moore wrote: > On 6 January 2015 at 18:36, Antoine Pitrou wrote: > > On Tue, 6 Jan 2015 18:22:44 +0000 > > Paul Moore wrote: > >> On 6 January 2015 at 17:14, Raymond Hettinger > >> wrote: > >> >> On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: > >> >> > >> >> In writing a utility script today, I found myself needing to do > >> >> something similar to what the Unix "comm" utility does - take two > >> >> sorted iterators, and partition the values into "only in the first", > >> >> "only in the second", and "in both" groups. > >> > > >> > As far as I can tell, this would be a very rare need. > >> > >> It's come up for me a few times, usually when trying to check two > >> lists of files to see which ones have been missed by a program, and > >> which ones the program thinks are present but no longer exist. > > > > Why don't you use sets for such things? Your iterator is really only > > useful for huge or unhashable inputs. > > For the case described you're right. I had a case the other day where > one of the problems was that one list had duplicates, and I needed to > see that ([1,1,2,2] vs [1,2] needed to show [1,2] as "only in the > first list" and [1,2] as "in both"). I could probably have used > counters. But I was starting from thinking that I had a pair of sorted > lists, and "in the Unix shell I'd use comm"...) > > Paul > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue Jan 6 20:02:16 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 06 Jan 2015 11:02:16 -0800 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: <20150106180005.GE19387@ando.pearwood.info> <54AC2947.3000209@stoneleaf.us> <54AC2CCB.5040703@stoneleaf.us> Message-ID: <54AC3138.40107@stoneleaf.us> On 01/06/2015 10:47 AM, Paul Moore wrote: > On 6 January 2015 at 18:43, Ethan Furman wrote: >> >> Yup, it sure does. Guess I should have paid more attention to that niggling feeling that I was missing something. ;) >> On the other hand, I figured even if I was wrong it wouldn't hurt to increase awareness about the change to generators. > > I should probably point out that when writing my code, I was conscious > of the generator change and took special case of catching all of the > StopIterations that might leak out. It's probably good that I was made > to think carefully about it, but all those try...except blocks sure > look ugly. Having looked more closely at your code, I don't see any thing that wouldn't have had to be there even without the generator change because your exhausting two iterators. > (And Steven's version with its sentinel value doesn't look > much better, with all those comparisons against a magic value I think I prefer his, although I would rename MISSING to FINISHED. ;) -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From abarnert at yahoo.com Tue Jan 6 19:59:08 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Tue, 6 Jan 2015 18:59:08 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: Message-ID: <98F84827-B54F-4163-B3EF-C3AFEF5BA811@yahoo.com> On Jan 6, 2015, at 18:29, Paul Moore wrote: > On 6 January 2015 at 17:39, Andrew Barnert wrote: >>> 2. The times I've needed this have been ad-hoc scripts (I'm on >>> Windows, so while a Unix user might use a quick shell pipeline with >>> comm, that's less convenient for me) where depending on a 3rd party >>> distribution from PyPI is less ideal. >> >> Why? Current standard Windows installers include pip, and being pure Python you won't need a compiler, so what's wrong with requiring a PyPI distribution? (Of course that means you need to be able to count on a relatively recent Python 3.4+/2.7+, but it's hard to see how that's worse than something in a future version of the stdlib, which would mean you need to be able to count on 3.5+.) > > Well, I usually write my "little utility scripts" as simple .py files > to be run with the system Python. I tend to use them on multiple > machines. So unless a dependency is one of the modules I routinely > install (things like requests) the process goes run script, oops, > needed that distribution, pip install dist, run it again. I do the same thing; I just long ago got into the habit of including more-itertools as one of my routine installs alongside requests, etc. :) I wonder if there's a common-enough set of things that don't really belong in stdlib (often just because they update too frequently) but are often worth having for many people. If I could just "pip install extralib" on every machine, even at the cost of getting a few libs I don't actually need, it would be worth it. On the other hand, if the common set isn't common enough, so for many people extralib only had half of what they want and was 70% stuff they didn't care shouted it wouldn't be that useful... > Not a big > issue certainly (and hardly a showstopper) but annoying. And it does > mean I'd need to make a PyPI project for my personal utility > functions, which doesn't really seem an appropriate use for PyPI, tbh. > > Requiring Python 3.5+ isn't a big deal, I routinely put the newest > version of Python on all my machines. The ones I can't tend to be > "secure", meaning I have no access to PyPI either :-( > >> And I'll bet if you submit this as a pull request to more-itertools, it'll be accepted, meaning you don't even have to create or maintain a PyPI project. > > Thanks for the suggestion, I might do that. > > Paul From wes.turner at gmail.com Tue Jan 6 20:25:06 2015 From: wes.turner at gmail.com (Wes Turner) Date: Tue, 6 Jan 2015 13:25:06 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <54AB9D76.7030105@egenix.com> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> Message-ID: Fair disclosure: I'm not a big fan of Moin syntax (can Pandoc convert this?). I don't like having to login to share with the Python community. It would be great to gain maximum synergy from the community on this. Some interesting perspectives on wikis, and where wikis are going: [1] https://github.com/blog/1939-how-github-uses-github-to-document-github [2] https://github.com/westurner/wiki/blob/master/Makefile [2] is a Sphinx Makefile for a GitHub ReStructuredText wiki. It seems to work okay for my purposes. What could prevent this from scaling to handle the Python wiki? >From https://github.com/westurner/wiki/issues/5 , in Markdown (which works on both BitBucket and GitHub): # Advantages > * Beautiful Sphinx output: > https://github.com/westurner/wiki/blob/master/conf.py > * Search > * Context-focused pages > * Navbar > * **Responsive** CSS Freedom; for my cell phone > * Pull Requests > # Challenges / Disadvantages > * New wiki pages created through the GitHub wiki interface add the `.rest` > suffix, rather than `.rst` > * Sort of an advantage (`.rest` files are docutils-only) > * This precludes inclusion of the wiki pages into a standard Sphinx > docset as a submodule or subtree. > * Sphinx ReStructuredText is a superset of GitHub ReStructuredText > (docutils), so Sphinx markup is, in the best case not supported, and in the > worst case breaks the wiki render > * Notably: `:ref:`, `.. index:`, and `.. toctree::` are only supported > by Sphinx > * To test this: `make rst2html_all` > * Double Tables of Contents (#4) > * Double pulls and pushes (`make pull push`): > https://github.com/westurner/wiki/blob/master/Makefile > * Sphinx requires a manual build step in order to publish in-progress > changes On Tue, Jan 6, 2015 at 2:31 AM, M.-A. Lemburg wrote: > On 06.01.2015 07:26, Ben Finney wrote: > > "M.-A. Lemburg" writes: > > > >> [editing the Python wiki] requiring asking for editing rights > >> on the pydotorg-www mailing list. Which is a little annoying and > >> some work for the admins, but has resulted in the amount of > >> spam to go down to zero. We usually grant the editing requests > >> within a day. > > > > I quite understand the motivation for this. > > > > It does need to be recognised that this will dramatically reduce the > > number of pople who will pass that hurdle to edit the wiki, and thus the > > wiki loses a lot of edits (both helpful and unhelpful) it might > > otherwise have. > > We might lose some occasional quick typo fixes, but it seems that > those genuinely interested in helping with the wiki don't have > a problem asking on the list. > > To reduce the problem I had created a list of user names > who had made good edits in the months before the change. > > The only nit I still have with the setup is that it's not > necessarily apparent for new users how to get editing rights. > There's a section on the front page, but you don't see this > when looking at a random page. > > > Thanks to those doing the work to maintain Python community > > infrastructure. > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Jan 06 2015) > >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ > >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ > >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > ________________________________________________________________________ > > ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wes.turner at gmail.com Tue Jan 6 20:27:47 2015 From: wes.turner at gmail.com (Wes Turner) Date: Tue, 6 Jan 2015 13:27:47 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> Message-ID: ... I had created an awesome-python-android page, but I seem to have `push -f`'ed over it and the reflog is too hard. On Tue, Jan 6, 2015 at 1:25 PM, Wes Turner wrote: > Fair disclosure: I'm not a big fan of Moin syntax (can Pandoc convert > this?). I don't like having to login to share with the Python community. It > would be great to gain maximum synergy from the community on this. > > Some interesting perspectives on wikis, and where wikis are going: > > [1] https://github.com/blog/1939-how-github-uses-github-to-document-github > [2] https://github.com/westurner/wiki/blob/master/Makefile > > [2] is a Sphinx Makefile for a GitHub ReStructuredText wiki. It seems to > work okay for my purposes. What could prevent this from scaling to handle > the Python wiki? > > From https://github.com/westurner/wiki/issues/5 , in Markdown (which > works on both BitBucket and GitHub): > > # Advantages >> > > > * Beautiful Sphinx output: >> https://github.com/westurner/wiki/blob/master/conf.py >> * Search >> * Context-focused pages >> * Navbar >> * **Responsive** CSS Freedom; for my cell phone >> * Pull Requests >> # Challenges / Disadvantages >> * New wiki pages created through the GitHub wiki interface add the >> `.rest` suffix, rather than `.rst` >> * Sort of an advantage (`.rest` files are docutils-only) >> * This precludes inclusion of the wiki pages into a standard Sphinx >> docset as a submodule or subtree. >> * Sphinx ReStructuredText is a superset of GitHub ReStructuredText >> (docutils), so Sphinx markup is, in the best case not supported, and in the >> worst case breaks the wiki render >> * Notably: `:ref:`, `.. index:`, and `.. toctree::` are only supported >> by Sphinx >> * To test this: `make rst2html_all` >> * Double Tables of Contents (#4) >> * Double pulls and pushes (`make pull push`): >> https://github.com/westurner/wiki/blob/master/Makefile >> * Sphinx requires a manual build step in order to publish in-progress >> changes > > > > > > On Tue, Jan 6, 2015 at 2:31 AM, M.-A. Lemburg wrote: > >> On 06.01.2015 07:26, Ben Finney wrote: >> > "M.-A. Lemburg" writes: >> > >> >> [editing the Python wiki] requiring asking for editing rights >> >> on the pydotorg-www mailing list. Which is a little annoying and >> >> some work for the admins, but has resulted in the amount of >> >> spam to go down to zero. We usually grant the editing requests >> >> within a day. >> > >> > I quite understand the motivation for this. >> > >> > It does need to be recognised that this will dramatically reduce the >> > number of pople who will pass that hurdle to edit the wiki, and thus the >> > wiki loses a lot of edits (both helpful and unhelpful) it might >> > otherwise have. >> >> We might lose some occasional quick typo fixes, but it seems that >> those genuinely interested in helping with the wiki don't have >> a problem asking on the list. >> >> To reduce the problem I had created a list of user names >> who had made good edits in the months before the change. >> >> The only nit I still have with the setup is that it's not >> necessarily apparent for new users how to get editing rights. >> There's a section on the front page, but you don't see this >> when looking at a random page. >> >> > Thanks to those doing the work to maintain Python community >> > infrastructure. >> >> -- >> Marc-Andre Lemburg >> eGenix.com >> >> Professional Python Services directly from the Source (#1, Jan 06 2015) >> >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >> >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >> >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ >> ________________________________________________________________________ >> >> ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: >> >> eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 >> D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg >> Registered at Amtsgericht Duesseldorf: HRB 46611 >> http://www.egenix.com/company/contact/ >> _______________________________________________ >> Python-ideas mailing list >> Python-ideas at python.org >> https://mail.python.org/mailman/listinfo/python-ideas >> Code of Conduct: http://python.org/psf/codeofconduct/ >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From guido at python.org Tue Jan 6 20:31:41 2015 From: guido at python.org (Guido van Rossum) Date: Tue, 6 Jan 2015 11:31:41 -0800 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <54AB9D76.7030105@egenix.com> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> Message-ID: If you ask me the bigger problem with the Wiki is not how to encourage or manage small edits, it is how to deal with the entire wiki gradually getting out of date due to page "owners" losing interest or topics becoming irrelevant. (A random example: https://wiki.python.org/moin/MostPopularPythonProjects is 10 years old, which makes it actively harmful given its lofty title and linkage from other pages.) An early Python contributor, Ken Manheimer, described the necessary activity as "wiki gardening". We need more wiki gardeners, people who have an eye for the big picture and actively edit content, not just guards who passively judge contribute proposed changes (even that's also needed -- Python is sufficiently well-known that the wiki would attract a lot of spam and occasional vandalism if it was completely open). -- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: From eltoder at gmail.com Tue Jan 6 20:35:54 2015 From: eltoder at gmail.com (Eugene Toder) Date: Tue, 6 Jan 2015 14:35:54 -0500 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> Message-ID: On Tue, Jan 6, 2015 at 3:25 AM, Andrew Barnert wrote: > I think you're missing another important point here: statements and expressions are different things. Blocks are made up of statements, not expressions, and statements don't have values. This is different from many other languages like C, Ruby, or JavaScript, where as many things as possible are expressions (and therefore have values), so a block is (oversimplifying a bit) just a sequence of expressions separated by semicolons and stuck inside braces, and therefore it has a last value. Statements and expressions are separate in C and Javascript, and statements don't have values. This is the reason, for example, for having the ?: operator, and for having statement expressions in GNU C [1]. This separation is common in C-like languages. Some C-like languages that have REPL invent a rule for statement values similar to Python's REPL. > One type of statement, the expression statement, is just an expression on a line by itself (or between semicolons), so you _could_ invent a rule pretty easily that expression statements have the value of their expression, and all other statements have a value of None, and a block has the value of its last statement. This is basically the same rule used by the interactive REPL for displaying the repr of what you've typed and setting the _ variable, so it wouldn't be a huge stretch to add the same rule to the language itself--but it would still be a new rule, and a significant change to the internals of the interpreter, even though it would only be useful in this new context. I don't think one needs to invent this rule in the context of this idea. All that is needed is to end the "return expression" (or whatever you want to call it) with an expression rather than a statement (i.e. return_expr ::= "keyword" statement* expression). The value of this last expression is the value of the whole thing. [1] https://gcc.gnu.org/onlinedocs/gcc-3.1/gcc/Statement-Exprs.html From p.f.moore at gmail.com Tue Jan 6 20:39:39 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 6 Jan 2015 19:39:39 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> <20150106193655.2be8dcf0@fsol> Message-ID: On 6 January 2015 at 18:47, Guido van Rossum wrote: > Folks, I realize I'm sounding a bit like Raymond here, but can you all > please find a different forum to discuss algorithms and coding problems and > pick each other's solutions apart? The focus on python-ideas should be to > quickly validate ideas for the language or the stdlib, not to discuss > arbitrary snippets of code. Agreed. I'm happy with the consensus (reached pretty quickly) that this isn't useful enough for the stdlib. Thanks all. Paul From skip.montanaro at gmail.com Tue Jan 6 20:39:38 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 6 Jan 2015 13:39:38 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> Message-ID: On Tue, Jan 6, 2015 at 1:31 PM, Guido van Rossum wrote: > it is how to deal with the entire wiki gradually getting out of date due > to page "owners" losing interest or topics becoming irrelevant. Even if you can recruit lots of gardeners, you need a few master gardeners to lay things out (define the structure of the garden). Otherwise you wind up with just a bag of pages. Pushing the gardening metaphor to its limit: no planning means the lettuce is always shaded by the corn. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From guido at python.org Tue Jan 6 20:44:34 2015 From: guido at python.org (Guido van Rossum) Date: Tue, 6 Jan 2015 11:44:34 -0800 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> Message-ID: On Tue, Jan 6, 2015 at 11:39 AM, Skip Montanaro wrote: > > > On Tue, Jan 6, 2015 at 1:31 PM, Guido van Rossum wrote: > >> it is how to deal with the entire wiki gradually getting out of date due >> to page "owners" losing interest or topics becoming irrelevant. > > > Even if you can recruit lots of gardeners, you need a few master gardeners > to lay things out (define the structure of the garden). Otherwise you wind > up with just a bag of pages. Pushing the gardening metaphor to its limit: > no planning means the lettuce is always shaded by the corn. > Nice one, and agreed. I don't see anyone with a serious wish to be a master gardener for wiki.python.org in this sense though. :-( Perhaps we should advertise the position? It's a volunteer role, but will require a lot of motivation. Ideally the master gardener team should be allowed to select the tool suite and be given permission to switch to a new suite pretty aggressively. The team should also be responsible for deciding on the policy for edit access. This seems more workable than having an open-ended discussion on python-ideas. -- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip.montanaro at gmail.com Tue Jan 6 20:51:19 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 6 Jan 2015 13:51:19 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> Message-ID: On Tue, Jan 6, 2015 at 1:25 PM, Wes Turner wrote: > I'm not a big fan of Moin syntax (can Pandoc convert this?). I haven't followed wiki markup at all in the past several years. Back when Moin came along, it was (arguably?) the correct choice for wiki.python.org. I think most of us active at the time were very much in the "eat your own dog food" camp at the time. I've never heard of Pandoc (I grow old, can't follow every trend), but I thought there were some tools which could convert Moin into other formats. I can't find much now, though this https://ikiwiki.info/tips/convert_moinmoin_to_ikiwiki/ looks like it might be a reasonable starting point. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From wes.turner at gmail.com Tue Jan 6 20:59:00 2015 From: wes.turner at gmail.com (Wes Turner) Date: Tue, 6 Jan 2015 13:59:00 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> Message-ID: On Tue, Jan 6, 2015 at 1:31 PM, Guido van Rossum wrote: > > An early Python contributor, Ken Manheimer, described the necessary > activity as "wiki gardening". We need more wiki gardeners, people who have > an eye for the big picture and actively edit content, not just guards who > passively judge contribute proposed changes (even that's also needed -- > Python is sufficiently well-known that the wiki would attract a lot of spam > and occasional vandalism if it was completely open). > > The edx wiki seems to avoid many of these challenges. https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request Other than versioning docs/ with the code and encouraging helpful community members to provide a valuable service, IDK of any other good solutions. As far as change control, pull requests (of the wiki branch) seem to work great for just me. -------------- next part -------------- An HTML attachment was scrubbed... URL: From donald at stufft.io Tue Jan 6 21:24:53 2015 From: donald at stufft.io (Donald Stufft) Date: Tue, 6 Jan 2015 15:24:53 -0500 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> Message-ID: <80F2EFB1-07F4-4966-9DCB-6BBD50B50D42@stufft.io> > On Jan 6, 2015, at 2:44 PM, Guido van Rossum wrote: > > On Tue, Jan 6, 2015 at 11:39 AM, Skip Montanaro > wrote: > > > On Tue, Jan 6, 2015 at 1:31 PM, Guido van Rossum > wrote: > it is how to deal with the entire wiki gradually getting out of date due to page "owners" losing interest or topics becoming irrelevant. > > Even if you can recruit lots of gardeners, you need a few master gardeners to lay things out (define the structure of the garden). Otherwise you wind up with just a bag of pages. Pushing the gardening metaphor to its limit: no planning means the lettuce is always shaded by the corn. > > Nice one, and agreed. I don't see anyone with a serious wish to be a master gardener for wiki.python.org in this sense though. :-( Perhaps we should advertise the position? It's a volunteer role, but will require a lot of motivation. Ideally the master gardener team should be allowed to select the tool suite and be given permission to switch to a new suite pretty aggressively. The team should also be responsible for deciding on the policy for edit access. This seems more workable than having an open-ended discussion on python-ideas. I have very little opinion on what the wiki is or does but I wanted to just say if at some point we do switch software then with my infrastructure team hat on I would ask for two properties to exist in the software (not really specific to the wiki tbh): 1. Configuration that is able to be handled via config management like salt/chef/puppet etc. Typically this just means that the configuration is handled via a text file and the software itself doesn?t attempt to write to the configuration as part of it?s normal execution. 2. State does not need to be stored on the local file system and instead can be stored in something like a database (preferably PostgreSQL) or an object store (preferably cloudfiles). This allows us to treat the servers running the software as emphereal with all of the state stored elsewhere. This makes it easier to manage the servers, makes it easier to recover from security issues on a server, makes it easier to upgrade the server, and makes it easier to scale the service in general. Of the two, the first property is the most important, but the second one is a really good idea too. --- Donald Stufft PGP: 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Tue Jan 6 22:04:55 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 7 Jan 2015 08:04:55 +1100 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> References: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> Message-ID: <20150106210455.GA65122@cskk.homeip.net> On 06Jan2015 09:14, Raymond Hettinger wrote: >> On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: >> In writing a utility script today, I found myself needing to do >> something similar to what the Unix "comm" utility does - take two >> sorted iterators, and partition the values into "only in the first", >> "only in the second", and "in both" groups. > >As far as I can tell, this would be a very rare need. Really? I do this on an ad hoc basis in shell scripts a lot. I think it might just be rare for you. In Python I would generally be choosing to use sets, but that is at least partially because sets are there and the stdlib doesn't have a comm. With sets, I inherently need finite sources, and I also don't get to yield results progressively from ordered iterators. Also, it needs to fit into memory. The most obvious Python use case I happen to actually have to hand would almost be an abuse of the suggested comm(): a log merge tool I wrote for merging multiple logs; in that case the "common" set is always empty, hence the "abuse" idea; it isn't really abuse, just a corner use case. It gets run many times every day. Reviewing the code, I notice it starts with: from heapq import merge It strikes me that it might be easier to write comm() as a wrapper to heapq.merge. Though that wouldn't handle Steven's "unorderable items" case. Cheers, Cameron Simpson If it sticks, force it. If it breaks, it needed replacing anyway. From cs at zip.com.au Tue Jan 6 22:09:59 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 7 Jan 2015 08:09:59 +1100 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <20150106193655.2be8dcf0@fsol> References: <20150106193655.2be8dcf0@fsol> Message-ID: <20150106210959.GA87112@cskk.homeip.net> On 06Jan2015 19:36, Antoine Pitrou wrote: >On Tue, 6 Jan 2015 18:22:44 +0000 >Paul Moore wrote: >> On 6 January 2015 at 17:14, Raymond Hettinger >> wrote: >> >> On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: >> >> >> >> In writing a utility script today, I found myself needing to do >> >> something similar to what the Unix "comm" utility does - take two >> >> sorted iterators, and partition the values into "only in the first", >> >> "only in the second", and "in both" groups. >> > >> > As far as I can tell, this would be a very rare need. >> >> It's come up for me a few times, usually when trying to check two >> lists of files to see which ones have been missed by a program, and >> which ones the program thinks are present but no longer exist. > >Why don't you use sets for such things? Your iterator is really only >useful for huge or unhashable inputs. In my use case (an existing tool): 1) I'm merging log files of arbitrary size; I am _not_ going to suck them into memory. A comm()-like function has a tiny and fixed memory footprint, versus an unbounded out. 2) I want ordered output, and my inputs are already ordered; why on earth would I impose a pointless sorting cost on my (currently linear) runtime? Sets are the "obvious" Python way to do this, because comm() is more or less a set intersection operation and sets are right there in Python. But for unbounded sorted inputs and progressive output, they are a _bad_ choice. Cheers, Cameron Simpson Yesterday, I was running a CNC plasma cutter that's controlled by Windows XP. This is a machine that moves around a plasma torch that cuts thick steel plate. ?A "New Java update is available" window popped up while I was working. ?Not good. - John Nagle From solipsis at pitrou.net Tue Jan 6 22:24:48 2015 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 6 Jan 2015 22:24:48 +0100 Subject: [Python-ideas] Possible new itertool: comm() References: <20150106193655.2be8dcf0@fsol> <20150106210959.GA87112@cskk.homeip.net> Message-ID: <20150106222448.574f82fa@fsol> On Wed, 7 Jan 2015 08:09:59 +1100 Cameron Simpson wrote: > On 06Jan2015 19:36, Antoine Pitrou wrote: > >On Tue, 6 Jan 2015 18:22:44 +0000 > >Paul Moore wrote: > >> On 6 January 2015 at 17:14, Raymond Hettinger > >> wrote: > >> >> On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: > >> >> > >> >> In writing a utility script today, I found myself needing to do > >> >> something similar to what the Unix "comm" utility does - take two > >> >> sorted iterators, and partition the values into "only in the first", > >> >> "only in the second", and "in both" groups. > >> > > >> > As far as I can tell, this would be a very rare need. > >> > >> It's come up for me a few times, usually when trying to check two > >> lists of files to see which ones have been missed by a program, and > >> which ones the program thinks are present but no longer exist. > > > >Why don't you use sets for such things? Your iterator is really only > >useful for huge or unhashable inputs. > > In my use case (an existing tool): > > 1) I'm merging log files of arbitrary size; I am _not_ going to suck them into > memory. A comm()-like function has a tiny and fixed memory footprint, versus an > unbounded out. I don't understand what your use case has to do with comm(). If you just want to merge sorted iterators you don't need all the complication this function has. Regards Antoine. From wes.turner at gmail.com Tue Jan 6 22:48:25 2015 From: wes.turner at gmail.com (Wes Turner) Date: Tue, 6 Jan 2015 15:48:25 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <80F2EFB1-07F4-4966-9DCB-6BBD50B50D42@stufft.io> References: <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <80F2EFB1-07F4-4966-9DCB-6BBD50B50D42@stufft.io> Message-ID: On Tue, Jan 6, 2015 at 2:24 PM, Donald Stufft wrote: > > I have very little opinion on what the wiki is or does but I wanted to > just say if at some point we do switch software then with my infrastructure > team hat on I would ask for two properties to exist in the software (not > really specific to the wiki tbh): > > 1. Configuration that is able to be handled via config management like > salt/chef/puppet etc. Typically this just means that the configuration is > handled via a text file and the software itself doesn?t attempt to write to > the configuration as part of it?s normal execution. > +1 * http://psf-salt.readthedocs.org/en/latest/ * https://github.com/python/psf-salt > > 2. State does not need to be stored on the local file system and instead > can be stored in something like a database (preferably PostgreSQL) or an > object store (preferably cloudfiles). This allows us to treat the servers > running the software as emphereal with all of the state stored elsewhere. > This makes it easier to manage the servers, makes it easier to recover from > security issues on a server, makes it easier to upgrade the server, and > makes it easier to scale the service in general. > > Of the two, the first property is the most important, but the second one > is a really good idea too. > > re: persistence * difflib * hg diff * git diff structured data * http://www.w3.org/2001/sw/wiki/Tools (RDF; FreeBase is moving to WikiData) * https://westurner.github.io/wiki/tools * https://westurner.github.io/dotfiles/tools.html#python * https://westurner.github.io/dotfiles/_sources/tools.txt (this is the simplest ReST markup I could think of, a sphinxcontrib-rdf directive/role could be really useful, but wouldn't work w/ GitHub wikis without a Sphinx compile step) : .. index:: Python > .. _python: Python > ================= > | Wikipedia: ` >`_ > | Homepage: https://www.python.org/ > | Docs: https://docs.python.org/2/ > | Docs: https://docs.python.org/devguide/ > | Docs: https://docs.python.org/devguide/documenting.html > | Docs: http://learnxinyminutes.com/docs/python/ > | Source: hg https://hg.python.org/cpython Python is a dynamically-typed, :ref:`C`-based third-generation > programming language. [...] -------------- next part -------------- An HTML attachment was scrubbed... URL: From mal at egenix.com Tue Jan 6 23:01:19 2015 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 06 Jan 2015 23:01:19 +0100 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> Message-ID: <54AC5B2F.6090504@egenix.com> On 06.01.2015 20:44, Guido van Rossum wrote: > On Tue, Jan 6, 2015 at 11:39 AM, Skip Montanaro > wrote: >> On Tue, Jan 6, 2015 at 1:31 PM, Guido van Rossum wrote: >> >>> it is how to deal with the entire wiki gradually getting out of date due >>> to page "owners" losing interest or topics becoming irrelevant. >> >> >> Even if you can recruit lots of gardeners, you need a few master gardeners >> to lay things out (define the structure of the garden). Otherwise you wind >> up with just a bag of pages. Pushing the gardening metaphor to its limit: >> no planning means the lettuce is always shaded by the corn. >> > > Nice one, and agreed. I don't see anyone with a serious wish to be a master > gardener for wiki.python.org in this sense though. :-( Perhaps we should > advertise the position? It's a volunteer role, but will require a lot of > motivation. Ideally the master gardener team should be allowed to select > the tool suite and be given permission to switch to a new suite pretty > aggressively. The team should also be responsible for deciding on the > policy for edit access. This seems more workable than having an open-ended > discussion on python-ideas. Such discussions should really happen on pydotorg-www where that team already works. We do have several people who maintain pages or page sets on the wiki, but more editorial help is always welcome. We need people who have experience in technical writing and a passion to maintain informational resources. FWIW: A change of tools won't magically give us better content. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From wes.turner at gmail.com Tue Jan 6 23:11:44 2015 From: wes.turner at gmail.com (Wes Turner) Date: Tue, 6 Jan 2015 16:11:44 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <54AC5B2F.6090504@egenix.com> References: <29AE11E7-7347-4C9C-BC4E-996DFA6C1754@yahoo.com> <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> Message-ID: On Tue, Jan 6, 2015 at 4:01 PM, M.-A. Lemburg wrote: > On 06.01.2015 20:44, Guido van Rossum wrote: > > On Tue, Jan 6, 2015 at 11:39 AM, Skip Montanaro < > skip.montanaro at gmail.com> > > wrote: > >> On Tue, Jan 6, 2015 at 1:31 PM, Guido van Rossum > wrote: > >> > >>> it is how to deal with the entire wiki gradually getting out of date > due > >>> to page "owners" losing interest or topics becoming irrelevant. > >> > >> > >> Even if you can recruit lots of gardeners, you need a few master > gardeners > >> to lay things out (define the structure of the garden). Otherwise you > wind > >> up with just a bag of pages. Pushing the gardening metaphor to its > limit: > >> no planning means the lettuce is always shaded by the corn. > >> > > > > Nice one, and agreed. I don't see anyone with a serious wish to be a > master > > gardener for wiki.python.org in this sense though. :-( Perhaps we should > > advertise the position? It's a volunteer role, but will require a lot of > > motivation. Ideally the master gardener team should be allowed to select > > the tool suite and be given permission to switch to a new suite pretty > > aggressively. The team should also be responsible for deciding on the > > policy for edit access. This seems more workable than having an > open-ended > > discussion on python-ideas. > > Such discussions should really happen on pydotorg-www where > that team already works. We do have several people who maintain pages > or page sets on the wiki, but more editorial help is always welcome. > https://mail.python.org/mailman/listinfo/pydotorg-www https://www.python.org/dev/pydotorg/website/ > > We need people who have experience in technical writing and > a passion to maintain informational resources. > > FWIW: A change of tools won't magically give us better content. > A boost in familiar usability could encourage effortless contributions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue Jan 6 23:48:18 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 06 Jan 2015 14:48:18 -0800 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> Message-ID: <54AC6632.5040204@stoneleaf.us> On 01/06/2015 02:11 PM, Wes Turner wrote: > On Tue, Jan 6, 2015 at 4:01 PM, M.-A. Lemburg wrote: >> >> Such discussions should really happen on pydotorg-www where >> that team already works. We do have several people who maintain pages >> or page sets on the wiki, but more editorial help is always welcome. > > https://www.python.org/dev/pydotorg/website/ Subversion, huh? > A boost in familiar usability could encourage effortless contributions. Not even breathing is effortless. -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From mal at egenix.com Wed Jan 7 00:04:02 2015 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 07 Jan 2015 00:04:02 +0100 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> Message-ID: <54AC69E2.6070303@egenix.com> On 06.01.2015 23:11, Wes Turner wrote: > On Tue, Jan 6, 2015 at 4:01 PM, M.-A. Lemburg wrote: > >> On 06.01.2015 20:44, Guido van Rossum wrote: >>> On Tue, Jan 6, 2015 at 11:39 AM, Skip Montanaro < >> skip.montanaro at gmail.com> >>> wrote: >>>> On Tue, Jan 6, 2015 at 1:31 PM, Guido van Rossum >> wrote: >>>> >>>>> it is how to deal with the entire wiki gradually getting out of date >> due >>>>> to page "owners" losing interest or topics becoming irrelevant. >>>> >>>> >>>> Even if you can recruit lots of gardeners, you need a few master >> gardeners >>>> to lay things out (define the structure of the garden). Otherwise you >> wind >>>> up with just a bag of pages. Pushing the gardening metaphor to its >> limit: >>>> no planning means the lettuce is always shaded by the corn. >>>> >>> >>> Nice one, and agreed. I don't see anyone with a serious wish to be a >> master >>> gardener for wiki.python.org in this sense though. :-( Perhaps we should >>> advertise the position? It's a volunteer role, but will require a lot of >>> motivation. Ideally the master gardener team should be allowed to select >>> the tool suite and be given permission to switch to a new suite pretty >>> aggressively. The team should also be responsible for deciding on the >>> policy for edit access. This seems more workable than having an >> open-ended >>> discussion on python-ideas. >> >> Such discussions should really happen on pydotorg-www where >> that team already works. We do have several people who maintain pages >> or page sets on the wiki, but more editorial help is always welcome. >> > > https://mail.python.org/mailman/listinfo/pydotorg-www Yep, that's the list. > https://www.python.org/dev/pydotorg/website/ That page explains the old python.org website system. It doesn't have anything to do with wiki.python.org. >> We need people who have experience in technical writing and >> a passion to maintain informational resources. >> >> FWIW: A change of tools won't magically give us better content. >> > > A boost in familiar usability could encourage effortless contributions. The wiki does support ReST syntax if you don't like the wiki markup: http://moinmo.in/HelpOnParsers/ReStructuredText and it also supports WYSIWYG editing using FCKeditor (even though the generated markup code doesn't look all that nice). -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From victor.stinner at gmail.com Wed Jan 7 00:11:51 2015 From: victor.stinner at gmail.com (Victor Stinner) Date: Wed, 7 Jan 2015 00:11:51 +0100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> Message-ID: Hi, This idea was already proposed as part of a larger PEP: https://www.python.org/dev/peps/pep-0471/#wildcard-support The PEP explains why the Windows wildcard idea was rejected. Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From mal at egenix.com Wed Jan 7 00:12:33 2015 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 07 Jan 2015 00:12:33 +0100 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <54AC69E2.6070303@egenix.com> References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> <54AC69E2.6070303@egenix.co m> Message-ID: <54AC6BE1.5000505@egenix.com> While we're in wishlist mode: A contribution we'd really appreciate is a moin 1.9 theme adapted to the new python.org style :-) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 07 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From wes.turner at gmail.com Wed Jan 7 00:21:33 2015 From: wes.turner at gmail.com (Wes Turner) Date: Tue, 6 Jan 2015 17:21:33 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <54AC69E2.6070303@egenix.com> References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> <54AC69E2.6070303@egenix.com> Message-ID: On Tue, Jan 6, 2015 at 5:04 PM, M.-A. Lemburg wrote: > > > https://mail.python.org/mailman/listinfo/pydotorg-www > > Yep, that's the list. > > > https://www.python.org/dev/pydotorg/website/ > > That page explains the old python.org website system. It > doesn't have anything to do with wiki.python.org. > My mistake. That page does seem outdated. I must've been looking for one level up: https://www.python.org/dev/pydotorg/ What content should be version controlled with the website? > > >> We need people who have experience in technical writing and > >> a passion to maintain informational resources. > >> > >> FWIW: A change of tools won't magically give us better content. > >> > > > > A boost in familiar usability could encourage effortless contributions. > > The wiki does support ReST syntax if you don't like the wiki > markup: > > http://moinmo.in/HelpOnParsers/ReStructuredText Ah, thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From random832 at fastmail.us Wed Jan 7 00:35:05 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 06 Jan 2015 18:35:05 -0500 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: References: <20141229185326.19663a01@fsol> <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> Message-ID: <1420587305.879324.210454157.1BA5CE04@webmail.messagingengine.com> On Tue, Jan 6, 2015, at 18:11, Victor Stinner wrote: > Hi, > > This idea was already proposed as part of a larger PEP: > https://www.python.org/dev/peps/pep-0471/#wildcard-support Not the same idea, really. The _main_ thrust of this idea is to have a way to have a single function (OS-specific algorithms or otherwise) which acts (roughly) like itertools.chain(map(glob,lst)) on windows and simply uses the original list unmodified on unix, and to use this in places like fileinput. The point is that command line argument wildcard processing belongs in a different place on each platform. The windows-specific matching algorithm is just an aside. From steve at pearwood.info Wed Jan 7 01:42:50 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 7 Jan 2015 11:42:50 +1100 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: References: <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> Message-ID: <20150107004249.GF19387@ando.pearwood.info> On Wed, Jan 07, 2015 at 12:11:51AM +0100, Victor Stinner wrote: > Hi, > > This idea was already proposed as part of a larger PEP: > https://www.python.org/dev/peps/pep-0471/#wildcard-support > > The PEP explains why the Windows wildcard idea was rejected. The Windows wildcard idea was rejected in the context of a faster os.walk, not globbing. The PEP is inaccurate: it gives the wrong Python-Ideas thread for discussions on the wildcard idea. The wildcard idea is discussed in this thread: https://mail.python.org/pipermail/python-ideas/2012-November/017965.html not in the thread given in the PEP. Well, I say "discussed", but it's mostly ignored, with only a couple of comments. There's somewhat more discussion on Python-Dev: https://mail.python.org/pipermail/python-dev/2014-June/135217.html but it's mostly people just saying "-1 on wildcards". I agree with this decision, for PEP 471. But I don't believe this is relevant to the question of explicit globbing. -- Steve From stephen at xemacs.org Wed Jan 7 02:16:15 2015 From: stephen at xemacs.org (Stephen J. Turnbull) Date: Wed, 07 Jan 2015 10:16:15 +0900 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <54AC6632.5040204@stoneleaf.us> References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> <54AC6632.5040204@stoneleaf.us> Message-ID: <87387n1jc0.fsf@uwakimon.sk.tsukuba.ac.jp> Ethan Furman writes: > On 01/06/2015 02:11 PM, Wes Turner wrote: > > A boost in familiar usability could encourage effortless contributions. > > Not even breathing is effortless. True, but that's the wrong fallacy. The energy required is not the point, it's the thinking. Wes's point is that he'd like it to be possible to contribute to Python without being aware of the mechanics of contribution, just as it's possible to breath without being aware of your lungs most of the time. That's reasonable, and wikis actually do work in some contexts. The fallacy in applying wiki-think to Python is that for new and small projects with SEI "Level Zero" processes, *increase in quantity* of documentation is *improvement in quality* of documentation. That's no longer true of Python, and hasn't been for two decades (at least). It isn't even clear that filling an obvious hole with an accurate-as- far-as-it-goes drive-by contribution is a good thing. Not only may the residual inaccuracy mislead the reader, it may also contribute to an impression that the Python docs are lower quality on average than they actually are. From ethan at stoneleaf.us Wed Jan 7 02:28:13 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 06 Jan 2015 17:28:13 -0800 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <87387n1jc0.fsf@uwakimon.sk.tsukuba.ac.jp> References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> <54AC6632.5040204@stoneleaf.us> <87387n1jc0.fsf@uwakimon.sk.tsukuba.ac.jp> Message-ID: <54AC8BAD.8000203@stoneleaf.us> On 01/06/2015 05:16 PM, Stephen J. Turnbull wrote: > Ethan Furman writes: >> On 01/06/2015 02:11 PM, Wes Turner wrote: >>> >>> A boost in familiar usability could encourage effortless contributions. >> >> Not even breathing is effortless. > > True, but that's the wrong fallacy. [...] > > The fallacy in applying wiki-think to Python is that [an] *increase in > quantity* of documentation is [not necessarily an] *improvement in quality* > of documentation. [...] > > It isn't even clear that filling an obvious hole with an accurate-as- > far-as-it-goes drive-by contribution is a good thing. Not only may > the residual inaccuracy mislead the reader, it may also contribute to > an impression that the Python docs are lower quality on average than > they actually are. Thanks -- that's worded much better than my own feeble attempt. :) -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From yawar.amin at gmail.com Wed Jan 7 03:08:46 2015 From: yawar.amin at gmail.com (Yawar Amin) Date: Tue, 06 Jan 2015 21:08:46 -0500 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> Message-ID: <54AC952E.5060301@gmail.com> On 2015-01-06 03:25, Andrew Barnert wrote: > [...] > I think you're missing another important point here: statements and > expressions are different things. Blocks are made up of statements, > not expressions, ... Actually I can offer counter-examples to that: def p(x): print x class A: p("Hello!") class B: 1 # Etc. But I think I see what's happening here: statements are the top dogs in Python, and when Python wants a statement but only has an expression, it 'promotes' the expression into a statement by evaluating it, throwing away its value, and pretending nothing happened (i.e., that there was a 'pass' statement there). Thus defining a class can have the nonsensical effect of calling a function. But there's currently no way of going in the other direction, i.e. demoting a statement to an expression. Which is what I was trying to do. I _still_ think at least something like the following would work (in terms of Python's grammar[1]): expr_expr: 'expr' ':' small_stmt (';' small_stmt)* [';' expr] So e.g.: x = expr: import os; os.system("date") I'll explore this further and see where it goes. Regards, Yawar [1] https://docs.python.org/3/reference/grammar.html -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 834 bytes Desc: OpenPGP digital signature URL: From cs at zip.com.au Wed Jan 7 03:14:40 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 7 Jan 2015 13:14:40 +1100 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <20150106222448.574f82fa@fsol> References: <20150106222448.574f82fa@fsol> Message-ID: <20150107021440.GA34389@cskk.homeip.net> On 06Jan2015 22:24, Antoine Pitrou wrote: >On Wed, 7 Jan 2015 08:09:59 +1100 >Cameron Simpson wrote: >> On 06Jan2015 19:36, Antoine Pitrou wrote: >> >On Tue, 6 Jan 2015 18:22:44 +0000 >> >Paul Moore wrote: >> >> On 6 January 2015 at 17:14, Raymond Hettinger >> >> wrote: >> >> >> On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: >> >> >> >> >> >> In writing a utility script today, I found myself needing to do >> >> >> something similar to what the Unix "comm" utility does - take two >> >> >> sorted iterators, and partition the values into "only in the first", >> >> >> "only in the second", and "in both" groups. >> >> > >> >> > As far as I can tell, this would be a very rare need. >> >> >> >> It's come up for me a few times, usually when trying to check two >> >> lists of files to see which ones have been missed by a program, and >> >> which ones the program thinks are present but no longer exist. >> > >> >Why don't you use sets for such things? Your iterator is really only >> >useful for huge or unhashable inputs. >> >> In my use case (an existing tool): >> >> 1) I'm merging log files of arbitrary size; I am _not_ going to suck them into >> memory. A comm()-like function has a tiny and fixed memory footprint, versus an >> unbounded out. > >I don't understand what your use case has to do with comm(). I've got two! I, like another poster, also very commonly compare two similar directory trees for commonality, and equivalent list comparisons. >If you >just want to merge sorted iterators you don't need all the complication >this function has. Indeed not, but they are very similar tasks: you're pulling in 2 or more streams of sorted inputs and classifying them. In my direct use case, all into the same output stream, in order. In comm(), into three streams (well, being an iterator output: one stream with three classifications). Cheers, Cameron Simpson The double cam chain setup on the 1980's DOHC CB750 was another one of Honda's pointless engineering breakthroughs. You know the cycle (if you'll pardon the pun :-), Wonderful New Feature is introduced with much fanfare, WNF is fawned over by the press, WNF is copied by the other three Japanese makers (this step is sometimes optional), and finally, WNF is quietly dropped by Honda. - Blaine Gardner, From rosuav at gmail.com Wed Jan 7 03:28:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 Jan 2015 13:28:34 +1100 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <54AC952E.5060301@gmail.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> <54AC952E.5060301@gmail.com> Message-ID: On Wed, Jan 7, 2015 at 1:08 PM, Yawar Amin wrote: > But I think I see what's happening here: statements are the top dogs in > Python, and when Python wants a statement but only has an expression, it > 'promotes' the expression into a statement by evaluating it, throwing > away its value, and pretending nothing happened (i.e., that there was a > 'pass' statement there). Thus defining a class can have the nonsensical > effect of calling a function. One type of statement is (via a couple of levels of indirection) the expr_stmt, which contains an expression and (if I'm not misreading the grammar) may or may not assign it to anything. https://docs.python.org/3/reference/grammar.html It's not that an expression gets "promoted", it's that one valid form of statement is an expression with nothing around it. In C, the definition is more like "an expression followed by a semicolon", but in Python, you don't need any adornment, so it looks identical. However, there is (as far as I know) no way in Python to wrap a statement into an expression. Some languages have such a thing (eg a lambda function syntax, which is an expression returning a function, and in which statements are allowed), but I don't think Python does, anywhere; all compound units that allow statements are themselves statements. ChrisA From jim.baker at python.org Wed Jan 7 04:30:56 2015 From: jim.baker at python.org (Jim Baker) Date: Tue, 6 Jan 2015 20:30:56 -0700 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <20150107021440.GA34389@cskk.homeip.net> References: <20150106222448.574f82fa@fsol> <20150107021440.GA34389@cskk.homeip.net> Message-ID: The comm functionality sounds very reasonable for inclusion. But please call it itertools.common. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Jan 7 04:41:24 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jan 2015 03:41:24 +0000 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <54AC952E.5060301@gmail.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> <54AC952E.5060301@gmail.com> Message-ID: <54ACAAE4.3090505@mrabarnett.plus.com> On 2015-01-07 02:08, Yawar Amin wrote: > On 2015-01-06 03:25, Andrew Barnert wrote: >> [...] >> I think you're missing another important point here: statements and >> expressions are different things. Blocks are made up of statements, >> not expressions, ... > > Actually I can offer counter-examples to that: > > def p(x): print x > class A: p("Hello!") > class B: 1 > # Etc. > > But I think I see what's happening here: statements are the top dogs in > Python, and when Python wants a statement but only has an expression, it > 'promotes' the expression into a statement by evaluating it, throwing > away its value, and pretending nothing happened (i.e., that there was a > 'pass' statement there). Thus defining a class can have the nonsensical > effect of calling a function. > > But there's currently no way of going in the other direction, i.e. > demoting a statement to an expression. Which is what I was trying to do. > I _still_ think at least something like the following would work (in > terms of Python's grammar[1]): > > expr_expr: 'expr' ':' small_stmt (';' small_stmt)* [';' expr] > > So e.g.: > > x = expr: import os; os.system("date") > [snip] In BCPL, the body of a routine can be only a single statement, but that statement can be a block: LET foo() BE $( .... $) Similarly, the body of a function can be only an expression, but that expression can include VALOF. VALOF is followed by a block, and the value of VALOF is given by the expression after RESULTIS: LET foo() = VALOF $( ... RESULTIS ... ... $) Of course, in Python, the block would be indented, so it's not entirely suitable, but you could imagine this: x = valof: import os resultis os.system("date") I think you're better off using a function instead! From abarnert at yahoo.com Wed Jan 7 05:43:49 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Tue, 6 Jan 2015 23:43:49 -0500 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> Message-ID: LOn Jan 6, 2015, at 14:35, Eugene Toder wrote: > On Tue, Jan 6, 2015 at 3:25 AM, Andrew Barnert > wrote: >> I think you're missing another important point here: statements and expressions are different things. Blocks are made up of statements, not expressions, and statements don't have values. This is different from many other languages like C, Ruby, or JavaScript, where as many things as possible are expressions (and therefore have values), so a block is (oversimplifying a bit) just a sequence of expressions separated by semicolons and stuck inside braces, and therefore it has a last value. > Statements and expressions are separate in C and Javascript, Well, obviously; otherwise "as many things as possible are expressions" would be pointless. In C, unlike Python (and, more to the point, unlike many of C's predecessors), assignment, augmented assignment, and increment are expressions. Different languages have since taken that farther: Ruby makes most flow control into expressions, JavaScript makes function definitions into expressions (which means you can wrap any statement in an expression by defining and calling a function around it), CoffeeScript makes everything but return, continue, and break into expressions. >> One type of statement, the expression statement, is just an expression on a line by itself (or between semicolons), so you _could_ invent a rule pretty easily that expression statements have the value of their expression, and all other statements have a value of None, and a block has the value of its last statement. This is basically the same rule used by the interactive REPL for displaying the repr of what you've typed and setting the _ variable, so it wouldn't be a huge stretch to add the same rule to the language itself--but it would still be a new rule, and a significant change to the internals of the interpreter, even though it would only be useful in this new context. > I don't think one needs to invent this rule in the context of this > idea. All that is needed is to end the "return expression" (or > whatever you want to call it) with an expression rather than a > statement (i.e. return_expr ::= "keyword" statement* expression). The > value of this last expression is the value of the whole thing. That's equivalent to arguing that function bodies don't need return, break, or continue, because you can theoretically write anything to fall off the end. I'm assuming that the OP wanted something that works intuitively similar to other languages, the REPL, etc.--e.g., if the last statement executed is in the true block of an if/else, it doesn't matter that it's not textually the last statement. From yawar.amin at gmail.com Wed Jan 7 06:29:27 2015 From: yawar.amin at gmail.com (Yawar Amin) Date: Wed, 07 Jan 2015 00:29:27 -0500 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> Message-ID: <54ACC437.20608@gmail.com> On 2015-01-06 23:43, Andrew Barnert wrote: > [...] > That's equivalent to arguing that function bodies don't need return, > break, or continue, because you can theoretically write anything to > fall off the end. Not really; it's more like arguing that the particular proposed new syntax doesn't need a return statement because it is defined to automatically return its last expression (i.e., 'fall off the end'). All other control structures and syntax keep their existing behaviour, including functions. And in any case, many languages don't have any concept of a return statement; they _do_ actually return the last expression in their function bodies. > I'm assuming that the OP wanted something that works intuitively > similar to other languages, the REPL, etc.--e.g., if the last > statement executed is in the true block of an if/else, it doesn't > matter that it's not textually the last statement. Not exactly, I think ... I just wanted a way to 'wrap' statements inside expressions. That would unify the two concepts in Python and make it much more expressive. Regards, Yawar -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 834 bytes Desc: OpenPGP digital signature URL: From ncoghlan at gmail.com Wed Jan 7 07:15:32 2015 From: ncoghlan at gmail.com (Nick Coghlan) Date: Wed, 7 Jan 2015 16:15:32 +1000 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <54ACC437.20608@gmail.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> <54ACC437.20608@gmail.com> Message-ID: On 7 January 2015 at 15:29, Yawar Amin wrote: > Not exactly, I think ... I just wanted a way to 'wrap' statements inside > expressions. That would unify the two concepts in Python The data modelling and control flow aspects of Python, as represented by statements, are deliberately distinct from the computational aspects, as represented by expressions. Some constructs blur the boundaries between computation, data modelling and control flow, and hence may exist in both statement and expression forms. The fact that it permits data modelling and control flow constructs to be embedded inside computational ones is an argument *against* your proposal, not one in its favour. > and make it much more expressive. Allowing data modelling and control flow constructs to be embedded inside expressions doesn't make the language more expressive overall, it just lets you do more within a single expression without giving the results of suboperations names and/or factoring them out into separate usable functions. The number of cases where executing a suboperation first and binding the result to a name even arguably reduces clarity are relatively few and far between, and better represented in PEPs like 403 and 3150 than they are in a general purpose statement-as-expression syntax. So if you're interested in pursuing this further, I suggest focusing on the possible pragmatic benefits of defining a standard way to tunnel Python code through whitespace insensitive contexts and reformat it with a pretty printer at the far end, rather than the far more nebulous concept of expressiveness. Regards, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From mal at egenix.com Wed Jan 7 09:49:55 2015 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 07 Jan 2015 09:49:55 +0100 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> <54AC69E2.6070303@egenix.com> Message-ID: <54ACF333.80307@egenix.com> On 07.01.2015 00:21, Wes Turner wrote: > On Tue, Jan 6, 2015 at 5:04 PM, M.-A. Lemburg wrote: > >> >>> https://mail.python.org/mailman/listinfo/pydotorg-www >> >> Yep, that's the list. >> >>> https://www.python.org/dev/pydotorg/website/ >> >> That page explains the old python.org website system. It >> doesn't have anything to do with wiki.python.org. >> > > My mistake. That page does seem outdated. > > I must've been looking for one level up: > https://www.python.org/dev/pydotorg/ Sorry to say, but that content is outdated as well :-( > What content should be version controlled with the website? The current python.org website is a mix of code and templates in github repo, content/data stored in a database and a (for various reasons) homegrown CMS to manage pages such as the ones you found. There's work underway to replace the homegrown CMS with a standard more feature rich one, which will hopefully allow us to open up site editing to way more volunteers than we currently have. wiki.python.org is a separate VM, which doesn't have anything to do with www.python.org. The VM runs a more or less standard moin installation, which uses its own version control system (you can access this via the "info" link on the pages). >>>> We need people who have experience in technical writing and >>>> a passion to maintain informational resources. >>>> >>>> FWIW: A change of tools won't magically give us better content. >>>> >>> >>> A boost in familiar usability could encourage effortless contributions. >> >> The wiki does support ReST syntax if you don't like the wiki >> markup: >> >> http://moinmo.in/HelpOnParsers/ReStructuredText > > > Ah, thanks! -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 07 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From wes.turner at gmail.com Wed Jan 7 12:00:24 2015 From: wes.turner at gmail.com (Wes Turner) Date: Wed, 7 Jan 2015 05:00:24 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: <54ACF333.80307@egenix.com> References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> <54AC69E2.6070303@egenix.com> <54ACF333.80307@egenix.com> Message-ID: On Wed, Jan 7, 2015 at 2:49 AM, M.-A. Lemburg wrote: > > > > What content should be version controlled with the website? > > The current python.org website is a mix of code and templates > in github repo, content/data stored in a database and a (for > various reasons) homegrown CMS to manage pages such as > the ones you found. > > There's work underway to replace the homegrown CMS with a > standard more feature rich one, which will hopefully allow us > to open up site editing to way more volunteers than we > currently have. > > So there are no topical guidelines? > wiki.python.org is a separate VM, which doesn't have anything > to do with www.python.org. The VM runs a more or less standard > moin installation, which uses its own version control system > (you can access this via the "info" link on the pages). > > https://github.com/dwf/moin2rst Formatter plugin > Simply put ``RenderAsRestructuredtext.py`` to MoinMoin's > ``plugin/formatter`` directory. > Action plugin > Simply put ``RenderAsRestructuredtext.py`` to MoinMoin's ``plugin/action`` > directory. > >>>> We need people who have experience in technical writing and > >>>> a passion to maintain informational resources. > >>>> > >>>> FWIW: A change of tools won't magically give us better content. > >>>> > >>> > >>> A boost in familiar usability could encourage effortless contributions. > >> > >> The wiki does support ReST syntax if you don't like the wiki > >> markup: > >> > >> http://moinmo.in/HelpOnParsers/ReStructuredText > > > > > > Ah, thanks! > -------------- next part -------------- An HTML attachment was scrubbed... URL: From abarnert at yahoo.com Wed Jan 7 08:11:32 2015 From: abarnert at yahoo.com (Andrew Barnert) Date: Wed, 7 Jan 2015 02:11:32 -0500 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <54AC952E.5060301@gmail.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> <54AC952E.5060301@gmail.com> Message-ID: <74164843-0774-441F-A898-4776E15EFC8D@yahoo.com> On Jan 6, 2015, at 21:08, Yawar Amin wrote: > Actually I can offer counter-examples to that: > > def p(x): print x > class A: p("Hello!") > class B: 1 > # Etc. No, there are no counter-examples there. A top-level program is a sequence of statements. Both def and class are compound statements, meaning the colon is followed by either a simple statement list or an indented block of statements. An expression statement is a kind of simple statement containing nothing but an expression. > But I think I see what's happening here: statements are the top dogs in > Python, and when Python wants a statement but only has an expression, it > 'promotes' the expression into a statement by evaluating it, throwing > away its value, and pretending nothing happened (i.e., that there was a > 'pass' statement there). Thus defining a class can have the nonsensical > effect of calling a function. > > But there's currently no way of going in the other direction, i.e. > demoting a statement to an expression. Which is what I was trying to do. That's the key. A function is a way to wrap a sequence of statements (the function body) so it can be used in an expression (a function call). Because JavaScript lets you define functions (with full statement syntax) in expressions, that gives you a way to "demote" an expression inline, while Python can only do so out-of-line. At the core, this is what all of the multiline lambda attempts and similar proposals are trying to accomplish. From skip.montanaro at gmail.com Wed Jan 7 14:27:23 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 7 Jan 2015 07:27:23 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> <54AC69E2.6070303@egenix.com> <54ACF333.80307@egenix.com> Message-ID: I'm going to add one more bit here about wiki gardening. BITD, the main website had many pages which today would be called listicles. The problem was that those lists were dynamic. They weren't just the "top ten scientific Python modules of all time" or the "seven best packaging tools." They were whatever was at the front of the author's brain at some point in the past. Having these static pages given the imprimatur of the PSF when in fact none of the site maintainers were obviously responsible for (or interested in) keeping them up-to-date did a disservice to the community and to authors of other packages which weren't represented in those lists. In addition, there were more barriers to update than necessary (essentially, figure out how to report the problem, offer suggested fix(es), then have them swallowed up into the site update mechanism). One of the main uses envisioned for the wiki was as a place where these listicles could be maintained by the greater Python community. For some things, that's worked out pretty well. The most obvious thing that comes to mind is the PythonTraining page. That works because the people whose skills are represented on that page have a very good reason for keeping things up-to-date: it's free advertising for their businesses. Other listicle type pages haven't been keep as up-to-date. For example, the PythonEditors page was last updated in Feb 2014, is huge (and might benefit from being split into multiple pages), and probably no longer accurately represents the available editors or IDEs which support Python. The takeaway in my mind is that we could probably use "gardeners" to take over active maintenance of these listicle pages. That, coupled with a couple "master gardeners" to develop some suitable structure, and some landscape crews to prune dead/outdated/no-longer-useful pages, would likely go a long way to improving the quality of the wiki. Skip From toddrjen at gmail.com Wed Jan 7 14:33:54 2015 From: toddrjen at gmail.com (Todd) Date: Wed, 7 Jan 2015 14:33:54 +0100 Subject: [Python-ideas] math.inf and math.nan constants Message-ID: The current way to get infinite and nan floats are to do float("inf") and float("nan"), respectively. For many applications, this is sufficient. However, for scientific and mathematical computing, using inf and nan values is very common, and the current approach is very verbose. So for those applications, I think it would be useful if the math standard library module provided "math.nan" and "math.inf", which would return the same thing as float("nan") and float("inf"), respectively. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marky1991 at gmail.com Wed Jan 7 14:49:32 2015 From: marky1991 at gmail.com (Mark Young) Date: Wed, 7 Jan 2015 08:49:32 -0500 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: References: Message-ID: So with the proposal, you'd likely do something like from math import nan, inf Couldn't you just instead put nan, inf = float("nan"), float("inf") at the top of your script? I don't really think this is any more verbose than an import from the math module. (Unless you're already doing an import star from math) -------------- next part -------------- An HTML attachment was scrubbed... URL: From victor.stinner at gmail.com Wed Jan 7 15:19:31 2015 From: victor.stinner at gmail.com (Victor Stinner) Date: Wed, 7 Jan 2015 15:19:31 +0100 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> References: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> Message-ID: Hi, 2015-01-06 18:14 GMT+01:00 Raymond Hettinger : >> On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: >> >> In writing a utility script today, I found myself needing to do >> something similar to what the Unix "comm" utility does - take two >> sorted iterators, and partition the values into "only in the first", >> "only in the second", and "in both" groups. > > As far as I can tell, this would be a very rare need. I never used the UNIX comm tool. I didn't know that it exists :-) Can you maybe explain the purpose the tool/your function? Show an example. difflib may be a better candidate to add such function than contextlib. Victor From victor.stinner at gmail.com Wed Jan 7 15:29:14 2015 From: victor.stinner at gmail.com (Victor Stinner) Date: Wed, 7 Jan 2015 15:29:14 +0100 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: References: Message-ID: 2015-01-07 14:33 GMT+01:00 Todd : > The current way to get infinite and nan floats are to do float("inf") and > float("nan"), respectively. For many applications, this is sufficient. > However, for scientific and mathematical computing, using inf and nan values > is very common, and the current approach is very verbose. So for those > applications, I think it would be useful if the math standard library module > provided "math.nan" and "math.inf", which would return the same thing as > float("nan") and float("inf"), respectively. Do you expect singletons? I mean that float("nan") is math.nan would be True. Request of float("0.0") singleton: http://bugs.python.org/issue4024 I dislike the idea of adding math.. I agree with Mark Young, you are already create you own symbols in a module. Victor From random832 at fastmail.us Wed Jan 7 15:44:26 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Wed, 07 Jan 2015 09:44:26 -0500 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <20150107004249.GF19387@ando.pearwood.info> References: <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150107004249.GF19387@ando.pearwood.info> Message-ID: <1420641866.1163622.210704857.0D786745@webmail.messagingengine.com> On Tue, Jan 6, 2015, at 19:42, Steven D'Aprano wrote: > The PEP is inaccurate: it gives the wrong Python-Ideas thread for > discussions on the wildcard idea. The wildcard idea is discussed in this > thread: > > https://mail.python.org/pipermail/python-ideas/2012-November/017965.html I think the fundamental difference between these cases is in handling user-entered strings, especially command-line arguments (where the user will expect them to behave a certain way, in particular "*.*" matching all files even those with no dot - most of the other quirks are obscure anyway) vs hardcoded (where expectations are determined by the programmer, not the user). From ethan at stoneleaf.us Wed Jan 7 15:55:51 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 07 Jan 2015 06:55:51 -0800 Subject: [Python-ideas] Add OS-dependent automatic glob support In-Reply-To: <1420641866.1163622.210704857.0D786745@webmail.messagingengine.com> References: <7D7CB381-EE2A-4931-89DB-E6661A541715@yahoo.com> <54A1E167.1050605@canterbury.ac.nz> <1420205066.2836204.208806917.69EED9B5@webmail.messagingengine.com> <20150103015045.GB27426@ando.pearwood.info> <1420399476.1260565.209437029.38EF0C44@webmail.messagingengine.com> <54A9AA6F.8020400@stoneleaf.us> <1420413001.1294229.209490357.7C0E4C45@webmail.messagingengine.com> <20150107004249.GF19387@ando.pearwood.info> <1420641866.1163622.210704857.0D786745@webmail.messagingengine.com> Message-ID: <54AD48F7.6000407@stoneleaf.us> On 01/07/2015 06:44 AM, random832 at fastmail.us wrote: > On Tue, Jan 6, 2015, at 19:42, Steven D'Aprano wrote: >> The PEP is inaccurate: it gives the wrong Python-Ideas thread for >> discussions on the wildcard idea. The wildcard idea is discussed in this >> thread: >> >> https://mail.python.org/pipermail/python-ideas/2012-November/017965.html > > I think the fundamental difference between these cases is in handling > user-entered strings, especially command-line arguments (where the user > will expect them to behave a certain way, in particular "*.*" matching > all files even those with no dot - most of the other quirks are obscure > anyway) vs hardcoded (where expectations are determined by the > programmer, not the user). But is the programmer a *nix programmer or a Win programmer? ;) -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From jeanpierreda at gmail.com Wed Jan 7 15:55:57 2015 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 7 Jan 2015 08:55:57 -0600 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: References: Message-ID: On Wed, Jan 7, 2015 at 8:29 AM, Victor Stinner wrote: > 2015-01-07 14:33 GMT+01:00 Todd : >> The current way to get infinite and nan floats are to do float("inf") and >> float("nan"), respectively. For many applications, this is sufficient. >> However, for scientific and mathematical computing, using inf and nan values >> is very common, and the current approach is very verbose. So for those >> applications, I think it would be useful if the math standard library module >> provided "math.nan" and "math.inf", which would return the same thing as >> float("nan") and float("inf"), respectively. > > Do you expect singletons? I mean that float("nan") is math.nan would be True. That seems like a bad idea. There are millions of different NaNs, so xxx is math.nan would only work sometimes. (math.isnan is the way to deal with this.) -- Devin From toddrjen at gmail.com Wed Jan 7 15:58:37 2015 From: toddrjen at gmail.com (Todd) Date: Wed, 7 Jan 2015 15:58:37 +0100 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: References: Message-ID: Yes, this would be a shortcut for that. math.nan and math.inf are less verbose than float("nan") and float("inf"), even if you aren't already using the math module (fewer characters total, and in particular fewer special characters). It would also, at least in my opinion, be more readable. Plus there is already the math.isnan and math.isinf, so I don't think it would be totally out-of-place. On Wed, Jan 7, 2015 at 2:49 PM, Mark Young wrote: > So with the proposal, you'd likely do something like > > from math import nan, inf > > Couldn't you just instead put > > nan, inf = float("nan"), float("inf") > > at the top of your script? I don't really think this is any more verbose > than an import from the math module. (Unless you're already doing an import > star from math) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Wed Jan 7 16:03:08 2015 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 7 Jan 2015 16:03:08 +0100 Subject: [Python-ideas] math.inf and math.nan constants References: Message-ID: <20150107160308.7415d5dd@fsol> On Wed, 7 Jan 2015 14:33:54 +0100 Todd wrote: > The current way to get infinite and nan floats are to do float("inf") and > float("nan"), respectively. For many applications, this is sufficient. > However, for scientific and mathematical computing, using inf and nan > values is very common, and the current approach is very verbose. So for > those applications, I think it would be useful if the math standard library > module provided "math.nan" and "math.inf", which would return the same > thing as float("nan") and float("inf"), respectively. Note if you are using Numpy, you already have np.nan and np.inf. Regards Antoine. From solipsis at pitrou.net Wed Jan 7 16:02:02 2015 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 7 Jan 2015 16:02:02 +0100 Subject: [Python-ideas] math.inf and math.nan constants References: Message-ID: <20150107160202.531577d8@fsol> On Wed, 7 Jan 2015 15:29:14 +0100 Victor Stinner wrote: > 2015-01-07 14:33 GMT+01:00 Todd : > > The current way to get infinite and nan floats are to do float("inf") and > > float("nan"), respectively. For many applications, this is sufficient. > > However, for scientific and mathematical computing, using inf and nan values > > is very common, and the current approach is very verbose. So for those > > applications, I think it would be useful if the math standard library module > > provided "math.nan" and "math.inf", which would return the same thing as > > float("nan") and float("inf"), respectively. > > Do you expect singletons? I mean that float("nan") is math.nan would be True. > > Request of float("0.0") singleton: http://bugs.python.org/issue4024 > > I dislike the idea of adding math.. You mean like math.pi and math.e? :) From marco.buttu at gmail.com Wed Jan 7 16:23:29 2015 From: marco.buttu at gmail.com (Marco Buttu) Date: Wed, 07 Jan 2015 16:23:29 +0100 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: References: Message-ID: <54AD4F71.7060008@oa-cagliari.inaf.it> On 07/01/2015 15:58, Todd wrote: > Yes, this would be a shortcut for that. math.nan and math.inf are > less verbose than float("nan") and float("inf"), even if you aren't > already using the math module (fewer characters total, and in > particular fewer special characters). It would also, at least in my > opinion, be more readable. Plus there is already the math.isnan and > math.isinf, so I don't think it would be totally out-of-place. I totally agree. +1 -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbuttu at oa-cagliari.inaf.it From wes.turner at gmail.com Wed Jan 7 16:24:26 2015 From: wes.turner at gmail.com (Wes Turner) Date: Wed, 7 Jan 2015 09:24:26 -0600 Subject: [Python-ideas] build:// Path / URI / URN with the __div__ operator Message-ID: * [ ] build Path / URI / URN with the __div__ operator * [ ] pick some combination of operators for URI schema, query, fragment conjunction (like URLObject.with_<*>):: # scheme://user at host.netloc:port/path/?query#fragment from _ import URI, https, //, http https // 'user at host.netloc:port' / path ** query % fragment * __div__ / * __floordiv__ // * __and__ && * __mod__ % * __invert__ ~ * __or__ | * __xor__ ^ * __and__ + * __mul__ * * __pow__ ** * __lshift__ << * __rshift__ >> References ----------------- * https://pypi.python.org/pypi/path.py -- __div__ * https://pypi.python.org/pypi/pathlib -- [ Standard Library ] * https://pypi.python.org/pypi/furl * https://pypi.python.org/pypi/URLObject - [ with_scheme, with_netloc, with_path, ... ] * https://urlobject.readthedocs.org/en/latest/quickstart.html * https://pypi.python.org/pypi/rdflib -------------- next part -------------- An HTML attachment was scrubbed... URL: From p.f.moore at gmail.com Wed Jan 7 16:32:45 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 7 Jan 2015 15:32:45 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> Message-ID: On 7 January 2015 at 14:19, Victor Stinner wrote: > I never used the UNIX comm tool. I didn't know that it exists :-) > > Can you maybe explain the purpose the tool/your function? Show an example. The function has doctests included which may help. Basically, take 2 sorted lists (the Unix tool takes 2 sorted files of text), and merge them, preserving order, with each line marked as "only occurs in the first input", "only occurs in the second input" and "occurs in both inputs". So, for example, with inputs 1,1,2,4 and 1,3,4 we would get both: 1 first: 1 first: 2 second: 3 both: 4 The problem with difflib/diff is mainly that it does a *lot* more work than is needed - for sorted input, a fast single-pass algorithm is fine, whereas a general diff needs to work to find common subsequences. Paul From p.f.moore at gmail.com Wed Jan 7 16:36:02 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 7 Jan 2015 15:36:02 +0000 Subject: [Python-ideas] build:// Path / URI / URN with the __div__ operator In-Reply-To: References: Message-ID: On 7 January 2015 at 15:24, Wes Turner wrote: > * [ ] build Path / URI / URN with the __div__ operator > * [ ] pick some combination of operators for URI schema, query, fragment > conjunction (like URLObject.with_<*>):: [...] That was way too terse. What are you proposing? Paul From steve at pearwood.info Wed Jan 7 16:38:48 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 8 Jan 2015 02:38:48 +1100 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: References: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> Message-ID: <20150107153847.GG19387@ando.pearwood.info> On Wed, Jan 07, 2015 at 03:19:31PM +0100, Victor Stinner wrote: > Hi, > > 2015-01-06 18:14 GMT+01:00 Raymond Hettinger : > >> On Jan 6, 2015, at 8:22 AM, Paul Moore wrote: > >> > >> In writing a utility script today, I found myself needing to do > >> something similar to what the Unix "comm" utility does - take two > >> sorted iterators, and partition the values into "only in the first", > >> "only in the second", and "in both" groups. > > > > As far as I can tell, this would be a very rare need. > > I never used the UNIX comm tool. I didn't know that it exists :-) > > Can you maybe explain the purpose the tool/your function? Show an example. It might help to realise that comm is abbreviated from "common". It took me an embarrassingly long time to work that out. This example of using comm in Unix might help: http://www.theunixschool.com/2011/03/comm-beautiful-comparison.html > difflib may be a better candidate to add such function than contextlib. I think you mean itertools rather than contextlib. It seems to me that difflib would be a good place for it. -- Steve From senthil at uthcode.com Wed Jan 7 16:53:39 2015 From: senthil at uthcode.com (Senthil Kumaran) Date: Wed, 7 Jan 2015 07:53:39 -0800 Subject: [Python-ideas] build:// Path / URI / URN with the __div__ operator In-Reply-To: References: Message-ID: On Wed, Jan 7, 2015 at 7:36 AM, Paul Moore wrote: > That was way too terse. What are you proposing? His proposal seems like a __div__ method an (no existing yet) URI Object. But __div__ method for an existing Path Object. I get the idea, but I am having a hard time understanding the use cases which may not be confusing for common cases. Question: Does __div__ makes sense for strings? Why does it? I dont think so, but this question I pose has marginal relationship to the proposal. thanks, Senthil -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexander.belopolsky at gmail.com Wed Jan 7 17:07:28 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Wed, 7 Jan 2015 11:07:28 -0500 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: <54AD4F71.7060008@oa-cagliari.inaf.it> References: <54AD4F71.7060008@oa-cagliari.inaf.it> Message-ID: On Wed, Jan 7, 2015 at 10:23 AM, Marco Buttu wrote: > On 07/01/2015 15:58, Todd wrote: > > Yes, this would be a shortcut for that. math.nan and math.inf are less >> verbose than float("nan") and float("inf"), even if you aren't already >> using the math module (fewer characters total, and in particular fewer >> special characters). It would also, at least in my opinion, be more >> readable. Plus there is already the math.isnan and math.isinf, so I don't >> think it would be totally out-of-place. >> > > I totally agree. +1 Another +1. Two points: 1. The current ways to create inf and nan are not obvious and hard to discover. It will be nice to have these constants discoverable in tab completion from math. 2. The repr()s of nan and inf are simply 'nan' and 'inf', not 'float("nan")' and 'float("inf")', so it is natural to expect nan and inf constants in some namespace. -------------- next part -------------- An HTML attachment was scrubbed... URL: From guido at python.org Wed Jan 7 17:07:45 2015 From: guido at python.org (Guido van Rossum) Date: Wed, 7 Jan 2015 08:07:45 -0800 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: <54AD4F71.7060008@oa-cagliari.inaf.it> References: <54AD4F71.7060008@oa-cagliari.inaf.it> Message-ID: +1. Let's do it. On Wed, Jan 7, 2015 at 7:23 AM, Marco Buttu wrote: > On 07/01/2015 15:58, Todd wrote: > > Yes, this would be a shortcut for that. math.nan and math.inf are less >> verbose than float("nan") and float("inf"), even if you aren't already >> using the math module (fewer characters total, and in particular fewer >> special characters). It would also, at least in my opinion, be more >> readable. Plus there is already the math.isnan and math.isinf, so I don't >> think it would be totally out-of-place. >> > > I totally agree. +1 > > -- > Marco Buttu > > INAF-Osservatorio Astronomico di Cagliari > Via della Scienza n. 5, 09047 Selargius (CA) > Phone: 070 711 80 217 > Email: mbuttu at oa-cagliari.inaf.it > > > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Wed Jan 7 17:09:26 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 8 Jan 2015 03:09:26 +1100 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: References: Message-ID: <20150107160925.GH19387@ando.pearwood.info> On Wed, Jan 07, 2015 at 02:33:54PM +0100, Todd wrote: > The current way to get infinite and nan floats are to do float("inf") and > float("nan"), respectively. For many applications, this is sufficient. > However, for scientific and mathematical computing, using inf and nan > values is very common, and the current approach is very verbose. So for > those applications, I think it would be useful if the math standard library > module provided "math.nan" and "math.inf", which would return the same > thing as float("nan") and float("inf"), respectively. Compare: inf = float('inf') func(inf) versus: from math import inf func(inf) Defining your module's own constant actually takes two characters fewer than importing it from the math module. In any case, we're talking about an utterly trivial micro-optimization. This is Python, not Unix shell scripting. We don't use names like "umount" to save one character over "unmount", we encouraging writing for clarity and correctness over brevity. The math module has constants pi and e because it would be truly an inconvenience to have to create them yourself: pi = 3.14159265389793 I can remember the first six digits of pi, 3.1415, anything more than that I have to look up, and of course there is the considerable risk of getting it wrong, as I did above. But the same does not apply to creating your own inf constant. There is no long series of digits to remember, just three letters, and it's hard to get it wrong. Whether you write import math process(math.inf) or inf = float('inf') process(inf) is much the same effort. At worst, we might say that it is a matter of personal taste which you prefer. But frankly, the difference is trivial. Of course, writing float('inf') every single time you want an infinity is wasteful and silly, but that's a matter of education. If you can't teach people to write inf = float('inf') you won't be able to teach them to use math.inf either. Up to now, I have only discussed inf, not nan, because there is only one inf value in floats. (Two if you count -inf.) But the IEEE 754 standard provides many different NAN values, and offers a possible interpretion of them: the extra "payload" on each NAN can be used to carry diagnostic information on which numeric operation failed. Back in the 1980s, I was a user of the Apple Standard Numerics Environment (SANE), which provided easy access to NAN payloads and a standard interpretation for them. It is a system which can work well and help in debugging. Python today doesn't give us any simple way to access all those different float NANs, or offer any interpretation of what they might mean, but it might some day. I am strongly opposed to anything which might pre-empt that or discourage future advances. In summary: - offering a math.inf is harmless but not especially useful; - offering a single math.nan is harmful and I strongly oppose it. -- Steve From p.f.moore at gmail.com Wed Jan 7 17:09:51 2015 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 7 Jan 2015 16:09:51 +0000 Subject: [Python-ideas] Possible new itertool: comm() In-Reply-To: <20150107153847.GG19387@ando.pearwood.info> References: <1BC2F2DA-DC73-4BE3-8550-37F5EA872C07@gmail.com> <20150107153847.GG19387@ando.pearwood.info> Message-ID: On 7 January 2015 at 15:38, Steven D'Aprano wrote: > This example of using comm in Unix might help: > > http://www.theunixschool.com/2011/03/comm-beautiful-comparison.html The example on that page is the exact reason I wrote my own implementation (the Windows version of comm that I have locally got confused by non-ASCII content in some of the filenames I had). Paul From wes.turner at gmail.com Wed Jan 7 17:11:46 2015 From: wes.turner at gmail.com (Wes Turner) Date: Wed, 7 Jan 2015 10:11:46 -0600 Subject: [Python-ideas] build:// Path / URI / URN with the __div__ operator In-Reply-To: References: Message-ID: %doctest_mode >>> p = pathlib.Path('//') / 'two' / 'three' >>> p PosixPath('//two/three') >>> 'https' + p Traceback (most recent call last): File "", line 1, in 'https' + p TypeError: cannot concatenate 'str' and 'PosixPath' objects >>> 'root(//)' + p Traceback (most recent call last): File "", line 1, in 'root(//)' + p TypeError: cannot concatenate 'str' and 'PosixPath' objects >>> p = pathlib.Path('https://example.org/') / 'two' / 'three' >>> p PosixPath('https:/example.org/two/three') >>> p + "?query=value" + "#fragment" Traceback (most recent call last): File "", line 1, in p + "?query=value" + "#fragment" TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str' So, something like this would/could be really helpful, for usability: from ns/uri/url import URI, http, https from _ import base # "//" _url = https // 'user at host.netloc:port' / path ** query % fragment _url = base // path ** query % fragment # or, just: _url = https / 'user at host.netloc:port' / path ** query % fragment _url = base / path ** query % fragment An OrderedMultiDict of query vars would also be helpful for building a union set of GET params joined by not os.path.sep: * ?key=val args and/or * #{'key':'val'} * OrderedDict.setdefault(key, list) On Wed, Jan 7, 2015 at 9:53 AM, Senthil Kumaran wrote: > > On Wed, Jan 7, 2015 at 7:36 AM, Paul Moore wrote: > >> That was way too terse. What are you proposing? > > > His proposal seems like a __div__ method an (no existing yet) URI Object. > But __div__ method for an existing Path Object. > > I get the idea, but I am having a hard time understanding the use cases > which may not be confusing for common cases. > > Question: Does __div__ makes sense for strings? Why does it? I dont think > so, but this question I pose has marginal relationship to the proposal. > > thanks, > Senthil > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jan 7 17:14:17 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 Jan 2015 03:14:17 +1100 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: <20150107160925.GH19387@ando.pearwood.info> References: <20150107160925.GH19387@ando.pearwood.info> Message-ID: On Thu, Jan 8, 2015 at 3:09 AM, Steven D'Aprano wrote: > I can remember the first six digits of pi, 3.1415... Aside: That's technically an incorrect approximation. Since the next digit is a 9, you ought to round that up... or just use 3.14159, stopping before the 2 and thus correctly rounding down. ChrisA From guido at python.org Wed Jan 7 17:16:18 2015 From: guido at python.org (Guido van Rossum) Date: Wed, 7 Jan 2015 08:16:18 -0800 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: <20150107160925.GH19387@ando.pearwood.info> References: <20150107160925.GH19387@ando.pearwood.info> Message-ID: On Wed, Jan 7, 2015 at 8:09 AM, Steven D'Aprano wrote: > On Wed, Jan 07, 2015 at 02:33:54PM +0100, Todd wrote: > > > The current way to get infinite and nan floats are to do float("inf") and > > float("nan"), respectively. For many applications, this is sufficient. > > However, for scientific and mathematical computing, using inf and nan > > values is very common, and the current approach is very verbose. So for > > those applications, I think it would be useful if the math standard > library > > module provided "math.nan" and "math.inf", which would return the same > > thing as float("nan") and float("inf"), respectively. > > Compare: > > inf = float('inf') > func(inf) > > versus: > > from math import inf > func(inf) > But using a more common style, you already have math imported anyway, and you can just write math.inf rather than having to interrupt your coding flow, see if you already have an inf variable defined, if not define it, etc. > > Defining your module's own constant actually takes two characters fewer > than importing it from the math module. > But that's not the (whole) point. The existing idioms are commonly used and unintuitive. I suppose you would also be in favor of defining e = math.exp(1) in favor of math.e? > > In any case, we're talking about an utterly trivial micro-optimization. > This is Python, not Unix shell scripting. We don't use names like > "umount" to save one character over "unmount", we encouraging writing > for clarity and correctness over brevity. > > The math module has constants pi and e because it would be truly an > inconvenience to have to create them yourself: > > pi = 3.14159265389793 > > I can remember the first six digits of pi, 3.1415, anything more than > that I have to look up, and of course there is the considerable risk of > getting it wrong, as I did above. > > But the same does not apply to creating your own inf constant. There is > no long series of digits to remember, just three letters, and it's hard > to get it wrong. Whether you write > > import math > process(math.inf) > > or > > inf = float('inf') > process(inf) > > is much the same effort. At worst, we might say that it is a matter of > personal taste which you prefer. But frankly, the difference is trivial. > > I say bah to that long-winded diatribe. > Of course, writing float('inf') every single time you want an infinity > is wasteful and silly, but that's a matter of education. If you can't > teach people to write inf = float('inf') you won't be able to teach them > to use math.inf either. > > Up to now, I have only discussed inf, not nan, because there is only one > inf value in floats. (Two if you count -inf.) But the IEEE 754 standard > provides many different NAN values, and offers a possible interpretion > of them: the extra "payload" on each NAN can be used to carry diagnostic > information on which numeric operation failed. Back in the 1980s, I was > a user of the Apple Standard Numerics Environment (SANE), which provided > easy access to NAN payloads and a standard interpretation for them. It > is a system which can work well and help in debugging. > > Python today doesn't give us any simple way to access all those > different float NANs, or offer any interpretation of what they might > mean, but it might some day. I am strongly opposed to anything which > might pre-empt that or discourage future advances. > I don't see how the existence of a nan constant pre-empts anything. Your imagined new mechanism will have to co-exist with float("nan") anyway. > In summary: > > - offering a math.inf is harmless but not especially useful; > > - offering a single math.nan is harmful and I strongly oppose it. That's your opinion and you're entitled to it. -- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: From yawar.amin at gmail.com Wed Jan 7 17:20:46 2015 From: yawar.amin at gmail.com (Yawar Amin) Date: Wed, 7 Jan 2015 11:20:46 -0500 Subject: [Python-ideas] Syntax: 'return: ...' expressions In-Reply-To: <74164843-0774-441F-A898-4776E15EFC8D@yahoo.com> References: <54AA093A.2050508@gmail.com> <3002533B-C171-49E0-B3DA-CFB08345D370@yahoo.com> <54AB4178.3050508@gmail.com> <97D50920-B7D2-4125-9389-224C4CBC83CA@yahoo.com> <54AC952E.5060301@gmail.com> <74164843-0774-441F-A898-4776E15EFC8D@yahoo.com> Message-ID: <8C6A6BAA-197B-4796-9163-6EE3AE3E1553@gmail.com> On 2015-01-07, at 2:11, Andrew Barnert wrote: > [...] >> > > That's the key. A function is a way to wrap a sequence of statements (the function body) so it can be used in an expression (a function call). Because JavaScript lets you define functions (with full statement syntax) in expressions, that gives you a way to "demote" an expression inline, while Python can only do so out-of-line. At the core, this is what all of the multiline lambda attempts and similar proposals are trying to accomplish. Thanks. This has given me an idea that's on a slightly different tangent than this one. Will write it up (this time with some actual runnable code) when I get home tonight. Regards, Yawar From alexander.belopolsky at gmail.com Wed Jan 7 17:21:15 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Wed, 7 Jan 2015 11:21:15 -0500 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: References: <20150107160925.GH19387@ando.pearwood.info> Message-ID: On Wed, Jan 7, 2015 at 11:16 AM, Guido van Rossum wrote: > But that's not the (whole) point. The existing idioms are commonly used > and unintuitive. I suppose you would also be in favor of defining e = > math.exp(1) in favor of math.e? .. math.acos(-1) in favor of math.pi? -------------- next part -------------- An HTML attachment was scrubbed... URL: From wes.turner at gmail.com Wed Jan 7 17:23:06 2015 From: wes.turner at gmail.com (Wes Turner) Date: Wed, 7 Jan 2015 10:23:06 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> <54AC69E2.6070303@egenix.com> <54ACF333.80307@egenix.com> Message-ID: On Wed, Jan 7, 2015 at 7:27 AM, Skip Montanaro wrote: > I'm going to add one more bit here about wiki gardening. > In order to test parsing code in order to produce Linked Data http://5stardata.info , it could be helpful to produce a periodic archive/dump sort of like http://wiki.dbpedia.org/Datasets . A github repository could be useful for hosting these types of releases. python/wiki___ ? > > BITD, the main website had many pages which today would be called > listicles. The problem was that those lists were dynamic. They weren't > just the "top ten scientific Python modules of all time" or the "seven > best packaging tools." They were whatever was at the front of the > author's brain at some point in the past. Having these static pages > given the imprimatur of the PSF when in fact none of the site > maintainers were obviously responsible for (or interested in) keeping > them up-to-date did a disservice to the community and to authors of > other packages which weren't represented in those lists. In addition, > there were more barriers to update than necessary (essentially, figure > out how to report the problem, offer suggested fix(es), then have them > swallowed up into the site update mechanism). > Are the links out of date, or the descriptions and exclusive clusters? * http://schema.org/SoftwareApplication (RDFa in HTML5, Microdata) * http://json-ld.org/ * URIs are tags > > One of the main uses envisioned for the wiki was as a place where > these listicles could be maintained by the greater Python > community. For some things, that's worked out pretty well. The most > obvious thing that comes to mind is the PythonTraining page. That > works because the people whose skills are represented on that page > have a very good reason for keeping things up-to-date: it's free > advertising for their businesses. > > Other listicle type pages haven't been keep as up-to-date. For > example, the PythonEditors page was last updated in Feb 2014, is huge > (and might benefit from being split into multiple pages), and probably > no longer accurately represents the available editors or IDEs which > support Python. > The takeaway in my mind is that we could probably use "gardeners" to > take over active maintenance of these listicle pages. That, coupled > with a couple "master gardeners" to develop some suitable structure, > and some landscape crews to prune dead/outdated/no-longer-useful > pages, would likely go a long way to improving the quality of the > wiki. > > Skip > Are there tools for working with a regular editor (such as vim) and MoinMoin pages? With ReStructuredText, the Riv.vim syntax helpers are great for things like tables; Voom is great for outlines (:Voom rest). -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.barker at noaa.gov Wed Jan 7 17:25:22 2015 From: chris.barker at noaa.gov (Chris Barker) Date: Wed, 7 Jan 2015 08:25:22 -0800 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: <20150107160925.GH19387@ando.pearwood.info> References: <20150107160925.GH19387@ando.pearwood.info> Message-ID: On Wed, Jan 7, 2015 at 8:09 AM, Steven D'Aprano wrote: > import math > process(math.inf) > > or > > inf = float('inf') > process(inf) > > is much the same effort. At worst, we might say that it is a matter of > personal taste which you prefer. But frankly, the difference is trivial. > exactly -- but the cost is trivial too. Note that numpy provides np.inf and np.nan for a reason, and it s a nice thing to have. > - offering a math.inf is harmless but not especially useful; > but nice. - offering a single math.nan is harmful and I strongly oppose it. defining math.nan as a singleton could be considered harmful, but I don't see any harm at all in offering it as a pre-defined constant. We NEED to have a way to create a NaN-valued float in any case (and do with float('nan')) -- this would be no different. And as nan (and inf, and -inf) can result from computation, rather than python-level object creation, they are different than None anyway (they are also particular values or a float, rather than a particular type). +1 -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Wed Jan 7 17:48:35 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 8 Jan 2015 03:48:35 +1100 Subject: [Python-ideas] math.inf and math.nan constants In-Reply-To: References: <20150107160925.GH19387@ando.pearwood.info> Message-ID: <20150107164834.GI19387@ando.pearwood.info> On Thu, Jan 08, 2015 at 03:14:17AM +1100, Chris Angelico wrote: > On Thu, Jan 8, 2015 at 3:09 AM, Steven D'Aprano wrote: > > I can remember the first six digits of pi, 3.1415... > > Aside: That's technically an incorrect approximation. I know. I didn't say it was a good approximation, I said I could remember those digits. -- Steve From skip.montanaro at gmail.com Wed Jan 7 17:55:55 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 7 Jan 2015 10:55:55 -0600 Subject: [Python-ideas] Encouraging more use of the Python wiki In-Reply-To: References: <1752C815-970E-4588-8DEE-523833EC4E8A@yahoo.com> <822B30F1-3A5C-4CF9-BE10-0A818A5241DB@yahoo.com> <20150105011312.GS27426@ando.pearwood.info> <85387qyqas.fsf_-_@benfinney.id.au> <54AAAD7F.6080201@egenix.com> <85tx04xw43.fsf@benfinney.id.au> <54AB9D76.7030105@egenix.com> <54AC5B2F.6090504@egenix.com> <54AC69E2.6070303@egenix.com> <54ACF333.80307@egenix.com> Message-ID: On Wed, Jan 7, 2015 at 10:23 AM, Wes Turner wrote: > Are there tools for working with a regular editor (such as vim) and > MoinMoin pages? I'm not at all concerned with this, as I see the editing step being pretty much orthogonal to the markup language and the version control tools. Editing through a web browser pretty much sucks no matter what you're trying to edit, especially if you are used to using highly functional, mature editors like vim and Emacs. If you want your editing to happen outside a glorified