Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'imports': 0.07; 'python': 0.08; 'subject:python': 0.10; '*really*': 0.16; '--config': 0.16; 'disk.': 0.16; 'skip:\xc2 40': 0.16; 'subject:command': 0.16; 'wsgi': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'seems': 0.20; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; 'linux,': 0.21; 'header:In-Reply-To:1': 0.22; 'changed': 0.23; 'command': 0.24; 'sat,': 0.25; 'cc:2**0': 0.26; 'skip:[ 10': 0.27; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'server': 0.30; 'generally': 0.30; 'recreate': 0.30; 'chris': 0.30; 'cases': 0.32; 'instead': 0.33; 'received:209.85.214': 0.36; 'run': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'difference': 0.38; 'received:209.85': 0.38; 'uses': 0.38; 'files': 0.39; 'received:209': 0.39; 'from:': 0.40; 'header:Received:6': 0.61; 'kind': 0.62; 'subject:The': 0.69; 'problematic': 0.84; 'sender:addr:chris': 0.84; 'subject:original': 0.84 Received-SPF: pass (google.com: domain of chris@rebertia.com designates 10.205.133.13 as permitted sender) client-ip=10.205.133.13; Authentication-Results: mr.google.com; spf=pass (google.com: domain of chris@rebertia.com designates 10.205.133.13 as permitted sender) smtp.mail=chris@rebertia.com; dkim=pass header.i=chris@rebertia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=B1LlNbItf88NUGf9Jm5kJfyYm7YXX4GUsNNdlxLDNno=; b=DdO/wDDkYdQCsUg1wkctkCi2gA46Z0MR5Ub9IlfbqZkbK3dbsVNLeGMB4mzZ1fhonW k3Lc1+ZqzFNP80gcI6pJnglHgSs6EgFD48Zq5G5LiTzvTVJxko/kgN5ZqLZZ+SlWRINb VNdEuzzOp++tQ0vP5v+JJfvGEGtLPkYUkdUI0= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Date: Sat, 3 Mar 2012 21:48:58 -0800 X-Google-Sender-Auth: XTsX4WYwFOXceCqLIKj6gzU9Des Subject: Re: The original command python line From: Chris Rebert To: Damjan Georgievski Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQmLfEXDLHYgh72B5e9dWXazD/Bko7Fp0S47M5OXz7hcI2DoUKQ8lMfu5illx+pwYkXbJH6u Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1330840141 news.xs4all.nl 6872 [2001:888:2000:d::a6]:44884 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21180 On Sat, Mar 3, 2012 at 9:38 PM, Damjan Georgievski wrot= e: > How can I get the *really* original command line that started my python > interpreter? > > Werkzeug has a WSGI server which reloads itself when files are changed > on disk. It uses `args =3D [sys.executable] + sys.argv` to kind of > recreate the command line, and the uses subprocess.call to run that > command line. > > BUT that's problematic as, when you run:: > > =C2=A0 =C2=A0 =C2=A0 =C2=A0python -m mypackage --config > > sys.argv printed in mypackage/__main__.py will be:: > > =C2=A0 =C2=A0 =C2=A0 =C2=A0['/full/path/to/mypackage/__main__.py', '--con= fig'] > > so you get:: > > =C2=A0 =C2=A0 =C2=A0 =C2=A0python /full/path/to/mypackage/__main__.py --c= onfig > > instead of:: > > =C2=A0 =C2=A0 =C2=A0 =C2=A0python -m mypackage --config > > > the difference in the 2 cases is what the current package is, and > whether you can use relative imports. On Linux, you can read from: /proc//cmdline to get the null-delimited "command line". Sidenote: Consensus generally seems to be that relative imports are a bad i= dea. Cheers, Chris