本文整理汇总了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
示例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])
示例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))
示例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
示例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
示例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)
示例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
示例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
示例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
示例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]
示例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