-
Notifications
You must be signed in to change notification settings - Fork 67
uproot.open should implement support for with statement #4
Comments
Of course! Sorry I overlooked that. In #6, I added >>> import uproot
>>> with uproot.open("tests/Zmumu.root") as tree:
... print tree.contents
...
{'events;1': 'TTree'}
>>> tree["events"]
<TTree 'events' len=2304 at 0x7e564c3ca6d0> Arguably, you could say that one should get objects from the file only within the (Memory maps are important for performance: to be able to deal with the amount of seeking the ROOT format requires and to allow parallel reading.) On the other hand, I do have a non-memory mapped option (that I'm thinking of removing), as well as an XRootD option. I put a >>> with uproot.open("tests/Zmumu.root", memmap=False) as tree:
... print tree.contents
...
{'events;1': 'TTree'}
>>> tree["events"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "uproot/rootio.py", line 149, in __getitem__
return self.get(name)
File "uproot/rootio.py", line 179, in get
return self.dir.get(name, cycle)
File "uproot/rootio.py", line 241, in get
out = out.keys.get(n, cycle)
File "uproot/rootio.py", line 312, in get
return key.get()
File "uproot/rootio.py", line 366, in get
out = Deserialized.classes[self.classname](self._filewalker, self._walker)
File "uproot/tree.py", line 67, in __init__
vers, bcnt = walker.readversion()
File "uproot/_walker/lazyarraywalker.py", line 96, in readversion
if not self._evaluated: self._evaluate()
File "uproot/_walker/lazyarraywalker.py", line 37, in _evaluate
walker.startcontext()
File "uproot/_walker/localfilewalker.py", line 61, in startcontext
self.file.seek(self.index)
ValueError: I/O operation on closed file Good. |
…to-methods Move conversion code to methods
In python almost all open operations can be supported in with statement. You need to implement open with enter and exit method to do that. The following snippet
produces the following traceback
The text was updated successfully, but these errors were encountered: