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. Advertisements

  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. Advertisements

  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. Advertisements

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. nas
    Replies:
    10
    Views:
    657
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=
    Jun 19, 2007
  2. Paul Rubin
    Replies:
    5
    Views:
    597
    Hendrik van Rooyen
    Aug 6, 2009
  3. Dun Peal
    Replies:
    10
    Views:
    708
    Chris Rebert
    May 3, 2011
  4. bdb112
    Replies:
    2
    Views:
    455
    Chris Torek
    Jul 2, 2011
  5. Andrew Berg
    Replies:
    3
    Views:
    164
    Steven D'Aprano
    Oct 2, 2011
  6. John Smith
    Replies:
    8
    Views:
    366
    David K. Wall
    Sep 26, 2003
  7. Volker Nicolai
    Replies:
    9
    Views:
    2,100
    Fabian Pilkowski
    Jul 4, 2005
  8. Pavils Jurjans
    Replies:
    3
    Views:
    416
    Pavils Jurjans
    Mar 18, 2005
Loading...