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 
  1. why c: not considered absolute, c:\ is?
  2. why ntpath.join() not add slash between c: , 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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -