Nodes/ComfyUI-Data-Analysis/Py String To List
ComfyUI Node

Py String To List

Type a Python List Literal, Get a Real List — Round Trip Included

By HowToSD·Created 2 years ago·Updated about a year ago· 23
Py String To List
    • PYLIST
    data

    Lists are everywhere in data work - a set of categories, a list of column names, a sequence of numbers - and in a node graph they usually start life as text. Py String To List is the parser: type a Python list literal into a multiline box, get a real PYLIST out.

    It's the mirror of Py List To String, and together they're a clean round trip: convert a list to text for display or storage, then parse it back when you need the actual list again.

    How it works

    The node uses ast.literal_eval() on your text, so the input must be a valid Python list literal. [1, 2, 3] and ["apple", "banana"] work; list(range(5)) does not, because that's an expression, not a literal. literal_eval is safe - it won't execute arbitrary code - but it's strict about syntax.

    One JSON gotcha carries over from the pack's other literal-parsing nodes: Python booleans, not JSON's. So [true, false] fails; [True, False] works. If you're feeding it JSON-style arrays, mind the case on booleans and null.

    Inputs and outputs

    • data - the multiline string holding your list literal.

    Output: a PYLIST - the parsed list, ready for list-consuming nodes or Py List To String for the trip back to text.

    Install

    Ships in HowToSD/ComfyUI-Data-Analysis. Manager: search "Data analysis" in the Custom Node Manager, install ComfyUI-Data-Analysis, restart, reload the browser. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/HowToSD/ComfyUI-Data-Analysis.git
    mv ComfyUI-Data-Analysis data-analysis   # README: example workflows expect this folder name
    pip install -r requirements.txt
    

    No models, no GPU - parsing is all it does.

    Common issues

    Syntax errors are the whole risk surface, and they're loud. Missing brackets, a stray true instead of True, or a trailing comma where Python doesn't want one will all raise. Empty list is fine as []. And remember, single values like "42" parse as a string, not a list - if you need a one-element list, type [42]. When in doubt, run Py List To String on an existing list to see exactly what literal text the parser will accept, then copy that.

    CategoryData Analysis

    Inputs (1)

    NameTypeDefaultDescription
    dataSTRING

    Outputs (1)

    NameTypeDescription
    PYLISTPYLIST