Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

If you have been coding in python, even for a while, you must be familiar with the

concept of ‘pip’ by now.


It is a package management system used to install and manage software
packages/libraries written in Python.
Then one may ask that where are all these packages/libraries stored?
It is obvious that there must be a large “on-line repository” which stores all
this code.
And the answer to this question is Python Package Index (PyPI).

PyPI is the official third-party software repository for Python


a
packages makes projects easy to manage and conceptually clear
*python package is a directory containing
@sub packages
@modules
@along with an__init__.py file

We have included a __init__.py, file inside a directory to tell Python that the
current directory is a package.
Whenever you want to create a package, then you have to include __init__.py file
in the directory.
You can write code inside or leave it as blank as your wish. It doesn't bothers
Python.

Follow the below steps to create a package in Python

Create a directory and include a __init__.py file in it to tell Python that the
current directory is a package.
Include other sub-packages or files you want.
Next, access them with the valid import statements.
Let's create a simple package that has the following structure.

Package (university)

__init__.py
student.py
faculty.py
Go to any directory in your laptop or desktop and create the above folder
structure.
After creating the above folder structure include the following code in respective
files.
example:

# student.py
class Student:

def __init__(self, student):


self.name = student['name']
self.gender = student['gender']
self.year = student['year']

def get_student_details(self):
return f"Name: {self.name}\nGender: {self.gender}\nYear: {self.year}"

# faculty.py
class Faculty:
def __init__(self, faculty):
self.name = faculty['name']
self.subject = faculty['subject']

def get_faculty_details(self):
return f"Name: {self.name}\nSubject: {self.subject}"

You might also like