Tutorial 4 - The Store class - saving data quickly¶
The anamnesis.Store class can be used as a very simple way of storing data without having to define your own class.
To use the Store class, you simply have to place any data which you want to serialise into the extra_data member variable.
As usual with the tutorials, we start with a script which creates an example test file: test_script4_write.py:
#!/usr/bin/python3
import h5py
from anamnesis import Store
# Create a Store
s = Store()
s.extra_data['airport_from'] = 'Manchester'
s.extra_data['airport_to'] = 'Schipol'
# Write the store into a file
f = h5py.File('test_script4.hdf5', 'w')
s.to_hdf5(f.create_group('data'))
f.close()
Reading back a Store¶
Reading back a Store is no different to reading any other anamnesis object as can be seen in test_script4_read.py.
#!/usr/bin/python3
from anamnesis import obj_from_hdf5file
# Read from our store
s = obj_from_hdf5file('test_script4.hdf5')
print(s.extra_data['airport_from'])
print(s.extra_data['airport_to'])