[Python-Dev] A wart which should have been repaired in 3.0?

Nick Coghlan ncoghlan at gmail.com
Sat Dec 27 21:44:00 CET 2008


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


More information about the Python-Dev mailing list