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


Groups > comp.lang.python > #21180

Re: The original command python line

References <4obb29-os3.ln1@archaeopteryx.softver.org.mk>
Date 2012-03-03 21:48 -0800
Subject Re: The original command python line
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.369.1330840141.3037.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Mar 3, 2012 at 9:38 PM, Damjan Georgievski <gdamjan@gmail.com> wrote:
> How can I get the *really* original command line that started my python
> interpreter?
>
> Werkzeug has a WSGI server which reloads itself when files are changed
> on disk. It uses `args = [sys.executable] + sys.argv` to kind of
> recreate the command line, and the uses subprocess.call to run that
> command line.
>
> BUT that's problematic as, when you run::
>
>        python -m mypackage --config
>
> sys.argv printed in mypackage/__main__.py will be::
>
>        ['/full/path/to/mypackage/__main__.py', '--config']
>
> so you get::
>
>        python /full/path/to/mypackage/__main__.py --config
>
> instead of::
>
>        python -m mypackage --config
>
>
> the difference in the 2 cases is what the current package is, and
> whether you can use relative imports.

On Linux, you can read from:
    /proc/<PID here>/cmdline
to get the null-delimited "command line".

Sidenote: Consensus generally seems to be that relative imports are a bad idea.

Cheers,
Chris

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


Thread

The original command python line Damjan Georgievski <gdamjan@gmail.com> - 2012-03-04 06:38 +0100
  Re: The original python command line Damjan Georgievski <gdamjan@gmail.com> - 2012-03-04 06:52 +0100
  Re: The original command python line Chris Rebert <clp2@rebertia.com> - 2012-03-03 21:48 -0800
    Re: The original command python line Grant Edwards <invalid@invalid.invalid> - 2012-03-04 14:34 +0000
  Re: The original command python line Chris Rebert <clp2@rebertia.com> - 2012-03-03 21:57 -0800
    Re: The original command python line Damjan Georgievski <gdamjan@gmail.com> - 2012-03-04 07:20 +0100
      Re: The original command python line Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-03-04 02:19 -0500

csiph-web