Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a getall function to lsit (top lwevel) keys and used os.path.expand.user so referring to e.g. ~/example.db works #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pickledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, location, option):
def load(self, location, option):
'''Loads, reloads or changes the path to the db file.
DO NOT USE this method has it may be deprecated in the future.'''
location = os.path.expanduser(location)
self.loco = location
self.fsave = option
if os.path.exists(location):
Expand All @@ -69,6 +70,10 @@ def get(self, key):
except KeyError:
return None

def getall(self):
'''return a list of all the keys'''
return self.db.keys()

def rem(self, key):
'''Delete a key'''
del self.db[key]
Expand Down Expand Up @@ -181,7 +186,7 @@ def deldb(self):
self._dumpdb(self.fsave)
return True

def _loaddb(self):
def _loaddb(self) :
'''Load or reload the json info from the file'''
self.db = json.load(open(self.loco, 'rb'))

Expand Down