__getattr__ for global namespace?

Harold Fellermann dadapapa at googlemail.com
Thu May 4 07:50:18 EDT 2006


Hi,

I am writing an application that initializes the global namespace, and
afterwards, leaves the user with the python prompt. Now, I want to
catch NameErrors in user input like e.g.

>>> some_name
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'some_name' is not defined

For classes, there are the __getattr__ and __getattribute__ functions.
I wonder if there is some related function for (failed) global
attribute
lookup that is invoked with name as its argument instead.

I consulted the docs, but could not find anything. Any ideas?

- harold -




More information about the Python-list mailing list