Python Gotcha's?

Emile van Sebille emile at fenx.com
Thu Apr 5 16:06:36 EDT 2012


On 4/5/2012 11:10 AM Jon Clements said...
> On Wednesday, 4 April 2012 23:34:20 UTC+1, Miki Tebeka  wrote:
>> Greetings,
>>
>> I'm going to give a "Python Gotcha's" talk at work.
>> If you have an interesting/common "Gotcha" (warts/dark corners ...) please share.
>>
>> (Note that I want over http://wiki.python.org/moin/PythonWarts already).
>>
>> Thanks,
>> --
>> Miki
>
> One I've had to debug...
>
>>>> text = 'abcdef'
>
>>>> if text.find('abc'):
> 	print 'found it!'
> # Nothing prints as bool(0) is False
>
>>>> if text.find('bob'):
> 	print 'found it!'
> found it!
>
> Someone new who hasn't read the docs might try this, but then I guess it's not really a gotcha if they haven't bothered doing that.
>


Kind of begs for a contains method that returns the appropriate boolean:

if text.contains('bob')

Emile




More information about the Python-list mailing list