Efficient way to store a dictionary (hash) in a file using python?

I am implementing a Unix user-space tool that needs to store a hash on disk. A hash will be read every program start, quite often. A hash should only store name: path values.

I looked at the bsddb standard library module for python, but I see that it will be deprecated in Python 3. I also saw the pickle standard library module.

I'm not a python guy, so what is an efficient way to serialize a hash and frequent open / read / close operations?

+5
source share
3 answers

shelve , . , .

import shelve

d = shelve.open('filename')

d['name'] = 'path'

d.close()

d = shelve.open('filename')

d = hash['name']

, , , .

+4

, .

0

All Articles