The rap against "while True:" loops

Ben Finney ben+python at benfinney.id.au
Sun Oct 18 05:43:16 EDT 2009


Lie Ryan <lie.1296 at gmail.com> writes:

> 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?

In that example, yes. Paul is encouraging the reader to think of more
complex cases where they are compound expressions, that can therefore
raise other errors depending on what those expressions contain.

-- 
 \     “Don't be afraid of missing opportunities. Behind every failure |
  `\         is an opportunity somebody wishes they had missed.” —Jane |
_o__)                                          Wagner, via Lily Tomlin |
Ben Finney



More information about the Python-list mailing list