Chapter 7: Files Flashcards
To prevent an exception from terminating a program using the try and except statements.
catch
A special character used in files and strings to indicate the end of a line.
newline
\n
A technique that works elegantly in Python. “Using try and except is the _____ way to recover from missing files”.
pythonic
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.
Quality Assurance
A sequence of characters stored in permanent storage (like a hard drive).
text file
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
file handle
FileHandle = open(file.txt)
function that returns a file handle.
doesn’t read entire file
open()
eg. open(‘file_name.txt)
separates characters in a file into lines
creates double spacing with print function
newline
\n
method that reads whole file as one long string into assigned variable
.read()
eg. variable = filehandle.read()
function called to terminate the program and not return
exit()
sys.exit(0)
file handle mode notation to read a file
‘r’
read
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
‘w’
write
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
.close()
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
repr()