2

In python 2.6.5, an instance of dbm does not have a __nonzero__ or a __len__ method, so why does it evaluate false as a boolean?

>>> a = dbm.open( 'foo', 'c' )
>>> if a: print 'true'
...
>>>
William Pursell
  • 204,365
  • 48
  • 270
  • 300

1 Answers1

4

According to the python documentation one of the types of values that is considered false is

any empty mapping, for example, {}.

Since a dbm object is a mapping and a new instance is empty, it is therefore false.

srgerg
  • 18,719
  • 4
  • 57
  • 39