python - Behaviour of "C:" with ntpath module -
cpython 3.4.1
>>> import ntpath p >>> p.isabs('c:') false >>> p.isabs('c:\\') true >>> p.join('c:', 'foo') 'c:foo' >>> p.join('c:\\', 'foo') 'c:\\foo' >>> what have expected
>>> import ntpath p >>> p.isabs('c:') true >>> p.join('c:', 'foo') 'c:\\foo' >>> # others same - why
c:not considered absolute,c:\is? - why
ntpath.join()not add slash betweenc:,foo?
why c: not considered absolute
because without additional slash means “the current directory of c: drive” (each drive having own current-directory in dos/windows):
c:\> cd windows c:\windows\> python python 2.7.11. (default, ...) >>> import os >>> os.listdir('c:') ['0.log', 'addins', 'apppatch', ... (this listing of c:\windows directory, not root c:\.)
why ntpath.join() not add slash between c: , foo?
maybe wanted file foo in c: drive's current directory.
practical upshot: because path not ‘absolute’ doesn't mean it's relative actual current working directory. similarly, \ absolute path, still depends on current working drive.
(and riscospath weirder; in general, posix platform on ‘absoluteness’ useful concept.)
Comments
Post a Comment