[Baypiggies] Notes on defaultdict

Keith Dart keith at dartworks.biz
Fri Aug 27 21:20:36 CEST 2010


On Fri, 27 Aug 2010 07:39:41 -0500
Zach Collins <recursive.cookie.jar at gmail.com> wrote:

> try:
>     output[color].append(value)
> except:
>     output[color] = [value]

That's a pretty good way to do it, except for the bare "except" part.
You should specifically catch the expected exception only.

try:
	output[color].append(value)
except KeyError:
	output[color] = [value]

That is generally the best practice for any exception handling. Only
catch what you are prepared to handle in your current scope. 


-- 
-- ------------------------------
Keith Dart
=================================



More information about the Baypiggies mailing list