ROOTPY. tree

Dear Root Wizards,

I have a problem with ROOTPY. I just started using Python.
I want to open an existing root file with defined tree and add now entries to that tree. However, every time I reopen the file and add new events, they create their own tree in a given file. As a result I have one root file with many trees.
This is my code (part where I open a file , add events and saves everything):

f = root_open(‘test.root’, ‘update’)
tree = f.test
for event in tree:
print event.xpos
for i in range (0, num):
tree.idd = 2
tree.number_of_events = num
tree.event_number = events_numbers[i]
tree.xpos = xs[i]
tree.ypos = ys[i]
tree.integral = peak_flux[i]
tree.fill()
tree.write()
f.Close()

What happens if you use instead?

I’ve tried that already.

I have an error:

Traceback (most recent call last):
File “program.py”, line 148, in
tree.Write(TObject.kWriteDelete)
NameError: name ‘TObject’ is not defined

Any other ideas?

Call first:

from ROOT import TObject

Thank you!

I did:
from ROOT import TObject
free.Write("",TObject.kWriteDelete)
and it works.