Chapter 7: Files Flashcards

1
Q

To prevent an exception from terminating a program using the try and except statements.

A

catch

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

A special character used in files and strings to indicate the end of a line.

A

newline
\n

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

A technique that works elegantly in Python. “Using try and except is the _____ way to recover from missing files”.

A

pythonic

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

A person or team focused on insuring the overall quality of a software product. Often involved in testing a product and identifying problems before the product is released.

A

Quality Assurance

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

A sequence of characters stored in permanent storage (like a hard drive).

A

text file

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

Not the actual data contained in the file, but can be used to read the data. Given if the requested file exists and you have the proper permissions to read the file.
Can be used as the sequence in a for loop

A

file handle

FileHandle = open(file.txt)

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

function that returns a file handle.
doesn’t read entire file

A

open()
eg. open(‘file_name.txt)

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

separates characters in a file into lines
creates double spacing with print function

A

newline
\n

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

method that reads whole file as one long string into assigned variable

A

.read()
eg. variable = filehandle.read()

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

function called to terminate the program and not return

A

exit()
sys.exit(0)

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

file handle mode notation to read a file

A

‘r’
read

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

file handle method to add characters to a file
if existing file, erases old data
if new file, creates new file
doesn’t automatically add newline
returns number of characters added

A

‘w’
write

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

file handle method to make sure that the last bit of data is physically written to the disk so it will not be lost if the power goes off

A

.close()

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

function that takes any object as an argument and returns a string representation of the object. For strings, it represents whitespace characters with backslash sequences

A

repr()

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