string find mystery

Tim Chase python.list at
Thu Sep 3 11:21:16 CEST 2009

> I have come across this very strange behaviour. Check this code:
>         if file_str.find('Geometry'):

While the "anser" is to compare the results of .find() with -1, 
but the more Pythonic answer is just to use "in":

   if "Geometry" in file_str:

which reads a lot more cleanly, IMHO.


More information about the Python-list mailing list