which of the following command is used to open a file "c:\temp.txt" in read-mode only?
a)infile=open("c:\\temp.txt","r")
b)infile=open(file = "c:\\temp.txt","r+")
c)infile=open(file ="c:\\temp.txt","r+")
Answers
Answered by
12
Answer:
infil =open("c:\\temp.txt,","r")
Answered by
1
option 1 is correct answer
Explanation:
open(file, mode=’r’, buffering=-1, encoding=None, errors=None, newline=None)
* file – The file parameter specifies the relative path to the current working directory or absolute
- path of the file that you want to open and perform some operation. If file cannot be opened, an error occurs (OSError).
* mode – This is where you will specify the purpose of opening a file. For example, ‘r’ (the default)
- value opens a file in reading mode for text files. If you require writing to a text file, then use ‘w’ mode.
- For opening a file in write mode for appending text, use the ‘a’ value.
- The detailed list of modes is given in the last section.
Hence, option 1 is correct to open a file only in read only.
Similar questions