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