Reading and Writing Files Flashcards

1
Q

Close the file

A

.close()

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

Read the file

A

file_contents is variable name

#assume file_name is file path
file_contents = read(file_name)

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

Read just one line from a text file

A

line = readline(file_name)

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

Empty the file !!! CAREFUL !!!

A

truncate(file_name)

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

Write ‘stuff’ to the file

A

target = open(filename, ‘w’)
target.write(‘stuff’)

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

Move the read/write location to the beginning of the file

A

seek(0)

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

open a file

A

set open(file_name) to a variable

#assume(file_name) is full file path
target = open(file_name)

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