string find mystery

Tim Chase python.list at tim.thechases.com
Thu Sep 3 05:21:16 EDT 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.

-tkc







More information about the Python-list mailing list