openpathsampling.netcdfplus.proxy.lazy_loading_attributes

openpathsampling.netcdfplus.proxy.lazy_loading_attributes(*attributes)[source]

Set attributes in the decorated class to be handled as lazy loaded objects.

An attribute that is added here will be turned into a special descriptor that will dynamically load an objects if it is represented internally as a LoaderProxy object and will return the real object, not the proxy!

The second thing you can do is that saving using the .write() command will automatically remove the real object and turn the stored object into a proxy

Notes

This decorator will obfuscate the __init__ signature in Python 2. This is fixed in Python 3.4+

Examples

Set an attribute to a LoaderProxy

>>> my_obj.lazy_attribute = LoaderProxy(snapshot_store, 13)
>>> print my_obj.lazy_attribute
openpathsampling.Snapshot object

It will not return the proxy. This is completely hidden.

If you want to use the intelligent saving that will remove the reference to the object you can do >>> sample_store.write(‘parent’, index, my_sample)

After this call the attribute my_sample.parent will be turned into a proxy