##// END OF EJS Templates
Update interactive reference docs.
Thomas Kluyver -
Show More
@@ -11,6 +11,10 b' You start IPython with the command::'
11
11
12 $ ipython [options] files
12 $ ipython [options] files
13
13
14 .. note::
15
16 For IPython on Python 3, use ``ipython3`` in place of ``ipython``.
17
14 If invoked with no options, it executes all the files listed in sequence
18 If invoked with no options, it executes all the files listed in sequence
15 and drops you into the interpreter while still acknowledging any options
19 and drops you into the interpreter while still acknowledging any options
16 you may have set in your ipython_config.py. This behavior is different from
20 you may have set in your ipython_config.py. This behavior is different from
@@ -45,8 +49,7 b' Regular Options'
45
49
46 After the above threading options have been given, regular options can
50 After the above threading options have been given, regular options can
47 follow in any order. All options can be abbreviated to their shortest
51 follow in any order. All options can be abbreviated to their shortest
48 non-ambiguous form and are case-sensitive. One or two dashes can be
52 non-ambiguous form and are case-sensitive.
49 used. Some options have an alternate short form, indicated after a ``|``.
50
53
51 Most options can also be set from your configuration file. See the provided
54 Most options can also be set from your configuration file. See the provided
52 example for more details on what the options do. Options given at the command
55 example for more details on what the options do. Options given at the command
@@ -372,31 +375,24 b' An example (with automagic on) should clarify all this:'
372
375
373 .. sourcecode:: ipython
376 .. sourcecode:: ipython
374
377
375 In [1]: cd ipython # %cd is called by automagic
378 In [1]: cd ipython # %cd is called by automagic
376
377 /home/fperez/ipython
379 /home/fperez/ipython
378
380
379 In [2]: cd=1 # now cd is just a variable
381 In [2]: cd=1 # now cd is just a variable
380
381 In [3]: cd .. # and doesn't work as a function anymore
382
383 ------------------------------
384
385 File "<console>", line 1
386
387 cd ..
388
389 ^
390
382
383 In [3]: cd .. # and doesn't work as a function anymore
384 File "<ipython-input-3-9fedb3aff56c>", line 1
385 cd ..
386 ^
391 SyntaxError: invalid syntax
387 SyntaxError: invalid syntax
392
388
393 In [4]: %cd .. # but %cd always works
394
389
390 In [4]: %cd .. # but %cd always works
395 /home/fperez
391 /home/fperez
396
392
397 In [5]: del cd # if you remove the cd variable
393 In [5]: del cd # if you remove the cd variable, automagic works again
398
394
399 In [6]: cd ipython # automagic can work again
395 In [6]: cd ipython
400
396
401 /home/fperez/ipython
397 /home/fperez/ipython
402
398
@@ -408,20 +404,14 b' following example defines a new magic command, %impall:'
408 ip = get_ipython()
404 ip = get_ipython()
409
405
410 def doimp(self, arg):
406 def doimp(self, arg):
411
412 ip = self.api
407 ip = self.api
408 ip.ex("import %s; reload(%s); from %s import *" % (arg,arg,arg) )
413
409
414 ip.ex("import %s; reload(%s); from %s import *" % (
410 ip.define_magic('impall', doimp)
415
416 arg,arg,arg)
417
418 )
419
411
420 ip.expose_magic('impall', doimp)
412 Type ``%magic`` for more information, including a list of all available magic
421
422 Type `%magic` for more information, including a list of all available magic
423 functions at any time and their docstrings. You can also type
413 functions at any time and their docstrings. You can also type
424 %magic_function_name? (see :ref:`below <dynamic_object_info` for information on
414 ``%magic_function_name?`` (see :ref:`below <dynamic_object_info>` for information on
425 the '?' system) to get information about any particular magic function you are
415 the '?' system) to get information about any particular magic function you are
426 interested in.
416 interested in.
427
417
@@ -432,12 +422,10 b' docstrings of all currently available magic commands.'
432 Access to the standard Python help
422 Access to the standard Python help
433 ----------------------------------
423 ----------------------------------
434
424
435 As of Python 2.1, a help system is available with access to object docstrings
425 Simply type ``help()`` to access Python's standard help system. You can
436 and the Python manuals. Simply type 'help' (no quotes) to access it. You can
426 also type ``help(object)`` for information about a given object, or
437 also type help(object) to obtain information about a given object, and
427 ``help('keyword')`` for information on a keyword. You may need to configure your
438 help('keyword') for information on a keyword. As noted :ref:`here
428 PYTHONDOCS environment variable for this feature to work correctly.
439 <accessing_help>`, you need to properly configure your environment variable
440 PYTHONDOCS for this feature to work correctly.
441
429
442 .. _dynamic_object_info:
430 .. _dynamic_object_info:
443
431
@@ -445,20 +433,20 b' Dynamic object information'
445 --------------------------
433 --------------------------
446
434
447 Typing ``?word`` or ``word?`` prints detailed information about an object. If
435 Typing ``?word`` or ``word?`` prints detailed information about an object. If
448 certain strings in the object are too long (docstrings, code, etc.) they get
436 certain strings in the object are too long (e.g. function signatures) they get
449 snipped in the center for brevity. This system gives access variable types and
437 snipped in the center for brevity. This system gives access variable types and
450 values, full source code for any object (if available), function prototypes and
438 values, docstrings, function prototypes and other useful information.
451 other useful information.
439
440 If the information will not fit in the terminal, it is displayed in a pager
441 (``less`` if available, otherwise a basic internal pager).
452
442
453 Typing ``??word`` or ``word??`` gives access to the full information without
443 Typing ``??word`` or ``word??`` gives access to the full information, including
454 snipping long strings. Long strings are sent to the screen through the
444 the source code where possible. Long strings are not snipped.
455 less pager if longer than the screen and printed otherwise. On systems
456 lacking the less command, IPython uses a very basic internal pager.
457
445
458 The following magic functions are particularly useful for gathering
446 The following magic functions are particularly useful for gathering
459 information about your working environment. You can get more details by
447 information about your working environment. You can get more details by
460 typing ``%magic`` or querying them individually (use %function_name? with or
448 typing ``%magic`` or querying them individually (``%function_name?``);
461 without the %), this is just a summary:
449 this is just a summary:
462
450
463 * **%pdoc <object>**: Print (or run through a pager if too long) the
451 * **%pdoc <object>**: Print (or run through a pager if too long) the
464 docstring for an object. If the given object is a class, it will
452 docstring for an object. If the given object is a class, it will
@@ -477,9 +465,9 b' without the %), this is just a summary:'
477 each identifier.
465 each identifier.
478
466
479 Note that the dynamic object information functions (?/??, ``%pdoc``,
467 Note that the dynamic object information functions (?/??, ``%pdoc``,
480 ``%pfile``, ``%pdef``, ``%psource``) give you access to documentation even on
468 ``%pfile``, ``%pdef``, ``%psource``) work on object attributes, as well as
481 things which are not really defined as separate identifiers. Try for example
469 directly on variables. For example, after doing ``import os``, you can use
482 typing {}.get? or after doing import os, type ``os.path.abspath??``.
470 ``os.path.abspath??``.
483
471
484 .. _readline:
472 .. _readline:
485
473
@@ -557,8 +545,8 b' Note that there are 4 spaces between the quote marks after "M-i" above.'
557 can also disable it permanently on in your :file:`ipython_config.py` file
545 can also disable it permanently on in your :file:`ipython_config.py` file
558 (set TerminalInteractiveShell.autoindent=False).
546 (set TerminalInteractiveShell.autoindent=False).
559
547
560 If you want to paste multiple lines, it is recommended that you use
548 If you want to paste multiple lines in the terminal, it is recommended that
561 ``%paste``.
549 you use ``%paste``.
562
550
563
551
564 Customizing readline behavior
552 Customizing readline behavior
@@ -574,9 +562,8 b' options via a simple interface. In brief, you can customize readline by'
574 setting the following options in your configuration file (note
562 setting the following options in your configuration file (note
575 that these options can not be specified at the command line):
563 that these options can not be specified at the command line):
576
564
577 * **readline_parse_and_bind**: this option can appear as many times as
565 * **readline_parse_and_bind**: this holds a list of strings to be executed
578 you want, each time defining a string to be executed via a
566 via a readline.parse_and_bind() command. The syntax for valid commands
579 readline.parse_and_bind() command. The syntax for valid commands
580 of this kind can be found by reading the documentation for the GNU
567 of this kind can be found by reading the documentation for the GNU
581 readline library, as these commands are of the kind which readline
568 readline library, as these commands are of the kind which readline
582 accepts in its configuration file.
569 accepts in its configuration file.
@@ -584,17 +571,6 b' that these options can not be specified at the command line):'
584 from the default word-delimiters list used by readline, so that
571 from the default word-delimiters list used by readline, so that
585 completions may be performed on strings which contain them. Do not
572 completions may be performed on strings which contain them. Do not
586 change the default value unless you know what you're doing.
573 change the default value unless you know what you're doing.
587 * **readline_omit__names**: when tab-completion is enabled, hitting
588 <tab> after a '.' in a name will complete all attributes of an
589 object, including all the special methods whose names include
590 double underscores (like __getitem__ or __class__). If you'd
591 rather not see these names by default, you can set this option to
592 1. Note that even when this option is set, you can still see those
593 names by explicitly typing a _ after the period and hitting <tab>:
594 'name._<tab>' will always complete attribute names starting with '_'.
595
596 This option is off by default so that new users see all
597 attributes of any objects they are dealing with.
598
574
599 You will find the default values in your configuration file.
575 You will find the default values in your configuration file.
600
576
@@ -688,20 +664,19 b' system shell commands. These aliases can have parameters.'
688
664
689 ``%alias alias_name cmd`` defines 'alias_name' as an alias for 'cmd'
665 ``%alias alias_name cmd`` defines 'alias_name' as an alias for 'cmd'
690
666
691 Then, typing ``%alias_name params`` will execute the system command 'cmd
667 Then, typing ``alias_name params`` will execute the system command 'cmd
692 params' (from your underlying operating system).
668 params' (from your underlying operating system).
693
669
694 You can also define aliases with parameters using %s specifiers (one per
670 You can also define aliases with parameters using %s specifiers (one per
695 parameter). The following example defines the %parts function as an
671 parameter). The following example defines the parts function as an
696 alias to the command 'echo first %s second %s' where each %s will be
672 alias to the command 'echo first %s second %s' where each %s will be
697 replaced by a positional parameter to the call to %parts::
673 replaced by a positional parameter to the call to %parts::
698
674
699 In [1]: alias parts echo first %s second %s
675 In [1]: %alias parts echo first %s second %s
700 In [2]: %parts A B
676 In [2]: parts A B
701 first A second B
677 first A second B
702 In [3]: %parts A
678 In [3]: parts A
703 Incorrect number of arguments: 2 expected.
679 ERROR: Alias <parts> requires 2 arguments, 1 given.
704 parts is an alias to: 'echo first %s second %s'
705
680
706 If called with no parameters, %alias prints the table of currently
681 If called with no parameters, %alias prints the table of currently
707 defined aliases.
682 defined aliases.
@@ -715,9 +690,11 b' ipython aliases. See its docstring for further details.'
715 Recursive reload
690 Recursive reload
716 ----------------
691 ----------------
717
692
718 The dreload function does a recursive reload of a module: changes made
693 The :mod:`IPython.lib.deepreload` module allows you to recursively reload a
719 to the module since you imported will actually be available without
694 module: changes made to any of its dependencies will be reloaded without
720 having to exit.
695 having to exit. To start using it, do::
696
697 from IPython.lib.deepreload import reload as dreload
721
698
722
699
723 Verbose and colored exception traceback printouts
700 Verbose and colored exception traceback printouts
@@ -767,11 +744,9 b' are strings), modify or exec them (typing ``exec _i9`` will re-execute the'
767 contents of input prompt 9.
744 contents of input prompt 9.
768
745
769 You can also re-execute multiple lines of input easily by using the
746 You can also re-execute multiple lines of input easily by using the
770 magic %macro function (which automates the process and allows
747 magic %rerun or %macro functions. The macro system also allows you to re-execute
771 re-execution without having to type 'exec' every time). The macro system
748 previous lines which include magic function calls (which require special
772 also allows you to re-execute previous lines which include magic
749 processing). Type %macro? for more details on the macro system.
773 function calls (which require special processing). Type %macro? for more details
774 on the macro system.
775
750
776 A history function %hist allows you to see any part of your input
751 A history function %hist allows you to see any part of your input
777 history by printing a range of the _i variables.
752 history by printing a range of the _i variables.
@@ -804,7 +779,7 b' being the prompt counter), such that the result of output <n> is always'
804 available as _<n> (don't use the angle brackets, just the number, e.g.
779 available as _<n> (don't use the angle brackets, just the number, e.g.
805 _21).
780 _21).
806
781
807 These global variables are all stored in a global dictionary (not a
782 These variables are also stored in a global dictionary (not a
808 list, since it only has entries for lines which returned a result)
783 list, since it only has entries for lines which returned a result)
809 available under the names _oh and Out (similar to _ih and In). So the
784 available under the names _oh and Out (similar to _ih and In). So the
810 output from line 12 can be obtained as _12, Out[12] or _oh[12]. If you
785 output from line 12 can be obtained as _12, Out[12] or _oh[12]. If you
@@ -836,78 +811,75 b' meant to allow less typing for common situations.'
836
811
837
812
838 Automatic parentheses
813 Automatic parentheses
839 ---------------------
814 +++++++++++++++++++++
840
815
841 Callable objects (i.e. functions, methods, etc) can be invoked like this
816 Callable objects (i.e. functions, methods, etc) can be invoked like this
842 (notice the commas between the arguments)::
817 (notice the commas between the arguments)::
843
818
844 >>> callable_ob arg1, arg2, arg3
819 In [1]: callable_ob arg1, arg2, arg3
845
820 ------> callable_ob(arg1, arg2, arg3)
846 and the input will be translated to this::
847
848 -> callable_ob(arg1, arg2, arg3)
849
821
850 You can force automatic parentheses by using '/' as the first character
822 You can force automatic parentheses by using '/' as the first character
851 of a line. For example::
823 of a line. For example::
852
824
853 >>> /globals # becomes 'globals()'
825 In [2]: /globals # becomes 'globals()'
854
826
855 Note that the '/' MUST be the first character on the line! This won't work::
827 Note that the '/' MUST be the first character on the line! This won't work::
856
828
857 >>> print /globals # syntax error
829 In [3]: print /globals # syntax error
858
830
859 In most cases the automatic algorithm should work, so you should rarely
831 In most cases the automatic algorithm should work, so you should rarely
860 need to explicitly invoke /. One notable exception is if you are trying
832 need to explicitly invoke /. One notable exception is if you are trying
861 to call a function with a list of tuples as arguments (the parenthesis
833 to call a function with a list of tuples as arguments (the parenthesis
862 will confuse IPython)::
834 will confuse IPython)::
863
835
864 In [1]: zip (1,2,3),(4,5,6) # won't work
836 In [4]: zip (1,2,3),(4,5,6) # won't work
865
837
866 but this will work::
838 but this will work::
867
839
868 In [2]: /zip (1,2,3),(4,5,6)
840 In [5]: /zip (1,2,3),(4,5,6)
869 ---> zip ((1,2,3),(4,5,6))
841 ------> zip ((1,2,3),(4,5,6))
870 Out[2]= [(1, 4), (2, 5), (3, 6)]
842 Out[5]: [(1, 4), (2, 5), (3, 6)]
871
843
872 IPython tells you that it has altered your command line by displaying
844 IPython tells you that it has altered your command line by displaying
873 the new command line preceded by ->. e.g.::
845 the new command line preceded by ->. e.g.::
874
846
875 In [18]: callable list
847 In [6]: callable list
876 ----> callable (list)
848 ------> callable(list)
877
849
878
850
879 Automatic quoting
851 Automatic quoting
880 -----------------
852 +++++++++++++++++
881
853
882 You can force automatic quoting of a function's arguments by using ','
854 You can force automatic quoting of a function's arguments by using ','
883 or ';' as the first character of a line. For example::
855 or ';' as the first character of a line. For example::
884
856
885 >>> ,my_function /home/me # becomes my_function("/home/me")
857 In [1]: ,my_function /home/me # becomes my_function("/home/me")
886
858
887 If you use ';' instead, the whole argument is quoted as a single string
859 If you use ';' the whole argument is quoted as a single string, while ',' splits
888 (while ',' splits on whitespace)::
860 on whitespace::
889
861
890 >>> ,my_function a b c # becomes my_function("a","b","c")
862 In [2]: ,my_function a b c # becomes my_function("a","b","c")
891
863
892 >>> ;my_function a b c # becomes my_function("a b c")
864 In [3]: ;my_function a b c # becomes my_function("a b c")
893
865
894 Note that the ',' or ';' MUST be the first character on the line! This
866 Note that the ',' or ';' MUST be the first character on the line! This
895 won't work::
867 won't work::
896
868
897 >>> x = ,my_function /home/me # syntax error
869 In [4]: x = ,my_function /home/me # syntax error
898
870
899 IPython as your default Python environment
871 IPython as your default Python environment
900 ==========================================
872 ==========================================
901
873
902 Python honors the environment variable PYTHONSTARTUP and will execute at
874 Python honors the environment variable PYTHONSTARTUP and will execute at
903 startup the file referenced by this variable. If you put at the end of
875 startup the file referenced by this variable. If you put the following code at
904 this file the following two lines of code::
876 the end of that file, then IPython will be your working environment anytime you
877 start Python::
905
878
906 from IPython.frontend.terminal.ipapp import launch_new_instance
879 from IPython.frontend.terminal.ipapp import launch_new_instance
907 launch_new_instance()
880 launch_new_instance()
908 raise SystemExit
881 raise SystemExit
909
882
910 then IPython will be your working environment anytime you start Python.
911 The ``raise SystemExit`` is needed to exit Python when
883 The ``raise SystemExit`` is needed to exit Python when
912 it finishes, otherwise you'll be back at the normal Python '>>>'
884 it finishes, otherwise you'll be back at the normal Python '>>>'
913 prompt.
885 prompt.
@@ -929,6 +901,11 b' any changes you make to values while in the shell do not propagate back'
929 to the running code, so it is safe to modify your values because you
901 to the running code, so it is safe to modify your values because you
930 won't break your code in bizarre ways by doing so.
902 won't break your code in bizarre ways by doing so.
931
903
904 .. note::
905
906 At present, trying to embed IPython from inside IPython causes problems. Run
907 the code samples below outside IPython.
908
932 This feature allows you to easily have a fully functional python
909 This feature allows you to easily have a fully functional python
933 environment for doing object introspection anywhere in your code with a
910 environment for doing object introspection anywhere in your code with a
934 simple function call. In some cases a simple print statement is enough,
911 simple function call. In some cases a simple print statement is enough,
@@ -1008,8 +985,8 b' This will load the pdb.doc document in a file viewer for you automatically.'
1008 Automatic invocation of pdb on exceptions
985 Automatic invocation of pdb on exceptions
1009 -----------------------------------------
986 -----------------------------------------
1010
987
1011 IPython, if started with the -pdb option (or if the option is set in
988 IPython, if started with the ``--pdb`` option (or if the option is set in
1012 your rc file) can call the Python pdb debugger every time your code
989 your config file) can call the Python pdb debugger every time your code
1013 triggers an uncaught exception. This feature
990 triggers an uncaught exception. This feature
1014 can also be toggled at any time with the %pdb magic command. This can be
991 can also be toggled at any time with the %pdb magic command. This can be
1015 extremely useful in order to find the origin of subtle bugs, because pdb
992 extremely useful in order to find the origin of subtle bugs, because pdb
@@ -1021,7 +998,7 b' the origin of the problem.'
1021 Furthermore, you can use these debugging facilities both with the
998 Furthermore, you can use these debugging facilities both with the
1022 embedded IPython mode and without IPython at all. For an embedded shell
999 embedded IPython mode and without IPython at all. For an embedded shell
1023 (see sec. Embedding_), simply call the constructor with
1000 (see sec. Embedding_), simply call the constructor with
1024 '--pdb' in the argument string and automatically pdb will be called if an
1001 ``--pdb`` in the argument string and pdb will automatically be called if an
1025 uncaught exception is triggered by your code.
1002 uncaught exception is triggered by your code.
1026
1003
1027 For stand-alone use of the feature in your programs which do not use
1004 For stand-alone use of the feature in your programs which do not use
@@ -1036,7 +1013,7 b' routine::'
1036 The mode keyword can be either 'Verbose' or 'Plain', giving either very
1013 The mode keyword can be either 'Verbose' or 'Plain', giving either very
1037 detailed or normal tracebacks respectively. The color_scheme keyword can
1014 detailed or normal tracebacks respectively. The color_scheme keyword can
1038 be one of 'NoColor', 'Linux' (default) or 'LightBG'. These are the same
1015 be one of 'NoColor', 'Linux' (default) or 'LightBG'. These are the same
1039 options which can be set in IPython with -colors and -xmode.
1016 options which can be set in IPython with ``--colors`` and ``--xmode``.
1040
1017
1041 This will give any of your programs detailed, colored tracebacks with
1018 This will give any of your programs detailed, colored tracebacks with
1042 automatic invocation of pdb.
1019 automatic invocation of pdb.
@@ -1274,7 +1251,7 b' docstring, which you can access via::'
1274 demo?
1251 demo?
1275
1252
1276 Limitations: It is important to note that these demos are limited to
1253 Limitations: It is important to note that these demos are limited to
1277 fairly simple uses. In particular, you can not put division marks in
1254 fairly simple uses. In particular, you cannot break up sections within
1278 indented code (loops, if statements, function definitions, etc.)
1255 indented code (loops, if statements, function definitions, etc.)
1279 Supporting something like this would basically require tracking the
1256 Supporting something like this would basically require tracking the
1280 internal execution state of the Python interpreter, so only top-level
1257 internal execution state of the Python interpreter, so only top-level
General Comments 0
You need to be logged in to leave comments. Login now