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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is each collumn called in a file

A

field

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is each row called in a file

A

record

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how to close a file

A

myFile = open(“filename.txt”)
myFile.close()

  • .close method
  • has empty brackets after
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly