Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.maint.python > #8612

Python program as a command-line program (was: Python package providing both modules and an app)

From Ben Finney <ben+debian@benfinney.id.au>
Newsgroups linux.debian.maint.python
Subject Python program as a command-line program (was: Python package providing both modules and an app)
Date 2016-06-23 03:20 +0200
Message-ID <rN1tg-2Ol-11@gated-at.bofh.it> (permalink)
References <rMBfr-2Hb-9@gated-at.bofh.it> <rMF9n-57L-25@gated-at.bofh.it> <rN19U-2q7-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Barry Warsaw <barry@debian.org> writes:

> On Jun 22, 2016, at 11:25 AM, Ben Finney wrote:
>
> >There is a compounding tendency to disparage ‘python3 ./foo/bar.py’,
> >[…]. I wish this trend could be effectively reversed, because IMO
> >this is a serious impediment to considering Python a good choice for
> >command-line scripting.
>
> Sorry, I don't quite understand the above. Do you mean that you would
> rather use `python3 ./foo/bar.py` more often and `python3 -m foo.bar`
> less often?

When ‘./foo/bar.py’ has a shebang of ‘#! /usr/bin/python3’, and I invoke
that path as a command, the Unix shebang semantics turn that into
‘/usr/bin/python3 ./foo/bar.py’. Python will run the file as the main
module.

But invoking it that way runs into the nastiness and constraints
described in PEP 366 (primarily, relative imports break).

There isn't, AFAIK, anything portable that I can write in the shebang to
turn a command invocation of ‘./foo/bar.py’ into ‘python3 -m foo.bar’.

So yes, I expect Unix shebang semantics to work, and the fact that
design decisions in Python's import mechanism defeat that mode is an
impediment to using Python for writing command-line programs.

-- 
 \              “Dvorak users of the world flgkd!” —Kirsten Chevalier, |
  `\                                                rec.humor.oracle.d |
_o__)                                                                  |
Ben Finney

Back to linux.debian.maint.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Python package providing both modules and an app Hugo Lefeuvre <hle@debian.org> - 2016-06-21 23:20 +0200
  Re: Python package providing both modules and an app Ben Finney <ben+debian@benfinney.id.au> - 2016-06-22 03:30 +0200
    Re: Python package providing both modules and an app Hugo Lefeuvre <hle@debian.org> - 2016-06-22 22:00 +0200
      Re: Python package providing both modules and an app Ben Finney <ben+debian@benfinney.id.au> - 2016-06-23 03:10 +0200
        Re: Python package providing both modules and an app Hugo Lefeuvre <hle@debian.org> - 2016-06-23 18:40 +0200
          Re: Python package providing both modules and an app Hugo Lefeuvre <hle@debian.org> - 2016-06-30 08:30 +0200
      Re: Python package providing both modules and an app Thomas Goirand <zigo@debian.org> - 2016-07-05 10:50 +0200
    Re: Python package providing both modules and an app Barry Warsaw <barry@debian.org> - 2016-06-23 03:00 +0200
      Python program as a command-line program (was: Python package providing both modules and an app) Ben Finney <ben+debian@benfinney.id.au> - 2016-06-23 03:20 +0200
        Re: Python program as a command-line program (was: Python package  providing both modules and an app) Barry Warsaw <barry@debian.org> - 2016-06-24 21:30 +0200
          Re: Python program as a command-line program Ben Finney <ben+debian@benfinney.id.au> - 2016-06-27 09:00 +0200
      Re: Python package providing both modules and an app Ian Cordasco <graffatcolmingov@gmail.com> - 2016-06-23 03:30 +0200
  Re: Python package providing both modules and an app Thomas Goirand <zigo@debian.org> - 2016-07-05 10:40 +0200
    Re: Python package providing both modules and an app Hugo Lefeuvre <hle@debian.org> - 2016-07-05 16:50 +0200
      Re: Python package providing both modules and an app Thomas Goirand <zigo@debian.org> - 2016-07-05 21:00 +0200

csiph-web