本文整理汇总了Python中posixpath.commonprefix方法的典型用法代码示例。如果您正苦于以下问题:Python posixpath.commonprefix方法的具体用法?Python posixpath.commonprefix怎么用?Python posixpath.commonprefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类posixpath
的用法示例。
在下文中一共展示了posixpath.commonprefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_commonprefix
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import commonprefix [as 别名]
def test_commonprefix(self):
self.assertEqual(
posixpath.commonprefix([]),
""
)
self.assertEqual(
posixpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"]),
"/home/swen"
)
self.assertEqual(
posixpath.commonprefix(["/home/swen/spam", "/home/swen/eggs"]),
"/home/swen/"
)
self.assertEqual(
posixpath.commonprefix(["/home/swen/spam", "/home/swen/spam"]),
"/home/swen/spam"
)
示例2: is_suburi
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import commonprefix [as 别名]
def is_suburi(self, base, test):
"""Check if test is below base in a URI tree
Both args must be URIs in reduced form.
"""
if base == test:
return 1
if base[0] != test[0]:
return 0
common = posixpath.commonprefix((base[1], test[1]))
if len(common) == len(base[1]):
return 1
return 0
示例3: is_suburi
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import commonprefix [as 别名]
def is_suburi(self, base, test):
"""Check if test is below base in a URI tree
Both args must be URIs in reduced form.
"""
if base == test:
return True
if base[0] != test[0]:
return False
common = posixpath.commonprefix((base[1], test[1]))
if len(common) == len(base[1]):
return True
return False