Message70825
| Author |
pitrou |
| Recipients |
loewis, ocean-city, pitrou |
| Date |
2008年08月07日.13:43:13 |
| SpamBayes Score |
0.00011187705 |
| Marked as misclassified |
No |
| Message-id |
<1218116594.37.0.476524768082.issue3515@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
You don't need to raise another exception, calling sys.exc_clear()
should be fine. But a cleaner way to write your example is:
def foo():
with open("a.txt", "w") as io:
raise RuntimeError()
"with" will automatically close the file when the block exits.
If you are concerned with Python < 2.5 compatibility, use "try: ...
finally:" instead.
And, you're right, the problem doesn't occur at all in Python 3.0
because the exception is cleaned up after the end of the "except:" block
catching it. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2008年08月07日 13:43:14 | pitrou | set | recipients:
+ pitrou, loewis, ocean-city |
| 2008年08月07日 13:43:14 | pitrou | set | messageid: <1218116594.37.0.476524768082.issue3515@psf.upfronthosting.co.za> |
| 2008年08月07日 13:43:13 | pitrou | link | issue3515 messages |
| 2008年08月07日 13:43:13 | pitrou | create |
|