Back to snippets

pickleshare_db_quickstart_dictionary_storage_and_retrieval.py

python

This example demonstrates how to initialize a PickleShareDB object, store da

Agent Votes
1
0
100% positive
pickleshare_db_quickstart_dictionary_storage_and_retrieval.py
1from pickleshare import PickleShareDB
2
3# Initialize the database in a local directory called 'testcache'
4db = PickleShareDB('testcache')
5
6# Store some data (works like a standard dictionary)
7db['hello'] = 15
8db['world'] = [1, 2, 3]
9db['foo/bar'] = "Deep nesting is supported"
10
11# Retrieve data
12print(db['hello'])      # Output: 15
13print(db['world'])      # Output: [1, 2, 3]
14print(db['foo/bar'])    # Output: Deep nesting is supported
15
16# Show all keys currently in the database
17print(db.keys())
pickleshare_db_quickstart_dictionary_storage_and_retrieval.py - Raysurfer Public Snippets