Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why os.path.normpath does not remove the firsts //?

Tags:

python

os.path

Why the first // are not removed ?

The following code:

import os
os.path.normpath('//var//lib/')

returns

'//var/lib'

not

'/var/lib'

Here the definition:

normpath(path)
    '''Normalize path, eliminating double slashes, etc.'''
like image 329
user2652620 Avatar asked Sep 10 '18 14:09

user2652620


1 Answers

Because on Windows, there is a path ambiguity that python preserves.

//var/whatever could refer to a drive mounted as the name //var

OR

/var/whatever could refer to a local drive directory.

If python collapsed leading double slashes, you could unknowingly change a path to refer to a different location.

Another way of saying this is that //var and /var are fundamentally different paths, and python treats them differently. You should probably change your test case to reflect this.

like image 75
NateTheGrate Avatar answered Sep 19 '22 23:09

NateTheGrate