Computer Science
Which of the following command is used to open a file "c:\pat.txt" in read-mode only ?
- fin = open("c:\pat.txt", "r")
- fin = open("c:\\pat.txt", "r")
- fin = open(file = "c:\pat.txt", "r+")
- fin = open(file = "c:\\pat.txt", "r+")
Python File Handling
2 Likes
Answer
fin = open("c:\\pat.txt", "r")
Reason — The syntax to open a file in read-mode only is f = open("c:\\temp\\data.txt", "r")
. Hence according to this syntax fin = open("c:\\pat.txt", "r")
format is correct.
Answered By
1 Like
Related Questions
Which of the following is not a valid mode to open a file ?
- ab
- rw
- r+
- w+
Which of the following mode in file opening statement results or generates an error if the file does not exist ?
- a+
- r+
- w+
- None of these
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+")