Python C API: omitted variable assignment causes unexpected behavior

When using python with pyroot (the python interface in the CERN data analysis package called ROOT ), I came across the following weird behavior:

print ROOT.TFile(fname).GetListOfKeys()

outputs Nonewhile seemingly semantically equivalent code

f=ROOT.TFile(fname)
print f.GetListOfKeys()

prints the expected <ROOT.THashList object ("THashList") at 0x13f0fa0>.

Although this is hardly the first error that I encountered while working with ROOT, this time I am very puzzled that python allows this error to occur.

I believe that for some reason, the reference counter for the TFile object is wrong in the first example and that it is deleted before GetListOfKeys is actually called. (After installing ROOT.TFile.__del__for some print command, this is really what happens.)

, , ROOT.TFile(fname), GetListOfKeys() TFile . , , , GetListOfKeys() .

- , ?

python del , ? gc.disable(), . , - ?

+4

All Articles