The perfect place for easy learning...



Topics List

Python Packages

In Python, a package is a directory which must contains a file. This file can be an empty file.

A package in the Python can contain any file with .py extension including modules.

How to create a package?

To create a package in Python, just create a directory with the package name, then create an empty file inside that directory. Then the directory acts as a package which can be imported the same way a module can be imported.

Now, we can place any python file in this directory so that it becomes a member of that package.

How to use a package?

To use a package in python, we must import the package using import statement the same way a module has imported in the earlier tutorials.

For example, a package with name My_Package can be imported as import My_Package. A specific module can also be imported using the syntax from Package_Name import Module_Name.

Your ads here