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


Groups > comp.lang.python > #80606

Re: __missing__ for the top-level Python script

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@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; 'explicitly': 0.05; 'importing': 0.05; 'represents': 0.05; 'subject:Python': 0.06; 'absent': 0.09; 'happen.': 0.09; 'subject:script': 0.09; 'suppress': 0.09; 'thrown': 0.09; 'be:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'globals(),': 0.16; 'importerror': 0.16; 'modules,': 0.16; 'raised,': 0.16; 'semantics': 0.16; 'subject:top': 0.16; 'wrote:': 0.18; '(not': 0.18; 'successful,': 0.19; 'import': 0.22; 'python?': 0.22; 'to:name:python-list@python.org': 0.22; 'mon,': 0.24; 'header:In- Reply-To:1': 0.27; 'chris': 0.29; 'feature': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'raised': 0.31; 'this.': 0.32; 'trouble': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'done.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'crazy': 0.36; 'module.': 0.36; 'should': 0.36; 'nov': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'simple': 0.61; 'save': 0.62; 'usage.': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=TYIr7oKDQqF/wlcFr3i+2T/tLzPRH23tybKVtbbLdK4=; b=WI+Q6SVShh6ClvLAQfE+dyfHcIyV5Si69zRy5P8ZtFUZEzxpX4yr0lhDYdjeiIEkQw R1g8hR6UMt+KywOZrRzBjddTZK4nQhxjMTNpgmUvb8pKitkm5HUFev9KS6iZv+4nUkem cOBPiqxNO9n+k2Wp0M35mxHTaBYfdI66YOo4atoRF6m2JuxVZhVAkJs1xm77bG3zayKE 8ga4zuhdoc0VcKxXJK7gi/hJHdlPR5Ajj6a1qTizv2vzNxdOeIpak9eGDB0jVSlw+cuh yLsDXMiKT6beY/sL+hjzI9ld4IWj8WxUvJpGBUchtYaL14QeJv7s8ZT+sdcCf3QVNe83 fisw==
MIME-Version 1.0
X-Received by 10.107.134.89 with SMTP id i86mr24770249iod.53.1415803032381; Wed, 12 Nov 2014 06:37:12 -0800 (PST)
In-Reply-To <CAPTjJmpVVfPzwrbeornk9Txyfiz+H5MDfHG2nY_9va7RCUEmEw@mail.gmail.com>
References <CAPTjJmpVVfPzwrbeornk9Txyfiz+H5MDfHG2nY_9va7RCUEmEw@mail.gmail.com>
Date Thu, 13 Nov 2014 01:37:12 +1100
Subject Re: __missing__ for the top-level Python script
From Chris Angelico <rosuav@gmail.com>
To "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15722.1415803041.18130.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415803041 news.xs4all.nl 2904 [2001:888:2000:d::a6]:41492
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80606

Show key headers only | View raw


On Mon, Nov 10, 2014 at 10:31 AM, Chris Angelico <rosuav@gmail.com> wrote:
> So the semantics should be: If NameError would be raised (not
> including UnboundLocalError, which still represents an error), attempt
> to import the absent name. If successful, continue as if it had
> already been done. If ImportError is raised, suppress it and let the
> original NameError happen.

No bites? I'd have thought there'd be a few crazy ideas thrown out in
answer to this.

What if it's worded as a feature for interactive Python? Save you the
trouble of explicitly importing modules, by auto-importing them in
response to usage. In theory, it's as simple as adding __missing__ to
globals(), but I don't know of a way to do that for the main module.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: __missing__ for the top-level Python script Chris Angelico <rosuav@gmail.com> - 2014-11-13 01:37 +1100

csiph-web