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

Discussion in 'Python' started by Casey Hawthorne, Aug 4, 2005.

  1. 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
     
    Casey Hawthorne, Aug 4, 2005
    #1
    1. Advertising

  2. Casey Hawthorne <> 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
     
    David M. Cooke, Aug 4, 2005
    #2
    1. Advertising

  3. Casey Hawthorne

    Peter Hansen Guest

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

    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
     
    Peter Hansen, Aug 5, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dun Peal
    Replies:
    10
    Views:
    473
    Chris Rebert
    May 3, 2011
  2. bdb112
    Replies:
    2
    Views:
    317
    Chris Torek
    Jul 2, 2011
  3. Andrew Berg
    Replies:
    3
    Views:
    114
    Steven D'Aprano
    Oct 2, 2011
  4. Volker Nicolai
    Replies:
    9
    Views:
    1,123
    Fabian Pilkowski
    Jul 4, 2005
  5. Pavils Jurjans
    Replies:
    3
    Views:
    236
    Pavils Jurjans
    Mar 18, 2005
Loading...

Share This Page