Title here
Summary here
In this article, we will see how to use packages in Python. We can use packages as a namespace and organize a big project.
In the root of the project folder, create the folders and files
.
├── hive
│ ├── __init__.py
│ ├── server.py
└── test_hive.py
The __init__.py
is an empty file. It tells Python to treat hive folder as a package. The hive is the package directory.
The contents of server.py
:
def hello():
print("Hello from Hive!")
You can now use the package in your code.
from hive import server
server.hello()
From the project folder:
python3 test_hive.py
Hello from Hive!
We now have a working setup for creating and using packages.