Change file format of File Output node in python (from PNG to OpenEXR)

Hello,

Ok so this is a relatively short question but I am struggling with it for some time now.
If you have a File Output node and select it in the Node Editor window, under Properties you can change
the file format from PNG to OpenEXR.
The only thing I want to accomplish is to do this in python script.
If I change it manually, the Info window gives me the following:

bpy.data.node_groups["Compositing Nodetree"].(null) = 'OPEN_EXR'

which doesn’t seem to work for me (even if I select the node and set it active, as I would do using the Blender GUI)
Here is the code snippet how I set up my nodes in python


render_layers_node = tree.nodes.new(type='CompositorNodeRLayers')


composite_node = tree.nodes.new(type='CompositorNodeComposite')


depth_o_node = tree.nodes.new(type='CompositorNodeOutputFile')
normal_o_node = tree.nodes.new(type='CompositorNodeOutputFile')


#delete standard socket and add new one
#Images are called depth_#step
bpy.context.area.type = 'NODE_EDITOR'
depth_o_node.select = True
tree.nodes.active = depth_o_node


bpy.ops.node.output_file_remove_active_socket()


bpy.ops.node.output_file_add_socket(file_path="depth_")


depth_o_node.select = False


#same for normal output node
#delete standard socket and add new one
#Images are called normal_#step
bpy.context.area.type = 'NODE_EDITOR'
normal_o_node.select = True
tree.nodes.active = normal_o_node


bpy.ops.node.output_file_remove_active_socket()


bpy.ops.node.output_file_add_socket(file_path="normal_")


normal_o_node.select = False


#connect nodes!
links = tree.links


link = links.new(render_layers_node.outputs[0], composite_node.inputs[0])
link2 = links.new(render_layers_node.outputs[2], depth_o_node.inputs[0])
link3 = links.new(render_layers_node.outputs[3], normal_o_node.inputs[0])

Now the socket of depth_o_node.inputs[0] (and normal_o_node) should have the file format OpenEXR.

Thanks in advance for any answer

Like this:

depth_o_node.format.file_format = "OPEN_EXR"

I would also stay away from using ops as much as possible.

Thank you so much, this was exactly what I was looking for!
Thanks for the tip, I guess there are more elegant way to achieve this :slight_smile: