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


Groups > comp.lang.python > #37279

Re: Retrieving the full command line

Date 2013-01-22 15:07 +0000
From Tim Golden <mail@timgolden.me.uk>
Subject Re: Retrieving the full command line
References <50FE5AC7.3050909@timgolden.me.uk> <kdm962$cc3$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.793.1358867242.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 22/01/2013 14:53, Terry Reedy wrote:
> On 1/22/2013 4:24 AM, Tim Golden wrote:
>> [Python 2.7/3.3 (and hg tip) running on Windows. Not Windows-specific,
>> though].
>>
>> I use the python -mpackage incantation to run a package which has a
>> __main__.py module and which uses relative imports internally.
>>
>> I'm developing under cherrypy which includes a reloader for development.
>> The reloader attempts to rebuild the original
>> command line by combining sys.executable and sys.argv and then does an
>> execv.
>>
>> There does not appear to be any way within Python of determining the
>> command line I used. The combination of sys.executable and sys.argv in
>> this case will look like: "c:\python33\python.exe app/__main__.py". But
>> running this precludes the use of package-relative imports.
> 
> If I understand right, the reloader should be updated to translate
> 'x/__main__.py' to '-m x'. Filenames of form'__x__' are reserved, in a
> sense, like similar identifiers in programs, and '__main__.py' should
> not be used for a file meant to executed directly.

To be clear: it's Python itself, not the reloader, which is coming up
with __main__.py. sys.executable is "c:\python33\python.exe" and
sys.argv is ['c:\path\to\__main__.py'] for a program which has been
started by "c:\python33\python.exe -mpath\to".

Obviously, there is any number of ways around this specific issue,
including what you suggest: a canonical rewrite of "python
path\to\__main__.py" into "python -mpath\to". But it's not clear to me
that this rewrite should be the responsibility of calling code.

TJG

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Retrieving the full command line Tim Golden <mail@timgolden.me.uk> - 2013-01-22 15:07 +0000
  Re: Retrieving the full command line Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:46 +0000
    Re: Retrieving the full command line Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-23 00:53 +0000
      Re: Retrieving the full command line Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-23 03:58 +0000
        Re: Retrieving the full command line Tim Golden <mail@timgolden.me.uk> - 2013-01-23 09:58 +0000
        Re: Retrieving the full command line Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-23 10:01 +0000
          Re: Retrieving the full command line Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-24 04:49 +0000
            Re: Retrieving the full command line Chris Angelico <rosuav@gmail.com> - 2013-01-24 16:06 +1100
            Re: Retrieving the full command line Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-24 10:06 +0000
            Re: Retrieving the full command line Tim Golden <mail@timgolden.me.uk> - 2013-01-24 10:56 +0000
            Re: Retrieving the full command line Tim Golden <mail@timgolden.me.uk> - 2013-01-24 11:04 +0000
            Re: Retrieving the full command line Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-24 11:30 +0000
            Re: Retrieving the full command line Tim Golden <mail@timgolden.me.uk> - 2013-01-24 13:45 +0000
            Re: Retrieving the full command line Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-24 15:28 +0000
            Re: Retrieving the full command line Tim Golden <mail@timgolden.me.uk> - 2013-01-24 15:51 +0000
            Re: Retrieving the full command line Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-24 16:08 +0000
            Re: Retrieving the full command line Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-24 16:53 +0000
            Re: Retrieving the full command line Tim Golden <mail@timgolden.me.uk> - 2013-01-24 17:13 +0000
            Re: Retrieving the full command line Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-24 20:01 +0000
            Re: Retrieving the full command line Tim Golden <mail@timgolden.me.uk> - 2013-01-24 20:54 +0000

csiph-web