string find mystery
John Yeung
gallium.arsenide at gmail.com
Thu Sep 3 01:49:46 EDT 2009
On Sep 3, 1:10 am, Helvin <helvin... at gmail.com> wrote:
> if file_str.find('Geometry'):
> #if file_str.endswith('Data_Input_Geometry.txt'):
> print 'I found geometry'
> 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'.
>
> Does anyone know why this is happening?
Yep. You should read the documentation on the find method. It
returns -1 when the substring is not found. Also, if 'Geometry' had
been found at the beginning, it would have returned 0.
John
More information about the Python-list
mailing list