Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37611
| Date | 2013-01-24 17:13 +0000 |
|---|---|
| From | Tim Golden <mail@timgolden.me.uk> |
| Subject | Re: Retrieving the full command line |
| References | (11 earlier) <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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.999.1359047594.2939.python-list@python.org> (permalink) |
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 | 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