Is there a way to determine -- when parsing -- if a word contains a builtin name or other imported system module name?

Peter Hansen peter at engcorp.com
Thu Aug 4 21:00:47 EDT 2005


Casey Hawthorne wrote:
> Is there a way to determine -- when parsing -- if a word contains a
> builtin name or other imported system module name?

As David pointed out, the keys in sys.modules are the names of all 
imported modules throughout the interpreter (but not just those in the 
current scope).

Likewise, do "import __builtin__" and you'll have access to all the 
builtin names, which you could test against using "hasattr(__builtin__, 
name)".

-Peter



More information about the Python-list mailing list