Is this a bug in os or can someone explain to me what's going on?
>>> os.path.realpath("C:")
'C:\\PythonApp'
>>> os.path.realpath("E:")
'E:\\'
My current directory is C:\PythonApp. It seems os defaults to the current directory if I give it an开发者_StackOverflow社区 unknown path name for something like os.listdir so why does it work for E and not C?
Compare what you get with:
os.path.realpath("C:\\")
Windows saves a "current directory" for each drive, and C: (without the slash) refers to that, not the root of the drive.
The python docs for os.path.join mention this:
Note that on Windows, since there is a current directory for each drive, os.path.join("c:", "foo") represents a path relative to the current directory on drive C: (c:foo), not c:\foo.
加载中,请稍侯......
精彩评论