What is the difference between __init__.py and setup.py and __main.py
When using function as modules, they use a setup.py files, but when I use pycharm, it generates a init.py.
So my question is.
What is the difference between a module and a package in python.
What is the difference between init.py & setup.py?
__main.py
A module is a single .py file. A package is a directory that contains a file named __init__.py and usually other files as well, but which acts like a module. It's imported the same way you import a single file module (except you import by the directory name not by a file name), and it acts like a single module, even though the implementation can be split among many files/submodules.
setup.py is used by distutils/setuptools and is concerned with building, distributing, and installing the module. For example, it's where dependencies are stated so that when you use a tool like pip to install a package, it can also ensure you have all the dependencies installed, or fetch and install them if you don't. But after the module/package is installed, setup.py isn't really in the picture any more. __init__.py on the other hand is run every time you import the package, and in many cases it's the central core of functionality.
A module is a single .py file that can be imported from other files - think of it as a file.
A package is a folder of .py files / modules that has a hierarchy and structure. Think of it as a folder.
__init__.py basically tells python that this folder is a python package, and to look for .py files (modules) in this directory.
setup.py is typically used to install/test your python module with setuptools and has no relation to __init__.py
Comments
Post a Comment