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: 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: References: Date: Thu, 13 Nov 2014 01:37:12 +1100 Subject: Re: __missing__ for the top-level Python script From: Chris Angelico To: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Mon, Nov 10, 2014 at 10:31 AM, Chris Angelico 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