Antoine Pitrou wrote:
<skip <at> pobox.com> writes:
If we add commonpath or commonpathprefix or pathprefix, or whatever, then find someplace to move the existing commonprefix function (maybe to the string module or as a class method of string objects?) then could we make a 2to3 fixer for this?
IMHO it's a bug, the py3k migration process needn't apply.
The current behaviour is exactly what one would need to implement bash-style tab completion , so I don't get why anyone is calling it "useless" or "obviously broken". It's brokenness isn't obvious at all to me - it just doesn't do what you want it to do.
Adding a separate function called "os.path.commonpath" with the behaviour Skip wants sounds like *exactly* the right answer to me.
entries = os.listdir() candidates = [e for e in entries if e.startswith(typed)] if len(candidates) > 1: tab_result = os.path.commonprefix(entries) elif candidates: tab_result = candidates else: tab_result = typed