4.2.1.3 Fields, records and files Flashcards
What is a text file?
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.
What’s the difference between how data is stored in a text file and a binary file?
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 do you read a text file in python?
file = open(“filename.txt”, “r”)
for line in file:
array.append(line.strip())
file.close()
How do you write to a text file in python?
File = open(“filename.txt”, “w”)
File.write(“string”)
File.close()