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


Groups > comp.lang.python > #37389

Re: Retrieving the full command line

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
X-Original-To Python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'none:': 0.05; 'tmp': 0.07; 'used.': 0.07; 'python': 0.09; 'cherrypy': 0.09; 'imports': 0.09; 'mkdir': 0.09; 'rebuild': 0.09; 'subject:command': 0.09; 'cc:addr:python-list': 0.10; 'cc:name:python list': 0.16; 'determining': 0.16; 'wrote:': 0.17; 'tim': 0.18; 'module': 0.19; 'combination': 0.22; 'cc:2**0': 0.23; 'linux': 0.24; 'command': 0.24; 'script': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'appear': 0.26; 'skip:" 20': 0.26; 'message-id:@mail.gmail.com': 0.27; 'developing': 0.28; 'run': 0.28; 'cat': 0.29; "i'm": 0.29; 'relative': 0.30; '(and': 0.32; 'running': 0.32; 'print': 0.32; 'like:': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'development.': 0.36; 'does': 0.37; 'option': 0.37; 'uses': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'within': 0.64; 'touch': 0.69; 'combining': 0.71; '2013': 0.84; 'internally.': 0.84; 'oscar': 0.84; 'to:addr:mail': 0.91; 'imagine': 0.96
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=Lyjo4ICmCIhn4lmCyCV4L+g4kirH5wKP8b5kcs9prcI=; b=nNbktLkKCt63vfDQp7IbCZAZ+XD5ZyeOEoqkhkodB1+JY+oE3rhvCoqvLneYCLInp7 COzajGPFJlicRw2DlRL3cpbiaNO/4MuoD1iB1H0Fm7L1slooTBMUpyM3hQ0yneQ9tG6Z wRmL6lhlcySwACwZq4tfasqxArIdj+CSsTA5w3Xi7fAe7kujWDuHWJSfsSYk/Uty0+yI cqdFGcREKwhMFU8q+21T/xxuBxcsP+bYcizqnvUZoXozAWCLyddzl649nj++QzxQcopA uNHxahNFHwx1wZXmcT28KNWJmeaYYnUJnHtJaE20NVA+tJGlGWKAhR5dbKMtmtVklOJV 0wYw==
MIME-Version 1.0
X-Received by 10.152.144.71 with SMTP id sk7mr23195756lab.29.1358903655499; Tue, 22 Jan 2013 17:14:15 -0800 (PST)
In-Reply-To <50FE5AC7.3050909@timgolden.me.uk>
References <50FE5AC7.3050909@timgolden.me.uk>
Date Wed, 23 Jan 2013 01:14:15 +0000
Subject Re: Retrieving the full command line
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
To Tim Golden <mail@timgolden.me.uk>
Content-Type text/plain; charset=ISO-8859-1
Cc Python List <Python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.852.1358903657.2939.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358903657 news.xs4all.nl 6857 [2001:888:2000:d::a6]:49724
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37389

Show key headers only | View raw


On 22 January 2013 09:24, Tim Golden <mail@timgolden.me.uk> 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.

I tried this on Linux but I imagine that it works the same on Windows.
You can check the value of the __package__ module global:

~$ mkdir tmp
~$ touch tmp/__init__.py
~$ vim tmp/__main__.py
~$ cat tmp/__main__.py
if __package__ is None:
    print 'Running as a script'
else:
    print 'Running with the -m option'
~$ python tmp/__main__.py
Running as a script
~$ python -m tmp
Running with the -m option


Oscar

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


Thread

Re: Retrieving the full command line Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-23 01:14 +0000

csiph-web