473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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?
Feb 1 '08 #1
9 2115
On 2008-02-01, Giampaolo Rodola' <gn****@gmail.comwrote:
I'm trying to solve a jython-related issue and I discovered a
different behavior affecting os.path.isabs between CPython and
Jython.
[...]
Is there a reason why "/" is considered an absolute pathname
by CPython?
Sure seems like a bug to me. On Unix, "/" is an absolute path.
On windows, "/" is relative to the current device.

--
Grant Edwards grante Yow! I hope something GOOD
at came in the mail today so
visi.com I have a REASON to live!!
Feb 1 '08 #2
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/

Feb 1 '08 #3
On Feb 1, 9:55*pm, Grant Edwards <gra...@visi.comwrote:
On 2008-02-01, Giampaolo Rodola' <gne...@gmail.comwrote:
I'm trying to solve a jython-related issue and I discovered a
different behavior affecting os.path.isabs between CPython and
Jython.

[...]
Is there a reason why "/" is considered an absolute pathname
by CPython?

Sure seems like a bug to me. *On Unix, "/" is an absolute path.
On windows, "/" is relative to the current device.
If you mean "the current drive letter" it's not actually true since "\
\" is used for that:
>>os.getcwd()
'C:\\Python25'
>>os.path.realpath('\\')
'C:\\'
>>>

Feb 1 '08 #4
On 2008-02-01, Steve Holden <st***@holdenweb.comwrote:
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.
I guess it depends on your definition of "absolute". In my
mind, it means that it always refers to the same location
regardless of the CWD.

That's not true for the paths starting with "/" on Windows. If
CWD is "C:/foo/bar" then "/" refers to a different location
than it does if CWD is "D:/whatever".

--
Grant Edwards grante Yow! I have accepted
at Provolone into my life!
visi.com
Feb 1 '08 #5
On 2008-02-01, Giampaolo Rodola' <gn****@gmail.comwrote:
On Feb 1, 9:55*pm, Grant Edwards <gra...@visi.comwrote:
>On 2008-02-01, Giampaolo Rodola' <gne...@gmail.comwrote:
I'm trying to solve a jython-related issue and I discovered a
different behavior affecting os.path.isabs between CPython and
Jython.

[...]
Is there a reason why "/" is considered an absolute pathname
by CPython?

Sure seems like a bug to me. *On Unix, "/" is an absolute path.
On windows, "/" is relative to the current device.

If you mean "the current drive letter" it's not actually true
since "\ \" is used for that:
>os.getcwd()
'C:\\Python25'
>os.path.realpath('\\')
'C:\\'
>>
You'll get identical results with "/".

--
Grant Edwards grante Yow! I always have fun
at because I'm out of my
visi.com mind!!!
Feb 1 '08 #6
On Feb 1, 10:34*pm, Grant Edwards <gra...@visi.comwrote:
On 2008-02-01, Giampaolo Rodola' <gne...@gmail.comwrote:


On Feb 1, 9:55*pm, Grant Edwards <gra...@visi.comwrote:
On 2008-02-01, Giampaolo Rodola' <gne...@gmail.comwrote:
I'm trying to solve a jython-related issue and I discovered a
different behavior affecting os.path.isabs between CPython and
Jython.
[...]
Is there a reason why "/" is considered an absolute pathname
by CPython?
Sure seems like a bug to me. *On Unix, "/" is an absolute path.
On windows, "/" is relative to the current device.
If you mean "the current drive letter" it's not actually true
since "\ \" is used for that:
>>os.getcwd()
*'C:\\Python25'
>>os.path.realpath('\\')
*'C:\\'

You'll get identical results with "/".
Didn't know that. And this is another strange thing since Windows
shell does not behave like that:

C:\Python25>cd /

C:\Python25>cd \

C:\>
Feb 1 '08 #7
On 2008-02-01, Giampaolo Rodola' <gn****@gmail.comwrote:
>Sure seems like a bug to me. *On Unix, "/" is an absolute path.
On windows, "/" is relative to the current device.
If you mean "the current drive letter" it's not actually true
since "\ \" is used for that:
>>os.getcwd()
*'C:\\Python25'
os.path.realpath('\\')
*'C:\\'

You'll get identical results with "/".

Didn't know that. And this is another strange thing since Windows
shell does not behave like that:

C:\Python25>cd /

C:\Python25>cd \
True, but we're not talking about how Windows' shell (cmd.exe)
parses its command line.

The Windows system calls (at least at the library level) are
perfectly happy with "/" as a directory separator and always
have been. MS-DOS system calls before that were also happy
with "/" as a directory separator. Back in the early days of
MS-DOS, you could even tell command.com to use '-' as an option
flag instead of '/', then you could use properly spelled paths
at the DOS shell also. [I've read that 32-bit cmd.exe has lost
that feature. I don't really know, I always use bash instead.]

--
Grant Edwards grante Yow! I just had a NOSE
at JOB!!
visi.com
Feb 1 '08 #8
Grant Edwards <gr****@visi.comwrote:
>I guess it depends on your definition of "absolute". In my
mind, it means that it always refers to the same location
regardless of the CWD.
Strictly speaking "/" refers to same location regardless of the current
working directory (CWD) on Windows. It's only relative with respect
of the current drive, which Windows considers something different than
the current working directory. On the other hand Python on Window
does for the most part hide this, treating the current drive as being
part of current working directory, so it's strange the isabs() behaves
differently.

Ross Ridge

--
l/ // Ross Ridge -- The Great HTMU
[oo][oo] rr****@csclub.uwaterloo.ca
-()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
db //
Feb 2 '08 #9
Is there a reason why "/" is considered an absolute pathname by
CPython?
Yes: it tests whether a path is absolute on the current volume.
Use the source, Luke.

Regards,
Martin
Feb 2 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Alpha | last post by:
I use FolderBrowserDlg for user to select a folder path then store it in the sql table. I then retrieve it to concatenate in a sqlcommand text to retrive files from that directory but it won't...
1
by: ±ù÷¢ | last post by:
I have a standard vb crystal reports viewer control on a web form with just the one simple report bound to it. when I run the project I get the following error: ACCESS TO THE PATH...
0
by: Nicola George | last post by:
Hi all, I hope someone can help me as I'm going a bit metal with this problem. I have a project in ASP.NET, within this project I have Crystal Report called Catalogue. On an asp page I have a...
1
by: Winterminute | last post by:
If I try to make any changes to the ASP.NET Portal Starter kit it fails with an access denied error. This was working when I left last week and is failing today. I don't remember changing...
5
by: Tom Vogel | last post by:
Creating a subfolder within my ASP.NET application folder fails with the above error, but only at my hosting provider. The command: Directory.CreateDirectory(path) Path is set to...
1
by: Michiel Schaeverbeke | last post by:
Hi, I'm trying to reach an xml file from within a web application. The file is physically on a different server. When I try to reach it using \\servername\path\ style, I get the error...
9
by: Clinton Frankland | last post by:
Hi, On a Windows 2000 Server when attempting to use System.IO.Directory.CreateDirectory(string.concat(Server.MapPath(""), "\verify")) I receive a System.IO.DirectoryNotFoundException error:...
3
by: Eckhard Schwabe | last post by:
I only found one post on Google where someone mentions the same problem with a DataSet: XmlDataReader in .Net 1.1 can not read XML files from a path which contains "%10" or "%3f". code to...
1
by: jalupinu | last post by:
My OS is Winxp SP2 and the software I am having trouble with is Maximizer 9.5 Enterprise. It has a Web Portal feature that i am trying to use and followed the instructions to set it up however I keep...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.