##// END OF EJS Templates
Doc updates about demos...
fperez -
Show More
@@ -1,8964 +1,9056 b''
1 1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 2 \lyxformat 221
3 3 \textclass article
4 4 \begin_preamble
5 5 %\usepackage{ae,aecompl}
6 6 \usepackage{color}
7 7
8 8 % A few colors to replace the defaults for certain link types
9 9 \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
10 10 \definecolor{darkorange}{rgb}{.71,0.21,0.01}
11 11 \definecolor{darkred}{rgb}{.52,0.08,0.01}
12 12 \definecolor{darkgreen}{rgb}{.12,.54,.11}
13 13
14 14 % Use and configure listings package for nicely formatted code
15 15 \usepackage{listings}
16 16 \lstset{
17 17 language=Python,
18 18 basicstyle=\small\ttfamily,
19 19 commentstyle=\ttfamily\color{blue},
20 20 stringstyle=\ttfamily\color{darkorange},
21 21 showstringspaces=false,
22 22 breaklines=true,
23 23 postbreak = \space\dots
24 24 }
25 25
26 26 \usepackage[%pdftex, % needed for pdflatex
27 27 breaklinks=true, % so long urls are correctly broken across lines
28 28 colorlinks=true,
29 29 urlcolor=blue,
30 30 linkcolor=darkred,
31 31 citecolor=darkgreen,
32 32 ]{hyperref}
33 33
34 34 \usepackage{html}
35 35
36 36 % This helps prevent overly long lines that stretch beyond the margins
37 37 \sloppy
38 38
39 39 % Define a \codelist command which either uses listings for latex, or
40 40 % plain verbatim for html (since latex2html doesn't understand the
41 41 % listings package).
42 42 \usepackage{verbatim}
43 43 \newcommand{\codelist}[1] {
44 44 \latex{\lstinputlisting{#1}}
45 45 \html{\verbatiminput{#1}}
46 46 }
47 47 \end_preamble
48 48 \language english
49 49 \inputencoding latin1
50 50 \fontscheme palatino
51 51 \graphics default
52 52 \paperfontsize 10
53 53 \spacing single
54 54 \papersize Default
55 55 \paperpackage a4
56 56 \use_geometry 1
57 57 \use_amsmath 0
58 58 \use_natbib 0
59 59 \use_numerical_citations 0
60 60 \paperorientation portrait
61 61 \leftmargin 1.1in
62 62 \topmargin 1in
63 63 \rightmargin 1.1in
64 64 \bottommargin 1in
65 65 \secnumdepth 3
66 66 \tocdepth 3
67 67 \paragraph_separation skip
68 68 \defskip medskip
69 69 \quotes_language english
70 70 \quotes_times 2
71 71 \papercolumns 1
72 72 \papersides 1
73 73 \paperpagestyle fancy
74 74
75 75 \layout Title
76 76
77 77 IPython
78 78 \newline
79 79
80 80 \size larger
81 81 An enhanced Interactive Python
82 82 \size large
83 83
84 84 \newline
85 85 User Manual, v.
86 86 __version__
87 87 \layout Author
88 88
89 89 Fernando PοΏ½rez
90 90 \layout Standard
91 91
92 92
93 93 \begin_inset ERT
94 94 status Collapsed
95 95
96 96 \layout Standard
97 97
98 98 \backslash
99 99 latex{
100 100 \end_inset
101 101
102 102
103 103 \begin_inset LatexCommand \tableofcontents{}
104 104
105 105 \end_inset
106 106
107 107
108 108 \begin_inset ERT
109 109 status Collapsed
110 110
111 111 \layout Standard
112 112 }
113 113 \end_inset
114 114
115 115
116 116 \layout Standard
117 117
118 118
119 119 \begin_inset ERT
120 120 status Open
121 121
122 122 \layout Standard
123 123
124 124 \backslash
125 125 html{
126 126 \backslash
127 127 bodytext{bgcolor=#ffffff}}
128 128 \end_inset
129 129
130 130
131 131 \layout Section
132 132 \pagebreak_top
133 133 Overview
134 134 \layout Standard
135 135
136 136 One of Python's most useful features is its interactive interpreter.
137 137 This system allows very fast testing of ideas without the overhead of creating
138 138 test files as is typical in most programming languages.
139 139 However, the interpreter supplied with the standard Python distribution
140 140 is somewhat limited for extended interactive use.
141 141 \layout Standard
142 142
143 143 IPython is a free software project (released under the BSD license) which
144 144 tries to:
145 145 \layout Enumerate
146 146
147 147 Provide an interactive shell superior to Python's default.
148 148 IPython has many features for object introspection, system shell access,
149 149 and its own special command system for adding functionality when working
150 150 interactively.
151 151 It tries to be a very efficient environment both for Python code development
152 152 and for exploration of problems using Python objects (in situations like
153 153 data analysis).
154 154 \layout Enumerate
155 155
156 156 Serve as an embeddable, ready to use interpreter for your own programs.
157 157 IPython can be started with a single call from inside another program,
158 158 providing access to the current namespace.
159 159 This can be very useful both for debugging purposes and for situations
160 160 where a blend of batch-processing and interactive exploration are needed.
161 161 \layout Enumerate
162 162
163 163 Offer a flexible framework which can be used as the base environment for
164 164 other systems with Python as the underlying language.
165 165 Specifically scientific environments like Mathematica, IDL and Matlab inspired
166 166 its design, but similar ideas can be useful in many fields.
167 167 \layout Subsection
168 168
169 169 Main features
170 170 \layout Itemize
171 171
172 172 Dynamic object introspection.
173 173 One can access docstrings, function definition prototypes, source code,
174 174 source files and other details of any object accessible to the interpreter
175 175 with a single keystroke (`
176 176 \family typewriter
177 177 ?
178 178 \family default
179 179 ').
180 180 \layout Itemize
181 181
182 182 Completion in the local namespace, by typing TAB at the prompt.
183 183 This works for keywords, methods, variables and files in the current directory.
184 184 This is supported via the readline library, and full access to configuring
185 185 readline's behavior is provided.
186 186 \layout Itemize
187 187
188 188 Numbered input/output prompts with command history (persistent across sessions
189 189 and tied to each profile), full searching in this history and caching of
190 190 all input and output.
191 191 \layout Itemize
192 192
193 193 User-extensible `magic' commands.
194 194 A set of commands prefixed with
195 195 \family typewriter
196 196 %
197 197 \family default
198 198 is available for controlling IPython itself and provides directory control,
199 199 namespace information and many aliases to common system shell commands.
200 200 \layout Itemize
201 201
202 202 Alias facility for defining your own system aliases.
203 203 \layout Itemize
204 204
205 205 Complete system shell access.
206 206 Lines starting with ! are passed directly to the system shell, and using
207 207 !! captures shell output into python variables for further use.
208 208 \layout Itemize
209 209
210 210 All calls to the system (via aliases or via !) have their standard output/error
211 211 automatically stored as strings, and also available as lists.
212 212 \layout Itemize
213 213
214 214 Background execution of Python commands in a separate thread.
215 215 IPython has an internal job manager called
216 216 \family typewriter
217 217 jobs
218 218 \family default
219 219 , and a conveninence backgrounding magic function called
220 220 \family typewriter
221 221 %bg
222 222 \family default
223 223 .
224 224 \layout Itemize
225 225
226 226 The ability to expand python variables when calling the system shell.
227 227 In a shell command, any python variable prefixed with
228 228 \family typewriter
229 229 $
230 230 \family default
231 231 is expanded.
232 232 A double
233 233 \family typewriter
234 234 $$
235 235 \family default
236 236 allows passing a literal
237 237 \family typewriter
238 238 $
239 239 \family default
240 240 to the shell (for access to shell and environment variables like
241 241 \family typewriter
242 242 $PATH
243 243 \family default
244 244 ).
245 245 \layout Itemize
246 246
247 247 Filesystem navigation, via a magic
248 248 \family typewriter
249 249 %cd
250 250 \family default
251 251 command, along with a persistent bookmark system (using
252 252 \family typewriter
253 253 %bookmark
254 254 \family default
255 255 ) for fast access to frequently visited directories.
256 256 \layout Itemize
257 257
258 258 Automatic indentation (optional) of code as you type (through the readline
259 259 library).
260 260 \layout Itemize
261 261
262 262 Macro system for quickly re-executing multiple lines of previous input with
263 263 a single name.
264 264 \layout Itemize
265 265
266 266 Session logging (you can then later use these logs as code in your programs).
267 267 \layout Itemize
268 268
269 269 Session restoring: logs can be replayed to restore a previous session to
270 270 the state where you left it.
271 271 \layout Itemize
272 272
273 273 Verbose and colored exception traceback printouts.
274 274 Easier to parse visually, and in verbose mode they produce a lot of useful
275 275 debugging information (basically a terminal version of the cgitb module).
276 276 \layout Itemize
277 277
278 278 Auto-parentheses: callable objects can be executed without parentheses:
279 279
280 280 \family typewriter
281 281 `sin 3'
282 282 \family default
283 283 is automatically converted to
284 284 \family typewriter
285 285 `sin(3)
286 286 \family default
287 287 '.
288 288 \layout Itemize
289 289
290 290 Auto-quoting: using `
291 291 \family typewriter
292 292 ,
293 293 \family default
294 294 ' or `
295 295 \family typewriter
296 296 ;
297 297 \family default
298 298 ' as the first character forces auto-quoting of the rest of the line:
299 299 \family typewriter
300 300 `,my_function a\SpecialChar ~
301 301 b'
302 302 \family default
303 303 becomes automatically
304 304 \family typewriter
305 305 `my_function("a","b")'
306 306 \family default
307 307 , while
308 308 \family typewriter
309 309 `;my_function a\SpecialChar ~
310 310 b'
311 311 \family default
312 312 becomes
313 313 \family typewriter
314 314 `my_function("a b")'
315 315 \family default
316 316 .
317 317 \layout Itemize
318 318
319 319 Extensible input syntax.
320 320 You can define filters that pre-process user input to simplify input in
321 321 special situations.
322 322 This allows for example pasting multi-line code fragments which start with
323 323
324 324 \family typewriter
325 325 `>>>'
326 326 \family default
327 327 or
328 328 \family typewriter
329 329 `...'
330 330 \family default
331 331 such as those from other python sessions or the standard Python documentation.
332 332 \layout Itemize
333 333
334 334 Flexible configuration system.
335 335 It uses a configuration file which allows permanent setting of all command-line
336 336 options, module loading, code and file execution.
337 337 The system allows recursive file inclusion, so you can have a base file
338 338 with defaults and layers which load other customizations for particular
339 339 projects.
340 340 \layout Itemize
341 341
342 342 Embeddable.
343 343 You can call IPython as a python shell inside your own python programs.
344 344 This can be used both for debugging code or for providing interactive abilities
345 345 to your programs with knowledge about the local namespaces (very useful
346 346 in debugging and data analysis situations).
347 347 \layout Itemize
348 348
349 349 Easy debugger access.
350 350 You can set IPython to call up the Python debugger (pdb) every time there
351 351 is an uncaught exception.
352 352 This drops you inside the code which triggered the exception with all the
353 353 data live and it is possible to navigate the stack to rapidly isolate the
354 354 source of a bug.
355 355 The
356 356 \family typewriter
357 357 %run
358 358 \family default
359 359 magic command --with the
360 360 \family typewriter
361 361 -d
362 362 \family default
363 363 option-- can run any script under
364 364 \family typewriter
365 365 pdb
366 366 \family default
367 367 's control, automatically setting initial breakpoints for you.
368 368 \layout Itemize
369 369
370 370 Profiler support.
371 371 You can run single statements (similar to
372 372 \family typewriter
373 373 profile.run()
374 374 \family default
375 375 ) or complete programs under the profiler's control.
376 376 While this is possible with the standard
377 377 \family typewriter
378 378 profile
379 379 \family default
380 380 module, IPython wraps this functionality with magic commands (see
381 381 \family typewriter
382 382 `%prun'
383 383 \family default
384 384 and
385 385 \family typewriter
386 386 `%run -p
387 387 \family default
388 388 ') convenient for rapid interactive work.
389 389 \layout Subsection
390 390
391 391 Portability and Python requirements
392 392 \layout Standard
393 393
394 394
395 395 \series bold
396 396 Python requirements:
397 397 \series default
398 398 IPython works with Python version 2.2 or newer.
399 399 It has been tested with Python 2.4 and no problems have been reported.
400 400 Support for Python 2.1 hasn't been recently tested, since I don't have access
401 401 to it on any of my systems.
402 402 But I suspect there may be some problems with Python 2.1, because some of
403 403 the newer code may use 2.2 features.
404 404 \layout Standard
405 405
406 406 IPython is developed under
407 407 \series bold
408 408 Linux
409 409 \series default
410 410 , but it should work in any reasonable Unix-type system (tested OK under
411 411 Solaris and the *BSD family, for which a port exists thanks to Dryice Liu).
412 412 \layout Standard
413 413
414 414
415 415 \series bold
416 416 Mac OS X
417 417 \series default
418 418 : it works, apparently without any problems (thanks to Jim Boyle at Lawrence
419 419 Livermore for the information).
420 420 Thanks to Andrea Riciputi, Fink support is available.
421 421 \layout Standard
422 422
423 423
424 424 \series bold
425 425 CygWin
426 426 \series default
427 427 : it works mostly OK, though some users have reported problems with prompt
428 428 coloring.
429 429 No satisfactory solution to this has been found so far, you may want to
430 430 disable colors permanently in the
431 431 \family typewriter
432 432 ipythonrc
433 433 \family default
434 434 configuration file if you experience problems.
435 435 If you have proper color support under cygwin, please post to the IPython
436 436 mailing list so this issue can be resolved for all users.
437 437 \layout Standard
438 438
439 439
440 440 \series bold
441 441 Windows
442 442 \series default
443 443 : it works well under Windows XP/2k, and I suspect NT should behave similarly.
444 444 Section\SpecialChar ~
445 445
446 446 \begin_inset LatexCommand \ref{sub:Under-Windows}
447 447
448 448 \end_inset
449 449
450 450 describes installation details for Windows, including some additional tools
451 451 needed on this platform.
452 452 \layout Standard
453 453
454 454 Windows 9x support is present, and has been reported to work fine (at least
455 455 on WinME).
456 456 \layout Standard
457 457
458 458 Please note, however, that I have very little access to and experience with
459 459 Windows development.
460 460 For this reason, Windows-specific bugs tend to linger far longer than I
461 461 would like, and often I just can't find a satisfactory solution.
462 462 If any Windows user wants to join in with development help, all hands are
463 463 always welcome.
464 464 \layout Subsection
465 465
466 466 Location
467 467 \layout Standard
468 468
469 469 IPython is generously hosted at
470 470 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
471 471
472 472 \end_inset
473 473
474 474 by the SciPy project.
475 475 This site offers downloads, subversion access, mailing lists and a bug
476 476 tracking system.
477 477 I am very grateful to Enthought (
478 478 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
479 479
480 480 \end_inset
481 481
482 482 ) and all of the SciPy team for their contribution.
483 483 \layout Section
484 484
485 485
486 486 \begin_inset LatexCommand \label{sec:install}
487 487
488 488 \end_inset
489 489
490 490 Installation
491 491 \layout Subsection
492 492
493 493 Instant instructions
494 494 \layout Standard
495 495
496 496 If you are of the impatient kind, under Linux/Unix simply untar/unzip the
497 497 download, then install with
498 498 \family typewriter
499 499 `python setup.py install'
500 500 \family default
501 501 .
502 502 Under Windows, double-click on the provided
503 503 \family typewriter
504 504 .exe
505 505 \family default
506 506 binary installer.
507 507 \layout Standard
508 508
509 509 Then, take a look at Sections
510 510 \begin_inset LatexCommand \ref{sec:good_config}
511 511
512 512 \end_inset
513 513
514 514 for configuring things optimally and
515 515 \begin_inset LatexCommand \ref{sec:quick_tips}
516 516
517 517 \end_inset
518 518
519 519 for quick tips on efficient use of IPython.
520 520 You can later refer to the rest of the manual for all the gory details.
521 521 \layout Standard
522 522
523 523 See the notes in sec.
524 524
525 525 \begin_inset LatexCommand \ref{sec:upgrade}
526 526
527 527 \end_inset
528 528
529 529 for upgrading IPython versions.
530 530 \layout Subsection
531 531
532 532 Detailed Unix instructions (Linux, Mac OS X, etc.)
533 533 \layout Standard
534 534
535 535 For RPM based systems, simply install the supplied package in the usual
536 536 manner.
537 537 If you download the tar archive, the process is:
538 538 \layout Enumerate
539 539
540 540 Unzip/untar the
541 541 \family typewriter
542 542 ipython-XXX.tar.gz
543 543 \family default
544 544 file wherever you want (
545 545 \family typewriter
546 546 XXX
547 547 \family default
548 548 is the version number).
549 549 It will make a directory called
550 550 \family typewriter
551 551 ipython-XXX.
552 552
553 553 \family default
554 554 Change into that directory where you will find the files
555 555 \family typewriter
556 556 README
557 557 \family default
558 558 and
559 559 \family typewriter
560 560 setup.py
561 561 \family default
562 562 .
563 563
564 564 \family typewriter
565 565 O
566 566 \family default
567 567 nce you've completed the installation, you can safely remove this directory.
568 568
569 569 \layout Enumerate
570 570
571 571 If you are installing over a previous installation of version 0.2.0 or earlier,
572 572 first remove your
573 573 \family typewriter
574 574 $HOME/.ipython
575 575 \family default
576 576 directory, since the configuration file format has changed somewhat (the
577 577 '=' were removed from all option specifications).
578 578 Or you can call ipython with the
579 579 \family typewriter
580 580 -upgrade
581 581 \family default
582 582 option and it will do this automatically for you.
583 583 \layout Enumerate
584 584
585 585 IPython uses distutils, so you can install it by simply typing at the system
586 586 prompt (don't type the
587 587 \family typewriter
588 588 $
589 589 \family default
590 590 )
591 591 \newline
592 592
593 593 \family typewriter
594 594 $ python setup.py install
595 595 \family default
596 596
597 597 \newline
598 598 Note that this assumes you have root access to your machine.
599 599 If you don't have root access or don't want IPython to go in the default
600 600 python directories, you'll need to use the
601 601 \begin_inset ERT
602 602 status Collapsed
603 603
604 604 \layout Standard
605 605
606 606 \backslash
607 607 verb|--home|
608 608 \end_inset
609 609
610 610 option (or
611 611 \begin_inset ERT
612 612 status Collapsed
613 613
614 614 \layout Standard
615 615
616 616 \backslash
617 617 verb|--prefix|
618 618 \end_inset
619 619
620 620 ).
621 621 For example:
622 622 \newline
623 623
624 624 \begin_inset ERT
625 625 status Collapsed
626 626
627 627 \layout Standard
628 628
629 629 \backslash
630 630 verb|$ python setup.py install --home $HOME/local|
631 631 \end_inset
632 632
633 633
634 634 \newline
635 635 will install IPython into
636 636 \family typewriter
637 637 $HOME/local
638 638 \family default
639 639 and its subdirectories (creating them if necessary).
640 640 \newline
641 641 You can type
642 642 \newline
643 643
644 644 \begin_inset ERT
645 645 status Collapsed
646 646
647 647 \layout Standard
648 648
649 649 \backslash
650 650 verb|$ python setup.py --help|
651 651 \end_inset
652 652
653 653
654 654 \newline
655 655 for more details.
656 656 \newline
657 657 Note that if you change the default location for
658 658 \begin_inset ERT
659 659 status Collapsed
660 660
661 661 \layout Standard
662 662
663 663 \backslash
664 664 verb|--home|
665 665 \end_inset
666 666
667 667 at installation, IPython may end up installed at a location which is not
668 668 part of your
669 669 \family typewriter
670 670 $PYTHONPATH
671 671 \family default
672 672 environment variable.
673 673 In this case, you'll need to configure this variable to include the actual
674 674 directory where the
675 675 \family typewriter
676 676 IPython/
677 677 \family default
678 678 directory ended (typically the value you give to
679 679 \begin_inset ERT
680 680 status Collapsed
681 681
682 682 \layout Standard
683 683
684 684 \backslash
685 685 verb|--home|
686 686 \end_inset
687 687
688 688 plus
689 689 \family typewriter
690 690 /lib/python
691 691 \family default
692 692 ).
693 693 \layout Subsubsection
694 694
695 695 Mac OSX information
696 696 \layout Standard
697 697
698 698 Under OSX, there is a choice you need to make.
699 699 Apple ships its own build of Python, which lives in the core OSX filesystem
700 700 hierarchy.
701 701 You can also manually install a separate Python, either purely by hand
702 702 (typically in
703 703 \family typewriter
704 704 /usr/local
705 705 \family default
706 706 ) or by using Fink, which puts everything under
707 707 \family typewriter
708 708 /sw
709 709 \family default
710 710 .
711 711 Which route to follow is a matter of personal preference, as I've seen
712 712 users who favor each of the approaches.
713 713 Here I will simply list the known installation issues under OSX, along
714 714 with their solutions.
715 715 \layout Standard
716 716
717 717 This page:
718 718 \begin_inset LatexCommand \htmlurl{http://geosci.uchicago.edu/~tobis/pylab.html}
719 719
720 720 \end_inset
721 721
722 722 contains information on this topic, with additional details on how to make
723 723 IPython and matplotlib play nicely under OSX.
724 724 \layout Subsubsection*
725 725
726 726 GUI problems
727 727 \layout Standard
728 728
729 729 The following instructions apply to an install of IPython under OSX from
730 730 unpacking the
731 731 \family typewriter
732 732 .tar.gz
733 733 \family default
734 734 distribution and installing it for the default Python interpreter shipped
735 735 by Apple.
736 736 If you are using a fink install, fink will take care of these details for
737 737 you, by installing IPython against fink's Python.
738 738 \layout Standard
739 739
740 740 IPython offers various forms of support for interacting with graphical applicati
741 741 ons from the command line, from simple Tk apps (which are in principle always
742 742 supported by Python) to interactive control of WX, Qt and GTK apps.
743 743 Under OSX, however, this requires that ipython is installed by calling
744 744 the special
745 745 \family typewriter
746 746 pythonw
747 747 \family default
748 748 script at installation time, which takes care of coordinating things with
749 749 Apple's graphical environment.
750 750 \layout Standard
751 751
752 752 So when installing under OSX, it is best to use the following command:
753 753 \family typewriter
754 754
755 755 \newline
756 756
757 757 \family default
758 758
759 759 \begin_inset ERT
760 760 status Collapsed
761 761
762 762 \layout Standard
763 763
764 764 \backslash
765 765 verb| $ sudo pythonw setup.py install --install-scripts=/usr/local/bin|
766 766 \end_inset
767 767
768 768
769 769 \newline
770 770 or
771 771 \newline
772 772
773 773 \begin_inset ERT
774 774 status Open
775 775
776 776 \layout Standard
777 777
778 778 \backslash
779 779 verb| $ sudo pythonw setup.py install --install-scripts=/usr/bin|
780 780 \end_inset
781 781
782 782
783 783 \newline
784 784 depending on where you like to keep hand-installed executables.
785 785 \layout Standard
786 786
787 787 The resulting script will have an appropriate shebang line (the first line
788 788 in the script whic begins with
789 789 \family typewriter
790 790 #!...
791 791 \family default
792 792 ) such that the ipython interpreter can interact with the OS X GUI.
793 793 If the installed version does not work and has a shebang line that points
794 794 to, for example, just
795 795 \family typewriter
796 796 /usr/bin/python
797 797 \family default
798 798 , then you might have a stale, cached version in your
799 799 \family typewriter
800 800 build/scripts-<python-version>
801 801 \family default
802 802 directory.
803 803 Delete that directory and rerun the
804 804 \family typewriter
805 805 setup.py
806 806 \family default
807 807 .
808 808
809 809 \layout Standard
810 810
811 811 It is also a good idea to use the special flag
812 812 \begin_inset ERT
813 813 status Collapsed
814 814
815 815 \layout Standard
816 816
817 817 \backslash
818 818 verb|--install-scripts|
819 819 \end_inset
820 820
821 821 as indicated above, to ensure that the ipython scripts end up in a location
822 822 which is part of your
823 823 \family typewriter
824 824 $PATH
825 825 \family default
826 826 .
827 827 Otherwise Apple's Python will put the scripts in an internal directory
828 828 not available by default at the command line (if you use
829 829 \family typewriter
830 830 /usr/local/bin
831 831 \family default
832 832 , you need to make sure this is in your
833 833 \family typewriter
834 834 $PATH
835 835 \family default
836 836 , which may not be true by default).
837 837 \layout Subsubsection*
838 838
839 839 Readline problems
840 840 \layout Standard
841 841
842 842 By default, the Python version shipped by Apple does
843 843 \emph on
844 844 not
845 845 \emph default
846 846 include the readline library, so central to IPython's behavior.
847 847 If you install IPython against Apple's Python, you will not have arrow
848 848 keys, tab completion, etc.
849 849 For Mac OSX 10.3 (Panther), you can find a prebuilt readline library here:
850 850 \newline
851 851
852 852 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip}
853 853
854 854 \end_inset
855 855
856 856
857 857 \layout Standard
858 858
859 859 If you are using OSX 10.4 (Tiger), after installing this package you need
860 860 to either:
861 861 \layout Enumerate
862 862
863 863 move
864 864 \family typewriter
865 865 readline.so
866 866 \family default
867 867 from
868 868 \family typewriter
869 869 /Library/Python/2.3
870 870 \family default
871 871 to
872 872 \family typewriter
873 873 /Library/Python/2.3/site-packages
874 874 \family default
875 875 , or
876 876 \layout Enumerate
877 877
878 878 install
879 879 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/TigerPython23Compat.pkg.zip}
880 880
881 881 \end_inset
882 882
883 883
884 884 \layout Standard
885 885
886 886 Users installing against Fink's Python or a properly hand-built one should
887 887 not have this problem.
888 888 \layout Subsection
889 889
890 890
891 891 \begin_inset LatexCommand \label{sub:Under-Windows}
892 892
893 893 \end_inset
894 894
895 895 Windows instructions
896 896 \layout Standard
897 897
898 898 While you can use IPython under Windows with only a stock Python installation,
899 899 there is one extension,
900 900 \family typewriter
901 901 readline
902 902 \family default
903 903 , which will make the whole experience a lot more pleasant.
904 904 It is almost a requirement, since IPython will complain in its absence
905 905 (though it will function).
906 906
907 907 \layout Standard
908 908
909 909 The
910 910 \family typewriter
911 911 readline
912 912 \family default
913 913 extension needs two other libraries to work, so in all you need:
914 914 \layout Enumerate
915 915
916 916
917 917 \family typewriter
918 918 PyWin32
919 919 \family default
920 920 from
921 921 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
922 922
923 923 \end_inset
924 924
925 925 .
926 926 \layout Enumerate
927 927
928 928
929 929 \family typewriter
930 930 CTypes
931 931 \family default
932 932 from
933 933 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
934 934
935 935 \end_inset
936 936
937 937 (you
938 938 \emph on
939 939 must
940 940 \emph default
941 941 use version 0.9.1 or newer).
942 942 \layout Enumerate
943 943
944 944
945 945 \family typewriter
946 946 Readline
947 947 \family default
948 948 for Windows from
949 949 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/uncpythontools}
950 950
951 951 \end_inset
952 952
953 953 .
954 954 \layout Standard
955 955
956 956
957 957 \series bold
958 958 Warning about a broken readline-like library:
959 959 \series default
960 960 several users have reported problems stemming from using the pseudo-readline
961 961 library at
962 962 \begin_inset LatexCommand \htmlurl{http://newcenturycomputers.net/projects/readline.html}
963 963
964 964 \end_inset
965 965
966 966 .
967 967 This is a broken library which, while called readline, only implements
968 968 an incomplete subset of the readline API.
969 969 Since it is still called readline, it fools IPython's detection mechanisms
970 970 and causes unpredictable crashes later.
971 971 If you wish to use IPython under Windows, you must NOT use this library,
972 972 which for all purposes is (at least as of version 1.6) terminally broken.
973 973 \layout Subsubsection
974 974
975 975 Gary Bishop's readline and color support for Windows
976 976 \layout Standard
977 977
978 978 Some of IPython's very useful features are:
979 979 \layout Itemize
980 980
981 981 Integrated readline support (Tab-based file, object and attribute completion,
982 982 input history across sessions, editable command line, etc.)
983 983 \layout Itemize
984 984
985 985 Coloring of prompts, code and tracebacks.
986 986 \layout Standard
987 987
988 988 These, by default, are only available under Unix-like operating systems.
989 989 However, thanks to Gary Bishop's work, Windows XP/2k users can also benefit
990 990 from them.
991 991 His readline library implements both GNU readline functionality and color
992 992 support, so that IPython under Windows XP/2k can be as friendly and powerful
993 993 as under Unix-like environments.
994 994 \layout Standard
995 995
996 996 You can find Gary's tools at
997 997 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/uncpythontools}
998 998
999 999 \end_inset
1000 1000
1001 1001 ; Gary's
1002 1002 \family typewriter
1003 1003 readline
1004 1004 \family default
1005 1005 requires in turn the
1006 1006 \family typewriter
1007 1007 ctypes
1008 1008 \family default
1009 1009 library by Thomas Heller, available at
1010 1010 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
1011 1011
1012 1012 \end_inset
1013 1013
1014 1014 , and Mark Hammond's
1015 1015 \family typewriter
1016 1016 PyWin32
1017 1017 \family default
1018 1018 from
1019 1019 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
1020 1020
1021 1021 \end_inset
1022 1022
1023 1023 (
1024 1024 \family typewriter
1025 1025 PyWin32
1026 1026 \family default
1027 1027 is great for anything Windows-related anyway, so you might as well get
1028 1028 it).
1029 1029 \layout Standard
1030 1030
1031 1031 Under MS\SpecialChar ~
1032 1032 Windows, IPython will complain if it can not find this
1033 1033 \family typewriter
1034 1034 readline
1035 1035 \family default
1036 1036 library at startup and any time the
1037 1037 \family typewriter
1038 1038 %colors
1039 1039 \family default
1040 1040 command is issued, so you can consider it to be a quasi-requirement.
1041 1041 \layout Subsubsection
1042 1042
1043 1043 Installation procedure
1044 1044 \layout Standard
1045 1045
1046 1046 Once you have the above installed, from the IPython download directory grab
1047 1047 the
1048 1048 \family typewriter
1049 1049 ipython-XXX.win32.exe
1050 1050 \family default
1051 1051 file, where
1052 1052 \family typewriter
1053 1053 XXX
1054 1054 \family default
1055 1055 represents the version number.
1056 1056 This is a regular windows executable installer, which you can simply double-cli
1057 1057 ck to install.
1058 1058 It will add an entry for IPython to your Start Menu, as well as registering
1059 1059 IPython in the Windows list of applications, so you can later uninstall
1060 1060 it from the Control Panel.
1061 1061
1062 1062 \layout Standard
1063 1063
1064 1064 IPython tries to install the configuration information in a directory named
1065 1065
1066 1066 \family typewriter
1067 1067 .ipython
1068 1068 \family default
1069 1069 (
1070 1070 \family typewriter
1071 1071 _ipython
1072 1072 \family default
1073 1073 under Windows) located in your `home' directory.
1074 1074 IPython sets this directory by looking for a
1075 1075 \family typewriter
1076 1076 HOME
1077 1077 \family default
1078 1078 environment variable; if such a variable does not exist, it uses
1079 1079 \family typewriter
1080 1080 HOMEDRIVE
1081 1081 \backslash
1082 1082 HOMEPATH
1083 1083 \family default
1084 1084 (these are always defined by Windows).
1085 1085 This typically gives something like
1086 1086 \family typewriter
1087 1087 C:
1088 1088 \backslash
1089 1089 Documents and Settings
1090 1090 \backslash
1091 1091 YourUserName
1092 1092 \family default
1093 1093 , but your local details may vary.
1094 1094 In this directory you will find all the files that configure IPython's
1095 1095 defaults, and you can put there your profiles and extensions.
1096 1096 This directory is automatically added by IPython to
1097 1097 \family typewriter
1098 1098 sys.path
1099 1099 \family default
1100 1100 , so anything you place there can be found by
1101 1101 \family typewriter
1102 1102 import
1103 1103 \family default
1104 1104 statements.
1105 1105 \layout Paragraph
1106 1106
1107 1107 Upgrading
1108 1108 \layout Standard
1109 1109
1110 1110 For an IPython upgrade, you should first uninstall the previous version.
1111 1111 This will ensure that all files and directories (such as the documentation)
1112 1112 which carry embedded version strings in their names are properly removed.
1113 1113 \layout Paragraph
1114 1114
1115 1115 Manual installation under Win32
1116 1116 \layout Standard
1117 1117
1118 1118 In case the automatic installer does not work for some reason, you can download
1119 1119 the
1120 1120 \family typewriter
1121 1121 ipython-XXX.tar.gz
1122 1122 \family default
1123 1123 file, which contains the full IPython source distribution (the popular
1124 1124 WinZip can read
1125 1125 \family typewriter
1126 1126 .tar.gz
1127 1127 \family default
1128 1128 files).
1129 1129 After uncompressing the archive, you can install it at a command terminal
1130 1130 just like any other Python module, by using
1131 1131 \family typewriter
1132 1132 `python setup.py install'
1133 1133 \family default
1134 1134 .
1135 1135
1136 1136 \layout Standard
1137 1137
1138 1138 After the installation, run the supplied
1139 1139 \family typewriter
1140 1140 win32_manual_post_install.py
1141 1141 \family default
1142 1142 script, which creates the necessary Start Menu shortcuts for you.
1143 1143 \layout Subsection
1144 1144
1145 1145
1146 1146 \begin_inset LatexCommand \label{sec:upgrade}
1147 1147
1148 1148 \end_inset
1149 1149
1150 1150 Upgrading from a previous version
1151 1151 \layout Standard
1152 1152
1153 1153 If you are upgrading from a previous version of IPython, after doing the
1154 1154 routine installation described above, you should call IPython with the
1155 1155
1156 1156 \family typewriter
1157 1157 -upgrade
1158 1158 \family default
1159 1159 option the first time you run your new copy.
1160 1160 This will automatically update your configuration directory while preserving
1161 1161 copies of your old files.
1162 1162 You can then later merge back any personal customizations you may have
1163 1163 made into the new files.
1164 1164 It is a good idea to do this as there may be new options available in the
1165 1165 new configuration files which you will not have.
1166 1166 \layout Standard
1167 1167
1168 1168 Under Windows, if you don't know how to call python scripts with arguments
1169 1169 from a command line, simply delete the old config directory and IPython
1170 1170 will make a new one.
1171 1171 Win2k and WinXP users will find it in
1172 1172 \family typewriter
1173 1173 C:
1174 1174 \backslash
1175 1175 Documents and Settings
1176 1176 \backslash
1177 1177 YourUserName
1178 1178 \backslash
1179 1179 _ipython
1180 1180 \family default
1181 1181 , and Win 9x users under
1182 1182 \family typewriter
1183 1183 C:
1184 1184 \backslash
1185 1185 Program Files
1186 1186 \backslash
1187 1187 IPython
1188 1188 \backslash
1189 1189 _ipython.
1190 1190 \layout Section
1191 1191
1192 1192
1193 1193 \begin_inset LatexCommand \label{sec:good_config}
1194 1194
1195 1195 \end_inset
1196 1196
1197 1197
1198 1198 \begin_inset OptArg
1199 1199 collapsed true
1200 1200
1201 1201 \layout Standard
1202 1202
1203 1203 Initial configuration
1204 1204 \begin_inset ERT
1205 1205 status Collapsed
1206 1206
1207 1207 \layout Standard
1208 1208
1209 1209 \backslash
1210 1210 ldots
1211 1211 \end_inset
1212 1212
1213 1213
1214 1214 \end_inset
1215 1215
1216 1216 Initial configuration of your environment
1217 1217 \layout Standard
1218 1218
1219 1219 This section will help you set various things in your environment for your
1220 1220 IPython sessions to be as efficient as possible.
1221 1221 All of IPython's configuration information, along with several example
1222 1222 files, is stored in a directory named by default
1223 1223 \family typewriter
1224 1224 $HOME/.ipython
1225 1225 \family default
1226 1226 .
1227 1227 You can change this by defining the environment variable
1228 1228 \family typewriter
1229 1229 IPYTHONDIR
1230 1230 \family default
1231 1231 , or at runtime with the command line option
1232 1232 \family typewriter
1233 1233 -ipythondir
1234 1234 \family default
1235 1235 .
1236 1236 \layout Standard
1237 1237
1238 1238 If all goes well, the first time you run IPython it should automatically
1239 1239 create a user copy of the config directory for you, based on its builtin
1240 1240 defaults.
1241 1241 You can look at the files it creates to learn more about configuring the
1242 1242 system.
1243 1243 The main file you will modify to configure IPython's behavior is called
1244 1244
1245 1245 \family typewriter
1246 1246 ipythonrc
1247 1247 \family default
1248 1248 (with a
1249 1249 \family typewriter
1250 1250 .ini
1251 1251 \family default
1252 1252 extension under Windows), included for reference in Sec.
1253 1253
1254 1254 \begin_inset LatexCommand \ref{sec:ipytonrc-sample}
1255 1255
1256 1256 \end_inset
1257 1257
1258 1258 .
1259 1259 This file is very commented and has many variables you can change to suit
1260 1260 your taste, you can find more details in Sec.
1261 1261
1262 1262 \begin_inset LatexCommand \ref{sec:customization}
1263 1263
1264 1264 \end_inset
1265 1265
1266 1266 .
1267 1267 Here we discuss the basic things you will want to make sure things are
1268 1268 working properly from the beginning.
1269 1269 \layout Subsection
1270 1270
1271 1271
1272 1272 \begin_inset LatexCommand \label{sec:help-access}
1273 1273
1274 1274 \end_inset
1275 1275
1276 1276 Access to the Python help system
1277 1277 \layout Standard
1278 1278
1279 1279 This is true for Python in general (not just for IPython): you should have
1280 1280 an environment variable called
1281 1281 \family typewriter
1282 1282 PYTHONDOCS
1283 1283 \family default
1284 1284 pointing to the directory where your HTML Python documentation lives.
1285 1285 In my system it's
1286 1286 \family typewriter
1287 1287 /usr/share/doc/python-docs-2.3.4/html
1288 1288 \family default
1289 1289 , check your local details or ask your systems administrator.
1290 1290
1291 1291 \layout Standard
1292 1292
1293 1293 This is the directory which holds the HTML version of the Python manuals.
1294 1294 Unfortunately it seems that different Linux distributions package these
1295 1295 files differently, so you may have to look around a bit.
1296 1296 Below I show the contents of this directory on my system for reference:
1297 1297 \layout Standard
1298 1298
1299 1299
1300 1300 \family typewriter
1301 1301 [html]> ls
1302 1302 \newline
1303 1303 about.dat acks.html dist/ ext/ index.html lib/ modindex.html stdabout.dat tut/
1304 1304 about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
1305 1305 \layout Standard
1306 1306
1307 1307 You should really make sure this variable is correctly set so that Python's
1308 1308 pydoc-based help system works.
1309 1309 It is a powerful and convenient system with full access to the Python manuals
1310 1310 and all modules accessible to you.
1311 1311 \layout Standard
1312 1312
1313 1313 Under Windows it seems that pydoc finds the documentation automatically,
1314 1314 so no extra setup appears necessary.
1315 1315 \layout Subsection
1316 1316
1317 1317 Editor
1318 1318 \layout Standard
1319 1319
1320 1320 The
1321 1321 \family typewriter
1322 1322 %edit
1323 1323 \family default
1324 1324 command (and its alias
1325 1325 \family typewriter
1326 1326 %ed
1327 1327 \family default
1328 1328 ) will invoke the editor set in your environment as
1329 1329 \family typewriter
1330 1330 EDITOR
1331 1331 \family default
1332 1332 .
1333 1333 If this variable is not set, it will default to
1334 1334 \family typewriter
1335 1335 vi
1336 1336 \family default
1337 1337 under Linux/Unix and to
1338 1338 \family typewriter
1339 1339 notepad
1340 1340 \family default
1341 1341 under Windows.
1342 1342 You may want to set this variable properly and to a lightweight editor
1343 1343 which doesn't take too long to start (that is, something other than a new
1344 1344 instance of
1345 1345 \family typewriter
1346 1346 Emacs
1347 1347 \family default
1348 1348 ).
1349 1349 This way you can edit multi-line code quickly and with the power of a real
1350 1350 editor right inside IPython.
1351 1351
1352 1352 \layout Standard
1353 1353
1354 1354 If you are a dedicated
1355 1355 \family typewriter
1356 1356 Emacs
1357 1357 \family default
1358 1358 user, you should set up the
1359 1359 \family typewriter
1360 1360 Emacs
1361 1361 \family default
1362 1362 server so that new requests are handled by the original process.
1363 1363 This means that almost no time is spent in handling the request (assuming
1364 1364 an
1365 1365 \family typewriter
1366 1366 Emacs
1367 1367 \family default
1368 1368 process is already running).
1369 1369 For this to work, you need to set your
1370 1370 \family typewriter
1371 1371 EDITOR
1372 1372 \family default
1373 1373 environment variable to
1374 1374 \family typewriter
1375 1375 'emacsclient'
1376 1376 \family default
1377 1377 .
1378 1378
1379 1379 \family typewriter
1380 1380
1381 1381 \family default
1382 1382 The code below, supplied by Francois Pinard, can then be used in your
1383 1383 \family typewriter
1384 1384 .emacs
1385 1385 \family default
1386 1386 file to enable the server:
1387 1387 \layout Standard
1388 1388
1389 1389
1390 1390 \family typewriter
1391 1391 (defvar server-buffer-clients)
1392 1392 \newline
1393 1393 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
1394 1394 \newline
1395 1395
1396 1396 \begin_inset ERT
1397 1397 status Collapsed
1398 1398
1399 1399 \layout Standard
1400 1400
1401 1401 \backslash
1402 1402 hspace*{0mm}
1403 1403 \end_inset
1404 1404
1405 1405 \SpecialChar ~
1406 1406 \SpecialChar ~
1407 1407 (server-start)
1408 1408 \newline
1409 1409
1410 1410 \begin_inset ERT
1411 1411 status Collapsed
1412 1412
1413 1413 \layout Standard
1414 1414
1415 1415 \backslash
1416 1416 hspace*{0mm}
1417 1417 \end_inset
1418 1418
1419 1419 \SpecialChar ~
1420 1420 \SpecialChar ~
1421 1421 (defun fp-kill-server-with-buffer-routine ()
1422 1422 \newline
1423 1423
1424 1424 \begin_inset ERT
1425 1425 status Collapsed
1426 1426
1427 1427 \layout Standard
1428 1428
1429 1429 \backslash
1430 1430 hspace*{0mm}
1431 1431 \end_inset
1432 1432
1433 1433 \SpecialChar ~
1434 1434 \SpecialChar ~
1435 1435 \SpecialChar ~
1436 1436 \SpecialChar ~
1437 1437 (and server-buffer-clients (server-done)))
1438 1438 \newline
1439 1439
1440 1440 \begin_inset ERT
1441 1441 status Collapsed
1442 1442
1443 1443 \layout Standard
1444 1444
1445 1445 \backslash
1446 1446 hspace*{0mm}
1447 1447 \end_inset
1448 1448
1449 1449 \SpecialChar ~
1450 1450 \SpecialChar ~
1451 1451 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
1452 1452 \layout Standard
1453 1453
1454 1454 You can also set the value of this editor via the commmand-line option '-
1455 1455 \family typewriter
1456 1456 editor'
1457 1457 \family default
1458 1458 or in your
1459 1459 \family typewriter
1460 1460 ipythonrc
1461 1461 \family default
1462 1462 file.
1463 1463 This is useful if you wish to use specifically for IPython an editor different
1464 1464 from your typical default (and for Windows users who tend to use fewer
1465 1465 environment variables).
1466 1466 \layout Subsection
1467 1467
1468 1468 Color
1469 1469 \layout Standard
1470 1470
1471 1471 The default IPython configuration has most bells and whistles turned on
1472 1472 (they're pretty safe).
1473 1473 But there's one that
1474 1474 \emph on
1475 1475 may
1476 1476 \emph default
1477 1477 cause problems on some systems: the use of color on screen for displaying
1478 1478 information.
1479 1479 This is very useful, since IPython can show prompts and exception tracebacks
1480 1480 with various colors, display syntax-highlighted source code, and in general
1481 1481 make it easier to visually parse information.
1482 1482 \layout Standard
1483 1483
1484 1484 The following terminals seem to handle the color sequences fine:
1485 1485 \layout Itemize
1486 1486
1487 1487 Linux main text console, KDE Konsole, Gnome Terminal, E-term, rxvt, xterm.
1488 1488 \layout Itemize
1489 1489
1490 1490 CDE terminal (tested under Solaris).
1491 1491 This one boldfaces light colors.
1492 1492 \layout Itemize
1493 1493
1494 1494 (X)Emacs buffers.
1495 1495 See sec.
1496 1496 \begin_inset LatexCommand \ref{sec:emacs}
1497 1497
1498 1498 \end_inset
1499 1499
1500 1500 for more details on using IPython with (X)Emacs.
1501 1501 \layout Itemize
1502 1502
1503 1503 A Windows (XP/2k) command prompt
1504 1504 \emph on
1505 1505 with Gary Bishop's support extensions
1506 1506 \emph default
1507 1507 .
1508 1508 Gary's extensions are discussed in Sec.\SpecialChar ~
1509 1509
1510 1510 \begin_inset LatexCommand \ref{sub:Under-Windows}
1511 1511
1512 1512 \end_inset
1513 1513
1514 1514 .
1515 1515 \layout Itemize
1516 1516
1517 1517 A Windows (XP/2k) CygWin shell.
1518 1518 Although some users have reported problems; it is not clear whether there
1519 1519 is an issue for everyone or only under specific configurations.
1520 1520 If you have full color support under cygwin, please post to the IPython
1521 1521 mailing list so this issue can be resolved for all users.
1522 1522 \layout Standard
1523 1523
1524 1524 These have shown problems:
1525 1525 \layout Itemize
1526 1526
1527 1527 Windows command prompt in WinXP/2k logged into a Linux machine via telnet
1528 1528 or ssh.
1529 1529 \layout Itemize
1530 1530
1531 1531 Windows native command prompt in WinXP/2k,
1532 1532 \emph on
1533 1533 without
1534 1534 \emph default
1535 1535 Gary Bishop's extensions.
1536 1536 Once Gary's readline library is installed, the normal WinXP/2k command
1537 1537 prompt works perfectly.
1538 1538 \layout Standard
1539 1539
1540 1540 Currently the following color schemes are available:
1541 1541 \layout Itemize
1542 1542
1543 1543
1544 1544 \family typewriter
1545 1545 NoColor
1546 1546 \family default
1547 1547 : uses no color escapes at all (all escapes are empty
1548 1548 \begin_inset Quotes eld
1549 1549 \end_inset
1550 1550
1551 1551
1552 1552 \begin_inset Quotes eld
1553 1553 \end_inset
1554 1554
1555 1555 strings).
1556 1556 This 'scheme' is thus fully safe to use in any terminal.
1557 1557 \layout Itemize
1558 1558
1559 1559
1560 1560 \family typewriter
1561 1561 Linux
1562 1562 \family default
1563 1563 : works well in Linux console type environments: dark background with light
1564 1564 fonts.
1565 1565 It uses bright colors for information, so it is difficult to read if you
1566 1566 have a light colored background.
1567 1567 \layout Itemize
1568 1568
1569 1569
1570 1570 \family typewriter
1571 1571 LightBG
1572 1572 \family default
1573 1573 : the basic colors are similar to those in the
1574 1574 \family typewriter
1575 1575 Linux
1576 1576 \family default
1577 1577 scheme but darker.
1578 1578 It is easy to read in terminals with light backgrounds.
1579 1579 \layout Standard
1580 1580
1581 1581 IPython uses colors for two main groups of things: prompts and tracebacks
1582 1582 which are directly printed to the terminal, and the object introspection
1583 1583 system which passes large sets of data through a pager.
1584 1584 \layout Subsubsection
1585 1585
1586 1586 Input/Output prompts and exception tracebacks
1587 1587 \layout Standard
1588 1588
1589 1589 You can test whether the colored prompts and tracebacks work on your system
1590 1590 interactively by typing
1591 1591 \family typewriter
1592 1592 '%colors Linux'
1593 1593 \family default
1594 1594 at the prompt (use '
1595 1595 \family typewriter
1596 1596 %colors LightBG'
1597 1597 \family default
1598 1598 if your terminal has a light background).
1599 1599 If the input prompt shows garbage like:
1600 1600 \newline
1601 1601
1602 1602 \family typewriter
1603 1603 [0;32mIn [[1;32m1[0;32m]: [0;00m
1604 1604 \family default
1605 1605
1606 1606 \newline
1607 1607 instead of (in color) something like:
1608 1608 \newline
1609 1609
1610 1610 \family typewriter
1611 1611 In [1]:
1612 1612 \family default
1613 1613
1614 1614 \newline
1615 1615 this means that your terminal doesn't properly handle color escape sequences.
1616 1616 You can go to a 'no color' mode by typing '
1617 1617 \family typewriter
1618 1618 %colors NoColor
1619 1619 \family default
1620 1620 '.
1621 1621
1622 1622 \layout Standard
1623 1623
1624 1624 You can try using a different terminal emulator program.
1625 1625 To permanently set your color preferences, edit the file
1626 1626 \family typewriter
1627 1627 $HOME/.ipython/ipythonrc
1628 1628 \family default
1629 1629 and set the
1630 1630 \family typewriter
1631 1631 colors
1632 1632 \family default
1633 1633 option to the desired value.
1634 1634 \layout Subsubsection
1635 1635
1636 1636 Object details (types, docstrings, source code, etc.)
1637 1637 \layout Standard
1638 1638
1639 1639 IPython has a set of special functions for studying the objects you are
1640 1640 working with, discussed in detail in Sec.
1641 1641
1642 1642 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1643 1643
1644 1644 \end_inset
1645 1645
1646 1646 .
1647 1647 But this system relies on passing information which is longer than your
1648 1648 screen through a data pager, such as the common Unix
1649 1649 \family typewriter
1650 1650 less
1651 1651 \family default
1652 1652 and
1653 1653 \family typewriter
1654 1654 more
1655 1655 \family default
1656 1656 programs.
1657 1657 In order to be able to see this information in color, your pager needs
1658 1658 to be properly configured.
1659 1659 I strongly recommend using
1660 1660 \family typewriter
1661 1661 less
1662 1662 \family default
1663 1663 instead of
1664 1664 \family typewriter
1665 1665 more
1666 1666 \family default
1667 1667 , as it seems that
1668 1668 \family typewriter
1669 1669 more
1670 1670 \family default
1671 1671 simply can not understand colored text correctly.
1672 1672 \layout Standard
1673 1673
1674 1674 In order to configure
1675 1675 \family typewriter
1676 1676 less
1677 1677 \family default
1678 1678 as your default pager, do the following:
1679 1679 \layout Enumerate
1680 1680
1681 1681 Set the environment
1682 1682 \family typewriter
1683 1683 PAGER
1684 1684 \family default
1685 1685 variable to
1686 1686 \family typewriter
1687 1687 less
1688 1688 \family default
1689 1689 .
1690 1690 \layout Enumerate
1691 1691
1692 1692 Set the environment
1693 1693 \family typewriter
1694 1694 LESS
1695 1695 \family default
1696 1696 variable to
1697 1697 \family typewriter
1698 1698 -r
1699 1699 \family default
1700 1700 (plus any other options you always want to pass to
1701 1701 \family typewriter
1702 1702 less
1703 1703 \family default
1704 1704 by default).
1705 1705 This tells
1706 1706 \family typewriter
1707 1707 less
1708 1708 \family default
1709 1709 to properly interpret control sequences, which is how color information
1710 1710 is given to your terminal.
1711 1711 \layout Standard
1712 1712
1713 1713 For the
1714 1714 \family typewriter
1715 1715 csh
1716 1716 \family default
1717 1717 or
1718 1718 \family typewriter
1719 1719 tcsh
1720 1720 \family default
1721 1721 shells, add to your
1722 1722 \family typewriter
1723 1723 ~/.cshrc
1724 1724 \family default
1725 1725 file the lines:
1726 1726 \layout Standard
1727 1727
1728 1728
1729 1729 \family typewriter
1730 1730 setenv PAGER less
1731 1731 \newline
1732 1732 setenv LESS -r
1733 1733 \layout Standard
1734 1734
1735 1735 There is similar syntax for other Unix shells, look at your system documentation
1736 1736 for details.
1737 1737 \layout Standard
1738 1738
1739 1739 If you are on a system which lacks proper data pagers (such as Windows),
1740 1740 IPython will use a very limited builtin pager.
1741 1741 \layout Subsection
1742 1742
1743 1743
1744 1744 \begin_inset LatexCommand \label{sec:emacs}
1745 1745
1746 1746 \end_inset
1747 1747
1748 1748 (X)Emacs configuration
1749 1749 \layout Standard
1750 1750
1751 1751 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, currently
1752 1752 (X)Emacs and IPython get along very well.
1753 1753
1754 1754 \layout Standard
1755 1755
1756 1756
1757 1757 \series bold
1758 1758 Important note:
1759 1759 \series default
1760 1760 You will need to use a recent enough version of
1761 1761 \family typewriter
1762 1762 python-mode.el
1763 1763 \family default
1764 1764 , along with the file
1765 1765 \family typewriter
1766 1766 ipython.el
1767 1767 \family default
1768 1768 .
1769 1769 You can check that the version you have of
1770 1770 \family typewriter
1771 1771 python-mode.el
1772 1772 \family default
1773 1773 is new enough by either looking at the revision number in the file itself,
1774 1774 or asking for it in (X)Emacs via
1775 1775 \family typewriter
1776 1776 M-x py-version
1777 1777 \family default
1778 1778 .
1779 1779 Versions 4.68 and newer contain the necessary fixes for proper IPython support.
1780 1780 \layout Standard
1781 1781
1782 1782 The file
1783 1783 \family typewriter
1784 1784 ipython.el
1785 1785 \family default
1786 1786 is included with the IPython distribution, in the documentation directory
1787 1787 (where this manual resides in PDF and HTML formats).
1788 1788 \layout Standard
1789 1789
1790 1790 Once you put these files in your Emacs path, all you need in your
1791 1791 \family typewriter
1792 1792 .emacs
1793 1793 \family default
1794 1794 file is:
1795 1795 \layout Standard
1796 1796
1797 1797
1798 1798 \family typewriter
1799 1799 (require 'ipython)
1800 1800 \layout Standard
1801 1801
1802 1802 This should give you full support for executing code snippets via IPython,
1803 1803 opening IPython as your Python shell via
1804 1804 \family typewriter
1805 1805 C-c\SpecialChar ~
1806 1806 !
1807 1807 \family default
1808 1808 , etc.
1809 1809
1810 1810 \layout Subsubsection*
1811 1811
1812 1812 Notes
1813 1813 \layout Itemize
1814 1814
1815 1815 There is one caveat you should be aware of: you must start the IPython shell
1816 1816
1817 1817 \emph on
1818 1818 before
1819 1819 \emph default
1820 1820 attempting to execute any code regions via
1821 1821 \family typewriter
1822 1822 C-c\SpecialChar ~
1823 1823 |
1824 1824 \family default
1825 1825 .
1826 1826 Simply type
1827 1827 \family typewriter
1828 1828 C-c\SpecialChar ~
1829 1829 !
1830 1830 \family default
1831 1831 to start IPython before passing any code regions to the interpreter, and
1832 1832 you shouldn't experience any problems.
1833 1833 \newline
1834 1834 This is due to a bug in Python itself, which has been fixed for Python 2.3,
1835 1835 but exists as of Python 2.2.2 (reported as SF bug [ 737947 ]).
1836 1836 \layout Itemize
1837 1837
1838 1838 The (X)Emacs support is maintained by Alexander Schmolck, so all comments/reques
1839 1839 ts should be directed to him through the IPython mailing lists.
1840 1840
1841 1841 \layout Itemize
1842 1842
1843 1843 This code is still somewhat experimental so it's a bit rough around the
1844 1844 edges (although in practice, it works quite well).
1845 1845 \layout Itemize
1846 1846
1847 1847 Be aware that if you customize
1848 1848 \family typewriter
1849 1849 py-python-command
1850 1850 \family default
1851 1851 previously, this value will override what
1852 1852 \family typewriter
1853 1853 ipython.el
1854 1854 \family default
1855 1855 does (because loading the customization variables comes later).
1856 1856 \layout Section
1857 1857
1858 1858
1859 1859 \begin_inset LatexCommand \label{sec:quick_tips}
1860 1860
1861 1861 \end_inset
1862 1862
1863 1863 Quick tips
1864 1864 \layout Standard
1865 1865
1866 1866 IPython can be used as an improved replacement for the Python prompt, and
1867 1867 for that you don't really need to read any more of this manual.
1868 1868 But in this section we'll try to summarize a few tips on how to make the
1869 1869 most effective use of it for everyday Python development, highlighting
1870 1870 things you might miss in the rest of the manual (which is getting long).
1871 1871 We'll give references to parts in the manual which provide more detail
1872 1872 when appropriate.
1873 1873 \layout Standard
1874 1874
1875 1875 The following article by Jeremy Jones provides an introductory tutorial
1876 1876 about IPython:
1877 1877 \newline
1878 1878
1879 1879 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html}
1880 1880
1881 1881 \end_inset
1882 1882
1883 1883
1884 1884 \layout Itemize
1885 1885
1886 1886 The TAB key.
1887 1887 TAB-completion, especially for attributes, is a convenient way to explore
1888 1888 the structure of any object you're dealing with.
1889 1889 Simply type
1890 1890 \family typewriter
1891 1891 object_name.<TAB>
1892 1892 \family default
1893 1893 and a list of the object's attributes will be printed (see sec.
1894 1894
1895 1895 \begin_inset LatexCommand \ref{sec:readline}
1896 1896
1897 1897 \end_inset
1898 1898
1899 1899 for more).
1900 1900 Tab completion also works on file and directory names, which combined with
1901 1901 IPython's alias system allows you to do from within IPython many of the
1902 1902 things you normally would need the system shell for.
1903 1903
1904 1904 \layout Itemize
1905 1905
1906 1906 Explore your objects.
1907 1907 Typing
1908 1908 \family typewriter
1909 1909 object_name?
1910 1910 \family default
1911 1911 will print all sorts of details about any object, including docstrings,
1912 1912 function definition lines (for call arguments) and constructor details
1913 1913 for classes.
1914 1914 The magic commands
1915 1915 \family typewriter
1916 1916 %pdoc
1917 1917 \family default
1918 1918 ,
1919 1919 \family typewriter
1920 1920 %pdef
1921 1921 \family default
1922 1922 ,
1923 1923 \family typewriter
1924 1924 %psource
1925 1925 \family default
1926 1926 and
1927 1927 \family typewriter
1928 1928 %pfile
1929 1929 \family default
1930 1930 will respectively print the docstring, function definition line, full source
1931 1931 code and the complete file for any object (when they can be found).
1932 1932 If automagic is on (it is by default), you don't need to type the '
1933 1933 \family typewriter
1934 1934 %
1935 1935 \family default
1936 1936 ' explicitly.
1937 1937 See sec.
1938 1938
1939 1939 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1940 1940
1941 1941 \end_inset
1942 1942
1943 1943 for more.
1944 1944 \layout Itemize
1945 1945
1946 1946 The
1947 1947 \family typewriter
1948 1948 %run
1949 1949 \family default
1950 1950 magic command allows you to run any python script and load all of its data
1951 1951 directly into the interactive namespace.
1952 1952 Since the file is re-read from disk each time, changes you make to it are
1953 1953 reflected immediately (in contrast to the behavior of
1954 1954 \family typewriter
1955 1955 import
1956 1956 \family default
1957 1957 ).
1958 1958 I rarely use
1959 1959 \family typewriter
1960 1960 import
1961 1961 \family default
1962 1962 for code I am testing, relying on
1963 1963 \family typewriter
1964 1964 %run
1965 1965 \family default
1966 1966 instead.
1967 1967 See sec.
1968 1968
1969 1969 \begin_inset LatexCommand \ref{sec:magic}
1970 1970
1971 1971 \end_inset
1972 1972
1973 1973 for more on this and other magic commands, or type the name of any magic
1974 1974 command and ? to get details on it.
1975 1975 See also sec.
1976 1976
1977 1977 \begin_inset LatexCommand \ref{sec:dreload}
1978 1978
1979 1979 \end_inset
1980 1980
1981 1981 for a recursive reload command.
1982 1982 \newline
1983 1983
1984 1984 \family typewriter
1985 1985 %run
1986 1986 \family default
1987 1987 also has special flags for timing the execution of your scripts (
1988 1988 \family typewriter
1989 1989 -t
1990 1990 \family default
1991 1991 ) and for executing them under the control of either Python's
1992 1992 \family typewriter
1993 1993 pdb
1994 1994 \family default
1995 1995 debugger (
1996 1996 \family typewriter
1997 1997 -d
1998 1998 \family default
1999 1999 ) or profiler (
2000 2000 \family typewriter
2001 2001 -p
2002 2002 \family default
2003 2003 ).
2004 2004 With all of these,
2005 2005 \family typewriter
2006 2006 %run
2007 2007 \family default
2008 2008 can be used as the main tool for efficient interactive development of code
2009 2009 which you write in your editor of choice.
2010 2010 \layout Itemize
2011 2011
2012 2012 Use the Python debugger,
2013 2013 \family typewriter
2014 2014 pdb
2015 2015 \family default
2016 2016
2017 2017 \begin_inset Foot
2018 2018 collapsed true
2019 2019
2020 2020 \layout Standard
2021 2021
2022 2022 Thanks to Christian Hart and Matthew Arnison for the suggestions leading
2023 2023 to IPython's improved debugger and profiler support.
2024 2024 \end_inset
2025 2025
2026 2026 .
2027 2027 The
2028 2028 \family typewriter
2029 2029 %pdb
2030 2030 \family default
2031 2031 command allows you to toggle on and off the automatic invocation of the
2032 2032 pdb debugger at any uncaught exception.
2033 2033 The advantage of this is that pdb starts
2034 2034 \emph on
2035 2035 inside
2036 2036 \emph default
2037 2037 the function where the exception occurred, with all data still available.
2038 2038 You can print variables, see code, execute statements and even walk up
2039 2039 and down the call stack to track down the true source of the problem (which
2040 2040 often is many layers in the stack above where the exception gets triggered).
2041 2041 \newline
2042 2042 Running programs with
2043 2043 \family typewriter
2044 2044 %run
2045 2045 \family default
2046 2046 and pdb active can be an efficient to develop and debug code, in many cases
2047 2047 eliminating the need for
2048 2048 \family typewriter
2049 2049 print
2050 2050 \family default
2051 2051 statements or external debugging tools.
2052 2052 I often simply put a
2053 2053 \family typewriter
2054 2054 1/0
2055 2055 \family default
2056 2056 in a place where I want to take a look so that pdb gets called, quickly
2057 2057 view whatever variables I need to or test various pieces of code and then
2058 2058 remove the
2059 2059 \family typewriter
2060 2060 1/0
2061 2061 \family default
2062 2062 .
2063 2063 \newline
2064 2064 Note also that `
2065 2065 \family typewriter
2066 2066 %run -d
2067 2067 \family default
2068 2068 ' activates
2069 2069 \family typewriter
2070 2070 pdb
2071 2071 \family default
2072 2072 and automatically sets initial breakpoints for you to step through your
2073 2073 code, watch variables, etc.
2074 2074 See Sec.\SpecialChar ~
2075 2075
2076 2076 \begin_inset LatexCommand \ref{sec:cache_output}
2077 2077
2078 2078 \end_inset
2079 2079
2080 2080 for details.
2081 2081 \layout Itemize
2082 2082
2083 2083 Use the output cache.
2084 2084 All output results are automatically stored in a global dictionary named
2085 2085
2086 2086 \family typewriter
2087 2087 Out
2088 2088 \family default
2089 2089 and variables named
2090 2090 \family typewriter
2091 2091 _1
2092 2092 \family default
2093 2093 ,
2094 2094 \family typewriter
2095 2095 _2
2096 2096 \family default
2097 2097 , etc.
2098 2098 alias them.
2099 2099 For example, the result of input line 4 is available either as
2100 2100 \family typewriter
2101 2101 Out[4]
2102 2102 \family default
2103 2103 or as
2104 2104 \family typewriter
2105 2105 _4
2106 2106 \family default
2107 2107 .
2108 2108 Additionally, three variables named
2109 2109 \family typewriter
2110 2110 _
2111 2111 \family default
2112 2112 ,
2113 2113 \family typewriter
2114 2114 __
2115 2115 \family default
2116 2116 and
2117 2117 \family typewriter
2118 2118 ___
2119 2119 \family default
2120 2120 are always kept updated with the for the last three results.
2121 2121 This allows you to recall any previous result and further use it for new
2122 2122 calculations.
2123 2123 See Sec.\SpecialChar ~
2124 2124
2125 2125 \begin_inset LatexCommand \ref{sec:cache_output}
2126 2126
2127 2127 \end_inset
2128 2128
2129 2129 for more.
2130 2130 \layout Itemize
2131 2131
2132 2132 Put a '
2133 2133 \family typewriter
2134 2134 ;
2135 2135 \family default
2136 2136 ' at the end of a line to supress the printing of output.
2137 2137 This is useful when doing calculations which generate long output you are
2138 2138 not interested in seeing.
2139 2139 The
2140 2140 \family typewriter
2141 2141 _*
2142 2142 \family default
2143 2143 variables and the
2144 2144 \family typewriter
2145 2145 Out[]
2146 2146 \family default
2147 2147 list do get updated with the contents of the output, even if it is not
2148 2148 printed.
2149 2149 You can thus still access the generated results this way for further processing.
2150 2150 \layout Itemize
2151 2151
2152 2152 A similar system exists for caching input.
2153 2153 All input is stored in a global list called
2154 2154 \family typewriter
2155 2155 In
2156 2156 \family default
2157 2157 , so you can re-execute lines 22 through 28 plus line 34 by typing
2158 2158 \family typewriter
2159 2159 'exec In[22:29]+In[34]'
2160 2160 \family default
2161 2161 (using Python slicing notation).
2162 2162 If you need to execute the same set of lines often, you can assign them
2163 2163 to a macro with the
2164 2164 \family typewriter
2165 2165 %macro
2166 2166 \family default
2167 2167
2168 2168 \family typewriter
2169 2169 function.
2170 2170
2171 2171 \family default
2172 2172 See sec.
2173 2173
2174 2174 \begin_inset LatexCommand \ref{sec:cache_input}
2175 2175
2176 2176 \end_inset
2177 2177
2178 2178 for more.
2179 2179 \layout Itemize
2180 2180
2181 2181 Use your input history.
2182 2182 The
2183 2183 \family typewriter
2184 2184 %hist
2185 2185 \family default
2186 2186 command can show you all previous input, without line numbers if desired
2187 2187 (option
2188 2188 \family typewriter
2189 2189 -n
2190 2190 \family default
2191 2191 ) so you can directly copy and paste code either back in IPython or in a
2192 2192 text editor.
2193 2193 You can also save all your history by turning on logging via
2194 2194 \family typewriter
2195 2195 %logstart
2196 2196 \family default
2197 2197 ; these logs can later be either reloaded as IPython sessions or used as
2198 2198 code for your programs.
2199 2199 \layout Itemize
2200 2200
2201 2201 Define your own macros with
2202 2202 \family typewriter
2203 2203 %macro
2204 2204 \family default
2205 2205 .
2206 2206 This can be useful for automating sequences of expressions when working
2207 2207 interactively.
2208 2208 \layout Itemize
2209 2209
2210 2210 Define your own system aliases.
2211 2211 Even though IPython gives you access to your system shell via the
2212 2212 \family typewriter
2213 2213 !
2214 2214 \family default
2215 2215 prefix, it is convenient to have aliases to the system commands you use
2216 2216 most often.
2217 2217 This allows you to work seamlessly from inside IPython with the same commands
2218 2218 you are used to in your system shell.
2219 2219 \newline
2220 2220 IPython comes with some pre-defined aliases and a complete system for changing
2221 2221 directories, both via a stack (see
2222 2222 \family typewriter
2223 2223 %pushd
2224 2224 \family default
2225 2225 ,
2226 2226 \family typewriter
2227 2227 %popd
2228 2228 \family default
2229 2229 and
2230 2230 \family typewriter
2231 2231 %ds
2232 2232 \family default
2233 2233 ) and via direct
2234 2234 \family typewriter
2235 2235 %cd
2236 2236 \family default
2237 2237 .
2238 2238 The latter keeps a history of visited directories and allows you to go
2239 2239 to any previously visited one.
2240 2240 \layout Itemize
2241 2241
2242 2242 Use Python to manipulate the results of system commands.
2243 2243 The `
2244 2244 \family typewriter
2245 2245 !!
2246 2246 \family default
2247 2247 ' special syntax, and the
2248 2248 \family typewriter
2249 2249 %sc
2250 2250 \family default
2251 2251 and
2252 2252 \family typewriter
2253 2253 %sx
2254 2254 \family default
2255 2255 magic commands allow you to capture system output into Python variables.
2256 2256 \layout Itemize
2257 2257
2258 2258 Expand python variables when calling the shell (either via
2259 2259 \family typewriter
2260 2260 `!'
2261 2261 \family default
2262 2262 and
2263 2263 \family typewriter
2264 2264 `!!'
2265 2265 \family default
2266 2266 or via aliases) by prepending a
2267 2267 \family typewriter
2268 2268 $
2269 2269 \family default
2270 2270 in front of them.
2271 2271 You can also expand complete python expressions.
2272 2272 See sec.\SpecialChar ~
2273 2273
2274 2274 \begin_inset LatexCommand \ref{sub:System-shell-access}
2275 2275
2276 2276 \end_inset
2277 2277
2278 2278 for more.
2279 2279 \layout Itemize
2280 2280
2281 2281 Use profiles to maintain different configurations (modules to load, function
2282 2282 definitions, option settings) for particular tasks.
2283 2283 You can then have customized versions of IPython for specific purposes.
2284 2284 See sec.\SpecialChar ~
2285 2285
2286 2286 \begin_inset LatexCommand \ref{sec:profiles}
2287 2287
2288 2288 \end_inset
2289 2289
2290 2290 for more.
2291 2291 \layout Itemize
2292 2292
2293 2293 Embed IPython in your programs.
2294 2294 A few lines of code are enough to load a complete IPython inside your own
2295 2295 programs, giving you the ability to work with your data interactively after
2296 2296 automatic processing has been completed.
2297 2297 See sec.\SpecialChar ~
2298 2298
2299 2299 \begin_inset LatexCommand \ref{sec:embed}
2300 2300
2301 2301 \end_inset
2302 2302
2303 2303 for more.
2304 2304 \layout Itemize
2305 2305
2306 2306 Use the Python profiler.
2307 2307 When dealing with performance issues, the
2308 2308 \family typewriter
2309 2309 %run
2310 2310 \family default
2311 2311 command with a
2312 2312 \family typewriter
2313 2313 -p
2314 2314 \family default
2315 2315 option allows you to run complete programs under the control of the Python
2316 2316 profiler.
2317 2317 The
2318 2318 \family typewriter
2319 2319 %prun
2320 2320 \family default
2321 2321 command does a similar job for single Python expressions (like function
2322 2322 calls).
2323 2323 \layout Itemize
2324 2324
2325 2325 Use
2326 2326 \family typewriter
2327 2327 %edit
2328 2328 \family default
2329 2329 to have almost multiline editing.
2330 2330 While IPython doesn't support true multiline editing, this command allows
2331 2331 you to call an editor on the spot, and IPython will execute the code you
2332 2332 type in there as if it were typed interactively.
2333 2333 \layout Itemize
2334 2334
2335 2335 Use the IPython.demo.Demo class to load any Python script as an interactive
2336 2336 demo.
2337 2337 With a minimal amount of simple markup, you can control the execution of
2338 2338 the script, stopping as needed.
2339 2339 See sec.\SpecialChar ~
2340 2340
2341 2341 \begin_inset LatexCommand \ref{sec:interactive-demos}
2342 2342
2343 2343 \end_inset
2344 2344
2345 2345 for more.
2346 2346 \layout Standard
2347 2347
2348 2348 If you have your own favorite tip on using IPython efficiently for a certain
2349 2349 task (especially things which can't be done in the normal Python interpreter),
2350 2350 don't hesitate to send it!
2351 2351 \layout Section
2352 2352
2353 2353 Command-line use
2354 2354 \layout Standard
2355 2355
2356 2356 You start IPython with the command:
2357 2357 \layout Standard
2358 2358
2359 2359
2360 2360 \family typewriter
2361 2361 $ ipython [options] files
2362 2362 \layout Standard
2363 2363
2364 2364 If invoked with no options, it executes all the files listed in sequence
2365 2365 and drops you into the interpreter while still acknowledging any options
2366 2366 you may have set in your ipythonrc file.
2367 2367 This behavior is different from standard Python, which when called as
2368 2368 \family typewriter
2369 2369 python -i
2370 2370 \family default
2371 2371 will only execute one file and ignore your configuration setup.
2372 2372 \layout Standard
2373 2373
2374 2374 Please note that some of the configuration options are not available at
2375 2375 the command line, simply because they are not practical here.
2376 2376 Look into your ipythonrc configuration file for details on those.
2377 2377 This file typically installed in the
2378 2378 \family typewriter
2379 2379 $HOME/.ipython
2380 2380 \family default
2381 2381 directory.
2382 2382 For Windows users,
2383 2383 \family typewriter
2384 2384 $HOME
2385 2385 \family default
2386 2386 resolves to
2387 2387 \family typewriter
2388 2388 C:
2389 2389 \backslash
2390 2390
2391 2391 \backslash
2392 2392 Documents and Settings
2393 2393 \backslash
2394 2394
2395 2395 \backslash
2396 2396 YourUserName
2397 2397 \family default
2398 2398 in most instances.
2399 2399 In the rest of this text, we will refer to this directory as
2400 2400 \family typewriter
2401 2401 IPYTHONDIR
2402 2402 \family default
2403 2403 .
2404 2404 \layout Subsection
2405 2405
2406 2406
2407 2407 \begin_inset LatexCommand \label{sec:threading-opts}
2408 2408
2409 2409 \end_inset
2410 2410
2411 2411 Special Threading Options
2412 2412 \layout Standard
2413 2413
2414 2414 The following special options are ONLY valid at the beginning of the command
2415 2415 line, and not later.
2416 2416 This is because they control the initial- ization of ipython itself, before
2417 2417 the normal option-handling mechanism is active.
2418 2418 \layout List
2419 2419 \labelwidthstring 00.00.0000
2420 2420
2421 2421
2422 2422 \family typewriter
2423 2423 \series bold
2424 2424 -gthread,\SpecialChar ~
2425 2425 -qthread,\SpecialChar ~
2426 2426 -wthread,\SpecialChar ~
2427 2427 -pylab:
2428 2428 \family default
2429 2429 \series default
2430 2430 Only
2431 2431 \emph on
2432 2432 one
2433 2433 \emph default
2434 2434 of these can be given, and it can only be given as the first option passed
2435 2435 to IPython (it will have no effect in any other position).
2436 2436 They provide threading support for the GTK Qt and WXPython toolkits, and
2437 2437 for the matplotlib library.
2438 2438 \layout List
2439 2439 \labelwidthstring 00.00.0000
2440 2440
2441 2441 \SpecialChar ~
2442 2442 With any of the first three options, IPython starts running a separate
2443 2443 thread for the graphical toolkit's operation, so that you can open and
2444 2444 control graphical elements from within an IPython command line, without
2445 2445 blocking.
2446 2446 All three provide essentially the same functionality, respectively for
2447 2447 GTK, QT and WXWidgets (via their Python interfaces).
2448 2448 \layout List
2449 2449 \labelwidthstring 00.00.0000
2450 2450
2451 2451 \SpecialChar ~
2452 2452 If
2453 2453 \family typewriter
2454 2454 -pylab
2455 2455 \family default
2456 2456 is given, IPython loads special support for the mat plotlib library (
2457 2457 \begin_inset LatexCommand \htmlurl{http://matplotlib.sourceforge.net}
2458 2458
2459 2459 \end_inset
2460 2460
2461 2461 ), allowing interactive usage of any of its backends as defined in the user's
2462 2462
2463 2463 \family typewriter
2464 2464 ~/.matplotlib/matplotlibrc
2465 2465 \family default
2466 2466 file.
2467 2467 It automatically activates GTK, Qt or WX threading for IPyhton if the choice
2468 2468 of matplotlib backend requires it.
2469 2469 It also modifies the
2470 2470 \family typewriter
2471 2471 %run
2472 2472 \family default
2473 2473 command to correctly execute (without blocking) any matplotlib-based script
2474 2474 which calls
2475 2475 \family typewriter
2476 2476 show()
2477 2477 \family default
2478 2478 at the end.
2479 2479
2480 2480 \layout List
2481 2481 \labelwidthstring 00.00.0000
2482 2482
2483 2483
2484 2484 \family typewriter
2485 2485 \series bold
2486 2486 -tk
2487 2487 \family default
2488 2488 \series default
2489 2489 The
2490 2490 \family typewriter
2491 2491 -g/q/wthread
2492 2492 \family default
2493 2493 options, and
2494 2494 \family typewriter
2495 2495 -pylab
2496 2496 \family default
2497 2497 (if matplotlib is configured to use GTK, Qt or WX), will normally block
2498 2498 Tk graphical interfaces.
2499 2499 This means that when either GTK, Qt or WX threading is active, any attempt
2500 2500 to open a Tk GUI will result in a dead window, and possibly cause the Python
2501 2501 interpreter to crash.
2502 2502 An extra option,
2503 2503 \family typewriter
2504 2504 -tk
2505 2505 \family default
2506 2506 , is available to address this issue.
2507 2507 It can
2508 2508 \emph on
2509 2509 only
2510 2510 \emph default
2511 2511 be given as a
2512 2512 \emph on
2513 2513 second
2514 2514 \emph default
2515 2515 option after any of the above (
2516 2516 \family typewriter
2517 2517 -gthread
2518 2518 \family default
2519 2519 ,
2520 2520 \family typewriter
2521 2521 -wthread
2522 2522 \family default
2523 2523 or
2524 2524 \family typewriter
2525 2525 -pylab
2526 2526 \family default
2527 2527 ).
2528 2528 \layout List
2529 2529 \labelwidthstring 00.00.0000
2530 2530
2531 2531 \SpecialChar ~
2532 2532 If
2533 2533 \family typewriter
2534 2534 -tk
2535 2535 \family default
2536 2536 is given, IPython will try to coordinate Tk threading with GTK, Qt or WX.
2537 2537 This is however potentially unreliable, and you will have to test on your
2538 2538 platform and Python configuration to determine whether it works for you.
2539 2539 Debian users have reported success, apparently due to the fact that Debian
2540 2540 builds all of Tcl, Tk, Tkinter and Python with pthreads support.
2541 2541 Under other Linux environments (such as Fedora Core 2/3), this option has
2542 2542 caused random crashes and lockups of the Python interpreter.
2543 2543 Under other operating systems (Mac OSX and Windows), you'll need to try
2544 2544 it to find out, since currently no user reports are available.
2545 2545 \layout List
2546 2546 \labelwidthstring 00.00.0000
2547 2547
2548 2548 \SpecialChar ~
2549 2549 There is unfortunately no way for IPython to determine at run time whether
2550 2550
2551 2551 \family typewriter
2552 2552 -tk
2553 2553 \family default
2554 2554 will work reliably or not, so you will need to do some experiments before
2555 2555 relying on it for regular work.
2556 2556
2557 2557 \layout Subsection
2558 2558
2559 2559
2560 2560 \begin_inset LatexCommand \label{sec:cmd-line-opts}
2561 2561
2562 2562 \end_inset
2563 2563
2564 2564 Regular Options
2565 2565 \layout Standard
2566 2566
2567 2567 After the above threading options have been given, regular options can follow
2568 2568 in any order.
2569 2569 All options can be abbreviated to their shortest non-ambiguous form and
2570 2570 are case-sensitive.
2571 2571 One or two dashes can be used.
2572 2572 Some options have an alternate short form, indicated after a
2573 2573 \family typewriter
2574 2574 |
2575 2575 \family default
2576 2576 .
2577 2577 \layout Standard
2578 2578
2579 2579 Most options can also be set from your ipythonrc configuration file.
2580 2580 See the provided example for more details on what the options do.
2581 2581 Options given at the command line override the values set in the ipythonrc
2582 2582 file.
2583 2583 \layout Standard
2584 2584
2585 2585 All options with a
2586 2586 \family typewriter
2587 2587 no|
2588 2588 \family default
2589 2589 prepended can be specified in 'no' form (
2590 2590 \family typewriter
2591 2591 -nooption
2592 2592 \family default
2593 2593 instead of
2594 2594 \family typewriter
2595 2595 -option
2596 2596 \family default
2597 2597 ) to turn the feature off.
2598 2598 \layout List
2599 2599 \labelwidthstring 00.00.0000
2600 2600
2601 2601
2602 2602 \family typewriter
2603 2603 \series bold
2604 2604 -help
2605 2605 \family default
2606 2606 \series default
2607 2607 : print a help message and exit.
2608 2608 \layout List
2609 2609 \labelwidthstring 00.00.0000
2610 2610
2611 2611
2612 2612 \family typewriter
2613 2613 \series bold
2614 2614 -pylab:
2615 2615 \family default
2616 2616 \series default
2617 2617 this can
2618 2618 \emph on
2619 2619 only
2620 2620 \emph default
2621 2621 be given as the
2622 2622 \emph on
2623 2623 first
2624 2624 \emph default
2625 2625 option passed to IPython (it will have no effect in any other position).
2626 2626 It adds special support for the matplotlib library (
2627 2627 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
2628 2628
2629 2629 \end_inset
2630 2630
2631 2631 ), allowing interactive usage of any of its backends as defined in the user's
2632 2632
2633 2633 \family typewriter
2634 2634 .matplotlibrc
2635 2635 \family default
2636 2636 file.
2637 2637 It automatically activates GTK or WX threading for IPyhton if the choice
2638 2638 of matplotlib backend requires it.
2639 2639 It also modifies the
2640 2640 \family typewriter
2641 2641 %run
2642 2642 \family default
2643 2643 command to correctly execute (without blocking) any matplotlib-based script
2644 2644 which calls
2645 2645 \family typewriter
2646 2646 show()
2647 2647 \family default
2648 2648 at the end.
2649 2649 See Sec.\SpecialChar ~
2650 2650
2651 2651 \begin_inset LatexCommand \ref{sec:matplotlib-support}
2652 2652
2653 2653 \end_inset
2654 2654
2655 2655 for more details.
2656 2656 \layout List
2657 2657 \labelwidthstring 00.00.0000
2658 2658
2659 2659
2660 2660 \family typewriter
2661 2661 \series bold
2662 2662 -no|automagic
2663 2663 \series default
2664 2664 :
2665 2665 \family default
2666 2666 make magic commands automatic (without needing their first character to
2667 2667 be
2668 2668 \family typewriter
2669 2669 %
2670 2670 \family default
2671 2671 ).
2672 2672 Type
2673 2673 \family typewriter
2674 2674 %magic
2675 2675 \family default
2676 2676 at the IPython prompt for more information.
2677 2677 \layout List
2678 2678 \labelwidthstring 00.00.0000
2679 2679
2680 2680
2681 2681 \family typewriter
2682 2682 \series bold
2683 2683 -no|banner
2684 2684 \series default
2685 2685 :
2686 2686 \family default
2687 2687 Print the initial information banner (default on).
2688 2688 \layout List
2689 2689 \labelwidthstring 00.00.0000
2690 2690
2691 2691
2692 2692 \family typewriter
2693 2693 \series bold
2694 2694 -c\SpecialChar ~
2695 2695 <command>:
2696 2696 \family default
2697 2697 \series default
2698 2698 execute the given command string, and set sys.argv to
2699 2699 \family typewriter
2700 2700 ['c']
2701 2701 \family default
2702 2702 .
2703 2703 This is similar to the
2704 2704 \family typewriter
2705 2705 -c
2706 2706 \family default
2707 2707 option in the normal Python interpreter.
2708 2708
2709 2709 \layout List
2710 2710 \labelwidthstring 00.00.0000
2711 2711
2712 2712
2713 2713 \family typewriter
2714 2714 \series bold
2715 2715 -cache_size|cs\SpecialChar ~
2716 2716 <n>
2717 2717 \series default
2718 2718 :
2719 2719 \family default
2720 2720 size of the output cache (maximum number of entries to hold in memory).
2721 2721 The default is 1000, you can change it permanently in your config file.
2722 2722 Setting it to 0 completely disables the caching system, and the minimum
2723 2723 value accepted is 20 (if you provide a value less than 20, it is reset
2724 2724 to 0 and a warning is issued) This limit is defined because otherwise you'll
2725 2725 spend more time re-flushing a too small cache than working.
2726 2726 \layout List
2727 2727 \labelwidthstring 00.00.0000
2728 2728
2729 2729
2730 2730 \family typewriter
2731 2731 \series bold
2732 2732 -classic|cl
2733 2733 \series default
2734 2734 :
2735 2735 \family default
2736 2736 Gives IPython a similar feel to the classic Python prompt.
2737 2737 \layout List
2738 2738 \labelwidthstring 00.00.0000
2739 2739
2740 2740
2741 2741 \family typewriter
2742 2742 \series bold
2743 2743 -colors\SpecialChar ~
2744 2744 <scheme>:
2745 2745 \family default
2746 2746 \series default
2747 2747 Color scheme for prompts and exception reporting.
2748 2748 Currently implemented: NoColor, Linux and LightBG.
2749 2749 \layout List
2750 2750 \labelwidthstring 00.00.0000
2751 2751
2752 2752
2753 2753 \family typewriter
2754 2754 \series bold
2755 2755 -no|color_info:
2756 2756 \family default
2757 2757 \series default
2758 2758 IPython can display information about objects via a set of functions, and
2759 2759 optionally can use colors for this, syntax highlighting source code and
2760 2760 various other elements.
2761 2761 However, because this information is passed through a pager (like 'less')
2762 2762 and many pagers get confused with color codes, this option is off by default.
2763 2763 You can test it and turn it on permanently in your ipythonrc file if it
2764 2764 works for you.
2765 2765 As a reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
2766 2766 that in RedHat 7.2 doesn't.
2767 2767 \layout List
2768 2768 \labelwidthstring 00.00.0000
2769 2769
2770 2770 \SpecialChar ~
2771 2771 Test it and turn it on permanently if it works with your system.
2772 2772 The magic function
2773 2773 \family typewriter
2774 2774 %color_info
2775 2775 \family default
2776 2776 allows you to toggle this interactively for testing.
2777 2777 \layout List
2778 2778 \labelwidthstring 00.00.0000
2779 2779
2780 2780
2781 2781 \family typewriter
2782 2782 \series bold
2783 2783 -no|debug
2784 2784 \family default
2785 2785 \series default
2786 2786 : Show information about the loading process.
2787 2787 Very useful to pin down problems with your configuration files or to get
2788 2788 details about session restores.
2789 2789 \layout List
2790 2790 \labelwidthstring 00.00.0000
2791 2791
2792 2792
2793 2793 \family typewriter
2794 2794 \series bold
2795 2795 -no|deep_reload
2796 2796 \series default
2797 2797 :
2798 2798 \family default
2799 2799 IPython can use the
2800 2800 \family typewriter
2801 2801 deep_reload
2802 2802 \family default
2803 2803 module which reloads changes in modules recursively (it replaces the
2804 2804 \family typewriter
2805 2805 reload()
2806 2806 \family default
2807 2807 function, so you don't need to change anything to use it).
2808 2808
2809 2809 \family typewriter
2810 2810 deep_reload()
2811 2811 \family default
2812 2812 forces a full reload of modules whose code may have changed, which the
2813 2813 default
2814 2814 \family typewriter
2815 2815 reload()
2816 2816 \family default
2817 2817 function does not.
2818 2818 \layout List
2819 2819 \labelwidthstring 00.00.0000
2820 2820
2821 2821 \SpecialChar ~
2822 2822 When deep_reload is off, IPython will use the normal
2823 2823 \family typewriter
2824 2824 reload()
2825 2825 \family default
2826 2826 , but deep_reload will still be available as
2827 2827 \family typewriter
2828 2828 dreload()
2829 2829 \family default
2830 2830 .
2831 2831 This feature is off by default [which means that you have both normal
2832 2832 \family typewriter
2833 2833 reload()
2834 2834 \family default
2835 2835 and
2836 2836 \family typewriter
2837 2837 dreload()
2838 2838 \family default
2839 2839 ].
2840 2840 \layout List
2841 2841 \labelwidthstring 00.00.0000
2842 2842
2843 2843
2844 2844 \family typewriter
2845 2845 \series bold
2846 2846 -editor\SpecialChar ~
2847 2847 <name>
2848 2848 \family default
2849 2849 \series default
2850 2850 : Which editor to use with the
2851 2851 \family typewriter
2852 2852 %edit
2853 2853 \family default
2854 2854 command.
2855 2855 By default, IPython will honor your
2856 2856 \family typewriter
2857 2857 EDITOR
2858 2858 \family default
2859 2859 environment variable (if not set, vi is the Unix default and notepad the
2860 2860 Windows one).
2861 2861 Since this editor is invoked on the fly by IPython and is meant for editing
2862 2862 small code snippets, you may want to use a small, lightweight editor here
2863 2863 (in case your default
2864 2864 \family typewriter
2865 2865 EDITOR
2866 2866 \family default
2867 2867 is something like Emacs).
2868 2868 \layout List
2869 2869 \labelwidthstring 00.00.0000
2870 2870
2871 2871
2872 2872 \family typewriter
2873 2873 \series bold
2874 2874 -ipythondir\SpecialChar ~
2875 2875 <name>
2876 2876 \series default
2877 2877 :
2878 2878 \family default
2879 2879 name of your IPython configuration directory
2880 2880 \family typewriter
2881 2881 IPYTHONDIR
2882 2882 \family default
2883 2883 .
2884 2884 This can also be specified through the environment variable
2885 2885 \family typewriter
2886 2886 IPYTHONDIR
2887 2887 \family default
2888 2888 .
2889 2889 \layout List
2890 2890 \labelwidthstring 00.00.0000
2891 2891
2892 2892
2893 2893 \family typewriter
2894 2894 \series bold
2895 2895 -log|l
2896 2896 \family default
2897 2897 \series default
2898 2898 : generate a log file of all input.
2899 2899 Defaults to
2900 2900 \family typewriter
2901 2901 $IPYTHONDIR/log
2902 2902 \family default
2903 2903 .
2904 2904 You can use this to later restore a session by loading your logfile as
2905 2905 a file to be executed with option
2906 2906 \family typewriter
2907 2907 -logplay
2908 2908 \family default
2909 2909 (see below).
2910 2910 \layout List
2911 2911 \labelwidthstring 00.00.0000
2912 2912
2913 2913
2914 2914 \family typewriter
2915 2915 \series bold
2916 2916 -logfile|lf\SpecialChar ~
2917 2917 <name>
2918 2918 \series default
2919 2919 :
2920 2920 \family default
2921 2921 specify the name of your logfile.
2922 2922 \layout List
2923 2923 \labelwidthstring 00.00.0000
2924 2924
2925 2925
2926 2926 \family typewriter
2927 2927 \series bold
2928 2928 -logplay|lp\SpecialChar ~
2929 2929 <name>
2930 2930 \series default
2931 2931 :
2932 2932 \family default
2933 2933 you can replay a previous log.
2934 2934 For restoring a session as close as possible to the state you left it in,
2935 2935 use this option (don't just run the logfile).
2936 2936 With
2937 2937 \family typewriter
2938 2938 -logplay
2939 2939 \family default
2940 2940 , IPython will try to reconstruct the previous working environment in full,
2941 2941 not just execute the commands in the logfile.
2942 2942 \layout List
2943 2943 \labelwidthstring 00.00.0000
2944 2944
2945 2945 \SpecialChar ~
2946 2946 When a session is restored, logging is automatically turned on again with
2947 2947 the name of the logfile it was invoked with (it is read from the log header).
2948 2948 So once you've turned logging on for a session, you can quit IPython and
2949 2949 reload it as many times as you want and it will continue to log its history
2950 2950 and restore from the beginning every time.
2951 2951 \layout List
2952 2952 \labelwidthstring 00.00.0000
2953 2953
2954 2954 \SpecialChar ~
2955 2955 Caveats: there are limitations in this option.
2956 2956 The history variables
2957 2957 \family typewriter
2958 2958 _i*
2959 2959 \family default
2960 2960 ,
2961 2961 \family typewriter
2962 2962 _*
2963 2963 \family default
2964 2964 and
2965 2965 \family typewriter
2966 2966 _dh
2967 2967 \family default
2968 2968 don't get restored properly.
2969 2969 In the future we will try to implement full session saving by writing and
2970 2970 retrieving a 'snapshot' of the memory state of IPython.
2971 2971 But our first attempts failed because of inherent limitations of Python's
2972 2972 Pickle module, so this may have to wait.
2973 2973 \layout List
2974 2974 \labelwidthstring 00.00.0000
2975 2975
2976 2976
2977 2977 \family typewriter
2978 2978 \series bold
2979 2979 -no|messages
2980 2980 \series default
2981 2981 :
2982 2982 \family default
2983 2983 Print messages which IPython collects about its startup process (default
2984 2984 on).
2985 2985 \layout List
2986 2986 \labelwidthstring 00.00.0000
2987 2987
2988 2988
2989 2989 \family typewriter
2990 2990 \series bold
2991 2991 -no|pdb
2992 2992 \family default
2993 2993 \series default
2994 2994 : Automatically call the pdb debugger after every uncaught exception.
2995 2995 If you are used to debugging using pdb, this puts you automatically inside
2996 2996 of it after any call (either in IPython or in code called by it) which
2997 2997 triggers an exception which goes uncaught.
2998 2998 \layout List
2999 2999 \labelwidthstring 00.00.0000
3000 3000
3001 3001
3002 3002 \family typewriter
3003 3003 \series bold
3004 3004 -no|pprint
3005 3005 \series default
3006 3006 :
3007 3007 \family default
3008 3008 ipython can optionally use the pprint (pretty printer) module for displaying
3009 3009 results.
3010 3010 pprint tends to give a nicer display of nested data structures.
3011 3011 If you like it, you can turn it on permanently in your config file (default
3012 3012 off).
3013 3013 \layout List
3014 3014 \labelwidthstring 00.00.0000
3015 3015
3016 3016
3017 3017 \family typewriter
3018 3018 \series bold
3019 3019 -profile|p <name>
3020 3020 \series default
3021 3021 :
3022 3022 \family default
3023 3023 assume that your config file is
3024 3024 \family typewriter
3025 3025 ipythonrc-<name>
3026 3026 \family default
3027 3027 (looks in current dir first, then in
3028 3028 \family typewriter
3029 3029 IPYTHONDIR
3030 3030 \family default
3031 3031 ).
3032 3032 This is a quick way to keep and load multiple config files for different
3033 3033 tasks, especially if you use the include option of config files.
3034 3034 You can keep a basic
3035 3035 \family typewriter
3036 3036 IPYTHONDIR/ipythonrc
3037 3037 \family default
3038 3038 file and then have other 'profiles' which include this one and load extra
3039 3039 things for particular tasks.
3040 3040 For example:
3041 3041 \layout List
3042 3042 \labelwidthstring 00.00.0000
3043 3043
3044 3044
3045 3045 \family typewriter
3046 3046 \SpecialChar ~
3047 3047
3048 3048 \family default
3049 3049 1.
3050 3050
3051 3051 \family typewriter
3052 3052 $HOME/.ipython/ipythonrc
3053 3053 \family default
3054 3054 : load basic things you always want.
3055 3055 \layout List
3056 3056 \labelwidthstring 00.00.0000
3057 3057
3058 3058
3059 3059 \family typewriter
3060 3060 \SpecialChar ~
3061 3061
3062 3062 \family default
3063 3063 2.
3064 3064
3065 3065 \family typewriter
3066 3066 $HOME/.ipython/ipythonrc-math
3067 3067 \family default
3068 3068 : load (1) and basic math-related modules.
3069 3069
3070 3070 \layout List
3071 3071 \labelwidthstring 00.00.0000
3072 3072
3073 3073
3074 3074 \family typewriter
3075 3075 \SpecialChar ~
3076 3076
3077 3077 \family default
3078 3078 3.
3079 3079
3080 3080 \family typewriter
3081 3081 $HOME/.ipython/ipythonrc-numeric
3082 3082 \family default
3083 3083 : load (1) and Numeric and plotting modules.
3084 3084 \layout List
3085 3085 \labelwidthstring 00.00.0000
3086 3086
3087 3087 \SpecialChar ~
3088 3088 Since it is possible to create an endless loop by having circular file
3089 3089 inclusions, IPython will stop if it reaches 15 recursive inclusions.
3090 3090 \layout List
3091 3091 \labelwidthstring 00.00.0000
3092 3092
3093 3093
3094 3094 \family typewriter
3095 3095 \series bold
3096 3096 -prompt_in1|pi1\SpecialChar ~
3097 3097 <string>:
3098 3098 \family default
3099 3099 \series default
3100 3100 Specify the string used for input prompts.
3101 3101 Note that if you are using numbered prompts, the number is represented
3102 3102 with a '
3103 3103 \backslash
3104 3104 #' in the string.
3105 3105 Don't forget to quote strings with spaces embedded in them.
3106 3106 Default: '
3107 3107 \family typewriter
3108 3108 In\SpecialChar ~
3109 3109 [
3110 3110 \backslash
3111 3111 #]:
3112 3112 \family default
3113 3113 '.
3114 3114 Sec.\SpecialChar ~
3115 3115
3116 3116 \begin_inset LatexCommand \ref{sec:prompts}
3117 3117
3118 3118 \end_inset
3119 3119
3120 3120 discusses in detail all the available escapes to customize your prompts.
3121 3121 \layout List
3122 3122 \labelwidthstring 00.00.0000
3123 3123
3124 3124
3125 3125 \family typewriter
3126 3126 \series bold
3127 3127 -prompt_in2|pi2\SpecialChar ~
3128 3128 <string>:
3129 3129 \family default
3130 3130 \series default
3131 3131 Similar to the previous option, but used for the continuation prompts.
3132 3132 The special sequence '
3133 3133 \family typewriter
3134 3134
3135 3135 \backslash
3136 3136 D
3137 3137 \family default
3138 3138 ' is similar to '
3139 3139 \family typewriter
3140 3140
3141 3141 \backslash
3142 3142 #
3143 3143 \family default
3144 3144 ', but with all digits replaced dots (so you can have your continuation
3145 3145 prompt aligned with your input prompt).
3146 3146 Default: '
3147 3147 \family typewriter
3148 3148 \SpecialChar ~
3149 3149 \SpecialChar ~
3150 3150 \SpecialChar ~
3151 3151 .
3152 3152 \backslash
3153 3153 D.:
3154 3154 \family default
3155 3155 ' (note three spaces at the start for alignment with '
3156 3156 \family typewriter
3157 3157 In\SpecialChar ~
3158 3158 [
3159 3159 \backslash
3160 3160 #]
3161 3161 \family default
3162 3162 ').
3163 3163 \layout List
3164 3164 \labelwidthstring 00.00.0000
3165 3165
3166 3166
3167 3167 \family typewriter
3168 3168 \series bold
3169 3169 -prompt_out|po\SpecialChar ~
3170 3170 <string>:
3171 3171 \family default
3172 3172 \series default
3173 3173 String used for output prompts, also uses numbers like
3174 3174 \family typewriter
3175 3175 prompt_in1
3176 3176 \family default
3177 3177 .
3178 3178 Default: '
3179 3179 \family typewriter
3180 3180 Out[
3181 3181 \backslash
3182 3182 #]:
3183 3183 \family default
3184 3184 '
3185 3185 \layout List
3186 3186 \labelwidthstring 00.00.0000
3187 3187
3188 3188
3189 3189 \family typewriter
3190 3190 \series bold
3191 3191 -quick
3192 3192 \family default
3193 3193 \series default
3194 3194 : start in bare bones mode (no config file loaded).
3195 3195 \layout List
3196 3196 \labelwidthstring 00.00.0000
3197 3197
3198 3198
3199 3199 \family typewriter
3200 3200 \series bold
3201 3201 -rcfile\SpecialChar ~
3202 3202 <name>
3203 3203 \series default
3204 3204 :
3205 3205 \family default
3206 3206 name of your IPython resource configuration file.
3207 3207 Normally IPython loads ipythonrc (from current directory) or
3208 3208 \family typewriter
3209 3209 IPYTHONDIR/ipythonrc
3210 3210 \family default
3211 3211 .
3212 3212 \layout List
3213 3213 \labelwidthstring 00.00.0000
3214 3214
3215 3215 \SpecialChar ~
3216 3216 If the loading of your config file fails, IPython starts with a bare bones
3217 3217 configuration (no modules loaded at all).
3218 3218 \layout List
3219 3219 \labelwidthstring 00.00.0000
3220 3220
3221 3221
3222 3222 \family typewriter
3223 3223 \series bold
3224 3224 -no|readline
3225 3225 \family default
3226 3226 \series default
3227 3227 : use the readline library, which is needed to support name completion and
3228 3228 command history, among other things.
3229 3229 It is enabled by default, but may cause problems for users of X/Emacs in
3230 3230 Python comint or shell buffers.
3231 3231 \layout List
3232 3232 \labelwidthstring 00.00.0000
3233 3233
3234 3234 \SpecialChar ~
3235 3235 Note that X/Emacs 'eterm' buffers (opened with
3236 3236 \family typewriter
3237 3237 M-x\SpecialChar ~
3238 3238 term
3239 3239 \family default
3240 3240 ) support IPython's readline and syntax coloring fine, only 'emacs' (
3241 3241 \family typewriter
3242 3242 M-x\SpecialChar ~
3243 3243 shell
3244 3244 \family default
3245 3245 and
3246 3246 \family typewriter
3247 3247 C-c\SpecialChar ~
3248 3248 !
3249 3249 \family default
3250 3250 ) buffers do not.
3251 3251 \layout List
3252 3252 \labelwidthstring 00.00.0000
3253 3253
3254 3254
3255 3255 \family typewriter
3256 3256 \series bold
3257 3257 -screen_length|sl\SpecialChar ~
3258 3258 <n>
3259 3259 \series default
3260 3260 :
3261 3261 \family default
3262 3262 number of lines of your screen.
3263 3263 This is used to control printing of very long strings.
3264 3264 Strings longer than this number of lines will be sent through a pager instead
3265 3265 of directly printed.
3266 3266 \layout List
3267 3267 \labelwidthstring 00.00.0000
3268 3268
3269 3269 \SpecialChar ~
3270 3270 The default value for this is 0, which means IPython will auto-detect your
3271 3271 screen size every time it needs to print certain potentially long strings
3272 3272 (this doesn't change the behavior of the 'print' keyword, it's only triggered
3273 3273 internally).
3274 3274 If for some reason this isn't working well (it needs curses support), specify
3275 3275 it yourself.
3276 3276 Otherwise don't change the default.
3277 3277 \layout List
3278 3278 \labelwidthstring 00.00.0000
3279 3279
3280 3280
3281 3281 \family typewriter
3282 3282 \series bold
3283 3283 -separate_in|si\SpecialChar ~
3284 3284 <string>
3285 3285 \series default
3286 3286 :
3287 3287 \family default
3288 3288 separator before input prompts.
3289 3289 Default: '
3290 3290 \family typewriter
3291 3291
3292 3292 \backslash
3293 3293 n
3294 3294 \family default
3295 3295 '
3296 3296 \layout List
3297 3297 \labelwidthstring 00.00.0000
3298 3298
3299 3299
3300 3300 \family typewriter
3301 3301 \series bold
3302 3302 -separate_out|so\SpecialChar ~
3303 3303 <string>
3304 3304 \family default
3305 3305 \series default
3306 3306 : separator before output prompts.
3307 3307 Default: nothing.
3308 3308 \layout List
3309 3309 \labelwidthstring 00.00.0000
3310 3310
3311 3311
3312 3312 \family typewriter
3313 3313 \series bold
3314 3314 -separate_out2|so2\SpecialChar ~
3315 3315 <string>
3316 3316 \series default
3317 3317 :
3318 3318 \family default
3319 3319 separator after output prompts.
3320 3320 Default: nothing.
3321 3321 \layout List
3322 3322 \labelwidthstring 00.00.0000
3323 3323
3324 3324 \SpecialChar ~
3325 3325 For these three options, use the value 0 to specify no separator.
3326 3326 \layout List
3327 3327 \labelwidthstring 00.00.0000
3328 3328
3329 3329
3330 3330 \family typewriter
3331 3331 \series bold
3332 3332 -nosep
3333 3333 \series default
3334 3334 :
3335 3335 \family default
3336 3336 shorthand for
3337 3337 \family typewriter
3338 3338 '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'
3339 3339 \family default
3340 3340 .
3341 3341 Simply removes all input/output separators.
3342 3342 \layout List
3343 3343 \labelwidthstring 00.00.0000
3344 3344
3345 3345
3346 3346 \family typewriter
3347 3347 \series bold
3348 3348 -upgrade
3349 3349 \family default
3350 3350 \series default
3351 3351 : allows you to upgrade your
3352 3352 \family typewriter
3353 3353 IPYTHONDIR
3354 3354 \family default
3355 3355 configuration when you install a new version of IPython.
3356 3356 Since new versions may include new command line options or example files,
3357 3357 this copies updated ipythonrc-type files.
3358 3358 However, it backs up (with a
3359 3359 \family typewriter
3360 3360 .old
3361 3361 \family default
3362 3362 extension) all files which it overwrites so that you can merge back any
3363 3363 customizations you might have in your personal files.
3364 3364 \layout List
3365 3365 \labelwidthstring 00.00.0000
3366 3366
3367 3367
3368 3368 \family typewriter
3369 3369 \series bold
3370 3370 -Version
3371 3371 \series default
3372 3372 :
3373 3373 \family default
3374 3374 print version information and exit.
3375 3375 \layout List
3376 3376 \labelwidthstring 00.00.0000
3377 3377
3378 3378
3379 3379 \family typewriter
3380 3380 \series bold
3381 3381 -xmode <modename>
3382 3382 \series default
3383 3383 :
3384 3384 \family default
3385 3385 Mode for exception reporting.
3386 3386 \layout List
3387 3387 \labelwidthstring 00.00.0000
3388 3388
3389 3389 \SpecialChar ~
3390 3390 Valid modes: Plain, Context and Verbose.
3391 3391 \layout List
3392 3392 \labelwidthstring 00.00.0000
3393 3393
3394 3394 \SpecialChar ~
3395 3395 Plain: similar to python's normal traceback printing.
3396 3396 \layout List
3397 3397 \labelwidthstring 00.00.0000
3398 3398
3399 3399 \SpecialChar ~
3400 3400 Context: prints 5 lines of context source code around each line in the
3401 3401 traceback.
3402 3402 \layout List
3403 3403 \labelwidthstring 00.00.0000
3404 3404
3405 3405 \SpecialChar ~
3406 3406 Verbose: similar to Context, but additionally prints the variables currently
3407 3407 visible where the exception happened (shortening their strings if too long).
3408 3408 This can potentially be very slow, if you happen to have a huge data structure
3409 3409 whose string representation is complex to compute.
3410 3410 Your computer may appear to freeze for a while with cpu usage at 100%.
3411 3411 If this occurs, you can cancel the traceback with Ctrl-C (maybe hitting
3412 3412 it more than once).
3413 3413 \layout Section
3414 3414
3415 3415 Interactive use
3416 3416 \layout Standard
3417 3417
3418 3418
3419 3419 \series bold
3420 3420 Warning
3421 3421 \series default
3422 3422 : IPython relies on the existence of a global variable called
3423 3423 \family typewriter
3424 3424 __IP
3425 3425 \family default
3426 3426 which controls the shell itself.
3427 3427 If you redefine
3428 3428 \family typewriter
3429 3429 __IP
3430 3430 \family default
3431 3431 to anything, bizarre behavior will quickly occur.
3432 3432 \layout Standard
3433 3433
3434 3434 Other than the above warning, IPython is meant to work as a drop-in replacement
3435 3435 for the standard interactive interpreter.
3436 3436 As such, any code which is valid python should execute normally under IPython
3437 3437 (cases where this is not true should be reported as bugs).
3438 3438 It does, however, offer many features which are not available at a standard
3439 3439 python prompt.
3440 3440 What follows is a list of these.
3441 3441 \layout Subsection
3442 3442
3443 3443 Caution for Windows users
3444 3444 \layout Standard
3445 3445
3446 3446 Windows, unfortunately, uses the `
3447 3447 \family typewriter
3448 3448
3449 3449 \backslash
3450 3450
3451 3451 \family default
3452 3452 ' character as a path separator.
3453 3453 This is a terrible choice, because `
3454 3454 \family typewriter
3455 3455
3456 3456 \backslash
3457 3457
3458 3458 \family default
3459 3459 ' also represents the escape character in most modern programming languages,
3460 3460 including Python.
3461 3461 For this reason, issuing many of the commands discussed below (especially
3462 3462 magics which affect the filesystem) with `
3463 3463 \family typewriter
3464 3464
3465 3465 \backslash
3466 3466
3467 3467 \family default
3468 3468 ' in them will cause strange errors.
3469 3469 \layout Standard
3470 3470
3471 3471 A partial solution is to use instead the `
3472 3472 \family typewriter
3473 3473 /
3474 3474 \family default
3475 3475 ' character as a path separator, which Windows recognizes in
3476 3476 \emph on
3477 3477 most
3478 3478 \emph default
3479 3479 situations.
3480 3480 However, in Windows commands `
3481 3481 \family typewriter
3482 3482 /
3483 3483 \family default
3484 3484 ' flags options, so you can not use it for the root directory.
3485 3485 This means that paths beginning at the root must be typed in a contrived
3486 3486 manner like:
3487 3487 \newline
3488 3488
3489 3489 \family typewriter
3490 3490 %copy
3491 3491 \backslash
3492 3492 opt/foo/bar.txt
3493 3493 \backslash
3494 3494 tmp
3495 3495 \layout Standard
3496 3496
3497 3497 There is no sensible thing IPython can do to truly work around this flaw
3498 3498 in Windows
3499 3499 \begin_inset Foot
3500 3500 collapsed true
3501 3501
3502 3502 \layout Standard
3503 3503
3504 3504 If anyone comes up with a
3505 3505 \emph on
3506 3506 clean
3507 3507 \emph default
3508 3508 solution which works consistently and does not negatively impact other
3509 3509 platforms at all, I'll gladly accept a patch.
3510 3510 \end_inset
3511 3511
3512 3512 .
3513 3513 \layout Subsection
3514 3514
3515 3515
3516 3516 \begin_inset LatexCommand \label{sec:magic}
3517 3517
3518 3518 \end_inset
3519 3519
3520 3520 Magic command system
3521 3521 \layout Standard
3522 3522
3523 3523 IPython will treat any line whose first character is a
3524 3524 \family typewriter
3525 3525 %
3526 3526 \family default
3527 3527 as a special call to a 'magic' function.
3528 3528 These allow you to control the behavior of IPython itself, plus a lot of
3529 3529 system-type features.
3530 3530 They are all prefixed with a
3531 3531 \family typewriter
3532 3532 %
3533 3533 \family default
3534 3534 character, but parameters are given without parentheses or quotes.
3535 3535 \layout Standard
3536 3536
3537 3537 Example: typing
3538 3538 \family typewriter
3539 3539 '%cd mydir'
3540 3540 \family default
3541 3541 (without the quotes) changes you working directory to
3542 3542 \family typewriter
3543 3543 'mydir'
3544 3544 \family default
3545 3545 , if it exists.
3546 3546 \layout Standard
3547 3547
3548 3548 If you have 'automagic' enabled (in your
3549 3549 \family typewriter
3550 3550 ipythonrc
3551 3551 \family default
3552 3552 file, via the command line option
3553 3553 \family typewriter
3554 3554 -automagic
3555 3555 \family default
3556 3556 or with the
3557 3557 \family typewriter
3558 3558 %automagic
3559 3559 \family default
3560 3560 function), you don't need to type in the
3561 3561 \family typewriter
3562 3562 %
3563 3563 \family default
3564 3564 explicitly.
3565 3565 IPython will scan its internal list of magic functions and call one if
3566 3566 it exists.
3567 3567 With automagic on you can then just type '
3568 3568 \family typewriter
3569 3569 cd mydir
3570 3570 \family default
3571 3571 ' to go to directory '
3572 3572 \family typewriter
3573 3573 mydir
3574 3574 \family default
3575 3575 '.
3576 3576 The automagic system has the lowest possible precedence in name searches,
3577 3577 so defining an identifier with the same name as an existing magic function
3578 3578 will shadow it for automagic use.
3579 3579 You can still access the shadowed magic function by explicitly using the
3580 3580
3581 3581 \family typewriter
3582 3582 %
3583 3583 \family default
3584 3584 character at the beginning of the line.
3585 3585 \layout Standard
3586 3586
3587 3587 An example (with automagic on) should clarify all this:
3588 3588 \layout LyX-Code
3589 3589
3590 3590 In [1]: cd ipython # %cd is called by automagic
3591 3591 \layout LyX-Code
3592 3592
3593 3593 /home/fperez/ipython
3594 3594 \layout LyX-Code
3595 3595
3596 3596 In [2]: cd=1 # now cd is just a variable
3597 3597 \layout LyX-Code
3598 3598
3599 3599 In [3]: cd ..
3600 3600 # and doesn't work as a function anymore
3601 3601 \layout LyX-Code
3602 3602
3603 3603 ------------------------------------------------------------
3604 3604 \layout LyX-Code
3605 3605
3606 3606 File "<console>", line 1
3607 3607 \layout LyX-Code
3608 3608
3609 3609 cd ..
3610 3610 \layout LyX-Code
3611 3611
3612 3612 ^
3613 3613 \layout LyX-Code
3614 3614
3615 3615 SyntaxError: invalid syntax
3616 3616 \layout LyX-Code
3617 3617
3618 3618 \layout LyX-Code
3619 3619
3620 3620 In [4]: %cd ..
3621 3621 # but %cd always works
3622 3622 \layout LyX-Code
3623 3623
3624 3624 /home/fperez
3625 3625 \layout LyX-Code
3626 3626
3627 3627 In [5]: del cd # if you remove the cd variable
3628 3628 \layout LyX-Code
3629 3629
3630 3630 In [6]: cd ipython # automagic can work again
3631 3631 \layout LyX-Code
3632 3632
3633 3633 /home/fperez/ipython
3634 3634 \layout Standard
3635 3635
3636 3636 You can define your own magic functions to extend the system.
3637 3637 The following is a snippet of code which shows how to do it.
3638 3638 It is provided as file
3639 3639 \family typewriter
3640 3640 example-magic.py
3641 3641 \family default
3642 3642 in the examples directory:
3643 3643 \layout Standard
3644 3644
3645 3645
3646 3646 \begin_inset ERT
3647 3647 status Open
3648 3648
3649 3649 \layout Standard
3650 3650
3651 3651 \backslash
3652 3652 codelist{examples/example-magic.py}
3653 3653 \end_inset
3654 3654
3655 3655
3656 3656 \layout Standard
3657 3657
3658 3658 You can also define your own aliased names for magic functions.
3659 3659 In your
3660 3660 \family typewriter
3661 3661 ipythonrc
3662 3662 \family default
3663 3663 file, placing a line like:
3664 3664 \layout Standard
3665 3665
3666 3666
3667 3667 \family typewriter
3668 3668 execute __IP.magic_cl = __IP.magic_clear
3669 3669 \layout Standard
3670 3670
3671 3671 will define
3672 3672 \family typewriter
3673 3673 %cl
3674 3674 \family default
3675 3675 as a new name for
3676 3676 \family typewriter
3677 3677 %clear
3678 3678 \family default
3679 3679 .
3680 3680 \layout Standard
3681 3681
3682 3682 Type
3683 3683 \family typewriter
3684 3684 %magic
3685 3685 \family default
3686 3686 for more information, including a list of all available magic functions
3687 3687 at any time and their docstrings.
3688 3688 You can also type
3689 3689 \family typewriter
3690 3690 %magic_function_name?
3691 3691 \family default
3692 3692 (see sec.
3693 3693
3694 3694 \begin_inset LatexCommand \ref{sec:dyn-object-info}
3695 3695
3696 3696 \end_inset
3697 3697
3698 3698 for information on the
3699 3699 \family typewriter
3700 3700 '?'
3701 3701 \family default
3702 3702 system) to get information about any particular magic function you are
3703 3703 interested in.
3704 3704 \layout Subsubsection
3705 3705
3706 3706 Magic commands
3707 3707 \layout Standard
3708 3708
3709 3709 The rest of this section is automatically generated for each release from
3710 3710 the docstrings in the IPython code.
3711 3711 Therefore the formatting is somewhat minimal, but this method has the advantage
3712 3712 of having information always in sync with the code.
3713 3713 \layout Standard
3714 3714
3715 3715 A list of all the magic commands available in IPython's
3716 3716 \emph on
3717 3717 default
3718 3718 \emph default
3719 3719 installation follows.
3720 3720 This is similar to what you'll see by simply typing
3721 3721 \family typewriter
3722 3722 %magic
3723 3723 \family default
3724 3724 at the prompt, but that will also give you information about magic commands
3725 3725 you may have added as part of your personal customizations.
3726 3726 \layout Standard
3727 3727
3728 3728
3729 3729 \begin_inset Include \input{magic.tex}
3730 3730 preview false
3731 3731
3732 3732 \end_inset
3733 3733
3734 3734
3735 3735 \layout Subsection
3736 3736
3737 3737 Access to the standard Python help
3738 3738 \layout Standard
3739 3739
3740 3740 As of Python 2.1, a help system is available with access to object docstrings
3741 3741 and the Python manuals.
3742 3742 Simply type
3743 3743 \family typewriter
3744 3744 'help'
3745 3745 \family default
3746 3746 (no quotes) to access it.
3747 3747 You can also type
3748 3748 \family typewriter
3749 3749 help(object)
3750 3750 \family default
3751 3751 to obtain information about a given object, and
3752 3752 \family typewriter
3753 3753 help('keyword')
3754 3754 \family default
3755 3755 for information on a keyword.
3756 3756 As noted in sec.
3757 3757
3758 3758 \begin_inset LatexCommand \ref{sec:help-access}
3759 3759
3760 3760 \end_inset
3761 3761
3762 3762 , you need to properly configure your environment variable
3763 3763 \family typewriter
3764 3764 PYTHONDOCS
3765 3765 \family default
3766 3766 for this feature to work correctly.
3767 3767 \layout Subsection
3768 3768
3769 3769
3770 3770 \begin_inset LatexCommand \label{sec:dyn-object-info}
3771 3771
3772 3772 \end_inset
3773 3773
3774 3774 Dynamic object information
3775 3775 \layout Standard
3776 3776
3777 3777 Typing
3778 3778 \family typewriter
3779 3779 ?word
3780 3780 \family default
3781 3781 or
3782 3782 \family typewriter
3783 3783 word?
3784 3784 \family default
3785 3785 prints detailed information about an object.
3786 3786 If certain strings in the object are too long (docstrings, code, etc.) they
3787 3787 get snipped in the center for brevity.
3788 3788 This system gives access variable types and values, full source code for
3789 3789 any object (if available), function prototypes and other useful information.
3790 3790 \layout Standard
3791 3791
3792 3792 Typing
3793 3793 \family typewriter
3794 3794 ??word
3795 3795 \family default
3796 3796 or
3797 3797 \family typewriter
3798 3798 word??
3799 3799 \family default
3800 3800 gives access to the full information without snipping long strings.
3801 3801 Long strings are sent to the screen through the
3802 3802 \family typewriter
3803 3803 less
3804 3804 \family default
3805 3805 pager if longer than the screen and printed otherwise.
3806 3806 On systems lacking the
3807 3807 \family typewriter
3808 3808 less
3809 3809 \family default
3810 3810 command, IPython uses a very basic internal pager.
3811 3811 \layout Standard
3812 3812
3813 3813 The following magic functions are particularly useful for gathering information
3814 3814 about your working environment.
3815 3815 You can get more details by typing
3816 3816 \family typewriter
3817 3817 %magic
3818 3818 \family default
3819 3819 or querying them individually (use
3820 3820 \family typewriter
3821 3821 %function_name?
3822 3822 \family default
3823 3823 with or without the
3824 3824 \family typewriter
3825 3825 %
3826 3826 \family default
3827 3827 ), this is just a summary:
3828 3828 \layout List
3829 3829 \labelwidthstring 00.00.0000
3830 3830
3831 3831
3832 3832 \family typewriter
3833 3833 \series bold
3834 3834 %pdoc\SpecialChar ~
3835 3835 <object>
3836 3836 \family default
3837 3837 \series default
3838 3838 : Print (or run through a pager if too long) the docstring for an object.
3839 3839 If the given object is a class, it will print both the class and the constructo
3840 3840 r docstrings.
3841 3841 \layout List
3842 3842 \labelwidthstring 00.00.0000
3843 3843
3844 3844
3845 3845 \family typewriter
3846 3846 \series bold
3847 3847 %pdef\SpecialChar ~
3848 3848 <object>
3849 3849 \family default
3850 3850 \series default
3851 3851 : Print the definition header for any callable object.
3852 3852 If the object is a class, print the constructor information.
3853 3853 \layout List
3854 3854 \labelwidthstring 00.00.0000
3855 3855
3856 3856
3857 3857 \family typewriter
3858 3858 \series bold
3859 3859 %psource\SpecialChar ~
3860 3860 <object>
3861 3861 \family default
3862 3862 \series default
3863 3863 : Print (or run through a pager if too long) the source code for an object.
3864 3864 \layout List
3865 3865 \labelwidthstring 00.00.0000
3866 3866
3867 3867
3868 3868 \family typewriter
3869 3869 \series bold
3870 3870 %pfile\SpecialChar ~
3871 3871 <object>
3872 3872 \family default
3873 3873 \series default
3874 3874 : Show the entire source file where an object was defined via a pager, opening
3875 3875 it at the line where the object definition begins.
3876 3876 \layout List
3877 3877 \labelwidthstring 00.00.0000
3878 3878
3879 3879
3880 3880 \family typewriter
3881 3881 \series bold
3882 3882 %who/%whos
3883 3883 \family default
3884 3884 \series default
3885 3885 : These functions give information about identifiers you have defined interactiv
3886 3886 ely (not things you loaded or defined in your configuration files).
3887 3887
3888 3888 \family typewriter
3889 3889 %who
3890 3890 \family default
3891 3891 just prints a list of identifiers and
3892 3892 \family typewriter
3893 3893 %whos
3894 3894 \family default
3895 3895 prints a table with some basic details about each identifier.
3896 3896 \layout Standard
3897 3897
3898 3898 Note that the dynamic object information functions (
3899 3899 \family typewriter
3900 3900 ?/??, %pdoc, %pfile, %pdef, %psource
3901 3901 \family default
3902 3902 ) give you access to documentation even on things which are not really defined
3903 3903 as separate identifiers.
3904 3904 Try for example typing
3905 3905 \family typewriter
3906 3906 {}.get?
3907 3907 \family default
3908 3908 or after doing
3909 3909 \family typewriter
3910 3910 import os
3911 3911 \family default
3912 3912 , type
3913 3913 \family typewriter
3914 3914 os.path.abspath??
3915 3915 \family default
3916 3916 .
3917 3917 \layout Subsection
3918 3918
3919 3919
3920 3920 \begin_inset LatexCommand \label{sec:readline}
3921 3921
3922 3922 \end_inset
3923 3923
3924 3924 Readline-based features
3925 3925 \layout Standard
3926 3926
3927 3927 These features require the GNU readline library, so they won't work if your
3928 3928 Python installation lacks readline support.
3929 3929 We will first describe the default behavior IPython uses, and then how
3930 3930 to change it to suit your preferences.
3931 3931 \layout Subsubsection
3932 3932
3933 3933 Command line completion
3934 3934 \layout Standard
3935 3935
3936 3936 At any time, hitting TAB will complete any available python commands or
3937 3937 variable names, and show you a list of the possible completions if there's
3938 3938 no unambiguous one.
3939 3939 It will also complete filenames in the current directory if no python names
3940 3940 match what you've typed so far.
3941 3941 \layout Subsubsection
3942 3942
3943 3943 Search command history
3944 3944 \layout Standard
3945 3945
3946 3946 IPython provides two ways for searching through previous input and thus
3947 3947 reduce the need for repetitive typing:
3948 3948 \layout Enumerate
3949 3949
3950 3950 Start typing, and then use
3951 3951 \family typewriter
3952 3952 Ctrl-p
3953 3953 \family default
3954 3954 (previous,up) and
3955 3955 \family typewriter
3956 3956 Ctrl-n
3957 3957 \family default
3958 3958 (next,down) to search through only the history items that match what you've
3959 3959 typed so far.
3960 3960 If you use
3961 3961 \family typewriter
3962 3962 Ctrl-p/Ctrl-n
3963 3963 \family default
3964 3964 at a blank prompt, they just behave like normal arrow keys.
3965 3965 \layout Enumerate
3966 3966
3967 3967 Hit
3968 3968 \family typewriter
3969 3969 Ctrl-r
3970 3970 \family default
3971 3971 : opens a search prompt.
3972 3972 Begin typing and the system searches your history for lines that contain
3973 3973 what you've typed so far, completing as much as it can.
3974 3974 \layout Subsubsection
3975 3975
3976 3976 Persistent command history across sessions
3977 3977 \layout Standard
3978 3978
3979 3979 IPython will save your input history when it leaves and reload it next time
3980 3980 you restart it.
3981 3981 By default, the history file is named
3982 3982 \family typewriter
3983 3983 $IPYTHONDIR/history
3984 3984 \family default
3985 3985 , but if you've loaded a named profile, '
3986 3986 \family typewriter
3987 3987 -PROFILE_NAME
3988 3988 \family default
3989 3989 ' is appended to the name.
3990 3990 This allows you to keep separate histories related to various tasks: commands
3991 3991 related to numerical work will not be clobbered by a system shell history,
3992 3992 for example.
3993 3993 \layout Subsubsection
3994 3994
3995 3995 Autoindent
3996 3996 \layout Standard
3997 3997
3998 3998 IPython can recognize lines ending in ':' and indent the next line, while
3999 3999 also un-indenting automatically after 'raise' or 'return'.
4000 4000
4001 4001 \layout Standard
4002 4002
4003 4003 This feature uses the readline library, so it will honor your
4004 4004 \family typewriter
4005 4005 ~/.inputrc
4006 4006 \family default
4007 4007 configuration (or whatever file your
4008 4008 \family typewriter
4009 4009 INPUTRC
4010 4010 \family default
4011 4011 variable points to).
4012 4012 Adding the following lines to your
4013 4013 \family typewriter
4014 4014 .inputrc
4015 4015 \family default
4016 4016 file can make indenting/unindenting more convenient (
4017 4017 \family typewriter
4018 4018 M-i
4019 4019 \family default
4020 4020 indents,
4021 4021 \family typewriter
4022 4022 M-u
4023 4023 \family default
4024 4024 unindents):
4025 4025 \layout Standard
4026 4026
4027 4027
4028 4028 \family typewriter
4029 4029 $if Python
4030 4030 \newline
4031 4031 "
4032 4032 \backslash
4033 4033 M-i": "\SpecialChar ~
4034 4034 \SpecialChar ~
4035 4035 \SpecialChar ~
4036 4036 \SpecialChar ~
4037 4037 "
4038 4038 \newline
4039 4039 "
4040 4040 \backslash
4041 4041 M-u": "
4042 4042 \backslash
4043 4043 d
4044 4044 \backslash
4045 4045 d
4046 4046 \backslash
4047 4047 d
4048 4048 \backslash
4049 4049 d"
4050 4050 \newline
4051 4051 $endif
4052 4052 \layout Standard
4053 4053
4054 4054 Note that there are 4 spaces between the quote marks after
4055 4055 \family typewriter
4056 4056 "M-i"
4057 4057 \family default
4058 4058 above.
4059 4059 \layout Standard
4060 4060
4061 4061
4062 4062 \series bold
4063 4063 Warning:
4064 4064 \series default
4065 4065 this feature is ON by default, but it can cause problems with the pasting
4066 4066 of multi-line indented code (the pasted code gets re-indented on each line).
4067 4067 A magic function
4068 4068 \family typewriter
4069 4069 %autoindent
4070 4070 \family default
4071 4071 allows you to toggle it on/off at runtime.
4072 4072 You can also disable it permanently on in your
4073 4073 \family typewriter
4074 4074 ipythonrc
4075 4075 \family default
4076 4076 file (set
4077 4077 \family typewriter
4078 4078 autoindent 0
4079 4079 \family default
4080 4080 ).
4081 4081 \layout Subsubsection
4082 4082
4083 4083 Customizing readline behavior
4084 4084 \layout Standard
4085 4085
4086 4086 All these features are based on the GNU readline library, which has an extremely
4087 4087 customizable interface.
4088 4088 Normally, readline is configured via a file which defines the behavior
4089 4089 of the library; the details of the syntax for this can be found in the
4090 4090 readline documentation available with your system or on the Internet.
4091 4091 IPython doesn't read this file (if it exists) directly, but it does support
4092 4092 passing to readline valid options via a simple interface.
4093 4093 In brief, you can customize readline by setting the following options in
4094 4094 your
4095 4095 \family typewriter
4096 4096 ipythonrc
4097 4097 \family default
4098 4098 configuration file (note that these options can
4099 4099 \emph on
4100 4100 not
4101 4101 \emph default
4102 4102 be specified at the command line):
4103 4103 \layout List
4104 4104 \labelwidthstring 00.00.0000
4105 4105
4106 4106
4107 4107 \family typewriter
4108 4108 \series bold
4109 4109 readline_parse_and_bind:
4110 4110 \family default
4111 4111 \series default
4112 4112 this option can appear as many times as you want, each time defining a
4113 4113 string to be executed via a
4114 4114 \family typewriter
4115 4115 readline.parse_and_bind()
4116 4116 \family default
4117 4117 command.
4118 4118 The syntax for valid commands of this kind can be found by reading the
4119 4119 documentation for the GNU readline library, as these commands are of the
4120 4120 kind which readline accepts in its configuration file.
4121 4121 \layout List
4122 4122 \labelwidthstring 00.00.0000
4123 4123
4124 4124
4125 4125 \family typewriter
4126 4126 \series bold
4127 4127 readline_remove_delims:
4128 4128 \family default
4129 4129 \series default
4130 4130 a string of characters to be removed from the default word-delimiters list
4131 4131 used by readline, so that completions may be performed on strings which
4132 4132 contain them.
4133 4133 Do not change the default value unless you know what you're doing.
4134 4134 \layout List
4135 4135 \labelwidthstring 00.00.0000
4136 4136
4137 4137
4138 4138 \family typewriter
4139 4139 \series bold
4140 4140 readline_omit__names
4141 4141 \family default
4142 4142 \series default
4143 4143 : when tab-completion is enabled, hitting
4144 4144 \family typewriter
4145 4145 <tab>
4146 4146 \family default
4147 4147 after a '
4148 4148 \family typewriter
4149 4149 .
4150 4150 \family default
4151 4151 ' in a name will complete all attributes of an object, including all the
4152 4152 special methods whose names include double underscores (like
4153 4153 \family typewriter
4154 4154 __getitem__
4155 4155 \family default
4156 4156 or
4157 4157 \family typewriter
4158 4158 __class__
4159 4159 \family default
4160 4160 ).
4161 4161 If you'd rather not see these names by default, you can set this option
4162 4162 to 1.
4163 4163 Note that even when this option is set, you can still see those names by
4164 4164 explicitly typing a
4165 4165 \family typewriter
4166 4166 _
4167 4167 \family default
4168 4168 after the period and hitting
4169 4169 \family typewriter
4170 4170 <tab>
4171 4171 \family default
4172 4172 : '
4173 4173 \family typewriter
4174 4174 name._<tab>
4175 4175 \family default
4176 4176 ' will always complete attribute names starting with '
4177 4177 \family typewriter
4178 4178 _
4179 4179 \family default
4180 4180 '.
4181 4181 \layout List
4182 4182 \labelwidthstring 00.00.0000
4183 4183
4184 4184 \SpecialChar ~
4185 4185 This option is off by default so that new users see all attributes of any
4186 4186 objects they are dealing with.
4187 4187 \layout Standard
4188 4188
4189 4189 You will find the default values along with a corresponding detailed explanation
4190 4190 in your
4191 4191 \family typewriter
4192 4192 ipythonrc
4193 4193 \family default
4194 4194 file.
4195 4195 \layout Subsection
4196 4196
4197 4197 Session logging and restoring
4198 4198 \layout Standard
4199 4199
4200 4200 You can log all input from a session either by starting IPython with the
4201 4201 command line switches
4202 4202 \family typewriter
4203 4203 -log
4204 4204 \family default
4205 4205 or
4206 4206 \family typewriter
4207 4207 -logfile
4208 4208 \family default
4209 4209 (see sec.
4210 4210
4211 4211 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
4212 4212
4213 4213 \end_inset
4214 4214
4215 4215 )or by activating the logging at any moment with the magic function
4216 4216 \family typewriter
4217 4217 %logstart
4218 4218 \family default
4219 4219 .
4220 4220
4221 4221 \layout Standard
4222 4222
4223 4223 Log files can later be reloaded with the
4224 4224 \family typewriter
4225 4225 -logplay
4226 4226 \family default
4227 4227 option and IPython will attempt to 'replay' the log by executing all the
4228 4228 lines in it, thus restoring the state of a previous session.
4229 4229 This feature is not quite perfect, but can still be useful in many cases.
4230 4230 \layout Standard
4231 4231
4232 4232 The log files can also be used as a way to have a permanent record of any
4233 4233 code you wrote while experimenting.
4234 4234 Log files are regular text files which you can later open in your favorite
4235 4235 text editor to extract code or to 'clean them up' before using them to
4236 4236 replay a session.
4237 4237 \layout Standard
4238 4238
4239 4239 The
4240 4240 \family typewriter
4241 4241 %logstart
4242 4242 \family default
4243 4243 function for activating logging in mid-session is used as follows:
4244 4244 \layout Standard
4245 4245
4246 4246
4247 4247 \family typewriter
4248 4248 %logstart [log_name [log_mode]]
4249 4249 \layout Standard
4250 4250
4251 4251 If no name is given, it defaults to a file named
4252 4252 \family typewriter
4253 4253 'log'
4254 4254 \family default
4255 4255 in your IPYTHONDIR directory, in
4256 4256 \family typewriter
4257 4257 'rotate'
4258 4258 \family default
4259 4259 mode (see below).
4260 4260 \layout Standard
4261 4261
4262 4262 '
4263 4263 \family typewriter
4264 4264 %logstart name
4265 4265 \family default
4266 4266 ' saves to file
4267 4267 \family typewriter
4268 4268 'name'
4269 4269 \family default
4270 4270 in
4271 4271 \family typewriter
4272 4272 'backup'
4273 4273 \family default
4274 4274 mode.
4275 4275 It saves your history up to that point and then continues logging.
4276 4276 \layout Standard
4277 4277
4278 4278
4279 4279 \family typewriter
4280 4280 %logstart
4281 4281 \family default
4282 4282 takes a second optional parameter: logging mode.
4283 4283 This can be one of (note that the modes are given unquoted):
4284 4284 \layout List
4285 4285 \labelwidthstring 00.00.0000
4286 4286
4287 4287
4288 4288 \family typewriter
4289 4289 over
4290 4290 \family default
4291 4291 : overwrite existing
4292 4292 \family typewriter
4293 4293 log_name
4294 4294 \family default
4295 4295 .
4296 4296 \layout List
4297 4297 \labelwidthstring 00.00.0000
4298 4298
4299 4299
4300 4300 \family typewriter
4301 4301 backup
4302 4302 \family default
4303 4303 : rename (if exists) to
4304 4304 \family typewriter
4305 4305 log_name~
4306 4306 \family default
4307 4307 and start
4308 4308 \family typewriter
4309 4309 log_name
4310 4310 \family default
4311 4311 .
4312 4312 \layout List
4313 4313 \labelwidthstring 00.00.0000
4314 4314
4315 4315
4316 4316 \family typewriter
4317 4317 append
4318 4318 \family default
4319 4319 : well, that says it.
4320 4320 \layout List
4321 4321 \labelwidthstring 00.00.0000
4322 4322
4323 4323
4324 4324 \family typewriter
4325 4325 rotate
4326 4326 \family default
4327 4327 : create rotating logs
4328 4328 \family typewriter
4329 4329 log_name
4330 4330 \family default
4331 4331 .
4332 4332 \family typewriter
4333 4333 1~
4334 4334 \family default
4335 4335 ,
4336 4336 \family typewriter
4337 4337 log_name.2~
4338 4338 \family default
4339 4339 , etc.
4340 4340 \layout Standard
4341 4341
4342 4342 The
4343 4343 \family typewriter
4344 4344 %logoff
4345 4345 \family default
4346 4346 and
4347 4347 \family typewriter
4348 4348 %logon
4349 4349 \family default
4350 4350 functions allow you to temporarily stop and resume logging to a file which
4351 4351 had previously been started with
4352 4352 \family typewriter
4353 4353 %logstart
4354 4354 \family default
4355 4355 .
4356 4356 They will fail (with an explanation) if you try to use them before logging
4357 4357 has been started.
4358 4358 \layout Subsection
4359 4359
4360 4360
4361 4361 \begin_inset LatexCommand \label{sub:System-shell-access}
4362 4362
4363 4363 \end_inset
4364 4364
4365 4365 System shell access
4366 4366 \layout Standard
4367 4367
4368 4368 Any input line beginning with a
4369 4369 \family typewriter
4370 4370 !
4371 4371 \family default
4372 4372 character is passed verbatim (minus the
4373 4373 \family typewriter
4374 4374 !
4375 4375 \family default
4376 4376 , of course) to the underlying operating system.
4377 4377 For example, typing
4378 4378 \family typewriter
4379 4379 !ls
4380 4380 \family default
4381 4381 will run
4382 4382 \family typewriter
4383 4383 'ls'
4384 4384 \family default
4385 4385 in the current directory.
4386 4386 \layout Subsubsection
4387 4387
4388 4388 Manual capture of command output
4389 4389 \layout Standard
4390 4390
4391 4391 If the input line begins with
4392 4392 \emph on
4393 4393 two
4394 4394 \emph default
4395 4395 exclamation marks,
4396 4396 \family typewriter
4397 4397 !!
4398 4398 \family default
4399 4399 , the command is executed but its output is captured and returned as a python
4400 4400 list, split on newlines.
4401 4401 Any output sent by the subprocess to standard error is printed separately,
4402 4402 so that the resulting list only captures standard output.
4403 4403 The
4404 4404 \family typewriter
4405 4405 !!
4406 4406 \family default
4407 4407 syntax is a shorthand for the
4408 4408 \family typewriter
4409 4409 %sx
4410 4410 \family default
4411 4411 magic command.
4412 4412 \layout Standard
4413 4413
4414 4414 Finally, the
4415 4415 \family typewriter
4416 4416 %sc
4417 4417 \family default
4418 4418 magic (short for `shell capture') is similar to
4419 4419 \family typewriter
4420 4420 %sx
4421 4421 \family default
4422 4422 , but allowing more fine-grained control of the capture details, and storing
4423 4423 the result directly into a named variable.
4424 4424 \layout Standard
4425 4425
4426 4426 See Sec.\SpecialChar ~
4427 4427
4428 4428 \begin_inset LatexCommand \ref{sec:magic}
4429 4429
4430 4430 \end_inset
4431 4431
4432 4432 for details on the magics
4433 4433 \family typewriter
4434 4434 %sc
4435 4435 \family default
4436 4436 and
4437 4437 \family typewriter
4438 4438 %sx
4439 4439 \family default
4440 4440 , or use IPython's own help (
4441 4441 \family typewriter
4442 4442 sc?
4443 4443 \family default
4444 4444 and
4445 4445 \family typewriter
4446 4446 sx?
4447 4447 \family default
4448 4448 ) for further details.
4449 4449 \layout Standard
4450 4450
4451 4451 IPython also allows you to expand the value of python variables when making
4452 4452 system calls.
4453 4453 Any python variable or expression which you prepend with
4454 4454 \family typewriter
4455 4455 $
4456 4456 \family default
4457 4457 will get expanded before the system call is made.
4458 4458
4459 4459 \layout Standard
4460 4460
4461 4461
4462 4462 \family typewriter
4463 4463 In [1]: pyvar='Hello world'
4464 4464 \newline
4465 4465 In [2]: !echo "A python variable: $pyvar"
4466 4466 \newline
4467 4467 A python variable: Hello world
4468 4468 \layout Standard
4469 4469
4470 4470 If you want the shell to actually see a literal
4471 4471 \family typewriter
4472 4472 $
4473 4473 \family default
4474 4474 , you need to type it twice:
4475 4475 \layout Standard
4476 4476
4477 4477
4478 4478 \family typewriter
4479 4479 In [3]: !echo "A system variable: $$HOME"
4480 4480 \newline
4481 4481 A system variable: /home/fperez
4482 4482 \layout Standard
4483 4483
4484 4484 You can pass arbitrary expressions, though you'll need to delimit them with
4485 4485
4486 4486 \family typewriter
4487 4487 {}
4488 4488 \family default
4489 4489 if there is ambiguity as to the extent of the expression:
4490 4490 \layout Standard
4491 4491
4492 4492
4493 4493 \family typewriter
4494 4494 In [5]: x=10
4495 4495 \newline
4496 4496 In [6]: y=20
4497 4497 \newline
4498 4498 In [13]: !echo $x+y
4499 4499 \newline
4500 4500 10+y
4501 4501 \newline
4502 4502 In [7]: !echo ${x+y}
4503 4503 \newline
4504 4504 30
4505 4505 \layout Standard
4506 4506
4507 4507 Even object attributes can be expanded:
4508 4508 \layout Standard
4509 4509
4510 4510
4511 4511 \family typewriter
4512 4512 In [12]: !echo $sys.argv
4513 4513 \newline
4514 4514 [/home/fperez/usr/bin/ipython]
4515 4515 \layout Subsection
4516 4516
4517 4517 System command aliases
4518 4518 \layout Standard
4519 4519
4520 4520 The
4521 4521 \family typewriter
4522 4522 %alias
4523 4523 \family default
4524 4524 magic function and the
4525 4525 \family typewriter
4526 4526 alias
4527 4527 \family default
4528 4528 option in the
4529 4529 \family typewriter
4530 4530 ipythonrc
4531 4531 \family default
4532 4532 configuration file allow you to define magic functions which are in fact
4533 4533 system shell commands.
4534 4534 These aliases can have parameters.
4535 4535
4536 4536 \layout Standard
4537 4537
4538 4538 '
4539 4539 \family typewriter
4540 4540 %alias alias_name cmd
4541 4541 \family default
4542 4542 ' defines '
4543 4543 \family typewriter
4544 4544 alias_name
4545 4545 \family default
4546 4546 ' as an alias for '
4547 4547 \family typewriter
4548 4548 cmd
4549 4549 \family default
4550 4550 '
4551 4551 \layout Standard
4552 4552
4553 4553 Then, typing '
4554 4554 \family typewriter
4555 4555 %alias_name params
4556 4556 \family default
4557 4557 ' will execute the system command '
4558 4558 \family typewriter
4559 4559 cmd params
4560 4560 \family default
4561 4561 ' (from your underlying operating system).
4562 4562
4563 4563 \layout Standard
4564 4564
4565 4565 You can also define aliases with parameters using
4566 4566 \family typewriter
4567 4567 %s
4568 4568 \family default
4569 4569 specifiers (one per parameter).
4570 4570 The following example defines the
4571 4571 \family typewriter
4572 4572 %parts
4573 4573 \family default
4574 4574 function as an alias to the command '
4575 4575 \family typewriter
4576 4576 echo first %s second %s
4577 4577 \family default
4578 4578 ' where each
4579 4579 \family typewriter
4580 4580 %s
4581 4581 \family default
4582 4582 will be replaced by a positional parameter to the call to
4583 4583 \family typewriter
4584 4584 %parts:
4585 4585 \layout Standard
4586 4586
4587 4587
4588 4588 \family typewriter
4589 4589 In [1]: alias parts echo first %s second %s
4590 4590 \newline
4591 4591 In [2]: %parts A B
4592 4592 \newline
4593 4593 first A second B
4594 4594 \newline
4595 4595 In [3]: %parts A
4596 4596 \newline
4597 4597 Incorrect number of arguments: 2 expected.
4598 4598
4599 4599 \newline
4600 4600 parts is an alias to: 'echo first %s second %s'
4601 4601 \layout Standard
4602 4602
4603 4603 If called with no parameters,
4604 4604 \family typewriter
4605 4605 %alias
4606 4606 \family default
4607 4607 prints the table of currently defined aliases.
4608 4608 \layout Standard
4609 4609
4610 4610 The
4611 4611 \family typewriter
4612 4612 %rehash/rehashx
4613 4613 \family default
4614 4614 magics allow you to load your entire
4615 4615 \family typewriter
4616 4616 $PATH
4617 4617 \family default
4618 4618 as ipython aliases.
4619 4619 See their respective docstrings (or sec.\SpecialChar ~
4620 4620
4621 4621 \begin_inset LatexCommand \ref{sec:magic}
4622 4622
4623 4623 \end_inset
4624 4624
4625 4625 for further details).
4626 4626 \layout Subsection
4627 4627
4628 4628
4629 4629 \begin_inset LatexCommand \label{sec:dreload}
4630 4630
4631 4631 \end_inset
4632 4632
4633 4633 Recursive reload
4634 4634 \layout Standard
4635 4635
4636 4636 The
4637 4637 \family typewriter
4638 4638 %dreload
4639 4639 \family default
4640 4640 command does a recursive reload of a module: changes made to the module
4641 4641 since you imported will actually be available without having to exit.
4642 4642 \layout Subsection
4643 4643
4644 4644 Verbose and colored exception traceback printouts
4645 4645 \layout Standard
4646 4646
4647 4647 IPython provides the option to see very detailed exception tracebacks, which
4648 4648 can be especially useful when debugging large programs.
4649 4649 You can run any Python file with the
4650 4650 \family typewriter
4651 4651 %run
4652 4652 \family default
4653 4653 function to benefit from these detailed tracebacks.
4654 4654 Furthermore, both normal and verbose tracebacks can be colored (if your
4655 4655 terminal supports it) which makes them much easier to parse visually.
4656 4656 \layout Standard
4657 4657
4658 4658 See the magic
4659 4659 \family typewriter
4660 4660 xmode
4661 4661 \family default
4662 4662 and
4663 4663 \family typewriter
4664 4664 colors
4665 4665 \family default
4666 4666 functions for details (just type
4667 4667 \family typewriter
4668 4668 %magic
4669 4669 \family default
4670 4670 ).
4671 4671 \layout Standard
4672 4672
4673 4673 These features are basically a terminal version of Ka-Ping Yee's
4674 4674 \family typewriter
4675 4675 cgitb
4676 4676 \family default
4677 4677 module, now part of the standard Python library.
4678 4678 \layout Subsection
4679 4679
4680 4680
4681 4681 \begin_inset LatexCommand \label{sec:cache_input}
4682 4682
4683 4683 \end_inset
4684 4684
4685 4685 Input caching system
4686 4686 \layout Standard
4687 4687
4688 4688 IPython offers numbered prompts (In/Out) with input and output caching.
4689 4689 All input is saved and can be retrieved as variables (besides the usual
4690 4690 arrow key recall).
4691 4691 \layout Standard
4692 4692
4693 4693 The following GLOBAL variables always exist (so don't overwrite them!):
4694 4694
4695 4695 \family typewriter
4696 4696 _i
4697 4697 \family default
4698 4698 : stores previous input.
4699 4699
4700 4700 \family typewriter
4701 4701 _ii
4702 4702 \family default
4703 4703 : next previous.
4704 4704
4705 4705 \family typewriter
4706 4706 _iii
4707 4707 \family default
4708 4708 : next-next previous.
4709 4709
4710 4710 \family typewriter
4711 4711 _ih
4712 4712 \family default
4713 4713 : a list of all input
4714 4714 \family typewriter
4715 4715 _ih[n]
4716 4716 \family default
4717 4717 is the input from line
4718 4718 \family typewriter
4719 4719 n
4720 4720 \family default
4721 4721 and this list is aliased to the global variable
4722 4722 \family typewriter
4723 4723 In
4724 4724 \family default
4725 4725 .
4726 4726 If you overwrite
4727 4727 \family typewriter
4728 4728 In
4729 4729 \family default
4730 4730 with a variable of your own, you can remake the assignment to the internal
4731 4731 list with a simple
4732 4732 \family typewriter
4733 4733 'In=_ih'
4734 4734 \family default
4735 4735 .
4736 4736 \layout Standard
4737 4737
4738 4738 Additionally, global variables named
4739 4739 \family typewriter
4740 4740 _i<n>
4741 4741 \family default
4742 4742 are dynamically created (
4743 4743 \family typewriter
4744 4744 <n>
4745 4745 \family default
4746 4746 being the prompt counter), such that
4747 4747 \newline
4748 4748
4749 4749 \family typewriter
4750 4750 _i<n> == _ih[<n>] == In[<n>].
4751 4751 \layout Standard
4752 4752
4753 4753 For example, what you typed at prompt 14 is available as
4754 4754 \family typewriter
4755 4755 _i14,
4756 4756 \family default
4757 4757
4758 4758 \family typewriter
4759 4759 _ih[14]
4760 4760 \family default
4761 4761 and
4762 4762 \family typewriter
4763 4763 In[14]
4764 4764 \family default
4765 4765 .
4766 4766 \layout Standard
4767 4767
4768 4768 This allows you to easily cut and paste multi line interactive prompts by
4769 4769 printing them out: they print like a clean string, without prompt characters.
4770 4770 You can also manipulate them like regular variables (they are strings),
4771 4771 modify or exec them (typing
4772 4772 \family typewriter
4773 4773 'exec _i9'
4774 4774 \family default
4775 4775 will re-execute the contents of input prompt 9, '
4776 4776 \family typewriter
4777 4777 exec In[9:14]+In[18]
4778 4778 \family default
4779 4779 ' will re-execute lines 9 through 13 and line 18).
4780 4780 \layout Standard
4781 4781
4782 4782 You can also re-execute multiple lines of input easily by using the magic
4783 4783
4784 4784 \family typewriter
4785 4785 %macro
4786 4786 \family default
4787 4787 function (which automates the process and allows re-execution without having
4788 4788 to type '
4789 4789 \family typewriter
4790 4790 exec
4791 4791 \family default
4792 4792 ' every time).
4793 4793 The macro system also allows you to re-execute previous lines which include
4794 4794 magic function calls (which require special processing).
4795 4795 Type
4796 4796 \family typewriter
4797 4797 %macro?
4798 4798 \family default
4799 4799 or see sec.
4800 4800
4801 4801 \begin_inset LatexCommand \ref{sec:magic}
4802 4802
4803 4803 \end_inset
4804 4804
4805 4805 for more details on the macro system.
4806 4806 \layout Standard
4807 4807
4808 4808 A history function
4809 4809 \family typewriter
4810 4810 %hist
4811 4811 \family default
4812 4812 allows you to see any part of your input history by printing a range of
4813 4813 the
4814 4814 \family typewriter
4815 4815 _i
4816 4816 \family default
4817 4817 variables.
4818 4818 \layout Subsection
4819 4819
4820 4820
4821 4821 \begin_inset LatexCommand \label{sec:cache_output}
4822 4822
4823 4823 \end_inset
4824 4824
4825 4825 Output caching system
4826 4826 \layout Standard
4827 4827
4828 4828 For output that is returned from actions, a system similar to the input
4829 4829 cache exists but using
4830 4830 \family typewriter
4831 4831 _
4832 4832 \family default
4833 4833 instead of
4834 4834 \family typewriter
4835 4835 _i
4836 4836 \family default
4837 4837 .
4838 4838 Only actions that produce a result (NOT assignments, for example) are cached.
4839 4839 If you are familiar with Mathematica, IPython's
4840 4840 \family typewriter
4841 4841 _
4842 4842 \family default
4843 4843 variables behave exactly like Mathematica's
4844 4844 \family typewriter
4845 4845 %
4846 4846 \family default
4847 4847 variables.
4848 4848 \layout Standard
4849 4849
4850 4850 The following GLOBAL variables always exist (so don't overwrite them!):
4851 4851
4852 4852 \layout List
4853 4853 \labelwidthstring 00.00.0000
4854 4854
4855 4855
4856 4856 \family typewriter
4857 4857 \series bold
4858 4858 _
4859 4859 \family default
4860 4860 \series default
4861 4861 (a
4862 4862 \emph on
4863 4863 single
4864 4864 \emph default
4865 4865 underscore) : stores previous output, like Python's default interpreter.
4866 4866 \layout List
4867 4867 \labelwidthstring 00.00.0000
4868 4868
4869 4869
4870 4870 \family typewriter
4871 4871 \series bold
4872 4872 __
4873 4873 \family default
4874 4874 \series default
4875 4875 (two underscores): next previous.
4876 4876 \layout List
4877 4877 \labelwidthstring 00.00.0000
4878 4878
4879 4879
4880 4880 \family typewriter
4881 4881 \series bold
4882 4882 ___
4883 4883 \family default
4884 4884 \series default
4885 4885 (three underscores): next-next previous.
4886 4886 \layout Standard
4887 4887
4888 4888 Additionally, global variables named
4889 4889 \family typewriter
4890 4890 _<n>
4891 4891 \family default
4892 4892 are dynamically created (
4893 4893 \family typewriter
4894 4894 <n>
4895 4895 \family default
4896 4896 being the prompt counter), such that the result of output
4897 4897 \family typewriter
4898 4898 <n>
4899 4899 \family default
4900 4900 is always available as
4901 4901 \family typewriter
4902 4902 _<n>
4903 4903 \family default
4904 4904 (don't use the angle brackets, just the number, e.g.
4905 4905
4906 4906 \family typewriter
4907 4907 _21
4908 4908 \family default
4909 4909 ).
4910 4910 \layout Standard
4911 4911
4912 4912 These global variables are all stored in a global dictionary (not a list,
4913 4913 since it only has entries for lines which returned a result) available
4914 4914 under the names
4915 4915 \family typewriter
4916 4916 _oh
4917 4917 \family default
4918 4918 and
4919 4919 \family typewriter
4920 4920 Out
4921 4921 \family default
4922 4922 (similar to
4923 4923 \family typewriter
4924 4924 _ih
4925 4925 \family default
4926 4926 and
4927 4927 \family typewriter
4928 4928 In
4929 4929 \family default
4930 4930 ).
4931 4931 So the output from line 12 can be obtained as
4932 4932 \family typewriter
4933 4933 _12
4934 4934 \family default
4935 4935 ,
4936 4936 \family typewriter
4937 4937 Out[12]
4938 4938 \family default
4939 4939 or
4940 4940 \family typewriter
4941 4941 _oh[12]
4942 4942 \family default
4943 4943 .
4944 4944 If you accidentally overwrite the
4945 4945 \family typewriter
4946 4946 Out
4947 4947 \family default
4948 4948 variable you can recover it by typing
4949 4949 \family typewriter
4950 4950 'Out=_oh
4951 4951 \family default
4952 4952 ' at the prompt.
4953 4953 \layout Standard
4954 4954
4955 4955 This system obviously can potentially put heavy memory demands on your system,
4956 4956 since it prevents Python's garbage collector from removing any previously
4957 4957 computed results.
4958 4958 You can control how many results are kept in memory with the option (at
4959 4959 the command line or in your
4960 4960 \family typewriter
4961 4961 ipythonrc
4962 4962 \family default
4963 4963 file)
4964 4964 \family typewriter
4965 4965 cache_size
4966 4966 \family default
4967 4967 .
4968 4968 If you set it to 0, the whole system is completely disabled and the prompts
4969 4969 revert to the classic
4970 4970 \family typewriter
4971 4971 '>>>'
4972 4972 \family default
4973 4973 of normal Python.
4974 4974 \layout Subsection
4975 4975
4976 4976 Directory history
4977 4977 \layout Standard
4978 4978
4979 4979 Your history of visited directories is kept in the global list
4980 4980 \family typewriter
4981 4981 _dh
4982 4982 \family default
4983 4983 , and the magic
4984 4984 \family typewriter
4985 4985 %cd
4986 4986 \family default
4987 4987 command can be used to go to any entry in that list.
4988 4988 The
4989 4989 \family typewriter
4990 4990 %dhist
4991 4991 \family default
4992 4992 command allows you to view this history.
4993 4993 \layout Subsection
4994 4994
4995 4995 Automatic parentheses and quotes
4996 4996 \layout Standard
4997 4997
4998 4998 These features were adapted from Nathan Gray's LazyPython.
4999 4999 They are meant to allow less typing for common situations.
5000 5000 \layout Subsubsection
5001 5001
5002 5002 Automatic parentheses
5003 5003 \layout Standard
5004 5004
5005 5005 Callable objects (i.e.
5006 5006 functions, methods, etc) can be invoked like this (notice the commas between
5007 5007 the arguments):
5008 5008 \layout Standard
5009 5009
5010 5010
5011 5011 \family typewriter
5012 5012 >>> callable_ob arg1, arg2, arg3
5013 5013 \layout Standard
5014 5014
5015 5015 and the input will be translated to this:
5016 5016 \layout Standard
5017 5017
5018 5018
5019 5019 \family typewriter
5020 5020 --> callable_ob(arg1, arg2, arg3)
5021 5021 \layout Standard
5022 5022
5023 5023 You can force automatic parentheses by using '/' as the first character
5024 5024 of a line.
5025 5025 For example:
5026 5026 \layout Standard
5027 5027
5028 5028
5029 5029 \family typewriter
5030 5030 >>> /globals # becomes 'globals()'
5031 5031 \layout Standard
5032 5032
5033 5033 Note that the '/' MUST be the first character on the line! This won't work:
5034 5034
5035 5035 \layout Standard
5036 5036
5037 5037
5038 5038 \family typewriter
5039 5039 >>> print /globals # syntax error
5040 5040 \layout Standard
5041 5041
5042 5042 In most cases the automatic algorithm should work, so you should rarely
5043 5043 need to explicitly invoke /.
5044 5044 One notable exception is if you are trying to call a function with a list
5045 5045 of tuples as arguments (the parenthesis will confuse IPython):
5046 5046 \layout Standard
5047 5047
5048 5048
5049 5049 \family typewriter
5050 5050 In [1]: zip (1,2,3),(4,5,6) # won't work
5051 5051 \layout Standard
5052 5052
5053 5053 but this will work:
5054 5054 \layout Standard
5055 5055
5056 5056
5057 5057 \family typewriter
5058 5058 In [2]: /zip (1,2,3),(4,5,6)
5059 5059 \newline
5060 5060 ------> zip ((1,2,3),(4,5,6))
5061 5061 \newline
5062 5062 Out[2]= [(1, 4), (2, 5), (3, 6)]
5063 5063 \layout Standard
5064 5064
5065 5065 IPython tells you that it has altered your command line by displaying the
5066 5066 new command line preceded by
5067 5067 \family typewriter
5068 5068 -->
5069 5069 \family default
5070 5070 .
5071 5071 e.g.:
5072 5072 \layout Standard
5073 5073
5074 5074
5075 5075 \family typewriter
5076 5076 In [18]: callable list
5077 5077 \newline
5078 5078 -------> callable (list)
5079 5079 \layout Subsubsection
5080 5080
5081 5081 Automatic quoting
5082 5082 \layout Standard
5083 5083
5084 5084 You can force automatic quoting of a function's arguments by using
5085 5085 \family typewriter
5086 5086 `,'
5087 5087 \family default
5088 5088 or
5089 5089 \family typewriter
5090 5090 `;'
5091 5091 \family default
5092 5092 as the first character of a line.
5093 5093 For example:
5094 5094 \layout Standard
5095 5095
5096 5096
5097 5097 \family typewriter
5098 5098 >>> ,my_function /home/me # becomes my_function("/home/me")
5099 5099 \layout Standard
5100 5100
5101 5101 If you use
5102 5102 \family typewriter
5103 5103 `;'
5104 5104 \family default
5105 5105 instead, the whole argument is quoted as a single string (while
5106 5106 \family typewriter
5107 5107 `,'
5108 5108 \family default
5109 5109 splits on whitespace):
5110 5110 \layout Standard
5111 5111
5112 5112
5113 5113 \family typewriter
5114 5114 >>> ,my_function a b c # becomes my_function("a","b","c")
5115 5115 \layout Standard
5116 5116
5117 5117
5118 5118 \family typewriter
5119 5119 >>> ;my_function a b c # becomes my_function("a b c")
5120 5120 \layout Standard
5121 5121
5122 5122 Note that the `
5123 5123 \family typewriter
5124 5124 ,
5125 5125 \family default
5126 5126 ' or `
5127 5127 \family typewriter
5128 5128 ;
5129 5129 \family default
5130 5130 ' MUST be the first character on the line! This won't work:
5131 5131 \layout Standard
5132 5132
5133 5133
5134 5134 \family typewriter
5135 5135 >>> x = ,my_function /home/me # syntax error
5136 5136 \layout Section
5137 5137
5138 5138
5139 5139 \begin_inset LatexCommand \label{sec:customization}
5140 5140
5141 5141 \end_inset
5142 5142
5143 5143 Customization
5144 5144 \layout Standard
5145 5145
5146 5146 As we've already mentioned, IPython reads a configuration file which can
5147 5147 be specified at the command line (
5148 5148 \family typewriter
5149 5149 -rcfile
5150 5150 \family default
5151 5151 ) or which by default is assumed to be called
5152 5152 \family typewriter
5153 5153 ipythonrc
5154 5154 \family default
5155 5155 .
5156 5156 Such a file is looked for in the current directory where IPython is started
5157 5157 and then in your
5158 5158 \family typewriter
5159 5159 IPYTHONDIR
5160 5160 \family default
5161 5161 , which allows you to have local configuration files for specific projects.
5162 5162 In this section we will call these types of configuration files simply
5163 5163 rcfiles (short for resource configuration file).
5164 5164 \layout Standard
5165 5165
5166 5166 The syntax of an rcfile is one of key-value pairs separated by whitespace,
5167 5167 one per line.
5168 5168 Lines beginning with a
5169 5169 \family typewriter
5170 5170 #
5171 5171 \family default
5172 5172 are ignored as comments, but comments can
5173 5173 \series bold
5174 5174 not
5175 5175 \series default
5176 5176 be put on lines with data (the parser is fairly primitive).
5177 5177 Note that these are not python files, and this is deliberate, because it
5178 5178 allows us to do some things which would be quite tricky to implement if
5179 5179 they were normal python files.
5180 5180 \layout Standard
5181 5181
5182 5182 First, an rcfile can contain permanent default values for almost all command
5183 5183 line options (except things like
5184 5184 \family typewriter
5185 5185 -help
5186 5186 \family default
5187 5187 or
5188 5188 \family typewriter
5189 5189 -Version
5190 5190 \family default
5191 5191 ).
5192 5192 Sec\SpecialChar ~
5193 5193
5194 5194 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5195 5195
5196 5196 \end_inset
5197 5197
5198 5198 contains a description of all command-line options.
5199 5199 However, values you explicitly specify at the command line override the
5200 5200 values defined in the rcfile.
5201 5201 \layout Standard
5202 5202
5203 5203 Besides command line option values, the rcfile can specify values for certain
5204 5204 extra special options which are not available at the command line.
5205 5205 These options are briefly described below.
5206 5206
5207 5207 \layout Standard
5208 5208
5209 5209 Each of these options may appear as many times as you need it in the file.
5210 5210 \layout List
5211 5211 \labelwidthstring 00.00.0000
5212 5212
5213 5213
5214 5214 \family typewriter
5215 5215 \series bold
5216 5216 include\SpecialChar ~
5217 5217 <file1>\SpecialChar ~
5218 5218 <file2>\SpecialChar ~
5219 5219 ...
5220 5220 \family default
5221 5221 \series default
5222 5222 : you can name
5223 5223 \emph on
5224 5224 other
5225 5225 \emph default
5226 5226 rcfiles you want to recursively load up to 15 levels (don't use the
5227 5227 \family typewriter
5228 5228 <>
5229 5229 \family default
5230 5230 brackets in your names!).
5231 5231 This feature allows you to define a 'base' rcfile with general options
5232 5232 and special-purpose files which can be loaded only when needed with particular
5233 5233 configuration options.
5234 5234 To make this more convenient, IPython accepts the
5235 5235 \family typewriter
5236 5236 -profile <name>
5237 5237 \family default
5238 5238 option (abbreviates to
5239 5239 \family typewriter
5240 5240 -p <name
5241 5241 \family default
5242 5242 >)
5243 5243 \family typewriter
5244 5244 which
5245 5245 \family default
5246 5246 tells it to look for an rcfile named
5247 5247 \family typewriter
5248 5248 ipythonrc-<name>
5249 5249 \family default
5250 5250 .
5251 5251
5252 5252 \layout List
5253 5253 \labelwidthstring 00.00.0000
5254 5254
5255 5255
5256 5256 \family typewriter
5257 5257 \series bold
5258 5258 import_mod\SpecialChar ~
5259 5259 <mod1>\SpecialChar ~
5260 5260 <mod2>\SpecialChar ~
5261 5261 ...
5262 5262 \family default
5263 5263 \series default
5264 5264 : import modules with '
5265 5265 \family typewriter
5266 5266 import
5267 5267 \family default
5268 5268
5269 5269 \family typewriter
5270 5270 <mod1>,<mod2>,...
5271 5271 \family default
5272 5272 '
5273 5273 \layout List
5274 5274 \labelwidthstring 00.00.0000
5275 5275
5276 5276
5277 5277 \family typewriter
5278 5278 \series bold
5279 5279 import_some\SpecialChar ~
5280 5280 <mod>\SpecialChar ~
5281 5281 <f1>\SpecialChar ~
5282 5282 <f2>\SpecialChar ~
5283 5283 ...
5284 5284 \family default
5285 5285 \series default
5286 5286 : import functions with '
5287 5287 \family typewriter
5288 5288 from <mod> import
5289 5289 \family default
5290 5290
5291 5291 \family typewriter
5292 5292 <f1>,<f2>,...
5293 5293 \family default
5294 5294 '
5295 5295 \layout List
5296 5296 \labelwidthstring 00.00.0000
5297 5297
5298 5298
5299 5299 \family typewriter
5300 5300 \series bold
5301 5301 import_all\SpecialChar ~
5302 5302 <mod1>\SpecialChar ~
5303 5303 <mod2>\SpecialChar ~
5304 5304 ...
5305 5305 \family default
5306 5306 \series default
5307 5307 : for each module listed import functions with '
5308 5308 \family typewriter
5309 5309 from <mod> import *
5310 5310 \family default
5311 5311 '
5312 5312 \layout List
5313 5313 \labelwidthstring 00.00.0000
5314 5314
5315 5315
5316 5316 \family typewriter
5317 5317 \series bold
5318 5318 execute\SpecialChar ~
5319 5319 <python\SpecialChar ~
5320 5320 code>
5321 5321 \family default
5322 5322 \series default
5323 5323 : give any single-line python code to be executed.
5324 5324 \layout List
5325 5325 \labelwidthstring 00.00.0000
5326 5326
5327 5327
5328 5328 \family typewriter
5329 5329 \series bold
5330 5330 execfile\SpecialChar ~
5331 5331 <filename>
5332 5332 \family default
5333 5333 \series default
5334 5334 : execute the python file given with an '
5335 5335 \family typewriter
5336 5336 execfile(filename)
5337 5337 \family default
5338 5338 ' command.
5339 5339 Username expansion is performed on the given names.
5340 5340 So if you need any amount of extra fancy customization that won't fit in
5341 5341 any of the above 'canned' options, you can just put it in a separate python
5342 5342 file and execute it.
5343 5343 \layout List
5344 5344 \labelwidthstring 00.00.0000
5345 5345
5346 5346
5347 5347 \family typewriter
5348 5348 \series bold
5349 5349 alias\SpecialChar ~
5350 5350 <alias_def>
5351 5351 \family default
5352 5352 \series default
5353 5353 : this is equivalent to calling '
5354 5354 \family typewriter
5355 5355 %alias\SpecialChar ~
5356 5356 <alias_def>
5357 5357 \family default
5358 5358 ' at the IPython command line.
5359 5359 This way, from within IPython you can do common system tasks without having
5360 5360 to exit it or use the
5361 5361 \family typewriter
5362 5362 !
5363 5363 \family default
5364 5364 escape.
5365 5365 IPython isn't meant to be a shell replacement, but it is often very useful
5366 5366 to be able to do things with files while testing code.
5367 5367 This gives you the flexibility to have within IPython any aliases you may
5368 5368 be used to under your normal system shell.
5369 5369 \layout Subsection
5370 5370
5371 5371
5372 5372 \begin_inset LatexCommand \label{sec:ipytonrc-sample}
5373 5373
5374 5374 \end_inset
5375 5375
5376 5376 Sample
5377 5377 \family typewriter
5378 5378 ipythonrc
5379 5379 \family default
5380 5380 file
5381 5381 \layout Standard
5382 5382
5383 5383 The default rcfile, called
5384 5384 \family typewriter
5385 5385 ipythonrc
5386 5386 \family default
5387 5387 and supplied in your
5388 5388 \family typewriter
5389 5389 IPYTHONDIR
5390 5390 \family default
5391 5391 directory contains lots of comments on all of these options.
5392 5392 We reproduce it here for reference:
5393 5393 \layout Standard
5394 5394
5395 5395
5396 5396 \begin_inset ERT
5397 5397 status Open
5398 5398
5399 5399 \layout Standard
5400 5400
5401 5401 \backslash
5402 5402 codelist{../IPython/UserConfig/ipythonrc}
5403 5403 \end_inset
5404 5404
5405 5405
5406 5406 \layout Subsection
5407 5407
5408 5408
5409 5409 \begin_inset LatexCommand \label{sec:prompts}
5410 5410
5411 5411 \end_inset
5412 5412
5413 5413 Fine-tuning your prompt
5414 5414 \layout Standard
5415 5415
5416 5416 IPython's prompts can be customized using a syntax similar to that of the
5417 5417
5418 5418 \family typewriter
5419 5419 bash
5420 5420 \family default
5421 5421 shell.
5422 5422 Many of
5423 5423 \family typewriter
5424 5424 bash
5425 5425 \family default
5426 5426 's escapes are supported, as well as a few additional ones.
5427 5427 We list them below:
5428 5428 \layout Description
5429 5429
5430 5430
5431 5431 \backslash
5432 5432 # the prompt/history count number
5433 5433 \layout Description
5434 5434
5435 5435
5436 5436 \backslash
5437 5437 D the prompt/history count, with the actual digits replaced by dots.
5438 5438 Used mainly in continuation prompts (prompt_in2)
5439 5439 \layout Description
5440 5440
5441 5441
5442 5442 \backslash
5443 5443 w the current working directory
5444 5444 \layout Description
5445 5445
5446 5446
5447 5447 \backslash
5448 5448 W the basename of current working directory
5449 5449 \layout Description
5450 5450
5451 5451
5452 5452 \backslash
5453 5453 X
5454 5454 \emph on
5455 5455 n
5456 5456 \emph default
5457 5457 where
5458 5458 \begin_inset Formula $n=0\ldots5.$
5459 5459 \end_inset
5460 5460
5461 5461 The current working directory, with
5462 5462 \family typewriter
5463 5463 $HOME
5464 5464 \family default
5465 5465 replaced by
5466 5466 \family typewriter
5467 5467 ~
5468 5468 \family default
5469 5469 , and filtered out to contain only
5470 5470 \begin_inset Formula $n$
5471 5471 \end_inset
5472 5472
5473 5473 path elements
5474 5474 \layout Description
5475 5475
5476 5476
5477 5477 \backslash
5478 5478 Y
5479 5479 \emph on
5480 5480 n
5481 5481 \emph default
5482 5482 Similar to
5483 5483 \backslash
5484 5484 X
5485 5485 \emph on
5486 5486 n
5487 5487 \emph default
5488 5488 , but with the
5489 5489 \begin_inset Formula $n+1$
5490 5490 \end_inset
5491 5491
5492 5492 element included if it is
5493 5493 \family typewriter
5494 5494 ~
5495 5495 \family default
5496 5496 (this is similar to the behavior of the %c
5497 5497 \emph on
5498 5498 n
5499 5499 \emph default
5500 5500 escapes in
5501 5501 \family typewriter
5502 5502 tcsh
5503 5503 \family default
5504 5504 )
5505 5505 \layout Description
5506 5506
5507 5507
5508 5508 \backslash
5509 5509 u the username of the current user
5510 5510 \layout Description
5511 5511
5512 5512
5513 5513 \backslash
5514 5514 $ if the effective UID is 0, a #, otherwise a $
5515 5515 \layout Description
5516 5516
5517 5517
5518 5518 \backslash
5519 5519 h the hostname up to the first `.'
5520 5520 \layout Description
5521 5521
5522 5522
5523 5523 \backslash
5524 5524 H the hostname
5525 5525 \layout Description
5526 5526
5527 5527
5528 5528 \backslash
5529 5529 n a newline
5530 5530 \layout Description
5531 5531
5532 5532
5533 5533 \backslash
5534 5534 r a carriage return
5535 5535 \layout Description
5536 5536
5537 5537
5538 5538 \backslash
5539 5539 v IPython version string
5540 5540 \layout Standard
5541 5541
5542 5542 In addition to these, ANSI color escapes can be insterted into the prompts,
5543 5543 as
5544 5544 \family typewriter
5545 5545
5546 5546 \backslash
5547 5547 C_
5548 5548 \emph on
5549 5549 ColorName
5550 5550 \family default
5551 5551 \emph default
5552 5552 .
5553 5553 The list of valid color names is: Black, Blue, Brown, Cyan, DarkGray, Green,
5554 5554 LightBlue, LightCyan, LightGray, LightGreen, LightPurple, LightRed, NoColor,
5555 5555 Normal, Purple, Red, White, Yellow.
5556 5556 \layout Standard
5557 5557
5558 5558 Finally, IPython supports the evaluation of arbitrary expressions in your
5559 5559 prompt string.
5560 5560 The prompt strings are evaluated through the syntax of PEP 215, but basically
5561 5561 you can use
5562 5562 \family typewriter
5563 5563 $x.y
5564 5564 \family default
5565 5565 to expand the value of
5566 5566 \family typewriter
5567 5567 x.y
5568 5568 \family default
5569 5569 , and for more complicated expressions you can use braces:
5570 5570 \family typewriter
5571 5571 ${foo()+x}
5572 5572 \family default
5573 5573 will call function
5574 5574 \family typewriter
5575 5575 foo
5576 5576 \family default
5577 5577 and add to it the value of
5578 5578 \family typewriter
5579 5579 x
5580 5580 \family default
5581 5581 , before putting the result into your prompt.
5582 5582 For example, using
5583 5583 \newline
5584 5584
5585 5585 \family typewriter
5586 5586 prompt_in1 '${commands.getoutput("uptime")}
5587 5587 \backslash
5588 5588 nIn [
5589 5589 \backslash
5590 5590 #]: '
5591 5591 \newline
5592 5592
5593 5593 \family default
5594 5594 will print the result of the uptime command on each prompt (assuming the
5595 5595
5596 5596 \family typewriter
5597 5597 commands
5598 5598 \family default
5599 5599 module has been imported in your
5600 5600 \family typewriter
5601 5601 ipythonrc
5602 5602 \family default
5603 5603 file).
5604 5604 \layout Subsubsection
5605 5605
5606 5606 Prompt examples
5607 5607 \layout Standard
5608 5608
5609 5609 The following options in an ipythonrc file will give you IPython's default
5610 5610 prompts:
5611 5611 \layout Standard
5612 5612
5613 5613
5614 5614 \family typewriter
5615 5615 prompt_in1 'In [
5616 5616 \backslash
5617 5617 #]:'
5618 5618 \newline
5619 5619 prompt_in2 '\SpecialChar ~
5620 5620 \SpecialChar ~
5621 5621 \SpecialChar ~
5622 5622 .
5623 5623 \backslash
5624 5624 D.:'
5625 5625 \newline
5626 5626 prompt_out 'Out[
5627 5627 \backslash
5628 5628 #]:'
5629 5629 \layout Standard
5630 5630
5631 5631 which look like this:
5632 5632 \layout Standard
5633 5633
5634 5634
5635 5635 \family typewriter
5636 5636 In [1]: 1+2
5637 5637 \newline
5638 5638 Out[1]: 3
5639 5639 \layout Standard
5640 5640
5641 5641
5642 5642 \family typewriter
5643 5643 In [2]: for i in (1,2,3):
5644 5644 \newline
5645 5645
5646 5646 \begin_inset ERT
5647 5647 status Collapsed
5648 5648
5649 5649 \layout Standard
5650 5650
5651 5651 \backslash
5652 5652 hspace*{0mm}
5653 5653 \end_inset
5654 5654
5655 5655 \SpecialChar ~
5656 5656 \SpecialChar ~
5657 5657 \SpecialChar ~
5658 5658 ...: \SpecialChar ~
5659 5659 \SpecialChar ~
5660 5660 \SpecialChar ~
5661 5661 \SpecialChar ~
5662 5662 print i,
5663 5663 \newline
5664 5664
5665 5665 \begin_inset ERT
5666 5666 status Collapsed
5667 5667
5668 5668 \layout Standard
5669 5669
5670 5670 \backslash
5671 5671 hspace*{0mm}
5672 5672 \end_inset
5673 5673
5674 5674 \SpecialChar ~
5675 5675 \SpecialChar ~
5676 5676 \SpecialChar ~
5677 5677 ...:
5678 5678 \newline
5679 5679 1 2 3
5680 5680 \layout Standard
5681 5681
5682 5682 These will give you a very colorful prompt with path information:
5683 5683 \layout Standard
5684 5684
5685 5685
5686 5686 \family typewriter
5687 5687 #prompt_in1 '
5688 5688 \backslash
5689 5689 C_Red
5690 5690 \backslash
5691 5691 u
5692 5692 \backslash
5693 5693 C_Blue[
5694 5694 \backslash
5695 5695 C_Cyan
5696 5696 \backslash
5697 5697 Y1
5698 5698 \backslash
5699 5699 C_Blue]
5700 5700 \backslash
5701 5701 C_LightGreen
5702 5702 \backslash
5703 5703 #>'
5704 5704 \newline
5705 5705 prompt_in2 ' ..
5706 5706 \backslash
5707 5707 D>'
5708 5708 \newline
5709 5709 prompt_out '<
5710 5710 \backslash
5711 5711 #>'
5712 5712 \layout Standard
5713 5713
5714 5714 which look like this:
5715 5715 \layout Standard
5716 5716
5717 5717
5718 5718 \family typewriter
5719 5719 \color red
5720 5720 fperez
5721 5721 \color blue
5722 5722 [
5723 5723 \color cyan
5724 5724 ~/ipython
5725 5725 \color blue
5726 5726 ]
5727 5727 \color green
5728 5728 1>
5729 5729 \color default
5730 5730 1+2
5731 5731 \newline
5732 5732
5733 5733 \begin_inset ERT
5734 5734 status Collapsed
5735 5735
5736 5736 \layout Standard
5737 5737
5738 5738 \backslash
5739 5739 hspace*{0mm}
5740 5740 \end_inset
5741 5741
5742 5742 \SpecialChar ~
5743 5743 \SpecialChar ~
5744 5744 \SpecialChar ~
5745 5745 \SpecialChar ~
5746 5746 \SpecialChar ~
5747 5747 \SpecialChar ~
5748 5748 \SpecialChar ~
5749 5749 \SpecialChar ~
5750 5750 \SpecialChar ~
5751 5751 \SpecialChar ~
5752 5752 \SpecialChar ~
5753 5753 \SpecialChar ~
5754 5754 \SpecialChar ~
5755 5755 \SpecialChar ~
5756 5756 \SpecialChar ~
5757 5757 \SpecialChar ~
5758 5758
5759 5759 \color red
5760 5760 <1>
5761 5761 \color default
5762 5762 3
5763 5763 \newline
5764 5764
5765 5765 \color red
5766 5766 fperez
5767 5767 \color blue
5768 5768 [
5769 5769 \color cyan
5770 5770 ~/ipython
5771 5771 \color blue
5772 5772 ]
5773 5773 \color green
5774 5774 2>
5775 5775 \color default
5776 5776 for i in (1,2,3):
5777 5777 \newline
5778 5778
5779 5779 \begin_inset ERT
5780 5780 status Collapsed
5781 5781
5782 5782 \layout Standard
5783 5783
5784 5784 \backslash
5785 5785 hspace*{0mm}
5786 5786 \end_inset
5787 5787
5788 5788 \SpecialChar ~
5789 5789 \SpecialChar ~
5790 5790 \SpecialChar ~
5791 5791 \SpecialChar ~
5792 5792 \SpecialChar ~
5793 5793 \SpecialChar ~
5794 5794 \SpecialChar ~
5795 5795 \SpecialChar ~
5796 5796 \SpecialChar ~
5797 5797 \SpecialChar ~
5798 5798 \SpecialChar ~
5799 5799 \SpecialChar ~
5800 5800 \SpecialChar ~
5801 5801 \SpecialChar ~
5802 5802 \SpecialChar ~
5803 5803
5804 5804 \color green
5805 5805 ...>
5806 5806 \color default
5807 5807 \SpecialChar ~
5808 5808 \SpecialChar ~
5809 5809 \SpecialChar ~
5810 5810 \SpecialChar ~
5811 5811 print i,
5812 5812 \newline
5813 5813
5814 5814 \begin_inset ERT
5815 5815 status Collapsed
5816 5816
5817 5817 \layout Standard
5818 5818
5819 5819 \backslash
5820 5820 hspace*{0mm}
5821 5821 \end_inset
5822 5822
5823 5823 \SpecialChar ~
5824 5824 \SpecialChar ~
5825 5825 \SpecialChar ~
5826 5826 \SpecialChar ~
5827 5827 \SpecialChar ~
5828 5828 \SpecialChar ~
5829 5829 \SpecialChar ~
5830 5830 \SpecialChar ~
5831 5831 \SpecialChar ~
5832 5832 \SpecialChar ~
5833 5833 \SpecialChar ~
5834 5834 \SpecialChar ~
5835 5835 \SpecialChar ~
5836 5836 \SpecialChar ~
5837 5837 \SpecialChar ~
5838 5838
5839 5839 \color green
5840 5840 ...>
5841 5841 \color default
5842 5842
5843 5843 \newline
5844 5844 1 2 3
5845 5845 \layout Standard
5846 5846
5847 5847 The following shows the usage of dynamic expression evaluation:
5848 5848 \layout Subsection
5849 5849
5850 5850
5851 5851 \begin_inset LatexCommand \label{sec:profiles}
5852 5852
5853 5853 \end_inset
5854 5854
5855 5855 IPython profiles
5856 5856 \layout Standard
5857 5857
5858 5858 As we already mentioned, IPython supports the
5859 5859 \family typewriter
5860 5860 -profile
5861 5861 \family default
5862 5862 command-line option (see sec.
5863 5863
5864 5864 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5865 5865
5866 5866 \end_inset
5867 5867
5868 5868 ).
5869 5869 A profile is nothing more than a particular configuration file like your
5870 5870 basic
5871 5871 \family typewriter
5872 5872 ipythonrc
5873 5873 \family default
5874 5874 one, but with particular customizations for a specific purpose.
5875 5875 When you start IPython with '
5876 5876 \family typewriter
5877 5877 ipython -profile <name>
5878 5878 \family default
5879 5879 ', it assumes that in your
5880 5880 \family typewriter
5881 5881 IPYTHONDIR
5882 5882 \family default
5883 5883 there is a file called
5884 5884 \family typewriter
5885 5885 ipythonrc-<name>
5886 5886 \family default
5887 5887 , and loads it instead of the normal
5888 5888 \family typewriter
5889 5889 ipythonrc
5890 5890 \family default
5891 5891 .
5892 5892 \layout Standard
5893 5893
5894 5894 This system allows you to maintain multiple configurations which load modules,
5895 5895 set options, define functions, etc.
5896 5896 suitable for different tasks and activate them in a very simple manner.
5897 5897 In order to avoid having to repeat all of your basic options (common things
5898 5898 that don't change such as your color preferences, for example), any profile
5899 5899 can include another configuration file.
5900 5900 The most common way to use profiles is then to have each one include your
5901 5901 basic
5902 5902 \family typewriter
5903 5903 ipythonrc
5904 5904 \family default
5905 5905 file as a starting point, and then add further customizations.
5906 5906 \layout Standard
5907 5907
5908 5908 In sections
5909 5909 \begin_inset LatexCommand \ref{sec:syntax-extensions}
5910 5910
5911 5911 \end_inset
5912 5912
5913 5913 and
5914 5914 \begin_inset LatexCommand \ref{sec:Gnuplot}
5915 5915
5916 5916 \end_inset
5917 5917
5918 5918 we discuss some particular profiles which come as part of the standard
5919 5919 IPython distribution.
5920 5920 You may also look in your
5921 5921 \family typewriter
5922 5922 IPYTHONDIR
5923 5923 \family default
5924 5924 directory, any file whose name begins with
5925 5925 \family typewriter
5926 5926 ipythonrc-
5927 5927 \family default
5928 5928 is a profile.
5929 5929 You can use those as examples for further customizations to suit your own
5930 5930 needs.
5931 5931 \layout Section
5932 5932
5933 5933
5934 5934 \begin_inset OptArg
5935 5935 collapsed false
5936 5936
5937 5937 \layout Standard
5938 5938
5939 5939 IPython as default...
5940 5940 \end_inset
5941 5941
5942 5942 IPython as your default Python environment
5943 5943 \layout Standard
5944 5944
5945 5945 Python honors the environment variable
5946 5946 \family typewriter
5947 5947 PYTHONSTARTUP
5948 5948 \family default
5949 5949 and will execute at startup the file referenced by this variable.
5950 5950 If you put at the end of this file the following two lines of code:
5951 5951 \layout Standard
5952 5952
5953 5953
5954 5954 \family typewriter
5955 5955 import IPython
5956 5956 \newline
5957 5957 IPython.Shell.IPShell().mainloop(sys_exit=1)
5958 5958 \layout Standard
5959 5959
5960 5960 then IPython will be your working environment anytime you start Python.
5961 5961 The
5962 5962 \family typewriter
5963 5963 sys_exit=1
5964 5964 \family default
5965 5965 is needed to have IPython issue a call to
5966 5966 \family typewriter
5967 5967 sys.exit()
5968 5968 \family default
5969 5969 when it finishes, otherwise you'll be back at the normal Python '
5970 5970 \family typewriter
5971 5971 >>>
5972 5972 \family default
5973 5973 ' prompt
5974 5974 \begin_inset Foot
5975 5975 collapsed true
5976 5976
5977 5977 \layout Standard
5978 5978
5979 5979 Based on an idea by Holger Krekel.
5980 5980 \end_inset
5981 5981
5982 5982 .
5983 5983 \layout Standard
5984 5984
5985 5985 This is probably useful to developers who manage multiple Python versions
5986 5986 and don't want to have correspondingly multiple IPython versions.
5987 5987 Note that in this mode, there is no way to pass IPython any command-line
5988 5988 options, as those are trapped first by Python itself.
5989 5989 \layout Section
5990 5990
5991 5991
5992 5992 \begin_inset LatexCommand \label{sec:embed}
5993 5993
5994 5994 \end_inset
5995 5995
5996 5996 Embedding IPython
5997 5997 \layout Standard
5998 5998
5999 5999 It is possible to start an IPython instance
6000 6000 \emph on
6001 6001 inside
6002 6002 \emph default
6003 6003 your own Python programs.
6004 6004 This allows you to evaluate dynamically the state of your code, operate
6005 6005 with your variables, analyze them, etc.
6006 6006 Note however that any changes you make to values while in the shell do
6007 6007
6008 6008 \emph on
6009 6009 not
6010 6010 \emph default
6011 6011 propagate back to the running code, so it is safe to modify your values
6012 6012 because you won't break your code in bizarre ways by doing so.
6013 6013 \layout Standard
6014 6014
6015 6015 This feature allows you to easily have a fully functional python environment
6016 6016 for doing object introspection anywhere in your code with a simple function
6017 6017 call.
6018 6018 In some cases a simple print statement is enough, but if you need to do
6019 6019 more detailed analysis of a code fragment this feature can be very valuable.
6020 6020 \layout Standard
6021 6021
6022 6022 It can also be useful in scientific computing situations where it is common
6023 6023 to need to do some automatic, computationally intensive part and then stop
6024 6024 to look at data, plots, etc
6025 6025 \begin_inset Foot
6026 6026 collapsed true
6027 6027
6028 6028 \layout Standard
6029 6029
6030 6030 This functionality was inspired by IDL's combination of the
6031 6031 \family typewriter
6032 6032 stop
6033 6033 \family default
6034 6034 keyword and the
6035 6035 \family typewriter
6036 6036 .continue
6037 6037 \family default
6038 6038 executive command, which I have found very useful in the past, and by a
6039 6039 posting on comp.lang.python by cmkl <cmkleffner-AT-gmx.de> on Dec.
6040 6040 06/01 concerning similar uses of pyrepl.
6041 6041 \end_inset
6042 6042
6043 6043 .
6044 6044 Opening an IPython instance will give you full access to your data and
6045 6045 functions, and you can resume program execution once you are done with
6046 6046 the interactive part (perhaps to stop again later, as many times as needed).
6047 6047 \layout Standard
6048 6048
6049 6049 The following code snippet is the bare minimum you need to include in your
6050 6050 Python programs for this to work (detailed examples follow later):
6051 6051 \layout LyX-Code
6052 6052
6053 6053 from IPython.Shell import IPShellEmbed
6054 6054 \layout LyX-Code
6055 6055
6056 6056 ipshell = IPShellEmbed()
6057 6057 \layout LyX-Code
6058 6058
6059 6059 ipshell() # this call anywhere in your program will start IPython
6060 6060 \layout Standard
6061 6061
6062 6062 You can run embedded instances even in code which is itself being run at
6063 6063 the IPython interactive prompt with '
6064 6064 \family typewriter
6065 6065 %run\SpecialChar ~
6066 6066 <filename>
6067 6067 \family default
6068 6068 '.
6069 6069 Since it's easy to get lost as to where you are (in your top-level IPython
6070 6070 or in your embedded one), it's a good idea in such cases to set the in/out
6071 6071 prompts to something different for the embedded instances.
6072 6072 The code examples below illustrate this.
6073 6073 \layout Standard
6074 6074
6075 6075 You can also have multiple IPython instances in your program and open them
6076 6076 separately, for example with different options for data presentation.
6077 6077 If you close and open the same instance multiple times, its prompt counters
6078 6078 simply continue from each execution to the next.
6079 6079 \layout Standard
6080 6080
6081 6081 Please look at the docstrings in the
6082 6082 \family typewriter
6083 6083 Shell.py
6084 6084 \family default
6085 6085 module for more details on the use of this system.
6086 6086 \layout Standard
6087 6087
6088 6088 The following sample file illustrating how to use the embedding functionality
6089 6089 is provided in the examples directory as
6090 6090 \family typewriter
6091 6091 example-embed.py
6092 6092 \family default
6093 6093 .
6094 6094 It should be fairly self-explanatory:
6095 6095 \layout Standard
6096 6096
6097 6097
6098 6098 \begin_inset ERT
6099 6099 status Open
6100 6100
6101 6101 \layout Standard
6102 6102
6103 6103 \backslash
6104 6104 codelist{examples/example-embed.py}
6105 6105 \end_inset
6106 6106
6107 6107
6108 6108 \layout Standard
6109 6109
6110 6110 Once you understand how the system functions, you can use the following
6111 6111 code fragments in your programs which are ready for cut and paste:
6112 6112 \layout Standard
6113 6113
6114 6114
6115 6115 \begin_inset ERT
6116 6116 status Open
6117 6117
6118 6118 \layout Standard
6119 6119
6120 6120 \backslash
6121 6121 codelist{examples/example-embed-short.py}
6122 6122 \end_inset
6123 6123
6124 6124
6125 6125 \layout Section
6126 6126
6127 6127
6128 6128 \begin_inset LatexCommand \label{sec:using-pdb}
6129 6129
6130 6130 \end_inset
6131 6131
6132 6132 Using the Python debugger (
6133 6133 \family typewriter
6134 6134 pdb
6135 6135 \family default
6136 6136 )
6137 6137 \layout Subsection
6138 6138
6139 6139 Running entire programs via
6140 6140 \family typewriter
6141 6141 pdb
6142 6142 \layout Standard
6143 6143
6144 6144
6145 6145 \family typewriter
6146 6146 pdb
6147 6147 \family default
6148 6148 , the Python debugger, is a powerful interactive debugger which allows you
6149 6149 to step through code, set breakpoints, watch variables, etc.
6150 6150 IPython makes it very easy to start any script under the control of
6151 6151 \family typewriter
6152 6152 pdb
6153 6153 \family default
6154 6154 , regardless of whether you have wrapped it into a
6155 6155 \family typewriter
6156 6156 `main()'
6157 6157 \family default
6158 6158 function or not.
6159 6159 For this, simply type
6160 6160 \family typewriter
6161 6161 `%run -d myscript'
6162 6162 \family default
6163 6163 at an IPython prompt.
6164 6164 See the
6165 6165 \family typewriter
6166 6166 %run
6167 6167 \family default
6168 6168 command's documentation (via
6169 6169 \family typewriter
6170 6170 `%run?'
6171 6171 \family default
6172 6172 or in Sec.\SpecialChar ~
6173 6173
6174 6174 \begin_inset LatexCommand \ref{sec:magic}
6175 6175
6176 6176 \end_inset
6177 6177
6178 6178 ) for more details, including how to control where
6179 6179 \family typewriter
6180 6180 pdb
6181 6181 \family default
6182 6182 will stop execution first.
6183 6183 \layout Standard
6184 6184
6185 6185 For more information on the use of the
6186 6186 \family typewriter
6187 6187 pdb
6188 6188 \family default
6189 6189 debugger, read the included
6190 6190 \family typewriter
6191 6191 pdb.doc
6192 6192 \family default
6193 6193 file (part of the standard Python distribution).
6194 6194 On a stock Linux system it is located at
6195 6195 \family typewriter
6196 6196 /usr/lib/python2.3/pdb.doc
6197 6197 \family default
6198 6198 , but the easiest way to read it is by using the
6199 6199 \family typewriter
6200 6200 help()
6201 6201 \family default
6202 6202 function of the
6203 6203 \family typewriter
6204 6204 pdb
6205 6205 \family default
6206 6206 module as follows (in an IPython prompt):
6207 6207 \layout Standard
6208 6208
6209 6209
6210 6210 \family typewriter
6211 6211 In [1]: import pdb
6212 6212 \newline
6213 6213 In [2]: pdb.help()
6214 6214 \layout Standard
6215 6215
6216 6216 This will load the
6217 6217 \family typewriter
6218 6218 pdb.doc
6219 6219 \family default
6220 6220 document in a file viewer for you automatically.
6221 6221 \layout Subsection
6222 6222
6223 6223 Automatic invocation of
6224 6224 \family typewriter
6225 6225 pdb
6226 6226 \family default
6227 6227 on exceptions
6228 6228 \layout Standard
6229 6229
6230 6230 IPython, if started with the
6231 6231 \family typewriter
6232 6232 -pdb
6233 6233 \family default
6234 6234 option (or if the option is set in your rc file) can call the Python
6235 6235 \family typewriter
6236 6236 pdb
6237 6237 \family default
6238 6238 debugger every time your code triggers an uncaught exception
6239 6239 \begin_inset Foot
6240 6240 collapsed true
6241 6241
6242 6242 \layout Standard
6243 6243
6244 6244 Many thanks to Christopher Hart for the request which prompted adding this
6245 6245 feature to IPython.
6246 6246 \end_inset
6247 6247
6248 6248 .
6249 6249 This feature can also be toggled at any time with the
6250 6250 \family typewriter
6251 6251 %pdb
6252 6252 \family default
6253 6253 magic command.
6254 6254 This can be extremely useful in order to find the origin of subtle bugs,
6255 6255 because
6256 6256 \family typewriter
6257 6257 pdb
6258 6258 \family default
6259 6259 opens up at the point in your code which triggered the exception, and while
6260 6260 your program is at this point `dead', all the data is still available and
6261 6261 you can walk up and down the stack frame and understand the origin of the
6262 6262 problem.
6263 6263 \layout Standard
6264 6264
6265 6265 Furthermore, you can use these debugging facilities both with the embedded
6266 6266 IPython mode and without IPython at all.
6267 6267 For an embedded shell (see sec.
6268 6268
6269 6269 \begin_inset LatexCommand \ref{sec:embed}
6270 6270
6271 6271 \end_inset
6272 6272
6273 6273 ), simply call the constructor with
6274 6274 \family typewriter
6275 6275 `-pdb'
6276 6276 \family default
6277 6277 in the argument string and automatically
6278 6278 \family typewriter
6279 6279 pdb
6280 6280 \family default
6281 6281 will be called if an uncaught exception is triggered by your code.
6282 6282
6283 6283 \layout Standard
6284 6284
6285 6285 For stand-alone use of the feature in your programs which do not use IPython
6286 6286 at all, put the following lines toward the top of your `main' routine:
6287 6287 \layout Standard
6288 6288 \align left
6289 6289
6290 6290 \family typewriter
6291 6291 import sys,IPython.ultraTB
6292 6292 \newline
6293 6293 sys.excepthook = IPython.ultraTB.FormattedTB(mode=`Verbose', color_scheme=`Linux',
6294 6294 call_pdb=1)
6295 6295 \layout Standard
6296 6296
6297 6297 The
6298 6298 \family typewriter
6299 6299 mode
6300 6300 \family default
6301 6301 keyword can be either
6302 6302 \family typewriter
6303 6303 `Verbose'
6304 6304 \family default
6305 6305 or
6306 6306 \family typewriter
6307 6307 `Plain'
6308 6308 \family default
6309 6309 , giving either very detailed or normal tracebacks respectively.
6310 6310 The
6311 6311 \family typewriter
6312 6312 color_scheme
6313 6313 \family default
6314 6314 keyword can be one of
6315 6315 \family typewriter
6316 6316 `NoColor'
6317 6317 \family default
6318 6318 ,
6319 6319 \family typewriter
6320 6320 `Linux'
6321 6321 \family default
6322 6322 (default) or
6323 6323 \family typewriter
6324 6324 `LightBG'
6325 6325 \family default
6326 6326 .
6327 6327 These are the same options which can be set in IPython with
6328 6328 \family typewriter
6329 6329 -colors
6330 6330 \family default
6331 6331 and
6332 6332 \family typewriter
6333 6333 -xmode
6334 6334 \family default
6335 6335 .
6336 6336 \layout Standard
6337 6337
6338 6338 This will give any of your programs detailed, colored tracebacks with automatic
6339 6339 invocation of
6340 6340 \family typewriter
6341 6341 pdb
6342 6342 \family default
6343 6343 .
6344 6344 \layout Section
6345 6345
6346 6346
6347 6347 \begin_inset LatexCommand \label{sec:syntax-extensions}
6348 6348
6349 6349 \end_inset
6350 6350
6351 6351 Extensions for syntax processing
6352 6352 \layout Standard
6353 6353
6354 6354 This isn't for the faint of heart, because the potential for breaking things
6355 6355 is quite high.
6356 6356 But it can be a very powerful and useful feature.
6357 6357 In a nutshell, you can redefine the way IPython processes the user input
6358 6358 line to accept new, special extensions to the syntax without needing to
6359 6359 change any of IPython's own code.
6360 6360 \layout Standard
6361 6361
6362 6362 In the
6363 6363 \family typewriter
6364 6364 IPython/Extensions
6365 6365 \family default
6366 6366 directory you will find some examples supplied, which we will briefly describe
6367 6367 now.
6368 6368 These can be used `as is' (and both provide very useful functionality),
6369 6369 or you can use them as a starting point for writing your own extensions.
6370 6370 \layout Subsection
6371 6371
6372 6372 Pasting of code starting with
6373 6373 \family typewriter
6374 6374 `>>>
6375 6375 \family default
6376 6376 ' or
6377 6377 \family typewriter
6378 6378 `...
6379 6379
6380 6380 \family default
6381 6381 '
6382 6382 \layout Standard
6383 6383
6384 6384 In the python tutorial it is common to find code examples which have been
6385 6385 taken from real python sessions.
6386 6386 The problem with those is that all the lines begin with either
6387 6387 \family typewriter
6388 6388 `>>>
6389 6389 \family default
6390 6390 ' or
6391 6391 \family typewriter
6392 6392 `...
6393 6393
6394 6394 \family default
6395 6395 ', which makes it impossible to paste them all at once.
6396 6396 One must instead do a line by line manual copying, carefully removing the
6397 6397 leading extraneous characters.
6398 6398 \layout Standard
6399 6399
6400 6400 This extension identifies those starting characters and removes them from
6401 6401 the input automatically, so that one can paste multi-line examples directly
6402 6402 into IPython, saving a lot of time.
6403 6403 Please look at the file
6404 6404 \family typewriter
6405 6405 InterpreterPasteInput.py
6406 6406 \family default
6407 6407 in the
6408 6408 \family typewriter
6409 6409 IPython/Extensions
6410 6410 \family default
6411 6411 directory for details on how this is done.
6412 6412 \layout Standard
6413 6413
6414 6414 IPython comes with a special profile enabling this feature, called
6415 6415 \family typewriter
6416 6416 tutorial
6417 6417 \family default
6418 6418 \emph on
6419 6419 .
6420 6420
6421 6421 \emph default
6422 6422 Simply start IPython via
6423 6423 \family typewriter
6424 6424 `ipython\SpecialChar ~
6425 6425 -p\SpecialChar ~
6426 6426 tutorial'
6427 6427 \family default
6428 6428 and the feature will be available.
6429 6429 In a normal IPython session you can activate the feature by importing the
6430 6430 corresponding module with:
6431 6431 \newline
6432 6432
6433 6433 \family typewriter
6434 6434 In [1]: import IPython.Extensions.InterpreterPasteInput
6435 6435 \layout Standard
6436 6436
6437 6437 The following is a 'screenshot' of how things work when this extension is
6438 6438 on, copying an example from the standard tutorial:
6439 6439 \layout Standard
6440 6440
6441 6441
6442 6442 \family typewriter
6443 6443 IPython profile: tutorial
6444 6444 \newline
6445 6445 \SpecialChar ~
6446 6446
6447 6447 \newline
6448 6448 *** Pasting of code with ">>>" or "..." has been enabled.
6449 6449 \newline
6450 6450 \SpecialChar ~
6451 6451
6452 6452 \newline
6453 6453 In [1]: >>> def fib2(n): # return Fibonacci series up to n
6454 6454 \newline
6455 6455
6456 6456 \begin_inset ERT
6457 6457 status Collapsed
6458 6458
6459 6459 \layout Standard
6460 6460
6461 6461 \backslash
6462 6462 hspace*{0mm}
6463 6463 \end_inset
6464 6464
6465 6465 \SpecialChar ~
6466 6466 \SpecialChar ~
6467 6467 ...: ...\SpecialChar ~
6468 6468 \SpecialChar ~
6469 6469 \SpecialChar ~
6470 6470 \SpecialChar ~
6471 6471 """Return a list containing the Fibonacci series up to n."""
6472 6472 \newline
6473 6473
6474 6474 \begin_inset ERT
6475 6475 status Collapsed
6476 6476
6477 6477 \layout Standard
6478 6478
6479 6479 \backslash
6480 6480 hspace*{0mm}
6481 6481 \end_inset
6482 6482
6483 6483 \SpecialChar ~
6484 6484 \SpecialChar ~
6485 6485 ...: ...\SpecialChar ~
6486 6486 \SpecialChar ~
6487 6487 \SpecialChar ~
6488 6488 \SpecialChar ~
6489 6489 result = []
6490 6490 \newline
6491 6491
6492 6492 \begin_inset ERT
6493 6493 status Collapsed
6494 6494
6495 6495 \layout Standard
6496 6496
6497 6497 \backslash
6498 6498 hspace*{0mm}
6499 6499 \end_inset
6500 6500
6501 6501 \SpecialChar ~
6502 6502 \SpecialChar ~
6503 6503 ...: ...\SpecialChar ~
6504 6504 \SpecialChar ~
6505 6505 \SpecialChar ~
6506 6506 \SpecialChar ~
6507 6507 a, b = 0, 1
6508 6508 \newline
6509 6509
6510 6510 \begin_inset ERT
6511 6511 status Collapsed
6512 6512
6513 6513 \layout Standard
6514 6514
6515 6515 \backslash
6516 6516 hspace*{0mm}
6517 6517 \end_inset
6518 6518
6519 6519 \SpecialChar ~
6520 6520 \SpecialChar ~
6521 6521 ...: ...\SpecialChar ~
6522 6522 \SpecialChar ~
6523 6523 \SpecialChar ~
6524 6524 \SpecialChar ~
6525 6525 while b < n:
6526 6526 \newline
6527 6527
6528 6528 \begin_inset ERT
6529 6529 status Collapsed
6530 6530
6531 6531 \layout Standard
6532 6532
6533 6533 \backslash
6534 6534 hspace*{0mm}
6535 6535 \end_inset
6536 6536
6537 6537 \SpecialChar ~
6538 6538 \SpecialChar ~
6539 6539 ...: ...\SpecialChar ~
6540 6540 \SpecialChar ~
6541 6541 \SpecialChar ~
6542 6542 \SpecialChar ~
6543 6543 \SpecialChar ~
6544 6544 \SpecialChar ~
6545 6545 \SpecialChar ~
6546 6546 \SpecialChar ~
6547 6547 result.append(b)\SpecialChar ~
6548 6548 \SpecialChar ~
6549 6549 \SpecialChar ~
6550 6550 # see below
6551 6551 \newline
6552 6552
6553 6553 \begin_inset ERT
6554 6554 status Collapsed
6555 6555
6556 6556 \layout Standard
6557 6557
6558 6558 \backslash
6559 6559 hspace*{0mm}
6560 6560 \end_inset
6561 6561
6562 6562 \SpecialChar ~
6563 6563 \SpecialChar ~
6564 6564 ...: ...\SpecialChar ~
6565 6565 \SpecialChar ~
6566 6566 \SpecialChar ~
6567 6567 \SpecialChar ~
6568 6568 \SpecialChar ~
6569 6569 \SpecialChar ~
6570 6570 \SpecialChar ~
6571 6571 \SpecialChar ~
6572 6572 a, b = b, a+b
6573 6573 \newline
6574 6574
6575 6575 \begin_inset ERT
6576 6576 status Collapsed
6577 6577
6578 6578 \layout Standard
6579 6579
6580 6580 \backslash
6581 6581 hspace*{0mm}
6582 6582 \end_inset
6583 6583
6584 6584 \SpecialChar ~
6585 6585 \SpecialChar ~
6586 6586 ...: ...\SpecialChar ~
6587 6587 \SpecialChar ~
6588 6588 \SpecialChar ~
6589 6589 \SpecialChar ~
6590 6590 return result
6591 6591 \newline
6592 6592
6593 6593 \begin_inset ERT
6594 6594 status Collapsed
6595 6595
6596 6596 \layout Standard
6597 6597
6598 6598 \backslash
6599 6599 hspace*{0mm}
6600 6600 \end_inset
6601 6601
6602 6602 \SpecialChar ~
6603 6603 \SpecialChar ~
6604 6604 ...:
6605 6605 \newline
6606 6606 \SpecialChar ~
6607 6607
6608 6608 \newline
6609 6609 In [2]: fib2(10)
6610 6610 \newline
6611 6611 Out[2]: [1, 1, 2, 3, 5, 8]
6612 6612 \layout Standard
6613 6613
6614 6614 Note that as currently written, this extension does
6615 6615 \emph on
6616 6616 not
6617 6617 \emph default
6618 6618 recognize IPython's prompts for pasting.
6619 6619 Those are more complicated, since the user can change them very easily,
6620 6620 they involve numbers and can vary in length.
6621 6621 One could however extract all the relevant information from the IPython
6622 6622 instance and build an appropriate regular expression.
6623 6623 This is left as an exercise for the reader.
6624 6624 \layout Subsection
6625 6625
6626 6626 Input of physical quantities with units
6627 6627 \layout Standard
6628 6628
6629 6629 The module
6630 6630 \family typewriter
6631 6631 PhysicalQInput
6632 6632 \family default
6633 6633 allows a simplified form of input for physical quantities with units.
6634 6634 This file is meant to be used in conjunction with the
6635 6635 \family typewriter
6636 6636 PhysicalQInteractive
6637 6637 \family default
6638 6638 module (in the same directory) and
6639 6639 \family typewriter
6640 6640 Physics.PhysicalQuantities
6641 6641 \family default
6642 6642 from Konrad Hinsen's ScientificPython (
6643 6643 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/hinsen/scientific.html}
6644 6644
6645 6645 \end_inset
6646 6646
6647 6647 ).
6648 6648 \layout Standard
6649 6649
6650 6650 The
6651 6651 \family typewriter
6652 6652 Physics.PhysicalQuantities
6653 6653 \family default
6654 6654 module defines
6655 6655 \family typewriter
6656 6656 PhysicalQuantity
6657 6657 \family default
6658 6658 objects, but these must be declared as instances of a class.
6659 6659 For example, to define
6660 6660 \family typewriter
6661 6661 v
6662 6662 \family default
6663 6663 as a velocity of 3\SpecialChar ~
6664 6664 m/s, normally you would write:
6665 6665 \family typewriter
6666 6666
6667 6667 \newline
6668 6668 In [1]: v = PhysicalQuantity(3,'m/s')
6669 6669 \layout Standard
6670 6670
6671 6671 Using the
6672 6672 \family typewriter
6673 6673 PhysicalQ_Input
6674 6674 \family default
6675 6675 extension this can be input instead as:
6676 6676 \family typewriter
6677 6677
6678 6678 \newline
6679 6679 In [1]: v = 3 m/s
6680 6680 \family default
6681 6681
6682 6682 \newline
6683 6683 which is much more convenient for interactive use (even though it is blatantly
6684 6684 invalid Python syntax).
6685 6685 \layout Standard
6686 6686
6687 6687 The
6688 6688 \family typewriter
6689 6689 physics
6690 6690 \family default
6691 6691 profile supplied with IPython (enabled via
6692 6692 \family typewriter
6693 6693 'ipython -p physics'
6694 6694 \family default
6695 6695 ) uses these extensions, which you can also activate with:
6696 6696 \layout Standard
6697 6697
6698 6698
6699 6699 \family typewriter
6700 6700 from math import * # math MUST be imported BEFORE PhysicalQInteractive
6701 6701 \newline
6702 6702 from IPython.Extensions.PhysicalQInteractive import *
6703 6703 \newline
6704 6704 import IPython.Extensions.PhysicalQInput
6705 6705 \layout Section
6706 6706
6707 6707 IPython as a system shell
6708 6708 \layout Standard
6709 6709
6710 6710 IPython ships with a special profile called
6711 6711 \family typewriter
6712 6712 pysh
6713 6713 \family default
6714 6714 , which you can activate at the command line as
6715 6715 \family typewriter
6716 6716 `ipython -p pysh'
6717 6717 \family default
6718 6718 .
6719 6719 This loads
6720 6720 \family typewriter
6721 6721 InterpreterExec
6722 6722 \family default
6723 6723 , along with some additional facilities and a prompt customized for filesystem
6724 6724 navigation.
6725 6725 \layout Standard
6726 6726
6727 6727 Note that this does
6728 6728 \emph on
6729 6729 not
6730 6730 \emph default
6731 6731 make IPython a full-fledged system shell.
6732 6732 In particular, it has no job control, so if you type Ctrl-Z (under Unix),
6733 6733 you'll suspend pysh itself, not the process you just started.
6734 6734
6735 6735 \layout Standard
6736 6736
6737 6737 What the shell profile allows you to do is to use the convenient and powerful
6738 6738 syntax of Python to do quick scripting at the command line.
6739 6739 Below we describe some of its features.
6740 6740 \layout Subsection
6741 6741
6742 6742 Aliases
6743 6743 \layout Standard
6744 6744
6745 6745 All of your
6746 6746 \family typewriter
6747 6747 $PATH
6748 6748 \family default
6749 6749 has been loaded as IPython aliases, so you should be able to type any normal
6750 6750 system command and have it executed.
6751 6751 See
6752 6752 \family typewriter
6753 6753 %alias?
6754 6754 \family default
6755 6755 and
6756 6756 \family typewriter
6757 6757 %unalias?
6758 6758 \family default
6759 6759 for details on the alias facilities.
6760 6760 See also
6761 6761 \family typewriter
6762 6762 %rehash?
6763 6763 \family default
6764 6764 and
6765 6765 \family typewriter
6766 6766 %rehashx?
6767 6767 \family default
6768 6768 for details on the mechanism used to load
6769 6769 \family typewriter
6770 6770 $PATH
6771 6771 \family default
6772 6772 .
6773 6773 \layout Subsection
6774 6774
6775 6775 Special syntax
6776 6776 \layout Standard
6777 6777
6778 6778 Any lines which begin with
6779 6779 \family typewriter
6780 6780 `~'
6781 6781 \family default
6782 6782 ,
6783 6783 \family typewriter
6784 6784 `/'
6785 6785 \family default
6786 6786 and
6787 6787 \family typewriter
6788 6788 `.'
6789 6789 \family default
6790 6790 will be executed as shell commands instead of as Python code.
6791 6791 The special escapes below are also recognized.
6792 6792
6793 6793 \family typewriter
6794 6794 !cmd
6795 6795 \family default
6796 6796 is valid in single or multi-line input, all others are only valid in single-lin
6797 6797 e input:
6798 6798 \layout Description
6799 6799
6800 6800
6801 6801 \family typewriter
6802 6802 !cmd
6803 6803 \family default
6804 6804 pass `cmd' directly to the shell
6805 6805 \layout Description
6806 6806
6807 6807
6808 6808 \family typewriter
6809 6809 !!cmd
6810 6810 \family default
6811 6811 execute `cmd' and return output as a list (split on `
6812 6812 \backslash
6813 6813 n')
6814 6814 \layout Description
6815 6815
6816 6816
6817 6817 \family typewriter
6818 6818 $var=cmd
6819 6819 \family default
6820 6820 capture output of cmd into var, as a string
6821 6821 \layout Description
6822 6822
6823 6823
6824 6824 \family typewriter
6825 6825 $$var=cmd
6826 6826 \family default
6827 6827 capture output of cmd into var, as a list (split on `
6828 6828 \backslash
6829 6829 n')
6830 6830 \layout Standard
6831 6831
6832 6832 The
6833 6833 \family typewriter
6834 6834 $
6835 6835 \family default
6836 6836 /
6837 6837 \family typewriter
6838 6838 $$
6839 6839 \family default
6840 6840 syntaxes make Python variables from system output, which you can later
6841 6841 use for further scripting.
6842 6842 The converse is also possible: when executing an alias or calling to the
6843 6843 system via
6844 6844 \family typewriter
6845 6845 !
6846 6846 \family default
6847 6847 /
6848 6848 \family typewriter
6849 6849 !!
6850 6850 \family default
6851 6851 , you can expand any python variable or expression by prepending it with
6852 6852
6853 6853 \family typewriter
6854 6854 $
6855 6855 \family default
6856 6856 .
6857 6857 Full details of the allowed syntax can be found in Python's PEP 215.
6858 6858 \layout Standard
6859 6859
6860 6860 A few brief examples will illustrate these (note that the indentation below
6861 6861 may be incorrectly displayed):
6862 6862 \layout Standard
6863 6863
6864 6864
6865 6865 \family typewriter
6866 6866 fperez[~/test]|3> !ls *s.py
6867 6867 \newline
6868 6868 scopes.py strings.py
6869 6869 \layout Standard
6870 6870
6871 6871 ls is an internal alias, so there's no need to use
6872 6872 \family typewriter
6873 6873 !
6874 6874 \family default
6875 6875 :
6876 6876 \layout Standard
6877 6877
6878 6878
6879 6879 \family typewriter
6880 6880 fperez[~/test]|4> ls *s.py
6881 6881 \newline
6882 6882 scopes.py* strings.py
6883 6883 \layout Standard
6884 6884
6885 6885 !!ls will return the output into a Python variable:
6886 6886 \layout Standard
6887 6887
6888 6888
6889 6889 \family typewriter
6890 6890 fperez[~/test]|5> !!ls *s.py
6891 6891 \newline
6892 6892
6893 6893 \begin_inset ERT
6894 6894 status Collapsed
6895 6895
6896 6896 \layout Standard
6897 6897
6898 6898 \backslash
6899 6899 hspace*{0mm}
6900 6900 \end_inset
6901 6901
6902 6902 \SpecialChar ~
6903 6903 \SpecialChar ~
6904 6904 \SpecialChar ~
6905 6905 \SpecialChar ~
6906 6906 \SpecialChar ~
6907 6907 \SpecialChar ~
6908 6908 \SpecialChar ~
6909 6909 \SpecialChar ~
6910 6910 \SpecialChar ~
6911 6911 \SpecialChar ~
6912 6912 \SpecialChar ~
6913 6913 \SpecialChar ~
6914 6914 \SpecialChar ~
6915 6915 \SpecialChar ~
6916 6916 <5> ['scopes.py', 'strings.py']
6917 6917 \newline
6918 6918 fperez[~/test]|6> print _5
6919 6919 \newline
6920 6920 ['scopes.py', 'strings.py']
6921 6921 \layout Standard
6922 6922
6923 6923
6924 6924 \family typewriter
6925 6925 $
6926 6926 \family default
6927 6927 and
6928 6928 \family typewriter
6929 6929 $$
6930 6930 \family default
6931 6931 allow direct capture to named variables:
6932 6932 \layout Standard
6933 6933
6934 6934
6935 6935 \family typewriter
6936 6936 fperez[~/test]|7> $astr = ls *s.py
6937 6937 \newline
6938 6938 fperez[~/test]|8> astr
6939 6939 \newline
6940 6940
6941 6941 \begin_inset ERT
6942 6942 status Collapsed
6943 6943
6944 6944 \layout Standard
6945 6945
6946 6946 \backslash
6947 6947 hspace*{0mm}
6948 6948 \end_inset
6949 6949
6950 6950 \SpecialChar ~
6951 6951 \SpecialChar ~
6952 6952 \SpecialChar ~
6953 6953 \SpecialChar ~
6954 6954 \SpecialChar ~
6955 6955 \SpecialChar ~
6956 6956 \SpecialChar ~
6957 6957 \SpecialChar ~
6958 6958 \SpecialChar ~
6959 6959 \SpecialChar ~
6960 6960 \SpecialChar ~
6961 6961 \SpecialChar ~
6962 6962 \SpecialChar ~
6963 6963 \SpecialChar ~
6964 6964 <8> 'scopes.py
6965 6965 \backslash
6966 6966 nstrings.py'
6967 6967 \layout Standard
6968 6968
6969 6969
6970 6970 \family typewriter
6971 6971 fperez[~/test]|9> $$alist = ls *s.py
6972 6972 \newline
6973 6973 fperez[~/test]|10> alist
6974 6974 \newline
6975 6975
6976 6976 \begin_inset ERT
6977 6977 status Collapsed
6978 6978
6979 6979 \layout Standard
6980 6980
6981 6981 \backslash
6982 6982 hspace*{0mm}
6983 6983 \end_inset
6984 6984
6985 6985 \SpecialChar ~
6986 6986 \SpecialChar ~
6987 6987 \SpecialChar ~
6988 6988 \SpecialChar ~
6989 6989 \SpecialChar ~
6990 6990 \SpecialChar ~
6991 6991 \SpecialChar ~
6992 6992 \SpecialChar ~
6993 6993 \SpecialChar ~
6994 6994 \SpecialChar ~
6995 6995 \SpecialChar ~
6996 6996 \SpecialChar ~
6997 6997 \SpecialChar ~
6998 6998 \SpecialChar ~
6999 6999 <10> ['scopes.py', 'strings.py']
7000 7000 \layout Standard
7001 7001
7002 7002 alist is now a normal python list you can loop over.
7003 7003 Using
7004 7004 \family typewriter
7005 7005 $
7006 7006 \family default
7007 7007 will expand back the python values when alias calls are made:
7008 7008 \layout Standard
7009 7009
7010 7010
7011 7011 \family typewriter
7012 7012 fperez[~/test]|11> for f in alist:
7013 7013 \newline
7014 7014
7015 7015 \begin_inset ERT
7016 7016 status Collapsed
7017 7017
7018 7018 \layout Standard
7019 7019
7020 7020 \backslash
7021 7021 hspace*{0mm}
7022 7022 \end_inset
7023 7023
7024 7024 \SpecialChar ~
7025 7025 \SpecialChar ~
7026 7026 \SpecialChar ~
7027 7027 \SpecialChar ~
7028 7028 \SpecialChar ~
7029 7029 \SpecialChar ~
7030 7030 \SpecialChar ~
7031 7031 \SpecialChar ~
7032 7032 \SpecialChar ~
7033 7033 \SpecialChar ~
7034 7034 \SpecialChar ~
7035 7035 \SpecialChar ~
7036 7036 \SpecialChar ~
7037 7037 \SpecialChar ~
7038 7038 |..> \SpecialChar ~
7039 7039 \SpecialChar ~
7040 7040 \SpecialChar ~
7041 7041 \SpecialChar ~
7042 7042 print 'file',f,
7043 7043 \newline
7044 7044
7045 7045 \begin_inset ERT
7046 7046 status Collapsed
7047 7047
7048 7048 \layout Standard
7049 7049
7050 7050 \backslash
7051 7051 hspace*{0mm}
7052 7052 \end_inset
7053 7053
7054 7054 \SpecialChar ~
7055 7055 \SpecialChar ~
7056 7056 \SpecialChar ~
7057 7057 \SpecialChar ~
7058 7058 \SpecialChar ~
7059 7059 \SpecialChar ~
7060 7060 \SpecialChar ~
7061 7061 \SpecialChar ~
7062 7062 \SpecialChar ~
7063 7063 \SpecialChar ~
7064 7064 \SpecialChar ~
7065 7065 \SpecialChar ~
7066 7066 \SpecialChar ~
7067 7067 \SpecialChar ~
7068 7068 |..> \SpecialChar ~
7069 7069 \SpecialChar ~
7070 7070 \SpecialChar ~
7071 7071 \SpecialChar ~
7072 7072 wc -l $f
7073 7073 \newline
7074 7074
7075 7075 \begin_inset ERT
7076 7076 status Collapsed
7077 7077
7078 7078 \layout Standard
7079 7079
7080 7080 \backslash
7081 7081 hspace*{0mm}
7082 7082 \end_inset
7083 7083
7084 7084 \SpecialChar ~
7085 7085 \SpecialChar ~
7086 7086 \SpecialChar ~
7087 7087 \SpecialChar ~
7088 7088 \SpecialChar ~
7089 7089 \SpecialChar ~
7090 7090 \SpecialChar ~
7091 7091 \SpecialChar ~
7092 7092 \SpecialChar ~
7093 7093 \SpecialChar ~
7094 7094 \SpecialChar ~
7095 7095 \SpecialChar ~
7096 7096 \SpecialChar ~
7097 7097 \SpecialChar ~
7098 7098 |..>
7099 7099 \newline
7100 7100 file scopes.py 13 scopes.py
7101 7101 \newline
7102 7102 file strings.py 4 strings.py
7103 7103 \layout Standard
7104 7104
7105 7105 Note that you may need to protect your variables with braces if you want
7106 7106 to append strings to their names.
7107 7107 To copy all files in alist to
7108 7108 \family typewriter
7109 7109 .bak
7110 7110 \family default
7111 7111 extensions, you must use:
7112 7112 \layout Standard
7113 7113
7114 7114
7115 7115 \family typewriter
7116 7116 fperez[~/test]|12> for f in alist:
7117 7117 \newline
7118 7118
7119 7119 \begin_inset ERT
7120 7120 status Collapsed
7121 7121
7122 7122 \layout Standard
7123 7123
7124 7124 \backslash
7125 7125 hspace*{0mm}
7126 7126 \end_inset
7127 7127
7128 7128 \SpecialChar ~
7129 7129 \SpecialChar ~
7130 7130 \SpecialChar ~
7131 7131 \SpecialChar ~
7132 7132 \SpecialChar ~
7133 7133 \SpecialChar ~
7134 7134 \SpecialChar ~
7135 7135 \SpecialChar ~
7136 7136 \SpecialChar ~
7137 7137 \SpecialChar ~
7138 7138 \SpecialChar ~
7139 7139 \SpecialChar ~
7140 7140 \SpecialChar ~
7141 7141 \SpecialChar ~
7142 7142 |..> \SpecialChar ~
7143 7143 \SpecialChar ~
7144 7144 \SpecialChar ~
7145 7145 \SpecialChar ~
7146 7146 cp $f ${f}.bak
7147 7147 \layout Standard
7148 7148
7149 7149 If you try using
7150 7150 \family typewriter
7151 7151 $f.bak
7152 7152 \family default
7153 7153 , you'll get an AttributeError exception saying that your string object
7154 7154 doesn't have a
7155 7155 \family typewriter
7156 7156 .bak
7157 7157 \family default
7158 7158 attribute.
7159 7159 This is because the
7160 7160 \family typewriter
7161 7161 $
7162 7162 \family default
7163 7163 expansion mechanism allows you to expand full Python expressions:
7164 7164 \layout Standard
7165 7165
7166 7166
7167 7167 \family typewriter
7168 7168 fperez[~/test]|13> echo "sys.platform is: $sys.platform"
7169 7169 \newline
7170 7170 sys.platform is: linux2
7171 7171 \layout Standard
7172 7172
7173 7173 IPython's input history handling is still active, which allows you to rerun
7174 7174 a single block of multi-line input by simply using exec:
7175 7175 \newline
7176 7176
7177 7177 \family typewriter
7178 7178 fperez[~/test]|14> $$alist = ls *.eps
7179 7179 \newline
7180 7180 fperez[~/test]|15> exec _i11
7181 7181 \newline
7182 7182 file image2.eps 921 image2.eps
7183 7183 \newline
7184 7184 file image.eps 921 image.eps
7185 7185 \layout Standard
7186 7186
7187 7187 While these are new special-case syntaxes, they are designed to allow very
7188 7188 efficient use of the shell with minimal typing.
7189 7189 At an interactive shell prompt, conciseness of expression wins over readability.
7190 7190 \layout Subsection
7191 7191
7192 7192 Useful functions and modules
7193 7193 \layout Standard
7194 7194
7195 7195 The os, sys and shutil modules from the Python standard library are automaticall
7196 7196 y loaded.
7197 7197 Some additional functions, useful for shell usage, are listed below.
7198 7198 You can request more help about them with `
7199 7199 \family typewriter
7200 7200 ?
7201 7201 \family default
7202 7202 '.
7203 7203 \layout Description
7204 7204
7205 7205
7206 7206 \family typewriter
7207 7207 shell
7208 7208 \family default
7209 7209 - execute a command in the underlying system shell
7210 7210 \layout Description
7211 7211
7212 7212
7213 7213 \family typewriter
7214 7214 system
7215 7215 \family default
7216 7216 - like
7217 7217 \family typewriter
7218 7218 shell()
7219 7219 \family default
7220 7220 , but return the exit status of the command
7221 7221 \layout Description
7222 7222
7223 7223
7224 7224 \family typewriter
7225 7225 sout
7226 7226 \family default
7227 7227 - capture the output of a command as a string
7228 7228 \layout Description
7229 7229
7230 7230
7231 7231 \family typewriter
7232 7232 lout
7233 7233 \family default
7234 7234 - capture the output of a command as a list (split on `
7235 7235 \backslash
7236 7236 n')
7237 7237 \layout Description
7238 7238
7239 7239
7240 7240 \family typewriter
7241 7241 getoutputerror
7242 7242 \family default
7243 7243 - capture (output,error) of a shell commandss
7244 7244 \layout Standard
7245 7245
7246 7246
7247 7247 \family typewriter
7248 7248 sout
7249 7249 \family default
7250 7250 /
7251 7251 \family typewriter
7252 7252 lout
7253 7253 \family default
7254 7254 are the functional equivalents of
7255 7255 \family typewriter
7256 7256 $
7257 7257 \family default
7258 7258 /
7259 7259 \family typewriter
7260 7260 $$
7261 7261 \family default
7262 7262 .
7263 7263 They are provided to allow you to capture system output in the middle of
7264 7264 true python code, function definitions, etc (where
7265 7265 \family typewriter
7266 7266 $
7267 7267 \family default
7268 7268 and
7269 7269 \family typewriter
7270 7270 $$
7271 7271 \family default
7272 7272 are invalid).
7273 7273 \layout Subsection
7274 7274
7275 7275 Directory management
7276 7276 \layout Standard
7277 7277
7278 7278 Since each command passed by pysh to the underlying system is executed in
7279 7279 a subshell which exits immediately, you can NOT use !cd to navigate the
7280 7280 filesystem.
7281 7281 \layout Standard
7282 7282
7283 7283 Pysh provides its own builtin
7284 7284 \family typewriter
7285 7285 `%cd
7286 7286 \family default
7287 7287 ' magic command to move in the filesystem (the
7288 7288 \family typewriter
7289 7289 %
7290 7290 \family default
7291 7291 is not required with automagic on).
7292 7292 It also maintains a list of visited directories (use
7293 7293 \family typewriter
7294 7294 %dhist
7295 7295 \family default
7296 7296 to see it) and allows direct switching to any of them.
7297 7297 Type
7298 7298 \family typewriter
7299 7299 `cd?
7300 7300 \family default
7301 7301 ' for more details.
7302 7302 \layout Standard
7303 7303
7304 7304
7305 7305 \family typewriter
7306 7306 %pushd
7307 7307 \family default
7308 7308 ,
7309 7309 \family typewriter
7310 7310 %popd
7311 7311 \family default
7312 7312 and
7313 7313 \family typewriter
7314 7314 %dirs
7315 7315 \family default
7316 7316 are provided for directory stack handling.
7317 7317 \layout Subsection
7318 7318
7319 7319 Prompt customization
7320 7320 \layout Standard
7321 7321
7322 7322 The supplied
7323 7323 \family typewriter
7324 7324 ipythonrc-pysh
7325 7325 \family default
7326 7326 profile comes with an example of a very colored and detailed prompt, mainly
7327 7327 to serve as an illustration.
7328 7328 The valid escape sequences, besides color names, are:
7329 7329 \layout Description
7330 7330
7331 7331
7332 7332 \backslash
7333 7333 # - Prompt number.
7334 7334 \layout Description
7335 7335
7336 7336
7337 7337 \backslash
7338 7338 D - Dots, as many as there are digits in
7339 7339 \backslash
7340 7340 # (so they align).
7341 7341 \layout Description
7342 7342
7343 7343
7344 7344 \backslash
7345 7345 w - Current working directory (cwd).
7346 7346 \layout Description
7347 7347
7348 7348
7349 7349 \backslash
7350 7350 W - Basename of current working directory.
7351 7351 \layout Description
7352 7352
7353 7353
7354 7354 \backslash
7355 7355 X
7356 7356 \emph on
7357 7357 N
7358 7358 \emph default
7359 7359 - Where
7360 7360 \emph on
7361 7361 N
7362 7362 \emph default
7363 7363 =0..5.
7364 7364 N terms of the cwd, with $HOME written as ~.
7365 7365 \layout Description
7366 7366
7367 7367
7368 7368 \backslash
7369 7369 Y
7370 7370 \emph on
7371 7371 N
7372 7372 \emph default
7373 7373 - Where
7374 7374 \emph on
7375 7375 N
7376 7376 \emph default
7377 7377 =0..5.
7378 7378 Like X
7379 7379 \emph on
7380 7380 N
7381 7381 \emph default
7382 7382 , but if ~ is term
7383 7383 \emph on
7384 7384 N
7385 7385 \emph default
7386 7386 +1 it's also shown.
7387 7387 \layout Description
7388 7388
7389 7389
7390 7390 \backslash
7391 7391 u - Username.
7392 7392 \layout Description
7393 7393
7394 7394
7395 7395 \backslash
7396 7396 H - Full hostname.
7397 7397 \layout Description
7398 7398
7399 7399
7400 7400 \backslash
7401 7401 h - Hostname up to first '.'
7402 7402 \layout Description
7403 7403
7404 7404
7405 7405 \backslash
7406 7406 $ - Root symbol ($ or #).
7407 7407
7408 7408 \layout Description
7409 7409
7410 7410
7411 7411 \backslash
7412 7412 t - Current time, in H:M:S format.
7413 7413 \layout Description
7414 7414
7415 7415
7416 7416 \backslash
7417 7417 v - IPython release version.
7418 7418
7419 7419 \layout Description
7420 7420
7421 7421
7422 7422 \backslash
7423 7423 n - Newline.
7424 7424
7425 7425 \layout Description
7426 7426
7427 7427
7428 7428 \backslash
7429 7429 r - Carriage return.
7430 7430
7431 7431 \layout Description
7432 7432
7433 7433
7434 7434 \backslash
7435 7435
7436 7436 \backslash
7437 7437 - An explicitly escaped '
7438 7438 \backslash
7439 7439 '.
7440 7440 \layout Standard
7441 7441
7442 7442 You can configure your prompt colors using any ANSI color escape.
7443 7443 Each color escape sets the color for any subsequent text, until another
7444 7444 escape comes in and changes things.
7445 7445 The valid color escapes are:
7446 7446 \layout Description
7447 7447
7448 7448
7449 7449 \backslash
7450 7450 C_Black
7451 7451 \layout Description
7452 7452
7453 7453
7454 7454 \backslash
7455 7455 C_Blue
7456 7456 \layout Description
7457 7457
7458 7458
7459 7459 \backslash
7460 7460 C_Brown
7461 7461 \layout Description
7462 7462
7463 7463
7464 7464 \backslash
7465 7465 C_Cyan
7466 7466 \layout Description
7467 7467
7468 7468
7469 7469 \backslash
7470 7470 C_DarkGray
7471 7471 \layout Description
7472 7472
7473 7473
7474 7474 \backslash
7475 7475 C_Green
7476 7476 \layout Description
7477 7477
7478 7478
7479 7479 \backslash
7480 7480 C_LightBlue
7481 7481 \layout Description
7482 7482
7483 7483
7484 7484 \backslash
7485 7485 C_LightCyan
7486 7486 \layout Description
7487 7487
7488 7488
7489 7489 \backslash
7490 7490 C_LightGray
7491 7491 \layout Description
7492 7492
7493 7493
7494 7494 \backslash
7495 7495 C_LightGreen
7496 7496 \layout Description
7497 7497
7498 7498
7499 7499 \backslash
7500 7500 C_LightPurple
7501 7501 \layout Description
7502 7502
7503 7503
7504 7504 \backslash
7505 7505 C_LightRed
7506 7506 \layout Description
7507 7507
7508 7508
7509 7509 \backslash
7510 7510 C_Purple
7511 7511 \layout Description
7512 7512
7513 7513
7514 7514 \backslash
7515 7515 C_Red
7516 7516 \layout Description
7517 7517
7518 7518
7519 7519 \backslash
7520 7520 C_White
7521 7521 \layout Description
7522 7522
7523 7523
7524 7524 \backslash
7525 7525 C_Yellow
7526 7526 \layout Description
7527 7527
7528 7528
7529 7529 \backslash
7530 7530 C_Normal Stop coloring, defaults to your terminal settings.
7531 7531 \layout Section
7532 7532
7533 7533
7534 7534 \begin_inset LatexCommand \label{sec:Threading-support}
7535 7535
7536 7536 \end_inset
7537 7537
7538 7538 Threading support
7539 7539 \layout Standard
7540 7540
7541 7541
7542 7542 \series bold
7543 7543 WARNING:
7544 7544 \series default
7545 7545 The threading support is still somewhat experimental, and it has only seen
7546 7546 reasonable testing under Linux.
7547 7547 Threaded code is particularly tricky to debug, and it tends to show extremely
7548 7548 platform-dependent behavior.
7549 7549 Since I only have access to Linux machines, I will have to rely on user's
7550 7550 experiences and assistance for this area of IPython to improve under other
7551 7551 platforms.
7552 7552 \layout Standard
7553 7553
7554 7554 IPython, via the
7555 7555 \family typewriter
7556 7556 -gthread
7557 7557 \family default
7558 7558 ,
7559 7559 \family typewriter
7560 7560 -qthread
7561 7561 \family default
7562 7562 and
7563 7563 \family typewriter
7564 7564 -wthread
7565 7565 \family default
7566 7566 options (described in Sec.\SpecialChar ~
7567 7567
7568 7568 \begin_inset LatexCommand \ref{sec:threading-opts}
7569 7569
7570 7570 \end_inset
7571 7571
7572 7572 ), can run in multithreaded mode to support pyGTK, Qt and WXPython applications
7573 7573 respectively.
7574 7574 These GUI toolkits need to control the python main loop of execution, so
7575 7575 under a normal Python interpreter, starting a pyGTK, Qt or WXPython application
7576 7576 will immediately freeze the shell.
7577 7577
7578 7578 \layout Standard
7579 7579
7580 7580 IPython, with one of these options (you can only use one at a time), separates
7581 7581 the graphical loop and IPython's code execution run into different threads.
7582 7582 This allows you to test interactively (with
7583 7583 \family typewriter
7584 7584 %run
7585 7585 \family default
7586 7586 , for example) your GUI code without blocking.
7587 7587 \layout Standard
7588 7588
7589 7589 A nice mini-tutorial on using IPython along with the Qt Designer application
7590 7590 is available at the SciPy wiki:
7591 7591 \begin_inset LatexCommand \htmlurl{http://www.scipy.org/wikis/topical_software/QtWithIPythonAndDesigner}
7592 7592
7593 7593 \end_inset
7594 7594
7595 7595 .
7596 7596 \layout Subsection
7597 7597
7598 7598 Tk issues
7599 7599 \layout Standard
7600 7600
7601 7601 As indicated in Sec.\SpecialChar ~
7602 7602
7603 7603 \begin_inset LatexCommand \ref{sec:threading-opts}
7604 7604
7605 7605 \end_inset
7606 7606
7607 7607 , a special
7608 7608 \family typewriter
7609 7609 -tk
7610 7610 \family default
7611 7611 option is provided to try and allow Tk graphical applications to coexist
7612 7612 interactively with WX, Qt or GTK ones.
7613 7613 Whether this works at all, however, is very platform and configuration
7614 7614 dependent.
7615 7615 Please experiment with simple test cases before committing to using this
7616 7616 combination of Tk and GTK/Qt/WX threading in a production environment.
7617 7617 \layout Subsection
7618 7618
7619 7619 Signals and Threads
7620 7620 \layout Standard
7621 7621
7622 7622 When any of the thread systems (GTK, Qt or WX) are active, either directly
7623 7623 or via
7624 7624 \family typewriter
7625 7625 -pylab
7626 7626 \family default
7627 7627 with a threaded backend, it is impossible to interrupt long-running Python
7628 7628 code via
7629 7629 \family typewriter
7630 7630 Ctrl-C
7631 7631 \family default
7632 7632 .
7633 7633 IPython can not pass the KeyboardInterrupt exception (or the underlying
7634 7634
7635 7635 \family typewriter
7636 7636 SIGINT
7637 7637 \family default
7638 7638 ) across threads, so any long-running process started from IPython will
7639 7639 run to completion, or will have to be killed via an external (OS-based)
7640 7640 mechanism.
7641 7641 \layout Standard
7642 7642
7643 7643 To the best of my knowledge, this limitation is imposed by the Python interprete
7644 7644 r itself, and it comes from the difficulty of writing portable signal/threaded
7645 7645 code.
7646 7646 If any user is an expert on this topic and can suggest a better solution,
7647 7647 I would love to hear about it.
7648 7648 In the IPython sources, look at the
7649 7649 \family typewriter
7650 7650 Shell.py
7651 7651 \family default
7652 7652 module, and in particular at the
7653 7653 \family typewriter
7654 7654 runcode()
7655 7655 \family default
7656 7656 method.
7657 7657
7658 7658 \layout Subsection
7659 7659
7660 7660 I/O pitfalls
7661 7661 \layout Standard
7662 7662
7663 7663 Be mindful that the Python interpreter switches between threads every
7664 7664 \begin_inset Formula $N$
7665 7665 \end_inset
7666 7666
7667 7667 bytecodes, where the default value as of Python\SpecialChar ~
7668 7668 2.3 is
7669 7669 \begin_inset Formula $N=100.$
7670 7670 \end_inset
7671 7671
7672 7672 This value can be read by using the
7673 7673 \family typewriter
7674 7674 sys.getcheckinterval()
7675 7675 \family default
7676 7676 function, and it can be reset via
7677 7677 \family typewriter
7678 7678 sys.setcheckinterval(
7679 7679 \emph on
7680 7680 N
7681 7681 \emph default
7682 7682 )
7683 7683 \family default
7684 7684 .
7685 7685 This switching of threads can cause subtly confusing effects if one of
7686 7686 your threads is doing file I/O.
7687 7687 In text mode, most systems only flush file buffers when they encounter
7688 7688 a
7689 7689 \family typewriter
7690 7690 `
7691 7691 \backslash
7692 7692 n'
7693 7693 \family default
7694 7694 .
7695 7695 An instruction as simple as
7696 7696 \family typewriter
7697 7697
7698 7698 \newline
7699 7699 \SpecialChar ~
7700 7700 \SpecialChar ~
7701 7701 print >> filehandle,
7702 7702 \begin_inset Quotes eld
7703 7703 \end_inset
7704 7704
7705 7705 hello world
7706 7706 \begin_inset Quotes erd
7707 7707 \end_inset
7708 7708
7709 7709
7710 7710 \family default
7711 7711
7712 7712 \newline
7713 7713 actually consists of several bytecodes, so it is possible that the newline
7714 7714 does not reach your file before the next thread switch.
7715 7715 Similarly, if you are writing to a file in binary mode, the file won't
7716 7716 be flushed until the buffer fills, and your other thread may see apparently
7717 7717 truncated files.
7718 7718
7719 7719 \layout Standard
7720 7720
7721 7721 For this reason, if you are using IPython's thread support and have (for
7722 7722 example) a GUI application which will read data generated by files written
7723 7723 to from the IPython thread, the safest approach is to open all of your
7724 7724 files in unbuffered mode (the third argument to the
7725 7725 \family typewriter
7726 7726 file/open
7727 7727 \family default
7728 7728 function is the buffering value):
7729 7729 \newline
7730 7730
7731 7731 \family typewriter
7732 7732 \SpecialChar ~
7733 7733 \SpecialChar ~
7734 7734 filehandle = open(filename,mode,0)
7735 7735 \layout Standard
7736 7736
7737 7737 This is obviously a brute force way of avoiding race conditions with the
7738 7738 file buffering.
7739 7739 If you want to do it cleanly, and you have a resource which is being shared
7740 7740 by the interactive IPython loop and your GUI thread, you should really
7741 7741 handle it with thread locking and syncrhonization properties.
7742 7742 The Python documentation discusses these.
7743 7743 \layout Section
7744 7744
7745 7745
7746 7746 \begin_inset LatexCommand \label{sec:interactive-demos}
7747 7747
7748 7748 \end_inset
7749 7749
7750 7750 Interactive demos with IPython
7751 7751 \layout Standard
7752 7752
7753 IPython ships with XXX
7753 IPython ships with a basic system for running scripts interactively in sections,
7754 useful when presenting code to audiences.
7755 A few tags embedded in comments (so that the script remains valid Python
7756 code) divide a file into separate blocks, and the demo can be run one block
7757 at a time, with IPython printing (with syntax highlighting) the block before
7758 executing it, and returning to the interactive prompt after each block.
7759 The interactive namespace is updated after each block is run with the contents
7760 of the demo's namespace.
7761 \layout Standard
7762
7763 This allows you to show a piece of code, run it and then execute interactively
7764 commands based on the variables just created.
7765 Once you want to continue, you simply execute the next block of the demo.
7766 The following listing shows the markup necessary for dividing a script
7767 into sections for execution as a demo.
7754 7768 \layout Standard
7755 7769
7756 7770
7757 7771 \begin_inset ERT
7758 7772 status Open
7759 7773
7760 7774 \layout Standard
7761 7775
7762 7776 \backslash
7763 7777 codelist{examples/example-demo.py}
7764 7778 \end_inset
7765 7779
7766 7780
7781 \layout Standard
7782
7783 In order to run a file as a demo, you must first make a
7784 \family typewriter
7785 Demo
7786 \family default
7787 object out of it.
7788 If the file is named
7789 \family typewriter
7790 myscript.py
7791 \family default
7792 , the following code will make a demo:
7793 \layout LyX-Code
7794
7795 from IPython.demo import Demo
7796 \layout LyX-Code
7797
7798 mydemo = Demo('myscript.py')
7799 \layout Standard
7800
7801 This creates the
7802 \family typewriter
7803 mydemo
7804 \family default
7805 object, whose blocks you run one at a time by simply calling the object
7806 with no arguments.
7807 If you have autocall active in IPython (the default), all you need to do
7808 is type
7809 \layout LyX-Code
7810
7811 mydemo
7812 \layout Standard
7813
7814 and IPython will call it, executing each block.
7815 Demo objects can be restarted, you can move forward or back skipping blocks,
7816 re-execute the last block, etc.
7817 Simply use the Tab key on a demo object to see its methods, and call
7818 \family typewriter
7819 `?'
7820 \family default
7821 on them to see their docstrings for more usage details.
7822 In addition, the
7823 \family typewriter
7824 demo
7825 \family default
7826 module itself contains a comprehensive docstring, which you can access
7827 via
7828 \layout LyX-Code
7829
7830 from IPython import demo
7831 \layout LyX-Code
7832
7833 demo?
7834 \layout Standard
7835
7836
7837 \series bold
7838 Limitations:
7839 \series default
7840 It is important to note that these demos are limited to fairly simple uses.
7841 In particular, you can
7842 \emph on
7843 not
7844 \emph default
7845 put division marks in indented code (loops, if statements, function definitions
7846 , etc.) Supporting something like this would basically require tracking the
7847 internal execution state of the Python interpreter, so only top-level divisions
7848 are allowed.
7849 If you want to be able to open an IPython instance at an arbitrary point
7850 in a program, you can use IPython's embedding facilities, described in
7851 detail in Sec\SpecialChar \@.
7852 \SpecialChar ~
7853
7854 \begin_inset LatexCommand \ref{sec:embed}
7855
7856 \end_inset
7857
7858 .
7767 7859 \layout Section
7768 7860
7769 7861
7770 7862 \begin_inset LatexCommand \label{sec:matplotlib-support}
7771 7863
7772 7864 \end_inset
7773 7865
7774 7866 Plotting with
7775 7867 \family typewriter
7776 7868 matplotlib
7777 7869 \family default
7778 7870
7779 7871 \layout Standard
7780 7872
7781 7873 The matplotlib library (
7782 7874 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
7783 7875
7784 7876 \end_inset
7785 7877
7786 7878 ) provides high quality 2D plotting for Python.
7787 7879 Matplotlib can produce plots on screen using a variety of GUI toolkits,
7788 7880 including Tk, GTK and WXPython.
7789 7881 It also provides a number of commands useful for scientific computing,
7790 7882 all with a syntax compatible with that of the popular Matlab program.
7791 7883 \layout Standard
7792 7884
7793 7885 IPython accepts the special option
7794 7886 \family typewriter
7795 7887 -pylab
7796 7888 \family default
7797 7889 (Sec.\SpecialChar ~
7798 7890
7799 7891 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
7800 7892
7801 7893 \end_inset
7802 7894
7803 7895 ).
7804 7896 This configures it to support matplotlib, honoring the settings in the
7805 7897
7806 7898 \family typewriter
7807 7899 .matplotlibrc
7808 7900 \family default
7809 7901 file.
7810 7902 IPython will detect the user's choice of matplotlib GUI backend, and automatica
7811 7903 lly select the proper threading model to prevent blocking.
7812 7904 It also sets matplotlib in interactive mode and modifies
7813 7905 \family typewriter
7814 7906 %run
7815 7907 \family default
7816 7908 slightly, so that any matplotlib-based script can be executed using
7817 7909 \family typewriter
7818 7910 %run
7819 7911 \family default
7820 7912 and the final
7821 7913 \family typewriter
7822 7914 show()
7823 7915 \family default
7824 7916 command does not block the interactive shell.
7825 7917 \layout Standard
7826 7918
7827 7919 The
7828 7920 \family typewriter
7829 7921 -pylab
7830 7922 \family default
7831 7923 option must be given first in order for IPython to configure its threading
7832 7924 mode.
7833 7925 However, you can still issue other options afterwards.
7834 7926 This allows you to have a matplotlib-based environment customized with
7835 7927 additional modules using the standard IPython profile mechanism (Sec.\SpecialChar ~
7836 7928
7837 7929 \begin_inset LatexCommand \ref{sec:profiles}
7838 7930
7839 7931 \end_inset
7840 7932
7841 7933 ): ``
7842 7934 \family typewriter
7843 7935 ipython -pylab -p myprofile
7844 7936 \family default
7845 7937 '' will load the profile defined in
7846 7938 \family typewriter
7847 7939 ipythonrc-myprofile
7848 7940 \family default
7849 7941 after configuring matplotlib.
7850 7942 \layout Section
7851 7943
7852 7944
7853 7945 \begin_inset LatexCommand \label{sec:Gnuplot}
7854 7946
7855 7947 \end_inset
7856 7948
7857 7949 Plotting with
7858 7950 \family typewriter
7859 7951 Gnuplot
7860 7952 \layout Standard
7861 7953
7862 7954 Through the magic extension system described in sec.
7863 7955
7864 7956 \begin_inset LatexCommand \ref{sec:magic}
7865 7957
7866 7958 \end_inset
7867 7959
7868 7960 , IPython incorporates a mechanism for conveniently interfacing with the
7869 7961 Gnuplot system (
7870 7962 \begin_inset LatexCommand \htmlurl{http://www.gnuplot.info}
7871 7963
7872 7964 \end_inset
7873 7965
7874 7966 ).
7875 7967 Gnuplot is a very complete 2D and 3D plotting package available for many
7876 7968 operating systems and commonly included in modern Linux distributions.
7877 7969
7878 7970 \layout Standard
7879 7971
7880 7972 Besides having Gnuplot installed, this functionality requires the
7881 7973 \family typewriter
7882 7974 Gnuplot.py
7883 7975 \family default
7884 7976 module for interfacing python with Gnuplot.
7885 7977 It can be downloaded from:
7886 7978 \begin_inset LatexCommand \htmlurl{http://gnuplot-py.sourceforge.net}
7887 7979
7888 7980 \end_inset
7889 7981
7890 7982 .
7891 7983 \layout Subsection
7892 7984
7893 7985 Proper Gnuplot configuration
7894 7986 \layout Standard
7895 7987
7896 7988 As of version 4.0, Gnuplot has excellent mouse and interactive keyboard support.
7897 7989 However, as of
7898 7990 \family typewriter
7899 7991 Gnuplot.py
7900 7992 \family default
7901 7993 version 1.7, a new option was added to communicate between Python and Gnuplot
7902 7994 via FIFOs (pipes).
7903 7995 This mechanism, while fast, also breaks the mouse system.
7904 7996 You must therefore set the variable
7905 7997 \family typewriter
7906 7998 prefer_fifo_data
7907 7999 \family default
7908 8000 to
7909 8001 \family typewriter
7910 8002 0
7911 8003 \family default
7912 8004 in file
7913 8005 \family typewriter
7914 8006 gp_unix.py
7915 8007 \family default
7916 8008 if you wish to keep the interactive mouse and keyboard features working
7917 8009 properly (
7918 8010 \family typewriter
7919 8011 prefer_inline_data
7920 8012 \family default
7921 8013 also must be
7922 8014 \family typewriter
7923 8015 0
7924 8016 \family default
7925 8017 , but this is the default so unless you've changed it manually you should
7926 8018 be fine).
7927 8019 \layout Standard
7928 8020
7929 8021 'Out of the box', Gnuplot is configured with a rather poor set of size,
7930 8022 color and linewidth choices which make the graphs fairly hard to read on
7931 8023 modern high-resolution displays (although they work fine on old 640x480
7932 8024 ones).
7933 8025 Below is a section of my
7934 8026 \family typewriter
7935 8027 .Xdefaults
7936 8028 \family default
7937 8029 file which I use for having a more convenient Gnuplot setup.
7938 8030 Remember to load it by running
7939 8031 \family typewriter
7940 8032 `xrdb .Xdefaults`
7941 8033 \family default
7942 8034 :
7943 8035 \layout Standard
7944 8036
7945 8037
7946 8038 \family typewriter
7947 8039 !******************************************************************
7948 8040 \newline
7949 8041 ! gnuplot options
7950 8042 \newline
7951 8043 ! modify this for a convenient window size
7952 8044 \newline
7953 8045 gnuplot*geometry: 780x580
7954 8046 \layout Standard
7955 8047
7956 8048
7957 8049 \family typewriter
7958 8050 ! on-screen font (not for PostScript)
7959 8051 \newline
7960 8052 gnuplot*font: -misc-fixed-bold-r-normal--15-120-100-100-c-90-iso8859-1
7961 8053 \layout Standard
7962 8054
7963 8055
7964 8056 \family typewriter
7965 8057 ! color options
7966 8058 \newline
7967 8059 gnuplot*background: black
7968 8060 \newline
7969 8061 gnuplot*textColor: white
7970 8062 \newline
7971 8063 gnuplot*borderColor: white
7972 8064 \newline
7973 8065 gnuplot*axisColor: white
7974 8066 \newline
7975 8067 gnuplot*line1Color: red
7976 8068 \newline
7977 8069 gnuplot*line2Color: green
7978 8070 \newline
7979 8071 gnuplot*line3Color: blue
7980 8072 \newline
7981 8073 gnuplot*line4Color: magenta
7982 8074 \newline
7983 8075 gnuplot*line5Color: cyan
7984 8076 \newline
7985 8077 gnuplot*line6Color: sienna
7986 8078 \newline
7987 8079 gnuplot*line7Color: orange
7988 8080 \newline
7989 8081 gnuplot*line8Color: coral
7990 8082 \layout Standard
7991 8083
7992 8084
7993 8085 \family typewriter
7994 8086 ! multiplicative factor for point styles
7995 8087 \newline
7996 8088 gnuplot*pointsize: 2
7997 8089 \layout Standard
7998 8090
7999 8091
8000 8092 \family typewriter
8001 8093 ! line width options (in pixels)
8002 8094 \newline
8003 8095 gnuplot*borderWidth: 2
8004 8096 \newline
8005 8097 gnuplot*axisWidth: 2
8006 8098 \newline
8007 8099 gnuplot*line1Width: 2
8008 8100 \newline
8009 8101 gnuplot*line2Width: 2
8010 8102 \newline
8011 8103 gnuplot*line3Width: 2
8012 8104 \newline
8013 8105 gnuplot*line4Width: 2
8014 8106 \newline
8015 8107 gnuplot*line5Width: 2
8016 8108 \newline
8017 8109 gnuplot*line6Width: 2
8018 8110 \newline
8019 8111 gnuplot*line7Width: 2
8020 8112 \newline
8021 8113 gnuplot*line8Width: 2
8022 8114 \layout Subsection
8023 8115
8024 8116 The
8025 8117 \family typewriter
8026 8118 IPython.GnuplotRuntime
8027 8119 \family default
8028 8120 module
8029 8121 \layout Standard
8030 8122
8031 8123 IPython includes a module called
8032 8124 \family typewriter
8033 8125 Gnuplot2.py
8034 8126 \family default
8035 8127 which extends and improves the default
8036 8128 \family typewriter
8037 8129 Gnuplot
8038 8130 \family default
8039 8131 .
8040 8132 \family typewriter
8041 8133 py
8042 8134 \family default
8043 8135 (which it still relies upon).
8044 8136 For example, the new
8045 8137 \family typewriter
8046 8138 plot
8047 8139 \family default
8048 8140 function adds several improvements to the original making it more convenient
8049 8141 for interactive use, and
8050 8142 \family typewriter
8051 8143 hardcopy
8052 8144 \family default
8053 8145 fixes a bug in the original which under some circumstances blocks the creation
8054 8146 of PostScript output.
8055 8147 \layout Standard
8056 8148
8057 8149 For scripting use,
8058 8150 \family typewriter
8059 8151 GnuplotRuntime.py
8060 8152 \family default
8061 8153 is provided, which wraps
8062 8154 \family typewriter
8063 8155 Gnuplot2.py
8064 8156 \family default
8065 8157 and creates a series of global aliases.
8066 8158 These make it easy to control Gnuplot plotting jobs through the Python
8067 8159 language.
8068 8160 \layout Standard
8069 8161
8070 8162 Below is some example code which illustrates how to configure Gnuplot inside
8071 8163 your own programs but have it available for further interactive use through
8072 8164 an embedded IPython instance.
8073 8165 Simply run this file at a system prompt.
8074 8166 This file is provided as
8075 8167 \family typewriter
8076 8168 example-gnuplot.py
8077 8169 \family default
8078 8170 in the examples directory:
8079 8171 \layout Standard
8080 8172
8081 8173
8082 8174 \begin_inset ERT
8083 8175 status Open
8084 8176
8085 8177 \layout Standard
8086 8178
8087 8179 \backslash
8088 8180 codelist{examples/example-gnuplot.py}
8089 8181 \end_inset
8090 8182
8091 8183
8092 8184 \layout Subsection
8093 8185
8094 8186 The
8095 8187 \family typewriter
8096 8188 numeric
8097 8189 \family default
8098 8190 profile: a scientific computing environment
8099 8191 \layout Standard
8100 8192
8101 8193 The
8102 8194 \family typewriter
8103 8195 numeric
8104 8196 \family default
8105 8197 IPython profile, which you can activate with
8106 8198 \family typewriter
8107 8199 `ipython -p numeric
8108 8200 \family default
8109 8201 ' will automatically load the IPython Gnuplot extensions (plus Numeric and
8110 8202 other useful things for numerical computing), contained in the
8111 8203 \family typewriter
8112 8204 IPython.GnuplotInteractive
8113 8205 \family default
8114 8206 module.
8115 8207 This will create the globals
8116 8208 \family typewriter
8117 8209 Gnuplot
8118 8210 \family default
8119 8211 (an alias to the improved Gnuplot2 module),
8120 8212 \family typewriter
8121 8213 gp
8122 8214 \family default
8123 8215 (a Gnuplot active instance), the new magic commands
8124 8216 \family typewriter
8125 8217 %gpc
8126 8218 \family default
8127 8219 and
8128 8220 \family typewriter
8129 8221 %gp_set_instance
8130 8222 \family default
8131 8223 and several other convenient globals.
8132 8224 Type
8133 8225 \family typewriter
8134 8226 gphelp()
8135 8227 \family default
8136 8228 for further details.
8137 8229 \layout Standard
8138 8230
8139 8231 This should turn IPython into a convenient environment for numerical computing,
8140 8232 with all the functions in the NumPy library and the Gnuplot facilities
8141 8233 for plotting.
8142 8234 Further improvements can be obtained by loading the SciPy libraries for
8143 8235 scientific computing, available at
8144 8236 \begin_inset LatexCommand \htmlurl{http://scipy.org}
8145 8237
8146 8238 \end_inset
8147 8239
8148 8240 .
8149 8241 \layout Standard
8150 8242
8151 8243 If you are in the middle of a working session with numerical objects and
8152 8244 need to plot them but you didn't start the
8153 8245 \family typewriter
8154 8246 numeric
8155 8247 \family default
8156 8248 profile, you can load these extensions at any time by typing
8157 8249 \newline
8158 8250
8159 8251 \family typewriter
8160 8252 from IPython.GnuplotInteractive import *
8161 8253 \newline
8162 8254
8163 8255 \family default
8164 8256 at the IPython prompt.
8165 8257 This will allow you to keep your objects intact and start using Gnuplot
8166 8258 to view them.
8167 8259 \layout Section
8168 8260
8169 8261 Reporting bugs
8170 8262 \layout Subsection*
8171 8263
8172 8264 Automatic crash reports
8173 8265 \layout Standard
8174 8266
8175 8267 Ideally, IPython itself shouldn't crash.
8176 8268 It will catch exceptions produced by you, but bugs in its internals will
8177 8269 still crash it.
8178 8270 \layout Standard
8179 8271
8180 8272 In such a situation, IPython will leave a file named
8181 8273 \family typewriter
8182 8274 IPython_crash_report.txt
8183 8275 \family default
8184 8276 in your IPYTHONDIR directory (that way if crashes happen several times
8185 8277 it won't litter many directories, the post-mortem file is always located
8186 8278 in the same place and new occurrences just overwrite the previous one).
8187 8279 If you can mail this file to the developers (see sec.
8188 8280
8189 8281 \begin_inset LatexCommand \ref{sec:credits}
8190 8282
8191 8283 \end_inset
8192 8284
8193 8285 for names and addresses), it will help us
8194 8286 \emph on
8195 8287 a lot
8196 8288 \emph default
8197 8289 in understanding the cause of the problem and fixing it sooner.
8198 8290 \layout Subsection*
8199 8291
8200 8292 The bug tracker
8201 8293 \layout Standard
8202 8294
8203 8295 IPython also has an online bug-tracker, located at
8204 8296 \begin_inset LatexCommand \htmlurl{http://www.scipy.net/roundup/ipython}
8205 8297
8206 8298 \end_inset
8207 8299
8208 8300 .
8209 8301 In addition to mailing the developers, it would be a good idea to file
8210 8302 a bug report here.
8211 8303 This will ensure that the issue is properly followed to conclusion.
8212 8304 \layout Standard
8213 8305
8214 8306 You can also use this bug tracker to file feature requests.
8215 8307 \layout Section
8216 8308
8217 8309 Brief history
8218 8310 \layout Subsection
8219 8311
8220 8312 Origins
8221 8313 \layout Standard
8222 8314
8223 8315 The current IPython system grew out of the following three projects:
8224 8316 \layout List
8225 8317 \labelwidthstring 00.00.0000
8226 8318
8227 8319 ipython by Fernando PΓ©rez.
8228 8320 I was working on adding Mathematica-type prompts and a flexible configuration
8229 8321 system (something better than
8230 8322 \family typewriter
8231 8323 $PYTHONSTARTUP
8232 8324 \family default
8233 8325 ) to the standard Python interactive interpreter.
8234 8326 \layout List
8235 8327 \labelwidthstring 00.00.0000
8236 8328
8237 8329 IPP by Janko Hauser.
8238 8330 Very well organized, great usability.
8239 8331 Had an old help system.
8240 8332 IPP was used as the `container' code into which I added the functionality
8241 8333 from ipython and LazyPython.
8242 8334 \layout List
8243 8335 \labelwidthstring 00.00.0000
8244 8336
8245 8337 LazyPython by Nathan Gray.
8246 8338 Simple but
8247 8339 \emph on
8248 8340 very
8249 8341 \emph default
8250 8342 powerful.
8251 8343 The quick syntax (auto parens, auto quotes) and verbose/colored tracebacks
8252 8344 were all taken from here.
8253 8345 \layout Standard
8254 8346
8255 8347 When I found out (see sec.
8256 8348
8257 8349 \begin_inset LatexCommand \ref{figgins}
8258 8350
8259 8351 \end_inset
8260 8352
8261 8353 ) about IPP and LazyPython I tried to join all three into a unified system.
8262 8354 I thought this could provide a very nice working environment, both for
8263 8355 regular programming and scientific computing: shell-like features, IDL/Matlab
8264 8356 numerics, Mathematica-type prompt history and great object introspection
8265 8357 and help facilities.
8266 8358 I think it worked reasonably well, though it was a lot more work than I
8267 8359 had initially planned.
8268 8360 \layout Subsection
8269 8361
8270 8362 Current status
8271 8363 \layout Standard
8272 8364
8273 8365 The above listed features work, and quite well for the most part.
8274 8366 But until a major internal restructuring is done (see below), only bug
8275 8367 fixing will be done, no other features will be added (unless very minor
8276 8368 and well localized in the cleaner parts of the code).
8277 8369 \layout Standard
8278 8370
8279 8371 IPython consists of some 12000 lines of pure python code, of which roughly
8280 8372 50% are fairly clean.
8281 8373 The other 50% are fragile, messy code which needs a massive restructuring
8282 8374 before any further major work is done.
8283 8375 Even the messy code is fairly well documented though, and most of the problems
8284 8376 in the (non-existent) class design are well pointed to by a PyChecker run.
8285 8377 So the rewriting work isn't that bad, it will just be time-consuming.
8286 8378 \layout Subsection
8287 8379
8288 8380 Future
8289 8381 \layout Standard
8290 8382
8291 8383 See the separate
8292 8384 \family typewriter
8293 8385 new_design
8294 8386 \family default
8295 8387 document for details.
8296 8388 Ultimately, I would like to see IPython become part of the standard Python
8297 8389 distribution as a `big brother with batteries' to the standard Python interacti
8298 8390 ve interpreter.
8299 8391 But that will never happen with the current state of the code, so all contribut
8300 8392 ions are welcome.
8301 8393 \layout Section
8302 8394
8303 8395 License
8304 8396 \layout Standard
8305 8397
8306 8398 IPython is released under the terms of the BSD license, whose general form
8307 8399 can be found at:
8308 8400 \begin_inset LatexCommand \htmlurl{http://www.opensource.org/licenses/bsd-license.php}
8309 8401
8310 8402 \end_inset
8311 8403
8312 8404 .
8313 8405 The full text of the IPython license is reproduced below:
8314 8406 \layout Quote
8315 8407
8316 8408
8317 8409 \family typewriter
8318 8410 \size small
8319 8411 IPython is released under a BSD-type license.
8320 8412 \layout Quote
8321 8413
8322 8414
8323 8415 \family typewriter
8324 8416 \size small
8325 8417 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez <fperez@colorado.edu>.
8326 8418 \layout Quote
8327 8419
8328 8420
8329 8421 \family typewriter
8330 8422 \size small
8331 8423 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
8332 8424 \newline
8333 8425 Nathaniel Gray <n8gray@caltech.edu>.
8334 8426 \layout Quote
8335 8427
8336 8428
8337 8429 \family typewriter
8338 8430 \size small
8339 8431 All rights reserved.
8340 8432 \layout Quote
8341 8433
8342 8434
8343 8435 \family typewriter
8344 8436 \size small
8345 8437 Redistribution and use in source and binary forms, with or without modification,
8346 8438 are permitted provided that the following conditions are met:
8347 8439 \layout Quote
8348 8440
8349 8441
8350 8442 \family typewriter
8351 8443 \size small
8352 8444 a.
8353 8445 Redistributions of source code must retain the above copyright notice,
8354 8446 this list of conditions and the following disclaimer.
8355 8447 \layout Quote
8356 8448
8357 8449
8358 8450 \family typewriter
8359 8451 \size small
8360 8452 b.
8361 8453 Redistributions in binary form must reproduce the above copyright notice,
8362 8454 this list of conditions and the following disclaimer in the documentation
8363 8455 and/or other materials provided with the distribution.
8364 8456 \layout Quote
8365 8457
8366 8458
8367 8459 \family typewriter
8368 8460 \size small
8369 8461 c.
8370 8462 Neither the name of the copyright holders nor the names of any contributors
8371 8463 to this software may be used to endorse or promote products derived from
8372 8464 this software without specific prior written permission.
8373 8465 \layout Quote
8374 8466
8375 8467
8376 8468 \family typewriter
8377 8469 \size small
8378 8470 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
8379 8471 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8380 8472 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
8381 8473 PURPOSE ARE DISCLAIMED.
8382 8474 IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8383 8475 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
8384 8476 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
8385 8477 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
8386 8478 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8387 8479 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8388 8480 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8389 8481
8390 8482 \layout Standard
8391 8483
8392 8484 Individual authors are the holders of the copyright for their code and are
8393 8485 listed in each file.
8394 8486 \layout Standard
8395 8487
8396 8488 Some files (
8397 8489 \family typewriter
8398 8490 DPyGetOpt.py
8399 8491 \family default
8400 8492 , for example) may be licensed under different conditions.
8401 8493 Ultimately each file indicates clearly the conditions under which its author/au
8402 8494 thors have decided to publish the code.
8403 8495 \layout Standard
8404 8496
8405 8497 Versions of IPython up to and including 0.6.3 were released under the GNU
8406 8498 Lesser General Public License (LGPL), available at
8407 8499 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/copyleft/lesser.html}
8408 8500
8409 8501 \end_inset
8410 8502
8411 8503 .
8412 8504 \layout Section
8413 8505
8414 8506
8415 8507 \begin_inset LatexCommand \label{sec:credits}
8416 8508
8417 8509 \end_inset
8418 8510
8419 8511 Credits
8420 8512 \layout Standard
8421 8513
8422 8514 IPython is mainly developed by Fernando PΓ©rez
8423 8515 \family typewriter
8424 8516 <fperez@colorado.edu>
8425 8517 \family default
8426 8518 , but the project was born from mixing in Fernando's code with the IPP project
8427 8519 by Janko Hauser
8428 8520 \family typewriter
8429 8521 <jhauser-AT-zscout.de>
8430 8522 \family default
8431 8523 and LazyPython by Nathan Gray
8432 8524 \family typewriter
8433 8525 <n8gray-AT-caltech.edu>
8434 8526 \family default
8435 8527 .
8436 8528 For all IPython-related requests, please contact Fernando.
8437 8529
8438 8530 \layout Standard
8439 8531
8440 8532 As of late 2005, the following developers have joined the core team:
8441 8533 \layout List
8442 8534 \labelwidthstring 00.00.0000
8443 8535
8444 8536 Robert\SpecialChar ~
8445 8537 Kern
8446 8538 \family typewriter
8447 8539 <rkern-AT-enthought.com>
8448 8540 \family default
8449 8541 : co-mentored the 2005 Google Summer of Code project to develop python interacti
8450 8542 ve notebooks (XML documents) and graphical interface.
8451 8543 This project was awarded to the students Tzanko Matev
8452 8544 \family typewriter
8453 8545 <tsanko-AT-gmail.com>
8454 8546 \family default
8455 8547 and Toni Alatalo
8456 8548 \family typewriter
8457 8549 <antont-AT-an.org>
8458 8550 \layout List
8459 8551 \labelwidthstring 00.00.0000
8460 8552
8461 8553 Brian\SpecialChar ~
8462 8554 Granger
8463 8555 \family typewriter
8464 8556 <bgranger-AT-scu.edu>
8465 8557 \family default
8466 8558 : extending IPython to allow support for interactive parallel computing.
8467 8559 \layout Standard
8468 8560
8469 8561 User or development help should be requested via the IPython mailing lists:
8470 8562 \layout Description
8471 8563
8472 8564 User\SpecialChar ~
8473 8565 list:
8474 8566 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-user}
8475 8567
8476 8568 \end_inset
8477 8569
8478 8570
8479 8571 \layout Description
8480 8572
8481 8573 Developer's\SpecialChar ~
8482 8574 list:
8483 8575 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-dev}
8484 8576
8485 8577 \end_inset
8486 8578
8487 8579
8488 8580 \layout Standard
8489 8581
8490 8582 The IPython project is also very grateful to
8491 8583 \begin_inset Foot
8492 8584 collapsed true
8493 8585
8494 8586 \layout Standard
8495 8587
8496 8588 I've mangled email addresses to reduce spam, since the IPython manuals can
8497 8589 be accessed online.
8498 8590 \end_inset
8499 8591
8500 8592 :
8501 8593 \layout Standard
8502 8594
8503 8595 Bill Bumgarner
8504 8596 \family typewriter
8505 8597 <bbum-AT-friday.com>
8506 8598 \family default
8507 8599 : for providing the DPyGetOpt module which gives very powerful and convenient
8508 8600 handling of command-line options (light years ahead of what Python 2.1.1's
8509 8601 getopt module does).
8510 8602 \layout Standard
8511 8603
8512 8604 Ka-Ping Yee
8513 8605 \family typewriter
8514 8606 <ping-AT-lfw.org>
8515 8607 \family default
8516 8608 : for providing the Itpl module for convenient and powerful string interpolation
8517 8609 with a much nicer syntax than formatting through the '%' operator.
8518 8610 \layout Standard
8519 8611
8520 8612 Arnd BΓ€cker
8521 8613 \family typewriter
8522 8614 <baecker-AT-physik.tu-dresden.de>
8523 8615 \family default
8524 8616 : for his many very useful suggestions and comments, and lots of help with
8525 8617 testing and documentation checking.
8526 8618 Many of IPython's newer features are a result of discussions with him (bugs
8527 8619 are still my fault, not his).
8528 8620 \layout Standard
8529 8621
8530 8622 Obviously Guido van\SpecialChar ~
8531 8623 Rossum and the whole Python development team, that goes
8532 8624 without saying.
8533 8625 \layout Standard
8534 8626
8535 8627 IPython's website is generously hosted at
8536 8628 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
8537 8629
8538 8630 \end_inset
8539 8631
8540 8632 by Enthought (
8541 8633 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
8542 8634
8543 8635 \end_inset
8544 8636
8545 8637 ).
8546 8638 I am very grateful to them and all of the SciPy team for their contribution.
8547 8639 \layout Standard
8548 8640
8549 8641
8550 8642 \begin_inset LatexCommand \label{figgins}
8551 8643
8552 8644 \end_inset
8553 8645
8554 8646 Fernando would also like to thank Stephen Figgins
8555 8647 \family typewriter
8556 8648 <fig-AT-monitor.net>
8557 8649 \family default
8558 8650 , an O'Reilly Python editor.
8559 8651 His Oct/11/2001 article about IPP and LazyPython, was what got this project
8560 8652 started.
8561 8653 You can read it at:
8562 8654 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html}
8563 8655
8564 8656 \end_inset
8565 8657
8566 8658 .
8567 8659 \layout Standard
8568 8660
8569 8661 And last but not least, all the kind IPython users who have emailed new
8570 8662 code, bug reports, fixes, comments and ideas.
8571 8663 A brief list follows, please let me know if I have ommitted your name by
8572 8664 accident:
8573 8665 \layout List
8574 8666 \labelwidthstring 00.00.0000
8575 8667
8576 8668 Jack\SpecialChar ~
8577 8669 Moffit
8578 8670 \family typewriter
8579 8671 <jack-AT-xiph.org>
8580 8672 \family default
8581 8673 Bug fixes, including the infamous color problem.
8582 8674 This bug alone caused many lost hours and frustration, many thanks to him
8583 8675 for the fix.
8584 8676 I've always been a fan of Ogg & friends, now I have one more reason to
8585 8677 like these folks.
8586 8678 \newline
8587 8679 Jack is also contributing with Debian packaging and many other things.
8588 8680 \layout List
8589 8681 \labelwidthstring 00.00.0000
8590 8682
8591 8683 Alexander\SpecialChar ~
8592 8684 Schmolck
8593 8685 \family typewriter
8594 8686 <a.schmolck-AT-gmx.net>
8595 8687 \family default
8596 8688 Emacs work, bug reports, bug fixes, ideas, lots more.
8597 8689 The ipython.el mode for (X)Emacs is Alex's code, providing full support
8598 8690 for IPython under (X)Emacs.
8599 8691 \layout List
8600 8692 \labelwidthstring 00.00.0000
8601 8693
8602 8694 Andrea\SpecialChar ~
8603 8695 Riciputi
8604 8696 \family typewriter
8605 8697 <andrea.riciputi-AT-libero.it>
8606 8698 \family default
8607 8699 Mac OSX information, Fink package management.
8608 8700 \layout List
8609 8701 \labelwidthstring 00.00.0000
8610 8702
8611 8703 Gary\SpecialChar ~
8612 8704 Bishop
8613 8705 \family typewriter
8614 8706 <gb-AT-cs.unc.edu>
8615 8707 \family default
8616 8708 Bug reports, and patches to work around the exception handling idiosyncracies
8617 8709 of WxPython.
8618 8710 Readline and color support for Windows.
8619 8711 \layout List
8620 8712 \labelwidthstring 00.00.0000
8621 8713
8622 8714 Jeffrey\SpecialChar ~
8623 8715 Collins
8624 8716 \family typewriter
8625 8717 <Jeff.Collins-AT-vexcel.com>
8626 8718 \family default
8627 8719 Bug reports.
8628 8720 Much improved readline support, including fixes for Python 2.3.
8629 8721 \layout List
8630 8722 \labelwidthstring 00.00.0000
8631 8723
8632 8724 Dryice\SpecialChar ~
8633 8725 Liu
8634 8726 \family typewriter
8635 8727 <dryice-AT-liu.com.cn>
8636 8728 \family default
8637 8729 FreeBSD port.
8638 8730 \layout List
8639 8731 \labelwidthstring 00.00.0000
8640 8732
8641 8733 Mike\SpecialChar ~
8642 8734 Heeter
8643 8735 \family typewriter
8644 8736 <korora-AT-SDF.LONESTAR.ORG>
8645 8737 \layout List
8646 8738 \labelwidthstring 00.00.0000
8647 8739
8648 8740 Christopher\SpecialChar ~
8649 8741 Hart
8650 8742 \family typewriter
8651 8743 <hart-AT-caltech.edu>
8652 8744 \family default
8653 8745 PDB integration.
8654 8746 \layout List
8655 8747 \labelwidthstring 00.00.0000
8656 8748
8657 8749 Milan\SpecialChar ~
8658 8750 Zamazal
8659 8751 \family typewriter
8660 8752 <pdm-AT-zamazal.org>
8661 8753 \family default
8662 8754 Emacs info.
8663 8755 \layout List
8664 8756 \labelwidthstring 00.00.0000
8665 8757
8666 8758 Philip\SpecialChar ~
8667 8759 Hisley
8668 8760 \family typewriter
8669 8761 <compsys-AT-starpower.net>
8670 8762 \layout List
8671 8763 \labelwidthstring 00.00.0000
8672 8764
8673 8765 Holger\SpecialChar ~
8674 8766 Krekel
8675 8767 \family typewriter
8676 8768 <pyth-AT-devel.trillke.net>
8677 8769 \family default
8678 8770 Tab completion, lots more.
8679 8771 \layout List
8680 8772 \labelwidthstring 00.00.0000
8681 8773
8682 8774 Robin\SpecialChar ~
8683 8775 Siebler
8684 8776 \family typewriter
8685 8777 <robinsiebler-AT-starband.net>
8686 8778 \layout List
8687 8779 \labelwidthstring 00.00.0000
8688 8780
8689 8781 Ralf\SpecialChar ~
8690 8782 Ahlbrink
8691 8783 \family typewriter
8692 8784 <ralf_ahlbrink-AT-web.de>
8693 8785 \layout List
8694 8786 \labelwidthstring 00.00.0000
8695 8787
8696 8788 Thorsten\SpecialChar ~
8697 8789 Kampe
8698 8790 \family typewriter
8699 8791 <thorsten-AT-thorstenkampe.de>
8700 8792 \layout List
8701 8793 \labelwidthstring 00.00.0000
8702 8794
8703 8795 Fredrik\SpecialChar ~
8704 8796 Kant
8705 8797 \family typewriter
8706 8798 <fredrik.kant-AT-front.com>
8707 8799 \family default
8708 8800 Windows setup.
8709 8801 \layout List
8710 8802 \labelwidthstring 00.00.0000
8711 8803
8712 8804 Syver\SpecialChar ~
8713 8805 Enstad
8714 8806 \family typewriter
8715 8807 <syver-en-AT-online.no>
8716 8808 \family default
8717 8809 Windows setup.
8718 8810 \layout List
8719 8811 \labelwidthstring 00.00.0000
8720 8812
8721 8813 Richard
8722 8814 \family typewriter
8723 8815 <rxe-AT-renre-europe.com>
8724 8816 \family default
8725 8817 Global embedding.
8726 8818 \layout List
8727 8819 \labelwidthstring 00.00.0000
8728 8820
8729 8821 Hayden\SpecialChar ~
8730 8822 Callow
8731 8823 \family typewriter
8732 8824 <h.callow-AT-elec.canterbury.ac.nz>
8733 8825 \family default
8734 8826 Gnuplot.py 1.6 compatibility.
8735 8827 \layout List
8736 8828 \labelwidthstring 00.00.0000
8737 8829
8738 8830 Leonardo\SpecialChar ~
8739 8831 Santagada
8740 8832 \family typewriter
8741 8833 <retype-AT-terra.com.br>
8742 8834 \family default
8743 8835 Fixes for Windows installation.
8744 8836 \layout List
8745 8837 \labelwidthstring 00.00.0000
8746 8838
8747 8839 Christopher\SpecialChar ~
8748 8840 Armstrong
8749 8841 \family typewriter
8750 8842 <radix-AT-twistedmatrix.com>
8751 8843 \family default
8752 8844 Bugfixes.
8753 8845 \layout List
8754 8846 \labelwidthstring 00.00.0000
8755 8847
8756 8848 Francois\SpecialChar ~
8757 8849 Pinard
8758 8850 \family typewriter
8759 8851 <pinard-AT-iro.umontreal.ca>
8760 8852 \family default
8761 8853 Code and documentation fixes.
8762 8854 \layout List
8763 8855 \labelwidthstring 00.00.0000
8764 8856
8765 8857 Cory\SpecialChar ~
8766 8858 Dodt
8767 8859 \family typewriter
8768 8860 <cdodt-AT-fcoe.k12.ca.us>
8769 8861 \family default
8770 8862 Bug reports and Windows ideas.
8771 8863 Patches for Windows installer.
8772 8864 \layout List
8773 8865 \labelwidthstring 00.00.0000
8774 8866
8775 8867 Olivier\SpecialChar ~
8776 8868 Aubert
8777 8869 \family typewriter
8778 8870 <oaubert-AT-bat710.univ-lyon1.fr>
8779 8871 \family default
8780 8872 New magics.
8781 8873 \layout List
8782 8874 \labelwidthstring 00.00.0000
8783 8875
8784 8876 King\SpecialChar ~
8785 8877 C.\SpecialChar ~
8786 8878 Shu
8787 8879 \family typewriter
8788 8880 <kingshu-AT-myrealbox.com>
8789 8881 \family default
8790 8882 Autoindent patch.
8791 8883 \layout List
8792 8884 \labelwidthstring 00.00.0000
8793 8885
8794 8886 Chris\SpecialChar ~
8795 8887 Drexler
8796 8888 \family typewriter
8797 8889 <chris-AT-ac-drexler.de>
8798 8890 \family default
8799 8891 Readline packages for Win32/CygWin.
8800 8892 \layout List
8801 8893 \labelwidthstring 00.00.0000
8802 8894
8803 8895 Gustavo\SpecialChar ~
8804 8896 CΓ³rdova\SpecialChar ~
8805 8897 Avila
8806 8898 \family typewriter
8807 8899 <gcordova-AT-sismex.com>
8808 8900 \family default
8809 8901 EvalDict code for nice, lightweight string interpolation.
8810 8902 \layout List
8811 8903 \labelwidthstring 00.00.0000
8812 8904
8813 8905 Kasper\SpecialChar ~
8814 8906 Souren
8815 8907 \family typewriter
8816 8908 <Kasper.Souren-AT-ircam.fr>
8817 8909 \family default
8818 8910 Bug reports, ideas.
8819 8911 \layout List
8820 8912 \labelwidthstring 00.00.0000
8821 8913
8822 8914 Gever\SpecialChar ~
8823 8915 Tulley
8824 8916 \family typewriter
8825 8917 <gever-AT-helium.com>
8826 8918 \family default
8827 8919 Code contributions.
8828 8920 \layout List
8829 8921 \labelwidthstring 00.00.0000
8830 8922
8831 8923 Ralf\SpecialChar ~
8832 8924 Schmitt
8833 8925 \family typewriter
8834 8926 <ralf-AT-brainbot.com>
8835 8927 \family default
8836 8928 Bug reports & fixes.
8837 8929 \layout List
8838 8930 \labelwidthstring 00.00.0000
8839 8931
8840 8932 Oliver\SpecialChar ~
8841 8933 Sander
8842 8934 \family typewriter
8843 8935 <osander-AT-gmx.de>
8844 8936 \family default
8845 8937 Bug reports.
8846 8938 \layout List
8847 8939 \labelwidthstring 00.00.0000
8848 8940
8849 8941 Rod\SpecialChar ~
8850 8942 Holland
8851 8943 \family typewriter
8852 8944 <rhh-AT-structurelabs.com>
8853 8945 \family default
8854 8946 Bug reports and fixes to logging module.
8855 8947 \layout List
8856 8948 \labelwidthstring 00.00.0000
8857 8949
8858 8950 Daniel\SpecialChar ~
8859 8951 'Dang'\SpecialChar ~
8860 8952 Griffith
8861 8953 \family typewriter
8862 8954 <pythondev-dang-AT-lazytwinacres.net>
8863 8955 \family default
8864 8956 Fixes, enhancement suggestions for system shell use.
8865 8957 \layout List
8866 8958 \labelwidthstring 00.00.0000
8867 8959
8868 8960 Viktor\SpecialChar ~
8869 8961 Ransmayr
8870 8962 \family typewriter
8871 8963 <viktor.ransmayr-AT-t-online.de>
8872 8964 \family default
8873 8965 Tests and reports on Windows installation issues.
8874 8966 Contributed a true Windows binary installer.
8875 8967 \layout List
8876 8968 \labelwidthstring 00.00.0000
8877 8969
8878 8970 Mike\SpecialChar ~
8879 8971 Salib
8880 8972 \family typewriter
8881 8973 <msalib-AT-mit.edu>
8882 8974 \family default
8883 8975 Help fixing a subtle bug related to traceback printing.
8884 8976 \layout List
8885 8977 \labelwidthstring 00.00.0000
8886 8978
8887 8979 W.J.\SpecialChar ~
8888 8980 van\SpecialChar ~
8889 8981 der\SpecialChar ~
8890 8982 Laan
8891 8983 \family typewriter
8892 8984 <gnufnork-AT-hetdigitalegat.nl>
8893 8985 \family default
8894 8986 Bash-like prompt specials.
8895 8987 \layout List
8896 8988 \labelwidthstring 00.00.0000
8897 8989
8898 8990 Ville\SpecialChar ~
8899 8991 Vainio
8900 8992 \family typewriter
8901 8993 <vivainio-AT-kolumbus.fi>
8902 8994 \family default
8903 8995 Bugfixes and suggestions.
8904 8996 Excellent patches for many new features.
8905 8997 \layout List
8906 8998 \labelwidthstring 00.00.0000
8907 8999
8908 9000 Antoon\SpecialChar ~
8909 9001 Pardon
8910 9002 \family typewriter
8911 9003 <Antoon.Pardon-AT-rece.vub.ac.be>
8912 9004 \family default
8913 9005 Critical fix for the multithreaded IPython.
8914 9006 \layout List
8915 9007 \labelwidthstring 00.00.0000
8916 9008
8917 9009 John\SpecialChar ~
8918 9010 Hunter
8919 9011 \family typewriter
8920 9012 <jdhunter-AT-nitace.bsd.uchicago.edu>
8921 9013 \family default
8922 9014 Matplotlib author, helped with all the development of support for matplotlib
8923 9015 in IPyhton, including making necessary changes to matplotlib itself.
8924 9016 \layout List
8925 9017 \labelwidthstring 00.00.0000
8926 9018
8927 9019 Matthew\SpecialChar ~
8928 9020 Arnison
8929 9021 \family typewriter
8930 9022 <maffew-AT-cat.org.au>
8931 9023 \family default
8932 9024 Bug reports, `
8933 9025 \family typewriter
8934 9026 %run -d
8935 9027 \family default
8936 9028 ' idea.
8937 9029 \layout List
8938 9030 \labelwidthstring 00.00.0000
8939 9031
8940 9032 Prabhu\SpecialChar ~
8941 9033 Ramachandran
8942 9034 \family typewriter
8943 9035 <prabhu_r-AT-users.sourceforge.net>
8944 9036 \family default
8945 9037 Help with (X)Emacs support, threading patches, ideas...
8946 9038 \layout List
8947 9039 \labelwidthstring 00.00.0000
8948 9040
8949 9041 Norbert\SpecialChar ~
8950 9042 Tretkowski
8951 9043 \family typewriter
8952 9044 <tretkowski-AT-inittab.de>
8953 9045 \family default
8954 9046 help with Debian packaging and distribution.
8955 9047 \layout List
8956 9048 \labelwidthstring 00.00.0000
8957 9049
8958 9050 George\SpecialChar ~
8959 9051 Sakkis <
8960 9052 \family typewriter
8961 9053 gsakkis-AT-eden.rutgers.edu>
8962 9054 \family default
8963 9055 New matcher for tab-completing named arguments of user-defined functions.
8964 9056 \the_end
General Comments 0
You need to be logged in to leave comments. Login now