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


Python path.rsplit方法代碼示例

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


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

示例1: _parse_open_arg

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def _parse_open_arg(load_arg: str) -> Tuple[NullableStr, NullableStr, NullableStr, NullableStr]:
    """
    Parse string argument ``DS := "DS_NAME=DS_ID[,DATE1[,DATE2]]"`` and return tuple DS_NAME,DS_ID,DATE1,DATE2.

    :param load_arg: The DS string argument
    :return: The tuple DS_NAME,DS_ID,DATE1,DATE2
    """
    ds_name_and_ds_id = load_arg.split('=', maxsplit=1)
    ds_name, ds_id = ds_name_and_ds_id if len(ds_name_and_ds_id) == 2 else (None, load_arg)
    ds_id_and_date_range = ds_id.rsplit(',', maxsplit=2)
    if len(ds_id_and_date_range) == 3:
        ds_id, date1, date2 = ds_id_and_date_range
    elif len(ds_id_and_date_range) == 2:
        ds_id, date1, date2 = ds_id_and_date_range[0], ds_id_and_date_range[1], None
    else:
        ds_id, date1, date2 = ds_id_and_date_range[0], None, None
    return ds_name if ds_name else None, ds_id if ds_id else None, date1 if date1 else None, date2 if date2 else None 
開發者ID:CCI-Tools,項目名稱:cate,代碼行數:19,代碼來源:main.py

示例2: _get_step_from_checkpoint_path

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def _get_step_from_checkpoint_path(path):
  """Extracts the global step from a checkpoint path."""
  split_path = path.rsplit("model.ckpt-", 1)
  if len(split_path) != 2:
    raise ValueError("Unrecognized checkpoint path: {}".format(path))
  return int(split_path[1]) 
開發者ID:google-research,項目名稱:exoplanet-ml,代碼行數:8,代碼來源:prediction_fns.py

示例3: namespace_path_split

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def namespace_path_split(path):
    '''Split the namespace path into a pair (head, tail).

    Tail will be the last namespace path component and head will
    be everything leading up to that in the path. This is similar to
    os.path.split.

    :param path: (String) A namespace path.
    :returns: (String, String) A tuple where the first component is the base
              path and the second is the last path component.
    '''
    return tuple(path.rsplit('.', 1)) 
開發者ID:PyCQA,項目名稱:bandit,代碼行數:14,代碼來源:utils.py

示例4: _robust_path_split

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def _robust_path_split(path):
    sep = "\\" if "\\" in path else "/"
    parent, file = path.rsplit(sep, 1)
    filename, ext = os.path.splitext(file)
    return parent, filename, ext 
開發者ID:DeepLabCut,項目名稱:DeepLabCut,代碼行數:7,代碼來源:trainingsetmanipulation.py

示例5: can_resolve

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def can_resolve(self, uri_path, from_resource=None):
        uri_path = Resource.normalize(uri_path)
        fragment = uri_path.rsplit('#', maxsplit=1)
        nb_fragments = len(fragment)
        uri_str = ''
        if nb_fragments == 2:
            uri_str, fragment = fragment
            if uri_str in self.resources:
                return True
        start = from_resource.uri.normalize() if from_resource else '.'
        apath = path.dirname(start)
        uri = URI(path.join(apath, uri_str))
        return uri.normalize() in self.resources 
開發者ID:pyecore,項目名稱:pyecore,代碼行數:15,代碼來源:resource.py

示例6: resolve

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def resolve(self, uri, from_resource=None):
        upath = URIMapper.translate(Resource.normalize(uri), from_resource)
        uri_str, fragment = upath.rsplit('#', maxsplit=1)
        if uri_str in self.resources:
            root = self.resources[uri_str]
        else:
            start = from_resource.uri.normalize() if from_resource else '.'
            apath = path.dirname(start)
            uri = URI(path.join(apath, uri_str))
            root = self.resources[uri.normalize()]
        if isinstance(root, Resource):
            root_number, fragment = Resource.extract_rootnum_and_frag(fragment)
            root = root.contents[root_number]
        return Resource._navigate_from(fragment, root) 
開發者ID:pyecore,項目名稱:pyecore,代碼行數:16,代碼來源:resource.py

示例7: split_path

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def split_path(path):
        path = Resource.normalize(path)
        fragment = path.rsplit('#', maxsplit=1)
        if len(fragment) == 2:
            uri, fragment = fragment
        else:
            uri = None
        return uri, fragment 
開發者ID:pyecore,項目名稱:pyecore,代碼行數:10,代碼來源:resource.py

示例8: _is_external

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def _is_external(self, path):
        path = self.normalize(path)
        uri, fragment = (path.rsplit('#', maxsplit=1)
                         if '#' in path else (None, path))
        return uri, fragment 
開發者ID:pyecore,項目名稱:pyecore,代碼行數:7,代碼來源:resource.py

示例9: _parse_write_arg

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def _parse_write_arg(write_arg) -> Tuple[NullableStr, NullableStr, NullableStr]:
    """
    Parse string argument ``FILE := "[OUT_NAME=]PATH[,FORMAT]`` and return tuple OUT_NAME,PATH,FORMAT.

    :param write_arg: The FILE string argument
    :return: The tuple OUT_NAME,PATH,FORMAT
    """
    name_and_path = write_arg.split('=', maxsplit=1)
    name, path = name_and_path if len(name_and_path) == 2 else (None, write_arg)
    path_and_format = path.rsplit(',', maxsplit=1)
    path, format_name = path_and_format if len(path_and_format) == 2 else (path, None)
    return name if name else None, path if path else None, format_name.upper() if format_name else None 
開發者ID:CCI-Tools,項目名稱:cate,代碼行數:14,代碼來源:main.py

示例10: GetLastPathElement

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def GetLastPathElement(path):
    """
    Similar to basename.
    Generic utility function.
    """
    return path.rsplit('/', 1)[1] 
開發者ID:Azure,項目名稱:azure-linux-extensions,代碼行數:8,代碼來源:WaagentLib.py

示例11: _base_model

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import rsplit [as 別名]
def _base_model(self, path):
        """Build the common base of a contents model"""
        info = self._pyfilesystem_instance.getinfo(path, namespaces=['details', 'access'])

        try:
            # size of file
            size = info.size
        except (errors.MissingInfoNamespace,):
            self.log.warning('Unable to get size.')
            size = None

        # Use the Unix epoch as a fallback so we don't crash.
        try:
            last_modified = info.modified or EPOCH_START
        except (errors.MissingInfoNamespace,):
            self.log.warning('Invalid `modified` for %s', path)
            last_modified = EPOCH_START

        try:
            created = info.created or last_modified
        except (errors.MissingInfoNamespace,):
            self.log.warning('Invalid `created` for %s', path)
            created = EPOCH_START

        # Create the base model.
        model = {}
        model['name'] = path.rsplit('/', 1)[-1]
        model['path'] = path
        model['last_modified'] = last_modified
        model['created'] = created
        model['content'] = None
        model['format'] = None
        model['mimetype'] = None
        model['size'] = size

        try:
            model['writable'] = info.permissions.check('u_w')  # TODO check
        except (errors.MissingInfoNamespace,):
            # if relevant namespace is missing, assume writable
            # TODO: decide if this is wise
            model['writable'] = True
        except OSError:
            self.log.error("Failed to check write permissions on %s", path)
            model['writable'] = False
        return model 
開發者ID:jpmorganchase,項目名稱:jupyter-fs,代碼行數:47,代碼來源:fsmanager.py


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