Nodes/ComfyUI-JakeUpgrade/Evaluate Strings JK๐Ÿ‰
ComfyUI Node

Evaluate Strings JK๐Ÿ‰

Evaluate Strings JK runs Python string methods

By jakechaiยทCreated 2 years agoยทUpdated 3 months agoยท 146
Evaluate Strings JK๐Ÿ‰
    • STRING
    โ—„python_expressiona + b + cโ–บ
    โ—„aHelloโ–บ
    โ—„b Worldโ–บ
    โ—„c!โ–บ

    Prompt cleaning, filename building, tag wrangling - ComfyUI is full of string chores, and the default kit handles them awkwardly. Evaluate Strings JK gives you Python string operations inside one node: bind a, b, c to three strings, write an expression like a.strip().title() + " " + b, and get the result out as a single STRING. Same SimpleEval engine as the rest of the Evaluate family, but with string functions added to the whitelist.

    The defaults are instructive: a = "Hello", b = " World", c = "!", expression a + b + c โ†’ "Hello World!". It's a demo you can hit "Queue" on immediately and see work. From there, the examples node in the pack shows the real vocabulary: .upper(), .lower(), .title(), .strip(), .replace('old','new'), .split(' '), .isnumeric(), .startswith(), slicing a[:5], even a[::-1] to reverse. len() is also available, so len(a) + len(b) gives you a character count as a string.

    The honest limitations: it's string expression evaluation, not a full scripting environment. No loops, no if statements - but you can fake a lot with ternary-style expressions, and the whitelist means everything is safe to run. The output is always a string, so if you want the length back as an integer you'd better end the expression with a value that converts cleanly (the node returns str(result)).

    What you'd actually use it for: normalizing a messy prompt before it hits a text encoder, composing a filename prefix from parts (date + model name + seed string), stripping trailing commas after a random-prompt node, or standardizing casing so downstream tag matching works. If you're doing this more than once, this node beats a custom script.

    Install. It's part of ComfyUI-JakeUpgrade:

    cd ComfyUI/custom_nodes
    git clone https://github.com/jakechai/ComfyUI-JakeUpgrade
    cd ComfyUI-JakeUpgrade
    pip install -r requirements.txt
    

    Or ComfyUI Manager โ†’ "JakeUpgrade". Windows portable: install.bat or ../../../python_embeded/python.exe -s -m pip install -r requirements.txt. Restart. simpleeval comes with the pack - no model downloads.

    Gotchas: the result is str(result), so a non-string result (like True from a.startswith('H')) comes back as the literal text "True" - usually fine, but know it. Remember each of a/b/c defaults to a non-empty string here, so an expression referencing a variable you never connected evaluates against the default rather than erroring - connect them all to be safe. And the pack constants: LOAD_DEPRECATED_NODES = True if JK nodes report missing, disable ComfyUI MultiGPU per the README if you hit CUDA errors.

    Category๐Ÿ‰ JK/โœ–๏ธ Math

    Inputs (4)

    NameTypeDefaultDescription
    python_expressionSTRINGa + b + cPython expression using string variables a, b, c (e.g., 'a + b + c' or 'len(a)')
    aoptSTRINGHelloString variable a for expression
    boptSTRING WorldString variable b for expression
    coptSTRING!String variable c for expression

    Outputs (1)

    NameTypeDescription
    STRINGSTRINGโ€”