Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
readline.html800 linesDownload Raw Back to docs
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4  <head>5    <meta charset="utf-8" />6    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="readline — GNU readline interface" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/readline.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="The readline module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. This module can be used directly, or via the rlcompleter..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_readline_3bf68a8f.png" />15<meta property="og:image:alt" content="The readline module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. This module can be used directly, or via the rlcompleter..." />16<meta name="description" content="The readline module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. This module can be used directly, or via the rlcompleter..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>readline — GNU readline interface &#8212; Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21    22    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25    <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26    <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27    28    <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29    <script src="../_static/doctools.js?v=9bcbadda"></script>30    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31    <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32    33    <script src="../_static/sidebar.js"></script>34    35    <link rel="search" type="application/opensearchdescription+xml"36          title="Search within Python 3.15.0a6 documentation"37          href="../_static/opensearch.xml"/>38    <link rel="author" title="About these documents" href="../about.html" />39    <link rel="index" title="Index" href="../genindex.html" />40    <link rel="search" title="Search" href="../search.html" />41    <link rel="copyright" title="Copyright" href="../copyright.html" />42    <link rel="next" title="rlcompleter — Completion function for GNU readline" href="rlcompleter.html" />43    <link rel="prev" title="stringprep — Internet String Preparation" href="stringprep.html" />44    45      46      <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47      48      <link rel="canonical" href="https://docs.python.org/3/library/readline.html">49      50    51 52    53    <style>54      @media only screen {55        table.full-width-table {56            width: 100%;57        }58      }59    </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61    <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62            <script type="text/javascript" src="../_static/copybutton.js"></script>63            <script type="text/javascript" src="../_static/menu.js"></script>64            <script type="text/javascript" src="../_static/search-focus.js"></script>65            <script type="text/javascript" src="../_static/themetoggle.js"></script> 66            <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67            <meta name="readthedocs-addons-api-version" content="1">68 69  </head>70<body>71<div class="mobile-nav">72    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74    <nav class="nav-content" role="navigation">75        <label for="menuToggler" class="toggler__label">76            <span></span>77        </label>78        <span class="nav-items-wrapper">79            <a href="https://www.python.org/" class="nav-logo">80                <img src="../_static/py.svg" alt="Python logo">81            </a>82            <span class="version_switcher_placeholder"></span>83            <form role="search" class="search" action="../search.html" method="get">84                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85                    <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>86                </svg>87                <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88                <input type="submit" value="Go">89            </form>90        </span>91    </nav>92    <div class="menu-wrapper">93        <nav class="menu" role="navigation" aria-label="main navigation">94            <div class="language_switcher_placeholder"></div>95            96<label class="theme-selector-label">97    Theme98    <select class="theme-selector" oninput="activateTheme(this.value)">99        <option value="auto" selected>Auto</option>100        <option value="light">Light</option>101        <option value="dark">Dark</option>102    </select>103</label>104  <div>105    <h3><a href="../contents.html">Table of Contents</a></h3>106    <ul>107<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> — GNU readline interface</a><ul>108<li><a class="reference internal" href="#init-file">Init file</a></li>109<li><a class="reference internal" href="#line-buffer">Line buffer</a></li>110<li><a class="reference internal" href="#history-file">History file</a></li>111<li><a class="reference internal" href="#history-list">History list</a></li>112<li><a class="reference internal" href="#startup-hooks">Startup hooks</a></li>113<li><a class="reference internal" href="#completion">Completion</a></li>114<li><a class="reference internal" href="#example">Example</a></li>115</ul>116</li>117</ul>118 119  </div>120  <div>121    <h4>Previous topic</h4>122    <p class="topless"><a href="stringprep.html"123                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stringprep</span></code> — Internet String Preparation</a></p>124  </div>125  <div>126    <h4>Next topic</h4>127    <p class="topless"><a href="rlcompleter.html"128                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">rlcompleter</span></code> — Completion function for GNU readline</a></p>129  </div>130  <script>131    document.addEventListener('DOMContentLoaded', () => {132        const title = document.querySelector('meta[property="og:title"]').content;133        const elements = document.querySelectorAll('.improvepage');134        const pageurl = window.location.href.split('?')[0];135        elements.forEach(element => {136            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));137            url.searchParams.set('pagetitle', title);138            url.searchParams.set('pageurl', pageurl);139            url.searchParams.set('pagesource', "library/readline.rst");140            element.href = url.toString();141        });142    });143  </script>144  <div role="note" aria-label="source link">145    <h3>This page</h3>146    <ul class="this-page-menu">147      <li><a href="../bugs.html">Report a bug</a></li>148      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>149      <li>150        <a href="https://github.com/python/cpython/blob/main/Doc/library/readline.rst?plain=1"151            rel="nofollow">Show source152        </a>153      </li>154      155    </ul>156  </div>157        </nav>158    </div>159</div>160 161  162    <div class="related" role="navigation" aria-label="Related">163      <h3>Navigation</h3>164      <ul>165        <li class="right" style="margin-right: 10px">166          <a href="../genindex.html" title="General Index"167             accesskey="I">index</a></li>168        <li class="right" >169          <a href="../py-modindex.html" title="Python Module Index"170             >modules</a> |</li>171        <li class="right" >172          <a href="rlcompleter.html" title="rlcompleter — Completion function for GNU readline"173             accesskey="N">next</a> |</li>174        <li class="right" >175          <a href="stringprep.html" title="stringprep — Internet String Preparation"176             accesskey="P">previous</a> |</li>177 178          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>179          <li><a href="https://www.python.org/">Python</a> &#187;</li>180          <li class="switchers">181            <div class="language_switcher_placeholder"></div>182            <div class="version_switcher_placeholder"></div>183          </li>184          <li>185              186          </li>187    <li id="cpython-language-and-version">188      <a href="../index.html">3.15.0a6 Documentation</a> &#187;189    </li>190 191          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>192          <li class="nav-item nav-item-2"><a href="text.html" accesskey="U">Text Processing Services</a> &#187;</li>193        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> — GNU readline interface</a></li>194                <li class="right">195                    196 197    <div class="inline-search" role="search">198        <form class="inline-search" action="../search.html" method="get">199          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">200          <input type="submit" value="Go">201        </form>202    </div>203                     |204                </li>205            <li class="right">206<label class="theme-selector-label">207    Theme208    <select class="theme-selector" oninput="activateTheme(this.value)">209        <option value="auto" selected>Auto</option>210        <option value="light">Light</option>211        <option value="dark">Dark</option>212    </select>213</label> |</li>214            215      </ul>216    </div>    217 218    <div class="document">219      <div class="documentwrapper">220        <div class="bodywrapper">221          <div class="body" role="main">222            223  <section id="module-readline">224<span id="readline-gnu-readline-interface"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> — GNU readline interface<a class="headerlink" href="#module-readline" title="Link to this heading">¶</a></h1>225<hr class="docutils" />226<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> module defines a number of functions to facilitate227completion and reading/writing of history files from the Python interpreter.228This module can be used directly, or via the <a class="reference internal" href="rlcompleter.html#module-rlcompleter" title="rlcompleter: Python identifier completion, suitable for the GNU readline library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">rlcompleter</span></code></a> module, which229supports completion of Python identifiers at the interactive prompt.  Settings230made using  this module affect the behaviour of both the interpreter’s231interactive prompt  and the prompts offered by the built-in <a class="reference internal" href="functions.html#input" title="input"><code class="xref py py-func docutils literal notranslate"><span class="pre">input()</span></code></a>232function.</p>233<p>Readline keybindings may be configured via an initialization file, typically234<code class="docutils literal notranslate"><span class="pre">.inputrc</span></code> in your home directory.  See <a class="reference external" href="https://tiswww.cwru.edu/php/chet/readline/rluserman.html#Readline-Init-File">Readline Init File</a>235in the GNU Readline manual for information about the format and236allowable constructs of that file, and the capabilities of the237Readline library in general.</p>238<div class="availability docutils container">239<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not Android, not iOS, not WASI.</p>240<p>This module is not supported on <a class="reference internal" href="intro.html#mobile-availability"><span class="std std-ref">mobile platforms</span></a>241or <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a>.</p>242</div>243<p>This is an <a class="reference internal" href="../glossary.html#term-optional-module"><span class="xref std std-term">optional module</span></a>.244If it is missing from your copy of CPython,245look for documentation from your distributor (that is,246whoever provided Python to you).247If you are the distributor, see <a class="reference internal" href="../using/configure.html#optional-module-requirements"><span class="std std-ref">Requirements for optional modules</span></a>.</p>248<div class="availability docutils container">249<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>250</div>251<div class="admonition note">252<p class="admonition-title">Note</p>253<p>The underlying Readline library API may be implemented by254the <code class="docutils literal notranslate"><span class="pre">editline</span></code> (<code class="docutils literal notranslate"><span class="pre">libedit</span></code>) library instead of GNU readline.255On macOS the <code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> module detects which library is being used256at run time.</p>257<p>The configuration file for <code class="docutils literal notranslate"><span class="pre">editline</span></code> is different from that258of GNU readline. If you programmatically load configuration strings259you can use <a class="reference internal" href="#readline.backend" title="readline.backend"><code class="xref py py-data docutils literal notranslate"><span class="pre">backend</span></code></a> to determine which library is being used.</p>260<p>If you use <code class="docutils literal notranslate"><span class="pre">editline</span></code>/<code class="docutils literal notranslate"><span class="pre">libedit</span></code> readline emulation on macOS, the261initialization file located in your home directory is named262<code class="docutils literal notranslate"><span class="pre">.editrc</span></code>. For example, the following content in <code class="docutils literal notranslate"><span class="pre">~/.editrc</span></code> will263turn ON <em>vi</em> keybindings and TAB completion:</p>264<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span><span class="p">:</span><span class="n">bind</span> <span class="o">-</span><span class="n">v</span>265<span class="n">python</span><span class="p">:</span><span class="n">bind</span> <span class="o">^</span><span class="n">I</span> <span class="n">rl_complete</span>266</pre></div>267</div>268<p>Also note that different libraries may use different history file formats.269When switching the underlying library, existing history files may become270unusable.</p>271</div>272<dl class="py data">273<dt class="sig sig-object py" id="readline.backend">274<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">backend</span></span><a class="headerlink" href="#readline.backend" title="Link to this definition">¶</a></dt>275<dd><p>The name of the underlying Readline library being used, either276<code class="docutils literal notranslate"><span class="pre">&quot;readline&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;editline&quot;</span></code>.</p>277<div class="versionadded">278<p><span class="versionmodified added">Added in version 3.13.</span></p>279</div>280</dd></dl>281 282<section id="init-file">283<h2>Init file<a class="headerlink" href="#init-file" title="Link to this heading">¶</a></h2>284<p>The following functions relate to the init file and user configuration:</p>285<dl class="py function">286<dt class="sig sig-object py" id="readline.parse_and_bind">287<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">parse_and_bind</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#readline.parse_and_bind" title="Link to this definition">¶</a></dt>288<dd><p>Execute the init line provided in the <em>string</em> argument. This calls289<code class="xref c c-func docutils literal notranslate"><span class="pre">rl_parse_and_bind()</span></code> in the underlying library.</p>290</dd></dl>291 292<dl class="py function">293<dt class="sig sig-object py" id="readline.read_init_file">294<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">read_init_file</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.read_init_file" title="Link to this definition">¶</a></dt>295<dd><p>Execute a readline initialization file. The default filename is the last filename296used. This calls <code class="xref c c-func docutils literal notranslate"><span class="pre">rl_read_init_file()</span></code> in the underlying library.297It raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">open</span></code> with the file name298if given, and <code class="code docutils literal notranslate"><span class="pre">&quot;&lt;readline_init_file&gt;&quot;</span></code> otherwise, regardless of299which file the library resolves.</p>300<div class="versionchanged">301<p><span class="versionmodified changed">Changed in version 3.14: </span>The auditing event was added.</p>302</div>303</dd></dl>304 305</section>306<section id="line-buffer">307<h2>Line buffer<a class="headerlink" href="#line-buffer" title="Link to this heading">¶</a></h2>308<p>The following functions operate on the line buffer:</p>309<dl class="py function">310<dt class="sig sig-object py" id="readline.get_line_buffer">311<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">get_line_buffer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.get_line_buffer" title="Link to this definition">¶</a></dt>312<dd><p>Return the current contents of the line buffer (<code class="xref c c-data docutils literal notranslate"><span class="pre">rl_line_buffer</span></code>313in the underlying library).</p>314</dd></dl>315 316<dl class="py function">317<dt class="sig sig-object py" id="readline.insert_text">318<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">insert_text</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#readline.insert_text" title="Link to this definition">¶</a></dt>319<dd><p>Insert text into the line buffer at the cursor position.  This calls320<code class="xref c c-func docutils literal notranslate"><span class="pre">rl_insert_text()</span></code> in the underlying library, but ignores321the return value.</p>322</dd></dl>323 324<dl class="py function">325<dt class="sig sig-object py" id="readline.redisplay">326<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">redisplay</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.redisplay" title="Link to this definition">¶</a></dt>327<dd><p>Change what’s displayed on the screen to reflect the current contents of the328line buffer.  This calls <code class="xref c c-func docutils literal notranslate"><span class="pre">rl_redisplay()</span></code> in the underlying library.</p>329</dd></dl>330 331</section>332<section id="history-file">333<h2>History file<a class="headerlink" href="#history-file" title="Link to this heading">¶</a></h2>334<p>The following functions operate on a history file:</p>335<dl class="py function">336<dt class="sig sig-object py" id="readline.read_history_file">337<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">read_history_file</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.read_history_file" title="Link to this definition">¶</a></dt>338<dd><p>Load a readline history file, and append it to the history list.339The default filename is <code class="file docutils literal notranslate"><span class="pre">~/.history</span></code>.  This calls340<code class="xref c c-func docutils literal notranslate"><span class="pre">read_history()</span></code> in the underlying library341and raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">open</span></code> with the file342name if given and <code class="code docutils literal notranslate"><span class="pre">&quot;~/.history&quot;</span></code> otherwise.</p>343<div class="versionchanged">344<p><span class="versionmodified changed">Changed in version 3.14: </span>The auditing event was added.</p>345</div>346</dd></dl>347 348<dl class="py function">349<dt class="sig sig-object py" id="readline.write_history_file">350<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">write_history_file</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.write_history_file" title="Link to this definition">¶</a></dt>351<dd><p>Save the history list to a readline history file, overwriting any352existing file.  The default filename is <code class="file docutils literal notranslate"><span class="pre">~/.history</span></code>.  This calls353<code class="xref c c-func docutils literal notranslate"><span class="pre">write_history()</span></code> in the underlying library and raises an354<a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">open</span></code> with the file name if given and355<code class="code docutils literal notranslate"><span class="pre">&quot;~/.history&quot;</span></code> otherwise.</p>356<div class="versionchanged">357<p><span class="versionmodified changed">Changed in version 3.14: </span>The auditing event was added.</p>358</div>359</dd></dl>360 361<dl class="py function">362<dt class="sig sig-object py" id="readline.append_history_file">363<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">append_history_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">nelements</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.append_history_file" title="Link to this definition">¶</a></dt>364<dd><p>Append the last <em>nelements</em> items of history to a file.  The default filename is365<code class="file docutils literal notranslate"><span class="pre">~/.history</span></code>.  The file must already exist.  This calls366<code class="xref c c-func docutils literal notranslate"><span class="pre">append_history()</span></code> in the underlying library.  This function367only exists if Python was compiled for a version of the library368that supports it. It raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">open</span></code>369with the file name if given and <code class="code docutils literal notranslate"><span class="pre">&quot;~/.history&quot;</span></code> otherwise.</p>370<div class="versionadded">371<p><span class="versionmodified added">Added in version 3.5.</span></p>372</div>373<div class="versionchanged">374<p><span class="versionmodified changed">Changed in version 3.14: </span>The auditing event was added.</p>375</div>376</dd></dl>377 378<dl class="py function">379<dt class="sig sig-object py" id="readline.get_history_length">380<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">get_history_length</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.get_history_length" title="Link to this definition">¶</a></dt>381<dt class="sig sig-object py" id="readline.set_history_length">382<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">set_history_length</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">length</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#readline.set_history_length" title="Link to this definition">¶</a></dt>383<dd><p>Set or return the desired number of lines to save in the history file.384The <a class="reference internal" href="#readline.write_history_file" title="readline.write_history_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">write_history_file()</span></code></a> function uses this value to truncate385the history file, by calling <code class="xref c c-func docutils literal notranslate"><span class="pre">history_truncate_file()</span></code> in386the underlying library.  Negative values imply387unlimited history file size.</p>388</dd></dl>389 390</section>391<section id="history-list">392<h2>History list<a class="headerlink" href="#history-list" title="Link to this heading">¶</a></h2>393<p>The following functions operate on a global history list:</p>394<dl class="py function">395<dt class="sig sig-object py" id="readline.clear_history">396<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">clear_history</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.clear_history" title="Link to this definition">¶</a></dt>397<dd><p>Clear the current history.  This calls <code class="xref c c-func docutils literal notranslate"><span class="pre">clear_history()</span></code> in the398underlying library.  The Python function only exists if Python was399compiled for a version of the library that supports it.</p>400</dd></dl>401 402<dl class="py function">403<dt class="sig sig-object py" id="readline.get_current_history_length">404<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">get_current_history_length</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.get_current_history_length" title="Link to this definition">¶</a></dt>405<dd><p>Return the number of items currently in the history.  (This is different from406<a class="reference internal" href="#readline.get_history_length" title="readline.get_history_length"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_history_length()</span></code></a>, which returns the maximum number of lines that will407be written to a history file.)</p>408</dd></dl>409 410<dl class="py function">411<dt class="sig sig-object py" id="readline.get_history_item">412<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">get_history_item</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">index</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#readline.get_history_item" title="Link to this definition">¶</a></dt>413<dd><p>Return the current contents of history item at <em>index</em>.  The item index414is one-based.  This calls <code class="xref c c-func docutils literal notranslate"><span class="pre">history_get()</span></code> in the underlying library.</p>415</dd></dl>416 417<dl class="py function">418<dt class="sig sig-object py" id="readline.remove_history_item">419<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">remove_history_item</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pos</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#readline.remove_history_item" title="Link to this definition">¶</a></dt>420<dd><p>Remove history item specified by its position from the history.421The position is zero-based.  This calls <code class="xref c c-func docutils literal notranslate"><span class="pre">remove_history()</span></code> in422the underlying library.</p>423</dd></dl>424 425<dl class="py function">426<dt class="sig sig-object py" id="readline.replace_history_item">427<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">replace_history_item</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pos</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">line</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#readline.replace_history_item" title="Link to this definition">¶</a></dt>428<dd><p>Replace history item specified by its position with <em>line</em>.429The position is zero-based.  This calls <code class="xref c c-func docutils literal notranslate"><span class="pre">replace_history_entry()</span></code>430in the underlying library.</p>431</dd></dl>432 433<dl class="py function">434<dt class="sig sig-object py" id="readline.add_history">435<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">add_history</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">line</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#readline.add_history" title="Link to this definition">¶</a></dt>436<dd><p>Append <em>line</em> to the history buffer, as if it was the last line typed.437This calls <code class="xref c c-func docutils literal notranslate"><span class="pre">add_history()</span></code> in the underlying library.</p>438</dd></dl>439 440<dl class="py function">441<dt class="sig sig-object py" id="readline.set_auto_history">442<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">set_auto_history</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">enabled</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#readline.set_auto_history" title="Link to this definition">¶</a></dt>443<dd><p>Enable or disable automatic calls to <code class="xref c c-func docutils literal notranslate"><span class="pre">add_history()</span></code> when reading444input via readline.  The <em>enabled</em> argument should be a Boolean value445that when true, enables auto history, and that when false, disables446auto history.</p>447<div class="versionadded">448<p><span class="versionmodified added">Added in version 3.6.</span></p>449</div>450<div class="impl-detail compound">451<p><strong>CPython implementation detail:</strong> Auto history is enabled by default, and changes to this do not persist452across multiple sessions.</p>453</div>454</dd></dl>455 456</section>457<section id="startup-hooks">458<h2>Startup hooks<a class="headerlink" href="#startup-hooks" title="Link to this heading">¶</a></h2>459<dl class="py function">460<dt class="sig sig-object py" id="readline.set_startup_hook">461<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">set_startup_hook</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.set_startup_hook" title="Link to this definition">¶</a></dt>462<dd><p>Set or remove the function invoked by the <code class="xref c c-data docutils literal notranslate"><span class="pre">rl_startup_hook</span></code>463callback of the underlying library.  If <em>function</em> is specified, it will464be used as the new hook function; if omitted or <code class="docutils literal notranslate"><span class="pre">None</span></code>, any function465already installed is removed.  The hook is called with no466arguments just before readline prints the first prompt.</p>467</dd></dl>468 469<dl class="py function">470<dt class="sig sig-object py" id="readline.set_pre_input_hook">471<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">set_pre_input_hook</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.set_pre_input_hook" title="Link to this definition">¶</a></dt>472<dd><p>Set or remove the function invoked by the <code class="xref c c-data docutils literal notranslate"><span class="pre">rl_pre_input_hook</span></code>473callback of the underlying library.  If <em>function</em> is specified, it will474be used as the new hook function; if omitted or <code class="docutils literal notranslate"><span class="pre">None</span></code>, any475function already installed is removed.  The hook is called476with no arguments after the first prompt has been printed and just before477readline starts reading input characters.  This function only exists478if Python was compiled for a version of the library that supports it.</p>479</dd></dl>480 481<dl class="py function">482<dt class="sig sig-object py" id="readline.get_pre_input_hook">483<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">get_pre_input_hook</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.get_pre_input_hook" title="Link to this definition">¶</a></dt>484<dd><p>Get the current pre-input hook function, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if no pre-input hook485function has been set.  This function only exists if Python was compiled486for a version of the library that supports it.</p>487<div class="versionadded">488<p><span class="versionmodified added">Added in version 3.15.</span></p>489</div>490</dd></dl>491 492</section>493<section id="completion">494<span id="readline-completion"></span><h2>Completion<a class="headerlink" href="#completion" title="Link to this heading">¶</a></h2>495<p>The following functions relate to implementing a custom word completion496function.  This is typically operated by the Tab key, and can suggest and497automatically complete a word being typed.  By default, Readline is set up498to be used by <a class="reference internal" href="rlcompleter.html#module-rlcompleter" title="rlcompleter: Python identifier completion, suitable for the GNU readline library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">rlcompleter</span></code></a> to complete Python identifiers for499the interactive interpreter.  If the <code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> module is to be used500with a custom completer, a different set of word delimiters should be set.</p>501<dl class="py function">502<dt class="sig sig-object py" id="readline.set_completer">503<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">set_completer</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.set_completer" title="Link to this definition">¶</a></dt>504<dd><p>Set or remove the completer function.  If <em>function</em> is specified, it will be505used as the new completer function; if omitted or <code class="docutils literal notranslate"><span class="pre">None</span></code>, any completer506function already installed is removed.  The completer function is called as507<code class="docutils literal notranslate"><span class="pre">function(text,</span> <span class="pre">state)</span></code>, for <em>state</em> in <code class="docutils literal notranslate"><span class="pre">0</span></code>, <code class="docutils literal notranslate"><span class="pre">1</span></code>, <code class="docutils literal notranslate"><span class="pre">2</span></code>, …, until it508returns a non-string value.  It should return the next possible completion509starting with <em>text</em>.</p>510<p>The installed completer function is invoked by the <em>entry_func</em> callback511passed to <code class="xref c c-func docutils literal notranslate"><span class="pre">rl_completion_matches()</span></code> in the underlying library.512The <em>text</em> string comes from the first parameter to the513<code class="xref c c-data docutils literal notranslate"><span class="pre">rl_attempted_completion_function</span></code> callback of the514underlying library.</p>515</dd></dl>516 517<dl class="py function">518<dt class="sig sig-object py" id="readline.get_completer">519<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">get_completer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.get_completer" title="Link to this definition">¶</a></dt>520<dd><p>Get the completer function, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if no completer function has been set.</p>521</dd></dl>522 523<dl class="py function">524<dt class="sig sig-object py" id="readline.get_completion_type">525<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">get_completion_type</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.get_completion_type" title="Link to this definition">¶</a></dt>526<dd><p>Get the type of completion being attempted.  This returns the527<code class="xref c c-data docutils literal notranslate"><span class="pre">rl_completion_type</span></code> variable in the underlying library as528an integer.</p>529</dd></dl>530 531<dl class="py function">532<dt class="sig sig-object py" id="readline.get_begidx">533<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">get_begidx</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.get_begidx" title="Link to this definition">¶</a></dt>534<dt class="sig sig-object py" id="readline.get_endidx">535<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">get_endidx</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.get_endidx" title="Link to this definition">¶</a></dt>536<dd><p>Get the beginning or ending index of the completion scope.537These indexes are the <em>start</em> and <em>end</em> arguments passed to the538<code class="xref c c-data docutils literal notranslate"><span class="pre">rl_attempted_completion_function</span></code> callback of the539underlying library.  The values may be different in the same540input editing scenario based on the underlying C readline implementation.541Ex: libedit is known to behave differently than libreadline.</p>542</dd></dl>543 544<dl class="py function">545<dt class="sig sig-object py" id="readline.set_completer_delims">546<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">set_completer_delims</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#readline.set_completer_delims" title="Link to this definition">¶</a></dt>547<dt class="sig sig-object py" id="readline.get_completer_delims">548<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">get_completer_delims</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.get_completer_delims" title="Link to this definition">¶</a></dt>549<dd><p>Set or get the word delimiters for completion.  These determine the550start of the word to be considered for completion (the completion scope).551These functions access the <code class="xref c c-data docutils literal notranslate"><span class="pre">rl_completer_word_break_characters</span></code>552variable in the underlying library.</p>553</dd></dl>554 555<dl class="py function">556<dt class="sig sig-object py" id="readline.set_completion_display_matches_hook">557<span class="sig-prename descclassname"><span class="pre">readline.</span></span><span class="sig-name descname"><span class="pre">set_completion_display_matches_hook</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#readline.set_completion_display_matches_hook" title="Link to this definition">¶</a></dt>558<dd><p>Set or remove the completion display function.  If <em>function</em> is559specified, it will be used as the new completion display function;560if omitted or <code class="docutils literal notranslate"><span class="pre">None</span></code>, any completion display function already561installed is removed.  This sets or clears the562<code class="xref c c-data docutils literal notranslate"><span class="pre">rl_completion_display_matches_hook</span></code> callback in the563underlying library.  The completion display function is called as564<code class="docutils literal notranslate"><span class="pre">function(substitution,</span> <span class="pre">[matches],</span> <span class="pre">longest_match_length)</span></code> once565each time matches need to be displayed.</p>566</dd></dl>567 568</section>569<section id="example">570<span id="readline-example"></span><h2>Example<a class="headerlink" href="#example" title="Link to this heading">¶</a></h2>571<p>The following example demonstrates how to use the <code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> module’s572history reading and writing functions to automatically load and save a history573file named <code class="file docutils literal notranslate"><span class="pre">.python_history</span></code> from the user’s home directory.  The code574below would normally be executed automatically during interactive sessions575from the user’s <span class="target" id="index-0"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a> file.</p>576<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">atexit</span>577<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>578<span class="kn">import</span><span class="w"> </span><span class="nn">readline</span>579 580<span class="n">histfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="s2">&quot;~&quot;</span><span class="p">),</span> <span class="s2">&quot;.python_history&quot;</span><span class="p">)</span>581<span class="k">try</span><span class="p">:</span>582    <span class="n">readline</span><span class="o">.</span><span class="n">read_history_file</span><span class="p">(</span><span class="n">histfile</span><span class="p">)</span>583    <span class="c1"># default history len is -1 (infinite), which may grow unruly</span>584    <span class="n">readline</span><span class="o">.</span><span class="n">set_history_length</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span>585<span class="k">except</span> <span class="ne">FileNotFoundError</span><span class="p">:</span>586    <span class="k">pass</span>587 588<span class="n">atexit</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">readline</span><span class="o">.</span><span class="n">write_history_file</span><span class="p">,</span> <span class="n">histfile</span><span class="p">)</span>589</pre></div>590</div>591<p>This code is actually automatically run when Python is run in592<a class="reference internal" href="../tutorial/interpreter.html#tut-interactive"><span class="std std-ref">interactive mode</span></a> (see <a class="reference internal" href="site.html#rlcompleter-config"><span class="std std-ref">Readline configuration</span></a>).</p>593<p>The following example achieves the same goal but supports concurrent interactive594sessions, by only appending the new history.</p>595<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">atexit</span>596<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>597<span class="kn">import</span><span class="w"> </span><span class="nn">readline</span>598<span class="n">histfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="s2">&quot;~&quot;</span><span class="p">),</span> <span class="s2">&quot;.python_history&quot;</span><span class="p">)</span>599 600<span class="k">try</span><span class="p">:</span>601    <span class="n">readline</span><span class="o">.</span><span class="n">read_history_file</span><span class="p">(</span><span class="n">histfile</span><span class="p">)</span>602    <span class="n">h_len</span> <span class="o">=</span> <span class="n">readline</span><span class="o">.</span><span class="n">get_current_history_length</span><span class="p">()</span>603<span class="k">except</span> <span class="ne">FileNotFoundError</span><span class="p">:</span>604    <span class="nb">open</span><span class="p">(</span><span class="n">histfile</span><span class="p">,</span> <span class="s1">&#39;wb&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>605    <span class="n">h_len</span> <span class="o">=</span> <span class="mi">0</span>606 607<span class="k">def</span><span class="w"> </span><span class="nf">save</span><span class="p">(</span><span class="n">prev_h_len</span><span class="p">,</span> <span class="n">histfile</span><span class="p">):</span>608    <span class="n">new_h_len</span> <span class="o">=</span> <span class="n">readline</span><span class="o">.</span><span class="n">get_current_history_length</span><span class="p">()</span>609    <span class="n">readline</span><span class="o">.</span><span class="n">set_history_length</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span>610    <span class="n">readline</span><span class="o">.</span><span class="n">append_history_file</span><span class="p">(</span><span class="n">new_h_len</span> <span class="o">-</span> <span class="n">prev_h_len</span><span class="p">,</span> <span class="n">histfile</span><span class="p">)</span>611<span class="n">atexit</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">save</span><span class="p">,</span> <span class="n">h_len</span><span class="p">,</span> <span class="n">histfile</span><span class="p">)</span>612</pre></div>613</div>614<p>The following example extends the <a class="reference internal" href="code.html#code.InteractiveConsole" title="code.InteractiveConsole"><code class="xref py py-class docutils literal notranslate"><span class="pre">code.InteractiveConsole</span></code></a> class to615support history save/restore.</p>616<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">atexit</span>617<span class="kn">import</span><span class="w"> </span><span class="nn">code</span>618<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>619<span class="kn">import</span><span class="w"> </span><span class="nn">readline</span>620 621<span class="k">class</span><span class="w"> </span><span class="nc">HistoryConsole</span><span class="p">(</span><span class="n">code</span><span class="o">.</span><span class="n">InteractiveConsole</span><span class="p">):</span>622    <span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">locals</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="s2">&quot;&lt;console&gt;&quot;</span><span class="p">,</span>623                 <span class="n">histfile</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="s2">&quot;~/.console-history&quot;</span><span class="p">)):</span>624        <span class="n">code</span><span class="o">.</span><span class="n">InteractiveConsole</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">locals</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>625        <span class="bp">self</span><span class="o">.</span><span class="n">init_history</span><span class="p">(</span><span class="n">histfile</span><span class="p">)</span>626 627    <span class="k">def</span><span class="w"> </span><span class="nf">init_history</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">histfile</span><span class="p">):</span>628        <span class="n">readline</span><span class="o">.</span><span class="n">parse_and_bind</span><span class="p">(</span><span class="s2">&quot;tab: complete&quot;</span><span class="p">)</span>629        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">readline</span><span class="p">,</span> <span class="s2">&quot;read_history_file&quot;</span><span class="p">):</span>630            <span class="k">try</span><span class="p">:</span>631                <span class="n">readline</span><span class="o">.</span><span class="n">read_history_file</span><span class="p">(</span><span class="n">histfile</span><span class="p">)</span>632            <span class="k">except</span> <span class="ne">FileNotFoundError</span><span class="p">:</span>633                <span class="k">pass</span>634            <span class="n">atexit</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">save_history</span><span class="p">,</span> <span class="n">histfile</span><span class="p">)</span>635 636    <span class="k">def</span><span class="w"> </span><span class="nf">save_history</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">histfile</span><span class="p">):</span>637        <span class="n">readline</span><span class="o">.</span><span class="n">set_history_length</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span>638        <span class="n">readline</span><span class="o">.</span><span class="n">write_history_file</span><span class="p">(</span><span class="n">histfile</span><span class="p">)</span>639</pre></div>640</div>641<div class="admonition note">642<p class="admonition-title">Note</p>643<p>The new <a class="reference internal" href="../glossary.html#term-REPL"><span class="xref std std-term">REPL</span></a> introduced in version 3.13 doesn’t support readline.644However, readline can still be used by setting the <span class="target" id="index-1"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_BASIC_REPL"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_BASIC_REPL</span></code></a>645environment variable.</p>646</div>647</section>648</section>649 650 651            <div class="clearer"></div>652          </div>653        </div>654      </div>655      <div class="sphinxsidebar" role="navigation" aria-label="Main">656        <div class="sphinxsidebarwrapper">657  <div>658    <h3><a href="../contents.html">Table of Contents</a></h3>659    <ul>660<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> — GNU readline interface</a><ul>661<li><a class="reference internal" href="#init-file">Init file</a></li>662<li><a class="reference internal" href="#line-buffer">Line buffer</a></li>663<li><a class="reference internal" href="#history-file">History file</a></li>664<li><a class="reference internal" href="#history-list">History list</a></li>665<li><a class="reference internal" href="#startup-hooks">Startup hooks</a></li>666<li><a class="reference internal" href="#completion">Completion</a></li>667<li><a class="reference internal" href="#example">Example</a></li>668</ul>669</li>670</ul>671 672  </div>673  <div>674    <h4>Previous topic</h4>675    <p class="topless"><a href="stringprep.html"676                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stringprep</span></code> — Internet String Preparation</a></p>677  </div>678  <div>679    <h4>Next topic</h4>680    <p class="topless"><a href="rlcompleter.html"681                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">rlcompleter</span></code> — Completion function for GNU readline</a></p>682  </div>683  <script>684    document.addEventListener('DOMContentLoaded', () => {685        const title = document.querySelector('meta[property="og:title"]').content;686        const elements = document.querySelectorAll('.improvepage');687        const pageurl = window.location.href.split('?')[0];688        elements.forEach(element => {689            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));690            url.searchParams.set('pagetitle', title);691            url.searchParams.set('pageurl', pageurl);692            url.searchParams.set('pagesource', "library/readline.rst");693            element.href = url.toString();694        });695    });696  </script>697  <div role="note" aria-label="source link">698    <h3>This page</h3>699    <ul class="this-page-menu">700      <li><a href="../bugs.html">Report a bug</a></li>701      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>702      <li>703        <a href="https://github.com/python/cpython/blob/main/Doc/library/readline.rst?plain=1"704            rel="nofollow">Show source705        </a>706      </li>707      708    </ul>709  </div>710        </div>711<div id="sidebarbutton" title="Collapse sidebar">712<span>«</span>713</div>714 715      </div>716      <div class="clearer"></div>717    </div>  718    <div class="related" role="navigation" aria-label="Related">719      <h3>Navigation</h3>720      <ul>721        <li class="right" style="margin-right: 10px">722          <a href="../genindex.html" title="General Index"723             >index</a></li>724        <li class="right" >725          <a href="../py-modindex.html" title="Python Module Index"726             >modules</a> |</li>727        <li class="right" >728          <a href="rlcompleter.html" title="rlcompleter — Completion function for GNU readline"729             >next</a> |</li>730        <li class="right" >731          <a href="stringprep.html" title="stringprep — Internet String Preparation"732             >previous</a> |</li>733 734          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>735          <li><a href="https://www.python.org/">Python</a> &#187;</li>736          <li class="switchers">737            <div class="language_switcher_placeholder"></div>738            <div class="version_switcher_placeholder"></div>739          </li>740          <li>741              742          </li>743    <li id="cpython-language-and-version">744      <a href="../index.html">3.15.0a6 Documentation</a> &#187;745    </li>746 747          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>748          <li class="nav-item nav-item-2"><a href="text.html" >Text Processing Services</a> &#187;</li>749        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> — GNU readline interface</a></li>750                <li class="right">751                    752 753    <div class="inline-search" role="search">754        <form class="inline-search" action="../search.html" method="get">755          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">756          <input type="submit" value="Go">757        </form>758    </div>759                     |760                </li>761            <li class="right">762<label class="theme-selector-label">763    Theme764    <select class="theme-selector" oninput="activateTheme(this.value)">765        <option value="auto" selected>Auto</option>766        <option value="light">Light</option>767        <option value="dark">Dark</option>768    </select>769</label> |</li>770            771      </ul>772    </div>  773    <div class="footer">774    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.775    <br>776    This page is licensed under the Python Software Foundation License Version 2.777    <br>778    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.779    <br>780    781      See <a href="/license.html">History and License</a> for more information.<br>782    783    784    <br>785 786    The Python Software Foundation is a non-profit corporation.787<a href="https://www.python.org/psf/donations/">Please donate.</a>788<br>789    <br>790      Last updated on Mar 10, 2026 (08:58 UTC).791    792      <a href="/bugs.html">Found a bug</a>?793    794    <br>795 796    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.797    </div>798 799  </body>800</html>