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