# How to unlink a node with python?

Having a node, I want to unlink it. My current approach is to clear all links from a desired NodeSocket:

my_node.inputs[0].links.clear()


I get a:

AttributeError: 'tuple' object has no attribute 'clear'


I would think that 'links' is a NodeLinks structure, which would have 'clear()' and 'remove()', but apparently no? I also can not simply del my_node.inputs[0].links[0].

One approach I got working is:

for l in my_node.inputs[0].links:


but is there a simpler way? Should one of my previous attempts work?

The my_node.inputs[0] is a node Socket type, and the my_node.inputs[0].links is a read only list of links from this socket, so your first attempt won't work, and you have found the correct way, which is deleting the link from node_tree.links as follows:

 # remove only the desired link


output = my_node1.outputs[0]

Also you can check for the connected node: if l.to_node == my_node2: