Modules and packages python

November 11, 2017

Most of it has content from stackoverflow question.

  • Modules :
    • These are simple python files with the .py extension, which implement a set of functions/functionality.
    • Modules are imported from other modules using the import command like import file
    • Above will import variables/funtions/classes from
  • Packages :
    • Package is a directory of Python modules containing an additional file.
    • For python package or module are of same type
          >>> import some_module
          >>> type(some_module)
          <type 'module'>
          >>> import some_package
          >>> type(some_package)
          <type 'module'>
    • When we import module we get all it’s function, classes and variable defined in it.
    • When we import package only variables/functions/classes in the file of that package are directly visible, not sub-packages or modules.
    • The directory to be identified as package by python, should have file in that directory
    • Packages can have sub-packages, those directories should have file in the sub-directory.

Please give feedback at