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


Groups > comp.lang.python > #37611

Re: Retrieving the full command line

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <mail@timgolden.me.uk>
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; '(python': 0.05; 'say,': 0.05; 'python': 0.09; 'filesystem': 0.09; 'imports': 0.09; 'logic': 0.09; 'module)': 0.09; 'outlined': 0.09; 'path.': 0.09; 'subject:command': 0.09; 'attribute,': 0.16; 'benjamin': 0.16; 'dropping': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'message-id:@timgolden.me.uk': 0.16; 'none"': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'rerun': 0.16; 'script?': 0.16; 'sys.path': 0.16; 'tjg': 0.16; 'to:name:python list': 0.16; 'string': 0.17; 'wrote:': 0.17; 'module,': 0.17; 'module': 0.19; 'issue.': 0.20; 'written': 0.20; 'bit': 0.21; 'meant': 0.21; 'implicit': 0.22; 'branch': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; '2.6': 0.27; 'opposed': 0.27; "doesn't": 0.28; 'run': 0.28; 'waters': 0.29; '(including': 0.30; 'relative': 0.30; 'primary': 0.30; 'code': 0.31; 'running': 0.32; 'could': 0.32; "aren't": 0.33; 'received:192.168.100': 0.33; 'to:addr:python-list': 0.33; 'version': 0.34; 'described': 0.35; 'there': 0.35; 'but': 0.36; "didn't": 0.36; 'too': 0.36; 'problems': 0.36; 'does': 0.37; 'option': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'little': 0.39; 'received:192.168': 0.40; 'between': 0.63; 'more': 0.63; 'differences': 0.65; 'direct': 0.69; 'from:addr:mail': 0.71; 'oscar': 0.84; 'package?': 0.84; 'say:': 0.84; 'drops': 0.91
Date Thu, 24 Jan 2013 17:13:09 +0000
From Tim Golden <mail@timgolden.me.uk>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1
MIME-Version 1.0
To Python List <python-list@python.org>
Subject Re: Retrieving the full command line
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> <CAHVvXxRFVn0BQy=4EsW30OJB+reVhO7teNyrRVdczVD+W_+R_A@mail.gmail.com> <51013B0C.6000309@timgolden.me.uk> <CAHVvXxSwbXD_C_zfn4nTj9XTFUzBJXRk+nzaE8xPW76t+M7cjw@mail.gmail.com> <51015885.9060104@timgolden.me.uk> <CAHVvXxTOU8ERsCpnKECOsBNKquWfqqXJRmqhWkDtRRV+CR8NYw@mail.gmail.com> <CAHVvXxTUOOhwZCiN6+eRTvX2Rj-KGOsNwmgaRrvN4ccm==qZGw@mail.gmail.com>
In-Reply-To <CAHVvXxTUOOhwZCiN6+eRTvX2Rj-KGOsNwmgaRrvN4ccm==qZGw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
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.999.1359047594.2939.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359047594 news.xs4all.nl 6954 [2001:888:2000:d::a6]:45606
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37611

Show key headers only | View raw


On 24/01/2013 16:53, Oscar Benjamin wrote:
>> Does it work if you use the -m option to run a module rather than a script?
> 
> Sorry that was written incorrectly. I meant to say: does it work when
> a module is directly on sys.path rather than as a submodule of a
> package? In this case __package__ is set to the empty string if run
> with -m or None if run with a direct path. So the check needs to be
> "__package__ is not None" rather than "bool(__package__)".

The answer is: it depends. Given the code I outlined earlier:

A package-based module run via -m (python -m package.module) works
as described (including the implicit __main__ module, my
primary use-case).

A module run from the filesystem (python c:\path\to\module.py) works
by dropping through through to the not is_package logic branch.

A module run via -m (python -m module) actually works by accident,
because it too drops through to the not is_package branch and is
rerun with its full filesystem path. This doesn't have the same
problems as running a package from the filesystem because relative
imports aren't an issue. I don't know if there are any other differences
between python -mmodule and python c:\path\to\module.py.

As you say, a more refined check could determine a blank __package__
as opposed to a None __package__. But this code (cherrypy) must also
cope with version of Python before 2.6 which didn't even have a
__package__ attribute, muddying the waters that little bit further.

TJG

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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