vscode-debug-visualizer icon indicating copy to clipboard operation
vscode-debug-visualizer copied to clipboard

First time using this - Python

Open br00k130rr4y opened this issue 1 year ago • 1 comments

Image This is my first time using this extension. I'm trying to display the array y as a table, but it looks like a complete mess... Can someone guide me on how to use this?

br00k130rr4y avatar Feb 09 '25 17:02 br00k130rr4y

Note: the data must be transferred to the Visualizer as a json string for languages that only support BasicSupport. For the structure of json strings, see Visualization Playground Otherwise the Visualizer cannot display the data correctly.

The attached example uses the visualizeArray() function to create the json string. In the debugger, the call visualizeArray(y) must be specified instead of the variable y.

Image
# Demo for visualization of an array by using VS Code Debug Visualizer.
# ⚠️ Attention: the transfer to the Visualizer must be made as a json string 
# for languages that only support BasicSupport. 

import json

def visualizeArray(arr):
    """Serialize an array into a format the visualizer can understand."""
    formatted = {
        "kind": {"grid": True},
        "rows": [
            {
                "columns": [
                    {"content": str(value), "tag": str(value)} for value in arr
                ],
            }
        ],
    }
    return json.dumps(formatted)

y = [10,20,30]
y = [10,20,30,40]
y = [10,99,30,-3]
y = [0,99,30,-3, 4, 62]

Klummel69 avatar Feb 10 '25 09:02 Klummel69