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