python textwrap_python2.7.3编译python模块学习- textwrap 文本包装和填充
python模塊學習- 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.
'''
段落填充:import textwrap
from textwrap_exampleimport sample_text
print 'Nodedent:n'
printtextwrap.fill(sample_text, width=50)
執行結果:
# pythontextwrap_fill.py
No dedent:
The textwrap module can be used to format
text for outputin ? ? situations where pretty-
printing is desired. ?It offers ? ?programmatic
functionalitysimilar to the paragraph wrapping
or fillingfeatures found in many text editors.
結果為左對齊,第一行有縮進。行中的空格繼續保留。
移除縮進:import textwrap
fromtextwrap_example import sample_text
dedented_text = textwrap.dedent(sample_text)
print 'Dedented:'
printdedented_text
執行結果:
# pythontextwrap_dedent.py
Dedented:
The textwrapmodule can be used to format text for output in
situations wherepretty-printing is desired. ?It offers
programmaticfunctionality similar to the paragraph wrapping
or fillingfeatures found in many text editors.
這樣第一行就不會縮進。
結合移除縮進和填充:import textwrap
fromtextwrap_example import sample_text
dedented_text =textwrap.dedent(sample_text).strip()
for width in [ 45,70 ]:
print '%d Columns:n' % width
print textwrap.fill(dedented_text,width=width)
執行結果:
# pythontextwrap_fill_width.py
45 Columns:
The textwrapmodule can be used to format
text for output insituations where pretty-
printing isdesired. ?It offers programmatic
functionalitysimilar to the paragraph
wrapping orfilling features found in many
text editors.
70 Columns:
The textwrapmodule can be used to format text for output in
situations wherepretty-printing is desired. ?It offersprogrammatic
functionality similarto the paragraph wrapping or filling features
found in many texteditors.
懸掛縮進:懸掛縮進第一行的縮進小于其他行的縮進。import textwrap
fromtextwrap_example import sample_text
dedented_text =textwrap.dedent(sample_text).strip()
printtextwrap.fill(dedented_text,
initial_indent='',
subsequent_indent=' ' * 4,
width=50,
)
執行結果:
# pythontextwrap_hanging_indent.py
The textwrapmodule can be used to format text for
output in situations where pretty-printingis
desired. It offers programmatic functionality
similar to the paragraph wrapping orfilling
features found in many text editors.
其中的’’*4還可以使用其他字符代替。
TextWrap提供函數wrap()和fill(), 以及TextWrapper類,工具函數dedent(). 通常包裝或者填充一兩個字符串使用wrap()和fill()。其他情況使用TextWrapper更高效。
textwrap.wrap(text[,width[, ...]])
包裝單個段落(text為輸入,系字符串),每行最長寬度width。返回輸出行的列表,最后行無換行符。Width默認70。
textwrap.fill(text[,width[, ...]])
包裝單段文字,并返回包含包裹段落的字符串。實際上是"n".join(wrap(text,...))的縮寫。wrap() and fill()創建TextWrapper實例,并調用一個方法。這些實例不被重用,所以包裝/填充很多文本字符串要構造自己的TextWrapper對象更有效。TextWrapper.break_long_words設置是否拆長單詞。
textwrap.dedent(text)
反縮進去除每行行首的空白。這方便顯示三引號中的內容而不修改其源代碼中的縮進。
《python2.7.3編譯python模塊學習- textwrap 文本包裝和填充》總結了關于python培訓教程,對于我們來確實能學到不少知識。
更多:python2.7.3編譯python模塊學習- textwrap 文本包裝和填充
https://www.002pc.comhttps://www.002pc.com/python/1626.html
你可能感興趣的python,textwrap,填充,模塊,文本,包裝
刪除 php-fpmthinkphp3.2定義多模塊并設置默認模塊
前臺入口文件index.php《刪除 php-fpmthinkphp3.2定義多模塊并設置默認模塊》總結了關于電腦技術教程,對于我們來002pc.com確實能學到不少知識。
安卓電腦如何截屏Word中實現文本與表格的相互轉換
將文本轉換成表格
1、插入分隔符 (分隔符:將表格轉換為文本時,用分隔符標識文字分隔的位置,或在將文本轉換為表格時,用其標識新行或新列的起始位置。)(例如逗號或
js對象排序Js 網頁上反復顯示隱藏效果的文本
反復顯隱的文本www.002pc.com認為此文章對《Js 網頁上反復顯示隱藏效果的文本》說的很在理,第二電腦網為你提供最佳的網站制作,學習編程。
mysql is文本域、bootstrap-table顯示以及MySQL三者間的換行符問題
首先,今天在做項目的時候遇到的一個問題,如何實現文本輸入換行以及在前臺Bootstrap-table中顯示也能夠換行。
也許你馬上就會想到說,用富文本編輯器,然而我們需要實現的只是文本
反屏蔽 js使用text方法獲取Html元素文本信息示例
獲取文本信息的方法有很多,本例使用的使用的是jquery的text方法,這個方法想必大家都有使用過吧,簡單實用。獲取之后并使用alert將文本彈出,下面是實現代碼
qwebengine jSjavascript框架設計讀書筆記之模塊加載系統
模塊加載,其實就是把js分成很多個模塊,便于開發和維護。因此加載很多js模塊的時候,需要動態的加載,以便提高用戶體驗。
在介紹模塊加載庫之前,先介紹一個方法。
動態加載js方法:
ThinkPHP3.2.2及以上版本同一應用多模塊和多應用多模塊的實踐
ThinkPHP3.2.2及以后版本同一應用多模塊和多應用多模塊的設計已經比以前的版本更加簡單快捷。注:入口文件為index.php,內容為:[code]
asp.net 關閉.NET 緩存模塊設計實踐
上一篇談了我對緩存的概念,框架上的理解和看法,這篇承接上篇講講我自己的緩存模塊設計實踐。
基本的緩存模塊設計最基礎的緩存模塊一定有一個統一的CacheHelper,如下:?W WW
html js怎么加入關于腳本操作文本域的問題
用的jsp+servlert?在文本框里輸入的內容到達最右側以后,文本內容就會自動回行 而我在存入數據庫顯示的時候想要得到和錄入的形式完全符合的內容,沒有辦法獲得。 即我只能找到
在線觀看php和msql書籍【Thinkphp教程】空模塊
空模塊的概念是指當系統找不到指定的模塊名稱的時候,系統會嘗試定位空模塊(EmptyAction),利用這個機制我們可以用來定制錯誤頁面和進行URL的優化。現在我們把前面的需求進一步
0踩
賞
0 贊
總結
以上是生活随笔為你收集整理的python textwrap_python2.7.3编译python模块学习- textwrap 文本包装和填充的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: gin go 更新缓存_golang自动
- 下一篇: jq画布插件_超炫HTML 5开发的jQ