[Python-ideas] Allow manual creation of DirEntry objects

Serhiy Storchaka storchaka at gmail.com
Wed Aug 17 14:40:40 EDT 2016


On 16.08.16 22:35, Brendan Moloney wrote:
> I have a bunch of functions that operate on DirEntry objects, typically
> doing some sort of filtering
> to select the paths I actually want to process. The overwhelming
> majority of the time these functions
> are going to be operating on DirEntry objects produced by the scandir
> function, but there are some
> cases where the user will be supplying the path themselves (for example,
> the root of a directory tree
> to process). In my current code base that uses the scandir package I
> just wrap these paths in a
> 'GenericDirEntry' object and then pass them through the filter functions
> the same as any results
> coming from the scandir function.

You can just create an object that duck-types DirEntry. See for example 
_DummyDirEntry in the os module.




More information about the Python-ideas mailing list