user2652620
user2652620

Reputation: 464

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

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.'''

Upvotes: 7

Views: 2519

Answers (1)

NateTheGrate
NateTheGrate

Reputation: 600

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.

Upvotes: 7

Related Questions