__missing__ for the top-level Python script

Chris Angelico rosuav at gmail.com
Wed Nov 12 15:37:12 CET 2014

On Mon, Nov 10, 2014 at 10:31 AM, Chris Angelico <rosuav at 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.


More information about the Python-list mailing list