Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. Modules in Python
  5. Packages in python

Packages in python

Packages are directory with some specific classes, functions, etc. which we can use it later as per our convenience. We don’t save all the files in our computer system, so we create packages that are useful for later use and can be imported and used in our programs.

One or more modules can be put into a package. It must contain a special folder __init__.py.

Steps for creating a package:-

  1. Create a folder.
  2. Create a sub-folder with the same name.
  3. Place module files inside the sub folder.
  4. Create __init__.py folder.
  5. Create setup.py in the parent file.
  • We have to make directory first with a name suitable for the use.
  • Add some specific classes in it.

syantx:-

class class_name1: 
    "class functions"

class class_name2: 
    "class functions"
  • Now create __init__.py function so that we can import package.

syntax:-

form package_name import function_name
.
.
program in which it is used
.
.

This is all about packages in python.

Was this article helpful to you? Yes No

How can we help?