LO: To analyze the structure of text files.
To use text file from Python. SUCCESS
To implement various operations on text files using Python.
CRITERIA
A text file is structured as a sequence of lines. To create text
Each line of text is terminated by a special character known as End files.
Of Line character.
Text files are stored in human readable form and they can also be To apply suitable
created using any text editor. python functions
on text files.
Sample text file is as follows: To implement
read and write
operations.
To differentiate
the various
opening modes.
FILE OPENING MODES
r – to open the file in read only mode
w – to open the file in write mode
r+ - to open the file in read & write mode
w+ - to open the file in write & read mode
a - to open the file in append mode
a+ - to open the file in append & read mode
TEXT FILE READ OPERATION
1. read() method
TEXT FILE READ OPERATION
2. readline() method
TEXT FILE READ OPERATION
3. readlines() method
TEXT FILE WRITE OPERATION – write()
TEXT FILE WRITE OPERATION – writelines()