145 solutions available
Question 1Assertion. Python is said to have broadly two types of files - binary and text files, even when there are CSV and TSV files also.Reason....
Question 2Assertion. The file modes "r", "w", "a" work with text files, CSV files and TSV files alike.Reason. The CSV and TSV are types of delimited...
Question 3Assertion. The file modes "r", "w", "a" also reveal the type of file these are being used with.Reason. The binary file modes have 'b'...
Question 4Assertion. 'Pickling' is the process whereby a Python object hierarchy is converted into a byte-stream.Reason. A binary file works with...
Question 5Assertion. 'Pickling' is the process whereby a Python object hierarchy is converted into a byte-stream.Reason. Pickling process is used to...
Question 6Assertion. Every open file maintains a file-pointer and keeps track of its position after every operation.Reason. Every read and write...
Question 7Assertion. CSV (Comma Separated Values) is a file format for data storage which looks like a text file.Reason. The information is organized...
Question 1In which of the following file modes, the existing data of file will not be lost ?'rb'abww + b'a + b'wbwb+w+r+
Question 2What would be the data type of variable data in following statements ?data = f.read()data = f.read(10)data = f.readline()data =...
Question 3How are following statements different ?f.readline()f.readline().rstrip()f.readline().strip()f.readline.rstrip('\n')
Question 1What are text files ?
Question 2What are binary files ?
Question 3What are CSV files ?
Question 4Name the functions used to read and write in plain text files.
Question 5Name the functions used to read and write in binary files.
Question 6Name the functions used to read and write in CSV files.
Question 7What is the full form of :CSVTSV
Question 1The default file-open mode is read mode.
Question 2A file mode governs the type of operations (e.g., read/write/append) possible in the opened file.
Question 3The two types of data files can be text files and binary files.
Question 4The r+ file mode will open a file for read and write purpose.
Question 5The w+ or a+ file mode will open a file for write and read purpose.
Question 6To close an open file, close() method is used.
Question 7To read all the file contents in the form of a list, readlines() method is used.
Question 8To write a list in a file, writelines() method may be used.
Question 9To force Python to write the contents of file buffer on to storage file, flush() method may be used.
Question 10To read and write into binary files, pickle module of Python is used.
Question 11The dump() method of pickle module writes data into a binary file.
Question 12The load() method of pickle module reads data from a binary file.
Question 13The conversion of an object hierarchy in byte stream is called pickling or serialisation.
Question 14The character that separates the values in csv files is called the delimiter.
Question 15The default delimiter of csv files is comma.
Question 16The csv files are actually text files.
Question 17We can suppress EOL translation in text file by giving newline argument in open().
Question 18The file mode to open a binary file for reading as well writing is rb+.
Question 19The file mode to open a binary file for writing as well reading is wb+.
Question 20The file mode to open a csv file for reading as well writing is r+.
Question 21The file mode to open a csv file for appending as well reading is a+.
Question 22To specify a different delimiter while writing into a csv file, delimiter argument is used with csv.writer().
Question 1Information stored on a storage device with a specific name is called a ...............arraydictionaryfiletuple
Question 2Which of the following format of files can be created programmatically through Python to store some data ?Data filesText filesVideo...
Question 3To open a file c:\ss.txt for appending data, we usefile = open("c:\\ss.txt", "a")file = open("c:\\ss.txt", "rw")file = open(r"c:\ss.txt",...
Question 4To read the next line of the file from a file object infi, we useinfi.read(all)infi.read()infi.readline()infi.readlines()
Question 5To read the remaining lines of the file from a file object infi, we useinfi.read(all)infi.read()infi.readline()infi.readlines()
Question 6The readlines() method returnsstra list of linesa list of single charactersa list of integers
Question 7Which of the following mode will refer to binary data ?rw+b
Question 8Which of the following statement is not correct ?We can write content into a text file opened using 'w' mode.We can write content into a...
Question 9Which of the following option is the correct Python statement to read and display the first 10 characters of a text file "Notes.txt" ?F =...
Question 10Which of the following is not a correct Python statement to open a text file "Notes.txt" to write content into it ?F = open('Notes.txt',...
Question 11Which function is used to read all the characters ?read()readcharacters()readall()readchar()
Question 12Which function is used to read a single line from file ?readline()readlines()readstatement()readfullline()
Question 13Which function is used to write all the characters ?write()writecharacters()writeall()writechar()
Question 14Which function is used to write a list of strings in a file ?writeline()writelines()writestatement()writefullline()
Question 15Which of the following represents mode of both writing and reading in binary format in file. ?wb+wwbw+
Question 16Which of the following is not a valid mode to open a file ?abrwr+w+
Question 17Which of the following mode in file opening statement results or generates an error if the file does not exist ?a+r+w+None of these
Question 18Which of the following command is used to open a file "c:\pat.txt" in read-mode only ?fin = open("c:\pat.txt", "r")fin =...
Question 19Which of the following statements are true regarding the opening modes of a file ?When you open a file for reading, if the file does not...
Question 20Which of the following command is used to open a file "c:\pat.txt" for writing in binary format only ?fout = open("c:\pat.txt", "w")fout =...
Question 21Which of the following command is used to open a file "c:\pat.txt" for writing as well as reading in binary format only ?fout =...
Question 22Which of the following functions do you use to write data in the binary format ?write()output()dump()send()
Question 23Which of the following option is the correct usage for the tell() of a file object ?It places the file pointer at a desired offset in a...
Question 24Which of the following statement is incorrect in the context of pickled binary files ?The csv module is used for reading and writing...
Question 25What is the significance of the seek() method ?It seeks the absolute path of the file.It tells the current byte position of the file...
Question 26The correct syntax of seek() is :file_object.seek(offset[, reference_point])seek(offset[, reference_point])seek(offset,...
Question 1When you open a file for reading, if the file does not exist, an error occurs.
Question 2When you open a file for writing, if the file does not exist, an error occurs.
Question 3When you open a file for writing, if the file exists, the existing file is overwritten with the new file.
Question 4The absolute paths are from the topmost level of the directory structure.
Question 5The relative paths are relative to the current working directory.
Question 6The relative path for a file always remains the same even after changing the directory.
Question 7The types of operations that can be carried out on a file depend upon the file mode a file is opened in.
Question 8If no path is given with a file name in the file open(), then the file must exist in the current directory.
Question 9Functions readline() and readlines() are essentially the same.
Question 10Python automatically flushes the file buffers before closing a file with close() function.
Question 11When you open a file for writing, if the file does not exist, a new file is created.
Question 12When you open a file for appending, if the file exists, the existing file is overwritten with the new file.
Question 13Conversion of an object hierarchy in byte stream is called Serialisation.
Question 14Serialisation process is also called pickling.
Question 15The load() function of the pickle module performs pickling.
Question 16The dump() function of the pickle module performs unpickling.
Question 17The csv files can only take comma as delimiter.
Question 18The csv files are text files.
Question 1What is the difference between "w" and "a" modes ?
Question 2What is the significance of a file-object ?
Question 3How is file open() function different from close() function?
Question 4Write statements to open a binary file C:\Myfiles\Text1.txt in read and write mode by specifying file path in two different formats.
Question 5Which of the following Python modules is imported to store and retrieve objects using the process of serialization and deserialization...
Question 6Which of the following function is used with the csv module in Python to read the contents of a csv file into an object...
Question 7When a file is opened for output in write mode, what happens when(i) the mentioned file does not exist(ii) the mentioned file does exist ?
Question 8What role is played by file modes in file operations ? Describe the various file mode constants and their meanings.
Question 9What are the advantages of saving data in :(i) binary form(ii) text form(iii) csv files ?
Question 10When do you think text files should be preferred over binary files ?
Question 11Write a statement in Python to perform the following operations :(a) To open a text file "BOOK.TXT" in read mode(b) To open a text file...
Question 12When a file is opened for output in append mode, what happens when(i) the mentioned file does not exist(ii) the mentioned file does exist.
Question 13How many file objects would you need to create to manage the following situations ? Explain.(i) to process three files sequentially(ii) to...
Question 14Is csv file different from a text file ? Why/why not ?
Question 15Is csv file different from a binary file ? Why/why not ?
Question 16Why are csv files popular for data storage ?
Question 17How do you change the delimiter of a csv file while writing into it ?
Question 18When and why should you suppress the EOL translation in csv file handling ?
Question 19If you rename a text file's extension as .csv, will it become a csv file ? Why/why not ?
Question 20Differentiate between "w" and "r" file modes used in Python while opening a data file. Illustrate the difference using suitable examples.
Question 21Differentiate between the following :(i) f = open('diary.txt', 'r')(ii) f = open('diary.txt', 'w')
Question 1How are following codes different from one another ?(a)my_file = open('poem.txt', 'r') my_file.read()(b)my_file = open('poem.txt', 'r')...
Question 2If the file 'poemBTH.txt' contains the following poem (by Paramhans Yoganand) :God made the Earth; Man made confining countries And their...
Question 3Consider the file poemBTH.txt given above (in previous question). What output will be produced by following code fragment ?obj1 =...
Question 4Write code to open file contacts.txt with shown information and print it in following form :Name: <name> Phone: <phone...
Question 5Consider the file "poemBTH.txt" and predict the outputs of following code fragments if the file has been opened in filepointer file1 with...
Question 6What is the following code doing ?file = open("contacts.csv", "a") name = input("Please enter name.") phno = input("Please enter phone...
Question 7Consider the file "contacts.csv" created in above Q. and figure out what the following code is trying to do?name = input("Enter name :")...
Question 8Consider the file poemBTH.txt and predict the output of following code fragment. What exactly is the following code fragment doing ?f =...
Question 9Write a method in Python to read the content from a text file diary.txt line by line and display the same on screen.
Question 10Write a method in Python to write multiple line of text contents into a text file mylife.txt.line.
Question 11What will be the output of the following code ?import pickle ID = {1:"Ziva", 2:"53050", 3:"IT", 4:"38",...
Question 12What will be the output of the following code ?import pickle List1 = ['Roza', {'a': 23, 'b': True}, (1, 2, 3), [['dogs', 'cats'], None]]...
Question 13What is the output of the following considering the file data.csv given below. File data.csv contains: Identifier;First name;Last name...
Question 14(a)Identify the error in the following code.import csv f = open('attendees1.csv') csv_f = csv.writer(f)
Question 14(b)Identify the error in the following code.import csv f = open('attendees1.csv') csv_f = csv.reader() for row in csv_f: print(row)
Question 15Identify the error in the following code.import pickle data = ['one', 2, [3, 4, 5]] with open('data.dat', 'wb' : pickle.dump(data)
Question 1Write a program that reads a text file and creates another file that is identical except that every sequence of consecutive blank spaces is...
Question 2A file sports.dat contains information in following format:Event - ParticipantWrite a function that would read contents from file...
Question 3A file contains a list of telephone numbers in the following form:Arvind 7258031 Sachin 7259197 The names contain only one word, the names...
Question 4Write a program to count the words "to" and "the" present in a text file "Poem.txt".
Question 5Write a function AMCount() in Python, which should read each character of a text file STORY.TXT, should count and display the occurrence of...
Question 6Write a program to count the number of upper-case alphabets present in a text file "Article.txt".
Question 7Write a program that copies one file to another. Have the program read the file names from user ?
Question 8Write a program that appends the contents of one file to another. Have the program take the filenames from the user.
Question 9Write a method in python to read lines from a text file MYNOTES.TXT, and display those lines, which are starting with an alphabet 'K'.
Question 10Write a method/function DISPLAYWORDS() in python to read lines from a text file STORY.TXT, and display those words, which are less than 4...
Question 11Write a program that reads characters from the keyboard one by one. All lower case characters get stored inside the file LOWER, all upper...
Question 12Write a function in Python to count and display the number of lines starting with alphabet 'A' present in a text file "LINES.TXT". e.g.,...
Question 13Write a program that counts the number of characters up to the first $ in a text file.
Question 14Write a program that will create an object called filout for writing, associate it with the filename STRS.txt. The code should keep on...
Question 15Consider the following definition of a dictionary Member, write a method in Python to write the content in a pickled file...
Question 16Consider the following definition of dictionary Staff, write a method in python to search and display content in a pickled file staff.dat,...
Question 17Considering the following definition of dictionary COMPANY, write a method in Python to search and display the content in a pickled file...
Question 18Write a function to search and display details of all trains, whose destination is "Delhi" from a binary file "TRAIN.DAT". Assuming the...
Question 19A binary file "Book.dat" has structure [BookNo, Book_Name, Author, Price].(i) Write a user defined function CreateFile() to input data for...
Question 20Write a function Show_words() in python to read the content of a text file 'NOTES.TXT' and display only such lines of the file which have...
Question 21Write a Python program to read a given CSV file having tab delimiter.
Question 22Write a Python program to write a nested Python list to a csv file in one go. After writing the CSV file read the CSV file and display the...
Question 23Write a function that reads a csv file and creates another csv file with the same content, but with a different delimiter.
Question 24Write a function that reads a csv file and creates another csv file with the same content except the lines beginning with 'check'.
Question 25Give any one point of difference between a binary file and a CSV file.Write a Program in Python that defines and calls the following user...