[Python-ideas] Enhanced stat_result objects (was: Better stdlib support for Path objects)
Tim Delaney
timothy.c.delaney at gmail.com
Tue Oct 7 22:41:54 CEST 2014
On 8 October 2014 01:08, Paul Moore <p.f.moore at gmail.com> wrote:
> I would find it really useful if stat_result objects supported the
> various is_XXX methods from pathlib. Then I could write code like:
>
> p = Path(...)
> st = p.stat()
> if st.exists():
> ...
> elif st.is_dir():
> ...
>
> which explicitly shows that stat is only called once, but doesn't
> involve verbose and ugly code like
>
> if stat.S_ISDIR(st.st_mode):
> ...
>
> Would this be a worthwhile addition?
>
+1
Then Path, DirEntry (from scandir) and stat_result objects would all
support the same API.
DirEntry.is_dir() and .is_file() methods have an optional follow_symlinks
parameter - I'm thinking Path should follow suit. Obviously stat_result
would not.
Tim Delaney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141008/febd7526/attachment.html>
More information about the Python-ideas
mailing list