Hi, I’m a new user of pyroot. Today I followed the description of TFile.
It says we can use with... as... to close TFile object automatically. But when I try to do this:
with ROOT.TFile(trackeff_path, "read") as f1:
h1 = f1.Get("heffratio")
I got
Traceback (most recent call last):
File "/publicfs/ucas/user/xzh6313/xzh/RKst/test_pyroot/test.py", line 7, in <module>
with ROOT.TFile(trackeff_path, "read") as f1:
AttributeError: __enter__
Looks like the __enter__ is called, but there is no such method?
Dear @Zhihao_Xu ,
Thank you for taking interest in the feature. I believe you found it by reading the TFile reference website at ROOT: TFile Class Reference .
Notice that there is a drop menu on the top-left part of the page through which you can choose the ROOT version you are using. In your case it’s 6.26, so the corresponding TFile reference would be at ROOT: TFile Class Reference . You will see that in this page the context manager feature is not mentioned, so it’s not available in that release.