[Python-Dev] Improvements for Pathlib

Ryan Gonzalez rymg19 at gmail.com
Sat Nov 8 19:14:27 CET 2014


+1 for the context manager ideas. Anything that is like a resource should
be available as a context manager.

On Sat, Nov 8, 2014 at 9:46 AM, Ionel Cristian Mărieș <contact at 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)
>
> #2. A context manager for changing working directory (that switches to the
> old cwd on exit). Eg:
>
> with path.cd():
>  assert os.getcwd() == path
>
> #
> ​3​
> . Shutil-like features:
>
> - copy_file
> - copy_dir (or copy_tree?)
> - copy (does copy_dir or copy_file depending on what the source is. How to
> handle symlinks?)
> - rm_dir (or rm_tree? Also, this would be required for the TmpDir path).
>
> #4. Zip files support. A specialised Path subclass that works inside a zip
> file. I'm ok having this as an external package but some discussion would
> be useful as I'd have to rely on pathlib internals.
>
> After some brief looking in the pathlib code it would appear the wise
> thing would be to have the zip path as the "drive" for the ZipPaths that
> refer to files inside the zip.
>
> I'm not sure where the best place is to store the internal zipfile object.
> Perhaps the accessor?
>
> Ideally the ZipFiles would work with the shtuil-like api just fine (or at
> least the readonly operations).
>
> Thanks,
> -- Ionel M.
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/rymg19%40gmail.com
>
>


-- 
Ryan
If anybody ever asks me why I prefer C++ to C, my answer will be simple:
"It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was
nul-terminated."
Personal reality distortion fields are immune to contradictory evidence. -
srean
Check out my website: http://kirbyfan64.github.io/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20141108/824694e3/attachment.html>


More information about the Python-Dev mailing list