String#
String operations.
- ktz.string.args_hash(*args)#
Produce a hash value for the provided args.
All provided arguments are transformed by their __str__ implementation.
- Parameters:
- *argsTo be hashed arguments
- Returns:
- str
Hash value for the arguments
Examples
>>> from ktz.string import args_hash >>> args_hash(10, "foo", True) 'a8c83023141d8ed54fcb3d019bdf61a7468f01ac5704d0eb5bf1c626'
- ktz.string.decode_line(encoded, sep=',', fn=None, fns=None)#
Decode a value list bytestring.
Takes a unicode encoded bytestring separated by the seperator token(s) and returns a value tuple. If fns are given, these are used to transform the separated values.
- Parameters:
- encodedbytes
The value bytestring
- sepstr
Separator token
- fnCallable[[A], str] | None
Optional converter applied to all, overrides fns
- fnsIterable[Callable[[str], A] | None]
Optional converter functions
- Returns:
- tuple[str | A]
The separated values
Examples
from ktz.string import decode_line >>> line = “Hellö | 22 | True”.encode(“unicode_escape”) >>> decode_line(line, sep=”|”, fns=(str, int, bool)) (‘Hellö’, 22, True)
- ktz.string.encode_line(data, sep=',', fn=None, fns=None)#
Encode a value collection.
Take a collection of either string values or other (requires fns) and produces a bytestring representation with values separated by sep. If fns are set, values are mapped accordingly. Adds a newline.
- Parameters:
- dataIterable[str | A]
Collection to be encoded
- sepstr
Separator token
- fnCallable[[A], str] | None
Optional converter applied to all, overrides fns
- fnsIterable[Callable[[A], str] | None]
Optional converter functions
- Returns:
- bytes
Encoded bytestring
Examples
>>> from ktz.string import decode_line >>> line = encode_line(("Hellö", 22, True), sep="|", fn=str) >>> line b'Hell\\xf6|22|True\n' >>> decode_line(line, sep="|", fns=(str, int, bool)) ('Hellö', 22, True)