File Ijokk (Questions)
File Ijokk (Questions)
File
Handling
Important Questions
Important Question of text file
file
Type of modes
Write a function Show_words( ) in python to read the content of a text file 3
‘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
Write a function countmy( ) in python to read the text file “DATA.TXT” and
count the number of times “my” occurs in the file.
For example if the file “DATA.TXT” contains:
The countmy( ) function should display the output as : “my occurs 2 times”
Write a function in Python that counts the number of “Me” or “My”
words present in a text file “STORY.TXT”. If the “STORY.TXT”
contents are as follows:
a. no difference
b. in r+ the pointer is initially placed at the beginning of the file and the pointer is at
the end for w+
c. in w+ the pointer is initially placed at the beginning of the file and the pointer is
at the end for r+
b. Indicate that the next read or write occurs from that position in a file.
The future belongs to those who believe in beauty of their dreams. The
COUNTLINEVOWEL() function should display the output as: The number of lines starting
“This is my website.
I have displayed my preferences in the CHOICE section. You will get an idea of my
preferences from that section”
The countmy( ) function should return the count of ‘my’ from the file and program should
display the output as:
“my occurs 3 times in the file”.
If the following statement is used to read the contents of a text file object F:
x=F.readlines( )
(a) String
(b) list
(c) tuple
(d) dictionary
Write a function/method DISPLAYWORDS( ) in python to read lines from a text file
STORY.TXT and display those words, which are less than 4 characters.
(OR)
b. with open(“content.txt”,”r”)
data=file1.____________(4)
if data[0]==‘w’
print(data)
• Write one difference between tell() and seek() functions with syntax.
• Differentiate between the following:
(i) f=open(‘data.txt’,’)
• A binary file “STUDENT.DAT” has the structure [admission_number, Name ,
Percentage ]. Write a function countrec() in python that would read contents of
the file “STUDENT.DAT” and display the details of those students whose
percentage is above 75. Also display number of students satisfying the same
condition.
• Find out the errors in the code below. Underline and rewrite corrected code
after removing syntax errors.
Import pickle
Data=[“One”,2,[3,4,6]]
with open (‘data2.dat’,’r’) as fill1:
pickle.dump(fill1,Data)