KnowledgeBoat Logo

Computer Science

Which of the following command is used to open a file "c:\pat.txt" for writing as well as reading in binary format only ?

  1. fout = open("c:\pat.txt", "w")
  2. fout = open("c:\\pat.txt", "wb")
  3. fout = open("c:\pat.txt", "w+")
  4. fout = open("c:\\pat.txt", "wb+")

Python File Handling

2 Likes

Answer

fout = open("c:\\pat.txt", "wb+")

Reason — The syntax to open a file for writing as well as reading in binary format is f = open("c:\\temp\\data.txt", "wb+"). Hence according to this syntax fout = open("c:\\pat.txt", "wb+") format is correct.

Answered By

3 Likes


Related Questions