> Or you can use the has_key() and test it first. For example > > if foo.has_key('bar'): > print 'we have it' > else : > print 'we don't have bar.' >
Nowadays you can also say: if 'bar' in foo: # do something -- http://mail.python.org/mailman/listinfo/python-list