zoukankan      html  css  js  c++  java
  • textwrap 模块

    # -*- coding: utf-8 -*-
    #python 27
    #xiaodeng
    #textwrap 模块
    #http://www.cnblogs.com/hongten/p/python_textwrap.html
    
    
    
    import textwrap
    sample_text = '''
       The textwrap module can beused to format text for output in
       situations wherepretty-printing is desired.  It offers
       programmatic functionalitysimilar to the paragraph wrapping
       or filling features found inmany text editors.
    '''
    
    
    #fill(text, width=70, **kwargs):
    #该方法可以根据指定的长度,进行拆分字符串,然后逐行显示
    print textwrap.fill(sample_text,width=20)
    
    
    
    #wrap(text, width = 70, **kwargs):这个函数可以把一个字符串拆分成一个序列
    #width,按照特定宽度拆分字符串。
    print textwrap.wrap(sample_text,width=50)
    
    
    
    #dedent()方法->文本进行不缩进显示,相应的indent()方法 -> 进行缩进显示
    print textwrap.dedent(sample_text)
  • 相关阅读:
    数据库被黑后留下的数据
    cron(CronTrigger)表达式用法
    nodeJS常用的定时执行任务的插件
    css实现隐藏滚动条
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
  • 原文地址:https://www.cnblogs.com/dengyg200891/p/4943777.html
Copyright © 2011-2022 走看看