Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80609
| Path | csiph.com!usenet.pasdenom.info!news.franciliens.net!fdn.fr!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'method.': 0.07; 'source.': 0.07; 'absent': 0.09; 'happen.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'suppress': 0.09; 'thrown': 0.09; 'python': 0.11; 'wrote': 0.14; 'attribute,': 0.16; 'attributes.': 0.16; 'be:': 0.16; 'globals': 0.16; 'globals(),': 0.16; 'importerror': 0.16; 'modules,': 0.16; 'raised,': 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'semantics': 0.16; 'subject:top': 0.16; 'userdict': 0.16; 'wrote:': 0.18; '(not': 0.18; 'module': 0.19; 'trying': 0.19; 'successful,': 0.19; 'work,': 0.20; 'import': 0.22; 'python?': 0.22; 'mon,': 0.24; 'equivalent': 0.26; 'header:X-Complaints-To:1': 0.27; 'chris': 0.29; 'feature': 0.29; 'am,': 0.29; "doesn't": 0.30; 'work.': 0.31; 'code': 0.31; 'raised': 0.31; 'class': 0.32; 'this.': 0.32; 'implemented': 0.33; 'trouble': 0.34; 'skip:_ 10': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'could': 0.34; 'done.': 0.35; 'but': 0.35; 'add': 0.35; 'crazy': 0.36; 'module.': 0.36; 'next': 0.36; 'should': 0.36; 'changing': 0.37; 'being': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'short': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'challenge': 0.61; 'simple': 0.61; 'save': 0.62; 'within': 0.65; 'dict,': 0.84; 'dict.': 0.84; 'presumably': 0.84; 'slots.': 0.84; 'usage.': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dave Angel <davea@davea.name> |
| Subject | Re: __missing__ for the top-level Python script |
| Date | Wed, 12 Nov 2014 10:16:15 -0500 (EST) |
| Organization | news.gmane.org |
| References | <CAPTjJmpVVfPzwrbeornk9Txyfiz+H5MDfHG2nY_9va7RCUEmEw@mail.gmail.com> <CAPTjJmrhz7crC2_x+ZN9sLgPvd8B1Yn8skzMSTBXJ6gSj55TqQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | 97.73.240.77 |
| X-Newsreader | PiaoHong.Usenet.Client.VIP:1.65 |
| X-Archive | encrypt |
| 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.15725.1415805379.18130.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1415805379 news.xs4all.nl 2957 [2001:888:2000:d::a6]:50575 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:80609 |
Show key headers only | View raw
Chris Angelico <rosuav@gmail.com> Wrote in message: > 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 > I gave it a short whirl, just trying to make __missing__ work. The type of globals () is a dict. I was able to add a __missing__:myfunct to the instance but in order to work, the __missing__ must be added as a class attribute, a method. And dict, being implemented in C, doesn't let you add class attributes. Presumably the C code does the equivalent of slots. So the next thing to try would be to try to force the module dictionary to be a userdict without slots. Then we could add the necessary method. But that would be changing the python source. I wasn't sure that was within the challenge constraints. -- DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: __missing__ for the top-level Python script Dave Angel <davea@davea.name> - 2014-11-12 10:16 -0500
csiph-web