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


Python string.expandtabs方法代码示例

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


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

示例1: preformat

# 需要导入模块: import string [as 别名]
# 或者: from string import expandtabs [as 别名]
def preformat(self, text):
        """Format literal preformatted text."""
        text = self.escape(expandtabs(text))
        return replace(text, '\n\n', '\n \n', '\n\n', '\n \n',
                             ' ', '&nbsp;', '\n', '<br>\n') 
开发者ID:glmcdona,项目名称:meddle,代码行数:7,代码来源:pydoc.py

示例2: indentsize

# 需要导入模块: import string [as 别名]
# 或者: from string import expandtabs [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 expandtabs [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: wrap

# 需要导入模块: import string [as 别名]
# 或者: from string import expandtabs [as 别名]
def wrap(self, text):
        """wrap(text : string) -> [string]

        Reformat the single paragraph in 'text' so it fits in lines of
        no more than 'self.width' columns, and return a list of wrapped
        lines.  Tabs in 'text' are expanded with string.expandtabs(),
        and all other whitespace characters (including newline) are
        converted to space.
        """
        text = self._munge_whitespace(text)
        chunks = self._split(text)
        if self.fix_sentence_endings:
            self._fix_sentence_endings(chunks)
        return self._wrap_chunks(chunks) 
开发者ID:glmcdona,项目名称:meddle,代码行数:16,代码来源:textwrap.py

示例5: _munge_whitespace

# 需要导入模块: import string [as 别名]
# 或者: from string import expandtabs [as 别名]
def _munge_whitespace(self, text):
        """_munge_whitespace(text : string) -> string

        Munge whitespace in text: expand tabs and convert all other
        whitespace characters to spaces.  Eg. " foo\tbar\n\nbaz"
        becomes " foo    bar  baz".
        """
        if self.expand_tabs:
            text = string.expandtabs(text)
        if self.replace_whitespace:
            if isinstance(text, type('')):
                text = string.translate(text, self.whitespace_trans)
            elif isinstance(text, unicode):
                text = string.translate(text, self.unicode_whitespace_trans)
        return text 
开发者ID:coin3d,项目名称:pivy,代码行数:17,代码来源:_scons_textwrap.py

示例6: wrap

# 需要导入模块: import string [as 别名]
# 或者: from string import expandtabs [as 别名]
def wrap(self, text):
        """wrap(text : string) -> [string]

        Reformat the single paragraph in 'text' so it fits in lines of
        no more than 'self.width' columns, and return a list of wrapped
        lines.  Tabs in 'text' are expanded with string.expandtabs(),
        and all other whitespace characters (including newline) are
        converted to space.
        """
        text = self._munge_whitespace(text)
        indent = self.initial_indent
        chunks = self._split(text)
        if self.fix_sentence_endings:
            self._fix_sentence_endings(chunks)
        return self._wrap_chunks(chunks) 
开发者ID:coin3d,项目名称:pivy,代码行数:17,代码来源:_scons_textwrap.py

示例7: getdoc

# 需要导入模块: import string [as 别名]
# 或者: from string import expandtabs [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

示例8: getcomments

# 需要导入模块: import string [as 别名]
# 或者: from string import expandtabs [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


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