>>First Learn What is Module?>>
Package: It is a Folder containing one or more module and one __init__.py file (in case of python Programming).
Steps to Create a Python Package:
1. Create a folder name "My_Package"
2. Let we Have to Create a Package Having two Module , one init file , One Main Program.
3. Create the above stated File and save in "My_Package" then Run Main program.
Program:
1. Module1.py:
def fun1():
print("I am in fun1 of the Module 1")
def fun2():
print("I am in fun2 of Module 1")
2. Module2.py:
def function1():
print("I am in function 1 of the Module 2")
def function2():
print("I am in function 2 of Module 2")
3. __init__.py:
from module1 import module1
from module2 import module2
4. Main.py:
from module1 import *
from module2 import function1
from module2 import function2
fun1()
fun2()
print()
function1()
function2()
Expected O/P: {Running Main.py}
I am in fun1 of the Module 1
I am in fun2 of Module 1
I am in function 1 of the Module 2
I am in function 2 of Module 2
0 Comments
Post a Comment