Menu
Coddy logo textTech

Close

Lesson 9 of 12 in Coddy's File Handling in Python course.

It's a good practice to close the files you open, using close().

f = open('a.txt')
f.close()

Or it can be also done by using with in Python,

with open('a.txt') as f:
	# preform operations on f

Using with keyword eliminates the need to close the file as it does it for you!

Try it yourself

This lesson doesn't include a code challenge.

All lessons in File Handling in Python