Python-06 (Modules and File Input-Output)
Python-06 (Modules and File Input-Output)
Modules
Module is a file consisting of Python code.
It allows to organize Python code.
Import Statement Syntax:
>>> import ModuleName
FromImport Statement Syntax:
>>> from ModuleName import SubModule_1,
SubModule_2, SubModule_3 SubModule_n
Conti
Module-02
Module-03
Module-01
Conti
Module-01
Outputs
Modules Location
Python Interpreter searches for the module in
the following sequences, while importing the
module:
The current directory
Then, searches each directory in the shell variable
PYTHONPATH
Then, check the default path. In unix, default path
is /usr/local/lib/python/
File Input-Output
Keyword Input:
There are two build function in Python to read
a line of text from slandered input.
row_input
Example :
Str=row_input(Enter the inout=)
print(received input=,str)
input
Example :
Str=input(Enter the inout=)
print(received input=,str)
File Input-Output
Input() function is equivalent to row_input(), but
input() function assumes the input is a valide Python
expression and returns evaluated result.
Example :
Str=input(Enter the input=)
print(received input=,str)
>>>
Enter the input:[x*3 for x in range(2,10,2)]