Packaging your own Python modules
Now that we have seen how the Python packages can be downloaded and installed, we will look at how they can be created from our own modules. For now, we will only look at how they are packaged and leave out the process of publishing it to a repository.
Packaging a library
We will first look at how to package a library that can be imported by other Python scripts and applications.
We will start with a copy of the calculator module that we created in Chapter 3, Working with Data Structures and I/O.
- First, create a new directory named
calcpyand move thecalculatordirectory inside it. Thiscalcpydirectory will be the packaged library. - Now, create an empty Python file named
__init__.pyinside thecalcpydirectory using the following command. This file will tell Python that thecalcpydirectory should be treated as a module.touch __init__.py - Next, create another directory called
calcpythat contains thecalcpydirectory created in the previous step. This directory...