Re: __missing__ for the top-level Python script

2014-11-12 Thread Chris Angelico
On Mon, Nov 10, 2014 at 10:31 AM, Chris Angelico ros...@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

Re: __missing__ for the top-level Python script

2014-11-12 Thread Ethan Furman
On 11/12/2014 06:37 AM, Chris Angelico wrote: On Mon, Nov 10, 2014 at 10:31 AM, Chris Angelico ros...@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,

Re: __missing__ for the top-level Python script

2014-11-12 Thread Skip Montanaro
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

Re: __missing__ for the top-level Python script

2014-11-12 Thread Dave Angel
Chris Angelico ros...@gmail.com Wrote in message: On Mon, Nov 10, 2014 at 10:31 AM, Chris Angelico ros...@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

Re: __missing__ for the top-level Python script

2014-11-12 Thread Chris Angelico
On Thu, Nov 13, 2014 at 1:56 AM, Skip Montanaro skip.montan...@gmail.com wrote: sys.excepthook = autoload_exc 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

Re: __missing__ for the top-level Python script

2014-11-12 Thread Chris Angelico
On Thu, Nov 13, 2014 at 2:16 AM, Dave Angel da...@davea.name wrote: 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

Re: __missing__ for the top-level Python script

2014-11-12 Thread Skip Montanaro
On Wed, Nov 12, 2014 at 12:49 PM, Chris Angelico ros...@gmail.com wrote: Interesting data point there - that you actually have it handy and choose not to use it. And, I believe I wrote it. Can't have a worse recommendation than that. A cook who doesn't eat his own cooking. :-) I think I

Re: __missing__ for the top-level Python script

2014-11-12 Thread Chris Angelico
On Thu, Nov 13, 2014 at 5:09 AM, Skip Montanaro skip.montan...@gmail.com wrote: On Wed, Nov 12, 2014 at 12:49 PM, Chris Angelico ros...@gmail.com wrote: Interesting data point there - that you actually have it handy and choose not to use it. And, I believe I wrote it. Can't have a worse

__missing__ for the top-level Python script

2014-11-09 Thread Chris Angelico
Let's have some fun nutting out possible implementations for a bad idea :) If you want a dictionary that prepopulates itself on demand, you implement __missing__. Is there a way to implement the same thing for the __main__ module? Since it isn't imported (as such), I don't think switch out what's