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

Eric V. Smith eric at trueblade.com
Fri May 3 01:53:19 CEST 2013


On 5/2/2013 7:48 PM, Christian Heimes wrote:

> Second step: get file type as string
> 
> A property stat_result.file_type that returns the type of the file as
> string makes checks like "s.is_dir or s.is_file" even easier:
> 
> s = os.stat(f)
> if s.file_type in {'reg', 'dir'}:
>    do_something()
> 
> We have to agree on a set of names, though. IMHO the abbreviations from
> stat.h are clear and distinct: {'fifo', 'chr', 'dir', 'blk', 'reg',
> 'lnk', 'sock', 'door', 'port'}. door and port are special file types on
> Solaris.

Seems like a use case for a flag-based enum!

-- 
Eric.



More information about the Python-ideas mailing list