Files Flashcards

1
Q

Open

A

open(file, mode=’r’, …)
file - pathname

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

Modes

A

r reading
w writing
x exclusive creation
a appending
t text (default)
b binary
+ updating

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

Read Only

A

r
handle at the start
raises error if file does not exist

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

Read and Write

A

r+
handle at the start
raises error if file does not exist

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

Write Only

A

w
handle at the start
truncates existing file
creates the file if it does not exists

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

Write and Read

A

w+
handle at the start
truncates existing file
creates the file if it does not exists

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

Append Only

A

a
handle at the end
creates the file if it does not exists

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

Append and Read

A

a+
handle at the end
creates the file if it does not exists

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

Reading Methods

A

read(size=-1, /)
readline(size=-1, /)
readlines(hint=-1, /)

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

Writing Methods

A

write(s, /)
writelines(lines, /)

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

Close

A

close()

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

With

A
with expression [as variable]:
    ...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Iterate over Lines

A
for line in file:
    ...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly