Commit 59f667a5 authored by Mark Hymers's avatar Mark Hymers

Add Store tutorial

Signed-off-by: Mark Hymers's avatarMark Hymers <mark.hymers@ynic.york.ac.uk>
parent 53f6ad23
......@@ -9,4 +9,9 @@ Serialisation
tutorials/tutorial1
tutorials/tutorial2
tutorials/tutorial4
MPI
---
TODO
#!/usr/bin/python
import h5py
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'])
#!/usr/bin/python
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()
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`:
.. literalinclude:: test_script4_write.py
:language: python
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`.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment