我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用os.path.lstrip()。
def __init__(self, url=None, *args, **kwargs): # Works around an apparent Git bug # (see http://article.gmane.org/gmane.comp.version-control.git/146500) if url: scheme, netloc, path, query, fragment = urlsplit(url) if scheme.endswith('file'): initial_slashes = path[:-len(path.lstrip('/'))] newpath = ( initial_slashes + urllib_request.url2pathname(path) .replace('\\', '/').lstrip('/') ) url = urlunsplit((scheme, netloc, newpath, query, fragment)) after_plus = scheme.find('+') + 1 url = scheme[:after_plus] + urlunsplit( (scheme[after_plus:], netloc, newpath, query, fragment), ) super(Git, self).__init__(url, *args, **kwargs)
def list_children(self, path): """ Yield all direct children of the given root-relative path, as root- relative paths. If the path refers to a file, there will be no children. """ if len(path) > 0 and not path.endswith("/"): # We need a trailing slash after a real directory name for urljoin # to work later path = path + "/" # Strip leading slashes from the input path, so we always look inside # our base path. path = path.lstrip("/") # Construct the path to actually go to on the FTP server ftp_path = urlparse.urljoin(self.base_path, path) Logger.debug("Listing {}".format(ftp_path)) for child in robust_nlst(self.connection, ftp_path): # For every child, build a root-relative URL yield urlparse.urljoin(path, child)