Issue 8522: enhacement proposal in howto/doanddont
Issue8522
Created on 2010-04-24 17:57 by Adrián.Deccico, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| doanddont.rst.patch | Adrián.Deccico, 2010-04-24 19:14 | patch for "Doc/howto/doanddont.rst" | ||
| Messages (4) | |||
|---|---|---|---|
| msg104111 - (view) | Author: Adrián Deccico (Adrián.Deccico) | Date: 2010-04-24 17:57 | |
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.
|
|||
| msg104112 - (view) | Author: Éric Araujo (eric.araujo) * ![]() |
Date: 2010-04-24 18:04 | |
Hello You’re right, this idiom (new in 2.5, always enabled in 2.6) is now the recommended way of doing this. Note that the older code does close the file properly too, it’s just another way of doing it. Would you like to provide a patch against the latest version of this file? Regards |
|||
| msg104119 - (view) | Author: Adrián Deccico (Adrián.Deccico) | Date: 2010-04-24 19:14 | |
Hi, you are right. I am attaching the patch. I tested against 2.6.5 and trunk (the file has no changed) thanks |
|||
| msg104146 - (view) | Author: Georg Brandl (georg.brandl) * ![]() |
Date: 2010-04-25 10:17 | |
Thanks, applied in r80461. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:00 | admin | set | github: 52768 |
| 2010-04-25 10:17:48 | georg.brandl | set | status: open -> closed nosy:
+ georg.brandl resolution: fixed |
| 2010-04-24 19:14:10 | Adrián.Deccico | set | files:
+ doanddont.rst.patch keywords: + patch messages: + msg104119 |
| 2010-04-24 18:04:49 | eric.araujo | set | assignee: docs@python -> title: enhacement proposal in http://docs.python.org/howto/doanddont.html -> enhacement proposal in howto/doanddont |
| 2010-04-24 17:57:34 | Adrián.Deccico | create | |
