lundi 2 février 2015

How do I check if my loop never ran at all?

How do I check if my loop never ran at all?


This somehow looks too complicated to me:



x = _empty = object()
for x in data:
... # process x
if x is _empty:
raise ValueError("Empty data iterable: {!r:100}".format(data))


Ain't there a easier solution?


The above solution is from curiousefficiency.org


Background: data can contain None items.


Aucun commentaire:

Enregistrer un commentaire