当前位置: 首页>>代码示例>>Python>>正文


Python string.lstrip方法代码示例

本文整理汇总了Python中string.lstrip方法的典型用法代码示例。如果您正苦于以下问题:Python string.lstrip方法的具体用法?Python string.lstrip怎么用?Python string.lstrip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在string的用法示例。


在下文中一共展示了string.lstrip方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: search_filename

# 需要导入模块: import string [as 别名]
# 或者: from string import lstrip [as 别名]
def search_filename(filename, languages):
  title, year = xbmc.getCleanMovieTitle(filename)
  log(__name__, "clean title: \"%s\" (%s)" % (title, year))
  try:
    yearval = int(year)
  except ValueError:
    yearval = 0
  if title and yearval > 1900:
    query_Film(title, year, item['3let_language'], filename)
  else:
    match = re.search(r'\WS(?P<season>\d\d)E(?P<episode>\d\d)', title, flags=re.IGNORECASE)
    if match is not None:
      tvshow = string.strip(title[:match.start('season')-1])
      season = string.lstrip(match.group('season'), '0')
      episode = string.lstrip(match.group('episode'), '0')
      query_TvShow(tvshow, season, episode, item['3let_language'], filename)
    else:
      search_manual(filename, item['3let_language'], filename) 
开发者ID:cflannagan,项目名称:service.subtitles.addic7ed,代码行数:20,代码来源:service.py

示例2: indentsize

# 需要导入模块: import string [as 别名]
# 或者: from string import lstrip [as 别名]
def indentsize(line):
    """Return the indent size, in spaces, at the start of a line of text."""
    expline = string.expandtabs(line)
    return len(expline) - len(string.lstrip(expline)) 
开发者ID:glmcdona,项目名称:meddle,代码行数:6,代码来源:inspect.py

示例3: cleandoc

# 需要导入模块: import string [as 别名]
# 或者: from string import lstrip [as 别名]
def cleandoc(doc):
    """Clean up indentation from docstrings.

    Any whitespace that can be uniformly removed from the second line
    onwards is removed."""
    try:
        lines = string.split(string.expandtabs(doc), '\n')
    except UnicodeError:
        return None
    else:
        # Find minimum indentation of any non-blank lines after first line.
        margin = sys.maxint
        for line in lines[1:]:
            content = len(string.lstrip(line))
            if content:
                indent = len(line) - content
                margin = min(margin, indent)
        # Remove indentation.
        if lines:
            lines[0] = lines[0].lstrip()
        if margin < sys.maxint:
            for i in range(1, len(lines)): lines[i] = lines[i][margin:]
        # Remove any trailing or leading blank lines.
        while lines and not lines[-1]:
            lines.pop()
        while lines and not lines[0]:
            lines.pop(0)
        return string.join(lines, '\n') 
开发者ID:glmcdona,项目名称:meddle,代码行数:30,代码来源:inspect.py

示例4: getdoc

# 需要导入模块: import string [as 别名]
# 或者: from string import lstrip [as 别名]
def getdoc(object):
    """Get the documentation string for an object.

    All tabs are expanded to spaces.  To clean up docstrings that are
    indented to line up with blocks of code, any whitespace than can be
    uniformly removed from the second line onwards is removed."""
    try:
        doc = object.__doc__
    except AttributeError:
        return None
    if not isinstance(doc, (str, unicode)):
        return None
    try:
        lines = string.split(string.expandtabs(doc), '\n')
    except UnicodeError:
        return None
    else:
        margin = None
        for line in lines[1:]:
            content = len(string.lstrip(line))
            if not content: continue
            indent = len(line) - content
            if margin is None: margin = indent
            else: margin = min(margin, indent)
        if margin is not None:
            for i in range(1, len(lines)): lines[i] = lines[i][margin:]
        return string.join(lines, '\n') 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:29,代码来源:_pydev_inspect.py

示例5: getcomments

