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
--
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
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
What's your point? :/
that of making sure before you post and cause public emberassement?
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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,
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
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
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:
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
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,
: 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
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
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
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
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
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.
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
20 matches
Mail list logo