0

I'm having issues adding an index variable to dbm.dumb. What i mean by index variable:

var = b"string",b"string_one",b"string_two"
var[0] #being an index variable 

Now when I try and add to it using the following code:

database = dbm.dumb.open(z ,'c')


database["item 1"] = x[2],y[2]
database["item 2"] = x[0],y[0]
database["item 3"] = x[1],y[1]

and i get the following error

TypeError: values must be bytes or strings

I have tried casting the variables so they are strings but it wont let that go through. I'm stuck.

shurburt
  • 93
  • 2
  • 6
  • Use the `type` command to test your variables. `var` is a tuple, `var[0]` is a string, which is expected as input. But you are entering two strings separated by a comma. That's not a string. – roadrunner66 Mar 23 '16 at 18:51

1 Answers1

0

dbm is not he best lib to use in your case. shelve will solve your problem.

import shelve

database = shelve.open('/tmp/test.db', 'c')
database['item 1'] = [1, 2, 3]
database['item 2'] = 'string values'
database['item 3'] = {'name': 'Michael', 'lastname': 'Corbett'}
Mauro Baraldi
  • 6,346
  • 2
  • 32
  • 43