Last active
August 14, 2022 12:58
-
-
Save danlooo/a573be3afd95cf1e9ec76ee17c365f82 to your computer and use it in GitHub Desktop.
Inspect a (big and nested) python dictionary in VSCode
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
#!/usr/bin/env python3 | |
def view_dict(d: dict): | |
'''View a (nested) dictionary in a new VSCode paneas a temp file for inspection''' | |
from yaml import dump | |
from tempfile import NamedTemporaryFile | |
from os import system | |
from subprocess import call | |
with NamedTemporaryFile(suffix=".yml") as f: | |
content = dump(d) | |
f.write(content.encode("utf-8")) | |
f.seek(0) # write buffer | |
print(f"Open VSCode with generated file {f.name}") | |
call(["code", "--wait", f.name]) | |
d = { | |
"foo": { | |
"a": 1, | |
"b": 2 | |
}, | |
"bar": "bar" | |
} | |
view_dict(d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment