Professional Documents
Culture Documents
Divya
Divya
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.
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 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}"