Skip to content

Instantly share code, notes, and snippets.

@excenter
Created January 16, 2018 17:17
Show Gist options
  • Save excenter/90e3c7922c5a94c9a902acb218fa7fc6 to your computer and use it in GitHub Desktop.
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
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 + "-")
@excenter
Copy link
Author

sample output

-test: <type 'unicode'>
-object: <type 'dict'>
--subArray: <type 'list'>
--subNumber: <type 'int'>
--sub1: <type 'unicode'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment