[Python-Dev] Issue 11406: adding os.scandir(), a directory iterator returning stat-like info

Ben Hoyt benhoyt at gmail.com
Mon May 13 02:24:16 CEST 2013


On Mon, May 13, 2013 at 12:11 PM, Victor Stinner
<victor.stinner at gmail.com> wrote:
> 2013/5/13 Ben Hoyt <benhoyt at gmail.com>:
>> class DirEntry:
>> ...
>>     def lstat(self):
>>         if self._lstat is None:
>>             self._lstat = os.lstat(os.path.join(self._path, self.name))
>>         return self._lstat
>> ...
>
> You need to provide a way to invalidate the stat cache,
> DirEntry.clearcache() for example.

Hmm, I'm not sure why, as the stat result is cached on the DirEntry
instance (not the class). If you don't want the cached version, just
call os.stat() yourself, or throw away the DirEntry instance. DirEntry
instances would just be used for dealing with scandir() results.

-Ben


More information about the Python-Dev mailing list