Daily Weekly Monthly

Daily Shaarli

All links of one day in a single page.

March 13, 2019

How to Create a Python Package - Python Central

When you've got a large number of Python classes (or "modules"), you'll want to organize them into packages. When the number of modules (simply stated, a module might be just a file containing some classes) in any project grows significantly, it is wiser to organize them into packages – that is, placing functionally similar modules/classes in the same directory. This article will show you how to create a Python package.

Steps to Create a Python Package

Working with Python packages is really simple. All you need to do is:

Create a directory and give it your package's name.
Put your classes in it.
Create a __init__.py file in the directory

That's all! In order to create a Python package, it is very easy. The init.py file is necessary because with this file, Python will know that this directory is a Python package directory other than an ordinary directory (or folder – whatever you want to call it). Anyway, it is in this file where we'll write some import statements to import classes from our brand new package.