Is namespace available in Python?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • psbasha
    Contributor
    • Feb 2007
    • 440

    #1

    Is namespace available in Python?

    Hi,

    Is namespace available in Python?.


    Thanks
    PSB
  • Che M
    New Member
    • Feb 2007
    • 7

    #2
    Originally posted by psbasha
    Hi,

    Is namespace available in Python?.


    Thanks
    PSB
    Namespaces? If I understand you correctly, yes!

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by psbasha
      Hi,

      Is namespace available in Python?.


      Thanks
      PSB
      The .__dict__ attribute of an object stores its namespace. This includes modules. There is a 'builtin' module called __main__ that stores the main namespace.
      Use globals() and locals() to see what is in the respective dictionaries.
      The inspect library module is used do access regularly needed items. The Pythonic term is introspection and python is quite good at it.
      For example, a function can look at the arguments that it was called with in some very cool ways, but this a very advanced topic.

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by bartonc
        The .__dict__ attribute of an object stores its namespace. This includes modules. There is a 'builtin' module called __main__ that stores the main namespace.
        Use globals() and locals() to see what is in the respective dictionaries.
        The inspect library module is used do access regularly needed items. The Pythonic term is introspection and python is quite good at it.
        For example, a function can look at the arguments that it was called with in some very cool ways, but this a very advanced topic.
        This is pretty cool:

        >>> help(vars)
        Help on built-in function vars in module __builtin__:

        vars(...)
        vars([object]) -> dictionary

        Without arguments, equivalent to locals().
        With an argument, equivalent to object.__dict__ .

        >>>

        Comment

        Working...