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 ?
- fout = open("c:\pat.txt", "w")
- fout = open("c:\\pat.txt", "wb")
- fout = open("c:\pat.txt", "w+")
- fout = open("c:\\pat.txt", "wb+")
Python File Handling
3 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
Which of the following statements are true regarding the opening modes of a file ?
- When you open a file for reading, if the file does not exist, an error occurs.
- When you open a file for writing, if the file does not exist, an error occurs.
- When you open a file for reading, if the file does not exist, the program will open an empty file.
- When you open a file for writing, if the file does not exist, a new file is created.
- When you open a file for writing, if the file exists, the existing file is overwritten with the new file.
Which of the following command is used to open a file "c:\pat.txt" for writing in binary format only ?
- fout = open("c:\pat.txt", "w")
- fout = open("c:\\pat.txt", "wb")
- fout = open("c:\pat.txt", "w+")
- fout = open("c:\\pat.txt", "wb+")
Which of the following functions do you use to write data in the binary format ?
- write()
- output()
- dump()
- send()
Which of the following option is the correct usage for the tell() of a file object ?
- It places the file pointer at a desired offset in a file.
- It returns the entire content of a file.
- It returns the byte position of the file pointer as an integer.
- It tells the details about the file.