Last active
June 21, 2022 10:26
-
-
Save pank-su/f896c22cb28a63d3d49126328d6124cd to your computer and use it in GitHub Desktop.
Simple function, which translate json to qml ListModel file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def json_to_qml_model(json_array: list, filename: str): | |
with open(filename, "w", encoding="utf-8") as topic_model_file: | |
topic_model_file.write("""import QtQuick 2.0\n | |
ListModel {\n""") | |
for obj in json_array: | |
topic_model_file.write(" ListElement {\n") | |
[topic_model_file.write(f""" {key}: {repr(value)}\n""") | |
for key, value in obj.items()] | |
topic_model_file.write(" }\n") | |
topic_model_file.write("}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment