Skip to content

Reversibility #99

Answered by drhagen
Kircheneer asked this question in Q&A
Discussion options

You must be logged in to vote

In general, deparsing is much easier than parsing. You don't typically need a library to deparse a data structure, just str. For example, a few rounds with ChatGPT and some manual tweaking gave me this to convert your data to the desired text:

def convert_to_text_file(data, indent=0):
    output = ""
    for key, value in data.items():
        if isinstance(value, dict):
            output += " " * indent + key + "\n" + convert_to_text_file(value, indent + 4)
        elif value:
            output += " " * indent + key + "\n"
    return output

data = {"parent": {"child": {"bad-parameter": False, "good-parameter": True}, "other-child": {"bad-parameter": False}}}

text_file_output = conver…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by drhagen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #98 on July 02, 2023 12:45.