【发布时间】:2011-12-16 07:49:48
【问题描述】:
os.path.commonprefix 的反义词是什么?我有两条路径,我想要不重叠的路径,例如:
>>> p1 = '/Users/foo/something'
>>> p2 = '/Users/foo/something/else/etc'
>>> print somefunction([p1, p2])
'/else/etc'
【问题讨论】:
os.path.commonprefix 的反义词是什么?我有两条路径,我想要不重叠的路径,例如:
>>> p1 = '/Users/foo/something'
>>> p2 = '/Users/foo/something/else/etc'
>>> print somefunction([p1, p2])
'/else/etc'
【问题讨论】:
>>> p1 = '/Users/foo/something'
>>> p2 = '/Users/foo/something/else/etc'
>>> os.path.relpath(p2, start=p1)
'else/etc'
正确答案是'else/etc' 而不是'/else/etc'。
如果您在 p1 并输入 cd /else/etc,您将不会进入 p2,而是在其他地方。
os.path.join(p1, 'else/etc') 再次给你 p2。
【讨论】: