Chapter Six: Files and Exceptions

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/30

flashcard set

Earn XP

Description and Tags

Vocabulary and concepts relating to file input/output operations, data processing, and exception handling in Python, based on Chapter Six and Tony Gaddis's 'Starting Out with Python'.

Last updated 10:44 PM on 5/6/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

31 Terms

1
New cards

Writing to a file

The process of saving data in a file by copying a piece of data from RAM to the file.

2
New cards

Output file

The term used for a file that is being written to.

3
New cards

Reading data from a file

The process of retrieving data from a file by copying it to RAM and referencing it with a variable.

4
New cards

Input file

The term used for a file from which data is being read.

5
New cards

Opening a file

The first step in dealing with files that creates a connection between the file and the program.

6
New cards

Closing a file

The final step in dealing with files that disconnects the file from the program and clears the memory buffer area.

7
New cards

Text files

Files containing data encoded using schemes like ASCII or Unicode, where even numbers are stored in character format.

8
New cards

Binary files

Files containing data that has not been converted to text and is intended only for a program to read.

9
New cards

Sequential access

A file access method where data is read from beginning to end; you must read all preceding data to reach a middle piece.

10
New cards

Direct access (random access)

A file access method that allows jumping directly to any piece of data in the file.

11
New cards

Filename Extensions

The three characters following a filename that usually indicate the type of file, such as .jpg.jpg, .txt.txt, or .doc.doc.

12
New cards

File object

An object created in memory associated with a specific file that provides a link for the program to the file through a variable.

13
New cards

open function

A function in Python used to create a file object; follows the general format file_variable = open (filename, mode)\text{file\_variable = open (filename, mode)}.

14
New cards

Mode 'r'

A Python file mode used to open a file for reading only; the file cannot be changed or written to.

15
New cards

Mode 'w'

A Python file mode used to open a file for writing; it erases content if the file exists or creates a new one if it does not.

16
New cards

Mode 'a'

A Python file mode used to open a file for appending data to its end; it creates the file if it does not exist.

17
New cards

Raw string (r'')

A string prefix used when specifying file paths to tell the interpreter to read backslashes literally as backslashes.

18
New cards

Method

A function that belongs to an object and performs some operation using that object.

19
New cards

write method

A file object method used to write a string of data to a file.

20
New cards

read method

A file object method that reads the entire contents of a file into memory as a string.

21
New cards

readline method

A file object method that reads an individual line, including the \n\backslash n character, from a file.

22
New cards

Read position

An internal value maintained by Python that marks the location of the next item to be read from a file.

23
New cards

rstrip method

A string method used to remove characters from the right side of a string, often used to remove the \n\backslash n newline character.

24
New cards

str function

A Python function used to convert a number to a string, which is necessary before writing numeric data to a text file.

25
New cards

Record

A complete set of data in a file consisting of one or more fields.

26
New cards

Field

A single piece of data within a record.

27
New cards

Exception

An error that occurs while a program is running, causing the program to abruptly halt.

28
New cards

Exception handler

Code written with a try/except\text{try/except} statement that responds to exceptions and prevents a program from crashing.

29
New cards

IOError

A specific type of exception that can occur if, for example, a file being opened for reading does not exist.

30
New cards

ValueError

An exception raised when an attempt to convert a string to a numeric type (like int\text{int} or float\text{float}) fails.

31
New cards

finally clause

An optional clause in a try/except\text{try/except} suite that executes regardless of whether an exception was thrown, used for post-exception cleanup.