On 2014-11-08, at 16:46 , Ionel Cristian Mărieș <cont...@ionelmc.ro> wrote: > Hello, > > In the current incarnation Pathlib is missing some key features I need in my > usecases. I want to contribute them but i'd like a bit of feedback on the new > api before jumping to implementation. > > The four things I need are: > > #1. A context manager for temporary files and dirs (that cleans everything up > on exit). Eg: > > with pathlib.TmpDir(suffix='', prefix='') as tmp: > assert isinstance(tmp, pathlib.Path) > > with pathlib.TmpFile(suffix='', prefix='') as tmp: > assert isinstance(tmp, pathlib.Path) >
Why would pathlib need to provide this when tempfile already does? with tempfile.NamedTemporaryFile(prefix='') as f: tmp = pathlib.Path(f.name) with tempfile.TemporaryDirectoryDirectory(prefix='') as d: tmp = pathlib.Path(d.name) On 2014-11-08, at 19:14 , Ryan Gonzalez <rym...@gmail.com> wrote: > +1 for the context manager ideas. Anything that is like a resource should be > available as a context manager. The current working directory is not "a resource" though it's a big piece of global state. I've been bitten by context-manager-unexpectedly-being-global-state in the past (with warnings.catch_warnings, I had not noticed the note about thread-safety). All in all, not a fan. _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com