Starting Out with Python - Chapter 6: Files and Exceptions

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

1/32

flashcard set

Earn XP

Description and Tags

Vocabulary terms covering file I/O operations, file modes, loops for file processing, the with statement, record processing, and exception handling in Python.

33 Terms

1
New cards

Output file

A file that data is written to.

2
New cards

Input file

A file from which data is read.

3
New cards

Three steps when a program uses a file

  1. Open the file; 2. Process the file; 3. Close the file.
4
New cards

Text file

A file containing data that has been encoded as text.

5
New cards

Binary file

A file containing data that has not been converted to text.

6
New cards

Sequential access

A file access method where a file is read sequentially from beginning to end and cannot skip ahead.

7
New cards

Direct access

A file access method that allows a program to jump directly to any piece of data in the file.

8
New cards

Filename extension

A short sequence of characters that appears at the end of a filename preceded by a period, indicating the type of data stored in the file.

9
New cards

File object

An object associated with a specific file that provides a way for a program to work with the file and is referenced by a variable.

10
New cards

open function

A function used to open a file by creating a file object and associating it with a file on the disk using the general format file_object = open(filename, mode).

11
New cards

File mode

A string argument passed to the open function that specifies how the file will be opened, such as reading only ('r'), writing ('w'), and appending ('a').

12
New cards

Raw string literal (r prefix)

A string literal prefixed with the letter r, used when specifying an alternative path and file name argument in the open function.

13
New cards

Method

A function that belongs to an object and performs operations using that object.

14
New cards

write method

A file object method used to write data to a file in the format file_variable.write(string).

15
New cards

close method

A file object method used to close an open file in the format file_variable.close().

16
New cards

read method

A file object method that reads the entire file contents into memory as a string, working only when the file is opened for reading.

17
New cards

readline method

A file object method that reads a line from the file and returns it as a string, including the newline character ('\n').

18
New cards

Read position

A marker that marks the location of the next item to be read from a file.

19
New cards

rstrip method

A string method that strips specific characters from the end of a string, commonly used to remove '\n' from a string after reading it from a file.

20
New cards

Append mode ('a')

A file opening mode where if the file exists it is not erased, if it does not exist it is created, and data is written to the end of the current contents.

21
New cards

Empty string ('')

A sentinel value returned by the readline method when the end of a file has been reached.

22
New cards

with statement

A statement used to open a file and automatically close it once the enclosed suite finishes executing.

23
New cards

with suite

The indented block of statements following a with statement.

24
New cards

Record

A complete set of data that describes one item.

25
New cards

Field

A single piece of data within a record.

26
New cards

Exception

An error that occurs while a program is running, which usually causes the program to abruptly halt.

27
New cards

Traceback

An error message that gives information regarding the line numbers that caused an exception, the exception type, and a brief description of the error.

28
New cards

Exception handler

Code written as a try/except statement that responds when exceptions are raised and prevents the program from crashing.

29
New cards

Try suite

The block of statements contained in a try block that can potentially raise an exception.

30
New cards

Handler

The statements contained inside an except block that execute if an exception is raised in the try suite.

31
New cards

Exception object

An object created in memory when an exception is thrown, usually containing the default error message pertaining to that exception.

32
New cards

else clause (in try/except)

An optional clause aligned with try and except that executes its block of statements only if no exceptions were raised in the try suite.

33
New cards

finally clause

An optional clause in a try/except statement whose suite executes whether an exception occurs or not, primarily to perform cleanup before exiting.