1)Show the single Python statement to create a file object (myFObj) for a text f
ID: 3812448 • Letter: 1
Question
1)Show the single Python statement to create a file object (myFObj) for a text file called “myData.txt” that is available for retrieving information from the file.
2)Suppose the user has been asked to enter the name of their text file, and it is stored in fName.
Suppose that the file has been opened and an object of type file has been created called myFObj. Which of the following correctly retrieves information from the text file into a list called tmpList:
a. tmpList = fName.readline( ) b. tmpList = myFObj.readline( )
c. tmpList = myFObj.read( ) d. tmpList = fName.readlines( ) e. None of these
Explanation / Answer
1) myFObj = open("myData.txt")
open method used in python to return the file object which is used for file operations
.2) e. correct answer is myFObj.readlines( )
the (fileobject).readlines() method will return the list of each line.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.