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