
On Sun, 6 Sep 2009 03:51:43 pm Greg Ewing wrote:
Nick Coghlan wrote:
That said, I'm -0 on the idea overall. If someone actually needs it, it isn't particularly hard for them to write their own getany() function.
There's a situation where the need to do this kind of thing actually arises fairly frequently -- retrieving things from a relational database. Often you're expecting exactly one result from a query, but the API always gives you a sequence, which you then have to get the first item from. Doing that over and over again gets rather tedious.
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. -- Steven D'Aprano