jangada.serialization.Persistable.__init__#
- Persistable.__init__(*args, **kwargs) None#
Initialize a Persistable object.
Supports three modes based on arguments:
Normal construction:
obj = MyClass(prop1=val1)Load from file:
obj = MyClass('/path/file.hdf5')Context manager prep:
obj = MyClass('/path/file.hdf5', mode='r')
- Parameters:
- *argstuple
If empty: normal Serializable construction with kwargs If single Path/str: load from that file If single Path/str with kwargs: prepare for context manager
- **kwargsdict
For mode 1: property values For mode 3: must include ‘mode’ parameter (HDF5 file mode)
- Raises:
- ValueError
If unknown kwargs are provided in context manager mode.
- FileNotFoundError
If loading from non-existent file.
Examples
Normal construction:
exp = Experiment(name="Test", temperature=300.0)
Load from file:
exp = Experiment('data.hdf5')
Prepare for context manager:
exp = Experiment('data.hdf5', mode='r+') with exp as e: # Use e pass
Or directly:
with Experiment('data.hdf5', mode='r+') as exp: # Use exp pass