當前位置: 首頁>>代碼示例>>Python>>正文


Python ntpath.commonprefix方法代碼示例

本文整理匯總了Python中ntpath.commonprefix方法的典型用法代碼示例。如果您正苦於以下問題:Python ntpath.commonprefix方法的具體用法?Python ntpath.commonprefix怎麽用?Python ntpath.commonprefix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ntpath的用法示例。


在下文中一共展示了ntpath.commonprefix方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_commonprefix

# 需要導入模塊: import ntpath [as 別名]
# 或者: from ntpath import commonprefix [as 別名]
def test_commonprefix(self):
        tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
               "/home/swen")
        tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
               "\\home\\swen\\")
        tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
               "/home/swen/spam") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_ntpath.py

示例2: do_cd

# 需要導入模塊: import ntpath [as 別名]
# 或者: from ntpath import commonprefix [as 別名]
def do_cd(self, line):
        p = line.replace('/','\\')
        oldpwd = self.pwd
        newPath = ntpath.normpath(ntpath.join(self.pwd,p))
        if newPath == self.pwd:
            # Nothing changed
            return
        common = ntpath.commonprefix([newPath,oldpwd])

        if common == oldpwd:
            res = self.findPathName(ntpath.normpath(p))
        else:
            res = self.findPathName(newPath)

        if res is None:
            logging.error("Directory not found")
            self.pwd = oldpwd
            return 
        if res.isDirectory() == 0:
            logging.error("Not a directory!")
            self.pwd = oldpwd
            return
        else:
            self.currentINode = res
            self.do_ls('', False)
            self.pwd = ntpath.join(self.pwd,p)
            self.pwd = ntpath.normpath(self.pwd)
            self.prompt = self.pwd + '>' 
開發者ID:Coalfire-Research,項目名稱:Slackor,代碼行數:30,代碼來源:ntfs-read.py

示例3: do_cd

# 需要導入模塊: import ntpath [as 別名]
# 或者: from ntpath import commonprefix [as 別名]
def do_cd(self, line):
        p = string.replace(line,'/','\\')
        oldpwd = self.pwd
        newPath = ntpath.normpath(ntpath.join(self.pwd,p))
        if newPath == self.pwd:
            # Nothing changed
            return
        common = ntpath.commonprefix([newPath,oldpwd])

        if common == oldpwd:
            res = self.findPathName(ntpath.normpath(p))
        else:
            res = self.findPathName(newPath)

        if res is None:
            logging.error("Directory not found")
            self.pwd = oldpwd
            return 
        if res.isDirectory() == 0:
            logging.error("Not a directory!")
            self.pwd = oldpwd
            return
        else:
            self.currentINode = res
            self.do_ls('', False)
            self.pwd = ntpath.join(self.pwd,p)
            self.pwd = ntpath.normpath(self.pwd)
            self.prompt = self.pwd + '>' 
開發者ID:tholum,項目名稱:PiBunny,代碼行數:30,代碼來源:ntfs-read.py


注:本文中的ntpath.commonprefix方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。