Chapter 6 Flashcards
What is meant by “writing data to”?
Saving data on a file.
Output file
A file that data is written to.
What is meant by “reading data from?”
Process of retrieving data from a file.
Input file
A file from which data is read.
What are the 3 steps a program goes through when using a file?
- Open file.
- Process file.
- Close file.
Text file
Contains data that has been encoded as text.
Binary file
Contains data that has not been converted to text.
Name the two ways used to access data stored in a file.
Sequential access and direct access.
Sequential access
File read sequentially from beginning to end, can’t skip ahead.
Direct access
Can jump directly to any piece of data in the file.
Filename extensions
Short sequences of characters that appear at the end of a filename preceded by a period. The extension indicates the type of data stored in the file.
File object
Object associated with a specific file. Provides a way for the program to work with the file: file object referenced by a variable.
open function
Used to open a file. Creates a file object and associates it with a file on the disk. General format:
file_object = open(filename, mode)
Mode
String specifying how the file will be opened. Example: reading only (‘r’), writing (‘w’) and appending (‘a’)
Method
A function that belongs to an object. Performs operations using that object.
File object’s write method is used to write data to the file.
file_variable.write(string)
File should be closed using the file object close method.
file_variable.close()