Try block problem
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Tue Nov 20 09:05:49 EST 2001
On Tue, Nov 20, 2001 at 07:41:05AM -0600, Skip Montanaro wrote:
> def f(d):
> try:
> return d.keys()
> finally:
> d.clear()
>
> How would that be handled with try/except?
Imagine that we have a more generic case where instead of d.keys()
and d.clear() there are statements which may throw. Then the above
is equivalent to:
def f(d):
try:
result = d.keys()
except:
d.clear()
raise
else:
d.clear()
return result
--
__("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
\__/
^^
QRCZAK
More information about the Python-list
mailing list