jztools.slice_sequence#
Warning
This module is deprecated in favor of jztools.reference_sequence!!
Serializable sequential slicing.
Examples:
from jztools.slice_sequence import SliceSequence, SSQ_
Both SliceSequence and SSQ_ are aliases of the same class and can be used interchangeably.
# Using slice sequences
arr = {'field1':list(range(20))}
orig = arr['field1'][1:10][0]
with_syntax1 = SSQ_()['field1'][1:10][0](arr)
with_syntax2 = SSQ_(['field1', slice(1,10), 0])(arr)
assert with_syntax1 == orig
assert with_syntax1 == with_syntax2
Slice sequence objects can be serialized in a human-readable format:
from xerializer import Serializer
# Serialization:
srlzr = Serializer()
ssq = SSQ_()['field1'][1:10][0]
json_string = srlzr.serialize(ssq)
print(json_string)
deserialized_ssq = srlzr.deserialize(json_string)
assert deserialized_ssq(arr) == ssq(arr)
{"__type__": "SliceSequence", "value": ["field1", {"__type__": "slice", "start": 1, "stop": 10}, 0]}
Classes
alias of |
|
|
- class jztools.slice_sequence.SliceSequence(value=None)#
Bases:
Serializable- signature = 'SliceSequence'#
A class-level property (
Noneorstr, no@property-decorated methods allowed) specifying the string to use in the__type__field of the serialized representation. The actual signature is produced by classmethodget_signature().
- __call__(obj)#
Call self as a function.
- as_serializable()#
Carries out the same function as
TypeSerializer.as_serializable()but for the current object (self).
- classmethod from_serializable(value)#
Returns an object of this class. By default, calls
__init__with the provided keywords.(See
TypeSerializer.from_serializable())
- jztools.slice_sequence.SSQ_#
alias of
SliceSequence