| Store | Cart

Python style guidelines

From: Donn Cave <d...@u.washington.edu>
Thu, 11 Mar 2004 08:49:54 -0800
In article <EO%3c.2675$G3.20988 at localhost>,
 Peter Hansen <peter at engcorp.com> wrote:

[... re "if a.find(v):"]

> I believe it's more likely they just forgot what find() did return, as > they were writing the code.  I've done the same, thinking it was a > boolean, not thinking that it returned a negative but that negatives > were considered false.

I'm sure that's common.  In principle, seems to me that in
many if not most cases the "index" function expresses the
result better - for example,

   try:
       t = a.index(e)
   except ValueError:
       return a
   else:
       return a[:t]

But for some reason, the average programmer seems to greatly
prefer non-valid error returns over exceptions, even though
they're naturally idiosyncratic and prone to this kind of
error.  I sure don't recall seeing "index" very often, anyway.

   Donn Cave, donn at u.washington.edu

Recent Messages in this Thread
beli...@aol.com Mar 10, 2004 07:12 pm
Skip Montanaro Mar 10, 2004 10:09 pm
Will Berry Mar 11, 2004 10:39 pm
Richie Hindle Mar 12, 2004 09:36 am
Jorgen Grahn Mar 12, 2004 07:29 pm
MetalOne Mar 13, 2004 07:08 am
Heather Coppersmith Mar 13, 2004 01:22 pm
MetalOne Mar 13, 2004 09:28 pm
Andy Salnikov Mar 15, 2004 09:34 pm
wmwd...@sneakemail.com ) (Greg Ewing (using news.cis.dfn.de) Mar 15, 2004 12:39 am
Josef Meile Mar 11, 2004 09:48 am
Peter Otten Mar 11, 2004 11:18 am
Heather Coppersmith Mar 11, 2004 11:34 am
Josef Meile Mar 11, 2004 03:39 pm
Peter Hansen Mar 11, 2004 03:41 pm
Donn Cave Mar 11, 2004 04:49 pm
John Roth Mar 11, 2004 05:16 pm
wmwd...@sneakemail.com ) (Greg Ewing (using news.cis.dfn.de) Mar 12, 2004 03:23 am
Mel Wilson Mar 12, 2004 03:57 pm
Aahz Mar 11, 2004 04:27 pm
beli...@aol.com Mar 11, 2004 12:52 pm
Michael Hudson Mar 11, 2004 01:41 pm
Messages in this thread