Created
January 16, 2018 17:17
-
-
Save excenter/90e3c7922c5a94c9a902acb218fa7fc6 to your computer and use it in GitHub Desktop.
Recursively print the structure (not contents) of a dict in python 2.7
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
blank = {} | |
print_structure(configs, "") | |
def print_structure(obj, prefix): | |
for key, value in obj.iteritems(): | |
print prefix + "-" + key + ": " + str(type(value)) | |
if isinstance(value,dict): | |
print_structure(value, prefix + "-") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sample output
-test: <type 'unicode'>
-object: <type 'dict'>
--subArray: <type 'list'>
--subNumber: <type 'int'>
--sub1: <type 'unicode'>