开发者

documentations about how __init__.py works?

开发者 https://www.devze.com 2023-03-26 06:24 出处:网络
I stumbled over the import of __init__.py in python packages. See posts: different import results at different directories

I stumbled over the import of __init__.py in python packages. See posts:

  • different import results at different directories
  • how to reload a Class in python shell?

I was directed by Nate to very good explanations at this post:

Adding code to __init__.py.

I want to read more about this topic and more related topics. C开发者_JAVA百科ould anyone suggest further formal documentations or books on the topics? TIA!


Start here:

Python provides some acceptable tutorials which lead you to a basic understanding how the concepts of the language work.

This http://docs.python.org/tutorial/modules.html describes how modules and their initializers work.

In addition to that - if you want it the most formal way and can't get along with the language documentation for some reason - look in the PEPs (e.g. PEP 273 dealing with module imports from zip files)


I found a very good explanation at:

http://effbot.org/zone/import-confusion.htm#what-does-python-do

and the critical sentence for me was:

When Python imports a module, it first checks the module registry (sys.modules) to see if the module is already imported. If that’s the case, Python uses the existing module object as is.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号