annotate Doc/tutorial/interactive.rst @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents d5ef330bac50
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
1 .. _tut-interacting:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
2
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
3 **************************************************
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
4 Interactive Input Editing and History Substitution
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
5 **************************************************
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
6
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
7 Some versions of the Python interpreter support editing of the current input
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
8 line and history substitution, similar to facilities found in the Korn shell and
55580
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 43737
diff changeset
9 the GNU Bash shell. This is implemented using the `GNU Readline`_ library,
83608
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
10 which supports various styles of editing. This library has its own
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
11 documentation which we won't duplicate here.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
12
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
13
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
14 .. _tut-keybindings:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
15
83608
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
16 Tab Completion and History Editing
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
17 ==================================
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
18
83608
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
19 Completion of variable and module names is
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
20 :ref:`automatically enabled <rlcompleter-config>` at interpreter startup so
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
21 that the :kbd:`Tab` key invokes the completion function; it looks at
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
22 Python statement names, the current local variables, and the available
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
23 module names. For dotted expressions such as ``string.a``, it will evaluate
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
24 the expression up to the final ``'.'`` and then suggest completions from
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
25 the attributes of the resulting object. Note that this may execute
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
26 application-defined code if an object with a :meth:`__getattr__` method
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
27 is part of the expression. The default configuration also saves your
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
28 history into a file named :file:`.python_history` in your user directory.
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
29 The history will be available again during the next interactive interpreter
d5ef330bac50 Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
Antoine Pitrou <solipsis@pitrou.net>
parents: 71778
diff changeset
30 session.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
31
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
32
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
33 .. _tut-commentary:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
34
55580
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 43737
diff changeset
35 Alternatives to the Interactive Interpreter
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 43737
diff changeset
36 ===========================================
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
37
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
38 This facility is an enormous step forward compared to earlier versions of the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
39 interpreter; however, some wishes are left: It would be nice if the proper
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
40 indentation were suggested on continuation lines (the parser knows if an indent
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
41 token is required next). The completion mechanism might use the interpreter's
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
42 symbol table. A command to check (or even suggest) matching parentheses,
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
43 quotes, etc., would also be useful.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
44
55580
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 43737
diff changeset
45 One alternative enhanced interactive interpreter that has been around for quite
71778
74179a79d673 Improve documentation for PEP 370 support in site module (#8617).
Éric Araujo <merwok@netwok.org>
parents: 68946
diff changeset
46 some time is IPython_, which features tab completion, object exploration and
55580
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 43737
diff changeset
47 advanced history management. It can also be thoroughly customized and embedded
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 43737
diff changeset
48 into other applications. Another similar enhanced interactive environment is
71778
74179a79d673 Improve documentation for PEP 370 support in site module (#8617).
Éric Araujo <merwok@netwok.org>
parents: 68946
diff changeset
49 bpython_.
55580
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 43737
diff changeset
50
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
51
55580
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 43737
diff changeset
52 .. _GNU Readline: http://tiswww.case.edu/php/chet/readline/rltop.html
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 43737
diff changeset
53 .. _IPython: http://ipython.scipy.org/
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 43737
diff changeset
54 .. _bpython: http://www.bpython-interpreter.org/