Simple container class with basic IO capabilities.
It is capable of storing itself in a file, or loading from a file using cPickle (optionally via zlib from compressed files). Any serializable object can be bound to a hamster to be stored.
To undig burried hamster use Hamster(filename). Here is an example:
>>> import numpy as np
>>> import tempfile
>>> h = Hamster(bla='blai')
>>> h.boo = np.arange(5)
>>> tmp = tempfile.NamedTemporaryFile()
>>> h.dump(tmp.name)
...
>>> h = Hamster(tmp.name)
Since Hamster introduces methods dump, asdict and property ‘registered’, those names cannot be used to assign an attribute, nor provided in among constructor arguments.
Methods
asdict() | Return registered data as dictionary |
dump(filename[, compresslevel]) | Bury the hamster into the file |
Initialize Hamster.
Providing a single parameter string would treat it as a filename from which to undig the data. Otherwise all keyword parameters are assigned into the attributes of the object.
Methods
asdict() | Return registered data as dictionary |
dump(filename[, compresslevel]) | Bury the hamster into the file |
Return registered data as dictionary
Bury the hamster into the file
Parameters: | filename : str
compresslevel : ‘auto’ or int
|
---|
List registered attributes.