package:
- package is nothing but a folder or directory which represents collection of python modules.
- any folder or directory contains python modules,that folder or directory is called python package.
- any folder or directory called python package that folder or directory contains __init__.py module(file)
- a package can contain python modules and also can contain sub-packages.
- every sub-package should contain __init__.py module(file)
We can import the
properties of modules of packages using
- import package_name. module_name
- from package_name. module_name import property
create directory
with dir1 and place below x.py in dir1
a=10
def f1( ):
print("In f1 of x")
create directory
with dir2 in dir1 and place below y.py in dir2
b=20
def f2( ):
print("In f2 of y")
test.py must be outside dir1 folder
import dir1.x
from dir1.dir2.y import b,f2
print(dir1.x.a)
dir1.x.f1()
print(b)
f2()
10
In f1 of x
20
In f2 of y
No comments:
Post a Comment