[Python-ideas] data structures should have an .any() method
Antoine Pitrou
solipsis at pitrou.net
Sun Sep 6 23:45:49 CEST 2009
Steven D'Aprano <steve at ...> writes:
>
> If you're expecting "exactly one result", then surely it should be an
> error to receive more than one result? Rather than ask for "any" result
> and ignoring any unexpected extra items, I think it would be better to
> have a helper function that verifies you have got exactly one result.
Why do you need a helper function?
Simply write:
x, = db.query("SELECT blah...")
and you'll get a ValueError if there isn't exactly one item in the sequence.
Regards
Antoine.
More information about the Python-ideas
mailing list