[Nuke] extracting a read node from group but still connected to actual connection

Well I know I can extract a node from group, but what I want is to keep the connection to the actual node in the group in my case its reformat node.

Secondly how can I implement without using with statement for Nuke 6.1v3 that has python 2.5?

anyway I did it myself, couldnt wait for anyone,


import nuke
import nukescripts

grp = nuke.toNode("Group1")
readNode=''
grp.begin()
nodes = nuke.allNodes()

for node in nodes:
    if node.Class() == 'Read':
        readNode = node.name()
        node.setSelected(True)
        reformat = node.dependent()[0]
        nuke.extractSelected()
        nuke.nodeCopy(nukescripts.cut_paste_file())
        nukescripts.node_delete()
        input = nuke.createNode("Input")
        reformat.setInput(0,input)
        grp.end()
        nuke.nodePaste(nukescripts.cut_paste_file())
        grp.setInput(0,nuke.toNode(readNode))

Will anyone please like to refactor the code aboveā€¦