13 Dec
2011
13 Dec
'11
9:39 p.m.
On 12/13/2011 04:30 PM, Kirby Urner wrote:
I think of a "key not found" event in a dict as "routine, to be expected" whereas I think of try: / except: as for "crying wolf" (not for everyday contingencies). The opposite bias is: why make that distinction, try: / except: is a perfectly reasonable construct for trapping a new key to a dict.
More evidence for the "perfectly reasonable": Iterators are implemented with the StopIteration exception. You can find a few other examples in the language for things like that. I think it's perfectly reasonable myself. -- Corey Richardson