patx/pickledb — Issue #1: some improvements
Author: jabbalaci
Created: 2011-11-22 18:05:42+00:00
State: open

Hi,

I would have some ideas for improvements.

First, it should be called jsondb. You use json instead of pickle, so the name is very misleading. The line "import json as pickle" is terrible.

I would put everything in a class. Then you could have an interface like this:

jdb = JsonDb('test.db') # __init__ would do the job of your load() function
jdb.set('key', 'value')
jdb.get('key')

Global variables are discouraged to use, but if you group everything in a class, you could use those variables in the class with 'self', like self.db, etc.

Also, you do lots of I/O operations. It should be kept in memory and the user could call dump himself: jdb.dump() , and then you write everything to a file.

Add comments to every function. At the end of the source, add this:

if __name__ == "__main__":
# write an example for every function
# then the users will understand immediately how to use it

Laszlo