Python Tutorial

Thursday, December 12, 2013

Context manager API

Python file object support the context manager API to make it easy to ensure they are closed after all reading or writing is done

with open('z.txt', 'r') as f:
    data = f.read()
    print data

Output:
File content

0 comments:

Post a Comment