8.3 - File Handling Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a file

A

a collection of data stored by a computer program to be used again

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

Why is data stored in a file

A

> stored permanently

> Data stored in a file can thus be accessed by the same program at a later date or accessed by another program

> Data stored in a file can also be sent to be used on other computer(s).

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

Pseudocode to write to a file

A

DECLARE TextLine : STRING
DECLARE MyFile : STRING
MyFile ← “MyText.txt”
OPEN MyFile FOR WRITE
OUTPUT “Please enter a line of text”
INPUT TextLine
WRITEFILE, TextLine
CLOSEFILE(MyFile)

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

Pseudocode to read from a file

A

OUTPUT “The file contains this line of text:”
OPEN MyFile FOR READ
READFILE, TextLine
OUTPUT TextLine
CLOSEFILE(MyFile)

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

Python write to a file

A

MyFile = open (“MyText.txt”,”w”)
TextLine = input(“Please enter a line of text “)
MyFile.write(TextLine)
Myfile.close()

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

Python read from a file

A

print(“The file contains this line of text”)
MyFile = open (“MyText.txt”,”r”)
TextLine = MyFile.read()
print(TextLine)
Myfile.close()

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