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


Groups > comp.lang.python > #80607

Re: __missing__ for the top-level Python script

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
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; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'happen.': 0.09; 'message- id:@stoneleaf.us': 0.09; 'subject:script': 0.09; 'suppress': 0.09; 'thrown': 0.09; '~ethan~': 0.09; 'be:': 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; 'header:User-Agent:1': 0.23; 'mon,': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'feature': 0.29; 'am,': 0.29; 'raised': 0.31; 'this.': 0.32; 'url:python': 0.33; 'trouble': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'done.': 0.35; 'but': 0.35; 'crazy': 0.36; 'module.': 0.36; 'url:org': 0.36; 'should': 0.36; 'nov': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'url:3': 0.61; 'received:173': 0.61; 'simple': 0.61; 'save': 0.62; 'usage.': 0.84
Date Wed, 12 Nov 2014 06:54:56 -0800
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: __missing__ for the top-level Python script
References <CAPTjJmpVVfPzwrbeornk9Txyfiz+H5MDfHG2nY_9va7RCUEmEw@mail.gmail.com> <CAPTjJmrhz7crC2_x+ZN9sLgPvd8B1Yn8skzMSTBXJ6gSj55TqQ@mail.gmail.com>
In-Reply-To <CAPTjJmrhz7crC2_x+ZN9sLgPvd8B1Yn8skzMSTBXJ6gSj55TqQ@mail.gmail.com>
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 <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.15723.1415804101.18130.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415804101 news.xs4all.nl 2896 [2001:888:2000:d::a6]:44557
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80607

Show key headers only | View raw


On 11/12/2014 06:37 AM, Chris Angelico wrote:
> 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.

You might check out https://docs.python.org/3/library/sys.html#sys.excepthook

--
~Ethan~

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


Thread

Re: __missing__ for the top-level Python script Ethan Furman <ethan@stoneleaf.us> - 2014-11-12 06:54 -0800

csiph-web