CBSE Class 12 Computer Science Question 84 of 136

Data File Handling — Question 23

Back to all questions
23
Question

Question 23

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

  1. a text file "example.txt" in both read and write mode.
  2. a binary file "bfile.dat" in write mode
  3. a text file "try.txt" in append and read mode
  4. a binary file "btry.dat" in read only mode
Answer
  1. File Mode: 'r+'
fh = open("example.txt", "r+")
  1. File Mode: 'wb'
fh = open("bfile.dat", "wb")
  1. File Mode: 'a+'
fh = open("try.txt", "a+")
  1. File Mode: 'rb'
fh = open("btry.dat", "rb")