[Python-ideas] Extend the os.stat() result objects with methods like isfile() and isdir()

Pieter Nagel pieter at nagel.co.za
Fri May 3 06:55:10 CEST 2013


On Fri, 2013-05-03 at 01:48 +0200, Christian Heimes wrote:

> stat_result.isfile() or stat_result.isdir() don't have to be functions.
> The feature can also be implemented with properties, e.g.
> stat_result.is_file. Or can somebody think of a reason why they have to
> be callables anymore?

I lean towards keeping it a function call for symmetry with
os.path.isfile() and friends.

> s = os.stat(f)
> if s.file_type in {'reg', 'dir'}:
>    do_something()

If something like this were to be done, I wouldn't like doing it with
magic string constants. I agree that the new enums would be better to do
this with.

This also raises the issue of whether, if there is a file type
enumeration on the stat() result, whether there should be a symmetric
os.path.file_type(f) call added.

But I'll remain open to these kinds of discussions as the PEP is
discussed, It seems there's enough support for the basic principle for
me to go and work on the PEP.
-- 
Pieter Nagel





More information about the Python-ideas mailing list