Shared Flashcard Set

Details

Chapter 9 Files
Preparing for EXAM II
11
Computer Science
Undergraduate 2
11/06/2017

Additional Computer Science Flashcards

 


 

Cards

Term
open(file) Function
Definition
gets input from a file rather than from a user typing on a keyboard.
Term
file.close() Function
Definition
closes the file, after which no more reads or writes to the file are allowed.
Term
file.read() Function
Definition
returns the file contents as a string.
Term
readlines()
Definition
returns a list of strings, where the first element is the contents of the first line, the second element is the contents of the second line, and so on.
Term
file.write()
Definition
writes a string argument to a file.
Term
mode
Definition
indicates how a file is opened. open('myfile.txt', 'w') opens myfile.txt for writing. If mode is not specified the default is 'r'. types are 'r', 'w', 'a', and 'mode+'.
Term
buffering
Definition
data is written to disk only when a newline character is output. f = open('myfile.txt', 'w', buffering=100) will write the output buffer to disk every 100 bytes.
Term
flush()
Definition
can be called to force the interpreter to flush the output buffer to disk.
Term
portability
Definition
considered when reading and writing files outside the executing program's directory, since file path representations often differ between operating systems.
Term
os.path module
Definition
contains many portable functions for handling file paths.
Term
path separator
Definition
The character between directories, e.g. "\\"or "/"
Supporting users have an ad free experience!