Skip to content

Modules

surendrabisht edited this page Jul 13, 2020 · 1 revision

Modules are pieces of code already written earlier which can be used in your program to reuse the logic
written in that file.

Every python file is in itself is a module. When someone wants to use the logic written in this file, this file is a module for that file.We can import the functions/classes from module using:

import <modulename> 
or
from <modulename> import <functionName> 
or
from <modulename> import <functionName> as <aliasName>

and then call the function as :


<modulename>.<functionName>() 
or
<functionName>() 
or
<aliasName>()


sys.path refers to your Python’s system path. This is the list of
directories that Python goes through to search for modules and files or your current directory.

To add your python modules to sys.path, so you can import them easily using below code .
import sys
if 'drive:\\yourModulesFolder' not in sys.path:
sys.path.append('drive:\\yourModulesFolder')

3 types of Modules
    1. written by own
    2. Standard Library: libraries pre-installed from Python.
    3. External third- party libraries


Many Third-party python modules are stored on the Python Package Index.
PyPi.
To install these applications,pip command can be used which is provided
by default with modern distribution of Python.

-> pip install <libraryname>

Clone this wiki locally