Packages:
- package is a directory or folder.
- Application is a collection of packages.
- package is a collection of modules
- package contains related python source files called modules.
- Every module contains classes, variables and functions.
Accessing module inside package:
- ‘from’ keyword need to be used to access any module from the package.
- We must specify the module name while accessing functionality of that module.
…..desktop/pack/one.py :
def m1():
print("pack-one-m1()")
return
def m2():
print("pack-one-m2()")
return
…..desktop/two.py:
from pack import one
one.m1()
one.m2()
Accessing classes in Modules:
- A module is a collection classes.
- We can import the module using ‘from’ keyword
- Accessing class must be possible using module name.
…./desktop/pack/one.py:
class First:
def m1():
print("pack-one-First-m1()")
return
class Second:
def m2(self):
print("pack-one-Second-m2()")
return
…./desktop/access.py:
from pack import one
class Access:
def main():
one.First.m1()
obj = one.Second()
obj.m2()
return
Access.main()