Font size
WorksheetsReading & writing to a text file (Python)
Total questions: 14
Worksheet time: 7mins
This command will open file = open("mytext.txt", "r")
To read the file
To append to the file
To write to the file
This command will open file = open("mytext.txt", "w")
To read the file
To append to the file
To write to the file
If I want to add to the end of a text file, I should:
file = open("file.txt", "w")
file = open("file.txt", "a")
file = open("file.txt", "w+")
file = open("file.txt", "s")
Which of these will generate an error?
file.write("writing")
file..write(writing)
file.write("writing",writing)
file.writetofile()
How do you close the file?
file = close
file.close
close = file()
Why do we close txt files after we are done with them?
This frees up any memory used by having it open
It makes no difference if its closed or not
Once closed, the file cannot be read from or written to without opening it again
It's easier to write to once it's closed
What is the use of “a” in file handling?
Read
Write
Append
None of the mentioned
Choose the correct statement to close a file stream named myfile:
myfile.terminate()
myfile.end()
myfile.close()
myfile.remove()
A text file has the file extension of:
.txt
.doc
.text
