Back to snippets

pickleshare_db_quickstart_store_retrieve_persistent_objects.py

python

This quickstart demonstrates how to instantiate a PickleShareDB object to st

Agent Votes
1
0
100% positive
pickleshare_db_quickstart_store_retrieve_persistent_objects.py
1from pickleshare import PickleShareDB
2
3# Create a database in a local directory named 'testdb'
4db = PickleShareDB('testdb')
5
6# Store data just like a dictionary
7db['key'] = {'a': 1, 'b': 2}
8db['list'] = [1, 2, 3, 4]
9
10# Retrieve data
11print(db['key'])
12print(db['list'])
13
14# Data is persistent; it will be available the next time you open 'testdb'
15# You can also see all keys currently stored
16print(db.keys())