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
calcpy
and move thecalculator
directory inside it. Thiscalcpy
directory will be the packaged library. - Now, create an empty Python file named
__init__.py
inside thecalcpy
directory using the following command. This file will tell Python that thecalcpy
directory should be treated as a module.touch __init__.py
- Next, create another directory called
calcpy
that contains thecalcpy
directory created in the previous step. This directory...