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 [1], 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. Cheers, Nick. * 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[0] else: tab_result = typed -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia ---------------------------------------------------------------
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4