Files in unix and windows

Jeff Epler jepler at unpythonic.net
Sat Aug 21 09:05:31 EDT 2004


Which extra (back)slashes do you mean?  Do you mean that os.path.abspath
strips the trailing separator characters from its argument?

>>> os.path.abspath("../../../../etc/")
'/etc'
>>> os.path.normpath("./")
'.'

This behavior doesn't seem to be specifically documented.

If preserving the trailing '/' when present is important, you can easily
get this behavior using os.path.abspath:
    def myabspath(p):
        hadsep = p and p[-1] in (os.sep, os.altsep)
        p = os.path.abspath(p)
        if hadsep: p = p + os.sep
        return p

>>> myabspath('../../../../../etc/')
'/etc/'
>>> myabspath('../../../../../etc')
'/etc'

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040821/ac66c53f/attachment.sig>


More information about the Python-list mailing list