本文整理匯總了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)
示例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))
示例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')
示例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')
示例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, '')
示例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)
示例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
示例8: _accept
# 需要導入模塊: import string [as 別名]
# 或者: from string import lstrip [as 別名]
def _accept(prefix):
return string.lstrip(prefix)[:7] == "#define"
##
# Image plugin for X11 bitmaps.
示例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)
示例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