Files Flashcards

1
Q

Working with data files

A

• In Python, we must open files before we can use them and close them when we are done with them.

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

Open & close

A

open(filename, ‘r’)
Open a file called filename and use it for reading. This will return a reference to a file object.

open(filename, ‘w’)
Open a file called filename and use it for writing. This will also return a reference to a file object.

filevariable.close() File use is complete.

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