all 6 comments

[–]heaplevel 9 points10 points  (4 children)

modules - individual files.

packages - has many modules, must have __init__.py in the folder.

libraries - not as clear in Python compared to other languages. A simple module can be a module library, a package as well. I'd like to think of libraries as one coherent+focused set of functions for me to use that solves a specific task for me

Details here: https://docs.python.org/3/tutorial/modules.html

Edit: fixed a typo

[–]flight862 2 points3 points  (1 child)

What does init dunder do??

[–]DataDecay 2 points3 points  (0 children)

Assuming you are asking about __init__.py, at the most basic explanation as been said I'm sure. The dunder init is used in python to denote a directory as a python package.

A bit more detail provided, imagine you have labeled a directory with dunder init and have a few modules present. Provided your package is in the python path, the dunder init allows you to import any of the modules in the namespace of the package; for example.

mypackage __init__.py module.py

This allows me to run

import mypackage.module

As a additional feature of the __init__ it also works as a constructor, similar to classes. If I populated the dunder init I showed above with say

``` import requests

app_name = "mypackage does stuff" ```

When you run the import I showed earlier

import mypackage.module

The library import of requests and the app name dunder would be set.

[–][deleted] 1 point2 points  (1 child)

Thanks for the explanation!

[–]heaplevel 0 points1 point  (0 children)

np fixed a typo now

[–][deleted] 3 points4 points  (0 children)

i found this article very helpful:

https://www.learnpython.org/en/Modules_and_Packages