Day14

Pramod Ray
2 min readOct 1, 2019

Modular Programming: Modular programming is technique split code in separate parts.In other words: Minimization of dependencies is the goal.

Advantage of modular Programming
1. Simplicity
2. Maintainability
3. Re-usability
4. Scoping

Python Modules:

1. A module can be written in python itself.(suffix .py)
2. A module can be written in c and loaded dynamically at the run-time, like the re(regular expression), datetime, calendar e.t.c

The Module Search Path: When the interpreter the above import statement, it searched for mod.py .

1. The directory from which the input script was run on the current   directory if the interpreter is being run interactively
2. The list of directories contained in the PythonPath environment variable
3. An installation-dependent list of directories configured at the time Python in installed

The import Statement: Module contents are made available to the caller with the import statement.

import <module_name>

An alternate from of the import statement allow individual objects the module to be imported directly into the caller’s symbol table

from <module_name>import module

It is also possible to import individual object but enter them into the local symbol table with alternate names

from <module_name> import<name> as<alt_name>

Package : In Python, When the number of modules in any project grows significantly, it is wiser to organize them into packages that is, placing functionally similar modules/classes in the same directory. or,

Package are a way of structuring many modules which helps in a well-organized hierarchy of data set, making the directories and modules easy to access. Just like there are different drives and folders in an OS to help us store files, similarly packages help us in storing other sub-packages and modules, so that it can be used by the user when necessary.

Steps of create package :

  1. Create a directory and give it your package’s name.
  2. Put your classes in it.
  3. Create a __init__.py file in the directory

--

--