Message141535
You can already get the better prefix using os.path, albeit less efficiently. Here's an example:
def commondirname(paths):
subpath = os.path.commonprefix(paths)
for path in paths:
if path == subpath:
return subpath
else:
return os.path.join(os.path.split(subpath)[0], "")
However, would it be better to implicitly normalize paths first rather than doing a character-by-character comparison? Here is an unoptimized demonstration of what I mean:
def commondirname(paths):
result = ""
for path in paths:
path = os.path.normcase(os.path.abspath(path))
if not result:
result = path
else:
while not path.startswith(result + os.path.sep):
result, _ = os.path.split(result)
if os.path.splitdrive(result)[1] == os.path.sep:
return result
return result |
|
Date |
User |
Action |
Args |
2011-08-01 21:22:00 | eric.snow | set | recipients:
+ eric.snow, loewis, ronaldoussoren, eric.smith, ezio.melotti, eric.araujo, r.david.murray, santoso.wijaya, Roman.Evstifeev |
2011-08-01 21:21:59 | eric.snow | set | messageid: <1312233719.86.0.899538092477.issue10395@psf.upfronthosting.co.za> |
2011-08-01 21:21:59 | eric.snow | link | issue10395 messages |
2011-08-01 21:21:59 | eric.snow | create | |
|