Why os.path.isabs("/") on Windows returns True?

Steve Holden steve at holdenweb.com
Fri Feb 1 15:57:38 EST 2008


Giampaolo Rodola' wrote:
> Hi,
> I'm trying to solve a jython-related issue and I discovered a
> different behavior affecting os.path.isabs between CPython and Jython.
> 
> 
> C:\Python23>python.exe
> Python 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import os
>>>> os.path.isabs('/a')
> True
>>>> os.path.isabs('/')
> True
>>>> os.path
> <module 'ntpath' from 'C:\Python23\lib\ntpath.pyc'>
> 
> 
> C:\dist>jython.bat
> Jython 2.3a0 on java1.6.0_04
> Type "copyright", "credits" or "license" for more information.
>>>> import os
>>>> os.path.isabs('/a')
> False
>>>> os.path.isabs('/')
> False
>>>> os.path
> <module 'javapath' from 'C:\dist\Lib\javapath.py'>
> 
> 
> Is there a reason why "/" is considered an absolute pathname by
> CPython?

Personally I'd say it was Jython that was wrong. Anything beginning with 
a slash has to be absolute - "/" and "\" are treated as equivalent in 
most parts of the Windows environment.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list