1

I've created a klepto dir_archive.

On subsequent archive access, how can the archive keys be determined without loading the entire archive into memory?

jim vickroy
  • 142
  • 2
  • 9

1 Answers1

1

Something like this?

>>> import klepto as kl
>>> kl.archives.dir_archive()
dir_archive('memo', {}, cached=True)
>>> d = _
>>> d['a'] = 0
>>> d['b'] = 1
>>> d['c'] = 2
>>> d
dir_archive('memo', {'a': 0, 'c': 2, 'b': 1}, cached=True)
>>> d.dump()
>>> 

Then restart the session...

>>> import klepto as kl
>>> d = kl.archives.dir_archive()
>>> d
dir_archive('memo', {}, cached=True)
>>> d.archive.keys()
['a', 'c', 'b']

There are also several private methods, if you'd need something peculiar:

>>> d.archive._keydict()
{'a': None, 'c': None, 'b': None}

But, the main point is: you can easily interact with the dir_archive without loading it, by using the archive attribute.

Mike McKerns
  • 33,715
  • 8
  • 119
  • 139