loads#
loads(data) reads the file that dumps returned, a JSON str or CBOR
bytes, and returns the function, Pipeline or live session it holds. It is
load without a file, for a file kept in a database, sent over a network, or
held in a test.
Every function has the method dumps(format="json"), which returns its save
file as a str, or as bytes for format="cbor" (CBOR, RFC 8949, a binary
encoding of the same content). loads reads either encoding and takes the
same on_mismatch as load. In JavaScript, loads(data, { onMismatch })
takes the string or the Uint8Array that dumps returned.
Examples#
import screamer
f = screamer.EwMean(alpha=0.5)
f(1.0)
text = f.dumps()
print(text)
g = screamer.loads(f.dumps(format="cbor"))
print(g.dumps() == text)
{
"screamer": "save/1",
"library_version": "3.11.2",
"object": {
"type": "EwMean",
"settings": {
"com": null,
"span": null,
"halflife": null,
"alpha": 0.5
},
"state": {
"version": 1,
"values": {
"sum_x": 1.0,
"sum_w": 1.0
}
}
}
}
True
Signature#
loads(data, on_mismatch="error")
data- thestrorbytesthatdumpsreturned.on_mismatch-"error"or"fresh", as forload.
Used in the Guide#
See also#
load: Read a file that save wrote and return the function, Pipeline or live session it holdsfrom_settings: Build a fresh function from its type and settings, with no stateresume: The batch call that starts from a function's state and keeps the end state