Basic Python Read File | Write File programs
Basic Python Read File | Write File programs
Basic programs of Data File Handling (python read file and write to file) in python
Q1. Write a program to read entire content of file “story.txt”
Q2. Write a program to read first line of file “data.txt”.
Q3. Write a program to count total number of lines in “sports.txt”.
Q4. Write a program to display first alphabet of all the lines in “library.txt”.
Q5. Write a program to read first 15 characters from the file “class.txt”.
Q6. Write a program to display only third line of file “test.txt”.
Q7. Write a program to display the length of file “len.txt”(Should not include EOL)
Q8. Write python code to write the following lines in a file “story.txt”
Python read File and write File.
Weightage of python read file and write file is 10 marks.
Practice one program daily of python read file
Q9. Write a program to accept five numbers from the user and write in a file “number.txt” in separate lines.
Q10. Write a program to read content from a file “number.txt” and display the sum of numbers present in file.
for example : if the file contains the following data Total marks in exam is 25 My roll number is 15 My Address is 207(FF) Output : 22
Q11. Write a program to create a list of 10 numbers and store it in a file “num.dat”
Q12. Write a program to write the following dictionary in a binary file named “detail.dat”.
D = {1 : ‘A’, 2 : ‘B’, 3 : ‘C’}
Q13. Write a program to store roll number and marks of five students in a dictionary and write the dictionary in a binary file “student.dat”
Q14. Write a program to add record of product (product number, product name) in a binary file “product.dat” (using list).
Q15. Write a program to read all the records of product from “product.dat” (created above).
Q16. Write a program to search the record from the file “product.dat” created above according to the product number entered by the user.
Q17. Write a program to read the entire content from “record.csv”.
Q18. Write a program to read the entire content from “data.csv” using “with open ( ) ” method.
Q19. Write a program to count the number of records in “record.csv”.
Q20. Write a program to read the following data from “product.csv” and display the sum of all the price.
p_name , p_price Keyborad , 200 Mouse , 150 Harddisk , 2500 RAM , 2000
Important Links
100 Practice Questions on Python Fundamentals
120+ MySQL Practice Questions
90+ Practice Questions on List
50+ Output based Practice Questions
100 Practice Questions on String
70 Practice Questions on Loops
120 Practice Questions of Computer Network in Python
70 Practice Questions on if-else
40 Practice Questions on Data Structure
Class 12 Computer Science Sample Paper 2020-2021.
Class 12 Computer Science Sample Paper Marking Scheme
Class 12 Computer Science Test Series
Disclaimer : I tried to give the correct code of all the above questions of Data File Handling. If you feel or find some error in any code of the above questions of Data File Handling, please share the correction at csiplearninghub@gmail.com. Also share your feedback. Your feedback will motivate me and help me to give you better content