jacinle.io.pretty#
Functions to dump Python objects into human-readable formats.
Functions
|
Dump a structured object into a file, similar to |
|
Dump a JSON object into a file. |
|
Dump a list of dictionary into a JSON string, separated by new lines, with compressed format. |
|
Dump a structured object into a file, using |
|
Dump a structured object into a file, using |
|
Dump a list of strings into a file, separated by newlines. |
|
Dump an XML object into a file. |
|
Dump a YAML object into a file. |
|
Dump a structured object into a string, similar to |
|
Dump a JSON object into a string. |
|
Dump a list of dictionary into a JSON string, separated by new lines, with compressed format. |
|
Dump a structured object into a string, using |
|
Dump a structured object into a string, using |
|
Dump a list of strings into a string, separated by newlines. |
|
Dump an XML object into a string. |
|
Dump a YAML object into a string. |
|
Iterate over lines in a text file. |
|
Load a JSON object from a string. |
|
Load a list of JSON dictionaries from a string. |
|
Load an XML object from a string. |
|
Load a YAML object from a string. |
|
Load a JSON object from a string. |
|
Load a list of JSON dictionaries from a string. |
|
Load an XML object from a string. |
|
Load a YAML object from a string. |
|
Dump a file with pretty-printing. |
|
Dump a JSON object into a file, with pretty-printing. |
|
Dump a JSON object into a string, with pretty-printing. |
|
Load a file with pretty-printing. |
Functions
- dump_env(value)#
Dump a structured object into a file, similar to
os.environ()
.
- dump_json(value, compressed=True)#
Dump a JSON object into a file. In addition to the standard JSON format, this function also supports
__jsonify__
: an instance method for objects that returns a JSON-serializable object.For classes, it will store
__dict__
as the JSON object.
Note that both features can not be preserved when loading the JSON object back.
- dump_jsonc(value)#
Dump a list of dictionary into a JSON string, separated by new lines, with compressed format.
- dump_kv(value)#
Dump a structured object into a file, using
jacinle.utils.printing.kvformat()
.
- dump_struct(value)#
Dump a structured object into a file, using
jacinle.utils.printing.stformat()
.
- dump_txt(value)#
Dump a list of strings into a file, separated by newlines.
- dump_xml(value, **kwargs)#
Dump an XML object into a file.
- dumps_json(value, compressed=True)[source]#
Dump a JSON object into a string. In addition to the standard JSON format, this function also supports
__jsonify__
: an instance method for objects that returns a JSON-serializable object.For classes, it will store
__dict__
as the JSON object.
Note that both features can not be preserved when loading the JSON object back.
- dumps_jsonc(value)[source]#
Dump a list of dictionary into a JSON string, separated by new lines, with compressed format.
- dumps_kv(value)[source]#
Dump a structured object into a string, using
jacinle.utils.printing.kvformat()
.
- dumps_struct(value)[source]#
Dump a structured object into a string, using
jacinle.utils.printing.stformat()
.
- iter_txt(fd, strip=True)[source]#
Iterate over lines in a text file. This function will ignore empty lines.
- load_jsonc(value)#
Load a list of JSON dictionaries from a string. This function supports multiple JSON objects in a single string, separated by newlines. Note that this function only support a list of plain dictionaries. Do not use this function to load JSON objects with nested lists or dictionaries.
- load_xml(value, name_key='__name__', attribute_key='__attribute__')#
Load an XML object from a string. It will return a dictionary as the root node. For each node, it will have a key named “__name__” as the tag name, and a key “__attributes__” as a dictionary of attributes. Each child node will be a nested dictionary under the root node. If there are multiple child nodes with the same tag name, they will be stored in a list.
- loads_jsonc(value)[source]#
Load a list of JSON dictionaries from a string. This function supports multiple JSON objects in a single string, separated by newlines. Note that this function only support a list of plain dictionaries. Do not use this function to load JSON objects with nested lists or dictionaries.
- loads_xml(value, name_key='__name__', attribute_key='__attribute__')[source]#
Load an XML object from a string. It will return a dictionary as the root node. For each node, it will have a key named “__name__” as the tag name, and a key “__attributes__” as a dictionary of attributes. Each child node will be a nested dictionary under the root node. If there are multiple child nodes with the same tag name, they will be stored in a list.
- pretty_dump_json(value, compressed=False)#
Dump a JSON object into a file, with pretty-printing.