In Python writing script is a main task across all the data analytics project. This post tells you how to create sample macros and importing into your python interpreter and process or steps to execute it.
A module is created as a script file, which contains function definitions that can be called in two ways:
How to import
>>> import fact
# This program illustrates the designing/creation of a module def factorial(n): "This module computes factorial" f=1; for i in range (1, n+1): f=f*i; print(f) return
What is reloading the scriptThe Python interpreter imports a module only once in a session. If some modifications are performed in the module script then it must be reloaded (imported) again in the interpreter for further use.
A script is reusable component and you can add n number of functions inside of it.
Directory functionIn order to see the list of function names defined in a module, Python is provided with a built-in function called dir(). It displays the list of all the function definition names as follows:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__','__name__', '__package__','__spec__', 'fib']
Other way if we give 'module' name in dir(), you will get list of all functions inside of it.