Jacob H wrote:
Hello all,
Today I began writing a utility script that takes given binary files
and puts them all into one datafile. My idea is to be able to access
any binary data I want by indexing the datafile, e.g.
wanted_image_data = datafileobj[IMAGE_DATA]. The purpose is to hide
external image files from the user in a simple game I'm writing.
What you need, is a simple pickle of a dictionary save to disk.
It's dead easy, and does exactly what you want.
import cPickle
some_dict = {'my':'name','is':'norman','bates':'!'}
file_name = 'some.dict'
f = open(file_name, 'wb')
cPickle.dump(some_dict, f, -1)
f.close()
f = open(file_name, 'rb')
c = cPickle.load(f)
f.close()
print c
{'my': 'name', 'is': 'norman', 'bates': '!'}
"
3.14 pickle -- Python object serialization
The pickle module implements a fundamental, but powerful algorithm for
serializing and de-serializing a Python object structure. ``Pickling''
is the process whereby a Python object hierarchy is converted into a
byte stream, and ``unpickling'' is the inverse operation, whereby a byte
stream is converted back into an object hierarchy. Pickling (and
unpickling) is alternatively known as ``serialization'',
``marshalling,''3.2 or ``flattening'', however, to avoid confusion, the
terms used here are ``pickling'' and ``unpickling''.
This documentation describes both the pickle module and the cPickle module.
"
regards Max M