Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Importing Python Packages

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for PythonSpice PythonSpice
December 31, 2018

Importing Python Packages

The presentation gives details about the python packages , how to import packages, why do we need packages .

Avatar for PythonSpice

PythonSpice

December 31, 2018
Tweet

Other Decks in Education

Transcript

  1. 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
  2. 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.
  3. 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.
  4. 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:
  5. 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.
  6. 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.