that second example is not the same as the first. Is a simple matter of reference counting. If you do:>>> ROOT.TFile.Open('data.root')then the only thing keeping the file alive, is the implicit variable underscore (’_’). Once that dies, the file’s refcount goes to zero, and it closes. Most importantly, it takes the data with it.
This one:>>> ROOT.TFile.Open('data.root').Get('data')is none, b/c ref-counting of the TFile goes to zero with only the result of Get() assigned to the implicit variable, which then promptly gets erased.
Either load the data and reset its directory, or copy it over, or simply keep the file alive for the duration you need the data. Your final example takes the last approach.