Python os.path 模块,rfind() 实例源码

我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用os.path.rfind()

项目:jumpscale_portal    作者:jumpscale7    | 项目源码 | 文件源码
def __mimetype(self, path):
        """Detect mimetype of file"""
        mime = mimetypes.guess_type(path)[0] or 'unknown'
        ext = path[path.rfind('.') + 1:]

        if mime == 'unknown' and ('.' + ext) in mimetypes.types_map:
            mime = mimetypes.types_map['.' + ext]

        if mime == 'text/plain' and ext == 'pl':
            mime = self._mimeType[ext]

        if mime == 'application/vnd.ms-office' and ext == 'doc':
            mime = self._mimeType[ext]

        if mime == 'unknown':
            if os.path.basename(path) in ['README', 'ChangeLog']:
                mime = 'text/plain'
            else:
                if ext in self._mimeType:
                    mime = self._mimeType[ext]

        # self.__debug('mime ' + os.path.basename(path), ext + ' ' + mime)
        return mime
项目:myDotFiles    作者:GuidoFe    | 项目源码 | 文件源码
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path)
项目:SegmentationService    作者:jingchaoluan    | 项目源码 | 文件源码
def pyconstruct(s):
    """Constructs a Python object from a constructor, an expression
    of the form x.y.z.name(args).  This ensures that x.y.z is imported.
    In the future, more forms of syntax may be accepted."""
    env = {}
    if "(" not in s:
        s += "()"
    path = s[:s.find("(")]
    if "." in path:
        module = path[:path.rfind(".")]
        print("import", module)
        exec "import "+module in env
    return eval(s,env)
项目:arch-setup-i3wm    作者:i-PUSH    | 项目源码 | 文件源码
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path)
项目:paragraph2vec    作者:thunlp    | 项目源码 | 文件源码
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId)
项目:paragraph2vec    作者:thunlp    | 项目源码 | 文件源码
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId)
项目:itdepends    作者:zebmason    | 项目源码 | 文件源码
def GetPath(self, path):
        if path in self.tree:
            return self.tree[path]
        i = path.rfind('/')
        if i == -1:
            parent = self.tree['']
            branch = Branch(path, parent)
        else:
            parent = self.GetPath(path[:i])
            branch = Branch(path[i+1:], parent)
        parent.Add(branch)
        self.tree[path] = branch
        return branch
项目:topical_word_embeddings    作者:thunlp    | 项目源码 | 文件源码
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId)
项目:topical_word_embeddings    作者:thunlp    | 项目源码 | 文件源码
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId)
项目:topical_word_embeddings    作者:thunlp    | 项目源码 | 文件源码
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId)
项目:topical_word_embeddings    作者:thunlp    | 项目源码 | 文件源码
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId)
项目:topical_word_embeddings    作者:thunlp    | 项目源码 | 文件源码
def idFromDir(self, path):
        assert len(path) > len(self.baseDir)
        intId = path[1 + path.rfind('#') : ]
        pathId = path[len(self.baseDir) + 1 : ]
        return (intId, pathId)
项目:dotfiles    作者:maotora    | 项目源码 | 文件源码
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path)
项目:my-dots    作者:maotora    | 项目源码 | 文件源码
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path)
项目:anchorhub    作者:samjabrahams    | 项目源码 | 文件源码
def test_get_anchorhub_path_directory():
    """
    getanchorhubpath.py: Make sure directory given is named 'anchorhub'
    """
    path = get_anchorhub_path()
    dir = path[path.rfind(get_path_separator()) + 1:]
    assert dir == 'anchorhub'
项目:dotfiles    作者:leolanavo    | 项目源码 | 文件源码
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path)
项目:BinarizationService    作者:jingchaoluan    | 项目源码 | 文件源码
def pyconstruct(s):
    """Constructs a Python object from a constructor, an expression
    of the form x.y.z.name(args).  This ensures that x.y.z is imported.
    In the future, more forms of syntax may be accepted."""
    env = {}
    if "(" not in s:
        s += "()"
    path = s[:s.find("(")]
    if "." in path:
        module = path[:path.rfind(".")]
        print("import", module)
        exec "import "+module in env
    return eval(s,env)
项目:deep_ocr    作者:JinpengLI    | 项目源码 | 文件源码
def pyconstruct(s):
    """Constructs a Python object from a constructor, an expression
    of the form x.y.z.name(args).  This ensures that x.y.z is imported.
    In the future, more forms of syntax may be accepted."""
    env = {}
    if "(" not in s:
        s += "()"
    path = s[:s.find("(")]
    if "." in path:
        module = path[:path.rfind(".")]
        print("import", module)
        exec "import "+module in env
    return eval(s,env)
项目:plasma    作者:jnkh    | 项目源码 | 文件源码
def clean_shot_list(self,path):
        data = loadtxt(path)
        ending_idx = path.rfind('.')
        new_path = append_to_filename(path,'_clear')
        if len(shape(data)) < 2:
            #nondisruptive
            nd_times = -1.0*ones_like(data)
            data_two_column = vstack((data,nd_times)).transpose()
            savetxt(new_path,data_two_column,fmt = '%d %f')
            print('created new file: {}'.format(new_path))
            print('deleting old file: {}'.format(path))
            os.remove(path)
项目:plasma    作者:jnkh    | 项目源码 | 文件源码
def append_to_filename(path,to_append):
    ending_idx = path.rfind('.')
    new_path = path[:ending_idx] + to_append + path[ending_idx:]
    return new_path
项目:dotfiles    作者:ildyria    | 项目源码 | 文件源码
def execute(self):
        cf = self.fm.thisfile
        path = cf.relative_path.replace("%", "%%")
        if path.find('.') != 0 and path.rfind('.') != -1 and not cf.is_directory:
            self.fm.open_console('rename ' + path, position=(7 + path.rfind('.')))
        else:
            self.fm.open_console('rename ' + path)
项目:jumpscale_portal    作者:jumpscale7    | 项目源码 | 文件源码
def __uniqueName(self, path, copy = ' copy'):
        """Generate unique name for file copied file"""
        curDir = os.path.dirname(path)
        curName = os.path.basename(path)
        lastDot = curName.rfind('.')
        ext = newName = ''

        if not os.path.isdir(path) and re.search(r'\..{3}\.(gz|bz|bz2)$', curName):
            pos = -7
            if curName[-1:] == '2':
                pos -= 1
            ext = curName[pos:]
            oldName = curName[0:pos]
            newName = oldName + copy
        elif os.path.isdir(path) or lastDot <= 0:
            oldName = curName
            newName = oldName + copy
            pass
        else:
            ext = curName[lastDot:]
            oldName = curName[0:lastDot]
            newName = oldName + copy

        pos = 0

        if oldName[-len(copy):] == copy:
            newName = oldName
        elif re.search(r'' + copy +'\s\d+$', oldName):
            pos = oldName.rfind(copy) + len(copy)
            newName = oldName[0:pos]
        else:
            newPath = os.path.join(curDir, newName + ext)
            if not os.path.exists(newPath):
                return newPath

        # if we are here then copy already exists or making copy of copy
        # we will make new indexed copy *black magic*
        idx = 1
        if pos > 0: idx = int(oldName[pos:])
        while True:
            idx += 1
            newNameExt = newName + ' ' + str(idx) + ext
            newPath = os.path.join(curDir, newNameExt)
            if not os.path.exists(newPath):
                return newPath
            # if idx >= 1000: break # possible loop

        return