0

From what I understand a Python package is merely a folder that contains Python Modules (i.e. files), but also has the __init__.py file.

Is this file necessary if the modules are going to be imported locally, and why is it necessary to declare a module, since most of the code I have seen this file is just empty.

It seems unnecessarily complicated, what extra functionality does a blank file grant?

zigarn
  • 10,892
  • 2
  • 31
  • 45
sinavix742
  • 90
  • 6
  • *"[...] what extra functionality does a blank file grant?"* It makes the folder a package. – Klaus D. Aug 04 '21 at 06:38
  • @KlausD. ... but what is the point, when you can reference it the same anyway? – sinavix742 Aug 04 '21 at 06:41
  • You can't import a folder but you can import a package. – Klaus D. Aug 04 '21 at 06:45
  • Not sure about the exact reasoning but it is probably to prevent accidentally importing a `.py` file from any directory. You must explicitly specify it as a Python package by including the `__init__py`, even if it is empty. – Selcuk Aug 04 '21 at 06:50

0 Answers0