本文整理匯總了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