[issue22387] Making tempfile.NamedTemporaryFile a class

Antony Lee report at bugs.python.org
Thu Sep 11 17:49:10 CEST 2014


Antony Lee added the comment:

Yes, but this will make the context-manager approach (with NamedTemporaryFile(closed=True): <do stuff>) unusable, because the underlying file object will be closed before calling __enter__.  I think the only reasonable way to implement this would be to have __enter__ return the file name (as for TemporaryDirectory), instead of the file object (which is reasonable because if I pass closed=True, it probably means all I care is that a file exists here for some other process to use!).
But, with the function approach, I cannot override __enter__.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22387>
_______________________________________


More information about the Python-bugs-list mailing list