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