gdbm
is indeed a C module; the object implements the C-API mapping protocol instead.
See the source code for the PyMappingMethods
structure with function pointers.
You could use operator.getitem()
to access the keys:
>>> from operator import getitem
>>> db['foo'] = 'bar'
>>> getitem(db, 'foo')
'bar'
You could wrap getitem()
in functools.partial()
to make it an efficient callable with one argument:
>>> from functools import partial
>>> gi = partial(getitem, db)
>>> gi('foo')
'bar'
As getitem
and partial
are implemented in C, this combo will always be faster than custom objects, functions or lambdas to wrap the access.