Thanks!  I just realised that too, but I used the condition:    .find() > 0 But
I think your's is better.
Simple programming knowledge...  > <
I made a blog post:
http://learnwithhelvin.blogspot.com/2009/09/1-is-true-if-loops.html

<http://learnwithhelvin.blogspot.com/2009/09/1-is-true-if-loops.html>

On Thu, Sep 3, 2009 at 5:19 PM, Stephen Hansen <apt.shan...@gmail.com>wrote:

> The amazing thing is when file_str  = 'C:\Qt\SimLCM\Default
>> \Data_Input_Material.txt',
>> the first if statement if fulfilled, that seemingly says that in this
>> file_str, python actually finds the word 'Geometry'.
>> I know this, because the line: 'I found geometry' is printed. However,
>> if instead of using file_str.find(), I use file_str.endswith(), it
>> does not exhibit this strange behaviour.
>>
>>
> The problem is str.find returns -1 on failure; and -1 is a true value. Only
> 0, empty string, empty sequences, etc, are false values.
>
> So, you have to test, 'if find_str.find(pattern) != -1:'
>
> HTH,
>
> --S
>



-- 
Helvin

"Though the world may promise me more, I'm just made to be filled with the
Lord."
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to