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