New submission from Chris Angelico: Creating an issue to keep track of a patch, but this probably wants to be discussed on python-ideas.
The attached patch allows a Python function to be put into sys.__getglobal__, which then works like __getattr__ but for global names. This allows interactive interpreters to auto-import, for instance: def try_import(n): try: return __import__(n) except ImportError: raise NameError("Name %r is not defined"%n) import sys sys.__getglobal__ = try_import ---------- components: Interpreter Core files: nameerror_hook.patch keywords: patch messages: 233149 nosy: Rosuav priority: normal severity: normal status: open title: Add Python hook function to replace NameError versions: Python 3.5 Added file: http://bugs.python.org/file37551/nameerror_hook.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23126> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com