miscset.io.Parsable¶
- class miscset.io.Parsable[source]¶
Bases:
objectA class where slots are parsable.
Provides methods to import and export values for data slots from dictionaries.
- Use case:
Get a dictionary from any object structure.
Get a JSON or YAML string from any object structure.
Parse a dictionary to add/overwrite object slots with values.
Example code:
import miscset class Container(miscset.io.Parsable): def __init__(self, value): self.value = value c = Container([1,2,3]) c.import_dict({"foo": "bar"}, add = True) print(c.get_json())
Result:
{"value": [1, 2, 3], "foo": "bar"}- __init__()[source]¶
Initialize a Parsable object.
Initializes the object and calls the reset function.
Methods
__init__()Initialize a Parsable object.
get_dict()Return values of the data slots as dictionary.
get_json()"Return values of the data slots as a json string.
get_text([name, sep, private])Return a description.
get_yaml()"Return values of the data slots as a yaml string.
import_dict(obj[, add])Import a dictionary into data slots.
reset()Reset slots to default values.
- get_dict()[source]¶
Return values of the data slots as dictionary.
Same as accessing the __dict__ slot from a class instance.
- Returns
- A dictionary with keys named as the class instance slots
containing the respective values.
- Return type
- get_json()[source]¶
“Return values of the data slots as a json string.
- Returns
A JSON formatted string.
- Return type
- get_yaml()[source]¶
“Return values of the data slots as a yaml string.
- Returns
A YAML formatted string.
- Return type