File Handling Program List
File Handling Program List
File
1. Write a Python Program to read a text file and count the number of lines ending with vowels.
2. Write a Python Program that reads a text file and create a new file after adding “ing” to all
words ending with ‘t’ , ‘p’ and ‘d’.
3. Write a function RevString() to read a textfile “Input.txt” and prints the words starting with
‘O’ in reverse order.The rest of the content is displayed normally. Example :
If content in the text file is :
UBUNTU IS AN OPEN SOURCE OPERATING SYSTEM
Output will be :
UBUNTU IS AN NEPO SOURCE GNITAREPO SYSTEM
(words ‘OPEN’ and ‘OPERATING’ are displayed in reverse order)
4. Write the definition of a function ChangeGender() in Python , which reads the contents of a
text file “BIOPIC.TXT” and displays the content of the file with every occurrence of the word ‘he’
replaced by ‘she’.
For example, if the content of the file “BIOPIC.TXT” is as follows:
Last time he went to Agra, there was too much crowd, which he
did not like.
So this time he decided to visit some hill station.
The function should read the file content and display the output as follows:
Last time she went to Agra, there was too much crowd, which she did not
like. So this time she decided to visit some hill station.
5. Write a function Show_words() in python to read the content of a text file 'NOTES.TXT' and
display the entire content in capital letters.
Example, if the file contains:
"This is a test file"
Then the function should display the output as: THIS IS A TEST FILE
6. Write a function Show_words() in python to read the content of a text file 'NOTES.TXT' and
display only such lines of the file which have exactly 5 words in them.
Example, if the file contains:
"This is a sample file.
The file contains many sentences.
But need only sentences which have only 5 words." Then the function should display the
output as: This is a sample file. The file contains many sentences.
CSV File
7. Write a Python program to write data in a csv file “Department.csv” , consisting of :
Depid ,Dept Name ,DeptLocation.
Print only the Deptname and DeptLocation.
Binary File
44. Given a binary file employee.dat, created using dictionary object having keys: (empcode,
name, and salary)
Write a python function that add one more record at the end of file.
Write a python function that display all employee records whose salary is more that 30000
45. Write a Python script to create a binary file “Flight.dat” containing information : FlightNum ,
NoOfSeats, StartingPoint and Destination.
• Display all flights with Destination =”Delhi” Count all flights
with NoOfSeats more than 150. Display the details of flight
with given FlightNo.
• Change the Destination to “Mumbai” for flightNum= “A102”
46. Consider a file, SPORT.DAT, containing records of the following structure: [SportName,
TeamName, No_Players]
Write a function, copyData(), that reads contents from the file SPORT.DAT
and copies the records with Sport name as “Basket Ball” to the file named BASKET.DAT. The
function should return the total number of records copied to the file BASKET.DAT