Reputation: 464
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
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