Lab 11
Python Files
1. Write a function in python to read the content from a text file "[Link]" line by line and
display the same on screen
2. Write a Python program to read first n lines of a file.
3. Write a Python program to count the number of lines in a text file which starts with an alphabet
“T”.
4. Write a Python program to append text to a file and display the text.
5. Write a Python program to read a file line by line and store it into a list.
6. Write a Python program to read a file line by line store it into a variable.
7. Write a Python program to read a file line by line store it into an array.
8. Write a Python program to count and display the total number of words in a file.
9. Write a function in Python to read lines from a text file "[Link]". Your function should find
and display the occurrence of the word "the".
10. Write a Python program to write a list to a file.
11. Write a Python program to copy the contents of a file to another file.
12. Write a Python program to read a random line from a file.
13. Write a Python program to remove newline characters from a file.
14. Write a Python program to extract characters from various text files and puts them into a list.
15. Ram has used a text editing software to type some text. After saving the article as
[Link], she realized that she has wrongly typed alphabet J in place of alphabet I
everywhere in the article. Write a function definition for JTOI() in Python that would display
the corrected version of entire content of the file [Link] with all the alphabets "J" to be
displayed as an alphabet "I" on screen.
Note: Assuming that [Link] does not contain any J alphabet otherwise.
16. Demonstrate Renaming, Moving, Copying, and Removing operations of Files in python with
or without shutil package.