多参代码表达式
A Python eval box that sits right in your graph
- p0
- p1
- r0
MultiParamFormula ("多参代码表达式", multi-parameter code expression) is a mini code interpreter as a node: you feed it parameters named p0, p1, ... - of any type - type a Python expression, and it evaluates it and hands the result back on r0, r1, .... If you've ever used rgthree's Power Puter, it's that idea: a debug-and-compute escape hatch when no prebuilt node does the arithmetic you need.
Where this shines is the fiddly glue work ComfyUI is bad at. Comparing two values to drive a switch. Indexing into a list (p0[p1]). Slicing an image batch (p0[p1:p1+1]). Measuring a list's length (len(p0)). Joining a string array (','.join(p0)). The author's own examples, straight off the node, are exactly these. Instead of stringing together five math nodes, you write one line.
How it works
Simple mode takes your expression and evaluates it with p0, p1, ... in scope, plus a json module so you can do json.dumps(...) on a structure you want to inspect. The result goes to r0. If you want multiple outputs, return a tuple and they map to r0, r1, r2...
Advanced mode is where it gets powerful and a little dangerous: instead of a one-line expression it runs a block of code with exec, and you're expected to assign your answer to a variable named result - forget it and the node tells you "表达式没有返回值" (expression returned nothing). In this mode the code can also set an expand variable and a ui dict, which lets it do things like produce extra output nodes or push UI text. That's genuinely beyond what most ComfyUI expression nodes offer.
The inputs and outputs
expression- the Python code. One line for simple mode, a block for advanced.advanced-enable/disable, flips betweenevalandexecbehavior.p0,p1, ... - inputs of any type, available by name in the expression.- Outputs:
r0,r1, ... - the result(s).
Installing it
From the ComfyUI_Lam pack - Manager search "ComfyUI_Lam", or:
cd ComfyUI/custom_nodes
git clone https://github.com/yanlang0123/ComfyUI_Lam
Restart, find it in the lam category. Pure Python, no models. You can absolutely skip the pack's heavy README install (rars, TensorFlow pins, the works) - none of it is needed to evaluate an expression.
Common issues
Let's be straight about the elephant: this node runs arbitrary Python with whatever p0 you hand it, and it does so every queue. That's a power tool and a foot-gun. Errors are swallowed by default (you get "表达式错误" instead of a crash) unless you flip the error-stop toggle, so a silently-wrong result is the failure mode to watch for - put a print in your expression and check the console when a downstream node misbehaves.
Also remember inputs are positional: p0 is what you wired to the first input, and if you leave a gap, index alignment gets confusing fast. And in advanced mode, forgetting the result assignment is the single most common mistake - the node is explicit about it, but it still trips people every time.
The pack-level note as always: this is a Chinese-language pack with almost no community presence, its full install can wreck a clean Python environment, and if you uninstall it, delete ComfyUI/web/extensions/lam to stop the leftover popup.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| expression | STRING | — | |
| advanced | COMBO | disable | 2 options: enable, disable |
| errorEnd | COMBO | disable | 2 options: enable, disable |
| p0opt | * | — | |
| p1opt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| r0 | * | — |