file handling Flashcards
1
Q
how to open a file
A
myFile = open(“filename.txt”)
- txt means text file
- function open
- have to set it to a variable
2
Q
how to read a file
A
myFile = open(“filename.txt”)
print(myFile.read())
-.read is the method
- has to have empty brackets after the method
3
Q
how to read only certain amount of file
A
myFile = open(“filename.txt”)
print(myFile.read(5))
- prints our 5 characters from the file
4
Q
what is each collumn called in a file
A
field
5
Q
what is each row called in a file
A
record
6
Q
how to close a file
A
myFile = open(“filename.txt”)
myFile.close()
- .close method
- has empty brackets after
7
Q
how to write on a file
A
myFile = open(“filename”, “a”)
myFile.write(“whatever you want to add”)
- need to state “a” when opening it
- method .write followed with brackets containing what to write