Ananya jotted down few features of the “append modeâ€. Help her to identify the valid features.
1. If we open an existing file in append mode, the previous data will remain there.
2. In append mode the file object will be positioned at the end of the file.
3.In append mode, if the file does not exist then the new file will be created.
4.All the above
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
1.import
2.create
3.data
4.Import
Correct syntax of tell( ) function is _________. #f is file object
1. f.tell( )
2.tell(f)
3. f_tell( )
4.None of the above
Fill in the blank in the given code: >>> fo = open("myfile.txt",'w') >>> lines = ["Hello ", "Writing strings ", "third line"] >>> fo._____________(lines) >>>myobject.close()
1.write( )
2. writelines( )
3.. writeline( )
4.None of the above
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()
1.3
2.4
3.5
4.6
Identify the statement which can not be interpret from the given code:f = open("test.dat", "ab+")
1.test.dat is a binary file
2.reading operation can be done on test.dat
3.appending operation can be done on test.dat
4.test.dat contains records about books
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()))
1.2
2.3
3.4
4.5
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()))
1.4
2.5
3.6
4.7
Write the output of the following: f=open("test.txt","w+") f.write("FileHandling") f.seek(5) a=f.read(5) print(a)
1.andli
2.Handl
3.eHand
4.No Output
Aman jotted down few features of the “write modeâ€. Help him to identify the valid features.
1. If we open an already existing file in write mode, the previous data will be erased
2.In write mode, the file object will be positioned at the beginning of the file.
3.In write mode, if the file does not exist then the new file will be created.
4.All the above
Amit has written the following statement. He is working with ______ f = open("data", "rb")
1.Text File
2.CSV File
3.Binary File
4.None of the above
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( )
1.r
2.rb+
3.wa
4.w
Fill in the blank in the given code : import pickle f = open("data.dat", "rb") l = pickle._______(f) print(l) f.close()
1.dump
2.load
3.write
4.list
import pickle f = open("data.dat", "wb") L = [1, 2, 3] pickle._______ f.close()
1.dump(f, L)
2.load(f, L)
3.dump(L, f)
4.load(L, f)
In order to read the content from the file, we can open file in ___________
1.“r†mode
2.“r+†mode
3.“w+†mode
4.All the above
In reference to the code given below, the file object will move _______ bytes. file_object.seek(10, 0)
1.0
2.10
3.5
4.4
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.
1. read mode
2.append mode
3. write mode
4.All the above
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
1.“data.txtâ€
2. data.txt
3.“dataâ€
4.data
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.
1.file_object.seek(5, 1)
2.file_object.seek(1, 5)
3. file_object.seek(5, 0)
4.file_object.seek(5, 2)
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:
1.In case the user forgets to close the file explicitly the file will closed automatically.
2. file handle will always be present in the beginning of the file even in append mode.
3. File will be processed faster
4.None of the above
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
1.. Statement1
2.. Statement2
3.. Statemen3
4.. Statement4
Select the correct statement about the code given below: >>> myobj=open("myfile.txt", 'r') >>> print(myobj.readlines())
1.This code will read one line from the file.
2. This code will read all the lines from the file.
3.This code will read only last line from the file.
4.None of the above
The syntax of seek() is: file_object.seek(offset [, reference_point]). ___________________ value of reference_point indicate end of file
1.0
2.1
3.2
4.3
Which module is to be imported for CSV file?
1. pickle
2.unpickle
3.csv
4.pandas
Which module is to be imported for working in binary file?
1.unpickle
2.pickle
3.pickling
4.unpickling
Which of the following error is returned by the given code: >>> f = open("test.txt","w") >>> f.write(345)
1. Syntax Error
2.TypeError
3. StringError
4.Run Time Error
Which of the following function return the data of the file in the form of list?
1.read( )
2. read(n)
3.readline( )
4.readlines( )
Which of the following method does not return the number of characters written in the file.
1.write( )
2.writelines( )
3.Both of the above
4.None of the above
Which of the following method is used to clear the buffer?
1. clear( )
2.buffer( )
3. flush( )
4.clean( )
Which of the following method is used to read a specified number of bytes of data from a data file.
1.read( )
2.read(n)
3.readlines( )
4. reading(n)
Which of the following method reads one complete line from a file?
1.read( )
2.read(n)
3. readline( )
4.readlines( )
Which of the following method returns an integer value?
1. seek( )
2. read( )
3. tell( )
4.readline( )
Which of the following methods can be used to write data in the file?
1.write( )
2.writelines( )
3.Both of the above
4.None of the above
Which of the following option is correct?
1.if we try to write in a text file that does not exist, an error occurs
2.if we try to read a text file that does not exist, the file gets created.
3.if we try to write on a text file that does not exist, the file gets Created.
4.None of the above
Which of the following statement is wrong in reference to Text file?
1.A text file is usually considered as a sequence of characters consisting of alphabets, numbers and other special symbols.
2. Each line of a text file is terminated by a special character.
3. Text files are not in Human readable form.
4. Text files can be opened in Text editor.
Which of the following statement open the file “marker.txt†as a blank file?
1.f = open(“marker.txtâ€, “râ€)
2. f = open(“marker.txtâ€, “rbâ€)
3.f = open(“marker.txtâ€, “wâ€)
4.None of the above
Which of the following statement open the file “marker.txt†so that we can read existing content from file?
1. f = open(“marker.txtâ€, “râ€)
2. f = Open(“marker.txtâ€, “râ€)
3. f = open(“marker.txtâ€, “wâ€)
4.None of the above
Which of the following statement will return attribute error?
1.print(len(f.readlines( ).split( ))) #f is file handle
2.print(len(f.readline( ).split( ))) #f is file handle
3.print(len(f.read( ).split( ))) #f is file handle
4.None of the above
Write the output of the following code : import csv f = open(“data.csvâ€, ‘r’) row = csv.reader(f) print(row)
1.It prints the memory address where csv.reader object is stored
2. It prints the first record of data.csv
3. It prints all the records of data.csv
4.None of the above
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()))
1.13
2.14
3.15
4.16
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)
1.me i
2.. ame is
3.me is
4.Error
Write the output of the following: >>> f = open("test.txt","w") >>> f.write("File #Handling")
1.17
2.16
3.14
4.15
Write the output of the following: f=open("test.txt","r") print(f.tell())
1.1
2.2
3.-1
4.0
Write the output of the following: f=open("test.txt","r") print(f.tell(),end="6") f.seek(5) print(f.tell())
1.165
2.650
3.065
4.506
Write the output of the following: f=open("test.txt","w+") f.write("File Handling") f.seek(0) a=f.readline(-1) print(a)
1. File Handling
2. FileHandling
3.File
4.No Output
Write the output of the following: f=open("test.txt","w+") f.write("File Handling") f.seek(0) a=f.readline(2) print(a)
1.File Handling
2. FileHandling
3.Fi
4.No Output
Write the output of the following: f=open("test.txt","w+") f.write("File-Handling") a=f.read(5) print(a)
1.File-
2.File
3.File-H
4. No Output
Write the output of the following: f=open("test.txt","w+") f.write("FileHandling") f.seek(0) a=f.read() print(a)
1.File
2.Handling
3.FileHandling
4.No Output
Write the output of the following: f=open("test.txt","w+") f.write("FileHandling") f.seek(0) a=f.read(-1) print(a)
1.File
2.Handling
3. FileHandling
4.No Output
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))
1.<class ‘tuple’>
2.<class ‘list’>
3.<class ‘string’>
4.None of the above
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
1. isAmit
2.sAmit
3.Amit
4. eisAmit
_____ method is used to position the file object at a particular position in a file.
1.tell( )
2.seek( )
3.put( )
4.None of the above
______ method is used to read data from a binary file.
1.a. write( )
2.dump( )
3.load( )
4. writer( )
_______ function help us to read the csv file.
1.reader( )
2.read( )
3.read(n)
4.readline( )
________ method is used to write the objects in a binary file.
1. write( )
2.dump( )
3. load( )
4.writer( )
________ refers to the process of converting the structure to a byte stream before writing it to the file.
1. pickling
2.unpickling
3.reading
4.writing
__________________ function returns an integer that specifies the current position of the file object in the file.
1.seek( )
2.tell( )
3.disp( )
4.None of the above