[Tutor] How can isfile really do what it claims

Kent Johnson kent37 at tds.net
Fri Oct 26 15:36:06 CEST 2007


Sandip Bhattacharya wrote:
> $ ls -l /usr/lib/xulrunner/libfreebl3.so
> lrwxrwxrwx 1 root root 20 2007-10-20 12:13 /usr/lib/xulrunner/libfreebl3.so -> ../nss/libfreebl3.so
> 
> $ python
> Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32) 
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import os.path
>>>> os.path.isfile("/usr/lib/xulrunner/libfreebl3.so")
> True
>>>> print os.path.isfile.__doc__
> Test whether a path is a regular file
> 
> 
> Is this because isfile follows symlinks?

Yes; from the full docs:
isfile(  	path)
     Return True if path is an existing regular file. This follows 
symbolic links, so both islink() and isfile() can be true for the same 
path.

  If that is the case,
> how can I NOT make it do that?

def isfile(path):
     return not os.path.islink(path) and os.path.isfile(path)

Kent


More information about the Tutor mailing list