Posts

Showing posts with the label pickle

pywebsite.sqlitepickle. sqlite VS pickle

Image
The sqlite and pickle modules that come with python are quite useful. So lets mix them together and see what comes out. SQLITE Vs PICKLE pywebsite.sqlitepickle is a little module I just made which combines sqlite and pickle for persistence. Useful since it works with python3, and both pickle and sqlite are included with pythons (including pypy). Import the module. >>> from pywebsite import sqlitepickle An in memory db. >>> db = sqlitepickle.SQLPickle() >>> db.save('key', 'value') >>> db.get('key') 'value' Can also save to a file. So we first get a temp file name. >>> import tempfile >>> f = tempfile.NamedTemporaryFile() >>> fname = f.name >>> db = sqlitepickle.SQLPickle(fname) >>> db.save('key', 'value') >>> db.get('key') 'value' >>> db.close() The issues with this are that sqlite does not like sharing conn...