shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread jelle
the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? this breaks the if check.find('something'): do(somethingElse) idiom, which is a bit of a pity I think. cheers, -jelle --

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Martin Marcher
2007/10/31, jelle [EMAIL PROTECTED]: the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? this breaks the IMHO 0 would mean the substring starts at index 0 of the iterable. If that

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Andrii V. Mishkovskyi
2007/10/31, jelle [EMAIL PROTECTED]: the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? this breaks the if check.find('something'): do(somethingElse) idiom, which is a bit of

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread jelle feringa
What's your point? :/ that of making sure before you post and cause public emberassement? -- http://mail.python.org/mailman/listinfo/python-list

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Luis Zarrabeitia
the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? I belive str.find should return the first position where the substring appears. If string.find(ugh) were to return 0, how would you

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Simon Brunning
On 10/31/07, jelle [EMAIL PROTECTED] wrote: the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? this breaks the if check.find('something'): do(somethingElse) print

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Marc 'BlackJack' Rintsch
On Wed, 31 Oct 2007 13:31:06 +, jelle wrote: if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? this breaks the if check.find('something'): do(somethingElse) idiom, which is a bit of a pity I think. And

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Carsten Haese
On Wed, 2007-10-31 at 13:31 +, jelle wrote: the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? this breaks the if check.find('something'): do(somethingElse) idiom,

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Hrvoje Niksic
jelle [EMAIL PROTECTED] writes: the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? How would you treat the case of 'something' being at the beginning of the string? After all, find

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread jelle feringa
There is a subtle point though. If the substring is not found '_'.find(' '), will return -1 Semanticly, I was expecting the that if the substring was not found, the conditional statement would not be found. However, python evaluates -1 to True, so that is what I do find confusing. So, I was

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Tim Chase
if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? this breaks the if check.find('something'): do(somethingElse) idiom, which is a bit of a pity I think. That idiom is spelled: if 'something' in check:

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread J. Clifford Dyer
On Wed, Oct 31, 2007 at 03:55:49PM +0100, jelle feringa wrote regarding Re: shouldn't 'string'.find('ugh') return 0, not -1 ?: There is a subtle point though. If the substring is not found '_'.find(' '), will return -1 Semanticly, I was expecting the that if the substring

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Carl Banks
On Oct 31, 9:31 am, jelle [EMAIL PROTECTED] wrote: the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? this breaks the if check.find('something'): do(somethingElse) idiom,

RE: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Looney, James B
: Wednesday, October 31, 2007 8:56 AM To: Luis Zarrabeitia Cc: python-list@python.org Subject: Re: shouldn't 'string'.find('ugh') return 0, not -1 ? There is a subtle point though. If the substring is not found '_'.find(' '), will return -1

shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread jelle feringa
Hi Tim, Well, I this is another idiom in itself, right? Your checking if something is part of an iterable. I'm checking truth before entering a conditional expression. The latter is considered to be pythonic, right? -jelle On 10/31/07, Tim Chase [EMAIL PROTECTED] wrote: if I check a string

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread jelle feringa
The statement that you want to test the truth of is s.find(q) = 0. In other words, you want to see that the substring was found at a valid (non-negative) location. As someone else pointed out, it would make more sense to use None instead of -1. I agree, that would be nice. You still

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread jelle
if 'something' in check: do(somethingElse) Tim, you're absolutely right that the above makes far more sense in my case. Thanks for pointing that out. -jelle -- http://mail.python.org/mailman/listinfo/python-list

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Tim Chase
Well, I this is another idiom in itself, right? Your checking if something is part of an iterable. I'm checking truth before entering a conditional expression. I'm not sure I follow. I simply replaced your if check.find('something') with if 'something' in check: which (1) is more

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread jelle feringa
Thanks for your in-depth explanation Tim. Which is impossible to disagree with! On 10/31/07, Tim Chase [EMAIL PROTECTED] wrote: Well, I this is another idiom in itself, right? Your checking if something is part of an iterable. I'm checking truth before entering a conditional expression.

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread TheFlyingDutchman
On Oct 31, 8:11 am, Carl Banks [EMAIL PROTECTED] wrote: string.find has always been kind of a wart in Python; that's why they're getting rid of it. For testing for the presence of a substring, use the in operator: Per the Python 3000 presentation given by Guido Van Rossum at PyCon February