Book Image

Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

By : Dan Nixon
Book Image

Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

By: Dan Nixon

Overview of this book

Table of Contents (18 chapters)
Getting Started with Python and Raspberry Pi
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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.

  1. First, create a new directory named calcpy and move the calculator directory inside it. This calcpy directory will be the packaged library.

  2. Now, create an empty Python file named __init__.py inside the calcpy directory using the following command. This file will tell Python that the calcpy directory should be treated as a module.

    touch __init__.py
    
  3. Next, create another directory called calcpy that contains the calcpy directory created in the previous step. This directory...