Chapter 14: Files Flashcards
Define a Transient progam.
A program that runs for a set period and when it stops, the data disappears.
Running the program again, starts with a clean slate.
Define a Persistent program.
A program that runs for a long time (or all the time); keep at least some of their data in permanent storage; if they shut down and restart, they pick up where they left off.
Example of persistent program: Windows 10
” “ returns a file object that provides methods for working with the file.
open
The “” method puts data into the file.
write
You’ve used “open” to read the file, what do you need to do when you are done with the file?
close it. variable.close()
Note: If you don’t close the file, it gets closed for you when the program ends.
The argument of write has to be a?
string
variable.write(str(53))
What does ‘%d’ do?
Formats an integer to a string.
What does ‘%g’ do?
Formats to a floating point
What does ‘%s’ do?
Formats a string
Files are organized into?
directories
The “” module provides functions for working with files and directories.
os (stands for operating system)
A string like ‘/home/dinsdale’ that identifies a file or directory is called a “”
path
A simple filename, like memo.txt is also considered a path, but it is a “” path because it relates to the current directory.
relative
A path that begins with / does not depend on the current directory; it is called an “” path.
absolute
»> os.path.abspath(‘memo.txt’)
‘/home/dinsdale/memo.txt’
os.path.”” checks whether an item is a file.
isfile
os.path.isfile