import textwrap
doc='''Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
complex is better than complicated.
Flat is better than dense.
Readability counts.
Special cases arren't special enough to break the rules.
Although Praticality beats purity.'''
print(textwrap.fill(doc,20)) #按指定宽度进行排版
# Beautiful is better
# than ugly. Explicit
# is better than
# implicit. Simple is
# better than complex.
# complex is better
# than complicated.
# Flat is better than
# dense. Readability
# counts. Special
# cases arren't
# special enough to
# break the rules.
# Although Praticality
# beats purity. print(textwrap.fill(doc,width=80)) #按指定宽度进行排版
# Beautiful is better than ugly. Explicit is better than implicit. Simple is
# better than complex. complex is better than complicated. Flat is better than
# dense. Readability counts. Special cases arren't special enough to break the
# rules. Although Praticality beats purity. print(textwrap.wrap(doc)) #默认长度最大为70
# ['Beautiful is better than ugly. Explicit is better than implicit.', 'Simple is better than complex. complex is better than complicated.', "Flat is better than dense. Readability counts. Special cases arren't", 'special enough to break the rules. Although Praticality beats purity.']