gooderp18绿色标准版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

609 linhas
51KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="textwrap — Text wrapping and filling" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/textwrap.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/textwrap.py The textwrap module provides some convenience functions, as well as TextWrapper, the class that does all the work. If you’re just wrapping or filling one or two text st..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/textwrap.py The textwrap module provides some convenience functions, as well as TextWrapper, the class that does all the work. If you’re just wrapping or filling one or two text st..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>textwrap — Text wrapping and filling &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="unicodedata — Unicode Database" href="unicodedata.html" />
  33. <link rel="prev" title="difflib — Helpers for computing deltas" href="difflib.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/textwrap.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h4>Previous topic</h4>
  84. <p class="topless"><a href="difflib.html"
  85. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">difflib</span></code> — Helpers for computing deltas</a></p>
  86. </div>
  87. <div>
  88. <h4>Next topic</h4>
  89. <p class="topless"><a href="unicodedata.html"
  90. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">unicodedata</span></code> — Unicode Database</a></p>
  91. </div>
  92. <div role="note" aria-label="source link">
  93. <h3>This Page</h3>
  94. <ul class="this-page-menu">
  95. <li><a href="../bugs.html">Report a Bug</a></li>
  96. <li>
  97. <a href="https://github.com/python/cpython/blob/main/Doc/library/textwrap.rst"
  98. rel="nofollow">Show Source
  99. </a>
  100. </li>
  101. </ul>
  102. </div>
  103. </nav>
  104. </div>
  105. </div>
  106. <div class="related" role="navigation" aria-label="related navigation">
  107. <h3>Navigation</h3>
  108. <ul>
  109. <li class="right" style="margin-right: 10px">
  110. <a href="../genindex.html" title="General Index"
  111. accesskey="I">index</a></li>
  112. <li class="right" >
  113. <a href="../py-modindex.html" title="Python Module Index"
  114. >modules</a> |</li>
  115. <li class="right" >
  116. <a href="unicodedata.html" title="unicodedata — Unicode Database"
  117. accesskey="N">next</a> |</li>
  118. <li class="right" >
  119. <a href="difflib.html" title="difflib — Helpers for computing deltas"
  120. accesskey="P">previous</a> |</li>
  121. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  122. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  123. <li class="switchers">
  124. <div class="language_switcher_placeholder"></div>
  125. <div class="version_switcher_placeholder"></div>
  126. </li>
  127. <li>
  128. </li>
  129. <li id="cpython-language-and-version">
  130. <a href="../index.html">3.12.3 Documentation</a> &#187;
  131. </li>
  132. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  133. <li class="nav-item nav-item-2"><a href="text.html" accesskey="U">Text Processing Services</a> &#187;</li>
  134. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">textwrap</span></code> — Text wrapping and filling</a></li>
  135. <li class="right">
  136. <div class="inline-search" role="search">
  137. <form class="inline-search" action="../search.html" method="get">
  138. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  139. <input type="submit" value="Go" />
  140. </form>
  141. </div>
  142. |
  143. </li>
  144. <li class="right">
  145. <label class="theme-selector-label">
  146. Theme
  147. <select class="theme-selector" oninput="activateTheme(this.value)">
  148. <option value="auto" selected>Auto</option>
  149. <option value="light">Light</option>
  150. <option value="dark">Dark</option>
  151. </select>
  152. </label> |</li>
  153. </ul>
  154. </div>
  155. <div class="document">
  156. <div class="documentwrapper">
  157. <div class="bodywrapper">
  158. <div class="body" role="main">
  159. <section id="module-textwrap">
  160. <span id="textwrap-text-wrapping-and-filling"></span><h1><a class="reference internal" href="#module-textwrap" title="textwrap: Text wrapping and filling"><code class="xref py py-mod docutils literal notranslate"><span class="pre">textwrap</span></code></a> — Text wrapping and filling<a class="headerlink" href="#module-textwrap" title="Link to this heading">¶</a></h1>
  161. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/textwrap.py">Lib/textwrap.py</a></p>
  162. <hr class="docutils" />
  163. <p>The <a class="reference internal" href="#module-textwrap" title="textwrap: Text wrapping and filling"><code class="xref py py-mod docutils literal notranslate"><span class="pre">textwrap</span></code></a> module provides some convenience functions,
  164. as well as <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a>, the class that does all the work.
  165. If you’re just wrapping or filling one or two text strings, the convenience
  166. functions should be good enough; otherwise, you should use an instance of
  167. <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> for efficiency.</p>
  168. <dl class="py function">
  169. <dt class="sig sig-object py" id="textwrap.wrap">
  170. <span class="sig-prename descclassname"><span class="pre">textwrap.</span></span><span class="sig-name descname"><span class="pre">wrap</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">width</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">70</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">initial_indent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">subsequent_indent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">expand_tabs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">replace_whitespace</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fix_sentence_endings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">break_long_words</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">drop_whitespace</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">break_on_hyphens</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tabsize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">8</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_lines</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">placeholder</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'</span> <span class="pre">[...]'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#textwrap.wrap" title="Link to this definition">¶</a></dt>
  171. <dd><p>Wraps the single paragraph in <em>text</em> (a string) so every line is at most
  172. <em>width</em> characters long. Returns a list of output lines, without final
  173. newlines.</p>
  174. <p>Optional keyword arguments correspond to the instance attributes of
  175. <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a>, documented below.</p>
  176. <p>See the <a class="reference internal" href="#textwrap.TextWrapper.wrap" title="textwrap.TextWrapper.wrap"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TextWrapper.wrap()</span></code></a> method for additional details on how
  177. <a class="reference internal" href="#textwrap.wrap" title="textwrap.wrap"><code class="xref py py-func docutils literal notranslate"><span class="pre">wrap()</span></code></a> behaves.</p>
  178. </dd></dl>
  179. <dl class="py function">
  180. <dt class="sig sig-object py" id="textwrap.fill">
  181. <span class="sig-prename descclassname"><span class="pre">textwrap.</span></span><span class="sig-name descname"><span class="pre">fill</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">width</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">70</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">initial_indent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">subsequent_indent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">expand_tabs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">replace_whitespace</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fix_sentence_endings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">break_long_words</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">drop_whitespace</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">break_on_hyphens</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tabsize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">8</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_lines</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">placeholder</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'</span> <span class="pre">[...]'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#textwrap.fill" title="Link to this definition">¶</a></dt>
  182. <dd><p>Wraps the single paragraph in <em>text</em>, and returns a single string containing the
  183. wrapped paragraph. <a class="reference internal" href="#textwrap.fill" title="textwrap.fill"><code class="xref py py-func docutils literal notranslate"><span class="pre">fill()</span></code></a> is shorthand for</p>
  184. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">wrap</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="o">...</span><span class="p">))</span>
  185. </pre></div>
  186. </div>
  187. <p>In particular, <a class="reference internal" href="#textwrap.fill" title="textwrap.fill"><code class="xref py py-func docutils literal notranslate"><span class="pre">fill()</span></code></a> accepts exactly the same keyword arguments as
  188. <a class="reference internal" href="#textwrap.wrap" title="textwrap.wrap"><code class="xref py py-func docutils literal notranslate"><span class="pre">wrap()</span></code></a>.</p>
  189. </dd></dl>
  190. <dl class="py function">
  191. <dt class="sig sig-object py" id="textwrap.shorten">
  192. <span class="sig-prename descclassname"><span class="pre">textwrap.</span></span><span class="sig-name descname"><span class="pre">shorten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">width</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fix_sentence_endings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">break_long_words</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">break_on_hyphens</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">placeholder</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'</span> <span class="pre">[...]'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#textwrap.shorten" title="Link to this definition">¶</a></dt>
  193. <dd><p>Collapse and truncate the given <em>text</em> to fit in the given <em>width</em>.</p>
  194. <p>First the whitespace in <em>text</em> is collapsed (all whitespace is replaced by
  195. single spaces). If the result fits in the <em>width</em>, it is returned.
  196. Otherwise, enough words are dropped from the end so that the remaining words
  197. plus the <em>placeholder</em> fit within <em>width</em>:</p>
  198. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">textwrap</span><span class="o">.</span><span class="n">shorten</span><span class="p">(</span><span class="s2">&quot;Hello world!&quot;</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>
  199. <span class="go">&#39;Hello world!&#39;</span>
  200. <span class="gp">&gt;&gt;&gt; </span><span class="n">textwrap</span><span class="o">.</span><span class="n">shorten</span><span class="p">(</span><span class="s2">&quot;Hello world!&quot;</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">11</span><span class="p">)</span>
  201. <span class="go">&#39;Hello [...]&#39;</span>
  202. <span class="gp">&gt;&gt;&gt; </span><span class="n">textwrap</span><span class="o">.</span><span class="n">shorten</span><span class="p">(</span><span class="s2">&quot;Hello world&quot;</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">placeholder</span><span class="o">=</span><span class="s2">&quot;...&quot;</span><span class="p">)</span>
  203. <span class="go">&#39;Hello...&#39;</span>
  204. </pre></div>
  205. </div>
  206. <p>Optional keyword arguments correspond to the instance attributes of
  207. <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a>, documented below. Note that the whitespace is
  208. collapsed before the text is passed to the <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> <a class="reference internal" href="#textwrap.fill" title="textwrap.fill"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fill()</span></code></a>
  209. function, so changing the value of <a class="reference internal" href="#textwrap.TextWrapper.tabsize" title="textwrap.TextWrapper.tabsize"><code class="xref py py-attr docutils literal notranslate"><span class="pre">tabsize</span></code></a>, <a class="reference internal" href="#textwrap.TextWrapper.expand_tabs" title="textwrap.TextWrapper.expand_tabs"><code class="xref py py-attr docutils literal notranslate"><span class="pre">expand_tabs</span></code></a>,
  210. <a class="reference internal" href="#textwrap.TextWrapper.drop_whitespace" title="textwrap.TextWrapper.drop_whitespace"><code class="xref py py-attr docutils literal notranslate"><span class="pre">drop_whitespace</span></code></a>, and <a class="reference internal" href="#textwrap.TextWrapper.replace_whitespace" title="textwrap.TextWrapper.replace_whitespace"><code class="xref py py-attr docutils literal notranslate"><span class="pre">replace_whitespace</span></code></a> will have no effect.</p>
  211. <div class="versionadded">
  212. <p><span class="versionmodified added">New in version 3.4.</span></p>
  213. </div>
  214. </dd></dl>
  215. <dl class="py function">
  216. <dt class="sig sig-object py" id="textwrap.dedent">
  217. <span class="sig-prename descclassname"><span class="pre">textwrap.</span></span><span class="sig-name descname"><span class="pre">dedent</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#textwrap.dedent" title="Link to this definition">¶</a></dt>
  218. <dd><p>Remove any common leading whitespace from every line in <em>text</em>.</p>
  219. <p>This can be used to make triple-quoted strings line up with the left edge of the
  220. display, while still presenting them in the source code in indented form.</p>
  221. <p>Note that tabs and spaces are both treated as whitespace, but they are not
  222. equal: the lines <code class="docutils literal notranslate"><span class="pre">&quot;</span>&#160; <span class="pre">hello&quot;</span></code> and <code class="docutils literal notranslate"><span class="pre">&quot;\thello&quot;</span></code> are considered to have no
  223. common leading whitespace.</p>
  224. <p>Lines containing only whitespace are ignored in the input and normalized to a
  225. single newline character in the output.</p>
  226. <p>For example:</p>
  227. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">test</span><span class="p">():</span>
  228. <span class="c1"># end first line with \ to avoid the empty line!</span>
  229. <span class="n">s</span> <span class="o">=</span> <span class="s1">&#39;&#39;&#39;</span><span class="se">\</span>
  230. <span class="s1"> hello</span>
  231. <span class="s1"> world</span>
  232. <span class="s1"> &#39;&#39;&#39;</span>
  233. <span class="nb">print</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">s</span><span class="p">))</span> <span class="c1"># prints &#39; hello\n world\n &#39;</span>
  234. <span class="nb">print</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">dedent</span><span class="p">(</span><span class="n">s</span><span class="p">)))</span> <span class="c1"># prints &#39;hello\n world\n&#39;</span>
  235. </pre></div>
  236. </div>
  237. </dd></dl>
  238. <dl class="py function">
  239. <dt class="sig sig-object py" id="textwrap.indent">
  240. <span class="sig-prename descclassname"><span class="pre">textwrap.</span></span><span class="sig-name descname"><span class="pre">indent</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prefix</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">predicate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#textwrap.indent" title="Link to this definition">¶</a></dt>
  241. <dd><p>Add <em>prefix</em> to the beginning of selected lines in <em>text</em>.</p>
  242. <p>Lines are separated by calling <code class="docutils literal notranslate"><span class="pre">text.splitlines(True)</span></code>.</p>
  243. <p>By default, <em>prefix</em> is added to all lines that do not consist
  244. solely of whitespace (including any line endings).</p>
  245. <p>For example:</p>
  246. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s1">&#39;hello</span><span class="se">\n\n</span><span class="s1"> </span><span class="se">\n</span><span class="s1">world&#39;</span>
  247. <span class="gp">&gt;&gt;&gt; </span><span class="n">indent</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="s1">&#39; &#39;</span><span class="p">)</span>
  248. <span class="go">&#39; hello\n\n \n world&#39;</span>
  249. </pre></div>
  250. </div>
  251. <p>The optional <em>predicate</em> argument can be used to control which lines
  252. are indented. For example, it is easy to add <em>prefix</em> to even empty
  253. and whitespace-only lines:</p>
  254. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">indent</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="s1">&#39;+ &#39;</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">line</span><span class="p">:</span> <span class="kc">True</span><span class="p">))</span>
  255. <span class="go">+ hello</span>
  256. <span class="go">+</span>
  257. <span class="go">+</span>
  258. <span class="go">+ world</span>
  259. </pre></div>
  260. </div>
  261. <div class="versionadded">
  262. <p><span class="versionmodified added">New in version 3.3.</span></p>
  263. </div>
  264. </dd></dl>
  265. <p><a class="reference internal" href="#textwrap.wrap" title="textwrap.wrap"><code class="xref py py-func docutils literal notranslate"><span class="pre">wrap()</span></code></a>, <a class="reference internal" href="#textwrap.fill" title="textwrap.fill"><code class="xref py py-func docutils literal notranslate"><span class="pre">fill()</span></code></a> and <a class="reference internal" href="#textwrap.shorten" title="textwrap.shorten"><code class="xref py py-func docutils literal notranslate"><span class="pre">shorten()</span></code></a> work by creating a
  266. <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> instance and calling a single method on it. That
  267. instance is not reused, so for applications that process many text
  268. strings using <a class="reference internal" href="#textwrap.wrap" title="textwrap.wrap"><code class="xref py py-func docutils literal notranslate"><span class="pre">wrap()</span></code></a> and/or <a class="reference internal" href="#textwrap.fill" title="textwrap.fill"><code class="xref py py-func docutils literal notranslate"><span class="pre">fill()</span></code></a>, it may be more efficient to
  269. create your own <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> object.</p>
  270. <p>Text is preferably wrapped on whitespaces and right after the hyphens in
  271. hyphenated words; only then will long words be broken if necessary, unless
  272. <a class="reference internal" href="#textwrap.TextWrapper.break_long_words" title="textwrap.TextWrapper.break_long_words"><code class="xref py py-attr docutils literal notranslate"><span class="pre">TextWrapper.break_long_words</span></code></a> is set to false.</p>
  273. <dl class="py class">
  274. <dt class="sig sig-object py" id="textwrap.TextWrapper">
  275. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">textwrap.</span></span><span class="sig-name descname"><span class="pre">TextWrapper</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#textwrap.TextWrapper" title="Link to this definition">¶</a></dt>
  276. <dd><p>The <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> constructor accepts a number of optional keyword
  277. arguments. Each keyword argument corresponds to an instance attribute, so
  278. for example</p>
  279. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">wrapper</span> <span class="o">=</span> <span class="n">TextWrapper</span><span class="p">(</span><span class="n">initial_indent</span><span class="o">=</span><span class="s2">&quot;* &quot;</span><span class="p">)</span>
  280. </pre></div>
  281. </div>
  282. <p>is the same as</p>
  283. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">wrapper</span> <span class="o">=</span> <span class="n">TextWrapper</span><span class="p">()</span>
  284. <span class="n">wrapper</span><span class="o">.</span><span class="n">initial_indent</span> <span class="o">=</span> <span class="s2">&quot;* &quot;</span>
  285. </pre></div>
  286. </div>
  287. <p>You can re-use the same <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> object many times, and you can
  288. change any of its options through direct assignment to instance attributes
  289. between uses.</p>
  290. <p>The <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> instance attributes (and keyword arguments to the
  291. constructor) are as follows:</p>
  292. <dl class="py attribute">
  293. <dt class="sig sig-object py" id="textwrap.TextWrapper.width">
  294. <span class="sig-name descname"><span class="pre">width</span></span><a class="headerlink" href="#textwrap.TextWrapper.width" title="Link to this definition">¶</a></dt>
  295. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">70</span></code>) The maximum length of wrapped lines. As long as there
  296. are no individual words in the input text longer than <a class="reference internal" href="#textwrap.TextWrapper.width" title="textwrap.TextWrapper.width"><code class="xref py py-attr docutils literal notranslate"><span class="pre">width</span></code></a>,
  297. <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> guarantees that no output line will be longer than
  298. <a class="reference internal" href="#textwrap.TextWrapper.width" title="textwrap.TextWrapper.width"><code class="xref py py-attr docutils literal notranslate"><span class="pre">width</span></code></a> characters.</p>
  299. </dd></dl>
  300. <dl class="py attribute">
  301. <dt class="sig sig-object py" id="textwrap.TextWrapper.expand_tabs">
  302. <span class="sig-name descname"><span class="pre">expand_tabs</span></span><a class="headerlink" href="#textwrap.TextWrapper.expand_tabs" title="Link to this definition">¶</a></dt>
  303. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">True</span></code>) If true, then all tab characters in <em>text</em> will be
  304. expanded to spaces using the <a class="reference internal" href="stdtypes.html#str.expandtabs" title="str.expandtabs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">expandtabs()</span></code></a> method of <em>text</em>.</p>
  305. </dd></dl>
  306. <dl class="py attribute">
  307. <dt class="sig sig-object py" id="textwrap.TextWrapper.tabsize">
  308. <span class="sig-name descname"><span class="pre">tabsize</span></span><a class="headerlink" href="#textwrap.TextWrapper.tabsize" title="Link to this definition">¶</a></dt>
  309. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">8</span></code>) If <a class="reference internal" href="#textwrap.TextWrapper.expand_tabs" title="textwrap.TextWrapper.expand_tabs"><code class="xref py py-attr docutils literal notranslate"><span class="pre">expand_tabs</span></code></a> is true, then all tab characters
  310. in <em>text</em> will be expanded to zero or more spaces, depending on the
  311. current column and the given tab size.</p>
  312. <div class="versionadded">
  313. <p><span class="versionmodified added">New in version 3.3.</span></p>
  314. </div>
  315. </dd></dl>
  316. <dl class="py attribute">
  317. <dt class="sig sig-object py" id="textwrap.TextWrapper.replace_whitespace">
  318. <span class="sig-name descname"><span class="pre">replace_whitespace</span></span><a class="headerlink" href="#textwrap.TextWrapper.replace_whitespace" title="Link to this definition">¶</a></dt>
  319. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">True</span></code>) If true, after tab expansion but before wrapping,
  320. the <a class="reference internal" href="#textwrap.wrap" title="textwrap.wrap"><code class="xref py py-meth docutils literal notranslate"><span class="pre">wrap()</span></code></a> method will replace each whitespace character
  321. with a single space. The whitespace characters replaced are
  322. as follows: tab, newline, vertical tab, formfeed, and carriage
  323. return (<code class="docutils literal notranslate"><span class="pre">'\t\n\v\f\r'</span></code>).</p>
  324. <div class="admonition note">
  325. <p class="admonition-title">Note</p>
  326. <p>If <a class="reference internal" href="#textwrap.TextWrapper.expand_tabs" title="textwrap.TextWrapper.expand_tabs"><code class="xref py py-attr docutils literal notranslate"><span class="pre">expand_tabs</span></code></a> is false and <a class="reference internal" href="#textwrap.TextWrapper.replace_whitespace" title="textwrap.TextWrapper.replace_whitespace"><code class="xref py py-attr docutils literal notranslate"><span class="pre">replace_whitespace</span></code></a> is true,
  327. each tab character will be replaced by a single space, which is <em>not</em>
  328. the same as tab expansion.</p>
  329. </div>
  330. <div class="admonition note">
  331. <p class="admonition-title">Note</p>
  332. <p>If <a class="reference internal" href="#textwrap.TextWrapper.replace_whitespace" title="textwrap.TextWrapper.replace_whitespace"><code class="xref py py-attr docutils literal notranslate"><span class="pre">replace_whitespace</span></code></a> is false, newlines may appear in the
  333. middle of a line and cause strange output. For this reason, text should
  334. be split into paragraphs (using <a class="reference internal" href="stdtypes.html#str.splitlines" title="str.splitlines"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.splitlines()</span></code></a> or similar)
  335. which are wrapped separately.</p>
  336. </div>
  337. </dd></dl>
  338. <dl class="py attribute">
  339. <dt class="sig sig-object py" id="textwrap.TextWrapper.drop_whitespace">
  340. <span class="sig-name descname"><span class="pre">drop_whitespace</span></span><a class="headerlink" href="#textwrap.TextWrapper.drop_whitespace" title="Link to this definition">¶</a></dt>
  341. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">True</span></code>) If true, whitespace at the beginning and ending of
  342. every line (after wrapping but before indenting) is dropped.
  343. Whitespace at the beginning of the paragraph, however, is not dropped
  344. if non-whitespace follows it. If whitespace being dropped takes up an
  345. entire line, the whole line is dropped.</p>
  346. </dd></dl>
  347. <dl class="py attribute">
  348. <dt class="sig sig-object py" id="textwrap.TextWrapper.initial_indent">
  349. <span class="sig-name descname"><span class="pre">initial_indent</span></span><a class="headerlink" href="#textwrap.TextWrapper.initial_indent" title="Link to this definition">¶</a></dt>
  350. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">''</span></code>) String that will be prepended to the first line of
  351. wrapped output. Counts towards the length of the first line. The empty
  352. string is not indented.</p>
  353. </dd></dl>
  354. <dl class="py attribute">
  355. <dt class="sig sig-object py" id="textwrap.TextWrapper.subsequent_indent">
  356. <span class="sig-name descname"><span class="pre">subsequent_indent</span></span><a class="headerlink" href="#textwrap.TextWrapper.subsequent_indent" title="Link to this definition">¶</a></dt>
  357. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">''</span></code>) String that will be prepended to all lines of wrapped
  358. output except the first. Counts towards the length of each line except
  359. the first.</p>
  360. </dd></dl>
  361. <dl class="py attribute">
  362. <dt class="sig sig-object py" id="textwrap.TextWrapper.fix_sentence_endings">
  363. <span class="sig-name descname"><span class="pre">fix_sentence_endings</span></span><a class="headerlink" href="#textwrap.TextWrapper.fix_sentence_endings" title="Link to this definition">¶</a></dt>
  364. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">False</span></code>) If true, <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> attempts to detect
  365. sentence endings and ensure that sentences are always separated by exactly
  366. two spaces. This is generally desired for text in a monospaced font.
  367. However, the sentence detection algorithm is imperfect: it assumes that a
  368. sentence ending consists of a lowercase letter followed by one of <code class="docutils literal notranslate"><span class="pre">'.'</span></code>,
  369. <code class="docutils literal notranslate"><span class="pre">'!'</span></code>, or <code class="docutils literal notranslate"><span class="pre">'?'</span></code>, possibly followed by one of <code class="docutils literal notranslate"><span class="pre">'&quot;'</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;'&quot;</span></code>,
  370. followed by a space. One problem with this algorithm is that it is
  371. unable to detect the difference between “Dr.” in</p>
  372. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="o">...</span><span class="p">]</span> <span class="n">Dr</span><span class="o">.</span> <span class="n">Frankenstein</span><span class="s1">&#39;s monster [...]</span>
  373. </pre></div>
  374. </div>
  375. <p>and “Spot.” in</p>
  376. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="o">...</span><span class="p">]</span> <span class="n">See</span> <span class="n">Spot</span><span class="o">.</span> <span class="n">See</span> <span class="n">Spot</span> <span class="n">run</span> <span class="p">[</span><span class="o">...</span><span class="p">]</span>
  377. </pre></div>
  378. </div>
  379. <p><a class="reference internal" href="#textwrap.TextWrapper.fix_sentence_endings" title="textwrap.TextWrapper.fix_sentence_endings"><code class="xref py py-attr docutils literal notranslate"><span class="pre">fix_sentence_endings</span></code></a> is false by default.</p>
  380. <p>Since the sentence detection algorithm relies on <code class="docutils literal notranslate"><span class="pre">string.lowercase</span></code> for
  381. the definition of “lowercase letter”, and a convention of using two spaces
  382. after a period to separate sentences on the same line, it is specific to
  383. English-language texts.</p>
  384. </dd></dl>
  385. <dl class="py attribute">
  386. <dt class="sig sig-object py" id="textwrap.TextWrapper.break_long_words">
  387. <span class="sig-name descname"><span class="pre">break_long_words</span></span><a class="headerlink" href="#textwrap.TextWrapper.break_long_words" title="Link to this definition">¶</a></dt>
  388. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">True</span></code>) If true, then words longer than <a class="reference internal" href="#textwrap.TextWrapper.width" title="textwrap.TextWrapper.width"><code class="xref py py-attr docutils literal notranslate"><span class="pre">width</span></code></a> will be
  389. broken in order to ensure that no lines are longer than <a class="reference internal" href="#textwrap.TextWrapper.width" title="textwrap.TextWrapper.width"><code class="xref py py-attr docutils literal notranslate"><span class="pre">width</span></code></a>. If
  390. it is false, long words will not be broken, and some lines may be longer
  391. than <a class="reference internal" href="#textwrap.TextWrapper.width" title="textwrap.TextWrapper.width"><code class="xref py py-attr docutils literal notranslate"><span class="pre">width</span></code></a>. (Long words will be put on a line by themselves, in
  392. order to minimize the amount by which <a class="reference internal" href="#textwrap.TextWrapper.width" title="textwrap.TextWrapper.width"><code class="xref py py-attr docutils literal notranslate"><span class="pre">width</span></code></a> is exceeded.)</p>
  393. </dd></dl>
  394. <dl class="py attribute">
  395. <dt class="sig sig-object py" id="textwrap.TextWrapper.break_on_hyphens">
  396. <span class="sig-name descname"><span class="pre">break_on_hyphens</span></span><a class="headerlink" href="#textwrap.TextWrapper.break_on_hyphens" title="Link to this definition">¶</a></dt>
  397. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">True</span></code>) If true, wrapping will occur preferably on whitespaces
  398. and right after hyphens in compound words, as it is customary in English.
  399. If false, only whitespaces will be considered as potentially good places
  400. for line breaks, but you need to set <a class="reference internal" href="#textwrap.TextWrapper.break_long_words" title="textwrap.TextWrapper.break_long_words"><code class="xref py py-attr docutils literal notranslate"><span class="pre">break_long_words</span></code></a> to false if
  401. you want truly insecable words. Default behaviour in previous versions
  402. was to always allow breaking hyphenated words.</p>
  403. </dd></dl>
  404. <dl class="py attribute">
  405. <dt class="sig sig-object py" id="textwrap.TextWrapper.max_lines">
  406. <span class="sig-name descname"><span class="pre">max_lines</span></span><a class="headerlink" href="#textwrap.TextWrapper.max_lines" title="Link to this definition">¶</a></dt>
  407. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">None</span></code>) If not <code class="docutils literal notranslate"><span class="pre">None</span></code>, then the output will contain at most
  408. <em>max_lines</em> lines, with <em>placeholder</em> appearing at the end of the output.</p>
  409. <div class="versionadded">
  410. <p><span class="versionmodified added">New in version 3.4.</span></p>
  411. </div>
  412. </dd></dl>
  413. <dl class="py attribute" id="index-0">
  414. <dt class="sig sig-object py" id="textwrap.TextWrapper.placeholder">
  415. <span class="sig-name descname"><span class="pre">placeholder</span></span><a class="headerlink" href="#textwrap.TextWrapper.placeholder" title="Link to this definition">¶</a></dt>
  416. <dd><p>(default: <code class="docutils literal notranslate"><span class="pre">'</span> <span class="pre">[...]'</span></code>) String that will appear at the end of the output
  417. text if it has been truncated.</p>
  418. <div class="versionadded">
  419. <p><span class="versionmodified added">New in version 3.4.</span></p>
  420. </div>
  421. </dd></dl>
  422. <p><a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> also provides some public methods, analogous to the
  423. module-level convenience functions:</p>
  424. <dl class="py method">
  425. <dt class="sig sig-object py" id="textwrap.TextWrapper.wrap">
  426. <span class="sig-name descname"><span class="pre">wrap</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#textwrap.TextWrapper.wrap" title="Link to this definition">¶</a></dt>
  427. <dd><p>Wraps the single paragraph in <em>text</em> (a string) so every line is at most
  428. <a class="reference internal" href="#textwrap.TextWrapper.width" title="textwrap.TextWrapper.width"><code class="xref py py-attr docutils literal notranslate"><span class="pre">width</span></code></a> characters long. All wrapping options are taken from
  429. instance attributes of the <a class="reference internal" href="#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> instance. Returns a list
  430. of output lines, without final newlines. If the wrapped output has no
  431. content, the returned list is empty.</p>
  432. </dd></dl>
  433. <dl class="py method">
  434. <dt class="sig sig-object py" id="textwrap.TextWrapper.fill">
  435. <span class="sig-name descname"><span class="pre">fill</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#textwrap.TextWrapper.fill" title="Link to this definition">¶</a></dt>
  436. <dd><p>Wraps the single paragraph in <em>text</em>, and returns a single string
  437. containing the wrapped paragraph.</p>
  438. </dd></dl>
  439. </dd></dl>
  440. </section>
  441. <div class="clearer"></div>
  442. </div>
  443. </div>
  444. </div>
  445. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  446. <div class="sphinxsidebarwrapper">
  447. <div>
  448. <h4>Previous topic</h4>
  449. <p class="topless"><a href="difflib.html"
  450. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">difflib</span></code> — Helpers for computing deltas</a></p>
  451. </div>
  452. <div>
  453. <h4>Next topic</h4>
  454. <p class="topless"><a href="unicodedata.html"
  455. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">unicodedata</span></code> — Unicode Database</a></p>
  456. </div>
  457. <div role="note" aria-label="source link">
  458. <h3>This Page</h3>
  459. <ul class="this-page-menu">
  460. <li><a href="../bugs.html">Report a Bug</a></li>
  461. <li>
  462. <a href="https://github.com/python/cpython/blob/main/Doc/library/textwrap.rst"
  463. rel="nofollow">Show Source
  464. </a>
  465. </li>
  466. </ul>
  467. </div>
  468. </div>
  469. <div id="sidebarbutton" title="Collapse sidebar">
  470. <span>«</span>
  471. </div>
  472. </div>
  473. <div class="clearer"></div>
  474. </div>
  475. <div class="related" role="navigation" aria-label="related navigation">
  476. <h3>Navigation</h3>
  477. <ul>
  478. <li class="right" style="margin-right: 10px">
  479. <a href="../genindex.html" title="General Index"
  480. >index</a></li>
  481. <li class="right" >
  482. <a href="../py-modindex.html" title="Python Module Index"
  483. >modules</a> |</li>
  484. <li class="right" >
  485. <a href="unicodedata.html" title="unicodedata — Unicode Database"
  486. >next</a> |</li>
  487. <li class="right" >
  488. <a href="difflib.html" title="difflib — Helpers for computing deltas"
  489. >previous</a> |</li>
  490. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  491. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  492. <li class="switchers">
  493. <div class="language_switcher_placeholder"></div>
  494. <div class="version_switcher_placeholder"></div>
  495. </li>
  496. <li>
  497. </li>
  498. <li id="cpython-language-and-version">
  499. <a href="../index.html">3.12.3 Documentation</a> &#187;
  500. </li>
  501. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  502. <li class="nav-item nav-item-2"><a href="text.html" >Text Processing Services</a> &#187;</li>
  503. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">textwrap</span></code> — Text wrapping and filling</a></li>
  504. <li class="right">
  505. <div class="inline-search" role="search">
  506. <form class="inline-search" action="../search.html" method="get">
  507. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  508. <input type="submit" value="Go" />
  509. </form>
  510. </div>
  511. |
  512. </li>
  513. <li class="right">
  514. <label class="theme-selector-label">
  515. Theme
  516. <select class="theme-selector" oninput="activateTheme(this.value)">
  517. <option value="auto" selected>Auto</option>
  518. <option value="light">Light</option>
  519. <option value="dark">Dark</option>
  520. </select>
  521. </label> |</li>
  522. </ul>
  523. </div>
  524. <div class="footer">
  525. &copy;
  526. <a href="../copyright.html">
  527. Copyright
  528. </a>
  529. 2001-2024, Python Software Foundation.
  530. <br />
  531. This page is licensed under the Python Software Foundation License Version 2.
  532. <br />
  533. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  534. <br />
  535. See <a href="/license.html">History and License</a> for more information.<br />
  536. <br />
  537. The Python Software Foundation is a non-profit corporation.
  538. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  539. <br />
  540. <br />
  541. Last updated on Apr 09, 2024 (13:47 UTC).
  542. <a href="/bugs.html">Found a bug</a>?
  543. <br />
  544. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  545. </div>
  546. </body>
  547. </html>
上海开阖软件有限公司 沪ICP备12045867号-1