Help with dbm TypeError

ryan k ryan at ryankaskel.com
Mon Jan 9 16:14:14 EST 2006


I am writing a web application for mod_python that catalogs my home
(book) library. For now, I am using the Python dbm module to store
string representations of mod_python's req.form (using the
mod_python.publisher handler) using unique IDs as keys. In the .db
file, there is a key 'next' that holds the next key for the next form
submission. A TypeError exception is raised though when I attempt to
increment the 'next' key. This only occurs in mod_python.

This code...

    self._db['next'] = str(int(self._db['next'])+1)

raises this exception....

TypeError: string indices must be integers

>>> y = dbm.open("Test","c")
>>> next = 0
>>> y['next'] = str(next)
>>> y['next'] = str(int(y['next'])+1)
>>> y['next']
'1'
>>> y['next'] = str(int(y['next'])+1)
>>> y['next']

'2'

I do not understand the cause of this exception. I am using Python
2.3.5. Any help would be greatly appreciated.

Ryan Kaskel




More information about the Python-list mailing list