Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37570
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'package,': 0.03; 'importing': 0.04; 'none:': 0.05; 'sys': 0.05; "'python": 0.07; 'python': 0.09; 'cherrypy': 0.09; 'cherrypy,': 0.09; 'mkdir': 0.09; 'skip:[ 30': 0.09; 'spec': 0.09; 'subject:command': 0.09; 'thread,': 0.09; 'cc:addr:python-list': 0.10; '"python': 0.16; "'-m',": 0.16; '*any*': 0.16; 'benjamin': 0.16; 'cases:': 0.16; 'cc:name:python list': 0.16; 'enough:': 0.16; 'wrote:': 0.17; 'fixed.': 0.17; 'tim': 0.18; '>>>': 0.18; 'module': 0.19; 'import': 0.21; 'earlier': 0.21; 'cc:2**0': 0.23; 'somewhere': 0.24; 'command': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'skip:[ 10': 0.26; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'cat': 0.29; "d'aprano": 0.29; 'inspect': 0.29; 'issuing': 0.29; 'steven': 0.29; 'case,': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'code': 0.31; '(and': 0.32; 'running': 0.32; 'entry': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'clear': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; 'should': 0.36; 'itself': 0.37; 'two': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'your': 0.60; 'easy': 0.60; 'is.': 0.62; 'between': 0.63; 'information': 0.63; 'making': 0.64; 'believe': 0.69; 'touch': 0.69; '2013': 0.84; 'distinguish': 0.84; 'oscar': 0.84; 'to:addr:mail': 0.91 |
| 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=APm05ks/IMxRMhk9Slx8iOrOM/LqrRUbfgHdBLVws2w=; b=iK4uB7lHPoP6gvmTleDWOH/5aTOXk8Vaa/B6ap/Q3DPGUwJC9GvHppc8Cg9LmlnNMV lW1TfG9J1md0imxbEeOd7Cu+AF2do2HqPpmhOdPt66/NDgQIdToA/5KLKFnpcNvbsasp 0FSA/9G1GLP61Ko2wUr93SZlrAe/lWqChG/yCq10j8nJrY68BYoODspc3Ec8yC+WLGJ8 3cN2MWubKCVW4z5WkJ/K6Q+LZl4i5hdoQVpWHw19emUaGeijKa82yJpaNBTuv/dr5jw0 X3Hh7FTQAXncGf9YBmECxZgKLNzLZqMNFJI3DWgmUv8P8FJLtQDDqSTb6vtZGpWqXX/V NoCA== |
| MIME-Version | 1.0 |
| X-Received | by 10.152.109.210 with SMTP id hu18mr1528705lab.12.1359027029959; Thu, 24 Jan 2013 03:30:29 -0800 (PST) |
| In-Reply-To | <51011340.6020309@timgolden.me.uk> |
| References | <50FE5AC7.3050909@timgolden.me.uk> <kdm962$cc3$1@ger.gmane.org> <mailman.793.1358867242.2939.python-list@python.org> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <mailman.851.1358902404.2939.python-list@python.org> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <mailman.879.1358935287.2939.python-list@python.org> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> <CAHVvXxSHY5OztqH526b3DSuOvR6s8iA4ybh9pbj0pT4BDxQTCw@mail.gmail.com> <51011340.6020309@timgolden.me.uk> |
| Date | Thu, 24 Jan 2013 11:30:29 +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.968.1359027037.2939.python-list@python.org> (permalink) |
| Lines | 63 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1359027037 news.xs4all.nl 6957 [2001:888:2000:d::a6]:35418 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:37570 |
Show key headers only | View raw
On 24 January 2013 10:56, Tim Golden <mail@timgolden.me.uk> wrote: > On 24/01/2013 10:06, Oscar Benjamin wrote: >> On 24 January 2013 04:49, Steven D'Aprano >> <steve+comp.lang.python@pearwood.info> wrote: >> [SNIP] >>> >>> Contrariwise, I don't believe that there is currently *any* way to >>> distinguish between running a script with or without -m. That should be >>> fixed. >> >> As I said earlier in the thread, the __package__ module global >> distinguishes the two cases: >> >> ~$ mkdir pkg >> ~$ touch pkg/__init__.py >> ~$ vim pkg/__main__.py >> ~$ cat pkg/__main__.py >> import sys >> if __package__ is None: >> cmdline = [sys.executable] + sys.argv >> else: >> cmdline = [sys.executable, '-m', __package__] + sys.argv[1:] >> print(cmdline) >> ~$ python pkg/__main__.py arg1 arg2 >> ['q:\\tools\\Python27\\python.exe', 'pkg/__main__.py', 'arg1', 'arg2'] >> ~$ python -m pkg arg1 arg2 >> ['q:\\tools\\Python27\\python.exe', '-m', 'pkg', 'arg1', 'arg2'] > > Reasonable (and thanks for the clear example), but it doesn't work > if the package which is reconstructing the command line the package > which was the target of the original command line. In my case, > I'm making use of the cherrypy reloader, whose __package__ is > cherrypy.process. But the command which invoked the program was > python -m myapp. > > ie I'm issuing "python -m myapp". In myapp.__main__ I'm importing > cherrypy, itself a package, and somewhere in cherrypy.whatever there is > code which attempts to reconstruct the command line. Easy enough: ~$ mkdir pkg ~$ touch pkg/__init__.py ~$ vim pkg/__main__.py ~$ cat pkg/__main__.py import pkg.whatever ~$ vim pkg/whatever.py ~$ cat pkg/whatever.py import sys import pkg.__main__ as main cmdline = [sys.executable, '-m', main.__package__] + sys.argv[1:] print(cmdline) ~$ python -m pkg ['q:\\tools\\Python27\\python.exe', '-m', 'pkg'] ~$ python -m pkg arg1 arg32 ['q:\\tools\\Python27\\python.exe', '-m', 'pkg', 'arg1', 'arg32'] I don't really understand what your spec is. Why do you need to inspect this information from sys.argv? Can you not just always use 'python -m pkg' as your entry point? Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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