469,353 Members | 2,041 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

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

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!

--
Regards,
Casey
Aug 4 '05 #1
2 1146
Casey Hawthorne <ca***************@istar.ca> writes:
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.

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Aug 4 '05 #2
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
Aug 5 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Berteun Damman | last post: by
18 posts views Thread by Christopher W. Douglas | last post: by
7 posts views Thread by Eric Wertman | last post: by
6 posts views Thread by Paul Wilson | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.