Andrei wrote:
Pickling is also very useful when combined with the bsddb module, because you
get a fast database which functions very much like a dictionary, and in which
you can put anything you like, as long as you pickle it first.


import bsddb
mydb = bsddb.btopen('game.db')
mydb['highscores'] = pickle.dumps(mylist)
mydb['highestlevel'] = pickle.dumps(21)
mydb['lastplayer'] = pickle.dumps('John Doe')
mydb.close()
mydb = bsddb.btopen('game.db')
pickle.loads(mydb['lastplayer'])

'John Doe'

You might be interested in the shelve module which essentially does this for you. With shelve your example would look like this:


import shelve
d = shelve.open('game.db')
d['highscores'] = mylist
d['highestlevel'] = 21
d['lastplayer'] = 'John Doe'

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to