[Python-Dev] Re: Adding 'lexists()' to os.path

Tino Lange tino.lange at isg.de
Sun Aug 22 16:25:24 CEST 2004


Paul Moore wrote:
> 
>>I was just reviewing the patch at http://python.org/sf/941486, which proposes
>>adding a new 'lexists()' function to os.path. This function would return True
>>for dangling symbolic links, unlike os.path.exists() which returns False. One
>>could use 'os.path.islink(path) or os.path.exists()' as well, but that's two
>>stat calls instead of one.
> 
> 
> As an alternative, would there be any value in cacheing the last stat
> result? In a sequence like this, with multiple calls for the same
> argument, many stat calls would be replaced by one. And it's likely
> that the checking overhead on cache misses would be minimal compared
> to the cost of the stat call, so it's an overall win.

Hi Paul,

you will never know how long the cached result is true. Files on disk
can change outside your python script....

I doubt that we can find a good expire time for the caching? Someone
will come up with an application in which this caching will give wrong
results...

If someone knows what he does and likes efficient programming he can
cache the result of os.stat() himself and work with that. (Like this
lexists() function is programmed internally...)

My personal opinion:
+0.5 for os.lexists() [it's useful, but we can also live without it...]
-1 for a stat cache in os.*.

Cheers,

Tino




More information about the Python-Dev mailing list