textwrap

1.dedent 

Remove any common leading whitespace from every line in textNote that tabs and spaces are both treated as whitespace

  • simple example
from textwrap import dedent

print(">>>> Here will be a dedenting test:")
print(dedent("""    First Line
    Helllooo
    Hellooooo
    Test!!"""))
>>>> Here will be a dedenting test:
First Line
Helllooo
Hellooooo
Test!!

  • format output
import textwrap
name = 'WuwWei'
message = '''\
  {name}
  hello
  world
'''
body = message.format(name=name)
print body

screen output

  WuWei
  hello
  world

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章