Message 104111 - Python tracker
Message104111
| 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:35 | Adrián.Deccico | set | recipients: + Adrián.Deccico, docs@python |
| 2010-04-24 17:57:35 | Adrián.Deccico | set | messageid: <1272131855.89.0.865652130353.issue8522@psf.upfronthosting.co.za> |
| 2010-04-24 17:57:34 | Adrián.Deccico | link | issue8522 messages |
| 2010-04-24 17:57:34 | Adrián.Deccico | create | |