Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37608
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.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 | <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; 'args': 0.04; 'importing': 0.04; 'case.': 0.05; "'python": 0.07; 'args)': 0.07; 'pretend': 0.07; 'try:': 0.07; 'python': 0.09; 'cherrypy': 0.09; 'fetch': 0.09; 'imported': 0.09; 'nameerror:': 0.09; 'path.': 0.09; 'pep': 0.09; 'spec': 0.09; 'subclass': 0.09; 'subject:command': 0.09; 'url:peps': 0.09; 'cc:addr:python-list': 0.10; 'cases': 0.15; 'slightly': 0.15; "'-m',": 0.16; '(via': 0.16; '...]': 0.16; 'benjamin': 0.16; 'cc:name:python list': 0.16; 'merely': 0.16; 'none"': 0.16; 'script?': 0.16; 'somehow.': 0.16; 'sys.path': 0.16; 'string': 0.17; 'wrote:': 0.17; 'certainly': 0.17; 'url:dev': 0.17; 'tim': 0.18; '>>>': 0.18; 'module': 0.19; 'equivalent': 0.20; 'written': 0.20; 'sort': 0.21; 'import': 0.21; 'thanks.': 0.21; 'meant': 0.21; 'os,': 0.22; 'skip:_ 20': 0.22; 'cc:2**0': 0.23; 'this:': 0.23; 'command': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'skip:[ 10': 0.26; '(which': 0.26; 'skip:" 20': 0.26; 'guess': 0.27; 'message-id:@mail.gmail.com': 0.27; 'run': 0.28; '>>>>': 0.29; 'inspect': 0.29; 'piece': 0.29; 'restart': 0.29; "i'm": 0.29; 'compatible': 0.30; 'code': 0.31; 'url:python': 0.32; 'structure': 0.32; 'loading': 0.33; 'anyone': 0.33; 'knowledge': 0.33; 'entry': 0.33; 'skip:b 20': 0.34; 'received:google.com': 0.34; 'whatever': 0.35; 'false': 0.35; 'identified': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'really': 0.36; 'except': 0.36; 'but': 0.36; 'url:org': 0.36; 'does': 0.37; 'option': 0.37; 'why': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'application': 0.40; 'your': 0.60; "you've": 0.61; 'face': 0.61; 'first': 0.61; 'back': 0.62; 'is.': 0.62; 'information': 0.63; 'talking': 0.66; 'direct': 0.69; 'benefit': 0.70; '2013': 0.84; 'brilliant.': 0.84; 'me).': 0.84; 'oscar': 0.84; 'package?': 0.84; 'say:': 0.84; 'seen.': 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=G4eViOmvHKgJ0/mgYVQkshUEe3dOz3nBfc6zxd/mI1g=; b=a6062RKDVS9sRlpz7HtnOxeQEtJOWUB9678nSaNmufBBOoLr7uP4uQsLbN/yLE90L0 /EEzt2Mqaxk3bthLXVJyWIuEMhnHsBA0AweQzBXJH2NZAbK7gEyc2lkNd7zE2QBTJIy9 54dodyME4G2Yy6RZxbgvWERF4RU7LJ4aKfcNVS39+lEmR0QNwWUEnoLaxEO0uL+B0XuE BwoyXeC4JxDd1RPQlPIYycNd4fHXm5Bv9KRekkvgLkudLUyz3TuV9Lh5VvqnBvy+3gyM XE31k8VWmCysZWUDjczpcnH72Sn4tE5ir8l4RYE2XW4DEg3GZ9BiLSsE8LufpvVlFhsn 0qZA== |
| MIME-Version | 1.0 |
| X-Received | by 10.112.11.105 with SMTP id p9mr1004946lbb.129.1359046438981; Thu, 24 Jan 2013 08:53:58 -0800 (PST) |
| In-Reply-To | <CAHVvXxTOU8ERsCpnKECOsBNKquWfqqXJRmqhWkDtRRV+CR8NYw@mail.gmail.com> |
| 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> |
| Date | Thu, 24 Jan 2013 16:53:58 +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.997.1359046446.2939.python-list@python.org> (permalink) |
| Lines | 67 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1359046446 news.xs4all.nl 6913 [2001:888:2000:d::a6]:35600 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:37608 |
Show key headers only | View raw
On 24 January 2013 16:08, Oscar Benjamin <oscar.j.benjamin@gmail.com> wrote: > On 24 January 2013 15:51, Tim Golden <mail@timgolden.me.uk> wrote: >> On 24/01/2013 15:28, Oscar Benjamin wrote: >>> On 24 January 2013 13:45, Tim Golden <mail@timgolden.me.uk> wrote: >>>> On 24/01/2013 11:30, Oscar Benjamin wrote: >>>>> 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? >>>> >>> [SNIP] >>>> >>>> For completeness, I'm talking about the cherrypy Autoreloader which >>>> attempts to restart (via execv) whatever process was responsible for >>>> loading it in the first place, via an identical or equivalent command >>>> line. The current (cherrypy) code simply joins sys.executable and >>>> sys.argv but this fails in the face of python -m as we have seen. >>>> >>>> The cherrypy package has no especial knowledge of the structure of the >>>> application which imported it and so must piece together the command >>>> line somehow. Clearly, I can take various approaches of the sort >>>> which you've outlined, or subclass the reloader, or fetch the original >>>> command line from the OS, etc. It's not that this is a showstopper, >>>> merely slightly surprising. (To me). >>> >>> Ok I understand. Then I guess you want: >>> >>> import __main__ >>> pkg = __main__.__package__ >> >> Brilliant. Never thought of importing __main__. Thanks. >> >> For the benefit of anyone still watching, the code (which has to be >> compatible back to 2.3) looks something like this: >> >> <code> >> import __main__ >> >> # [.. .snip ...] >> >> try: >> is_package = bool(__main__.__package__) >> except NameError: >> is_package = False >> if is_package: >> args = [sys.executable, '-m', __main__.__package__] + sys.argv[1:] >> else: >> args = [sys.executable] + sys.argv >> >> os.chdir(_startup_cwd) # avoids relative/absolute issues >> os.execv(args[0], args) >> >> </code> >> >> I don't pretend it's foolproot, but it certainly works for my particular >> case. Nor have I considered it against all the cases identified in PEP >> 432: http://www.python.org/dev/peps/pep-0432/#configuring-sys-argv > > 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__)". 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