|
@@
-19,7
+19,7
b' 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
b' 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
b" 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
b' 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
b' 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
b' 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
b' 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
b' 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
b' 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
b' 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
b' 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
b' 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,7
+682,7
b' 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:
|
|
@@
-697,7
+697,7
b' context line to show. This allows to a many line of context on shallow stack tra'
|
|
697
|
...: 6
|
|
697
|
...: 6
|
|
698
|
...: 7
|
|
698
|
...: 7
|
|
699
|
...:
|
|
699
|
...:
|
|
700
|
|
|
700
|
|
|
701
|
In[6]: foo(1)
|
|
701
|
In[6]: foo(1)
|
|
702
|
# ...
|
|
702
|
# ...
|
|
703
|
ipdb> where 8
|
|
703
|
ipdb> where 8
|
|
@@
-797,7
+797,7
b' standard Python tutorial::'
|
|
797
|
In [4]: >>> while b < 10:
|
|
797
|
In [4]: >>> while b < 10:
|
|
798
|
...: ... print(b)
|
|
798
|
...: ... print(b)
|
|
799
|
...: ... a, b = b, a+b
|
|
799
|
...: ... a, b = b, a+b
|
|
800
|
...:
|
|
800
|
...:
|
|
801
|
1
|
|
801
|
1
|
|
802
|
1
|
|
802
|
1
|
|
803
|
2
|
|
803
|
2
|
|
@@
-810,7
+810,7
b' And pasting from IPython sessions works equally well::'
|
|
810
|
In [1]: In [5]: def f(x):
|
|
810
|
In [1]: In [5]: def f(x):
|
|
811
|
...: ...: "A simple function"
|
|
811
|
...: ...: "A simple function"
|
|
812
|
...: ...: return x**2
|
|
812
|
...: ...: return x**2
|
|
813
|
...: ...:
|
|
813
|
...: ...:
|
|
814
|
|
|
814
|
|
|
815
|
In [2]: f(3)
|
|
815
|
In [2]: f(3)
|
|
816
|
Out[2]: 9
|
|
816
|
Out[2]: 9
|
|
@@
-832,7
+832,7
b' advantages of this are:'
|
|
832
|
* GUIs can be enabled and disabled dynamically at runtime.
|
|
832
|
* GUIs can be enabled and disabled dynamically at runtime.
|
|
833
|
* The active GUI can be switched dynamically at runtime.
|
|
833
|
* The active GUI can be switched dynamically at runtime.
|
|
834
|
* In some cases, multiple GUIs can run simultaneously with no problems.
|
|
834
|
* In some cases, multiple GUIs can run simultaneously with no problems.
|
|
835
|
* There is a developer API in :mod:`IPython.lib.inputhook` for customizing
|
|
835
|
* There is a developer API in :mod:`IPython.lib.inputhook` for customizing
|
|
836
|
all of these things.
|
|
836
|
all of these things.
|
|
837
|
|
|
837
|
|
|
838
|
For users, enabling GUI event loop integration is simple. You simple use the
|
|
838
|
For users, enabling GUI event loop integration is simple. You simple use the
|
|
@@
-848,7
+848,7
b' object, do::'
|
|
848
|
|
|
848
|
|
|
849
|
%gui wx
|
|
849
|
%gui wx
|
|
850
|
|
|
850
|
|
|
851
|
You can also start IPython with an event loop set up using the :option:`--gui`
|
|
851
|
You can also start IPython with an event loop set up using the `--gui`
|
|
852
|
flag::
|
|
852
|
flag::
|
|
853
|
|
|
853
|
|
|
854
|
$ ipython --gui=qt
|
|
854
|
$ ipython --gui=qt
|
|
@@
-862,7
+862,7
b' form of a library, these capabilities are exposed in library form in the'
|
|
862
|
Interested developers should see the module docstrings for more information,
|
|
862
|
Interested developers should see the module docstrings for more information,
|
|
863
|
but there are a few points that should be mentioned here.
|
|
863
|
but there are a few points that should be mentioned here.
|
|
864
|
|
|
864
|
|
|
865
|
First, the ``PyOSInputHook`` approach only works in command line settings
|
|
865
|
First, the ``PyOSInputHook`` approach only works in command line settings
|
|
866
|
where readline is activated. The integration with various eventloops
|
|
866
|
where readline is activated. The integration with various eventloops
|
|
867
|
is handled somewhat differently (and more simply) when using the standalone
|
|
867
|
is handled somewhat differently (and more simply) when using the standalone
|
|
868
|
kernel, as in the qtconsole and notebook.
|
|
868
|
kernel, as in the qtconsole and notebook.
|
|
@@
-918,7
+918,7
b' neither v2 PyQt nor PySide work.'
|
|
918
|
Note that this means for ETS 4 to work with PyQt4, ``QT_API`` *must* be set
|
|
918
|
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
|
|
919
|
to work with IPython's qt integration, because otherwise PyQt4 will be
|
|
920
|
loaded in an incompatible mode.
|
|
920
|
loaded in an incompatible mode.
|
|
921
|
|
|
921
|
|
|
922
|
It also means that you must *not* have ``QT_API`` set if you want to
|
|
922
|
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.
|
|
923
|
use ``--gui=qt`` with code that requires PyQt4 API v1.
|
|
924
|
|
|
924
|
|