How to import other Python files?

importlib was added to Python 3 to programmatically import a module. The .py extension should be removed from moduleName. The function also defines a package argument for relative imports. In python 2.x: Just import file without the .py extension A folder can be marked as a package, by adding an empty __init__.py file You can use the __import__ function, which takes the module name (without … Read more

What is __init__.py for?

It used to be a required part of a package (old, pre-3.3 “regular package”, not newer 3.3+ “namespace package”). Here’s the documentation. Python defines two types of packages, regular packages and namespace packages. Regular packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is typically implemented as a directory … Read more

What is __init__.py for?

It used to be a required part of a package (old, pre-3.3 “regular package”, not newer 3.3+ “namespace package”). Here’s the documentation. Python defines two types of packages, regular packages and namespace packages. Regular packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is typically implemented as a directory … Read more

What is setup.py?

setup.py is a python file, the presence of which is an indication that the module/package you are about to install has likely been packaged and distributed with Distutils, which is the standard for distributing Python Modules. This allows you to easily install Python packages. Often it’s enough to write: pip will use setup.py to install … Read more