File Handling in Python NCERT Solution || File Handling in Python Class 12 Solution || File Handling in Python Class 12 CS Solution || File Handling in Python Computer Science Solution || NCERT File Handling in Python Solution || File Handling in Python Class 12 CS || File Handling in Python Solution


Note:- Please Click on Question to get the Answer !!


1. Differentiate between:
a) text file and binary file
b) readline() and readlines()
c) write() and writelines()




2. Write the use and syntax for the following methods:
a) open()
b) read()
c) seek()
d) dump()




3. Write the file mode that will be used for opening the following files. Also, write the Python statements to open the following files:

a) a text file “example.txt” in both read and write mode
b) a binary file “bfile.dat” in write mode
c) a text file “try.txt” in append and read mode
d) a binary file “btry.dat” in read only mode.




4. Why 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 error message be flashed?



5. What is the difference between the following set of statements (a) and (b):

a) P = open("practice.txt","r")
P.read(10)
b) with open("practice.txt", "r") as P:
x = P.read()




6. Write a command(s) to write the following lines to the text file named hello.txt. Assume that the file is opened in append mode.
"Welcome my class"
"It is a fun place"
"You will learn and play"




7. Write a Python program to open the file hello.txt used in question no 6 in read mode to display its contents. What will be the difference if the file was opened in write mode instead of append mode?



8. Write a program to accept string/sentences from the user till the user enters "END" to. Save the data in a text file and then display only those sentences which begin with an uppercase alphabet.



9. Define pickling in Python. Explain serialization and deserialization of Python object.


10. Write a program to enter the following records in a binary file:

Item No        integer
Item_Name     string
Qty            integer
Price            float

Number of records to be entered should be accepted from the user. Read the file to display the records in the following format:

Item No:
Item Name :        
Quantity:
Price per item:
Amount:        ( to be calculated as Price * Qty)



2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Ques are also in my textbook, where are the answers ?

    ReplyDelete
    Replies
    1. Please click on question to get answer of that question.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post