Choose a topic to test your knowledge and improve your Python skills
Rohan opened the file “myfile.txt” by using the following syntax. His friend told him few advantages of the given syntax. Help him to identify the correct advantage. with open ("myfile.txt", "a") as file_object:
Mohan wants to open the file to add some more content in the already existing file. Suggest him the suitable mode to open the file.
Aman jotted down few features of the “write mode”. Help him to identify the valid features.
Ananya jotted down few features of the “append mode”. Help her to identify the valid features.
Which of the following methods can be used to write data in the file?
Write the output of the following: >>> f = open("test.txt","w") >>> f.write("File #Handling")
Which of the following error is returned by the given code: >>> f = open("test.txt","w") >>> f.write(345)
Which of the following method is used to clear the buffer?
Which of the following method does not return the number of characters written in the file.
Fill in the blank in the given code: >>> fo = open("myfile.txt",'w') >>> lines = ["Hello ", "Writing strings ", "third line"] >>> fo._____________(lines) >>>myobject.close()
In order to read the content from the file, we can open file in ___________
Which of the following method is used to read a specified number of bytes of data from a data file.
Write the output of the following: f=open("test.txt","w+") f.write("File-Handling") a=f.read(5) print(a)
Write the output of the following: f=open("test.txt","w+") f.write("FileHandling") f.seek(5) a=f.read(5) print(a)
Write the output of the following: f=open("test.txt","w+") f.write("FileHandling") f.seek(0) a=f.read() print(a)
Write the output of the following: f=open("test.txt","w+") f.write("FileHandling") f.seek(0) a=f.read(-1) print(a)
Which of the following method reads one complete line from a file?
Write the output of the following: f=open("test.txt","w+") f.write("File Handling") f.seek(0) a=f.readline(-1) print(a)
Write the output of the following: f=open("test.txt","w+") f.write("File Handling") f.seek(0) a=f.readline(2) print(a)
Select the correct statement about the code given below: >>> myobj=open("myfile.txt", 'r') >>> print(myobj.readlines())
Write the output of the following: f=open("test.txt","w+") L = ["My name ", "is ", "Amit"] f.writelines(L) f.seek(0) a=f.readlines() print(type(a))
Which of the following function return the data of the file in the form of list?
Sanjeev has written a program which is showing an error. As a friend of Sanjeev, help him to identify the wrong statement. f=open("test.txt","w") #Statement1 L = ["My name ", "is ", "Amit"] #Statement2 f.writeline(L) #Statement3 f.close() #Statement4
__________________ function returns an integer that specifies the current position of the file object in the file.
_____ method is used to position the file object at a particular position in a file.
In reference to the code given below, the file object will move _______ bytes. file_object.seek(10, 0)
Ravi wants to move the file object 5 bytes from the current position of the file object. As a friend of Ravi, help him to write the code.
Write the output of the following code: f=open("test.txt","w+") f.write("My name is Amit ") f.seek(5,0) a=f.read(5) print(a)
Write the output of the following: f=open("test.txt","r") print(f.tell())
Write the output of the following: f=open("test.txt","r") print(f.tell(),end="6") f.seek(5) print(f.tell())
How many functions are used in the given code? fileobject=open("practice.txt","r") str = fileobject.readline() while str: print(str) str=fileobject.readline() fileobject.close()
________ method is used to write the objects in a binary file.
______ method is used to read data from a binary file.
Which module is to be imported for working in binary file?
Which of the following statement open the file “marker.txt” so that we can read existing content from file?
Which of the following statement open the file “marker.txt” as a blank file?
Amit has written the following statement. He is working with ______ f = open("data", "rb")
Which of the following option is correct?
Correct syntax of tell( ) function is _________. #f is file object
The syntax of seek() is: file_object.seek(offset [, reference_point]). ___________________ value of reference_point indicate end of file
Which of the following statement is wrong in reference to Text file?
Identify the statement which can not be interpret from the given code:f = open("test.dat", "ab+")
Which module is to be imported for CSV file?
Write the output of the following code : import csv f = open(“data.csv”, ‘r’) row = csv.reader(f) print(row)
_______ function help us to read the csv file.
Write the output of the second print statement of the given code: f=open("test.txt","r") print(f.read()) f.seek(7) print(f.read()) Output of first print statement is : MynameisAmit
Which of the following method returns an integer value?
________ refers to the process of converting the structure to a byte stream before writing it to the file.
Fill in the blank in the given code : import pickle f = open("data.dat", "rb") l = pickle._______(f) print(l) f.close()
Write the output of the following code: f = open("data.txt","w") L=["My ","name ","is ","amit"] f.writelines(L) f.close() f = open("data.txt","r") print(len(f.read()))
Write the output of the following code: f = open("data.txt","w") L=["My ","name ","is ","amit"] f.writelines(L) f.close() f = open("data.txt","r") print(len(f.readlines()))
Write the output of the following code: f = open("data.txt","w") L=["My ","name ","is ","amit"] f.writelines(L) f.close() f = open("data.txt","r") print(len(f.readline()))
import pickle f = open("data.dat", "wb") L = [1, 2, 3] pickle._______ f.close()
Which of the following statement will return attribute error?
Ravi is writing a program for counting the number of words in a text file named “data.txt”. He has written the incomplete code. Help him to complete the code. f = open("_________","r") # Statement 1 d = f._________ # Statement 2 nw = d._________ # Statement 3 print("Number of words are", _________(nw)) # Statement 4 Identify the suitable code for blank space in the line marked as Statement 1
Ananya was writing a program of reading data from csv file named “data.csv”. She writes the incomplete code. As a friend of Ananya help her to complete the code. ________ csv #Statement1 f=open("data.csv", '_______') #Statement2 d=csv.___________(f) #Statement3 for __________ in d: #Statement4 print(row) Identify the suitable option for Statement 1
Chinki is writing a program to copy the data from “data.csv” to “temp.csv”. However she is getting some error in executing the following program due to some missing commands. Help her to execute it successfully. import csv f=open(“data.csv”,”r”) f1=open(“temp.csv”,’__________’) #Statement 1 d=csv._________(f) #Statement 2 d1=csv.writer(f1) for i in d: ___________.writerow(i) #Statement3 f.close( ) f1.close( )