本文整理汇总了Python中textwrap.TextWrapper.drop_whitespace方法的典型用法代码示例。如果您正苦于以下问题:Python TextWrapper.drop_whitespace方法的具体用法?Python TextWrapper.drop_whitespace怎么用?Python TextWrapper.drop_whitespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类textwrap.TextWrapper
的用法示例。
在下文中一共展示了TextWrapper.drop_whitespace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import drop_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
示例2: draw_body
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import drop_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
示例3: DisassemblyPrinter
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import drop_whitespace [as 别名]
def DisassemblyPrinter( instructions, fifoname='', width=int(ExtensionSettings.getValue('main_termal_width')), wrap=False):
if (fifoname):
output=fifoname
else:
output=sys.stdout
print >>output, "=" * 16
data = gdb.execute("x/" + str(instructions) + "i $pc", False, True)
if wrap:
print >>output, data
else:
wrapper = TextWrapper() # use TextWrapper to properly deal with tab lengths in output
wrapper.width = width
wrapper.drop_whitespace = False
for line in data.split('\n'):
out = wrapper.wrap(line)
if len(out) > 0:
print >>output, wrapper.wrap(line)[0]
示例4: wordWrap
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import drop_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]