4.2.1.3 Fields, records and files Flashcards

1
Q

What is a text file?

A

A sequence of characters organised on a line by line basis. It can only contain characters, whereas a non-text file could store images, sounds etc.

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

What’s the difference between how data is stored in a text file and a binary file?

A

In text files all data is stored as characters, binary files store different data types. Text files store data so that they could be opened or created in a text editor, whereas it’s much more difficult to edit binary files.

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

How do you read a text file in python?

A

file = open(“filename.txt”, “r”)
for line in file:
array.append(line.strip())
file.close()

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

How do you write to a text file in python?

A

File = open(“filename.txt”, “w”)
File.write(“string”)
File.close()

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