Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is there a way to determine -- when parsing -- if a word contains a builtin name or other imported system module name?

Reply
Thread Tools

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

 
 
Casey Hawthorne
Guest
Posts: n/a
 
      08-04-2005
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
 
Reply With Quote
 
 
 
 
David M. Cooke
Guest
Posts: n/a
 
      08-04-2005
Casey Hawthorne <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      08-05-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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any way to access attributes from an imported module? Andrew Berg Python 3 10-02-2011 08:50 AM
subtle error slows code by 10x (builtin sum()) - replace builtin sumwithout using import? bdb112 Python 2 07-02-2011 03:13 AM
Why do directly imported variables behave differently than thoseattached to imported module? Dun Peal Python 10 05-03-2011 10:11 PM
"Variable ... is not imported..." using an imported variable from a module Volker Nicolai Perl Misc 9 07-04-2005 08:34 AM
Read form "name" attribute when it contains form field with name "name" Pavils Jurjans Javascript 3 03-18-2005 01:39 PM



Advertisments