Skip to content

Instantly share code, notes, and snippets.

@danlooo
Last active August 14, 2022 12:58
Show Gist options
  • Save danlooo/a573be3afd95cf1e9ec76ee17c365f82 to your computer and use it in GitHub Desktop.
Save danlooo/a573be3afd95cf1e9ec76ee17c365f82 to your computer and use it in GitHub Desktop.
Inspect a (big and nested) python dictionary in VSCode
#!/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