[issue25707] Add the close method for ElementTree.iterparse() object

Stefan Behnel report at bugs.python.org
Thu May 2 04:32:19 EDT 2019


Stefan Behnel <stefan_ml at behnel.de> added the comment:

Ok, I think it's reasonable to make the resource management explicit for the specific case of letting iterparse() open the file. That suggests that there should also be context manager support, given that safe usages would often involve a try-finally.

Since it might not always be obvious for users when they need to close the iterator or not, I would also suggest to not let it raise an error on a double-close, i.e. if .close() was already called or the iterator was already exhausted (and the file closed automatically), calling .close() should just do nothing.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue25707>
_______________________________________


More information about the Python-bugs-list mailing list