Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '(python': 0.05; 'think,': 0.07; 'python': 0.09; 'imports': 0.09; 'subject:command': 0.09; 'sys.argv[0]': 0.09; 'thread': 0.11; 'cases': 0.15; '"python': 0.16; 'benjamin': 0.16; 'dotted': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'message-id:@timgolden.me.uk': 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; 'say.': 0.16; 'tjg': 0.16; 'to:name:python list': 0.16; 'wrote:': 0.17; 'module,': 0.17; 'tim': 0.18; 'input': 0.18; 'module': 0.19; 'are:': 0.20; 'implicit': 0.22; 'work.': 0.23; 'split': 0.23; "haven't": 0.23; 'command': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'looks': 0.26; 'common': 0.26; 'am,': 0.27; 'instead.': 0.27; 'opposed': 0.27; 'run': 0.28; 'archives': 0.29; "i'm": 0.29; '(including': 0.30; 'primary': 0.30; 'code': 0.31; 'point': 0.31; 'asking': 0.32; 'running': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; "can't": 0.34; 'thanks': 0.34; 'described': 0.35; 'path': 0.35; 'received:192.168.0': 0.35; 'but': 0.36; 'modules': 0.36; 'does': 0.37; 'two': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'help': 0.40; 'think': 0.40; 'you.': 0.61; 'back': 0.62; 'strange': 0.62; 'direct': 0.69; 'from:addr:mail': 0.71; 'hoping': 0.72; '2013': 0.84; 'case?': 0.84; 'increasingly': 0.84; 'oscar': 0.84; 'touched': 0.84; 'checks.': 0.91; 'package"': 0.91; 'received:192.168.0.5': 0.91; 'walking': 0.91 Date: Thu, 24 Jan 2013 20:54:44 +0000 From: Tim Golden User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: Python List Subject: Re: Retrieving the full command line 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> <51011340.6020309@timgolden.me.uk> <51013B0C.6000309@timgolden.me.uk> <51015885.9060104@timgolden.me.uk> <51016BA5.6010401@timgolden.me.uk> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359060887 news.xs4all.nl 6924 [2001:888:2000:d::a6]:39090 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37630 On 24/01/2013 20:01, Oscar Benjamin wrote: > On 24 January 2013 17:13, Tim Golden wrote: >> A package-based module run via -m (python -m package.module) works >> as described (including the implicit __main__ module, my >> primary use-case). > > Does it work in the "python -m package.module" case? It looks to me as > if the code below will run "python -m package" instead. I think you > need to split the module name out of sys.argv[0] and put that into the > command line as well. Good catch. Unless I am, once again, mistaken, I can't see any way of recreating a dotted module path which is running as a main module without the somewhat fragile expedient of walking back up the filepath and hoping that nothing strange has happened to the imports on the way down? (pywin32: I'm looking at you!) And we haven't even touched on zipped archives or other invented loaders (pulling modules from a database or direct from the internet). I think, though, that the point which with I started this thread is still valid: that to reconstruct the command line with which Python was started, you need an increasingly awkward set of conditions and checks. As opposed to asking the interpreter: please give me the command line which started you. How common that particular requirement actually is, I couldn't say. But the two cases which clearly could use it are: the reloader setup we've been discussing here; and the apply-new-version-and-restart which I'm hoping to use in another setup at work. Thanks for all the help and input on this, Oscar TJG