KnowledgeBoat Logo

Computer Science

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.

Python File Handling

1 Like

Answer

1. File Mode: 'r+'

fh = open("example.txt", "r+")

2. File Mode: 'wb'

fh = open("bfile.dat", "wb")

3. File Mode: 'a+'

fh = open("try.txt", "a+")

4. File Mode: 'rb'

fh = open("btry.dat", "rb")

Answered By

1 Like


Related Questions