PrintTableVisitor

class mlfarm.debug.PrintTableVisitor[source]
visit_dict(obj)[source]

Appends “.k” for each k key in the dict before calling the child visit.

visit_list(obj)[source]

Appends “[i]” for each i index in the list before calling the child visit.

visit_obj(obj)[source]

This is here to be overwriten in a child class. We know the argument is not list, dict or str.

Parameters:obj (object) – Object to be transformed.
Returns:The same object.
Return type:str | object | list | dict
>>> class ObjVisitor(BaseVisitor):
...     def visit_obj(self, obj):
...         if obj % 2 == 0:
...             return obj // 2
...         else:
...             return (obj + 1) // 2
...
>>> ov = ObjVisitor()
>>> a = list(range(10))
>>> ov.visit(a)
[0, 1, 1, 2, 2, 3, 3, 4, 4, 5]
visit_str(obj)[source]

This is here to be overwriten in a child class. The argument is a string.

Parameters:obj (str) – Object to be transformed.
Returns:The same object.
Return type:str | object | list | dict
>>> class StrVisitor(BaseVisitor):
...     def visit_str(self, obj):
...         if obj == 'nok':
...             return 'error'
...         return obj
...
>>> sv = StrVisitor()
>>> a = [{'a': 'ok'}, {'b': 1}, {'c': 'nok'}]
>>> sv.visit(a)
[{'a': 'ok'}, {'b': 1}, {'c': 'error'}]