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

  • Thread starter Casey Hawthorne
  • Start date
C

Casey Hawthorne

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

Like "iskeyword" determines if a word is a keyword!
 
D

David M. Cooke

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

Like "iskeyword" determines if a word is a keyword!

Look in the keyword module; there is actually an "iskeyword" function
there :)

For modules, sys.modules is a dictionary of the modules that have been
imported.
 
P

Peter Hansen

Casey said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top