Show More
@@ -19,7 +19,7 file and ignore your configuration setup. | |||||
19 |
|
19 | |||
20 | Please note that some of the configuration options are not available at |
|
20 | Please note that some of the configuration options are not available at | |
21 | the command line, simply because they are not practical here. Look into |
|
21 | the command line, simply because they are not practical here. Look into | |
22 |
your configuration files for details on those. There are separate configuration |
|
22 | your configuration files for details on those. There are separate configuration | |
23 | files for each profile, and the files look like :file:`ipython_config.py` or |
|
23 | files for each profile, and the files look like :file:`ipython_config.py` or | |
24 | :file:`ipython_config_{frontendname}.py`. Profile directories look like |
|
24 | :file:`ipython_config_{frontendname}.py`. Profile directories look like | |
25 | :file:`profile_{profilename}` and are typically installed in the :envvar:`IPYTHONDIR` directory, |
|
25 | :file:`profile_{profilename}` and are typically installed in the :envvar:`IPYTHONDIR` directory, | |
@@ -95,17 +95,17 the same name:: | |||||
95 | /home/fperez |
|
95 | /home/fperez | |
96 |
|
96 | |||
97 | The following uses the builtin :magic:`timeit` in cell mode:: |
|
97 | The following uses the builtin :magic:`timeit` in cell mode:: | |
98 |
|
98 | |||
99 | In [10]: %%timeit x = range(10000) |
|
99 | In [10]: %%timeit x = range(10000) | |
100 | ...: min(x) |
|
100 | ...: min(x) | |
101 | ...: max(x) |
|
101 | ...: max(x) | |
102 |
...: |
|
102 | ...: | |
103 | 1000 loops, best of 3: 438 us per loop |
|
103 | 1000 loops, best of 3: 438 us per loop | |
104 |
|
104 | |||
105 | In this case, ``x = range(10000)`` is called as the line argument, and the |
|
105 | In this case, ``x = range(10000)`` is called as the line argument, and the | |
106 | block with ``min(x)`` and ``max(x)`` is called as the cell body. The |
|
106 | block with ``min(x)`` and ``max(x)`` is called as the cell body. The | |
107 | :magic:`timeit` magic receives both. |
|
107 | :magic:`timeit` magic receives both. | |
108 |
|
108 | |||
109 | If you have 'automagic' enabled (as it is by default), you don't need to type in |
|
109 | If you have 'automagic' enabled (as it is by default), you don't need to type in | |
110 | the single ``%`` explicitly for line magics; IPython will scan its internal |
|
110 | the single ``%`` explicitly for line magics; IPython will scan its internal | |
111 | list of magic functions and call one if it exists. With automagic on you can |
|
111 | list of magic functions and call one if it exists. With automagic on you can | |
@@ -116,7 +116,7 then just type ``cd mydir`` to go to directory 'mydir':: | |||||
116 |
|
116 | |||
117 | Cell magics *always* require an explicit ``%%`` prefix, automagic |
|
117 | Cell magics *always* require an explicit ``%%`` prefix, automagic | |
118 | calling only works for line magics. |
|
118 | calling only works for line magics. | |
119 |
|
119 | |||
120 | The automagic system has the lowest possible precedence in name searches, so |
|
120 | The automagic system has the lowest possible precedence in name searches, so | |
121 | you can freely use variables with the same names as magic commands. If a magic |
|
121 | you can freely use variables with the same names as magic commands. If a magic | |
122 | command is 'shadowed' by a variable, you will need the explicit ``%`` prefix to |
|
122 | command is 'shadowed' by a variable, you will need the explicit ``%`` prefix to | |
@@ -146,7 +146,7 use it: | |||||
146 | /home/fperez/ipython |
|
146 | /home/fperez/ipython | |
147 |
|
147 | |||
148 | Line magics, if they return a value, can be assigned to a variable using the syntax |
|
148 | Line magics, if they return a value, can be assigned to a variable using the syntax | |
149 |
``l = %sx ls`` (which in this particular case returns the result of `ls` as a python list). |
|
149 | ``l = %sx ls`` (which in this particular case returns the result of `ls` as a python list). | |
150 | See :ref:`below <manual_capture>` for more information. |
|
150 | See :ref:`below <manual_capture>` for more information. | |
151 |
|
151 | |||
152 | Type ``%magic`` for more information, including a list of all available magic |
|
152 | Type ``%magic`` for more information, including a list of all available magic | |
@@ -326,9 +326,9 You can assign the result of a system command to a Python variable with the | |||||
326 | syntax ``myfiles = !ls``. Similarly, the result of a magic (as long as it returns |
|
326 | syntax ``myfiles = !ls``. Similarly, the result of a magic (as long as it returns | |
327 | a value) can be assigned to a variable. For example, the syntax ``myfiles = %sx ls`` |
|
327 | a value) can be assigned to a variable. For example, the syntax ``myfiles = %sx ls`` | |
328 | is equivalent to the above system command example (the :magic:`sx` magic runs a shell command |
|
328 | is equivalent to the above system command example (the :magic:`sx` magic runs a shell command | |
329 |
and captures the output). Each of these gets machine |
|
329 | and captures the output). Each of these gets machine | |
330 |
readable output from stdout (e.g. without colours), and splits on newlines. To |
|
330 | readable output from stdout (e.g. without colours), and splits on newlines. To | |
331 |
explicitly get this sort of output without assigning to a variable, use two |
|
331 | explicitly get this sort of output without assigning to a variable, use two | |
332 | exclamation marks (``!!ls``) or the :magic:`sx` magic command without an assignment. |
|
332 | exclamation marks (``!!ls``) or the :magic:`sx` magic command without an assignment. | |
333 | (However, ``!!`` commands cannot be assigned to a variable.) |
|
333 | (However, ``!!`` commands cannot be assigned to a variable.) | |
334 |
|
334 | |||
@@ -340,8 +340,8 See :ref:`string_lists` for details. | |||||
340 | IPython also allows you to expand the value of python variables when |
|
340 | IPython also allows you to expand the value of python variables when | |
341 | making system calls. Wrap variables or expressions in {braces}:: |
|
341 | making system calls. Wrap variables or expressions in {braces}:: | |
342 |
|
342 | |||
343 |
In [1]: pyvar = 'Hello world' |
|
343 | In [1]: pyvar = 'Hello world' | |
344 |
In [2]: !echo "A python variable: {pyvar}" |
|
344 | In [2]: !echo "A python variable: {pyvar}" | |
345 | A python variable: Hello world |
|
345 | A python variable: Hello world | |
346 | In [3]: import math |
|
346 | In [3]: import math | |
347 | In [4]: x = 8 |
|
347 | In [4]: x = 8 | |
@@ -350,7 +350,7 making system calls. Wrap variables or expressions in {braces}:: | |||||
350 |
|
350 | |||
351 | For simple cases, you can alternatively prepend $ to a variable name:: |
|
351 | For simple cases, you can alternatively prepend $ to a variable name:: | |
352 |
|
352 | |||
353 |
In [6]: !echo $sys.argv |
|
353 | In [6]: !echo $sys.argv | |
354 | [/home/fperez/usr/bin/ipython] |
|
354 | [/home/fperez/usr/bin/ipython] | |
355 | In [7]: !echo "A system variable: $$HOME" # Use $$ for literal $ |
|
355 | In [7]: !echo "A system variable: $$HOME" # Use $$ for literal $ | |
356 | A system variable: /home/fperez |
|
356 | A system variable: /home/fperez | |
@@ -376,7 +376,7 replaced by a positional parameter to the call to %parts:: | |||||
376 | In [1]: %alias parts echo first %s second %s |
|
376 | In [1]: %alias parts echo first %s second %s | |
377 | In [2]: parts A B |
|
377 | In [2]: parts A B | |
378 | first A second B |
|
378 | first A second B | |
379 |
In [3]: parts A |
|
379 | In [3]: parts A | |
380 | ERROR: Alias <parts> requires 2 arguments, 1 given. |
|
380 | ERROR: Alias <parts> requires 2 arguments, 1 given. | |
381 |
|
381 | |||
382 | If called with no parameters, :magic:`alias` prints the table of currently |
|
382 | If called with no parameters, :magic:`alias` prints the table of currently | |
@@ -420,8 +420,8 Input caching system | |||||
420 | -------------------- |
|
420 | -------------------- | |
421 |
|
421 | |||
422 | IPython offers numbered prompts (In/Out) with input and output caching |
|
422 | IPython offers numbered prompts (In/Out) with input and output caching | |
423 |
(also referred to as 'input history'). All input is saved and can be |
|
423 | (also referred to as 'input history'). All input is saved and can be | |
424 |
retrieved as variables (besides the usual arrow key recall), in |
|
424 | retrieved as variables (besides the usual arrow key recall), in | |
425 | addition to the :magic:`rep` magic command that brings a history entry |
|
425 | addition to the :magic:`rep` magic command that brings a history entry | |
426 | up for editing on the next command line. |
|
426 | up for editing on the next command line. | |
427 |
|
427 | |||
@@ -451,7 +451,7 processing). Type %macro? for more details on the macro system. | |||||
451 | A history function :magic:`history` allows you to see any part of your input |
|
451 | A history function :magic:`history` allows you to see any part of your input | |
452 | history by printing a range of the _i variables. |
|
452 | history by printing a range of the _i variables. | |
453 |
|
453 | |||
454 |
You can also search ('grep') through your history by typing |
|
454 | You can also search ('grep') through your history by typing | |
455 | ``%hist -g somestring``. This is handy for searching for URLs, IP addresses, |
|
455 | ``%hist -g somestring``. This is handy for searching for URLs, IP addresses, | |
456 | etc. You can bring history entries listed by '%hist -g' up for editing |
|
456 | etc. You can bring history entries listed by '%hist -g' up for editing | |
457 | with the %recall command, or run them immediately with :magic:`rerun`. |
|
457 | with the %recall command, or run them immediately with :magic:`rerun`. | |
@@ -537,8 +537,8 will confuse IPython):: | |||||
537 |
|
537 | |||
538 | but this will work:: |
|
538 | but this will work:: | |
539 |
|
539 | |||
540 |
In [5]: /zip (1,2,3),(4,5,6) |
|
540 | In [5]: /zip (1,2,3),(4,5,6) | |
541 |
------> zip ((1,2,3),(4,5,6)) |
|
541 | ------> zip ((1,2,3),(4,5,6)) | |
542 | Out[5]: [(1, 4), (2, 5), (3, 6)] |
|
542 | Out[5]: [(1, 4), (2, 5), (3, 6)] | |
543 |
|
543 | |||
544 | IPython tells you that it has altered your command line by displaying |
|
544 | IPython tells you that it has altered your command line by displaying | |
@@ -648,7 +648,7 them separately, for example with different options for data | |||||
648 | presentation. If you close and open the same instance multiple times, |
|
648 | presentation. If you close and open the same instance multiple times, | |
649 | its prompt counters simply continue from each execution to the next. |
|
649 | its prompt counters simply continue from each execution to the next. | |
650 |
|
650 | |||
651 |
Please look at the docstrings in the :mod:`~IPython.frontend.terminal.embed` |
|
651 | Please look at the docstrings in the :mod:`~IPython.frontend.terminal.embed` | |
652 | module for more details on the use of this system. |
|
652 | module for more details on the use of this system. | |
653 |
|
653 | |||
654 | The following sample file illustrating how to use the embedding |
|
654 | The following sample file illustrating how to use the embedding | |
@@ -682,12 +682,13 For more information on the use of the pdb debugger, see :ref:`debugger-commands | |||||
682 | in the Python documentation. |
|
682 | in the Python documentation. | |
683 |
|
683 | |||
684 | IPython extends the debugger with a few useful additions, like coloring of |
|
684 | IPython extends the debugger with a few useful additions, like coloring of | |
685 |
tracebacks. The debugger will adopt the color scheme selected for IPython. |
|
685 | tracebacks. The debugger will adopt the color scheme selected for IPython. | |
686 |
|
686 | |||
687 | The ``where`` command has also been extended to take as argument the number of |
|
687 | The ``where`` command has also been extended to take as argument the number of | |
688 | context line to show. This allows to a many line of context on shallow stack trace: |
|
688 | context line to show. This allows to a many line of context on shallow stack trace: | |
689 |
|
689 | |||
690 | .. code:: |
|
690 | .. code:: | |
|
691 | ||||
691 | In [5]: def foo(x): |
|
692 | In [5]: def foo(x): | |
692 | ...: 1 |
|
693 | ...: 1 | |
693 | ...: 2 |
|
694 | ...: 2 | |
@@ -697,7 +698,7 context line to show. This allows to a many line of context on shallow stack tra | |||||
697 | ...: 6 |
|
698 | ...: 6 | |
698 | ...: 7 |
|
699 | ...: 7 | |
699 | ...: |
|
700 | ...: | |
700 |
|
701 | |||
701 | In[6]: foo(1) |
|
702 | In[6]: foo(1) | |
702 | # ... |
|
703 | # ... | |
703 | ipdb> where 8 |
|
704 | ipdb> where 8 | |
@@ -728,6 +729,7 context line to show. This allows to a many line of context on shallow stack tra | |||||
728 | And less context on shallower Stack Trace: |
|
729 | And less context on shallower Stack Trace: | |
729 |
|
730 | |||
730 | .. code:: |
|
731 | .. code:: | |
|
732 | ||||
731 | ipdb> where 1 |
|
733 | ipdb> where 1 | |
732 | <ipython-input-13-afa180a57233>(1)<module>() |
|
734 | <ipython-input-13-afa180a57233>(1)<module>() | |
733 | ----> 1 foo(7) |
|
735 | ----> 1 foo(7) | |
@@ -797,7 +799,7 standard Python tutorial:: | |||||
797 | In [4]: >>> while b < 10: |
|
799 | In [4]: >>> while b < 10: | |
798 | ...: ... print(b) |
|
800 | ...: ... print(b) | |
799 | ...: ... a, b = b, a+b |
|
801 | ...: ... a, b = b, a+b | |
800 |
...: |
|
802 | ...: | |
801 | 1 |
|
803 | 1 | |
802 | 1 |
|
804 | 1 | |
803 | 2 |
|
805 | 2 | |
@@ -810,7 +812,7 And pasting from IPython sessions works equally well:: | |||||
810 | In [1]: In [5]: def f(x): |
|
812 | In [1]: In [5]: def f(x): | |
811 | ...: ...: "A simple function" |
|
813 | ...: ...: "A simple function" | |
812 | ...: ...: return x**2 |
|
814 | ...: ...: return x**2 | |
813 |
...: ...: |
|
815 | ...: ...: | |
814 |
|
816 | |||
815 | In [2]: f(3) |
|
817 | In [2]: f(3) | |
816 | Out[2]: 9 |
|
818 | Out[2]: 9 | |
@@ -832,7 +834,7 advantages of this are: | |||||
832 | * GUIs can be enabled and disabled dynamically at runtime. |
|
834 | * GUIs can be enabled and disabled dynamically at runtime. | |
833 | * The active GUI can be switched dynamically at runtime. |
|
835 | * The active GUI can be switched dynamically at runtime. | |
834 | * In some cases, multiple GUIs can run simultaneously with no problems. |
|
836 | * In some cases, multiple GUIs can run simultaneously with no problems. | |
835 |
* There is a developer API in :mod:`IPython.lib.inputhook` for customizing |
|
837 | * There is a developer API in :mod:`IPython.lib.inputhook` for customizing | |
836 | all of these things. |
|
838 | all of these things. | |
837 |
|
839 | |||
838 | For users, enabling GUI event loop integration is simple. You simple use the |
|
840 | For users, enabling GUI event loop integration is simple. You simple use the | |
@@ -862,7 +864,7 form of a library, these capabilities are exposed in library form in the | |||||
862 | Interested developers should see the module docstrings for more information, |
|
864 | Interested developers should see the module docstrings for more information, | |
863 | but there are a few points that should be mentioned here. |
|
865 | but there are a few points that should be mentioned here. | |
864 |
|
866 | |||
865 |
First, the ``PyOSInputHook`` approach only works in command line settings |
|
867 | First, the ``PyOSInputHook`` approach only works in command line settings | |
866 | where readline is activated. The integration with various eventloops |
|
868 | where readline is activated. The integration with various eventloops | |
867 | is handled somewhat differently (and more simply) when using the standalone |
|
869 | is handled somewhat differently (and more simply) when using the standalone | |
868 | kernel, as in the qtconsole and notebook. |
|
870 | kernel, as in the qtconsole and notebook. | |
@@ -918,7 +920,7 neither v2 PyQt nor PySide work. | |||||
918 | Note that this means for ETS 4 to work with PyQt4, ``QT_API`` *must* be set |
|
920 | Note that this means for ETS 4 to work with PyQt4, ``QT_API`` *must* be set | |
919 | to work with IPython's qt integration, because otherwise PyQt4 will be |
|
921 | to work with IPython's qt integration, because otherwise PyQt4 will be | |
920 | loaded in an incompatible mode. |
|
922 | loaded in an incompatible mode. | |
921 |
|
923 | |||
922 | It also means that you must *not* have ``QT_API`` set if you want to |
|
924 | It also means that you must *not* have ``QT_API`` set if you want to | |
923 | use ``--gui=qt`` with code that requires PyQt4 API v1. |
|
925 | use ``--gui=qt`` with code that requires PyQt4 API v1. | |
924 |
|
926 |
@@ -74,12 +74,12 The class can implement optional methods for each of the available prompt types: | |||||
74 | - ``rewrite_prompt_tokens(self)`` |
|
74 | - ``rewrite_prompt_tokens(self)`` | |
75 | - ``out_prompt_tokens(self)`` |
|
75 | - ``out_prompt_tokens(self)`` | |
76 |
|
76 | |||
77 |
Each of these methods should return a list of `(TokenType, Token)` pairs. See documentation of `prompt_toolkit` and/or `Pygments`. |
|
77 | Each of these methods should return a list of `(TokenType, Token)` pairs. See documentation of `prompt_toolkit` and/or `Pygments`. | |
78 |
|
78 | |||
79 | Here is an example of Prompt class that will insert the current working directory in front of a prompt: |
|
79 | Here is an example of Prompt class that will insert the current working directory in front of a prompt: | |
80 |
|
80 | |||
81 |
|
81 | |||
82 |
.. codeblock:: python |
|
82 | .. code-block:: python | |
83 |
|
|
83 | ||
84 | from IPython.terminal.prompts import Prompts, Token |
|
84 | from IPython.terminal.prompts import Prompts, Token | |
85 | import os |
|
85 | import os | |
@@ -92,7 +92,7 Here is an example of Prompt class that will insert the current working director | |||||
92 |
|
92 | |||
93 | To set the new prompt, assign it to the `prompts` attribute of the IPython shell: |
|
93 | To set the new prompt, assign it to the `prompts` attribute of the IPython shell: | |
94 |
|
94 | |||
95 | .. codeblock:: python |
|
95 | .. code-block:: python | |
96 |
|
|
96 | ||
97 | In[2]: ip = get_ipython() |
|
97 | In[2]: ip = get_ipython() | |
98 | ...: ip.prompts = MyPrompt(ip) |
|
98 | ...: ip.prompts = MyPrompt(ip) | |
@@ -101,7 +101,7 To set the new prompt, assign it to the `prompts` attribute of the IPython shell | |||||
101 |
|
101 | |||
102 |
|
102 | |||
103 | See ``IPython/example/utils/cwd_prompt.py`` for an example of how to write an |
|
103 | See ``IPython/example/utils/cwd_prompt.py`` for an example of how to write an | |
104 |
extensions that customise prompts. |
|
104 | extensions that customise prompts. | |
105 |
|
105 | |||
106 |
|
106 | |||
107 | Read more about the :ref:`configuration system <config_overview>` for details |
|
107 | Read more about the :ref:`configuration system <config_overview>` for details | |
@@ -225,7 +225,7 First, capture output of "hg status":: | |||||
225 | 11: build\bdist.win32\winexe\temp\_hashlib.py |
|
225 | 11: build\bdist.win32\winexe\temp\_hashlib.py | |
226 | 12: build\bdist.win32\winexe\temp\_socket.py |
|
226 | 12: build\bdist.win32\winexe\temp\_socket.py | |
227 |
|
227 | |||
228 |
Now we can just remove these files by doing 'rm $junk.s'. |
|
228 | Now we can just remove these files by doing 'rm $junk.s'. | |
229 |
|
229 | |||
230 | The .s, .n, .p properties |
|
230 | The .s, .n, .p properties | |
231 | ------------------------- |
|
231 | ------------------------- |
General Comments 0
You need to be logged in to leave comments.
Login now