[issue8522] enhacement proposal in http://docs.python.org/howto/doanddont.html

Adrián Deccico report at bugs.python.org
Sat Apr 24 19:57:35 CEST 2010


New submission from Adrián Deccico <deccico at gmail.com>:

Hi, in "Exceptions" section. 

Instead of using:

def get_status(file):
    fp = open(file)
    try:
        return fp.readline()
    finally:
        fp.close()

Why no suggest this method:

def get_status(file):
    with open(file) as fp:
	return fp.readline()


which will properly close the file.

----------
assignee: docs at python
components: Documentation
messages: 104111
nosy: Adrián.Deccico, docs at python
severity: normal
status: open
title: enhacement proposal in http://docs.python.org/howto/doanddont.html
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8522>
_______________________________________


More information about the Python-bugs-list mailing list