0

Based on this post: What is __init__.py for?, I know that __init__.py in a module has two functions: 1) make the directory into a package so that the module can be imported. 2) do some necessary initialization job, if any. My question is when this __init__.py is executed? Every time the module is imported into a module? Or there is something like a shared library in the memory so that this __init__.py is only executed once in the whole application?
Further, I do not find good resources on how python interpreter executes python code, any suggestions on this would be appreciated.

Amadan
  • 191,408
  • 23
  • 240
  • 301
Quan Zhou
  • 307
  • 1
  • 12

1 Answers1

3

__init__.py is executed when imported on the first time. The latter imports in an application lifetime always loads from cache file.

  • 1
    "The latter imports in an application lifetime always loads from cache" ...unless reloaded (for example, via `importlib.reload`. – Amadan Jul 27 '18 at 04:09