Last active
February 7, 2016 18:42
-
-
Save samclane/c2e1bee32cd018407f04 to your computer and use it in GitHub Desktop.
Pretty print a nested dictionary into a RichTextCtrl(self)
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 pretty_print(self, elem, level=0): | |
""" | |
Adds indentation to output of an ElementTree based on depth of element. Recursive. | |
""" | |
# Todo: Write to be compliant with a dictionary | |
i = "\r\n" + 2 * level * " " | |
for item in elem: | |
(attr, val) = item | |
if not type(val) is dict: | |
self.BeginBold() | |
self.WriteText(i + attr + ": ") | |
self.EndBold() | |
self.WriteText(val) | |
else: | |
self.BeginBold() | |
self.WriteText(i + attr + ": ") | |
self.EndBold() | |
self.pretty_print(val.items(), level + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment