Lesson 5 Python.pptx
Lesson 5 Python.pptx
LESSON 5
01 File handling
● Text files do not have any specific ● Web standards: html, XML, CSS, JSON etc.
encoding and it can be opened in ● Source code: c, app, js, py, java etc.
normal text editor itself. ● Documents: txt, tex, RTF etc.
● Tabular data: csv, tsv etc.
● Configuration: ini, cfg, reg etc.
FILE HANDLING OPERATIONS
DEFINITION # EXAMPLE CREATE & OPEN FILE
Most common
Mode
text_file.write(people)
● In the case of performing file
operations a context manager ---------------------------------------------------------------------------
would automatically open and
close the file for us. with open('people.txt', 'r') as text_file:
contents = text_file.read()
Write a Python program to count the 1. Take the file name and the word to be
occurrences of a word in a text file counted from the user.
● Your program will take a word from 2. Read each line from the file and split
the user and count the number of the line to form a list of words.
occurrences of that word in a file. 3. Check if the word provided by the user
and any of the words in the list are
equal and if they are, then increment
the word count.
4. Exit
THANK YOU!