The rap against "while True:" loops

Lie Ryan lie.1296 at gmail.com
Sun Oct 18 05:21:31 EDT 2009


Paul Rubin wrote:
> Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:
>> For the record, the four lines Paul implies are "confusing" are:
>>
>> try:
>>     d[key] += value
>> except KeyError:
>>     d[key] = value
> 
> Consider what happens if the computation of "key" or "value" itself
> raises KeyError.

Isn't key and value just a simple variables/names? Why should it ever 
raises KeyError? The only other error that try-block code could ever 
possibly throw are NameError and possibly MemoryError.



More information about the Python-list mailing list