returnn.util.literal_py_to_pickle#

Convert literal Python (Python code which can be parsed with ast.literal_eval to Pickle.

Code partly taken from here: https://github.com/albertz/literal-python-to-pickle

returnn.util.literal_py_to_pickle.literal_eval(s)[source]#

This can be used as an alternative to ast.literal_eval. In contrast to ast.literal_eval, it also accepts bytes, and it should be ~5x faster.

Parameters:

s (str|bytes) –

Returns:

any object

returnn.util.literal_py_to_pickle.py_to_pickle(s)[source]#
Parameters:

s (str|bytes) –

Return type:

bytes