This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.exists should use os.access when possible
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: donut, loewis
Priority: normal Keywords: patch

Created on 2003-08-10 13:03 by donut, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
posixpath_exists_use_access.patch donut, 2003-08-10 13:03 patch for posixpath.py
Messages (2)
msg44428 - (view) Author: Matthew Mueller (donut) Date: 2003-08-10 13:03
Compared to os.access, os.stat is very slow (probably
due constructing to the stat object it returns).  

Therefore, os.path.exists should use os.access instead,
when possible.  (posixpath, I guess ntpath too.) 
(I didn't include a patch for ntpath since I can't test
it.)

As a bonus, the code is cleaner too. :)

examples:
> touch file_that_exists

> python2.3 timeit.py -s "from os.path import exists"
"exists('file_that_exists')"                          
                                                      
               
100000 loops, best of 3: 15.6 usec per loop

> python2.3 timeit.py -s "from newposixpath import
exists" "exists('file_that_exists')"                  
                                     
100000 loops, best of 3: 6.17 usec per loop

> python2.3 timeit.py -s "from os.path import exists"
"exists('file_that_does_not_exist')"                  
                                                      
                 
10000 loops, best of 3: 48.9 usec per loop

> python2.3 timeit.py -s "from newposixpath import
exists" "exists('file_that_does_not_exist')"
100000 loops, best of 3: 6.37 usec per loop
msg44429 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-08-31 16:55
Logged In: YES 
user_id=21627

This patch is incorrect (rejecting it), see

http://mail.python.org/pipermail/python-dev/2002-June/025511.html
History
Date User Action Args
2022-04-10 16:10:34adminsetgithub: 39041
2003-08-10 13:03:35donutcreate