This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Adrián.Deccico
Recipients Adrián.Deccico, docs@python
Date 2010-04-24.17:57:33
SpamBayes Score 7.779809e-05
Marked as misclassified No
Message-id <1272131855.89.0.865652130353.issue8522@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-04-24 17:57:35Adrián.Deccicosetrecipients: + Adrián.Deccico, docs@python
2010-04-24 17:57:35Adrián.Deccicosetmessageid: <1272131855.89.0.865652130353.issue8522@psf.upfronthosting.co.za>
2010-04-24 17:57:34Adrián.Deccicolinkissue8522 messages
2010-04-24 17:57:34Adrián.Deccicocreate