-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinteractive.html
243 lines (243 loc) · 8.2 KB
/
interactive.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=yes"
/>
<title>interactive</title>
<style type="text/css">
code {
white-space: pre-wrap;
}
span.smallcaps {
font-variant: small-caps;
}
span.underline {
text-decoration: underline;
}
div.column {
display: inline-block;
vertical-align: top;
width: 50%;
}
</style>
</head>
<body>
<h3 id="navigation">Navigation</h3>
<ul>
<li>
<a href="https://docs.python.org/3/genindex.html" title="General Index"
>index</a
>
</li>
<li>
<a
href="https://docs.python.org/3/py-modindex.html"
title="Python Module Index"
>modules</a
>
|
</li>
<li>
<a
href="floatingpoint.html"
title="15. Floating Point Arithmetic: Issues and Limitations"
>next</a
>
|
</li>
<li><a href="whatnow.html" title="13. What Now?">previous</a> |</li>
<li><img src="../_static/py.png" /></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<a href="https://docs.python.org/3/index.html">3.9.5 Documentation</a> »
</li>
<li><a href="index.html">The Python Tutorial</a> »</li>
<li></li>
</ul>
<p><span id="tut-interacting"></span></p>
<h1 id="interactive-input-editing-and-history-substitution">
<span class="section-number">14. </span>Interactive Input Editing and
History Substitution<a
href="#interactive-input-editing-and-history-substitution"
class="headerlink"
title="Permalink to this headline"
>¶</a
>
</h1>
<p>
Some versions of the Python interpreter support editing of the current
input line and history substitution, similar to facilities found in the
Korn shell and the GNU Bash shell. This is implemented using the
<a
href="https://tiswww.case.edu/php/chet/readline/rltop.html"
class="reference external"
>GNU Readline</a
>
library, which supports various styles of editing. This library has its
own documentation which we won’t duplicate here.
</p>
<p><span id="tut-keybindings"></span></p>
<h2 id="tab-completion-and-history-editing">
<span class="section-number">14.1. </span>Tab Completion and History
Editing<a
href="#tab-completion-and-history-editing"
class="headerlink"
title="Permalink to this headline"
>¶</a
>
</h2>
<p>
Completion of variable and module names is
<a
href="https://docs.python.org/3/library/site.html#rlcompleter-config"
class="reference internal"
><span class="std std-ref">automatically enabled</span></a
>
at interpreter startup so that the Tab key invokes the completion
function; it looks at Python statement names, the current local variables,
and the available module names. For dotted expressions such as
<code>string.a</code>, it will evaluate the expression up to the final
<code>'.'</code> and then suggest completions from the attributes of the
resulting object. Note that this may execute application-defined code if
an object with a
<a
href="https://docs.python.org/3/reference/datamodel.html#object.__getattr__"
class="reference internal"
title="object.__getattr__"
><code class="sourceCode python"
><span class="bu">getattr</span>()</code
></a
>
method is part of the expression. The default configuration also saves
your history into a file named <code>.python_history</code> in your user
directory. The history will be available again during the next interactive
interpreter session.
</p>
<p><span id="tut-commentary"></span></p>
<h2 id="alternatives-to-the-interactive-interpreter">
<span class="section-number">14.2. </span>Alternatives to the Interactive
Interpreter<a
href="#alternatives-to-the-interactive-interpreter"
class="headerlink"
title="Permalink to this headline"
>¶</a
>
</h2>
<p>
This facility is an enormous step forward compared to earlier versions of
the interpreter; however, some wishes are left: It would be nice if the
proper indentation were suggested on continuation lines (the parser knows
if an indent token is required next). The completion mechanism might use
the interpreter’s symbol table. A command to check (or even suggest)
matching parentheses, quotes, etc., would also be useful.
</p>
<p>
One alternative enhanced interactive interpreter that has been around for
quite some time is
<a href="https://ipython.org/" class="reference external">IPython</a>,
which features tab completion, object exploration and advanced history
management. It can also be thoroughly customized and embedded into other
applications. Another similar enhanced interactive environment is
<a href="https://www.bpython-interpreter.org/" class="reference external"
>bpython</a
>.
</p>
<h3 id="table-of-contents">
<a href="https://docs.python.org/3/contents.html">Table of Contents</a>
</h3>
<ul>
<li>
<a href="#" class="reference internal"
>14. Interactive Input Editing and History Substitution</a
>
<ul>
<li>
<a
href="#tab-completion-and-history-editing"
class="reference internal"
>14.1. Tab Completion and History Editing</a
>
</li>
<li>
<a
href="#alternatives-to-the-interactive-interpreter"
class="reference internal"
>14.2. Alternatives to the Interactive Interpreter</a
>
</li>
</ul>
</li>
</ul>
<h4 id="previous-topic">Previous topic</h4>
<p>
<a href="whatnow.html" title="previous chapter"
><span class="section-number">13. </span>What Now?</a
>
</p>
<h4 id="next-topic">Next topic</h4>
<p>
<a href="floatingpoint.html" title="next chapter"
><span class="section-number">15. </span>Floating Point Arithmetic:
Issues and Limitations</a
>
</p>
<h3 id="this-page">This Page</h3>
<ul>
<li><a href="https://docs.python.org/3/bugs.html">Report a Bug</a></li>
<li>
<a
href="https://github.com/python/cpython/blob/3.9/Doc/tutorial/interactive.rst"
>Show Source</a
>
</li>
</ul>
<h3 id="navigation-1">Navigation</h3>
<ul>
<li>
<a href="https://docs.python.org/3/genindex.html" title="General Index"
>index</a
>
</li>
<li>
<a
href="https://docs.python.org/3/py-modindex.html"
title="Python Module Index"
>modules</a
>
|
</li>
<li>
<a
href="floatingpoint.html"
title="15. Floating Point Arithmetic: Issues and Limitations"
>next</a
>
|
</li>
<li><a href="whatnow.html" title="13. What Now?">previous</a> |</li>
<li><img src="../_static/py.png" /></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<a href="https://docs.python.org/3/index.html">3.9.5 Documentation</a> »
</li>
<li><a href="index.html">The Python Tutorial</a> »</li>
<li></li>
</ul>
<p>
©
<a href="https://docs.python.org/3/copyright.html">Copyright</a>
2001-2021, Python Software Foundation.<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
</p>
<p>
Last updated on May 30, 2021.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</p>
</body>
</html>