Reading and Writing Files Flashcards
1
Q
Close the file
A
.close()
2
Q
Read the file
A
file_contents is variable name
#assume file_name is file path
file_contents = read(file_name)
3
Q
Read just one line from a text file
A
line = readline(file_name)
4
Q
Empty the file !!! CAREFUL !!!
A
truncate(file_name)
5
Q
Write ‘stuff’ to the file
A
target = open(filename, ‘w’)
target.write(‘stuff’)
5
Q
Move the read/write location to the beginning of the file
A
seek(0)
5
Q
open a file
A
set open(file_name) to a variable
#assume(file_name) is full file path
target = open(file_name)