# 需要导入模块: import string [as 别名]
# 或者: from string import lstrip [as 别名]
def getcomments(object):
    """Get lines of comments immediately preceding an object's source code."""
    try: lines, lnum = findsource(object)
    except IOError: return None

    if ismodule(object):
        # Look for a comment block at the top of the file.
        start = 0
        if lines and lines[0][:2] == '#!': start = 1
        while start < len(lines) and string.strip(lines[start]) in ['', '#']:
            start = start + 1
        if start < len(lines) and lines[start][:1] == '#':
            comments = []
            end = start
            while end < len(lines) and lines[end][:1] == '#':
                comments.append(string.expandtabs(lines[end]))
                end = end + 1
            return string.join(comments, '')

    # Look for a preceding block of comments at the same indentation.
    elif lnum > 0:
        indent = indentsize(lines[lnum])
        end = lnum - 1
        if end >= 0 and string.lstrip(lines[end])[:1] == '#' and \
            indentsize(lines[end]) == indent:
            comments = [string.lstrip(string.expandtabs(lines[end]))]
            if end > 0:
                end = end - 1
                comment = string.lstrip(string.expandtabs(lines[end]))
                while comment[:1] == '#' and indentsize(lines[end]) == indent:
                    comments[:0] = [comment]
                    end = end - 1
                    if end < 0: break
                    comment = string.lstrip(string.expandtabs(lines[end]))
            while comments and string.strip(comments[0]) == '#':
                comments[:1] = []
            while comments and string.strip(comments[-1]) == '#':
                comments[-1:] = []
            return string.join(comments, '') 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:41,代码来源:_pydev_inspect.py

示例6: test_integers

# 需要导入模块: import string [as 别名]
# 或者: from string import lstrip [as 别名]
def test_integers(self):
        # hex, octal and large positive ints.
        res = config.parse_config(string.lstrip(test_integers_1))
        self.failUnless(res['a'] == 255 and res['b'] == 255
                   and res['c'] == 017777777777) 
开发者ID:ActiveState,项目名称:code,代码行数:7,代码来源:recipe-576404.py

示例7: parse

# 需要导入模块: import string [as 别名]
# 或者: from string import lstrip [as 别名]
def parse(url):
  """
    Parse ZooKeeper URL.
    :param url: The URL in the form of "zk://username:password@servers/path".
    :return: Tuple (credential, servers, path).
             credential: Credential for authentication with "digest" scheme. Optional and default to
                         None.
             servers: Compatible with Kazoo's 'hosts' argument.
             path: Optional and default to '/'.
    NOTE: This method doesn't validate the values in the returned tuple.
  """
  index = string.find(url, "zk://")
  if index != 0:
    raise ValueError("Expecting 'zk://' at the beginning of the URL")

  url = string.lstrip(url, "zk://")

  try:
    servers, path = string.split(url, '/', 1)
  except ValueError:
    servers = url
    path = ''

  path = '/' + path

  try:
    credential, servers = string.split(servers, '@', 1)
  except ValueError:
    credential = None

  return credential, servers, path 
开发者ID:apache,项目名称:incubator-retired-cotton,代码行数:33,代码来源:zookeeper.py

示例8: _accept

# 需要导入模块: import string [as 别名]
# 或者: from string import lstrip [as 别名]
def _accept(prefix):
    return string.lstrip(prefix)[:7] == "#define"

##
# Image plugin for X11 bitmaps. 
开发者ID:awslabs,项目名称:mxnet-lambda,代码行数:7,代码来源:XbmImagePlugin.py

示例9: readLine

# 需要导入模块: import string [as 别名]
# 或者: from string import lstrip [as 别名]
def readLine(self, line):
        #this is the inner loop
        self._lineNo = self._lineNo + 1
        stripped = string.lstrip(line)
        if len(stripped) == 0:
            if self._mode == PLAIN:
                self.endPara()
            else:  #preformatted, append it
                self._buf.append(line)
        elif line[0]=='.':
            # we have a command of some kind
            self.endPara()
            words = string.split(stripped[1:])
            cmd, args = words[0], words[1:]

            #is it a parser method?
            if hasattr(self.__class__, cmd):
                #this was very bad; any type error in the method was hidden
                #we have to hack the traceback
                try:
                    getattr(self,cmd)(*args)
                except TypeError, err:
                    sys.stderr.write("Parser method: %s(*%s) %s at line %d\n" % (cmd, args, err, self._lineNo))
                    raise
            else:
                # assume it is a paragraph style -
                # becomes the formatter's problem
                self.endPara()  #end the last one
                words = string.split(stripped, ' ', 1)
                assert len(words)==2, "Style %s but no data at line %d" % (words[0], self._lineNo)
                (styletag, data) = words
                self._style = styletag[1:]
                self._buf.append(data) 
开发者ID:gltn,项目名称:stdm,代码行数:35,代码来源:yaml.py

示例10: Reindent

# 需要导入模块: import string [as 别名]
# 或者: from string import lstrip [as 别名]
def Reindent(s, numSpaces):
    # http://code.activestate.com/recipes/66055-changing-the-indentation-of-a-multi-line-string/
    s = string.split(s, '\n')
    s = [(numSpaces * ' ') + string.lstrip(line) for line in s]
    s = string.join(s, '\n')
    return s 
开发者ID:SimplySecurity,项目名称:SimplyTemplate,代码行数:8,代码来源:Helpers.py


注:本文中的string.lstrip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。