π Generic operation
Do math on anything, with a safe default
- First
- Second
- no_cache
- Default
- Flow
- Result
- Flow
The π 2 Boolean operation node is limited to booleans. The math expression nodes are limited to numbers. "π Generic operation" is FlowNodes' "fuck it, do it anyway" node: it takes any two values - no type restrictions - and applies an operation. Add, subtract, multiply, divide, index into a list or dict, or fetch an attribute. Its sockets are all * wildcards, so it swallows whatever you throw at it.
The operations
The Action dropdown offers six:
f + s,f - s,f * s,f / s- the four arithmetic operations, applied to whateverFirstandSecondhappen to be. With numbers this is the math expression node. With strings,f + sconcatenates andf * srepeats. With lists,f + sconcatenates. That's the point: the operation is whatever Python makes of your operands.f[s]- index. IfFirstis a list,Secondis the index (returns the item if in range,0 <= s < len, otherwise the Default). IfFirstis a dict,Secondis the key (returns the value if present, else Default).getattr(f, s)- fetch an attribute by name from the object.
The f[s] and getattr cases have a third, optional input: Default. It's the fallback value - what you get back when the index is out of range, the key is missing, or the attribute doesn't exist. Without it, those cases return None. That's the safety valve that makes the node usable: you can read a dict key that might not exist without crashing the whole graph.
How it reads
So for the f[s] action: First is the container, Second is the index/key, and you get the value out of Result. For arithmetic, First and Second are just the two operands. All three inputs are required except Default and Flow.
The no_cache input is the same dummy socket as every other FlowNodes function node - it forces re-execution every run so you don't get stale results. And there's a Flow input/output so you can sequence operations (this matters a lot when you chain into the write-variant of this node, where order is everything).
What it's actually for
This is the node you reach for when a specific value sits inside a larger structure. You have a dict from the persistent dict or from Stack parameters, and you want one key out of it. You have a list from Create batch and you want item 3. You built a small object and need its attribute. Instead of opening Execute Python for a one-liner, Generic operation does it inline, and the Default fallback means missing keys degrade gracefully.
It pairs naturally with the write variant (Generic operation (write)): read with this node, mutate with the other.
Install
Part of the FlowNodes pack:
cd ComfyUI/custom_nodes
git clone https://github.com/gitmylo/FlowNodes
# restart ComfyUI
or ComfyUI Manager β search FlowNodes β install. No Python dependencies, no models.
Troubleshooting
f[s]returns None on a list that has the item - the code only accepts non-negative indexes (0 <= s < len). A negative index returns Default/None instead of Python's from-the-end indexing.- Arithmetic on mismatched types errors -
f + swhere one operand is a string and the other an int raisesTypeError; that's Python, not a bug. Convert first. - Missing key crashes instead of returning Default - the Default only applies inside the
f[s]/getattractions, and only if you actually connected it. For plain arithmetic there's no fallback logic at all. - Result seems stale - check the no_cache socket is present; without it, caching can skip this node on repeat runs.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| Action | COMBO | 6 options: f + s, f - s, f * s, f / s, f[s], getattr(f, s) | |
| First | * | β | |
| Second | * | β | |
| no_cache | NO_CACHE | β | |
| Defaultopt | * | β | |
| Flowopt | FLOW | β |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| Result | * | β |
| Flow | FLOW | β |