=== modified file 'Doc/tutorial/inputoutput.rst' --- Doc/tutorial/inputoutput.rst 2008-01-27 15:18:18 +0000 +++ Doc/tutorial/inputoutput.rst 2008-07-16 23:06:50 +0000 @@ -308,6 +308,16 @@ File "", line 1, in ? ValueError: I/O operation on closed file +It is a common practice to use the with keyword to ensure that the file is +being closed even if an exception is raised during the reading process. :: + + >>> with open("test") as file_obj: + ... read_data = file_obj.read() + >>> file_obj.read() + Traceback (most recent call last): + File "", line 1, in + ValueError: I/O operation on closed file + File objects have some additional methods, such as :meth:`isatty` and :meth:`truncate` which are less frequently used; consult the Library Reference for a complete guide to file objects.