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


Python TextWrapper.replace_whitespace方法代码示例

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


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

示例1: __init__

# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import replace_whitespace [as 别名]
	def __init__(self, width=80):
		""" Sets up the class and configures the utilized Textwrapper-object"""
		self.width = width
		wrapper = TextWrapper()
		wrapper.width = width	
		wrapper.replace_whitespace = False	
		wrapper.drop_whitespace = False	
		self.wrapper = wrapper
开发者ID:jmtoball,项目名称:StudICLI,代码行数:10,代码来源:asciioutput.py

示例2: linewrap

# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import replace_whitespace [as 别名]
def linewrap(width = None):
    """Returns a function that wraps long lines to a max of 251 characters.
	Note that this function returns a list of lines, which is suitable as the
	argument for the spss.Submit function.
    """
    wrapper = TextWrapper()
    wrapper.width = width or 251
    wrapper.replace_whitespace = True
    wrapper.break_long_words = False
    wrapper.break_on_hyphens = False
    return wrapper.wrap
开发者ID:matt-hayden,项目名称:python-utilities,代码行数:13,代码来源:spss_functions.py

示例3: draw_body

# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import replace_whitespace [as 别名]
def draw_body(card, raw_text, center_y, card_width, chars_per_line):
	text = raw_text.decode('utf-8')
	wrapper = TextWrapper()
	wrapper.width = chars_per_line
	wrapper.replace_whitespace = True
	wrapper.drop_whitespace = False
	lines = wrapper.wrap(text)
	line_width, line_height = body_font.getsize(lines[0])
	y = center_y - (line_height * (float(len(lines)) / 2.0))
	for line in lines:
		line_width, line_height = body_font.getsize(line)
		draw = ImageDraw.Draw(card)
		draw.text(((card_width - line_width) / 2, y), line, font = body_font, fill = (0, 0, 0))
		y += line_height
开发者ID:eriksvedang,项目名称:card-creator,代码行数:16,代码来源:card.py

示例4: wordWrap

# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import replace_whitespace [as 别名]
def wordWrap(lines, rows, cols):
    """ Format an array of text to a specific number of 
        visible rows and columns """
    wrapped = []

    # Set up a TextWrapper
    wrapper = TextWrapper()
    wrapper.width = cols
    wrapper.expand_tabs = False
    wrapper.replace_whitespace = False
    wrapper.drop_whitespace = False

    for line in lines:
        if len(line) > cols:
            wrapped.extend(wrapper.wrap(line))
        else:
            wrapped.append(line)

        if len(wrapped) >= rows:
            break

    # Return only "rows" in case a word wrap added extra
    return wrapped[:rows]
开发者ID:spattersongt,项目名称:vippy,代码行数:25,代码来源:Formatting.py

示例5: TextWrapper

# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import replace_whitespace [as 别名]
# (at your option) any later version.
#
# TZMud is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with TZMud.  If not, see <http://www.gnu.org/licenses/>.


'''The Twisted protocol.'''

from textwrap import TextWrapper
wrapper = TextWrapper()
wrapper.replace_whitespace = False
wrapper.subsequent_indent = '    '
wrap = wrapper.wrap

import re
class Wrapper(TextWrapper):
    def _wrap_chunks(self, chunks):
        lines = []
        if self.width <= 0:
            raise ValueError("invalid width %r (must be > 0)" % self.width)
        chunks.reverse()
        while chunks:
            cur_line = []
            cur_len = 0
            if lines:
                indent = self.subsequent_indent
开发者ID:cryptixman,项目名称:tzmud,代码行数:33,代码来源:tzprotocol.py

示例6: join

# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import replace_whitespace [as 别名]
from misc import filePath, dirPath

# Enviromental variables
demo_dir = join(filePath(__file__).baseDir, 'example')
tty_width = 72
partition = '-' * tty_width
prompt = '>>> '

# Current dir
# current_dir = dirPath('./')


wrapper = TextWrapper()
wrapper.width = tty_width
wrapper.replace_whitespace = False
# wrapper.drop_whitespace = False
wrapper.initial_indent = "- "
wrapper.subsequent_indent = '- '

comment_wrapper = TextWrapper()
comment_wrapper.replace_whitespace = False
# comment_wrapper.drop_whitespace = False
comment_wrapper.width = tty_width
comment_wrapper.subsequent_indent = '# '

class demo_menu:
    """
    Menu object
    
    Contains a list of menu options, as well as the parent menu if exist.
开发者ID:Charley-fan,项目名称:metaArray,代码行数:32,代码来源:example.py


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