用法:
textwrap.shorten(text, width, *, fix_sentence_endings=False, break_long_words=True, break_on_hyphens=True, placeholder=' [...]')
折疊並截斷給定的
text
以適應給定的width
。首先
text
中的空格被折疊(所有空格都被單個空格替換)。如果結果適合width
,則返回。否則,從末尾刪除足夠的單詞,以便剩餘的單詞加上placeholder
適合width
:>>> textwrap.shorten("Hello world!", width=12) 'Hello world!' >>> textwrap.shorten("Hello world!", width=11) 'Hello [...]' >>> textwrap.shorten("Hello world", width=10, placeholder="...") 'Hello...'
可選關鍵字參數對應於
TextWrapper
的實例屬性,如下所述。請注意,在將文本傳遞給TextWrapper
fill()
函數之前,空格已折疊,因此更改tabsize
、expand_tabs
、drop_whitespace
和replace_whitespace
的值將無效。3.4 版中的新函數。
相關用法
- Python textwrap.indent用法及代碼示例
- Python textwrap.dedent用法及代碼示例
- Python textwrap.TextWrapper用法及代碼示例
- Python tensorflow.eye()用法及代碼示例
- Python tensorflow.fill()用法及代碼示例
- Python tensorflow.math.special.dawsn()用法及代碼示例
- Python tensorflow.ensure_shape()用法及代碼示例
- Python tensorflow.math.special.fresnel_cos()用法及代碼示例
- Python tensorflow.raw_ops.Cos()用法及代碼示例
- Python tensorflow.get_logger()用法及代碼示例
- Python tensorflow.math.sqrt()用法及代碼示例
- Python test.support.catch_unraisable_exception用法及代碼示例
- Python tensorflow.math.atanh()用法及代碼示例
- Python tensorflow.math.xlogy()用法及代碼示例
- Python tensorflow.math.cos()用法及代碼示例
- Python tell()用法及代碼示例
- Python tensorflow.math.nextafter()用法及代碼示例
- Python tensorflow.math.floordiv()用法及代碼示例
- Python tensorflow.DeviceSpec.replace()用法及代碼示例
- Python tensorflow.math.confusion_matrix()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 textwrap.shorten。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。