Slide 1

Slide 1 text

z Python Packages

Slide 2

Slide 2 text

z Python Packages: § A package is like a folder which consists of subpackages and modules. § It helps you maintain a program structure and framework by grouping similar modules in one package. § Package is like other directories on your system. A python package has a particular file “__init__.py“ which helps python identify that it is a package. § Use default packages from python official repository. www.pypi.org

Slide 3

Slide 3 text

z When to create Python Packages? § Create package when you have to use repetitive piece of code again and again. § Packages are the code repository for managing your modules, functions and data. § Create modules when you need to share functions/ data with other team members or maybe with other python members.

Slide 4

Slide 4 text

z Importing Python Package: There are multiple ways to import python modules: § Import myPackage.myModule : Import a specific module from the respective package. § from myPackage import myModule : Alternative way of importing a specific module from the respective package. § from myPackage. myModule import func1,func2 : Import specific functions from myModule in the package.

Slide 5

Slide 5 text

z from myPackage.subpackage.myModule Import a specific module from the respective subpackage. from myPackage.subpackage.myModule import func1,func2 Import specific functions from myModule in the subpackage. from myPackage.myModule import * import all the functions and data from the module. (Works only when __all__ is defined in __init__.py file) Importing Python Package:

Slide 6

Slide 6 text

z Creating a python package: Create a folder on your machine Create a __init__.py file in the folder Create classes/modules or subpackages in the main package.

Slide 7

Slide 7 text

z Path to the package § Search Path should be till the folder containing the package. § If the package is not in the same folder as your program, then add the path to the package to PYTHONPATH.

Slide 8

Slide 8 text

z Thanks!