Explanation of Python namespaces

后端 未结 2 693
無奈伤痛
無奈伤痛 2021-02-07 02:21

I am looking for a good introduction to Python namespaces. I found this tutorial to be good, but I\'m sure there is more to the story than that.

The Python reference con

相关标签:
2条回答
  • 2021-02-07 02:55

    It is all tied to naming in Python. Names are attached to objects in such a way that they can be detached and given to a new object. All objects without names are removed from memory (see here). Names available in your module are implemented as dictionaries and can be displayed using the __dict__ attribute.

    Type in

    >>> import time  
    >>> time.__dict__  
    

    The result is a dictionary containing the names used in defining objects in the built-in module time.

    0 讨论(0)
  • 2021-02-07 02:59

    They're really not all that complex. The import mechanisms can be somewhat complex and with relative imports now it can get even a bit more tricky, but as far as actual namespaces and how they're resolved in code, that tutorial seems to be pretty comprehensive.

    The language reference is always kind of the be-all, end-all however, but it's often overkill for those starting out.

    If you have any specific questions as to how certain things work, you'll get good responses on here.

    0 讨论(0)
提交回复
热议问题