Computer Science
To open a file c:\ss.txt for appending data, we use
- file = open("c:\\ss.txt", "a")
- file = open("c:\\ss.txt", "rw")
- file = open(r"c:\ss.txt", "a")
- file = open(file = "c:\ss.txt", "w")
- file = open(file = "c:\ss.txt", "w")
- file = open("c:\res.txt")
Answer
file = open("c:\\ss.txt", "a")
file = open(r"c:\ss.txt", "a")
Reason —
file = open("c:\\ss.txt", "a")— The syntax to open a filec:\ss.txtisf = open("c:\\temp\\data.txt", "a"). Hence according to this syntaxfile = open("c:\\ss.txt", "a")is correct format.file = open(r"c:\ss.txt", "a")— The syntax to open a filec:\ss.txtwith single slash isf = open(r"c:\temp\data.txt","a").The prefix r in front of a string makes it raw string that means there is no special meaning attached to any character. Hence according to this syntaxfile = open(r"c:\ss.txt", "a")is correct format.
Related Questions
Information stored on a storage device with a specific name is called a ……………
- array
- dictionary
- file
- tuple
Which of the following format of files can be created programmatically through Python to store some data ?
- Data files
- Text files
- Video files
- Binary files
To read the next line of the file from a file object infi, we use
- infi.read(all)
- infi.read()
- infi.readline()
- infi.readlines()
To read the remaining lines of the file from a file object infi, we use
- infi.read(all)
- infi.read()
- infi.readline()
- infi.readlines()