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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'none:': 0.05; 'sys': 0.05; 'python': 0.09; 'mkdir': 0.09; 'skip:[ 30': 0.09; 'subject:command': 0.09; 'thread,': 0.09; 'cc:addr:python- list': 0.10; "'-m',": 0.16; '*any*': 0.16; 'cases:': 0.16; 'cc:name:python list': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.17; 'fixed.': 0.17; 'module': 0.19; 'import': 0.21; 'earlier': 0.21; 'cc:2**0': 0.23; '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; 'cat': 0.29; "d'aprano": 0.29; 'steven': 0.29; "skip:' 10": 0.30; 'running': 0.32; 'received:google.com': 0.34; 'received:209.85': 0.35; 'there': 0.35; 'should': 0.36; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'between': 0.63; 'believe': 0.69; 'touch': 0.69; '2013': 0.84; 'distinguish': 0.84; 'oscar': 0.84 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=77ZOmrdl35mYN96Fv1wgyRjRcyW+wE83U2C9t+4X0eY=; b=xx7KZRhS5f2iWFdywONqtx4vOqCZyFPnTAfB5+Nn/GIFOD7jvOL9OlF3FZVJk3fU+2 knJcCEYeX4VQ5uMNZt2YQTw0EhtiVjv3mAs35eRCsGst8KQ4HEn4jstSsUe8dO8bLX2T YVIElTmsbhT2fSouzCKovQIZzTN5cQkQQ36oBta0anJx55P76Iy2Vk+E1DM7OU7hZlg9 OSxbly/63VdzZLWa/xyuD3nAmrlDRo2Hvtm9kXdhKK4uZ/atLqpWj0YPvadpBhWTx4yE HYKevZwJ0Dz+lDxDLL9+3rwTeYmJkSOCIzkyBpn9IAMnyIvhmjwE1FXEz5Dv5MgLo/zG D9Lg== MIME-Version: 1.0 X-Received: by 10.112.11.105 with SMTP id p9mr500008lbb.129.1359021998012; Thu, 24 Jan 2013 02:06:38 -0800 (PST) In-Reply-To: <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> References: <50FE5AC7.3050909@timgolden.me.uk> <50ff24e8$0$29994$c3e8da3$5496439d@news.astraweb.com> <50ff5ffc$0$29877$c3e8da3$5496439d@news.astraweb.com> <5100bd49$0$29877$c3e8da3$5496439d@news.astraweb.com> Date: Thu, 24 Jan 2013 10:06:37 +0000 Subject: Re: Retrieving the full command line From: Oscar Benjamin To: "Steven D'Aprano" Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359022006 news.xs4all.nl 6872 [2001:888:2000:d::a6]:57952 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37548 On 24 January 2013 04:49, Steven D'Aprano 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'] Oscar