[Python-ideas] Python-ideas Digest, Vol 65, Issue 43

Hobson Lane hobsonlane at gmail.com
Mon Apr 23 13:10:27 CEST 2012


Formatted and finished Rebert's solution to this issue

http://bugs.python.org/issue3177

But the question of where to put it is still open ( shutil.open vs.
shutil.launch vs. os.startfile ):

1. `shutil.open()` will break anyone that does `from shutil import *` or
edits the shutil.py file and tries to use the builtin open() after the
shutil.open() definition.

2. `shutil.launch()` is better than shutil.open() due to reduced breakage,
but not as simple or DRY or reverse-compatible as putting it in
os.startfile() in my mind. This fix just implements the functionality of
os.startfile() for non-Windows OSes.

3. `shutil.startfile()` was recommended against by a developer or two on
this mailing list, but seems appropriate to me. The only upstream
"breakage" for an os.startfile() location that I can think of is the
failure to raise exceptions on non-Windows OSes. Any legacy (<3.0) code
that relies on os.startfile() exceptions in order to detect a non-windows
OS is misguided and needs re-factoring anyway, IMHO. Though their only
indication of a "problem" in their code would be the successful launching
of a viewer for whatever path they pointed to...

4. `os.launch()` anyone? Not me.

On Mon, Apr 23, 2012 at 6:00 PM, <python-ideas-request at python.org> wrote:

> Send Python-ideas mailing list submissions to
>        python-ideas at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://mail.python.org/mailman/listinfo/python-ideas
> or, via email, send a message with subject or body 'help' to
>        python-ideas-request at python.org
>
> You can reach the person managing the list at
>        python-ideas-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-ideas digest..."
>
>
> Today's Topics:
>
>   1. Anyone working on a platform-agnostic os.startfile() (Hobson Lane)
>   2. Re: Anyone working on a platform-agnostic os.startfile()
>      (Chris Rebert)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 23 Apr 2012 13:21:10 +0800
> From: Hobson Lane <hobsonlane at gmail.com>
> To: python-ideas at python.org
> Cc: Hobson's Totalgood Aliases <knowledge at totalgood.com>
> Subject: [Python-ideas] Anyone working on a platform-agnostic
>        os.startfile()
> Message-ID:
>        <CACZ_DoceeafEpu9wsyG0JPuAGUay0PR91xOZSwzrVy4BGZo1nQ at mail.gmail.com
> >
> Content-Type: text/plain; charset="iso-8859-1"
>
> There is significant interest in a cross-platform
> file-launcher.[1][2][3][4]  The ideal implementation would be
> an operating-system-agnostic interface that launches a file for editing or
> viewing, similar to the way os.startfile() works for Windows, but
> generalized to allow caller-specification of view vs. edit preference and
> support all registered os.name operating systems, not just 'nt'.
>
> Mercurial has a mature python implementation for cross-platform launching
> of an editor (either GUI editor or terminal-based editor like vi).[5][6]
>  The python std lib os.startfile obviously works for Windows.
>
> The Mercurial functionality could be rolled into os.startfile() with
> additional named parameters for edit or view preference and gui or non-gui
> preference. Perhaps that would enable backporting belwo Python 3.x. Or is
> there a better place to incorporate this multi-platform file launching
> capability?
>
>  [1]:
>
> http://stackoverflow.com/questions/1856792/intelligently-launching-the-default-editor-from-inside-a-python-cli-program
>  [2]:
>
> http://stackoverflow.com/questions/434597/open-document-with-default-application-in-python
>  [3]:
>
> http://stackoverflow.com/questions/1442841/lauch-default-editor-like-webbrowser-module
>  [4]:
>
> http://stackoverflow.com/questions/434597/open-document-with-default-application-in-python
>  [5]: http://selenic.com/repo/hg-stable/file/2770d03ae49f/mercurial/ui.py
>  [6]:
> http://selenic.com/repo/hg-stable/file/2770d03ae49f/mercurial/util.py
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/python-ideas/attachments/20120423/e672411c/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Sun, 22 Apr 2012 22:57:30 -0700
> From: Chris Rebert <pyideas at rebertia.com>
> Cc: python-ideas at python.org
> Subject: Re: [Python-ideas] Anyone working on a platform-agnostic
>        os.startfile()
> Message-ID:
>        <CAMZYqRRiRcXGZa50ggxrRRHKjncXq2mv5=+aueAtazB76KfntQ at mail.gmail.com
> >
> Content-Type: text/plain; charset=UTF-8
>
> On Sun, Apr 22, 2012 at 10:21 PM, Hobson Lane <hobsonlane at gmail.com>
> wrote:
> > There is significant interest in a cross-platform
> > file-launcher.[1][2][3][4]??The ideal implementation would be
> > an?operating-system-agnostic interface that launches a file for editing
> or
> > viewing, similar to the way os.startfile() works for Windows, but
> > generalized to allow caller-specification of view vs. edit preference and
> > support all registered os.name operating systems, not just 'nt'.
>
> There is an existing open bug that requests such a feature:
> "Add shutil.open": http://bugs.python.org/issue3177
>
> Cheers,
> Chris
>
>
> ------------------------------
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>
> End of Python-ideas Digest, Vol 65, Issue 43
> ********************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120423/651d3fed/attachment.html>


More information about the Python-ideas mailing list