##// END OF EJS Templates
Update guiref with correct paging options....
epatters -
Show More
@@ -1,508 +1,509 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Usage information for the main IPython applications.
2 """Usage information for the main IPython applications.
3 """
3 """
4 #-----------------------------------------------------------------------------
4 #-----------------------------------------------------------------------------
5 # Copyright (C) 2008-2010 The IPython Development Team
5 # Copyright (C) 2008-2010 The IPython Development Team
6 # Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
6 # Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
7 #
7 #
8 # Distributed under the terms of the BSD License. The full license is in
8 # Distributed under the terms of the BSD License. The full license is in
9 # the file COPYING, distributed as part of this software.
9 # the file COPYING, distributed as part of this software.
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11
11
12 import sys
12 import sys
13 from IPython.core import release
13 from IPython.core import release
14
14
15 cl_usage = """\
15 cl_usage = """\
16 ipython [options] [files]
16 ipython [options] [files]
17
17
18 IPython: an enhanced interactive Python shell.
18 IPython: an enhanced interactive Python shell.
19
19
20 A Python shell with automatic history (input and output), dynamic object
20 A Python shell with automatic history (input and output), dynamic object
21 introspection, easier configuration, command completion, access to the
21 introspection, easier configuration, command completion, access to the
22 system shell and more. IPython can also be embedded in running programs.
22 system shell and more. IPython can also be embedded in running programs.
23
23
24 If invoked with no options, it executes all the files listed in sequence
24 If invoked with no options, it executes all the files listed in sequence
25 and exits, use -i to enter interactive mode after running the files. Files
25 and exits, use -i to enter interactive mode after running the files. Files
26 ending in .py will be treated as normal Python, but files ending in .ipy
26 ending in .py will be treated as normal Python, but files ending in .ipy
27 can contain special IPython syntax (magic commands, shell expansions, etc.)
27 can contain special IPython syntax (magic commands, shell expansions, etc.)
28
28
29 Please note that some of the configuration options are not available at the
29 Please note that some of the configuration options are not available at the
30 command line, simply because they are not practical here. Look into your
30 command line, simply because they are not practical here. Look into your
31 ipython_config.py configuration file for details on those.
31 ipython_config.py configuration file for details on those.
32
32
33 This file is typically installed in the IPYTHON_DIR directory. For Linux
33 This file is typically installed in the IPYTHON_DIR directory. For Linux
34 users, this will be $HOME/.config/ipython, and for other users it will be
34 users, this will be $HOME/.config/ipython, and for other users it will be
35 $HOME/.ipython. For Windows users, $HOME resolves to C:\\Documents and
35 $HOME/.ipython. For Windows users, $HOME resolves to C:\\Documents and
36 Settings\\YourUserName in most instances.
36 Settings\\YourUserName in most instances.
37
37
38 In IPython's documentation, we will refer to this directory as IPYTHON_DIR,
38 In IPython's documentation, we will refer to this directory as IPYTHON_DIR,
39 you can change its default location by setting any path you want in this
39 you can change its default location by setting any path you want in this
40 environment variable.
40 environment variable.
41
41
42 For more information, see the manual available in HTML and PDF in your
42 For more information, see the manual available in HTML and PDF in your
43 installation, or online at http://ipython.scipy.org.
43 installation, or online at http://ipython.scipy.org.
44 """
44 """
45
45
46 interactive_usage = """
46 interactive_usage = """
47 IPython -- An enhanced Interactive Python
47 IPython -- An enhanced Interactive Python
48 =========================================
48 =========================================
49
49
50 IPython offers a combination of convenient shell features, special commands
50 IPython offers a combination of convenient shell features, special commands
51 and a history mechanism for both input (command history) and output (results
51 and a history mechanism for both input (command history) and output (results
52 caching, similar to Mathematica). It is intended to be a fully compatible
52 caching, similar to Mathematica). It is intended to be a fully compatible
53 replacement for the standard Python interpreter, while offering vastly
53 replacement for the standard Python interpreter, while offering vastly
54 improved functionality and flexibility.
54 improved functionality and flexibility.
55
55
56 At your system command line, type 'ipython -help' to see the command line
56 At your system command line, type 'ipython -help' to see the command line
57 options available. This document only describes interactive features.
57 options available. This document only describes interactive features.
58
58
59 Warning: IPython relies on the existence of a global variable called __IP which
59 Warning: IPython relies on the existence of a global variable called __IP which
60 controls the shell itself. If you redefine __IP to anything, bizarre behavior
60 controls the shell itself. If you redefine __IP to anything, bizarre behavior
61 will quickly occur.
61 will quickly occur.
62
62
63 MAIN FEATURES
63 MAIN FEATURES
64
64
65 * Access to the standard Python help. As of Python 2.1, a help system is
65 * Access to the standard Python help. As of Python 2.1, a help system is
66 available with access to object docstrings and the Python manuals. Simply
66 available with access to object docstrings and the Python manuals. Simply
67 type 'help' (no quotes) to access it.
67 type 'help' (no quotes) to access it.
68
68
69 * Magic commands: type %magic for information on the magic subsystem.
69 * Magic commands: type %magic for information on the magic subsystem.
70
70
71 * System command aliases, via the %alias command or the ipythonrc config file.
71 * System command aliases, via the %alias command or the ipythonrc config file.
72
72
73 * Dynamic object information:
73 * Dynamic object information:
74
74
75 Typing ?word or word? prints detailed information about an object. If
75 Typing ?word or word? prints detailed information about an object. If
76 certain strings in the object are too long (docstrings, code, etc.) they get
76 certain strings in the object are too long (docstrings, code, etc.) they get
77 snipped in the center for brevity.
77 snipped in the center for brevity.
78
78
79 Typing ??word or word?? gives access to the full information without
79 Typing ??word or word?? gives access to the full information without
80 snipping long strings. Long strings are sent to the screen through the less
80 snipping long strings. Long strings are sent to the screen through the less
81 pager if longer than the screen, printed otherwise.
81 pager if longer than the screen, printed otherwise.
82
82
83 The ?/?? system gives access to the full source code for any object (if
83 The ?/?? system gives access to the full source code for any object (if
84 available), shows function prototypes and other useful information.
84 available), shows function prototypes and other useful information.
85
85
86 If you just want to see an object's docstring, type '%pdoc object' (without
86 If you just want to see an object's docstring, type '%pdoc object' (without
87 quotes, and without % if you have automagic on).
87 quotes, and without % if you have automagic on).
88
88
89 Both %pdoc and ?/?? give you access to documentation even on things which are
89 Both %pdoc and ?/?? give you access to documentation even on things which are
90 not explicitely defined. Try for example typing {}.get? or after import os,
90 not explicitely defined. Try for example typing {}.get? or after import os,
91 type os.path.abspath??. The magic functions %pdef, %source and %file operate
91 type os.path.abspath??. The magic functions %pdef, %source and %file operate
92 similarly.
92 similarly.
93
93
94 * Completion in the local namespace, by typing TAB at the prompt.
94 * Completion in the local namespace, by typing TAB at the prompt.
95
95
96 At any time, hitting tab will complete any available python commands or
96 At any time, hitting tab will complete any available python commands or
97 variable names, and show you a list of the possible completions if there's
97 variable names, and show you a list of the possible completions if there's
98 no unambiguous one. It will also complete filenames in the current directory.
98 no unambiguous one. It will also complete filenames in the current directory.
99
99
100 This feature requires the readline and rlcomplete modules, so it won't work
100 This feature requires the readline and rlcomplete modules, so it won't work
101 if your Python lacks readline support (such as under Windows).
101 if your Python lacks readline support (such as under Windows).
102
102
103 * Search previous command history in two ways (also requires readline):
103 * Search previous command history in two ways (also requires readline):
104
104
105 - Start typing, and then use Ctrl-p (previous,up) and Ctrl-n (next,down) to
105 - Start typing, and then use Ctrl-p (previous,up) and Ctrl-n (next,down) to
106 search through only the history items that match what you've typed so
106 search through only the history items that match what you've typed so
107 far. If you use Ctrl-p/Ctrl-n at a blank prompt, they just behave like
107 far. If you use Ctrl-p/Ctrl-n at a blank prompt, they just behave like
108 normal arrow keys.
108 normal arrow keys.
109
109
110 - Hit Ctrl-r: opens a search prompt. Begin typing and the system searches
110 - Hit Ctrl-r: opens a search prompt. Begin typing and the system searches
111 your history for lines that match what you've typed so far, completing as
111 your history for lines that match what you've typed so far, completing as
112 much as it can.
112 much as it can.
113
113
114 * Persistent command history across sessions (readline required).
114 * Persistent command history across sessions (readline required).
115
115
116 * Logging of input with the ability to save and restore a working session.
116 * Logging of input with the ability to save and restore a working session.
117
117
118 * System escape with !. Typing !ls will run 'ls' in the current directory.
118 * System escape with !. Typing !ls will run 'ls' in the current directory.
119
119
120 * The reload command does a 'deep' reload of a module: changes made to the
120 * The reload command does a 'deep' reload of a module: changes made to the
121 module since you imported will actually be available without having to exit.
121 module since you imported will actually be available without having to exit.
122
122
123 * Verbose and colored exception traceback printouts. See the magic xmode and
123 * Verbose and colored exception traceback printouts. See the magic xmode and
124 xcolor functions for details (just type %magic).
124 xcolor functions for details (just type %magic).
125
125
126 * Input caching system:
126 * Input caching system:
127
127
128 IPython offers numbered prompts (In/Out) with input and output caching. All
128 IPython offers numbered prompts (In/Out) with input and output caching. All
129 input is saved and can be retrieved as variables (besides the usual arrow
129 input is saved and can be retrieved as variables (besides the usual arrow
130 key recall).
130 key recall).
131
131
132 The following GLOBAL variables always exist (so don't overwrite them!):
132 The following GLOBAL variables always exist (so don't overwrite them!):
133 _i: stores previous input.
133 _i: stores previous input.
134 _ii: next previous.
134 _ii: next previous.
135 _iii: next-next previous.
135 _iii: next-next previous.
136 _ih : a list of all input _ih[n] is the input from line n.
136 _ih : a list of all input _ih[n] is the input from line n.
137
137
138 Additionally, global variables named _i<n> are dynamically created (<n>
138 Additionally, global variables named _i<n> are dynamically created (<n>
139 being the prompt counter), such that _i<n> == _ih[<n>]
139 being the prompt counter), such that _i<n> == _ih[<n>]
140
140
141 For example, what you typed at prompt 14 is available as _i14 and _ih[14].
141 For example, what you typed at prompt 14 is available as _i14 and _ih[14].
142
142
143 You can create macros which contain multiple input lines from this history,
143 You can create macros which contain multiple input lines from this history,
144 for later re-execution, with the %macro function.
144 for later re-execution, with the %macro function.
145
145
146 The history function %hist allows you to see any part of your input history
146 The history function %hist allows you to see any part of your input history
147 by printing a range of the _i variables. Note that inputs which contain
147 by printing a range of the _i variables. Note that inputs which contain
148 magic functions (%) appear in the history with a prepended comment. This is
148 magic functions (%) appear in the history with a prepended comment. This is
149 because they aren't really valid Python code, so you can't exec them.
149 because they aren't really valid Python code, so you can't exec them.
150
150
151 * Output caching system:
151 * Output caching system:
152
152
153 For output that is returned from actions, a system similar to the input
153 For output that is returned from actions, a system similar to the input
154 cache exists but using _ instead of _i. Only actions that produce a result
154 cache exists but using _ instead of _i. Only actions that produce a result
155 (NOT assignments, for example) are cached. If you are familiar with
155 (NOT assignments, for example) are cached. If you are familiar with
156 Mathematica, IPython's _ variables behave exactly like Mathematica's %
156 Mathematica, IPython's _ variables behave exactly like Mathematica's %
157 variables.
157 variables.
158
158
159 The following GLOBAL variables always exist (so don't overwrite them!):
159 The following GLOBAL variables always exist (so don't overwrite them!):
160 _ (one underscore): previous output.
160 _ (one underscore): previous output.
161 __ (two underscores): next previous.
161 __ (two underscores): next previous.
162 ___ (three underscores): next-next previous.
162 ___ (three underscores): next-next previous.
163
163
164 Global variables named _<n> are dynamically created (<n> being the prompt
164 Global variables named _<n> are dynamically created (<n> being the prompt
165 counter), such that the result of output <n> is always available as _<n>.
165 counter), such that the result of output <n> is always available as _<n>.
166
166
167 Finally, a global dictionary named _oh exists with entries for all lines
167 Finally, a global dictionary named _oh exists with entries for all lines
168 which generated output.
168 which generated output.
169
169
170 * Directory history:
170 * Directory history:
171
171
172 Your history of visited directories is kept in the global list _dh, and the
172 Your history of visited directories is kept in the global list _dh, and the
173 magic %cd command can be used to go to any entry in that list.
173 magic %cd command can be used to go to any entry in that list.
174
174
175 * Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)
175 * Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)
176
176
177 1. Auto-parentheses
177 1. Auto-parentheses
178 Callable objects (i.e. functions, methods, etc) can be invoked like
178 Callable objects (i.e. functions, methods, etc) can be invoked like
179 this (notice the commas between the arguments):
179 this (notice the commas between the arguments):
180 >>> callable_ob arg1, arg2, arg3
180 >>> callable_ob arg1, arg2, arg3
181 and the input will be translated to this:
181 and the input will be translated to this:
182 --> callable_ob(arg1, arg2, arg3)
182 --> callable_ob(arg1, arg2, arg3)
183 You can force auto-parentheses by using '/' as the first character
183 You can force auto-parentheses by using '/' as the first character
184 of a line. For example:
184 of a line. For example:
185 >>> /globals # becomes 'globals()'
185 >>> /globals # becomes 'globals()'
186 Note that the '/' MUST be the first character on the line! This
186 Note that the '/' MUST be the first character on the line! This
187 won't work:
187 won't work:
188 >>> print /globals # syntax error
188 >>> print /globals # syntax error
189
189
190 In most cases the automatic algorithm should work, so you should
190 In most cases the automatic algorithm should work, so you should
191 rarely need to explicitly invoke /. One notable exception is if you
191 rarely need to explicitly invoke /. One notable exception is if you
192 are trying to call a function with a list of tuples as arguments (the
192 are trying to call a function with a list of tuples as arguments (the
193 parenthesis will confuse IPython):
193 parenthesis will confuse IPython):
194 In [1]: zip (1,2,3),(4,5,6) # won't work
194 In [1]: zip (1,2,3),(4,5,6) # won't work
195 but this will work:
195 but this will work:
196 In [2]: /zip (1,2,3),(4,5,6)
196 In [2]: /zip (1,2,3),(4,5,6)
197 ------> zip ((1,2,3),(4,5,6))
197 ------> zip ((1,2,3),(4,5,6))
198 Out[2]= [(1, 4), (2, 5), (3, 6)]
198 Out[2]= [(1, 4), (2, 5), (3, 6)]
199
199
200 IPython tells you that it has altered your command line by
200 IPython tells you that it has altered your command line by
201 displaying the new command line preceded by -->. e.g.:
201 displaying the new command line preceded by -->. e.g.:
202 In [18]: callable list
202 In [18]: callable list
203 -------> callable (list)
203 -------> callable (list)
204
204
205 2. Auto-Quoting
205 2. Auto-Quoting
206 You can force auto-quoting of a function's arguments by using ',' as
206 You can force auto-quoting of a function's arguments by using ',' as
207 the first character of a line. For example:
207 the first character of a line. For example:
208 >>> ,my_function /home/me # becomes my_function("/home/me")
208 >>> ,my_function /home/me # becomes my_function("/home/me")
209
209
210 If you use ';' instead, the whole argument is quoted as a single
210 If you use ';' instead, the whole argument is quoted as a single
211 string (while ',' splits on whitespace):
211 string (while ',' splits on whitespace):
212 >>> ,my_function a b c # becomes my_function("a","b","c")
212 >>> ,my_function a b c # becomes my_function("a","b","c")
213 >>> ;my_function a b c # becomes my_function("a b c")
213 >>> ;my_function a b c # becomes my_function("a b c")
214
214
215 Note that the ',' MUST be the first character on the line! This
215 Note that the ',' MUST be the first character on the line! This
216 won't work:
216 won't work:
217 >>> x = ,my_function /home/me # syntax error
217 >>> x = ,my_function /home/me # syntax error
218 """
218 """
219
219
220 interactive_usage_min = """\
220 interactive_usage_min = """\
221 An enhanced console for Python.
221 An enhanced console for Python.
222 Some of its features are:
222 Some of its features are:
223 - Readline support if the readline library is present.
223 - Readline support if the readline library is present.
224 - Tab completion in the local namespace.
224 - Tab completion in the local namespace.
225 - Logging of input, see command-line options.
225 - Logging of input, see command-line options.
226 - System shell escape via ! , eg !ls.
226 - System shell escape via ! , eg !ls.
227 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
227 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
228 - Keeps track of locally defined variables via %who, %whos.
228 - Keeps track of locally defined variables via %who, %whos.
229 - Show object information with a ? eg ?x or x? (use ?? for more info).
229 - Show object information with a ? eg ?x or x? (use ?? for more info).
230 """
230 """
231
231
232 quick_reference = r"""
232 quick_reference = r"""
233 IPython -- An enhanced Interactive Python - Quick Reference Card
233 IPython -- An enhanced Interactive Python - Quick Reference Card
234 ================================================================
234 ================================================================
235
235
236 obj?, obj?? : Get help, or more help for object (also works as
236 obj?, obj?? : Get help, or more help for object (also works as
237 ?obj, ??obj).
237 ?obj, ??obj).
238 ?foo.*abc* : List names in 'foo' containing 'abc' in them.
238 ?foo.*abc* : List names in 'foo' containing 'abc' in them.
239 %magic : Information about IPython's 'magic' % functions.
239 %magic : Information about IPython's 'magic' % functions.
240
240
241 Magic functions are prefixed by %, and typically take their arguments without
241 Magic functions are prefixed by %, and typically take their arguments without
242 parentheses, quotes or even commas for convenience.
242 parentheses, quotes or even commas for convenience.
243
243
244 Example magic function calls:
244 Example magic function calls:
245
245
246 %alias d ls -F : 'd' is now an alias for 'ls -F'
246 %alias d ls -F : 'd' is now an alias for 'ls -F'
247 alias d ls -F : Works if 'alias' not a python name
247 alias d ls -F : Works if 'alias' not a python name
248 alist = %alias : Get list of aliases to 'alist'
248 alist = %alias : Get list of aliases to 'alist'
249 cd /usr/share : Obvious. cd -<tab> to choose from visited dirs.
249 cd /usr/share : Obvious. cd -<tab> to choose from visited dirs.
250 %cd?? : See help AND source for magic %cd
250 %cd?? : See help AND source for magic %cd
251
251
252 System commands:
252 System commands:
253
253
254 !cp a.txt b/ : System command escape, calls os.system()
254 !cp a.txt b/ : System command escape, calls os.system()
255 cp a.txt b/ : after %rehashx, most system commands work without !
255 cp a.txt b/ : after %rehashx, most system commands work without !
256 cp ${f}.txt $bar : Variable expansion in magics and system commands
256 cp ${f}.txt $bar : Variable expansion in magics and system commands
257 files = !ls /usr : Capture sytem command output
257 files = !ls /usr : Capture sytem command output
258 files.s, files.l, files.n: "a b c", ['a','b','c'], 'a\nb\nc'
258 files.s, files.l, files.n: "a b c", ['a','b','c'], 'a\nb\nc'
259
259
260 History:
260 History:
261
261
262 _i, _ii, _iii : Previous, next previous, next next previous input
262 _i, _ii, _iii : Previous, next previous, next next previous input
263 _i4, _ih[2:5] : Input history line 4, lines 2-4
263 _i4, _ih[2:5] : Input history line 4, lines 2-4
264 exec _i81 : Execute input history line #81 again
264 exec _i81 : Execute input history line #81 again
265 %rep 81 : Edit input history line #81
265 %rep 81 : Edit input history line #81
266 _, __, ___ : previous, next previous, next next previous output
266 _, __, ___ : previous, next previous, next next previous output
267 _dh : Directory history
267 _dh : Directory history
268 _oh : Output history
268 _oh : Output history
269 %hist : Command history. '%hist -g foo' search history for 'foo'
269 %hist : Command history. '%hist -g foo' search history for 'foo'
270
270
271 Autocall:
271 Autocall:
272
272
273 f 1,2 : f(1,2)
273 f 1,2 : f(1,2)
274 /f 1,2 : f(1,2) (forced autoparen)
274 /f 1,2 : f(1,2) (forced autoparen)
275 ,f 1 2 : f("1","2")
275 ,f 1 2 : f("1","2")
276 ;f 1 2 : f("1 2")
276 ;f 1 2 : f("1 2")
277
277
278 Remember: TAB completion works in many contexts, not just file names
278 Remember: TAB completion works in many contexts, not just file names
279 or python names.
279 or python names.
280
280
281 The following magic functions are currently available:
281 The following magic functions are currently available:
282
282
283 """
283 """
284
284
285 gui_reference = """\
285 gui_reference = """\
286 ===============================
286 ===============================
287 The graphical IPython console
287 The graphical IPython console
288 ===============================
288 ===============================
289
289
290 This console is designed to emulate the look, feel and workflow of a terminal
290 This console is designed to emulate the look, feel and workflow of a terminal
291 environment, while adding a number of enhancements that are simply not possible
291 environment, while adding a number of enhancements that are simply not possible
292 in a real terminal, such as inline syntax highlighting, true multiline editing,
292 in a real terminal, such as inline syntax highlighting, true multiline editing,
293 inline graphics and much more.
293 inline graphics and much more.
294
294
295 This quick reference document contains the basic information you'll need to
295 This quick reference document contains the basic information you'll need to
296 know to make the most efficient use of it. For the various command line
296 know to make the most efficient use of it. For the various command line
297 options available at startup, type ``--help`` at the command line.
297 options available at startup, type ``--help`` at the command line.
298
298
299
299
300 Multiline editing
300 Multiline editing
301 =================
301 =================
302
302
303 The graphical console is capable of true multiline editing, but it also tries
303 The graphical console is capable of true multiline editing, but it also tries
304 to behave intuitively like a terminal when possible. If you are used to
304 to behave intuitively like a terminal when possible. If you are used to
305 IPyhton's old terminal behavior, you should find the transition painless, and
305 IPyhton's old terminal behavior, you should find the transition painless, and
306 once you learn a few basic keybindings it will be a much more efficient
306 once you learn a few basic keybindings it will be a much more efficient
307 environment.
307 environment.
308
308
309 For single expressions or indented blocks, the console behaves almost like the
309 For single expressions or indented blocks, the console behaves almost like the
310 terminal IPython: single expressions are immediately evaluated, and indented
310 terminal IPython: single expressions are immediately evaluated, and indented
311 blocks are evaluated once a single blank line is entered::
311 blocks are evaluated once a single blank line is entered::
312
312
313 In [1]: print "Hello IPython!" # Enter was pressed at the end of the line
313 In [1]: print "Hello IPython!" # Enter was pressed at the end of the line
314 Hello IPython!
314 Hello IPython!
315
315
316 In [2]: for i in range(10):
316 In [2]: for i in range(10):
317 ...: print i,
317 ...: print i,
318 ...:
318 ...:
319 0 1 2 3 4 5 6 7 8 9
319 0 1 2 3 4 5 6 7 8 9
320
320
321 If you want to enter more than one expression in a single input block
321 If you want to enter more than one expression in a single input block
322 (something not possible in the terminal), you can use ``Control-Enter`` at the
322 (something not possible in the terminal), you can use ``Control-Enter`` at the
323 end of your first line instead of ``Enter``. At that point the console goes
323 end of your first line instead of ``Enter``. At that point the console goes
324 into 'cell mode' and even if your inputs are not indented, it will continue
324 into 'cell mode' and even if your inputs are not indented, it will continue
325 accepting arbitrarily many lines until either you enter an extra blank line or
325 accepting arbitrarily many lines until either you enter an extra blank line or
326 you hit ``Shift-Enter`` (the key binding that forces execution). When a
326 you hit ``Shift-Enter`` (the key binding that forces execution). When a
327 multiline cell is entered, IPython analyzes it and executes its code producing
327 multiline cell is entered, IPython analyzes it and executes its code producing
328 an ``Out[n]`` prompt only for the last expression in it, while the rest of the
328 an ``Out[n]`` prompt only for the last expression in it, while the rest of the
329 cell is executed as if it was a script. An example should clarify this::
329 cell is executed as if it was a script. An example should clarify this::
330
330
331 In [3]: x=1 # Hit C-Enter here
331 In [3]: x=1 # Hit C-Enter here
332 ...: y=2 # from now on, regular Enter is sufficient
332 ...: y=2 # from now on, regular Enter is sufficient
333 ...: z=3
333 ...: z=3
334 ...: x**2 # This does *not* produce an Out[] value
334 ...: x**2 # This does *not* produce an Out[] value
335 ...: x+y+z # Only the last expression does
335 ...: x+y+z # Only the last expression does
336 ...:
336 ...:
337 Out[3]: 6
337 Out[3]: 6
338
338
339 The behavior where an extra blank line forces execution is only active if you
339 The behavior where an extra blank line forces execution is only active if you
340 are actually typing at the keyboard each line, and is meant to make it mimic
340 are actually typing at the keyboard each line, and is meant to make it mimic
341 the IPython terminal behavior. If you paste a long chunk of input (for example
341 the IPython terminal behavior. If you paste a long chunk of input (for example
342 a long script copied form an editor or web browser), it can contain arbitrarily
342 a long script copied form an editor or web browser), it can contain arbitrarily
343 many intermediate blank lines and they won't cause any problems. As always,
343 many intermediate blank lines and they won't cause any problems. As always,
344 you can then make it execute by appending a blank line *at the end* or hitting
344 you can then make it execute by appending a blank line *at the end* or hitting
345 ``Shift-Enter`` anywhere within the cell.
345 ``Shift-Enter`` anywhere within the cell.
346
346
347 With the up arrow key, you can retrieve previous blocks of input that contain
347 With the up arrow key, you can retrieve previous blocks of input that contain
348 multiple lines. You can move inside of a multiline cell like you would in any
348 multiple lines. You can move inside of a multiline cell like you would in any
349 text editor. When you want it executed, the simplest thing to do is to hit the
349 text editor. When you want it executed, the simplest thing to do is to hit the
350 force execution key, ``Shift-Enter`` (though you can also navigate to the end
350 force execution key, ``Shift-Enter`` (though you can also navigate to the end
351 and append a blank line by using ``Enter`` twice).
351 and append a blank line by using ``Enter`` twice).
352
352
353 If you've edited a multiline cell and accidentally navigate out of it with the
353 If you've edited a multiline cell and accidentally navigate out of it with the
354 up or down arrow keys, IPython will clear the cell and replace it with the
354 up or down arrow keys, IPython will clear the cell and replace it with the
355 contents of the one above or below that you navigated to. If this was an
355 contents of the one above or below that you navigated to. If this was an
356 accident and you want to retrieve the cell you were editing, use the Undo
356 accident and you want to retrieve the cell you were editing, use the Undo
357 keybinding, ``Control-z``.
357 keybinding, ``Control-z``.
358
358
359
359
360 Key bindings
360 Key bindings
361 ============
361 ============
362
362
363 The IPython console supports most of the basic Emacs line-oriented keybindings,
363 The IPython console supports most of the basic Emacs line-oriented keybindings,
364 in addition to some of its own.
364 in addition to some of its own.
365
365
366 The keybinding prefixes mean:
366 The keybinding prefixes mean:
367
367
368 - ``C``: Control
368 - ``C``: Control
369 - ``S``: Shift
369 - ``S``: Shift
370 - ``M``: Meta (typically the Alt key)
370 - ``M``: Meta (typically the Alt key)
371
371
372 The keybindings themselves are:
372 The keybindings themselves are:
373
373
374 - ``Enter``: insert new line (may cause execution, see above).
374 - ``Enter``: insert new line (may cause execution, see above).
375 - ``C-Enter``: force new line, *never* causes execution.
375 - ``C-Enter``: force new line, *never* causes execution.
376 - ``S-Enter``: *force* execution regardless of where cursor is, no newline added.
376 - ``S-Enter``: *force* execution regardless of where cursor is, no newline added.
377 - ``C-c``: copy highlighted text to clipboard (prompts are automatically stripped).
377 - ``C-c``: copy highlighted text to clipboard (prompts are automatically stripped).
378 - ``C-S-c``: copy highlighted text to clipboard (prompts are not stripped).
378 - ``C-S-c``: copy highlighted text to clipboard (prompts are not stripped).
379 - ``C-v``: paste text from clipboard.
379 - ``C-v``: paste text from clipboard.
380 - ``C-z``: undo (retrieves lost text if you move out of a cell with the arrows).
380 - ``C-z``: undo (retrieves lost text if you move out of a cell with the arrows).
381 - ``C-S-z``: redo.
381 - ``C-S-z``: redo.
382 - ``C-o``: move to 'other' area, between pager and terminal.
382 - ``C-o``: move to 'other' area, between pager and terminal.
383 - ``C-l``: clear terminal.
383 - ``C-l``: clear terminal.
384 - ``C-a``: go to beginning of line.
384 - ``C-a``: go to beginning of line.
385 - ``C-e``: go to end of line.
385 - ``C-e``: go to end of line.
386 - ``C-k``: kill from cursor to the end of the line.
386 - ``C-k``: kill from cursor to the end of the line.
387 - ``C-y``: yank (paste)
387 - ``C-y``: yank (paste)
388 - ``C-p``: previous line (like up arrow)
388 - ``C-p``: previous line (like up arrow)
389 - ``C-n``: next line (like down arrow)
389 - ``C-n``: next line (like down arrow)
390 - ``C-f``: forward (like right arrow)
390 - ``C-f``: forward (like right arrow)
391 - ``C-b``: back (like left arrow)
391 - ``C-b``: back (like left arrow)
392 - ``C-d``: delete next character.
392 - ``C-d``: delete next character.
393 - ``M-<``: move to the beginning of the input region.
393 - ``M-<``: move to the beginning of the input region.
394 - ``M->``: move to the end of the input region.
394 - ``M->``: move to the end of the input region.
395 - ``M-d``: delete next word.
395 - ``M-d``: delete next word.
396 - ``M-Backspace``: delete previous word.
396 - ``M-Backspace``: delete previous word.
397 - ``C-.``: force a kernel restart (a confirmation dialog appears).
397 - ``C-.``: force a kernel restart (a confirmation dialog appears).
398 - ``C-+``: increase font size.
398 - ``C-+``: increase font size.
399 - ``C--``: decrease font size.
399 - ``C--``: decrease font size.
400
400
401 The IPython pager
401 The IPython pager
402 =================
402 =================
403
403
404 IPython will show long blocks of text from many sources using a builtin pager.
404 IPython will show long blocks of text from many sources using a builtin pager.
405 You can control where this pager appears with the ``--paging`` command-line
405 You can control where this pager appears with the ``--paging`` command-line
406 flag:
406 flag:
407
407
408 - default: it is overlaid on top of the main terminal. You must quit the pager
408 - ``inside`` [default]: the pager is overlaid on top of the main terminal. You
409 to get back to the terminal (similar to how a pager such as ``less`` or
409 must quit the pager to get back to the terminal (similar to how a pager such
410 ``more`` works).
410 as ``less`` or ``more`` works).
411
411
412 - vertical: the console is made double-tall, and the pager appears on the
412 - ``vsplit``: the console is made double-tall, and the pager appears on the
413 bottom area when needed. You can view its contents while using the terminal.
413 bottom area when needed. You can view its contents while using the terminal.
414
414
415 - horizontal: the console is made double-wide, and the pager appears on the
415 - ``hsplit``: the console is made double-wide, and the pager appears on the
416 right area when needed. You can view its contents while using the terminal.
416 right area when needed. You can view its contents while using the terminal.
417
417
418 - ``none``: the console never pages output.
419
418 If you use the vertical or horizontal paging modes, you can navigate between
420 If you use the vertical or horizontal paging modes, you can navigate between
419 terminal and pager as follows:
421 terminal and pager as follows:
420
422
421 - Tab key: goes from pager to terminal (but not the other way around).
423 - Tab key: goes from pager to terminal (but not the other way around).
422 - Control-o: goes from one to another always.
424 - Control-o: goes from one to another always.
423 - Mouse: click on either.
425 - Mouse: click on either.
424
426
425 In all cases, the ``q`` or ``Escape`` keys quit the pager (when used with the
427 In all cases, the ``q`` or ``Escape`` keys quit the pager (when used with the
426 focus on the pager area).
428 focus on the pager area).
427
429
428
429 Running subprocesses
430 Running subprocesses
430 ====================
431 ====================
431
432
432 The graphical IPython console uses the ``pexpect`` module to run subprocesses
433 The graphical IPython console uses the ``pexpect`` module to run subprocesses
433 when you type ``!command``. This has a number of advantages (true asynchronous
434 when you type ``!command``. This has a number of advantages (true asynchronous
434 output from subprocesses as well as very robust termination of rogue
435 output from subprocesses as well as very robust termination of rogue
435 subprocesses with ``Control-C``), as well as some limitations. The main
436 subprocesses with ``Control-C``), as well as some limitations. The main
436 limitation is that you can *not* interact back with the subprocess, so anything
437 limitation is that you can *not* interact back with the subprocess, so anything
437 that invokes a pager or expects you to type input into it will block and hang
438 that invokes a pager or expects you to type input into it will block and hang
438 (you can kill it with ``Control-C``).
439 (you can kill it with ``Control-C``).
439
440
440 We have provided as magics ``%less`` to page files (aliased to ``%more``),
441 We have provided as magics ``%less`` to page files (aliased to ``%more``),
441 ``%clear`` to clear the terminal, and ``%man`` on Linux/OSX. These cover the
442 ``%clear`` to clear the terminal, and ``%man`` on Linux/OSX. These cover the
442 most common commands you'd want to call in your subshell and that would cause
443 most common commands you'd want to call in your subshell and that would cause
443 problems if invoked via ``!cmd``, but you need to be aware of this limitation.
444 problems if invoked via ``!cmd``, but you need to be aware of this limitation.
444
445
445 Display
446 Display
446 =======
447 =======
447
448
448 The IPython console can now display objects in a variety of formats, including
449 The IPython console can now display objects in a variety of formats, including
449 HTML, PNG and SVG. This is accomplished using the display functions in
450 HTML, PNG and SVG. This is accomplished using the display functions in
450 ``IPython.core.display``::
451 ``IPython.core.display``::
451
452
452 In [4]: from IPython.core.display import display, display_html
453 In [4]: from IPython.core.display import display, display_html
453
454
454 In [5]: from IPython.core.display import display_png, display_svg
455 In [5]: from IPython.core.display import display_png, display_svg
455
456
456 Python objects can simply be passed to these functions and the appropriate
457 Python objects can simply be passed to these functions and the appropriate
457 representations will be displayed in the console as long as the objects know
458 representations will be displayed in the console as long as the objects know
458 how to compute those representations. The easiest way of teaching objects how
459 how to compute those representations. The easiest way of teaching objects how
459 to format themselves in various representations is to define special methods
460 to format themselves in various representations is to define special methods
460 such as: ``__html``, ``__svg__`` and ``__png__``. IPython's display formatters
461 such as: ``__html``, ``__svg__`` and ``__png__``. IPython's display formatters
461 can also be given custom formatter functions for various types::
462 can also be given custom formatter functions for various types::
462
463
463 In [6]: ip = get_ipython()
464 In [6]: ip = get_ipython()
464
465
465 In [7]: html_formatter = ip.display_formatter.formatters['text/html']
466 In [7]: html_formatter = ip.display_formatter.formatters['text/html']
466
467
467 In [8]: html_formatter.for_type(Foo, foo_to_html)
468 In [8]: html_formatter.for_type(Foo, foo_to_html)
468
469
469 For further details, see ``IPython.core.formatters``.
470 For further details, see ``IPython.core.formatters``.
470
471
471 Inline matplotlib graphics
472 Inline matplotlib graphics
472 ==========================
473 ==========================
473
474
474 The IPython console is capable of displaying matplotlib figures inline, in SVG
475 The IPython console is capable of displaying matplotlib figures inline, in SVG
475 format. If started with the ``--pylab inline`` flag, then all figures are
476 format. If started with the ``--pylab inline`` flag, then all figures are
476 rendered inline automatically. If started with ``--pylab`` or ``--pylab <your
477 rendered inline automatically. If started with ``--pylab`` or ``--pylab <your
477 backend>``, then a GUI backend will be used, but IPython's ``display()`` and
478 backend>``, then a GUI backend will be used, but IPython's ``display()`` and
478 ``getfigs()`` functions can be used to view plots inline::
479 ``getfigs()`` functions can be used to view plots inline::
479
480
480 In [9]: display(*getfigs()) # display all figures inline
481 In [9]: display(*getfigs()) # display all figures inline
481
482
482 In[10]: display(*getfigs(1,2)) # display figures 1 and 2 inline
483 In[10]: display(*getfigs(1,2)) # display figures 1 and 2 inline
483 """
484 """
484
485
485
486
486 quick_guide = """\
487 quick_guide = """\
487 ? -> Introduction and overview of IPython's features.
488 ? -> Introduction and overview of IPython's features.
488 %quickref -> Quick reference.
489 %quickref -> Quick reference.
489 help -> Python's own help system.
490 help -> Python's own help system.
490 object? -> Details about 'object', use 'object??' for extra details.
491 object? -> Details about 'object', use 'object??' for extra details.
491 """
492 """
492
493
493 gui_note = """\
494 gui_note = """\
494 %guiref -> A brief reference about the graphical user interface.
495 %guiref -> A brief reference about the graphical user interface.
495 """
496 """
496
497
497 default_banner_parts = [
498 default_banner_parts = [
498 'Python %s\n' % (sys.version.split('\n')[0],),
499 'Python %s\n' % (sys.version.split('\n')[0],),
499 'Type "copyright", "credits" or "license" for more information.\n\n',
500 'Type "copyright", "credits" or "license" for more information.\n\n',
500 'IPython %s -- An enhanced Interactive Python.\n' % (release.version,),
501 'IPython %s -- An enhanced Interactive Python.\n' % (release.version,),
501 quick_guide
502 quick_guide
502 ]
503 ]
503
504
504 default_gui_banner_parts = default_banner_parts + [gui_note]
505 default_gui_banner_parts = default_banner_parts + [gui_note]
505
506
506 default_banner = ''.join(default_banner_parts)
507 default_banner = ''.join(default_banner_parts)
507
508
508 default_gui_banner = ''.join(default_gui_banner_parts)
509 default_gui_banner = ''.join(default_gui_banner_parts)
General Comments 0
You need to be logged in to leave comments. Login now