Friday, 8 June 2012

Python namespaces


          Namespaces are mapping from names to objects . They are a collection of names in a module . Here in a single module no two names of methods are to be similar for obvious reasons. The other thing one has to remember is there is no connection between the names in different namespaces. Say two different modules may define same function "maximize" without confusion , so the user must prefix the module.

        Any name following the dot is an attribute so guass.solve here guass is a module and solve is a function name . The method is called directly and then can be used in the similar manner.    In order to remove the methods (on in this case - attribute) , we can use
del module.attribute

       Namespaces are created at different times and have different life spans. They are some that are called when a module is imported into the terminal . Also there are global variables within a namespace , local variables within a namespace .

In the below code some clarification can be achieved.
Loading ....

   The namespaces are important before going into the details . As because it forms the zen of python .
For details about zen of python . type into your python interpreter
import this

So , we will be continuing with python classes and metaclasses very soon.

No comments:

Post a Comment