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


Groups > comp.lang.python > #80608

Re: __missing__ for the top-level Python script

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <skip.montanaro@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; 'else:': 0.03; 'subject:Python': 0.06; 'none:': 0.07; 'string': 0.09; 'exec': 0.09; 'subject:script': 0.09; 'sys,': 0.09; 'thrown': 0.09; 'va,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'language.': 0.14; '(note': 0.16; 'commented': 0.16; 'inspect,': 0.16; 'subject:top': 0.16; 'module': 0.19; 'normally': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; '2.x': 0.24; 'days,': 0.24; 'skip': 0.24; 'math': 0.24; "haven't": 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'this.': 0.32; 'probably': 0.32; 'subject:the': 0.34; "i'd": 0.34; "can't": 0.35; 'something': 0.35; 'received:google.com': 0.35; 'crazy': 0.36; 'similar': 0.36; 'skip:- 10': 0.38; 'does': 0.39; 'bad': 0.39; 'users': 0.40; 'new': 0.61; 'to:addr:gmail.com': 0.65; 'mail.': 0.69; 'attentive': 0.84; 'wanting': 0.93
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 :cc:content-type; bh=tKofKuR2YYNF70SOWLjjjmaqGs057SAfyLnoXuddNO4=; b=sbVOjTegtBp69QOHqbKA/B5pswFkjJ7QrjTTeEeWbB2YAqcBRYghpVEn5hVfN5j4do pPMR7+wbCvaRRmWw/8+pPKohNS2onBUYKsHenrvD3ZHkZPBAvGd5bg4cFxgs9pOwscSp xmhp+QmsZaUn3tQ7Xl6Naxhtgud440RdlIssi4gAM34rexjz0iWj+MB++NKw1mCog1xL MvhxkprO3e0T3diDCTtGJhEE414/e0TaNFysPelxiGq8051IhYD/htPfEiE+Ll8XejY3 FxipYquNCcJgcgVQKeHsqEtSTHfUz3LH7+ebbSG+b7I22h3pa8scWEqXUQqUtziD73RW OlUA==
MIME-Version 1.0
X-Received by 10.51.16.37 with SMTP id ft5mr39966919igd.6.1415804218076; Wed, 12 Nov 2014 06:56:58 -0800 (PST)
In-Reply-To <CAPTjJmrhz7crC2_x+ZN9sLgPvd8B1Yn8skzMSTBXJ6gSj55TqQ@mail.gmail.com>
References <CAPTjJmpVVfPzwrbeornk9Txyfiz+H5MDfHG2nY_9va7RCUEmEw@mail.gmail.com> <CAPTjJmrhz7crC2_x+ZN9sLgPvd8B1Yn8skzMSTBXJ6gSj55TqQ@mail.gmail.com>
Date Wed, 12 Nov 2014 09:56:58 -0500
Subject Re: __missing__ for the top-level Python script
From Skip Montanaro <skip.montanaro@gmail.com>
To Chris Angelico <rosuav@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc "python-list@python.org" <python-list@python.org>
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.15724.1415804230.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415804230 news.xs4all.nl 2899 [2001:888:2000:d::a6]:47130
X-Complaints-To abuse@xs4all.nl
X-Received-Body-CRC 2834451857
X-Received-Bytes 4690
Xref csiph.com comp.lang.python:80608

Show key headers only | View raw


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

I was on vacation for a few days, so haven't been all that attentive
to my mail. I have an autoload module which does something similar
(note the Python 2.x syntax):

import sys, inspect, traceback, re

def autoload_exc(ty, va, tb):
    mat = re.search("name '([^']*)' is not defined", va.args[0])
    if mat is not None:
        modulename = mat.group(1)
        print >> sys.stderr, "autoloading", modulename
        f_locals = tb.tb_frame.f_locals
        f_globals = tb.tb_frame.f_globals

        exec "import " + modulename in f_locals, f_globals
        exec tb.tb_frame.f_code in f_locals, f_globals
    else:
        traceback.print_exception(ty, va, tb)

sys.excepthook = autoload_exc

which works about as you'd expect:

>>> sys.excepthook
<function autoload_exc at 0x1a5e140>
>>> math.sin(42)
autoloading math
-0.9165215479156338
>>> string.uppercase
autoloading string
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

I can't see a lot of people wanting this (I normally have its import
commented out in my PYTHONSTARTUP file), and I think it would probably
be bad practice for new users of the language.

Skip

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


Thread

Re: __missing__ for the top-level Python script Skip Montanaro <skip.montanaro@gmail.com> - 2014-11-12 09:56 -0500

csiph-web