51 solutions available
Question 6Assertion (A): The readline() method reads one complete line from a text file.Reasoning (R): The readline() function can also be used to...
Question 2To open a file c:\test.txt for writing, we should use the statement:fobj = open("c:\test.txt", "w")fobj = open("c:\\test.txt", "w")fobj =...
Question 4Which of the following statements is/are true?When we open a file for reading, if the file does not exist, an error occurs.When we open a...
Question 7What will be the output of the following snippet?f = None for i in range(5): with open("data.txt", "w") as f: if i > 2:...
Question 1What is the difference between "w" and "a" modes?
Question 3How are open() functions different from close() functions other than their functionality of opening and closing files?
Question 5In which of the following file modes will the existing data of the file not be lost?rbabww + ba + bwbwb+w+r+
Question 8What role is played by file modes in file operations? Describe the various file mode constants and their meanings.
Question 9Write a code snippet that will create an object called fileout for writing; associate it with the filename 'STRS'. The code should keep on...
Question 10Explain how many file objects would you need to create to manage the following situations:(a) To process three files sequentially.(b) To...
Question 11Write the advantages of saving data in:(a) Binary form(b) Text form
Question 12Why is it required to close a file after performing the reading and writing operations on a file?
Question 13When do you think text files should be preferred over binary files?
Question 14Write a program that reads a text file and creates another file that is identical except that every sequence of consecutive blank spaces...
Question 15A file 'sports.dat' contains information in the following format: EventName, ParticipantWrite a function that would read contents from...
Question 16Write a program to count the words "to" and "the" present in a text file "Poem.txt".
Question 17Write a program to count the number of uppercase alphabets present in a text file "Poem.txt".
Question 18Write a program that copies one file to another. Have the program read the file names from user.
Question 19Write a program that appends the contents of one file to another. Have the program take the file names from the user.
Question 20Write a program that reads characters from the keyboard one by one. All lower case characters get stored inside the file 'LOWER', all...
Question 21Write a program to search the names and addresses of persons having age more than 30 in the data list of persons stored in a text file.
Question 22Write 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 23Write the file mode that will be used for opening the following files. Also, write the Python statements to open the following files:a...
Question 24Why is it advised to close a file after we are done with the read and write operations? What will happen if we do not close it? Will some...
Question 25What is the difference between the following sets of statements (a) and (b):(a)P = open("practice.txt", "r") P.read(10)(b)with...
Question 26Write a program to accept string/sentences from the user till the user enters "END". Save the data in a text file and then display only...
Question 27Write a function to insert a sentence in a text file, assuming that text file is very big and can't fit in computer's memory.
Question 28Write a program to read a file 'Story.txt' and create another file, storing an index of 'Story.txt', telling which line of the file each...
Question 29Write a program to accept a filename from the user and display all the lines from the file which contain Python comment character '#'.
Question 30Reading a file line by line from the beginning is a common task. What if you want to read a file backward ? This happens when you need to...
Question 31Write a Python program to display the size of a file after removing EOL characters, leading and trailing white spaces and blank lines.
Question 32Write a function Remove_Lowercase() that accepts two file names, and copies all lines that do not start with lowercase letter from the...
Question 33Write a program to display all the records in a file along with line/record number.
Question 34Write a method in Python to write multiple line of text contents into a text file "mylife.txt".
Question 35Write a method in Python to read the content from a text file "DIARY.TXT" line by line and display the same on the screen.
Question 36Write appropriate statements to do the following:(a) To open a file named "RESULT.DAT" for output.(b) To go to the end of the file at any...
Question 37Write a program to add two more employees' details (empno, ename, salary, designation) to the file "emp.txt" already stored in disk.
Question 38How are the following codes different from one another?1.fp = open("file.txt", 'r') fp.read()2.fp = open("file.txt", 'r')
Question 39What is the output of the following code fragment? Explain.fout = open("output.txt", 'w') fout.write("Hello, world! \n") fout.write("How...
Question 40Write the output of the following code with justification if the contents of the file "ABC.txt" are:"Welcome to Python Programming!"f1 =...
Question 41Give the output of the following snippet:import pickle list1, list2 = [2, 3, 4, 5, 6, 7, 8, 9, 10], [] for i in list1: if (i % 2 == 0...
Question 42Anant has been asked to display all the students who have scored less than 40 for Remedial Classes. Write a user-defined function to...
Question 43Following is the structure of each record in a data file named "PRODUCT.DAT".{"prod_code": value, "prod_desc": value, "stock": value} The...
Question 44Given a binary file "STUDENT.DAT", containing records of the following type:[S_Admno, S_Name, Percentage]Where these three values...
Question 45Write a statement to open a binary file C:\Myfiles\Text1.dat in read and write mode by specifying for file path in two different formats.
Question 46Write a statement in Python to perform the following operations:(a) To open a text file "BOOK.TXT" in read and append mode(b) To open a...
Question 47What is the following code doing?import csv File = open("contacts.csv", "a") Name = input("Please enter name: ") Phno = input("Please...
Question 48Write code to open the file in the previous question and print it in the following form:Name : <name> Phone: <phone number>
Question 49Consider the file "contacts.csv" created in the question above and figure out what the following code is trying to do?name = input("Enter...
Question 50Write a program to enter the following records in a binary file:Item No — integerItem_Name — stringQty — integerPrice — floatNumber of...
Question 51Create a CSV file "Groceries" to store information of different items existing in a shop. The information is to be stored w.r.t. each item...