##// END OF EJS Templates
More moving around doc files.
Brian E Granger -
Show More
@@ -0,0 +1,7 b''
1 What's new in IPython
2 =====================
3
4 .. toctree::
5 :maxdepth: 1
6
7 changes.txt
@@ -0,0 +1,272 b''
1 =============================
2 Basic installation of IPython
3 =============================
4
5 Installation
6 ============
7
8 Instant instructions
9 --------------------
10
11 If you are of the impatient kind, under Linux/Unix simply untar/unzip
12 the download, then install with 'python setup.py install'. Under
13 Windows, double-click on the provided .exe binary installer.
14
15 Then, take a look at Customization_ section for configuring things
16 optimally and `Quick tips`_ for quick tips on efficient use of
17 IPython. You can later refer to the rest of the manual for all the
18 gory details.
19
20 See the notes in upgrading_ section for upgrading IPython versions.
21
22
23 Detailed Unix instructions (Linux, Mac OS X, etc.)
24
25 For RPM based systems, simply install the supplied package in the usual
26 manner. If you download the tar archive, the process is:
27
28 1. Unzip/untar the ipython-XXX.tar.gz file wherever you want (XXX is
29 the version number). It will make a directory called ipython-XXX.
30 Change into that directory where you will find the files README
31 and setup.py. Once you've completed the installation, you can
32 safely remove this directory.
33 2. If you are installing over a previous installation of version
34 0.2.0 or earlier, first remove your $HOME/.ipython directory,
35 since the configuration file format has changed somewhat (the '='
36 were removed from all option specifications). Or you can call
37 ipython with the -upgrade option and it will do this automatically
38 for you.
39 3. IPython uses distutils, so you can install it by simply typing at
40 the system prompt (don't type the $)::
41
42 $ python setup.py install
43
44 Note that this assumes you have root access to your machine. If
45 you don't have root access or don't want IPython to go in the
46 default python directories, you'll need to use the ``--home`` option
47 (or ``--prefix``). For example::
48
49 $ python setup.py install --home $HOME/local
50
51 will install IPython into $HOME/local and its subdirectories
52 (creating them if necessary).
53 You can type::
54
55 $ python setup.py --help
56
57 for more details.
58
59 Note that if you change the default location for ``--home`` at
60 installation, IPython may end up installed at a location which is
61 not part of your $PYTHONPATH environment variable. In this case,
62 you'll need to configure this variable to include the actual
63 directory where the IPython/ directory ended (typically the value
64 you give to ``--home`` plus /lib/python).
65
66
67 Mac OSX information
68 -------------------
69
70 Under OSX, there is a choice you need to make. Apple ships its own build
71 of Python, which lives in the core OSX filesystem hierarchy. You can
72 also manually install a separate Python, either purely by hand
73 (typically in /usr/local) or by using Fink, which puts everything under
74 /sw. Which route to follow is a matter of personal preference, as I've
75 seen users who favor each of the approaches. Here I will simply list the
76 known installation issues under OSX, along with their solutions.
77
78 This page: http://geosci.uchicago.edu/~tobis/pylab.html contains
79 information on this topic, with additional details on how to make
80 IPython and matplotlib play nicely under OSX.
81
82 To run IPython and readline on OSX "Leopard" system python, see the
83 wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard
84
85
86 GUI problems
87 ------------
88
89 The following instructions apply to an install of IPython under OSX from
90 unpacking the .tar.gz distribution and installing it for the default
91 Python interpreter shipped by Apple. If you are using a fink install,
92 fink will take care of these details for you, by installing IPython
93 against fink's Python.
94
95 IPython offers various forms of support for interacting with graphical
96 applications from the command line, from simple Tk apps (which are in
97 principle always supported by Python) to interactive control of WX, Qt
98 and GTK apps. Under OSX, however, this requires that ipython is
99 installed by calling the special pythonw script at installation time,
100 which takes care of coordinating things with Apple's graphical environment.
101
102 So when installing under OSX, it is best to use the following command::
103
104 $ sudo pythonw setup.py install --install-scripts=/usr/local/bin
105
106 or
107
108 $ sudo pythonw setup.py install --install-scripts=/usr/bin
109
110 depending on where you like to keep hand-installed executables.
111
112 The resulting script will have an appropriate shebang line (the first
113 line in the script whic begins with #!...) such that the ipython
114 interpreter can interact with the OS X GUI. If the installed version
115 does not work and has a shebang line that points to, for example, just
116 /usr/bin/python, then you might have a stale, cached version in your
117 build/scripts-<python-version> directory. Delete that directory and
118 rerun the setup.py.
119
120 It is also a good idea to use the special flag ``--install-scripts`` as
121 indicated above, to ensure that the ipython scripts end up in a location
122 which is part of your $PATH. Otherwise Apple's Python will put the
123 scripts in an internal directory not available by default at the command
124 line (if you use /usr/local/bin, you need to make sure this is in your
125 $PATH, which may not be true by default).
126
127
128 Readline problems
129 -----------------
130
131 By default, the Python version shipped by Apple does not include the
132 readline library, so central to IPython's behavior. If you install
133 IPython against Apple's Python, you will not have arrow keys, tab
134 completion, etc. For Mac OSX 10.3 (Panther), you can find a prebuilt
135 readline library here:
136 http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip
137
138 If you are using OSX 10.4 (Tiger), after installing this package you
139 need to either:
140
141 1. move readline.so from /Library/Python/2.3 to
142 /Library/Python/2.3/site-packages, or
143 2. install http://pythonmac.org/packages/TigerPython23Compat.pkg.zip
144
145 Users installing against Fink's Python or a properly hand-built one
146 should not have this problem.
147
148
149 DarwinPorts
150 -----------
151
152 I report here a message from an OSX user, who suggests an alternative
153 means of using IPython under this operating system with good results.
154 Please let me know of any updates that may be useful for this section.
155 His message is reproduced verbatim below:
156
157 From: Markus Banfi <markus.banfi-AT-mospheira.net>
158
159 As a MacOS X (10.4.2) user I prefer to install software using
160 DawinPorts instead of Fink. I had no problems installing ipython
161 with DarwinPorts. It's just:
162
163 sudo port install py-ipython
164
165 It automatically resolved all dependencies (python24, readline,
166 py-readline). So far I did not encounter any problems with the
167 DarwinPorts port of ipython.
168
169
170
171 Windows instructions
172 --------------------
173
174 Some of IPython's very useful features are:
175
176 * Integrated readline support (Tab-based file, object and attribute
177 completion, input history across sessions, editable command line,
178 etc.)
179 * Coloring of prompts, code and tracebacks.
180
181 .. _pyreadline:
182
183 These, by default, are only available under Unix-like operating systems.
184 However, thanks to Gary Bishop's work, Windows XP/2k users can also
185 benefit from them. His readline library originally implemented both GNU
186 readline functionality and color support, so that IPython under Windows
187 XP/2k can be as friendly and powerful as under Unix-like environments.
188
189 This library, now named PyReadline, has been absorbed by the IPython
190 team (Jörgen Stenarson, in particular), and it continues to be developed
191 with new features, as well as being distributed directly from the
192 IPython site.
193
194 The PyReadline extension requires CTypes and the windows IPython
195 installer needs PyWin32, so in all you need:
196
197 1. PyWin32 from http://sourceforge.net/projects/pywin32.
198 2. PyReadline for Windows from
199 http://ipython.scipy.org/moin/PyReadline/Intro. That page contains
200 further details on using and configuring the system to your liking.
201 3. Finally, only if you are using Python 2.3 or 2.4, you need CTypes
202 from http://starship.python.net/crew/theller/ctypes(you must use
203 version 0.9.1 or newer). This package is included in Python 2.5,
204 so you don't need to manually get it if your Python version is 2.5
205 or newer.
206
207 Warning about a broken readline-like library: several users have
208 reported problems stemming from using the pseudo-readline library at
209 http://newcenturycomputers.net/projects/readline.html. This is a broken
210 library which, while called readline, only implements an incomplete
211 subset of the readline API. Since it is still called readline, it fools
212 IPython's detection mechanisms and causes unpredictable crashes later.
213 If you wish to use IPython under Windows, you must NOT use this library,
214 which for all purposes is (at least as of version 1.6) terminally broken.
215
216
217 Installation procedure
218 ----------------------
219
220 Once you have the above installed, from the IPython download directory
221 grab the ipython-XXX.win32.exe file, where XXX represents the version
222 number. This is a regular windows executable installer, which you can
223 simply double-click to install. It will add an entry for IPython to your
224 Start Menu, as well as registering IPython in the Windows list of
225 applications, so you can later uninstall it from the Control Panel.
226
227 IPython tries to install the configuration information in a directory
228 named .ipython (_ipython under Windows) located in your 'home'
229 directory. IPython sets this directory by looking for a HOME environment
230 variable; if such a variable does not exist, it uses HOMEDRIVE\HOMEPATH
231 (these are always defined by Windows). This typically gives something
232 like C:\Documents and Settings\YourUserName, but your local details may
233 vary. In this directory you will find all the files that configure
234 IPython's defaults, and you can put there your profiles and extensions.
235 This directory is automatically added by IPython to sys.path, so
236 anything you place there can be found by import statements.
237
238
239 Upgrading
240 ---------
241
242 For an IPython upgrade, you should first uninstall the previous version.
243 This will ensure that all files and directories (such as the
244 documentation) which carry embedded version strings in their names are
245 properly removed.
246
247
248 Manual installation under Win32
249 -------------------------------
250
251 In case the automatic installer does not work for some reason, you can
252 download the ipython-XXX.tar.gz file, which contains the full IPython
253 source distribution (the popular WinZip can read .tar.gz files). After
254 uncompressing the archive, you can install it at a command terminal just
255 like any other Python module, by using 'python setup.py install'.
256
257 After the installation, run the supplied win32_manual_post_install.py
258 script, which creates the necessary Start Menu shortcuts for you.
259
260
261 .. upgrading:
262
263 Upgrading from a previous version
264 ---------------------------------
265
266 If you are upgrading from a previous version of IPython, you may want
267 to upgrade the contents of your ~/.ipython directory. Just run
268 %upgrade, look at the diffs and delete the suggested files manually,
269 if you think you can lose the old versions. %upgrade will never
270 overwrite or delete anything.
271
272
1 NO CONTENT: file renamed from docs/source/parallel/faq.txt to docs/source/faq.txt
NO CONTENT: file renamed from docs/source/parallel/faq.txt to docs/source/faq.txt
@@ -0,0 +1,3 b''
1 ======================
2 The History of IPython
3 ======================
@@ -1,169 +1,173 b''
1 =========================================
2 Advanced installation options for IPython
3 =========================================
4
1 .. _install:
5 .. _install:
2
6
3 ===================
7 ===================
4 Installing IPython
8 Installing IPython
5 ===================
9 ===================
6
10
7 .. contents::
11 .. contents::
8
12
9 Introduction
13 Introduction
10 ============
14 ============
11
15
12 IPython enables parallel applications to be developed in Python. This document
16 IPython enables parallel applications to be developed in Python. This document
13 describes the steps required to install IPython. For an overview of IPython's
17 describes the steps required to install IPython. For an overview of IPython's
14 architecture as it relates to parallel computing, see our :ref:`introduction to
18 architecture as it relates to parallel computing, see our :ref:`introduction to
15 parallel computing with IPython <ip1par>`.
19 parallel computing with IPython <ip1par>`.
16
20
17 Please let us know if you have problems installing IPython or any of its
21 Please let us know if you have problems installing IPython or any of its
18 dependencies. We have tested IPython extensively with Python 2.4 and 2.5.
22 dependencies. We have tested IPython extensively with Python 2.4 and 2.5.
19
23
20 .. warning::
24 .. warning::
21
25
22 IPython will not work with Python 2.3 or below.
26 IPython will not work with Python 2.3 or below.
23
27
24 IPython has three required dependencies:
28 IPython has three required dependencies:
25
29
26 1. `IPython`__
30 1. `IPython`__
27 2. `Zope Interface`__
31 2. `Zope Interface`__
28 3. `Twisted`__
32 3. `Twisted`__
29 4. `Foolscap`__
33 4. `Foolscap`__
30
34
31 .. __: http://ipython.scipy.org
35 .. __: http://ipython.scipy.org
32 .. __: http://pypi.python.org/pypi/zope.interface
36 .. __: http://pypi.python.org/pypi/zope.interface
33 .. __: http://twistedmatrix.com
37 .. __: http://twistedmatrix.com
34 .. __: http://foolscap.lothar.com/trac
38 .. __: http://foolscap.lothar.com/trac
35
39
36 It also has the following optional dependencies:
40 It also has the following optional dependencies:
37
41
38 1. pexpect (used for certain tests)
42 1. pexpect (used for certain tests)
39 2. nose (used to run our test suite)
43 2. nose (used to run our test suite)
40 3. sqlalchemy (used for database support)
44 3. sqlalchemy (used for database support)
41 4. mpi4py (for MPI support)
45 4. mpi4py (for MPI support)
42 5. Sphinx and pygments (for building documentation)
46 5. Sphinx and pygments (for building documentation)
43 6. pyOpenSSL (for security)
47 6. pyOpenSSL (for security)
44
48
45 Getting IPython
49 Getting IPython
46 ================
50 ================
47
51
48 IPython development has been moved to `Launchpad`_. The development branch of IPython can be checkout out using `Bazaar`_::
52 IPython development has been moved to `Launchpad`_. The development branch of IPython can be checkout out using `Bazaar`_::
49
53
50 $ bzr branch lp:///~ipython/ipython/ipython1-dev
54 $ bzr branch lp:///~ipython/ipython/ipython1-dev
51
55
52 .. _Launchpad: http://www.launchpad.net/ipython
56 .. _Launchpad: http://www.launchpad.net/ipython
53 .. _Bazaar: http://bazaar-vcs.org/
57 .. _Bazaar: http://bazaar-vcs.org/
54
58
55 Installation using setuptools
59 Installation using setuptools
56 =============================
60 =============================
57
61
58 The easiest way of installing IPython and its dependencies is using
62 The easiest way of installing IPython and its dependencies is using
59 `setuptools`_. If you have setuptools installed you can simple use the ``easy_install``
63 `setuptools`_. If you have setuptools installed you can simple use the ``easy_install``
60 script that comes with setuptools (this should be on your path if you have setuptools)::
64 script that comes with setuptools (this should be on your path if you have setuptools)::
61
65
62 $ easy_install ipython1
66 $ easy_install ipython1
63
67
64 This will download and install the latest version of IPython as well as all of its dependencies. For this to work, you will need to be connected to the internet when you run this command. This will install everything info the ``site-packages`` directory of your Python distribution. If this is the system wide Python, you will likely need admin privileges. For information about installing Python packages to other locations (that don't require admin privileges) see the `setuptools`_ documentation.
68 This will download and install the latest version of IPython as well as all of its dependencies. For this to work, you will need to be connected to the internet when you run this command. This will install everything info the ``site-packages`` directory of your Python distribution. If this is the system wide Python, you will likely need admin privileges. For information about installing Python packages to other locations (that don't require admin privileges) see the `setuptools`_ documentation.
65
69
66 .. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
70 .. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
67
71
68 If you don't want `setuptools`_ to automatically install the dependencies, you can also get the dependencies yourself, using ``easy_install``::
72 If you don't want `setuptools`_ to automatically install the dependencies, you can also get the dependencies yourself, using ``easy_install``::
69
73
70 $ easy_install IPython
74 $ easy_install IPython
71 $ easy_install zope.interface
75 $ easy_install zope.interface
72 $ easy_install Twisted
76 $ easy_install Twisted
73 $ easy_install foolscap
77 $ easy_install foolscap
74
78
75 or by simply downloading and installing the dependencies manually.
79 or by simply downloading and installing the dependencies manually.
76
80
77 If you want to have secure (highly recommended) network connections, you will also
81 If you want to have secure (highly recommended) network connections, you will also
78 need to get `pyOpenSSL`__, version 0.6, or just do:
82 need to get `pyOpenSSL`__, version 0.6, or just do:
79
83
80 $ easy_install ipython1[security]
84 $ easy_install ipython1[security]
81
85
82 .. hint:: If you want to do development on IPython and want to always
86 .. hint:: If you want to do development on IPython and want to always
83 run off your development branch, you can run
87 run off your development branch, you can run
84 :command:`python setupegg.py develop` in the IPython source tree.
88 :command:`python setupegg.py develop` in the IPython source tree.
85
89
86 .. __: http://pyopenssl.sourceforge.net/
90 .. __: http://pyopenssl.sourceforge.net/
87
91
88 Installation using plain distutils
92 Installation using plain distutils
89 ==================================
93 ==================================
90
94
91 If you don't have `setuptools`_ installed or don't want to use it, you can also install IPython and its dependencies using ``distutils``. In this approach, you will need to get the most recent stable releases of IPython's dependencies and install each of them by doing::
95 If you don't have `setuptools`_ installed or don't want to use it, you can also install IPython and its dependencies using ``distutils``. In this approach, you will need to get the most recent stable releases of IPython's dependencies and install each of them by doing::
92
96
93 $ python setup.py install
97 $ python setup.py install
94
98
95 The dependencies need to be installed before installing IPython. After installing the dependencies, install IPython by running::
99 The dependencies need to be installed before installing IPython. After installing the dependencies, install IPython by running::
96
100
97 $ cd ipython1-dev
101 $ cd ipython1-dev
98 $ python setup.py install
102 $ python setup.py install
99
103
100 .. note:: Here we are using setup.py rather than setupegg.py.
104 .. note:: Here we are using setup.py rather than setupegg.py.
101
105
102 .. _install_config:
106 .. _install_config:
103
107
104 Configuration
108 Configuration
105 =============
109 =============
106
110
107 IPython has a configuration system. When running IPython for the first time,
111 IPython has a configuration system. When running IPython for the first time,
108 reasonable defaults are used for the configuration. The configuration of IPython
112 reasonable defaults are used for the configuration. The configuration of IPython
109 can be changed in two ways:
113 can be changed in two ways:
110
114
111 * Configuration files
115 * Configuration files
112 * Commands line options (which override the configuration files)
116 * Commands line options (which override the configuration files)
113
117
114 IPython has a separate configuration file for each subpackage. Thus, the main
118 IPython has a separate configuration file for each subpackage. Thus, the main
115 configuration files are (in your ``~/.ipython`` directory):
119 configuration files are (in your ``~/.ipython`` directory):
116
120
117 * ``ipython1.core.ini``
121 * ``ipython1.core.ini``
118 * ``ipython1.kernel.ini``
122 * ``ipython1.kernel.ini``
119 * ``ipython1.notebook.ini``
123 * ``ipython1.notebook.ini``
120
124
121 To create these files for the first time, do the following::
125 To create these files for the first time, do the following::
122
126
123 from ipython1.kernel.config import config_manager as kernel_config
127 from ipython1.kernel.config import config_manager as kernel_config
124 kernel_config.write_default_config_file()
128 kernel_config.write_default_config_file()
125
129
126 But, you should only need to do this if you need to modify the defaults. If needed
130 But, you should only need to do this if you need to modify the defaults. If needed
127 repeat this process with the ``notebook`` and ``core`` configuration as well. If you
131 repeat this process with the ``notebook`` and ``core`` configuration as well. If you
128 are running into problems with IPython, you might try deleting these configuration
132 are running into problems with IPython, you might try deleting these configuration
129 files.
133 files.
130
134
131 .. _install_testing:
135 .. _install_testing:
132
136
133 Testing
137 Testing
134 =======
138 =======
135
139
136 Once you have completed the installation of the IPython kernel you can run our test suite
140 Once you have completed the installation of the IPython kernel you can run our test suite
137 with the command::
141 with the command::
138
142
139 trial ipython1
143 trial ipython1
140
144
141 Or if you have `nose`__ installed::
145 Or if you have `nose`__ installed::
142
146
143 nosetests -v ipython1
147 nosetests -v ipython1
144
148
145 The ``trial`` command is part of Twisted and allows asynchronous network based
149 The ``trial`` command is part of Twisted and allows asynchronous network based
146 applications to be tested using Python's unittest framework. Please let us know
150 applications to be tested using Python's unittest framework. Please let us know
147 if the tests do not pass. The best way to get in touch with us is on the `IPython
151 if the tests do not pass. The best way to get in touch with us is on the `IPython
148 developer mailing list`_.
152 developer mailing list`_.
149
153
150 .. __: http://somethingaboutorange.com/mrl/projects/nose/
154 .. __: http://somethingaboutorange.com/mrl/projects/nose/
151 .. _IPython developer mailing list: http://projects.scipy.org/mailman/listinfo/ipython-dev
155 .. _IPython developer mailing list: http://projects.scipy.org/mailman/listinfo/ipython-dev
152
156
153 MPI Support
157 MPI Support
154 ===========
158 ===========
155
159
156 IPython includes optional support for the Message Passing Interface (`MPI`_),
160 IPython includes optional support for the Message Passing Interface (`MPI`_),
157 which enables the IPython Engines to pass data between each other using `MPI`_. To use MPI with IPython, the minimal requirements are:
161 which enables the IPython Engines to pass data between each other using `MPI`_. To use MPI with IPython, the minimal requirements are:
158
162
159 * An MPI implementation (we recommend `Open MPI`_)
163 * An MPI implementation (we recommend `Open MPI`_)
160 * A way to call MPI (we recommend `mpi4py`_)
164 * A way to call MPI (we recommend `mpi4py`_)
161
165
162 But, IPython should work with any MPI implementation and with any code
166 But, IPython should work with any MPI implementation and with any code
163 (Python/C/C++/Fortran) that uses MPI. Please contact us for more information about
167 (Python/C/C++/Fortran) that uses MPI. Please contact us for more information about
164 this.
168 this.
165
169
166 .. _MPI: http://www-unix.mcs.anl.gov/mpi/
170 .. _MPI: http://www-unix.mcs.anl.gov/mpi/
167 .. _mpi4py: http://mpi4py.scipy.org/
171 .. _mpi4py: http://mpi4py.scipy.org/
168 .. _Open MPI: http://www.open-mpi.org/
172 .. _Open MPI: http://www.open-mpi.org/
169
173
@@ -1,16 +1,11 b''
1 IPython kernel documentation
1 IPython kernel documentation
2 ============================
2 ============================
3
3
4 User Documentation
4 User Documentation
5 ------------------
5 ------------------
6
6
7 .. toctree::
7 .. toctree::
8 :maxdepth: 2
8 :maxdepth: 2
9
9
10 install.txt
10 basic.txt
11 parallel_intro.txt
11 advanced.txt
12 parallel_multiengine.txt
13 parallel_task.txt
14 parallel_mpi.txt
15 changes.txt
16 faq.txt
@@ -1,5879 +1,5612 b''
1 .. IPython documentation master file, created by sphinx-quickstart.py on Mon Mar 24 17:01:34 2008.
1 .. IPython documentation master file, created by sphinx-quickstart.py on Mon Mar 24 17:01:34 2008.
2 You can adapt this file completely to your liking, but it should at least
2 You can adapt this file completely to your liking, but it should at least
3 contain the root 'toctree' directive.
3 contain the root 'toctree' directive.
4
4
5 IPython documentation
5 IPython documentation
6 =====================
6 =====================
7
7
8 Contents:
8 Contents:
9
9
10 .. toctree::
10 .. toctree::
11 :maxdepth: 2
11 :maxdepth: 2
12
12
13 Indices and tables
13 Indices and tables
14 ==================
14 ==================
15
15
16 * :ref:`genindex`
16 * :ref:`genindex`
17 * :ref:`modindex`
17 * :ref:`modindex`
18 * :ref:`search`
18 * :ref:`search`
19
19
20 Introduction
20 Introduction
21 ============
21 ============
22
22
23 This is the official documentation for IPython 0.x series (i.e. what
23 This is the official documentation for IPython 0.x series (i.e. what
24 we are used to refer to just as "IPython"). The original text of the
24 we are used to refer to just as "IPython"). The original text of the
25 manual (most of which is still in place) has been authored by Fernando
25 manual (most of which is still in place) has been authored by Fernando
26 Perez, but as recommended usage patterns and new features have
26 Perez, but as recommended usage patterns and new features have
27 emerged, this manual has been updated to reflect that fact. Most of
27 emerged, this manual has been updated to reflect that fact. Most of
28 the additions have been authored by Ville M. Vainio.
28 the additions have been authored by Ville M. Vainio.
29
29
30 The manual has been generated from reStructuredText source markup with
30 The manual has been generated from reStructuredText source markup with
31 Sphinx, which should make it much easier to keep it up-to-date in the
31 Sphinx, which should make it much easier to keep it up-to-date in the
32 future. Some reST artifacts and bugs may still be apparent in the
32 future. Some reST artifacts and bugs may still be apparent in the
33 documentation, but this should improve as the toolchain matures.
33 documentation, but this should improve as the toolchain matures.
34
34
35 Overview
35 Overview
36 ========
36 ========
37
37
38 One of Python's most useful features is its interactive interpreter.
38 One of Python's most useful features is its interactive interpreter.
39 This system allows very fast testing of ideas without the overhead of
39 This system allows very fast testing of ideas without the overhead of
40 creating test files as is typical in most programming languages.
40 creating test files as is typical in most programming languages.
41 However, the interpreter supplied with the standard Python distribution
41 However, the interpreter supplied with the standard Python distribution
42 is somewhat limited for extended interactive use.
42 is somewhat limited for extended interactive use.
43
43
44 IPython is a free software project (released under the BSD license)
44 IPython is a free software project (released under the BSD license)
45 which tries to:
45 which tries to:
46
46
47 1. Provide an interactive shell superior to Python's default. IPython
47 1. Provide an interactive shell superior to Python's default. IPython
48 has many features for object introspection, system shell access,
48 has many features for object introspection, system shell access,
49 and its own special command system for adding functionality when
49 and its own special command system for adding functionality when
50 working interactively. It tries to be a very efficient environment
50 working interactively. It tries to be a very efficient environment
51 both for Python code development and for exploration of problems
51 both for Python code development and for exploration of problems
52 using Python objects (in situations like data analysis).
52 using Python objects (in situations like data analysis).
53 2. Serve as an embeddable, ready to use interpreter for your own
53 2. Serve as an embeddable, ready to use interpreter for your own
54 programs. IPython can be started with a single call from inside
54 programs. IPython can be started with a single call from inside
55 another program, providing access to the current namespace. This
55 another program, providing access to the current namespace. This
56 can be very useful both for debugging purposes and for situations
56 can be very useful both for debugging purposes and for situations
57 where a blend of batch-processing and interactive exploration are
57 where a blend of batch-processing and interactive exploration are
58 needed.
58 needed.
59 3. Offer a flexible framework which can be used as the base
59 3. Offer a flexible framework which can be used as the base
60 environment for other systems with Python as the underlying
60 environment for other systems with Python as the underlying
61 language. Specifically scientific environments like Mathematica,
61 language. Specifically scientific environments like Mathematica,
62 IDL and Matlab inspired its design, but similar ideas can be
62 IDL and Matlab inspired its design, but similar ideas can be
63 useful in many fields.
63 useful in many fields.
64 4. Allow interactive testing of threaded graphical toolkits. IPython
64 4. Allow interactive testing of threaded graphical toolkits. IPython
65 has support for interactive, non-blocking control of GTK, Qt and
65 has support for interactive, non-blocking control of GTK, Qt and
66 WX applications via special threading flags. The normal Python
66 WX applications via special threading flags. The normal Python
67 shell can only do this for Tkinter applications.
67 shell can only do this for Tkinter applications.
68
68
69
69
70 Main features
70 Main features
71 -------------
71 -------------
72
72
73 * Dynamic object introspection. One can access docstrings, function
73 * Dynamic object introspection. One can access docstrings, function
74 definition prototypes, source code, source files and other details
74 definition prototypes, source code, source files and other details
75 of any object accessible to the interpreter with a single
75 of any object accessible to the interpreter with a single
76 keystroke ('?', and using '??' provides additional detail).
76 keystroke ('?', and using '??' provides additional detail).
77 * Searching through modules and namespaces with '*' wildcards, both
77 * Searching through modules and namespaces with '*' wildcards, both
78 when using the '?' system and via the %psearch command.
78 when using the '?' system and via the %psearch command.
79 * Completion in the local namespace, by typing TAB at the prompt.
79 * Completion in the local namespace, by typing TAB at the prompt.
80 This works for keywords, modules, methods, variables and files in the
80 This works for keywords, modules, methods, variables and files in the
81 current directory. This is supported via the readline library, and
81 current directory. This is supported via the readline library, and
82 full access to configuring readline's behavior is provided.
82 full access to configuring readline's behavior is provided.
83 Custom completers can be implemented easily for different purposes
83 Custom completers can be implemented easily for different purposes
84 (system commands, magic arguments etc.)
84 (system commands, magic arguments etc.)
85 * Numbered input/output prompts with command history (persistent
85 * Numbered input/output prompts with command history (persistent
86 across sessions and tied to each profile), full searching in this
86 across sessions and tied to each profile), full searching in this
87 history and caching of all input and output.
87 history and caching of all input and output.
88 * User-extensible 'magic' commands. A set of commands prefixed with
88 * User-extensible 'magic' commands. A set of commands prefixed with
89 % is available for controlling IPython itself and provides
89 % is available for controlling IPython itself and provides
90 directory control, namespace information and many aliases to
90 directory control, namespace information and many aliases to
91 common system shell commands.
91 common system shell commands.
92 * Alias facility for defining your own system aliases.
92 * Alias facility for defining your own system aliases.
93 * Complete system shell access. Lines starting with ! are passed
93 * Complete system shell access. Lines starting with ! are passed
94 directly to the system shell, and using !! or var = !cmd
94 directly to the system shell, and using !! or var = !cmd
95 captures shell output into python variables for further use.
95 captures shell output into python variables for further use.
96 * Background execution of Python commands in a separate thread.
96 * Background execution of Python commands in a separate thread.
97 IPython has an internal job manager called jobs, and a
97 IPython has an internal job manager called jobs, and a
98 conveninence backgrounding magic function called %bg.
98 conveninence backgrounding magic function called %bg.
99 * The ability to expand python variables when calling the system
99 * The ability to expand python variables when calling the system
100 shell. In a shell command, any python variable prefixed with $ is
100 shell. In a shell command, any python variable prefixed with $ is
101 expanded. A double $$ allows passing a literal $ to the shell (for
101 expanded. A double $$ allows passing a literal $ to the shell (for
102 access to shell and environment variables like $PATH).
102 access to shell and environment variables like $PATH).
103 * Filesystem navigation, via a magic %cd command, along with a
103 * Filesystem navigation, via a magic %cd command, along with a
104 persistent bookmark system (using %bookmark) for fast access to
104 persistent bookmark system (using %bookmark) for fast access to
105 frequently visited directories.
105 frequently visited directories.
106 * A lightweight persistence framework via the %store command, which
106 * A lightweight persistence framework via the %store command, which
107 allows you to save arbitrary Python variables. These get restored
107 allows you to save arbitrary Python variables. These get restored
108 automatically when your session restarts.
108 automatically when your session restarts.
109 * Automatic indentation (optional) of code as you type (through the
109 * Automatic indentation (optional) of code as you type (through the
110 readline library).
110 readline library).
111 * Macro system for quickly re-executing multiple lines of previous
111 * Macro system for quickly re-executing multiple lines of previous
112 input with a single name. Macros can be stored persistently via
112 input with a single name. Macros can be stored persistently via
113 %store and edited via %edit.
113 %store and edited via %edit.
114 * Session logging (you can then later use these logs as code in your
114 * Session logging (you can then later use these logs as code in your
115 programs). Logs can optionally timestamp all input, and also store
115 programs). Logs can optionally timestamp all input, and also store
116 session output (marked as comments, so the log remains valid
116 session output (marked as comments, so the log remains valid
117 Python source code).
117 Python source code).
118 * Session restoring: logs can be replayed to restore a previous
118 * Session restoring: logs can be replayed to restore a previous
119 session to the state where you left it.
119 session to the state where you left it.
120 * Verbose and colored exception traceback printouts. Easier to parse
120 * Verbose and colored exception traceback printouts. Easier to parse
121 visually, and in verbose mode they produce a lot of useful
121 visually, and in verbose mode they produce a lot of useful
122 debugging information (basically a terminal version of the cgitb
122 debugging information (basically a terminal version of the cgitb
123 module).
123 module).
124 * Auto-parentheses: callable objects can be executed without
124 * Auto-parentheses: callable objects can be executed without
125 parentheses: 'sin 3' is automatically converted to 'sin(3)'.
125 parentheses: 'sin 3' is automatically converted to 'sin(3)'.
126 * Auto-quoting: using ',' or ';' as the first character forces
126 * Auto-quoting: using ',' or ';' as the first character forces
127 auto-quoting of the rest of the line: ',my_function a b' becomes
127 auto-quoting of the rest of the line: ',my_function a b' becomes
128 automatically 'my_function("a","b")', while ';my_function a b'
128 automatically 'my_function("a","b")', while ';my_function a b'
129 becomes 'my_function("a b")'.
129 becomes 'my_function("a b")'.
130 * Extensible input syntax. You can define filters that pre-process
130 * Extensible input syntax. You can define filters that pre-process
131 user input to simplify input in special situations. This allows
131 user input to simplify input in special situations. This allows
132 for example pasting multi-line code fragments which start with
132 for example pasting multi-line code fragments which start with
133 '>>>' or '...' such as those from other python sessions or the
133 '>>>' or '...' such as those from other python sessions or the
134 standard Python documentation.
134 standard Python documentation.
135 * Flexible configuration system. It uses a configuration file which
135 * Flexible configuration system. It uses a configuration file which
136 allows permanent setting of all command-line options, module
136 allows permanent setting of all command-line options, module
137 loading, code and file execution. The system allows recursive file
137 loading, code and file execution. The system allows recursive file
138 inclusion, so you can have a base file with defaults and layers
138 inclusion, so you can have a base file with defaults and layers
139 which load other customizations for particular projects.
139 which load other customizations for particular projects.
140 * Embeddable. You can call IPython as a python shell inside your own
140 * Embeddable. You can call IPython as a python shell inside your own
141 python programs. This can be used both for debugging code or for
141 python programs. This can be used both for debugging code or for
142 providing interactive abilities to your programs with knowledge
142 providing interactive abilities to your programs with knowledge
143 about the local namespaces (very useful in debugging and data
143 about the local namespaces (very useful in debugging and data
144 analysis situations).
144 analysis situations).
145 * Easy debugger access. You can set IPython to call up an enhanced
145 * Easy debugger access. You can set IPython to call up an enhanced
146 version of the Python debugger (pdb) every time there is an
146 version of the Python debugger (pdb) every time there is an
147 uncaught exception. This drops you inside the code which triggered
147 uncaught exception. This drops you inside the code which triggered
148 the exception with all the data live and it is possible to
148 the exception with all the data live and it is possible to
149 navigate the stack to rapidly isolate the source of a bug. The
149 navigate the stack to rapidly isolate the source of a bug. The
150 %run magic command -with the -d option- can run any script under
150 %run magic command -with the -d option- can run any script under
151 pdb's control, automatically setting initial breakpoints for you.
151 pdb's control, automatically setting initial breakpoints for you.
152 This version of pdb has IPython-specific improvements, including
152 This version of pdb has IPython-specific improvements, including
153 tab-completion and traceback coloring support. For even easier
153 tab-completion and traceback coloring support. For even easier
154 debugger access, try %debug after seeing an exception. winpdb is
154 debugger access, try %debug after seeing an exception. winpdb is
155 also supported, see ipy_winpdb extension.
155 also supported, see ipy_winpdb extension.
156 * Profiler support. You can run single statements (similar to
156 * Profiler support. You can run single statements (similar to
157 profile.run()) or complete programs under the profiler's control.
157 profile.run()) or complete programs under the profiler's control.
158 While this is possible with standard cProfile or profile modules,
158 While this is possible with standard cProfile or profile modules,
159 IPython wraps this functionality with magic commands (see '%prun'
159 IPython wraps this functionality with magic commands (see '%prun'
160 and '%run -p') convenient for rapid interactive work.
160 and '%run -p') convenient for rapid interactive work.
161 * Doctest support. The special %doctest_mode command toggles a mode
161 * Doctest support. The special %doctest_mode command toggles a mode
162 that allows you to paste existing doctests (with leading '>>>'
162 that allows you to paste existing doctests (with leading '>>>'
163 prompts and whitespace) and uses doctest-compatible prompts and
163 prompts and whitespace) and uses doctest-compatible prompts and
164 output, so you can use IPython sessions as doctest code.
164 output, so you can use IPython sessions as doctest code.
165
165
166
166
167 Portability and Python requirements
167 Portability and Python requirements
168 -----------------------------------
168 -----------------------------------
169
169
170 Python requirements: IPython requires with Python version 2.3 or newer.
170 Python requirements: IPython requires with Python version 2.3 or newer.
171 If you are still using Python 2.2 and can not upgrade, the last version
171 If you are still using Python 2.2 and can not upgrade, the last version
172 of IPython which worked with Python 2.2 was 0.6.15, so you will have to
172 of IPython which worked with Python 2.2 was 0.6.15, so you will have to
173 use that.
173 use that.
174
174
175 IPython is developed under Linux, but it should work in any reasonable
175 IPython is developed under Linux, but it should work in any reasonable
176 Unix-type system (tested OK under Solaris and the BSD family, for which
176 Unix-type system (tested OK under Solaris and the BSD family, for which
177 a port exists thanks to Dryice Liu).
177 a port exists thanks to Dryice Liu).
178
178
179 Mac OS X: it works, apparently without any problems (thanks to Jim Boyle
179 Mac OS X: it works, apparently without any problems (thanks to Jim Boyle
180 at Lawrence Livermore for the information). Thanks to Andrea Riciputi,
180 at Lawrence Livermore for the information). Thanks to Andrea Riciputi,
181 Fink support is available.
181 Fink support is available.
182
182
183 CygWin: it works mostly OK, though some users have reported problems
183 CygWin: it works mostly OK, though some users have reported problems
184 with prompt coloring. No satisfactory solution to this has been found so
184 with prompt coloring. No satisfactory solution to this has been found so
185 far, you may want to disable colors permanently in the ipythonrc
185 far, you may want to disable colors permanently in the ipythonrc
186 configuration file if you experience problems. If you have proper color
186 configuration file if you experience problems. If you have proper color
187 support under cygwin, please post to the IPython mailing list so this
187 support under cygwin, please post to the IPython mailing list so this
188 issue can be resolved for all users.
188 issue can be resolved for all users.
189
189
190 Windows: it works well under Windows Vista/XP/2k, and I suspect NT should
190 Windows: it works well under Windows Vista/XP/2k, and I suspect NT should
191 behave similarly. Section "Installation under windows" describes
191 behave similarly. Section "Installation under windows" describes
192 installation details for Windows, including some additional tools needed
192 installation details for Windows, including some additional tools needed
193 on this platform.
193 on this platform.
194
194
195 Windows 9x support is present, and has been reported to work fine (at
195 Windows 9x support is present, and has been reported to work fine (at
196 least on WinME).
196 least on WinME).
197
197
198 Location
198 Location
199 --------
199 --------
200
200
201 IPython is generously hosted at http://ipython.scipy.org by the
201 IPython is generously hosted at http://ipython.scipy.org by the
202 Enthought, Inc and the SciPy project. This site offers downloads,
202 Enthought, Inc and the SciPy project. This site offers downloads,
203 subversion access, mailing lists and a bug tracking system. I am very
203 subversion access, mailing lists and a bug tracking system. I am very
204 grateful to Enthought (http://www.enthought.com) and all of the SciPy
204 grateful to Enthought (http://www.enthought.com) and all of the SciPy
205 team for their contribution.
205 team for their contribution.
206
206
207 Installation
208 ============
209
210 Instant instructions
211 --------------------
212
213 If you are of the impatient kind, under Linux/Unix simply untar/unzip
214 the download, then install with 'python setup.py install'. Under
215 Windows, double-click on the provided .exe binary installer.
216
217 Then, take a look at Customization_ section for configuring things
218 optimally and `Quick tips`_ for quick tips on efficient use of
219 IPython. You can later refer to the rest of the manual for all the
220 gory details.
221
222 See the notes in upgrading_ section for upgrading IPython versions.
223
224
225 Detailed Unix instructions (Linux, Mac OS X, etc.)
226
227 For RPM based systems, simply install the supplied package in the usual
228 manner. If you download the tar archive, the process is:
229
230 1. Unzip/untar the ipython-XXX.tar.gz file wherever you want (XXX is
231 the version number). It will make a directory called ipython-XXX.
232 Change into that directory where you will find the files README
233 and setup.py. Once you've completed the installation, you can
234 safely remove this directory.
235 2. If you are installing over a previous installation of version
236 0.2.0 or earlier, first remove your $HOME/.ipython directory,
237 since the configuration file format has changed somewhat (the '='
238 were removed from all option specifications). Or you can call
239 ipython with the -upgrade option and it will do this automatically
240 for you.
241 3. IPython uses distutils, so you can install it by simply typing at
242 the system prompt (don't type the $)::
243
244 $ python setup.py install
245
246 Note that this assumes you have root access to your machine. If
247 you don't have root access or don't want IPython to go in the
248 default python directories, you'll need to use the ``--home`` option
249 (or ``--prefix``). For example::
250
251 $ python setup.py install --home $HOME/local
252
253 will install IPython into $HOME/local and its subdirectories
254 (creating them if necessary).
255 You can type::
256
257 $ python setup.py --help
258
259 for more details.
260
261 Note that if you change the default location for ``--home`` at
262 installation, IPython may end up installed at a location which is
263 not part of your $PYTHONPATH environment variable. In this case,
264 you'll need to configure this variable to include the actual
265 directory where the IPython/ directory ended (typically the value
266 you give to ``--home`` plus /lib/python).
267
268
269 Mac OSX information
270 -------------------
271
272 Under OSX, there is a choice you need to make. Apple ships its own build
273 of Python, which lives in the core OSX filesystem hierarchy. You can
274 also manually install a separate Python, either purely by hand
275 (typically in /usr/local) or by using Fink, which puts everything under
276 /sw. Which route to follow is a matter of personal preference, as I've
277 seen users who favor each of the approaches. Here I will simply list the
278 known installation issues under OSX, along with their solutions.
279
280 This page: http://geosci.uchicago.edu/~tobis/pylab.html contains
281 information on this topic, with additional details on how to make
282 IPython and matplotlib play nicely under OSX.
283
284 To run IPython and readline on OSX "Leopard" system python, see the
285 wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard
286
287
288 GUI problems
289 ------------
290
291 The following instructions apply to an install of IPython under OSX from
292 unpacking the .tar.gz distribution and installing it for the default
293 Python interpreter shipped by Apple. If you are using a fink install,
294 fink will take care of these details for you, by installing IPython
295 against fink's Python.
296
297 IPython offers various forms of support for interacting with graphical
298 applications from the command line, from simple Tk apps (which are in
299 principle always supported by Python) to interactive control of WX, Qt
300 and GTK apps. Under OSX, however, this requires that ipython is
301 installed by calling the special pythonw script at installation time,
302 which takes care of coordinating things with Apple's graphical environment.
303
304 So when installing under OSX, it is best to use the following command::
305
306 $ sudo pythonw setup.py install --install-scripts=/usr/local/bin
307
308 or
309
310 $ sudo pythonw setup.py install --install-scripts=/usr/bin
311
312 depending on where you like to keep hand-installed executables.
313
314 The resulting script will have an appropriate shebang line (the first
315 line in the script whic begins with #!...) such that the ipython
316 interpreter can interact with the OS X GUI. If the installed version
317 does not work and has a shebang line that points to, for example, just
318 /usr/bin/python, then you might have a stale, cached version in your
319 build/scripts-<python-version> directory. Delete that directory and
320 rerun the setup.py.
321
322 It is also a good idea to use the special flag ``--install-scripts`` as
323 indicated above, to ensure that the ipython scripts end up in a location
324 which is part of your $PATH. Otherwise Apple's Python will put the
325 scripts in an internal directory not available by default at the command
326 line (if you use /usr/local/bin, you need to make sure this is in your
327 $PATH, which may not be true by default).
328
329
330 Readline problems
331 -----------------
332
333 By default, the Python version shipped by Apple does not include the
334 readline library, so central to IPython's behavior. If you install
335 IPython against Apple's Python, you will not have arrow keys, tab
336 completion, etc. For Mac OSX 10.3 (Panther), you can find a prebuilt
337 readline library here:
338 http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip
339
340 If you are using OSX 10.4 (Tiger), after installing this package you
341 need to either:
342
343 1. move readline.so from /Library/Python/2.3 to
344 /Library/Python/2.3/site-packages, or
345 2. install http://pythonmac.org/packages/TigerPython23Compat.pkg.zip
346
347 Users installing against Fink's Python or a properly hand-built one
348 should not have this problem.
349
350
351 DarwinPorts
352 -----------
353
354 I report here a message from an OSX user, who suggests an alternative
355 means of using IPython under this operating system with good results.
356 Please let me know of any updates that may be useful for this section.
357 His message is reproduced verbatim below:
358
359 From: Markus Banfi <markus.banfi-AT-mospheira.net>
360
361 As a MacOS X (10.4.2) user I prefer to install software using
362 DawinPorts instead of Fink. I had no problems installing ipython
363 with DarwinPorts. It's just:
364
365 sudo port install py-ipython
366
367 It automatically resolved all dependencies (python24, readline,
368 py-readline). So far I did not encounter any problems with the
369 DarwinPorts port of ipython.
370
371
372
373 Windows instructions
374 --------------------
375
376 Some of IPython's very useful features are:
377
378 * Integrated readline support (Tab-based file, object and attribute
379 completion, input history across sessions, editable command line,
380 etc.)
381 * Coloring of prompts, code and tracebacks.
382
383 .. _pyreadline:
384
385 These, by default, are only available under Unix-like operating systems.
386 However, thanks to Gary Bishop's work, Windows XP/2k users can also
387 benefit from them. His readline library originally implemented both GNU
388 readline functionality and color support, so that IPython under Windows
389 XP/2k can be as friendly and powerful as under Unix-like environments.
390
391 This library, now named PyReadline, has been absorbed by the IPython
392 team (Jörgen Stenarson, in particular), and it continues to be developed
393 with new features, as well as being distributed directly from the
394 IPython site.
395
396 The PyReadline extension requires CTypes and the windows IPython
397 installer needs PyWin32, so in all you need:
398
399 1. PyWin32 from http://sourceforge.net/projects/pywin32.
400 2. PyReadline for Windows from
401 http://ipython.scipy.org/moin/PyReadline/Intro. That page contains
402 further details on using and configuring the system to your liking.
403 3. Finally, only if you are using Python 2.3 or 2.4, you need CTypes
404 from http://starship.python.net/crew/theller/ctypes(you must use
405 version 0.9.1 or newer). This package is included in Python 2.5,
406 so you don't need to manually get it if your Python version is 2.5
407 or newer.
408
409 Warning about a broken readline-like library: several users have
410 reported problems stemming from using the pseudo-readline library at
411 http://newcenturycomputers.net/projects/readline.html. This is a broken
412 library which, while called readline, only implements an incomplete
413 subset of the readline API. Since it is still called readline, it fools
414 IPython's detection mechanisms and causes unpredictable crashes later.
415 If you wish to use IPython under Windows, you must NOT use this library,
416 which for all purposes is (at least as of version 1.6) terminally broken.
417
418
419 Installation procedure
420 ----------------------
421
422 Once you have the above installed, from the IPython download directory
423 grab the ipython-XXX.win32.exe file, where XXX represents the version
424 number. This is a regular windows executable installer, which you can
425 simply double-click to install. It will add an entry for IPython to your
426 Start Menu, as well as registering IPython in the Windows list of
427 applications, so you can later uninstall it from the Control Panel.
428
429 IPython tries to install the configuration information in a directory
430 named .ipython (_ipython under Windows) located in your 'home'
431 directory. IPython sets this directory by looking for a HOME environment
432 variable; if such a variable does not exist, it uses HOMEDRIVE\HOMEPATH
433 (these are always defined by Windows). This typically gives something
434 like C:\Documents and Settings\YourUserName, but your local details may
435 vary. In this directory you will find all the files that configure
436 IPython's defaults, and you can put there your profiles and extensions.
437 This directory is automatically added by IPython to sys.path, so
438 anything you place there can be found by import statements.
439
440
441 Upgrading
442 ---------
443
444 For an IPython upgrade, you should first uninstall the previous version.
445 This will ensure that all files and directories (such as the
446 documentation) which carry embedded version strings in their names are
447 properly removed.
448
449
450 Manual installation under Win32
451 -------------------------------
452
453 In case the automatic installer does not work for some reason, you can
454 download the ipython-XXX.tar.gz file, which contains the full IPython
455 source distribution (the popular WinZip can read .tar.gz files). After
456 uncompressing the archive, you can install it at a command terminal just
457 like any other Python module, by using 'python setup.py install'.
458
459 After the installation, run the supplied win32_manual_post_install.py
460 script, which creates the necessary Start Menu shortcuts for you.
461
462
463 .. upgrading:
464
465 Upgrading from a previous version
466 ---------------------------------
467
468 If you are upgrading from a previous version of IPython, you may want
469 to upgrade the contents of your ~/.ipython directory. Just run
470 %upgrade, look at the diffs and delete the suggested files manually,
471 if you think you can lose the old versions. %upgrade will never
472 overwrite or delete anything.
473
474 Initial configuration of your environment
207 Initial configuration of your environment
475 =========================================
208 =========================================
476
209
477 This section will help you set various things in your environment for
210 This section will help you set various things in your environment for
478 your IPython sessions to be as efficient as possible. All of IPython's
211 your IPython sessions to be as efficient as possible. All of IPython's
479 configuration information, along with several example files, is stored
212 configuration information, along with several example files, is stored
480 in a directory named by default $HOME/.ipython. You can change this by
213 in a directory named by default $HOME/.ipython. You can change this by
481 defining the environment variable IPYTHONDIR, or at runtime with the
214 defining the environment variable IPYTHONDIR, or at runtime with the
482 command line option -ipythondir.
215 command line option -ipythondir.
483
216
484 If all goes well, the first time you run IPython it should
217 If all goes well, the first time you run IPython it should
485 automatically create a user copy of the config directory for you,
218 automatically create a user copy of the config directory for you,
486 based on its builtin defaults. You can look at the files it creates to
219 based on its builtin defaults. You can look at the files it creates to
487 learn more about configuring the system. The main file you will modify
220 learn more about configuring the system. The main file you will modify
488 to configure IPython's behavior is called ipythonrc (with a .ini
221 to configure IPython's behavior is called ipythonrc (with a .ini
489 extension under Windows), included for reference in `ipythonrc`_
222 extension under Windows), included for reference in `ipythonrc`_
490 section. This file is very commented and has many variables you can
223 section. This file is very commented and has many variables you can
491 change to suit your taste, you can find more details in
224 change to suit your taste, you can find more details in
492 Sec. customization_. Here we discuss the basic things you will want to
225 Sec. customization_. Here we discuss the basic things you will want to
493 make sure things are working properly from the beginning.
226 make sure things are working properly from the beginning.
494
227
495
228
496 .. _Accessing help:
229 .. _Accessing help:
497
230
498 Access to the Python help system
231 Access to the Python help system
499 --------------------------------
232 --------------------------------
500
233
501 This is true for Python in general (not just for IPython): you should
234 This is true for Python in general (not just for IPython): you should
502 have an environment variable called PYTHONDOCS pointing to the directory
235 have an environment variable called PYTHONDOCS pointing to the directory
503 where your HTML Python documentation lives. In my system it's
236 where your HTML Python documentation lives. In my system it's
504 /usr/share/doc/python-docs-2.3.4/html, check your local details or ask
237 /usr/share/doc/python-docs-2.3.4/html, check your local details or ask
505 your systems administrator.
238 your systems administrator.
506
239
507 This is the directory which holds the HTML version of the Python
240 This is the directory which holds the HTML version of the Python
508 manuals. Unfortunately it seems that different Linux distributions
241 manuals. Unfortunately it seems that different Linux distributions
509 package these files differently, so you may have to look around a bit.
242 package these files differently, so you may have to look around a bit.
510 Below I show the contents of this directory on my system for reference::
243 Below I show the contents of this directory on my system for reference::
511
244
512 [html]> ls
245 [html]> ls
513 about.dat acks.html dist/ ext/ index.html lib/ modindex.html
246 about.dat acks.html dist/ ext/ index.html lib/ modindex.html
514 stdabout.dat tut/ about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
247 stdabout.dat tut/ about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
515
248
516 You should really make sure this variable is correctly set so that
249 You should really make sure this variable is correctly set so that
517 Python's pydoc-based help system works. It is a powerful and convenient
250 Python's pydoc-based help system works. It is a powerful and convenient
518 system with full access to the Python manuals and all modules accessible
251 system with full access to the Python manuals and all modules accessible
519 to you.
252 to you.
520
253
521 Under Windows it seems that pydoc finds the documentation automatically,
254 Under Windows it seems that pydoc finds the documentation automatically,
522 so no extra setup appears necessary.
255 so no extra setup appears necessary.
523
256
524
257
525 Editor
258 Editor
526 ------
259 ------
527
260
528 The %edit command (and its alias %ed) will invoke the editor set in your
261 The %edit command (and its alias %ed) will invoke the editor set in your
529 environment as EDITOR. If this variable is not set, it will default to
262 environment as EDITOR. If this variable is not set, it will default to
530 vi under Linux/Unix and to notepad under Windows. You may want to set
263 vi under Linux/Unix and to notepad under Windows. You may want to set
531 this variable properly and to a lightweight editor which doesn't take
264 this variable properly and to a lightweight editor which doesn't take
532 too long to start (that is, something other than a new instance of
265 too long to start (that is, something other than a new instance of
533 Emacs). This way you can edit multi-line code quickly and with the power
266 Emacs). This way you can edit multi-line code quickly and with the power
534 of a real editor right inside IPython.
267 of a real editor right inside IPython.
535
268
536 If you are a dedicated Emacs user, you should set up the Emacs server so
269 If you are a dedicated Emacs user, you should set up the Emacs server so
537 that new requests are handled by the original process. This means that
270 that new requests are handled by the original process. This means that
538 almost no time is spent in handling the request (assuming an Emacs
271 almost no time is spent in handling the request (assuming an Emacs
539 process is already running). For this to work, you need to set your
272 process is already running). For this to work, you need to set your
540 EDITOR environment variable to 'emacsclient'. The code below, supplied
273 EDITOR environment variable to 'emacsclient'. The code below, supplied
541 by Francois Pinard, can then be used in your .emacs file to enable the
274 by Francois Pinard, can then be used in your .emacs file to enable the
542 server::
275 server::
543
276
544 (defvar server-buffer-clients)
277 (defvar server-buffer-clients)
545 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
278 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
546 (server-start)
279 (server-start)
547 (defun fp-kill-server-with-buffer-routine ()
280 (defun fp-kill-server-with-buffer-routine ()
548 (and server-buffer-clients (server-done)))
281 (and server-buffer-clients (server-done)))
549 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
282 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
550
283
551 You can also set the value of this editor via the commmand-line option
284 You can also set the value of this editor via the commmand-line option
552 '-editor' or in your ipythonrc file. This is useful if you wish to use
285 '-editor' or in your ipythonrc file. This is useful if you wish to use
553 specifically for IPython an editor different from your typical default
286 specifically for IPython an editor different from your typical default
554 (and for Windows users who tend to use fewer environment variables).
287 (and for Windows users who tend to use fewer environment variables).
555
288
556
289
557 Color
290 Color
558 -----
291 -----
559
292
560 The default IPython configuration has most bells and whistles turned on
293 The default IPython configuration has most bells and whistles turned on
561 (they're pretty safe). But there's one that may cause problems on some
294 (they're pretty safe). But there's one that may cause problems on some
562 systems: the use of color on screen for displaying information. This is
295 systems: the use of color on screen for displaying information. This is
563 very useful, since IPython can show prompts and exception tracebacks
296 very useful, since IPython can show prompts and exception tracebacks
564 with various colors, display syntax-highlighted source code, and in
297 with various colors, display syntax-highlighted source code, and in
565 general make it easier to visually parse information.
298 general make it easier to visually parse information.
566
299
567 The following terminals seem to handle the color sequences fine:
300 The following terminals seem to handle the color sequences fine:
568
301
569 * Linux main text console, KDE Konsole, Gnome Terminal, E-term,
302 * Linux main text console, KDE Konsole, Gnome Terminal, E-term,
570 rxvt, xterm.
303 rxvt, xterm.
571 * CDE terminal (tested under Solaris). This one boldfaces light colors.
304 * CDE terminal (tested under Solaris). This one boldfaces light colors.
572 * (X)Emacs buffers. See the emacs_ section for more details on
305 * (X)Emacs buffers. See the emacs_ section for more details on
573 using IPython with (X)Emacs.
306 using IPython with (X)Emacs.
574 * A Windows (XP/2k) command prompt with pyreadline_.
307 * A Windows (XP/2k) command prompt with pyreadline_.
575 * A Windows (XP/2k) CygWin shell. Although some users have reported
308 * A Windows (XP/2k) CygWin shell. Although some users have reported
576 problems; it is not clear whether there is an issue for everyone
309 problems; it is not clear whether there is an issue for everyone
577 or only under specific configurations. If you have full color
310 or only under specific configurations. If you have full color
578 support under cygwin, please post to the IPython mailing list so
311 support under cygwin, please post to the IPython mailing list so
579 this issue can be resolved for all users.
312 this issue can be resolved for all users.
580
313
581 These have shown problems:
314 These have shown problems:
582
315
583 * Windows command prompt in WinXP/2k logged into a Linux machine via
316 * Windows command prompt in WinXP/2k logged into a Linux machine via
584 telnet or ssh.
317 telnet or ssh.
585 * Windows native command prompt in WinXP/2k, without Gary Bishop's
318 * Windows native command prompt in WinXP/2k, without Gary Bishop's
586 extensions. Once Gary's readline library is installed, the normal
319 extensions. Once Gary's readline library is installed, the normal
587 WinXP/2k command prompt works perfectly.
320 WinXP/2k command prompt works perfectly.
588
321
589 Currently the following color schemes are available:
322 Currently the following color schemes are available:
590
323
591 * NoColor: uses no color escapes at all (all escapes are empty '' ''
324 * NoColor: uses no color escapes at all (all escapes are empty '' ''
592 strings). This 'scheme' is thus fully safe to use in any terminal.
325 strings). This 'scheme' is thus fully safe to use in any terminal.
593 * Linux: works well in Linux console type environments: dark
326 * Linux: works well in Linux console type environments: dark
594 background with light fonts. It uses bright colors for
327 background with light fonts. It uses bright colors for
595 information, so it is difficult to read if you have a light
328 information, so it is difficult to read if you have a light
596 colored background.
329 colored background.
597 * LightBG: the basic colors are similar to those in the Linux scheme
330 * LightBG: the basic colors are similar to those in the Linux scheme
598 but darker. It is easy to read in terminals with light backgrounds.
331 but darker. It is easy to read in terminals with light backgrounds.
599
332
600 IPython uses colors for two main groups of things: prompts and
333 IPython uses colors for two main groups of things: prompts and
601 tracebacks which are directly printed to the terminal, and the object
334 tracebacks which are directly printed to the terminal, and the object
602 introspection system which passes large sets of data through a pager.
335 introspection system which passes large sets of data through a pager.
603
336
604
337
605 Input/Output prompts and exception tracebacks
338 Input/Output prompts and exception tracebacks
606 ---------------------------------------------
339 ---------------------------------------------
607
340
608 You can test whether the colored prompts and tracebacks work on your
341 You can test whether the colored prompts and tracebacks work on your
609 system interactively by typing '%colors Linux' at the prompt (use
342 system interactively by typing '%colors Linux' at the prompt (use
610 '%colors LightBG' if your terminal has a light background). If the input
343 '%colors LightBG' if your terminal has a light background). If the input
611 prompt shows garbage like::
344 prompt shows garbage like::
612
345
613 [0;32mIn [[1;32m1[0;32m]: [0;00m
346 [0;32mIn [[1;32m1[0;32m]: [0;00m
614
347
615 instead of (in color) something like::
348 instead of (in color) something like::
616
349
617 In [1]:
350 In [1]:
618
351
619 this means that your terminal doesn't properly handle color escape
352 this means that your terminal doesn't properly handle color escape
620 sequences. You can go to a 'no color' mode by typing '%colors NoColor'.
353 sequences. You can go to a 'no color' mode by typing '%colors NoColor'.
621
354
622 You can try using a different terminal emulator program (Emacs users,
355 You can try using a different terminal emulator program (Emacs users,
623 see below). To permanently set your color preferences, edit the file
356 see below). To permanently set your color preferences, edit the file
624 $HOME/.ipython/ipythonrc and set the colors option to the desired value.
357 $HOME/.ipython/ipythonrc and set the colors option to the desired value.
625
358
626
359
627 Object details (types, docstrings, source code, etc.)
360 Object details (types, docstrings, source code, etc.)
628 -----------------------------------------------------
361 -----------------------------------------------------
629
362
630 IPython has a set of special functions for studying the objects you
363 IPython has a set of special functions for studying the objects you
631 are working with, discussed in detail in Sec. `dynamic object
364 are working with, discussed in detail in Sec. `dynamic object
632 information`_. But this system relies on passing information which is
365 information`_. But this system relies on passing information which is
633 longer than your screen through a data pager, such as the common Unix
366 longer than your screen through a data pager, such as the common Unix
634 less and more programs. In order to be able to see this information in
367 less and more programs. In order to be able to see this information in
635 color, your pager needs to be properly configured. I strongly
368 color, your pager needs to be properly configured. I strongly
636 recommend using less instead of more, as it seems that more simply can
369 recommend using less instead of more, as it seems that more simply can
637 not understand colored text correctly.
370 not understand colored text correctly.
638
371
639 In order to configure less as your default pager, do the following:
372 In order to configure less as your default pager, do the following:
640
373
641 1. Set the environment PAGER variable to less.
374 1. Set the environment PAGER variable to less.
642 2. Set the environment LESS variable to -r (plus any other options
375 2. Set the environment LESS variable to -r (plus any other options
643 you always want to pass to less by default). This tells less to
376 you always want to pass to less by default). This tells less to
644 properly interpret control sequences, which is how color
377 properly interpret control sequences, which is how color
645 information is given to your terminal.
378 information is given to your terminal.
646
379
647 For the csh or tcsh shells, add to your ~/.cshrc file the lines::
380 For the csh or tcsh shells, add to your ~/.cshrc file the lines::
648
381
649 setenv PAGER less
382 setenv PAGER less
650 setenv LESS -r
383 setenv LESS -r
651
384
652 There is similar syntax for other Unix shells, look at your system
385 There is similar syntax for other Unix shells, look at your system
653 documentation for details.
386 documentation for details.
654
387
655 If you are on a system which lacks proper data pagers (such as Windows),
388 If you are on a system which lacks proper data pagers (such as Windows),
656 IPython will use a very limited builtin pager.
389 IPython will use a very limited builtin pager.
657
390
658 .. _emacs:
391 .. _emacs:
659
392
660 (X)Emacs configuration
393 (X)Emacs configuration
661 ----------------------
394 ----------------------
662
395
663 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran,
396 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran,
664 currently (X)Emacs and IPython get along very well.
397 currently (X)Emacs and IPython get along very well.
665
398
666 Important note: You will need to use a recent enough version of
399 Important note: You will need to use a recent enough version of
667 python-mode.el, along with the file ipython.el. You can check that the
400 python-mode.el, along with the file ipython.el. You can check that the
668 version you have of python-mode.el is new enough by either looking at
401 version you have of python-mode.el is new enough by either looking at
669 the revision number in the file itself, or asking for it in (X)Emacs via
402 the revision number in the file itself, or asking for it in (X)Emacs via
670 M-x py-version. Versions 4.68 and newer contain the necessary fixes for
403 M-x py-version. Versions 4.68 and newer contain the necessary fixes for
671 proper IPython support.
404 proper IPython support.
672
405
673 The file ipython.el is included with the IPython distribution, in the
406 The file ipython.el is included with the IPython distribution, in the
674 documentation directory (where this manual resides in PDF and HTML
407 documentation directory (where this manual resides in PDF and HTML
675 formats).
408 formats).
676
409
677 Once you put these files in your Emacs path, all you need in your .emacs
410 Once you put these files in your Emacs path, all you need in your .emacs
678 file is::
411 file is::
679
412
680 (require 'ipython)
413 (require 'ipython)
681
414
682 This should give you full support for executing code snippets via
415 This should give you full support for executing code snippets via
683 IPython, opening IPython as your Python shell via C-c !, etc.
416 IPython, opening IPython as your Python shell via C-c !, etc.
684
417
685 If you happen to get garbage instead of colored prompts as described in
418 If you happen to get garbage instead of colored prompts as described in
686 the previous section, you may need to set also in your .emacs file::
419 the previous section, you may need to set also in your .emacs file::
687
420
688 (setq ansi-color-for-comint-mode t)
421 (setq ansi-color-for-comint-mode t)
689
422
690
423
691 Notes:
424 Notes:
692
425
693 * There is one caveat you should be aware of: you must start the
426 * There is one caveat you should be aware of: you must start the
694 IPython shell before attempting to execute any code regions via
427 IPython shell before attempting to execute any code regions via
695 ``C-c |``. Simply type C-c ! to start IPython before passing any code
428 ``C-c |``. Simply type C-c ! to start IPython before passing any code
696 regions to the interpreter, and you shouldn't experience any
429 regions to the interpreter, and you shouldn't experience any
697 problems.
430 problems.
698 This is due to a bug in Python itself, which has been fixed for
431 This is due to a bug in Python itself, which has been fixed for
699 Python 2.3, but exists as of Python 2.2.2 (reported as SF bug [
432 Python 2.3, but exists as of Python 2.2.2 (reported as SF bug [
700 737947 ]).
433 737947 ]).
701 * The (X)Emacs support is maintained by Alexander Schmolck, so all
434 * The (X)Emacs support is maintained by Alexander Schmolck, so all
702 comments/requests should be directed to him through the IPython
435 comments/requests should be directed to him through the IPython
703 mailing lists.
436 mailing lists.
704 * This code is still somewhat experimental so it's a bit rough
437 * This code is still somewhat experimental so it's a bit rough
705 around the edges (although in practice, it works quite well).
438 around the edges (although in practice, it works quite well).
706 * Be aware that if you customize py-python-command previously, this
439 * Be aware that if you customize py-python-command previously, this
707 value will override what ipython.el does (because loading the
440 value will override what ipython.el does (because loading the
708 customization variables comes later).
441 customization variables comes later).
709
442
710 .. Quick tips:
443 .. Quick tips:
711
444
712 Quick tips
445 Quick tips
713 ==========
446 ==========
714
447
715 IPython can be used as an improved replacement for the Python prompt,
448 IPython can be used as an improved replacement for the Python prompt,
716 and for that you don't really need to read any more of this manual. But
449 and for that you don't really need to read any more of this manual. But
717 in this section we'll try to summarize a few tips on how to make the
450 in this section we'll try to summarize a few tips on how to make the
718 most effective use of it for everyday Python development, highlighting
451 most effective use of it for everyday Python development, highlighting
719 things you might miss in the rest of the manual (which is getting long).
452 things you might miss in the rest of the manual (which is getting long).
720 We'll give references to parts in the manual which provide more detail
453 We'll give references to parts in the manual which provide more detail
721 when appropriate.
454 when appropriate.
722
455
723 The following article by Jeremy Jones provides an introductory tutorial
456 The following article by Jeremy Jones provides an introductory tutorial
724 about IPython:
457 about IPython:
725 http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html
458 http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html
726
459
727 * The TAB key. TAB-completion, especially for attributes, is a
460 * The TAB key. TAB-completion, especially for attributes, is a
728 convenient way to explore the structure of any object you're
461 convenient way to explore the structure of any object you're
729 dealing with. Simply type object_name.<TAB> and a list of the
462 dealing with. Simply type object_name.<TAB> and a list of the
730 object's attributes will be printed (see readline_ for
463 object's attributes will be printed (see readline_ for
731 more). Tab completion also works on
464 more). Tab completion also works on
732 file and directory names, which combined with IPython's alias
465 file and directory names, which combined with IPython's alias
733 system allows you to do from within IPython many of the things you
466 system allows you to do from within IPython many of the things you
734 normally would need the system shell for.
467 normally would need the system shell for.
735 * Explore your objects. Typing object_name? will print all sorts of
468 * Explore your objects. Typing object_name? will print all sorts of
736 details about any object, including docstrings, function
469 details about any object, including docstrings, function
737 definition lines (for call arguments) and constructor details for
470 definition lines (for call arguments) and constructor details for
738 classes. The magic commands %pdoc, %pdef, %psource and %pfile will
471 classes. The magic commands %pdoc, %pdef, %psource and %pfile will
739 respectively print the docstring, function definition line, full
472 respectively print the docstring, function definition line, full
740 source code and the complete file for any object (when they can be
473 source code and the complete file for any object (when they can be
741 found). If automagic is on (it is by default), you don't need to
474 found). If automagic is on (it is by default), you don't need to
742 type the '%' explicitly. See sec. `dynamic object information`_
475 type the '%' explicitly. See sec. `dynamic object information`_
743 for more.
476 for more.
744 * The %run magic command allows you to run any python script and
477 * The %run magic command allows you to run any python script and
745 load all of its data directly into the interactive namespace.
478 load all of its data directly into the interactive namespace.
746 Since the file is re-read from disk each time, changes you make to
479 Since the file is re-read from disk each time, changes you make to
747 it are reflected immediately (in contrast to the behavior of
480 it are reflected immediately (in contrast to the behavior of
748 import). I rarely use import for code I am testing, relying on
481 import). I rarely use import for code I am testing, relying on
749 %run instead. See magic_ section for more on this
482 %run instead. See magic_ section for more on this
750 and other magic commands, or type the name of any magic command
483 and other magic commands, or type the name of any magic command
751 and ? to get details on it. See also sec. dreload_ for a
484 and ? to get details on it. See also sec. dreload_ for a
752 recursive reload command.
485 recursive reload command.
753 %run also has special flags for timing the execution of your
486 %run also has special flags for timing the execution of your
754 scripts (-t) and for executing them under the control of either
487 scripts (-t) and for executing them under the control of either
755 Python's pdb debugger (-d) or profiler (-p). With all of these,
488 Python's pdb debugger (-d) or profiler (-p). With all of these,
756 %run can be used as the main tool for efficient interactive
489 %run can be used as the main tool for efficient interactive
757 development of code which you write in your editor of choice.
490 development of code which you write in your editor of choice.
758 * Use the Python debugger, pdb. The %pdb
491 * Use the Python debugger, pdb. The %pdb
759 command allows you to toggle on and off the automatic invocation
492 command allows you to toggle on and off the automatic invocation
760 of an IPython-enhanced pdb debugger (with coloring, tab completion
493 of an IPython-enhanced pdb debugger (with coloring, tab completion
761 and more) at any uncaught exception. The advantage of this is that
494 and more) at any uncaught exception. The advantage of this is that
762 pdb starts inside the function where the exception occurred, with
495 pdb starts inside the function where the exception occurred, with
763 all data still available. You can print variables, see code,
496 all data still available. You can print variables, see code,
764 execute statements and even walk up and down the call stack to
497 execute statements and even walk up and down the call stack to
765 track down the true source of the problem (which often is many
498 track down the true source of the problem (which often is many
766 layers in the stack above where the exception gets triggered).
499 layers in the stack above where the exception gets triggered).
767 Running programs with %run and pdb active can be an efficient to
500 Running programs with %run and pdb active can be an efficient to
768 develop and debug code, in many cases eliminating the need for
501 develop and debug code, in many cases eliminating the need for
769 print statements or external debugging tools. I often simply put a
502 print statements or external debugging tools. I often simply put a
770 1/0 in a place where I want to take a look so that pdb gets
503 1/0 in a place where I want to take a look so that pdb gets
771 called, quickly view whatever variables I need to or test various
504 called, quickly view whatever variables I need to or test various
772 pieces of code and then remove the 1/0.
505 pieces of code and then remove the 1/0.
773 Note also that '%run -d' activates pdb and automatically sets
506 Note also that '%run -d' activates pdb and automatically sets
774 initial breakpoints for you to step through your code, watch
507 initial breakpoints for you to step through your code, watch
775 variables, etc. See Sec. `Output caching`_ for
508 variables, etc. See Sec. `Output caching`_ for
776 details.
509 details.
777 * Use the output cache. All output results are automatically stored
510 * Use the output cache. All output results are automatically stored
778 in a global dictionary named Out and variables named _1, _2, etc.
511 in a global dictionary named Out and variables named _1, _2, etc.
779 alias them. For example, the result of input line 4 is available
512 alias them. For example, the result of input line 4 is available
780 either as Out[4] or as _4. Additionally, three variables named _,
513 either as Out[4] or as _4. Additionally, three variables named _,
781 __ and ___ are always kept updated with the for the last three
514 __ and ___ are always kept updated with the for the last three
782 results. This allows you to recall any previous result and further
515 results. This allows you to recall any previous result and further
783 use it for new calculations. See Sec. `Output caching`_ for more.
516 use it for new calculations. See Sec. `Output caching`_ for more.
784 * Put a ';' at the end of a line to supress the printing of output.
517 * Put a ';' at the end of a line to supress the printing of output.
785 This is useful when doing calculations which generate long output
518 This is useful when doing calculations which generate long output
786 you are not interested in seeing. The _* variables and the Out[]
519 you are not interested in seeing. The _* variables and the Out[]
787 list do get updated with the contents of the output, even if it is
520 list do get updated with the contents of the output, even if it is
788 not printed. You can thus still access the generated results this
521 not printed. You can thus still access the generated results this
789 way for further processing.
522 way for further processing.
790 * A similar system exists for caching input. All input is stored in
523 * A similar system exists for caching input. All input is stored in
791 a global list called In , so you can re-execute lines 22 through
524 a global list called In , so you can re-execute lines 22 through
792 28 plus line 34 by typing 'exec In[22:29]+In[34]' (using Python
525 28 plus line 34 by typing 'exec In[22:29]+In[34]' (using Python
793 slicing notation). If you need to execute the same set of lines
526 slicing notation). If you need to execute the same set of lines
794 often, you can assign them to a macro with the %macro function.
527 often, you can assign them to a macro with the %macro function.
795 See sec. `Input caching`_ for more.
528 See sec. `Input caching`_ for more.
796 * Use your input history. The %hist command can show you all
529 * Use your input history. The %hist command can show you all
797 previous input, without line numbers if desired (option -n) so you
530 previous input, without line numbers if desired (option -n) so you
798 can directly copy and paste code either back in IPython or in a
531 can directly copy and paste code either back in IPython or in a
799 text editor. You can also save all your history by turning on
532 text editor. You can also save all your history by turning on
800 logging via %logstart; these logs can later be either reloaded as
533 logging via %logstart; these logs can later be either reloaded as
801 IPython sessions or used as code for your programs.
534 IPython sessions or used as code for your programs.
802 * Define your own system aliases. Even though IPython gives you
535 * Define your own system aliases. Even though IPython gives you
803 access to your system shell via the ! prefix, it is convenient to
536 access to your system shell via the ! prefix, it is convenient to
804 have aliases to the system commands you use most often. This
537 have aliases to the system commands you use most often. This
805 allows you to work seamlessly from inside IPython with the same
538 allows you to work seamlessly from inside IPython with the same
806 commands you are used to in your system shell.
539 commands you are used to in your system shell.
807 IPython comes with some pre-defined aliases and a complete system
540 IPython comes with some pre-defined aliases and a complete system
808 for changing directories, both via a stack (see %pushd, %popd and
541 for changing directories, both via a stack (see %pushd, %popd and
809 %dhist) and via direct %cd. The latter keeps a history of visited
542 %dhist) and via direct %cd. The latter keeps a history of visited
810 directories and allows you to go to any previously visited one.
543 directories and allows you to go to any previously visited one.
811 * Use Python to manipulate the results of system commands. The '!!'
544 * Use Python to manipulate the results of system commands. The '!!'
812 special syntax, and the %sc and %sx magic commands allow you to
545 special syntax, and the %sc and %sx magic commands allow you to
813 capture system output into Python variables.
546 capture system output into Python variables.
814 * Expand python variables when calling the shell (either via '!' and
547 * Expand python variables when calling the shell (either via '!' and
815 '!!' or via aliases) by prepending a $ in front of them. You can
548 '!!' or via aliases) by prepending a $ in front of them. You can
816 also expand complete python expressions. See
549 also expand complete python expressions. See
817 `System shell access`_ for more.
550 `System shell access`_ for more.
818 * Use profiles to maintain different configurations (modules to
551 * Use profiles to maintain different configurations (modules to
819 load, function definitions, option settings) for particular tasks.
552 load, function definitions, option settings) for particular tasks.
820 You can then have customized versions of IPython for specific
553 You can then have customized versions of IPython for specific
821 purposes. See sec. profiles_ for more.
554 purposes. See sec. profiles_ for more.
822 * Embed IPython in your programs. A few lines of code are enough to
555 * Embed IPython in your programs. A few lines of code are enough to
823 load a complete IPython inside your own programs, giving you the
556 load a complete IPython inside your own programs, giving you the
824 ability to work with your data interactively after automatic
557 ability to work with your data interactively after automatic
825 processing has been completed. See sec. embedding_
558 processing has been completed. See sec. embedding_
826 for more.
559 for more.
827 * Use the Python profiler. When dealing with performance issues, the
560 * Use the Python profiler. When dealing with performance issues, the
828 %run command with a -p option allows you to run complete programs
561 %run command with a -p option allows you to run complete programs
829 under the control of the Python profiler. The %prun command does a
562 under the control of the Python profiler. The %prun command does a
830 similar job for single Python expressions (like function calls).
563 similar job for single Python expressions (like function calls).
831 * Use the IPython.demo.Demo class to load any Python script as an
564 * Use the IPython.demo.Demo class to load any Python script as an
832 interactive demo. With a minimal amount of simple markup, you can
565 interactive demo. With a minimal amount of simple markup, you can
833 control the execution of the script, stopping as needed. See
566 control the execution of the script, stopping as needed. See
834 sec. `interactive demos`_ for more.
567 sec. `interactive demos`_ for more.
835 * Run your doctests from within IPython for development and
568 * Run your doctests from within IPython for development and
836 debugging. The special %doctest_mode command toggles a mode where
569 debugging. The special %doctest_mode command toggles a mode where
837 the prompt, output and exceptions display matches as closely as
570 the prompt, output and exceptions display matches as closely as
838 possible that of the default Python interpreter. In addition, this
571 possible that of the default Python interpreter. In addition, this
839 mode allows you to directly paste in code that contains leading
572 mode allows you to directly paste in code that contains leading
840 '>>>' prompts, even if they have extra leading whitespace (as is
573 '>>>' prompts, even if they have extra leading whitespace (as is
841 common in doctest files). This combined with the '%history -tn'
574 common in doctest files). This combined with the '%history -tn'
842 call to see your translated history (with these extra prompts
575 call to see your translated history (with these extra prompts
843 removed and no line numbers) allows for an easy doctest workflow,
576 removed and no line numbers) allows for an easy doctest workflow,
844 where you can go from doctest to interactive execution to pasting
577 where you can go from doctest to interactive execution to pasting
845 into valid Python code as needed.
578 into valid Python code as needed.
846
579
847
580
848 Source code handling tips
581 Source code handling tips
849 -------------------------
582 -------------------------
850
583
851 IPython is a line-oriented program, without full control of the
584 IPython is a line-oriented program, without full control of the
852 terminal. Therefore, it doesn't support true multiline editing. However,
585 terminal. Therefore, it doesn't support true multiline editing. However,
853 it has a number of useful tools to help you in dealing effectively with
586 it has a number of useful tools to help you in dealing effectively with
854 more complex editing.
587 more complex editing.
855
588
856 The %edit command gives a reasonable approximation of multiline editing,
589 The %edit command gives a reasonable approximation of multiline editing,
857 by invoking your favorite editor on the spot. IPython will execute the
590 by invoking your favorite editor on the spot. IPython will execute the
858 code you type in there as if it were typed interactively. Type %edit?
591 code you type in there as if it were typed interactively. Type %edit?
859 for the full details on the edit command.
592 for the full details on the edit command.
860
593
861 If you have typed various commands during a session, which you'd like to
594 If you have typed various commands during a session, which you'd like to
862 reuse, IPython provides you with a number of tools. Start by using %hist
595 reuse, IPython provides you with a number of tools. Start by using %hist
863 to see your input history, so you can see the line numbers of all input.
596 to see your input history, so you can see the line numbers of all input.
864 Let us say that you'd like to reuse lines 10 through 20, plus lines 24
597 Let us say that you'd like to reuse lines 10 through 20, plus lines 24
865 and 28. All the commands below can operate on these with the syntax::
598 and 28. All the commands below can operate on these with the syntax::
866
599
867 %command 10-20 24 28
600 %command 10-20 24 28
868
601
869 where the command given can be:
602 where the command given can be:
870
603
871 * %macro <macroname>: this stores the lines into a variable which,
604 * %macro <macroname>: this stores the lines into a variable which,
872 when called at the prompt, re-executes the input. Macros can be
605 when called at the prompt, re-executes the input. Macros can be
873 edited later using '%edit macroname', and they can be stored
606 edited later using '%edit macroname', and they can be stored
874 persistently across sessions with '%store macroname' (the storage
607 persistently across sessions with '%store macroname' (the storage
875 system is per-profile). The combination of quick macros,
608 system is per-profile). The combination of quick macros,
876 persistent storage and editing, allows you to easily refine
609 persistent storage and editing, allows you to easily refine
877 quick-and-dirty interactive input into permanent utilities, always
610 quick-and-dirty interactive input into permanent utilities, always
878 available both in IPython and as files for general reuse.
611 available both in IPython and as files for general reuse.
879 * %edit: this will open a text editor with those lines pre-loaded
612 * %edit: this will open a text editor with those lines pre-loaded
880 for further modification. It will then execute the resulting
613 for further modification. It will then execute the resulting
881 file's contents as if you had typed it at the prompt.
614 file's contents as if you had typed it at the prompt.
882 * %save <filename>: this saves the lines directly to a named file on
615 * %save <filename>: this saves the lines directly to a named file on
883 disk.
616 disk.
884
617
885 While %macro saves input lines into memory for interactive re-execution,
618 While %macro saves input lines into memory for interactive re-execution,
886 sometimes you'd like to save your input directly to a file. The %save
619 sometimes you'd like to save your input directly to a file. The %save
887 magic does this: its input sytnax is the same as %macro, but it saves
620 magic does this: its input sytnax is the same as %macro, but it saves
888 your input directly to a Python file. Note that the %logstart command
621 your input directly to a Python file. Note that the %logstart command
889 also saves input, but it logs all input to disk (though you can
622 also saves input, but it logs all input to disk (though you can
890 temporarily suspend it and reactivate it with %logoff/%logon); %save
623 temporarily suspend it and reactivate it with %logoff/%logon); %save
891 allows you to select which lines of input you need to save.
624 allows you to select which lines of input you need to save.
892
625
893
626
894 Lightweight 'version control'
627 Lightweight 'version control'
895 -----------------------------
628 -----------------------------
896
629
897 When you call %edit with no arguments, IPython opens an empty editor
630 When you call %edit with no arguments, IPython opens an empty editor
898 with a temporary file, and it returns the contents of your editing
631 with a temporary file, and it returns the contents of your editing
899 session as a string variable. Thanks to IPython's output caching
632 session as a string variable. Thanks to IPython's output caching
900 mechanism, this is automatically stored::
633 mechanism, this is automatically stored::
901
634
902 In [1]: %edit
635 In [1]: %edit
903
636
904 IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py
637 IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py
905
638
906 Editing... done. Executing edited code...
639 Editing... done. Executing edited code...
907
640
908 hello - this is a temporary file
641 hello - this is a temporary file
909
642
910 Out[1]: "print 'hello - this is a temporary file'\n"
643 Out[1]: "print 'hello - this is a temporary file'\n"
911
644
912 Now, if you call '%edit -p', IPython tries to open an editor with the
645 Now, if you call '%edit -p', IPython tries to open an editor with the
913 same data as the last time you used %edit. So if you haven't used %edit
646 same data as the last time you used %edit. So if you haven't used %edit
914 in the meantime, this same contents will reopen; however, it will be
647 in the meantime, this same contents will reopen; however, it will be
915 done in a new file. This means that if you make changes and you later
648 done in a new file. This means that if you make changes and you later
916 want to find an old version, you can always retrieve it by using its
649 want to find an old version, you can always retrieve it by using its
917 output number, via '%edit _NN', where NN is the number of the output
650 output number, via '%edit _NN', where NN is the number of the output
918 prompt.
651 prompt.
919
652
920 Continuing with the example above, this should illustrate this idea::
653 Continuing with the example above, this should illustrate this idea::
921
654
922 In [2]: edit -p
655 In [2]: edit -p
923
656
924 IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py
657 IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py
925
658
926 Editing... done. Executing edited code...
659 Editing... done. Executing edited code...
927
660
928 hello - now I made some changes
661 hello - now I made some changes
929
662
930 Out[2]: "print 'hello - now I made some changes'\n"
663 Out[2]: "print 'hello - now I made some changes'\n"
931
664
932 In [3]: edit _1
665 In [3]: edit _1
933
666
934 IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py
667 IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py
935
668
936 Editing... done. Executing edited code...
669 Editing... done. Executing edited code...
937
670
938 hello - this is a temporary file
671 hello - this is a temporary file
939
672
940 IPython version control at work :)
673 IPython version control at work :)
941
674
942 Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n"
675 Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n"
943
676
944
677
945 This section was written after a contribution by Alexander Belchenko on
678 This section was written after a contribution by Alexander Belchenko on
946 the IPython user list.
679 the IPython user list.
947
680
948
681
949 Effective logging
682 Effective logging
950 -----------------
683 -----------------
951
684
952 A very useful suggestion sent in by Robert Kern follows:
685 A very useful suggestion sent in by Robert Kern follows:
953
686
954 I recently happened on a nifty way to keep tidy per-project log files. I
687 I recently happened on a nifty way to keep tidy per-project log files. I
955 made a profile for my project (which is called "parkfield").
688 made a profile for my project (which is called "parkfield").
956
689
957 include ipythonrc
690 include ipythonrc
958
691
959 # cancel earlier logfile invocation:
692 # cancel earlier logfile invocation:
960
693
961 logfile ''
694 logfile ''
962
695
963 execute import time
696 execute import time
964
697
965 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
698 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
966
699
967 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
700 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
968
701
969 I also added a shell alias for convenience:
702 I also added a shell alias for convenience:
970
703
971 alias parkfield="ipython -pylab -profile parkfield"
704 alias parkfield="ipython -pylab -profile parkfield"
972
705
973 Now I have a nice little directory with everything I ever type in,
706 Now I have a nice little directory with everything I ever type in,
974 organized by project and date.
707 organized by project and date.
975
708
976 Contribute your own: If you have your own favorite tip on using IPython
709 Contribute your own: If you have your own favorite tip on using IPython
977 efficiently for a certain task (especially things which can't be done in
710 efficiently for a certain task (especially things which can't be done in
978 the normal Python interpreter), don't hesitate to send it!
711 the normal Python interpreter), don't hesitate to send it!
979
712
980 .. _Command line options:
713 .. _Command line options:
981
714
982 Command-line use
715 Command-line use
983 ================
716 ================
984
717
985 You start IPython with the command::
718 You start IPython with the command::
986
719
987 $ ipython [options] files
720 $ ipython [options] files
988
721
989 If invoked with no options, it executes all the files listed in sequence
722 If invoked with no options, it executes all the files listed in sequence
990 and drops you into the interpreter while still acknowledging any options
723 and drops you into the interpreter while still acknowledging any options
991 you may have set in your ipythonrc file. This behavior is different from
724 you may have set in your ipythonrc file. This behavior is different from
992 standard Python, which when called as python -i will only execute one
725 standard Python, which when called as python -i will only execute one
993 file and ignore your configuration setup.
726 file and ignore your configuration setup.
994
727
995 Please note that some of the configuration options are not available at
728 Please note that some of the configuration options are not available at
996 the command line, simply because they are not practical here. Look into
729 the command line, simply because they are not practical here. Look into
997 your ipythonrc configuration file for details on those. This file
730 your ipythonrc configuration file for details on those. This file
998 typically installed in the $HOME/.ipython directory. For Windows users,
731 typically installed in the $HOME/.ipython directory. For Windows users,
999 $HOME resolves to C:\\Documents and Settings\\YourUserName in most
732 $HOME resolves to C:\\Documents and Settings\\YourUserName in most
1000 instances. In the rest of this text, we will refer to this directory as
733 instances. In the rest of this text, we will refer to this directory as
1001 IPYTHONDIR.
734 IPYTHONDIR.
1002
735
1003 .. _Threading options:
736 .. _Threading options:
1004
737
1005
738
1006 Special Threading Options
739 Special Threading Options
1007 -------------------------
740 -------------------------
1008
741
1009 The following special options are ONLY valid at the beginning of the
742 The following special options are ONLY valid at the beginning of the
1010 command line, and not later. This is because they control the initial-
743 command line, and not later. This is because they control the initial-
1011 ization of ipython itself, before the normal option-handling mechanism
744 ization of ipython itself, before the normal option-handling mechanism
1012 is active.
745 is active.
1013
746
1014 -gthread, -qthread, -q4thread, -wthread, -pylab:
747 -gthread, -qthread, -q4thread, -wthread, -pylab:
1015 Only one of these can be given, and it can only be given as
748 Only one of these can be given, and it can only be given as
1016 the first option passed to IPython (it will have no effect in
749 the first option passed to IPython (it will have no effect in
1017 any other position). They provide threading support for the
750 any other position). They provide threading support for the
1018 GTK, Qt (versions 3 and 4) and WXPython toolkits, and for the
751 GTK, Qt (versions 3 and 4) and WXPython toolkits, and for the
1019 matplotlib library.
752 matplotlib library.
1020
753
1021 With any of the first four options, IPython starts running a
754 With any of the first four options, IPython starts running a
1022 separate thread for the graphical toolkit's operation, so that
755 separate thread for the graphical toolkit's operation, so that
1023 you can open and control graphical elements from within an
756 you can open and control graphical elements from within an
1024 IPython command line, without blocking. All four provide
757 IPython command line, without blocking. All four provide
1025 essentially the same functionality, respectively for GTK, Qt3,
758 essentially the same functionality, respectively for GTK, Qt3,
1026 Qt4 and WXWidgets (via their Python interfaces).
759 Qt4 and WXWidgets (via their Python interfaces).
1027
760
1028 Note that with -wthread, you can additionally use the
761 Note that with -wthread, you can additionally use the
1029 -wxversion option to request a specific version of wx to be
762 -wxversion option to request a specific version of wx to be
1030 used. This requires that you have the wxversion Python module
763 used. This requires that you have the wxversion Python module
1031 installed, which is part of recent wxPython distributions.
764 installed, which is part of recent wxPython distributions.
1032
765
1033 If -pylab is given, IPython loads special support for the mat
766 If -pylab is given, IPython loads special support for the mat
1034 plotlib library (http://matplotlib.sourceforge.net), allowing
767 plotlib library (http://matplotlib.sourceforge.net), allowing
1035 interactive usage of any of its backends as defined in the
768 interactive usage of any of its backends as defined in the
1036 user's ~/.matplotlib/matplotlibrc file. It automatically
769 user's ~/.matplotlib/matplotlibrc file. It automatically
1037 activates GTK, Qt or WX threading for IPyhton if the choice of
770 activates GTK, Qt or WX threading for IPyhton if the choice of
1038 matplotlib backend requires it. It also modifies the %run
771 matplotlib backend requires it. It also modifies the %run
1039 command to correctly execute (without blocking) any
772 command to correctly execute (without blocking) any
1040 matplotlib-based script which calls show() at the end.
773 matplotlib-based script which calls show() at the end.
1041
774
1042 -tk
775 -tk
1043 The -g/q/q4/wthread options, and -pylab (if matplotlib is
776 The -g/q/q4/wthread options, and -pylab (if matplotlib is
1044 configured to use GTK, Qt3, Qt4 or WX), will normally block Tk
777 configured to use GTK, Qt3, Qt4 or WX), will normally block Tk
1045 graphical interfaces. This means that when either GTK, Qt or WX
778 graphical interfaces. This means that when either GTK, Qt or WX
1046 threading is active, any attempt to open a Tk GUI will result in a
779 threading is active, any attempt to open a Tk GUI will result in a
1047 dead window, and possibly cause the Python interpreter to crash.
780 dead window, and possibly cause the Python interpreter to crash.
1048 An extra option, -tk, is available to address this issue. It can
781 An extra option, -tk, is available to address this issue. It can
1049 only be given as a second option after any of the above (-gthread,
782 only be given as a second option after any of the above (-gthread,
1050 -wthread or -pylab).
783 -wthread or -pylab).
1051
784
1052 If -tk is given, IPython will try to coordinate Tk threading
785 If -tk is given, IPython will try to coordinate Tk threading
1053 with GTK, Qt or WX. This is however potentially unreliable, and
786 with GTK, Qt or WX. This is however potentially unreliable, and
1054 you will have to test on your platform and Python configuration to
787 you will have to test on your platform and Python configuration to
1055 determine whether it works for you. Debian users have reported
788 determine whether it works for you. Debian users have reported
1056 success, apparently due to the fact that Debian builds all of Tcl,
789 success, apparently due to the fact that Debian builds all of Tcl,
1057 Tk, Tkinter and Python with pthreads support. Under other Linux
790 Tk, Tkinter and Python with pthreads support. Under other Linux
1058 environments (such as Fedora Core 2/3), this option has caused
791 environments (such as Fedora Core 2/3), this option has caused
1059 random crashes and lockups of the Python interpreter. Under other
792 random crashes and lockups of the Python interpreter. Under other
1060 operating systems (Mac OSX and Windows), you'll need to try it to
793 operating systems (Mac OSX and Windows), you'll need to try it to
1061 find out, since currently no user reports are available.
794 find out, since currently no user reports are available.
1062
795
1063 There is unfortunately no way for IPython to determine at run time
796 There is unfortunately no way for IPython to determine at run time
1064 whether -tk will work reliably or not, so you will need to do some
797 whether -tk will work reliably or not, so you will need to do some
1065 experiments before relying on it for regular work.
798 experiments before relying on it for regular work.
1066
799
1067
800
1068
801
1069 Regular Options
802 Regular Options
1070 ---------------
803 ---------------
1071
804
1072 After the above threading options have been given, regular options can
805 After the above threading options have been given, regular options can
1073 follow in any order. All options can be abbreviated to their shortest
806 follow in any order. All options can be abbreviated to their shortest
1074 non-ambiguous form and are case-sensitive. One or two dashes can be
807 non-ambiguous form and are case-sensitive. One or two dashes can be
1075 used. Some options have an alternate short form, indicated after a ``|``.
808 used. Some options have an alternate short form, indicated after a ``|``.
1076
809
1077 Most options can also be set from your ipythonrc configuration file. See
810 Most options can also be set from your ipythonrc configuration file. See
1078 the provided example for more details on what the options do. Options
811 the provided example for more details on what the options do. Options
1079 given at the command line override the values set in the ipythonrc file.
812 given at the command line override the values set in the ipythonrc file.
1080
813
1081 All options with a [no] prepended can be specified in negated form
814 All options with a [no] prepended can be specified in negated form
1082 (-nooption instead of -option) to turn the feature off.
815 (-nooption instead of -option) to turn the feature off.
1083
816
1084 -help print a help message and exit.
817 -help print a help message and exit.
1085
818
1086 -pylab
819 -pylab
1087 this can only be given as the first option passed to IPython
820 this can only be given as the first option passed to IPython
1088 (it will have no effect in any other position). It adds
821 (it will have no effect in any other position). It adds
1089 special support for the matplotlib library
822 special support for the matplotlib library
1090 (http://matplotlib.sourceforge.ne), allowing interactive usage
823 (http://matplotlib.sourceforge.ne), allowing interactive usage
1091 of any of its backends as defined in the user's .matplotlibrc
824 of any of its backends as defined in the user's .matplotlibrc
1092 file. It automatically activates GTK or WX threading for
825 file. It automatically activates GTK or WX threading for
1093 IPyhton if the choice of matplotlib backend requires it. It
826 IPyhton if the choice of matplotlib backend requires it. It
1094 also modifies the %run command to correctly execute (without
827 also modifies the %run command to correctly execute (without
1095 blocking) any matplotlib-based script which calls show() at
828 blocking) any matplotlib-based script which calls show() at
1096 the end. See `Matplotlib support`_ for more details.
829 the end. See `Matplotlib support`_ for more details.
1097
830
1098 -autocall <val>
831 -autocall <val>
1099 Make IPython automatically call any callable object even if you
832 Make IPython automatically call any callable object even if you
1100 didn't type explicit parentheses. For example, 'str 43' becomes
833 didn't type explicit parentheses. For example, 'str 43' becomes
1101 'str(43)' automatically. The value can be '0' to disable the feature,
834 'str(43)' automatically. The value can be '0' to disable the feature,
1102 '1' for smart autocall, where it is not applied if there are no more
835 '1' for smart autocall, where it is not applied if there are no more
1103 arguments on the line, and '2' for full autocall, where all callable
836 arguments on the line, and '2' for full autocall, where all callable
1104 objects are automatically called (even if no arguments are
837 objects are automatically called (even if no arguments are
1105 present). The default is '1'.
838 present). The default is '1'.
1106
839
1107 -[no]autoindent
840 -[no]autoindent
1108 Turn automatic indentation on/off.
841 Turn automatic indentation on/off.
1109
842
1110 -[no]automagic
843 -[no]automagic
1111 make magic commands automatic (without needing their first character
844 make magic commands automatic (without needing their first character
1112 to be %). Type %magic at the IPython prompt for more information.
845 to be %). Type %magic at the IPython prompt for more information.
1113
846
1114 -[no]autoedit_syntax
847 -[no]autoedit_syntax
1115 When a syntax error occurs after editing a file, automatically
848 When a syntax error occurs after editing a file, automatically
1116 open the file to the trouble causing line for convenient
849 open the file to the trouble causing line for convenient
1117 fixing.
850 fixing.
1118
851
1119 -[no]banner Print the initial information banner (default on).
852 -[no]banner Print the initial information banner (default on).
1120
853
1121 -c <command>
854 -c <command>
1122 execute the given command string. This is similar to the -c
855 execute the given command string. This is similar to the -c
1123 option in the normal Python interpreter.
856 option in the normal Python interpreter.
1124
857
1125 -cache_size, cs <n>
858 -cache_size, cs <n>
1126 size of the output cache (maximum number of entries to hold in
859 size of the output cache (maximum number of entries to hold in
1127 memory). The default is 1000, you can change it permanently in your
860 memory). The default is 1000, you can change it permanently in your
1128 config file. Setting it to 0 completely disables the caching system,
861 config file. Setting it to 0 completely disables the caching system,
1129 and the minimum value accepted is 20 (if you provide a value less than
862 and the minimum value accepted is 20 (if you provide a value less than
1130 20, it is reset to 0 and a warning is issued) This limit is defined
863 20, it is reset to 0 and a warning is issued) This limit is defined
1131 because otherwise you'll spend more time re-flushing a too small cache
864 because otherwise you'll spend more time re-flushing a too small cache
1132 than working.
865 than working.
1133
866
1134 -classic, cl
867 -classic, cl
1135 Gives IPython a similar feel to the classic Python
868 Gives IPython a similar feel to the classic Python
1136 prompt.
869 prompt.
1137
870
1138 -colors <scheme>
871 -colors <scheme>
1139 Color scheme for prompts and exception reporting. Currently
872 Color scheme for prompts and exception reporting. Currently
1140 implemented: NoColor, Linux and LightBG.
873 implemented: NoColor, Linux and LightBG.
1141
874
1142 -[no]color_info
875 -[no]color_info
1143 IPython can display information about objects via a set of functions,
876 IPython can display information about objects via a set of functions,
1144 and optionally can use colors for this, syntax highlighting source
877 and optionally can use colors for this, syntax highlighting source
1145 code and various other elements. However, because this information is
878 code and various other elements. However, because this information is
1146 passed through a pager (like 'less') and many pagers get confused with
879 passed through a pager (like 'less') and many pagers get confused with
1147 color codes, this option is off by default. You can test it and turn
880 color codes, this option is off by default. You can test it and turn
1148 it on permanently in your ipythonrc file if it works for you. As a
881 it on permanently in your ipythonrc file if it works for you. As a
1149 reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
882 reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
1150 that in RedHat 7.2 doesn't.
883 that in RedHat 7.2 doesn't.
1151
884
1152 Test it and turn it on permanently if it works with your
885 Test it and turn it on permanently if it works with your
1153 system. The magic function %color_info allows you to toggle this
886 system. The magic function %color_info allows you to toggle this
1154 interactively for testing.
887 interactively for testing.
1155
888
1156 -[no]debug
889 -[no]debug
1157 Show information about the loading process. Very useful to pin down
890 Show information about the loading process. Very useful to pin down
1158 problems with your configuration files or to get details about
891 problems with your configuration files or to get details about
1159 session restores.
892 session restores.
1160
893
1161 -[no]deep_reload:
894 -[no]deep_reload:
1162 IPython can use the deep_reload module which reloads changes in
895 IPython can use the deep_reload module which reloads changes in
1163 modules recursively (it replaces the reload() function, so you don't
896 modules recursively (it replaces the reload() function, so you don't
1164 need to change anything to use it). deep_reload() forces a full
897 need to change anything to use it). deep_reload() forces a full
1165 reload of modules whose code may have changed, which the default
898 reload of modules whose code may have changed, which the default
1166 reload() function does not.
899 reload() function does not.
1167
900
1168 When deep_reload is off, IPython will use the normal reload(),
901 When deep_reload is off, IPython will use the normal reload(),
1169 but deep_reload will still be available as dreload(). This
902 but deep_reload will still be available as dreload(). This
1170 feature is off by default [which means that you have both
903 feature is off by default [which means that you have both
1171 normal reload() and dreload()].
904 normal reload() and dreload()].
1172
905
1173 -editor <name>
906 -editor <name>
1174 Which editor to use with the %edit command. By default,
907 Which editor to use with the %edit command. By default,
1175 IPython will honor your EDITOR environment variable (if not
908 IPython will honor your EDITOR environment variable (if not
1176 set, vi is the Unix default and notepad the Windows one).
909 set, vi is the Unix default and notepad the Windows one).
1177 Since this editor is invoked on the fly by IPython and is
910 Since this editor is invoked on the fly by IPython and is
1178 meant for editing small code snippets, you may want to use a
911 meant for editing small code snippets, you may want to use a
1179 small, lightweight editor here (in case your default EDITOR is
912 small, lightweight editor here (in case your default EDITOR is
1180 something like Emacs).
913 something like Emacs).
1181
914
1182 -ipythondir <name>
915 -ipythondir <name>
1183 name of your IPython configuration directory IPYTHONDIR. This
916 name of your IPython configuration directory IPYTHONDIR. This
1184 can also be specified through the environment variable
917 can also be specified through the environment variable
1185 IPYTHONDIR.
918 IPYTHONDIR.
1186
919
1187 -log, l
920 -log, l
1188 generate a log file of all input. The file is named
921 generate a log file of all input. The file is named
1189 ipython_log.py in your current directory (which prevents logs
922 ipython_log.py in your current directory (which prevents logs
1190 from multiple IPython sessions from trampling each other). You
923 from multiple IPython sessions from trampling each other). You
1191 can use this to later restore a session by loading your
924 can use this to later restore a session by loading your
1192 logfile as a file to be executed with option -logplay (see
925 logfile as a file to be executed with option -logplay (see
1193 below).
926 below).
1194
927
1195 -logfile, lf <name> specify the name of your logfile.
928 -logfile, lf <name> specify the name of your logfile.
1196
929
1197 -logplay, lp <name>
930 -logplay, lp <name>
1198
931
1199 you can replay a previous log. For restoring a session as close as
932 you can replay a previous log. For restoring a session as close as
1200 possible to the state you left it in, use this option (don't just run
933 possible to the state you left it in, use this option (don't just run
1201 the logfile). With -logplay, IPython will try to reconstruct the
934 the logfile). With -logplay, IPython will try to reconstruct the
1202 previous working environment in full, not just execute the commands in
935 previous working environment in full, not just execute the commands in
1203 the logfile.
936 the logfile.
1204
937
1205 When a session is restored, logging is automatically turned on
938 When a session is restored, logging is automatically turned on
1206 again with the name of the logfile it was invoked with (it is
939 again with the name of the logfile it was invoked with (it is
1207 read from the log header). So once you've turned logging on for
940 read from the log header). So once you've turned logging on for
1208 a session, you can quit IPython and reload it as many times as
941 a session, you can quit IPython and reload it as many times as
1209 you want and it will continue to log its history and restore
942 you want and it will continue to log its history and restore
1210 from the beginning every time.
943 from the beginning every time.
1211
944
1212 Caveats: there are limitations in this option. The history
945 Caveats: there are limitations in this option. The history
1213 variables _i*,_* and _dh don't get restored properly. In the
946 variables _i*,_* and _dh don't get restored properly. In the
1214 future we will try to implement full session saving by writing
947 future we will try to implement full session saving by writing
1215 and retrieving a 'snapshot' of the memory state of IPython. But
948 and retrieving a 'snapshot' of the memory state of IPython. But
1216 our first attempts failed because of inherent limitations of
949 our first attempts failed because of inherent limitations of
1217 Python's Pickle module, so this may have to wait.
950 Python's Pickle module, so this may have to wait.
1218
951
1219 -[no]messages
952 -[no]messages
1220 Print messages which IPython collects about its startup
953 Print messages which IPython collects about its startup
1221 process (default on).
954 process (default on).
1222
955
1223 -[no]pdb
956 -[no]pdb
1224 Automatically call the pdb debugger after every uncaught
957 Automatically call the pdb debugger after every uncaught
1225 exception. If you are used to debugging using pdb, this puts
958 exception. If you are used to debugging using pdb, this puts
1226 you automatically inside of it after any call (either in
959 you automatically inside of it after any call (either in
1227 IPython or in code called by it) which triggers an exception
960 IPython or in code called by it) which triggers an exception
1228 which goes uncaught.
961 which goes uncaught.
1229
962
1230 -pydb
963 -pydb
1231 Makes IPython use the third party "pydb" package as debugger,
964 Makes IPython use the third party "pydb" package as debugger,
1232 instead of pdb. Requires that pydb is installed.
965 instead of pdb. Requires that pydb is installed.
1233
966
1234 -[no]pprint
967 -[no]pprint
1235 ipython can optionally use the pprint (pretty printer) module
968 ipython can optionally use the pprint (pretty printer) module
1236 for displaying results. pprint tends to give a nicer display
969 for displaying results. pprint tends to give a nicer display
1237 of nested data structures. If you like it, you can turn it on
970 of nested data structures. If you like it, you can turn it on
1238 permanently in your config file (default off).
971 permanently in your config file (default off).
1239
972
1240 -profile, p <name>
973 -profile, p <name>
1241
974
1242 assume that your config file is ipythonrc-<name> or
975 assume that your config file is ipythonrc-<name> or
1243 ipy_profile_<name>.py (looks in current dir first, then in
976 ipy_profile_<name>.py (looks in current dir first, then in
1244 IPYTHONDIR). This is a quick way to keep and load multiple
977 IPYTHONDIR). This is a quick way to keep and load multiple
1245 config files for different tasks, especially if you use the
978 config files for different tasks, especially if you use the
1246 include option of config files. You can keep a basic
979 include option of config files. You can keep a basic
1247 IPYTHONDIR/ipythonrc file and then have other 'profiles' which
980 IPYTHONDIR/ipythonrc file and then have other 'profiles' which
1248 include this one and load extra things for particular
981 include this one and load extra things for particular
1249 tasks. For example:
982 tasks. For example:
1250
983
1251 1. $HOME/.ipython/ipythonrc : load basic things you always want.
984 1. $HOME/.ipython/ipythonrc : load basic things you always want.
1252 2. $HOME/.ipython/ipythonrc-math : load (1) and basic math-related modules.
985 2. $HOME/.ipython/ipythonrc-math : load (1) and basic math-related modules.
1253 3. $HOME/.ipython/ipythonrc-numeric : load (1) and Numeric and plotting modules.
986 3. $HOME/.ipython/ipythonrc-numeric : load (1) and Numeric and plotting modules.
1254
987
1255 Since it is possible to create an endless loop by having
988 Since it is possible to create an endless loop by having
1256 circular file inclusions, IPython will stop if it reaches 15
989 circular file inclusions, IPython will stop if it reaches 15
1257 recursive inclusions.
990 recursive inclusions.
1258
991
1259 -prompt_in1, pi1 <string>
992 -prompt_in1, pi1 <string>
1260 Specify the string used for input prompts. Note that if you
993 Specify the string used for input prompts. Note that if you
1261 are using numbered prompts, the number is represented with a
994 are using numbered prompts, the number is represented with a
1262 '\#' in the string. Don't forget to quote strings with spaces
995 '\#' in the string. Don't forget to quote strings with spaces
1263 embedded in them. Default: 'In [\#]:'. Sec. Prompts_
996 embedded in them. Default: 'In [\#]:'. Sec. Prompts_
1264 discusses in detail all the available escapes to customize
997 discusses in detail all the available escapes to customize
1265 your prompts.
998 your prompts.
1266
999
1267 -prompt_in2, pi2 <string>
1000 -prompt_in2, pi2 <string>
1268 Similar to the previous option, but used for the continuation
1001 Similar to the previous option, but used for the continuation
1269 prompts. The special sequence '\D' is similar to '\#', but
1002 prompts. The special sequence '\D' is similar to '\#', but
1270 with all digits replaced dots (so you can have your
1003 with all digits replaced dots (so you can have your
1271 continuation prompt aligned with your input prompt). Default:
1004 continuation prompt aligned with your input prompt). Default:
1272 ' .\D.:' (note three spaces at the start for alignment with
1005 ' .\D.:' (note three spaces at the start for alignment with
1273 'In [\#]').
1006 'In [\#]').
1274
1007
1275 -prompt_out,po <string>
1008 -prompt_out,po <string>
1276 String used for output prompts, also uses numbers like
1009 String used for output prompts, also uses numbers like
1277 prompt_in1. Default: 'Out[\#]:'
1010 prompt_in1. Default: 'Out[\#]:'
1278
1011
1279 -quick start in bare bones mode (no config file loaded).
1012 -quick start in bare bones mode (no config file loaded).
1280
1013
1281 -rcfile <name>
1014 -rcfile <name>
1282 name of your IPython resource configuration file. Normally
1015 name of your IPython resource configuration file. Normally
1283 IPython loads ipythonrc (from current directory) or
1016 IPython loads ipythonrc (from current directory) or
1284 IPYTHONDIR/ipythonrc.
1017 IPYTHONDIR/ipythonrc.
1285
1018
1286 If the loading of your config file fails, IPython starts with
1019 If the loading of your config file fails, IPython starts with
1287 a bare bones configuration (no modules loaded at all).
1020 a bare bones configuration (no modules loaded at all).
1288
1021
1289 -[no]readline
1022 -[no]readline
1290 use the readline library, which is needed to support name
1023 use the readline library, which is needed to support name
1291 completion and command history, among other things. It is
1024 completion and command history, among other things. It is
1292 enabled by default, but may cause problems for users of
1025 enabled by default, but may cause problems for users of
1293 X/Emacs in Python comint or shell buffers.
1026 X/Emacs in Python comint or shell buffers.
1294
1027
1295 Note that X/Emacs 'eterm' buffers (opened with M-x term) support
1028 Note that X/Emacs 'eterm' buffers (opened with M-x term) support
1296 IPython's readline and syntax coloring fine, only 'emacs' (M-x
1029 IPython's readline and syntax coloring fine, only 'emacs' (M-x
1297 shell and C-c !) buffers do not.
1030 shell and C-c !) buffers do not.
1298
1031
1299 -screen_length, sl <n>
1032 -screen_length, sl <n>
1300 number of lines of your screen. This is used to control
1033 number of lines of your screen. This is used to control
1301 printing of very long strings. Strings longer than this number
1034 printing of very long strings. Strings longer than this number
1302 of lines will be sent through a pager instead of directly
1035 of lines will be sent through a pager instead of directly
1303 printed.
1036 printed.
1304
1037
1305 The default value for this is 0, which means IPython will
1038 The default value for this is 0, which means IPython will
1306 auto-detect your screen size every time it needs to print certain
1039 auto-detect your screen size every time it needs to print certain
1307 potentially long strings (this doesn't change the behavior of the
1040 potentially long strings (this doesn't change the behavior of the
1308 'print' keyword, it's only triggered internally). If for some
1041 'print' keyword, it's only triggered internally). If for some
1309 reason this isn't working well (it needs curses support), specify
1042 reason this isn't working well (it needs curses support), specify
1310 it yourself. Otherwise don't change the default.
1043 it yourself. Otherwise don't change the default.
1311
1044
1312 -separate_in, si <string>
1045 -separate_in, si <string>
1313
1046
1314 separator before input prompts.
1047 separator before input prompts.
1315 Default: '\n'
1048 Default: '\n'
1316
1049
1317 -separate_out, so <string>
1050 -separate_out, so <string>
1318 separator before output prompts.
1051 separator before output prompts.
1319 Default: nothing.
1052 Default: nothing.
1320
1053
1321 -separate_out2, so2
1054 -separate_out2, so2
1322 separator after output prompts.
1055 separator after output prompts.
1323 Default: nothing.
1056 Default: nothing.
1324 For these three options, use the value 0 to specify no separator.
1057 For these three options, use the value 0 to specify no separator.
1325
1058
1326 -nosep
1059 -nosep
1327 shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2
1060 shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2
1328 0'. Simply removes all input/output separators.
1061 0'. Simply removes all input/output separators.
1329
1062
1330 -upgrade
1063 -upgrade
1331 allows you to upgrade your IPYTHONDIR configuration when you
1064 allows you to upgrade your IPYTHONDIR configuration when you
1332 install a new version of IPython. Since new versions may
1065 install a new version of IPython. Since new versions may
1333 include new command line options or example files, this copies
1066 include new command line options or example files, this copies
1334 updated ipythonrc-type files. However, it backs up (with a
1067 updated ipythonrc-type files. However, it backs up (with a
1335 .old extension) all files which it overwrites so that you can
1068 .old extension) all files which it overwrites so that you can
1336 merge back any customizations you might have in your personal
1069 merge back any customizations you might have in your personal
1337 files. Note that you should probably use %upgrade instead,
1070 files. Note that you should probably use %upgrade instead,
1338 it's a safer alternative.
1071 it's a safer alternative.
1339
1072
1340
1073
1341 -Version print version information and exit.
1074 -Version print version information and exit.
1342
1075
1343 -wxversion <string>
1076 -wxversion <string>
1344 Select a specific version of wxPython (used in conjunction
1077 Select a specific version of wxPython (used in conjunction
1345 with -wthread). Requires the wxversion module, part of recent
1078 with -wthread). Requires the wxversion module, part of recent
1346 wxPython distributions
1079 wxPython distributions
1347
1080
1348 -xmode <modename>
1081 -xmode <modename>
1349
1082
1350 Mode for exception reporting.
1083 Mode for exception reporting.
1351
1084
1352 Valid modes: Plain, Context and Verbose.
1085 Valid modes: Plain, Context and Verbose.
1353
1086
1354 * Plain: similar to python's normal traceback printing.
1087 * Plain: similar to python's normal traceback printing.
1355 * Context: prints 5 lines of context source code around each
1088 * Context: prints 5 lines of context source code around each
1356 line in the traceback.
1089 line in the traceback.
1357 * Verbose: similar to Context, but additionally prints the
1090 * Verbose: similar to Context, but additionally prints the
1358 variables currently visible where the exception happened
1091 variables currently visible where the exception happened
1359 (shortening their strings if too long). This can potentially be
1092 (shortening their strings if too long). This can potentially be
1360 very slow, if you happen to have a huge data structure whose
1093 very slow, if you happen to have a huge data structure whose
1361 string representation is complex to compute. Your computer may
1094 string representation is complex to compute. Your computer may
1362 appear to freeze for a while with cpu usage at 100%. If this
1095 appear to freeze for a while with cpu usage at 100%. If this
1363 occurs, you can cancel the traceback with Ctrl-C (maybe hitting it
1096 occurs, you can cancel the traceback with Ctrl-C (maybe hitting it
1364 more than once).
1097 more than once).
1365
1098
1366 Interactive use
1099 Interactive use
1367 ===============
1100 ===============
1368
1101
1369 Warning: IPython relies on the existence of a global variable called
1102 Warning: IPython relies on the existence of a global variable called
1370 _ip which controls the shell itself. If you redefine _ip to anything,
1103 _ip which controls the shell itself. If you redefine _ip to anything,
1371 bizarre behavior will quickly occur.
1104 bizarre behavior will quickly occur.
1372
1105
1373 Other than the above warning, IPython is meant to work as a drop-in
1106 Other than the above warning, IPython is meant to work as a drop-in
1374 replacement for the standard interactive interpreter. As such, any code
1107 replacement for the standard interactive interpreter. As such, any code
1375 which is valid python should execute normally under IPython (cases where
1108 which is valid python should execute normally under IPython (cases where
1376 this is not true should be reported as bugs). It does, however, offer
1109 this is not true should be reported as bugs). It does, however, offer
1377 many features which are not available at a standard python prompt. What
1110 many features which are not available at a standard python prompt. What
1378 follows is a list of these.
1111 follows is a list of these.
1379
1112
1380
1113
1381 Caution for Windows users
1114 Caution for Windows users
1382 -------------------------
1115 -------------------------
1383
1116
1384 Windows, unfortunately, uses the '\' character as a path
1117 Windows, unfortunately, uses the '\' character as a path
1385 separator. This is a terrible choice, because '\' also represents the
1118 separator. This is a terrible choice, because '\' also represents the
1386 escape character in most modern programming languages, including
1119 escape character in most modern programming languages, including
1387 Python. For this reason, using '/' character is recommended if you
1120 Python. For this reason, using '/' character is recommended if you
1388 have problems with ``\``. However, in Windows commands '/' flags
1121 have problems with ``\``. However, in Windows commands '/' flags
1389 options, so you can not use it for the root directory. This means that
1122 options, so you can not use it for the root directory. This means that
1390 paths beginning at the root must be typed in a contrived manner like:
1123 paths beginning at the root must be typed in a contrived manner like:
1391 ``%copy \opt/foo/bar.txt \tmp``
1124 ``%copy \opt/foo/bar.txt \tmp``
1392
1125
1393 .. _magic:
1126 .. _magic:
1394
1127
1395 Magic command system
1128 Magic command system
1396 --------------------
1129 --------------------
1397
1130
1398 IPython will treat any line whose first character is a % as a special
1131 IPython will treat any line whose first character is a % as a special
1399 call to a 'magic' function. These allow you to control the behavior of
1132 call to a 'magic' function. These allow you to control the behavior of
1400 IPython itself, plus a lot of system-type features. They are all
1133 IPython itself, plus a lot of system-type features. They are all
1401 prefixed with a % character, but parameters are given without
1134 prefixed with a % character, but parameters are given without
1402 parentheses or quotes.
1135 parentheses or quotes.
1403
1136
1404 Example: typing '%cd mydir' (without the quotes) changes you working
1137 Example: typing '%cd mydir' (without the quotes) changes you working
1405 directory to 'mydir', if it exists.
1138 directory to 'mydir', if it exists.
1406
1139
1407 If you have 'automagic' enabled (in your ipythonrc file, via the command
1140 If you have 'automagic' enabled (in your ipythonrc file, via the command
1408 line option -automagic or with the %automagic function), you don't need
1141 line option -automagic or with the %automagic function), you don't need
1409 to type in the % explicitly. IPython will scan its internal list of
1142 to type in the % explicitly. IPython will scan its internal list of
1410 magic functions and call one if it exists. With automagic on you can
1143 magic functions and call one if it exists. With automagic on you can
1411 then just type 'cd mydir' to go to directory 'mydir'. The automagic
1144 then just type 'cd mydir' to go to directory 'mydir'. The automagic
1412 system has the lowest possible precedence in name searches, so defining
1145 system has the lowest possible precedence in name searches, so defining
1413 an identifier with the same name as an existing magic function will
1146 an identifier with the same name as an existing magic function will
1414 shadow it for automagic use. You can still access the shadowed magic
1147 shadow it for automagic use. You can still access the shadowed magic
1415 function by explicitly using the % character at the beginning of the line.
1148 function by explicitly using the % character at the beginning of the line.
1416
1149
1417 An example (with automagic on) should clarify all this::
1150 An example (with automagic on) should clarify all this::
1418
1151
1419 In [1]: cd ipython # %cd is called by automagic
1152 In [1]: cd ipython # %cd is called by automagic
1420
1153
1421 /home/fperez/ipython
1154 /home/fperez/ipython
1422
1155
1423 In [2]: cd=1 # now cd is just a variable
1156 In [2]: cd=1 # now cd is just a variable
1424
1157
1425 In [3]: cd .. # and doesn't work as a function anymore
1158 In [3]: cd .. # and doesn't work as a function anymore
1426
1159
1427 ------------------------------
1160 ------------------------------
1428
1161
1429 File "<console>", line 1
1162 File "<console>", line 1
1430
1163
1431 cd ..
1164 cd ..
1432
1165
1433 ^
1166 ^
1434
1167
1435 SyntaxError: invalid syntax
1168 SyntaxError: invalid syntax
1436
1169
1437 In [4]: %cd .. # but %cd always works
1170 In [4]: %cd .. # but %cd always works
1438
1171
1439 /home/fperez
1172 /home/fperez
1440
1173
1441 In [5]: del cd # if you remove the cd variable
1174 In [5]: del cd # if you remove the cd variable
1442
1175
1443 In [6]: cd ipython # automagic can work again
1176 In [6]: cd ipython # automagic can work again
1444
1177
1445 /home/fperez/ipython
1178 /home/fperez/ipython
1446
1179
1447 You can define your own magic functions to extend the system. The
1180 You can define your own magic functions to extend the system. The
1448 following example defines a new magic command, %impall::
1181 following example defines a new magic command, %impall::
1449
1182
1450 import IPython.ipapi
1183 import IPython.ipapi
1451
1184
1452 ip = IPython.ipapi.get()
1185 ip = IPython.ipapi.get()
1453
1186
1454 def doimp(self, arg):
1187 def doimp(self, arg):
1455
1188
1456 ip = self.api
1189 ip = self.api
1457
1190
1458 ip.ex("import %s; reload(%s); from %s import *" % (
1191 ip.ex("import %s; reload(%s); from %s import *" % (
1459
1192
1460 arg,arg,arg)
1193 arg,arg,arg)
1461
1194
1462 )
1195 )
1463
1196
1464 ip.expose_magic('impall', doimp)
1197 ip.expose_magic('impall', doimp)
1465
1198
1466 You can also define your own aliased names for magic functions. In your
1199 You can also define your own aliased names for magic functions. In your
1467 ipythonrc file, placing a line like:
1200 ipythonrc file, placing a line like:
1468
1201
1469 execute __IP.magic_cl = __IP.magic_clear
1202 execute __IP.magic_cl = __IP.magic_clear
1470
1203
1471 will define %cl as a new name for %clear.
1204 will define %cl as a new name for %clear.
1472
1205
1473 Type %magic for more information, including a list of all available
1206 Type %magic for more information, including a list of all available
1474 magic functions at any time and their docstrings. You can also type
1207 magic functions at any time and their docstrings. You can also type
1475 %magic_function_name? (see sec. 6.4 <#sec:dyn-object-info> for
1208 %magic_function_name? (see sec. 6.4 <#sec:dyn-object-info> for
1476 information on the '?' system) to get information about any particular
1209 information on the '?' system) to get information about any particular
1477 magic function you are interested in.
1210 magic function you are interested in.
1478
1211
1479
1212
1480 Magic commands
1213 Magic commands
1481 --------------
1214 --------------
1482
1215
1483 The rest of this section is automatically generated for each release
1216 The rest of this section is automatically generated for each release
1484 from the docstrings in the IPython code. Therefore the formatting is
1217 from the docstrings in the IPython code. Therefore the formatting is
1485 somewhat minimal, but this method has the advantage of having
1218 somewhat minimal, but this method has the advantage of having
1486 information always in sync with the code.
1219 information always in sync with the code.
1487
1220
1488 A list of all the magic commands available in IPython's default
1221 A list of all the magic commands available in IPython's default
1489 installation follows. This is similar to what you'll see by simply
1222 installation follows. This is similar to what you'll see by simply
1490 typing %magic at the prompt, but that will also give you information
1223 typing %magic at the prompt, but that will also give you information
1491 about magic commands you may have added as part of your personal
1224 about magic commands you may have added as part of your personal
1492 customizations.
1225 customizations.
1493
1226
1494 .. magic_start
1227 .. magic_start
1495
1228
1496 **%Exit**::
1229 **%Exit**::
1497
1230
1498 Exit IPython without confirmation.
1231 Exit IPython without confirmation.
1499
1232
1500 **%Pprint**::
1233 **%Pprint**::
1501
1234
1502 Toggle pretty printing on/off.
1235 Toggle pretty printing on/off.
1503
1236
1504 **%alias**::
1237 **%alias**::
1505
1238
1506 Define an alias for a system command.
1239 Define an alias for a system command.
1507
1240
1508 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
1241 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
1509
1242
1510 Then, typing 'alias_name params' will execute the system command 'cmd
1243 Then, typing 'alias_name params' will execute the system command 'cmd
1511 params' (from your underlying operating system).
1244 params' (from your underlying operating system).
1512
1245
1513 Aliases have lower precedence than magic functions and Python normal
1246 Aliases have lower precedence than magic functions and Python normal
1514 variables, so if 'foo' is both a Python variable and an alias, the
1247 variables, so if 'foo' is both a Python variable and an alias, the
1515 alias can not be executed until 'del foo' removes the Python variable.
1248 alias can not be executed until 'del foo' removes the Python variable.
1516
1249
1517 You can use the %l specifier in an alias definition to represent the
1250 You can use the %l specifier in an alias definition to represent the
1518 whole line when the alias is called. For example:
1251 whole line when the alias is called. For example:
1519
1252
1520 In [2]: alias all echo "Input in brackets: <%l>"\
1253 In [2]: alias all echo "Input in brackets: <%l>"\
1521 In [3]: all hello world\
1254 In [3]: all hello world\
1522 Input in brackets: <hello world>
1255 Input in brackets: <hello world>
1523
1256
1524 You can also define aliases with parameters using %s specifiers (one
1257 You can also define aliases with parameters using %s specifiers (one
1525 per parameter):
1258 per parameter):
1526
1259
1527 In [1]: alias parts echo first %s second %s\
1260 In [1]: alias parts echo first %s second %s\
1528 In [2]: %parts A B\
1261 In [2]: %parts A B\
1529 first A second B\
1262 first A second B\
1530 In [3]: %parts A\
1263 In [3]: %parts A\
1531 Incorrect number of arguments: 2 expected.\
1264 Incorrect number of arguments: 2 expected.\
1532 parts is an alias to: 'echo first %s second %s'
1265 parts is an alias to: 'echo first %s second %s'
1533
1266
1534 Note that %l and %s are mutually exclusive. You can only use one or
1267 Note that %l and %s are mutually exclusive. You can only use one or
1535 the other in your aliases.
1268 the other in your aliases.
1536
1269
1537 Aliases expand Python variables just like system calls using ! or !!
1270 Aliases expand Python variables just like system calls using ! or !!
1538 do: all expressions prefixed with '$' get expanded. For details of
1271 do: all expressions prefixed with '$' get expanded. For details of
1539 the semantic rules, see PEP-215:
1272 the semantic rules, see PEP-215:
1540 http://www.python.org/peps/pep-0215.html. This is the library used by
1273 http://www.python.org/peps/pep-0215.html. This is the library used by
1541 IPython for variable expansion. If you want to access a true shell
1274 IPython for variable expansion. If you want to access a true shell
1542 variable, an extra $ is necessary to prevent its expansion by IPython:
1275 variable, an extra $ is necessary to prevent its expansion by IPython:
1543
1276
1544 In [6]: alias show echo\
1277 In [6]: alias show echo\
1545 In [7]: PATH='A Python string'\
1278 In [7]: PATH='A Python string'\
1546 In [8]: show $PATH\
1279 In [8]: show $PATH\
1547 A Python string\
1280 A Python string\
1548 In [9]: show $$PATH\
1281 In [9]: show $$PATH\
1549 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1282 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1550
1283
1551 You can use the alias facility to acess all of $PATH. See the %rehash
1284 You can use the alias facility to acess all of $PATH. See the %rehash
1552 and %rehashx functions, which automatically create aliases for the
1285 and %rehashx functions, which automatically create aliases for the
1553 contents of your $PATH.
1286 contents of your $PATH.
1554
1287
1555 If called with no parameters, %alias prints the current alias table.
1288 If called with no parameters, %alias prints the current alias table.
1556
1289
1557 **%autocall**::
1290 **%autocall**::
1558
1291
1559 Make functions callable without having to type parentheses.
1292 Make functions callable without having to type parentheses.
1560
1293
1561 Usage:
1294 Usage:
1562
1295
1563 %autocall [mode]
1296 %autocall [mode]
1564
1297
1565 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
1298 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
1566 value is toggled on and off (remembering the previous state).
1299 value is toggled on and off (remembering the previous state).
1567
1300
1568 In more detail, these values mean:
1301 In more detail, these values mean:
1569
1302
1570 0 -> fully disabled
1303 0 -> fully disabled
1571
1304
1572 1 -> active, but do not apply if there are no arguments on the line.
1305 1 -> active, but do not apply if there are no arguments on the line.
1573
1306
1574 In this mode, you get:
1307 In this mode, you get:
1575
1308
1576 In [1]: callable
1309 In [1]: callable
1577 Out[1]: <built-in function callable>
1310 Out[1]: <built-in function callable>
1578
1311
1579 In [2]: callable 'hello'
1312 In [2]: callable 'hello'
1580 ------> callable('hello')
1313 ------> callable('hello')
1581 Out[2]: False
1314 Out[2]: False
1582
1315
1583 2 -> Active always. Even if no arguments are present, the callable
1316 2 -> Active always. Even if no arguments are present, the callable
1584 object is called:
1317 object is called:
1585
1318
1586 In [4]: callable
1319 In [4]: callable
1587 ------> callable()
1320 ------> callable()
1588
1321
1589 Note that even with autocall off, you can still use '/' at the start of
1322 Note that even with autocall off, you can still use '/' at the start of
1590 a line to treat the first argument on the command line as a function
1323 a line to treat the first argument on the command line as a function
1591 and add parentheses to it:
1324 and add parentheses to it:
1592
1325
1593 In [8]: /str 43
1326 In [8]: /str 43
1594 ------> str(43)
1327 ------> str(43)
1595 Out[8]: '43'
1328 Out[8]: '43'
1596
1329
1597 **%autoindent**::
1330 **%autoindent**::
1598
1331
1599 Toggle autoindent on/off (if available).
1332 Toggle autoindent on/off (if available).
1600
1333
1601 **%automagic**::
1334 **%automagic**::
1602
1335
1603 Make magic functions callable without having to type the initial %.
1336 Make magic functions callable without having to type the initial %.
1604
1337
1605 Without argumentsl toggles on/off (when off, you must call it as
1338 Without argumentsl toggles on/off (when off, you must call it as
1606 %automagic, of course). With arguments it sets the value, and you can
1339 %automagic, of course). With arguments it sets the value, and you can
1607 use any of (case insensitive):
1340 use any of (case insensitive):
1608
1341
1609 - on,1,True: to activate
1342 - on,1,True: to activate
1610
1343
1611 - off,0,False: to deactivate.
1344 - off,0,False: to deactivate.
1612
1345
1613 Note that magic functions have lowest priority, so if there's a
1346 Note that magic functions have lowest priority, so if there's a
1614 variable whose name collides with that of a magic fn, automagic won't
1347 variable whose name collides with that of a magic fn, automagic won't
1615 work for that function (you get the variable instead). However, if you
1348 work for that function (you get the variable instead). However, if you
1616 delete the variable (del var), the previously shadowed magic function
1349 delete the variable (del var), the previously shadowed magic function
1617 becomes visible to automagic again.
1350 becomes visible to automagic again.
1618
1351
1619 **%bg**::
1352 **%bg**::
1620
1353
1621 Run a job in the background, in a separate thread.
1354 Run a job in the background, in a separate thread.
1622
1355
1623 For example,
1356 For example,
1624
1357
1625 %bg myfunc(x,y,z=1)
1358 %bg myfunc(x,y,z=1)
1626
1359
1627 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
1360 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
1628 execution starts, a message will be printed indicating the job
1361 execution starts, a message will be printed indicating the job
1629 number. If your job number is 5, you can use
1362 number. If your job number is 5, you can use
1630
1363
1631 myvar = jobs.result(5) or myvar = jobs[5].result
1364 myvar = jobs.result(5) or myvar = jobs[5].result
1632
1365
1633 to assign this result to variable 'myvar'.
1366 to assign this result to variable 'myvar'.
1634
1367
1635 IPython has a job manager, accessible via the 'jobs' object. You can
1368 IPython has a job manager, accessible via the 'jobs' object. You can
1636 type jobs? to get more information about it, and use jobs.<TAB> to see
1369 type jobs? to get more information about it, and use jobs.<TAB> to see
1637 its attributes. All attributes not starting with an underscore are
1370 its attributes. All attributes not starting with an underscore are
1638 meant for public use.
1371 meant for public use.
1639
1372
1640 In particular, look at the jobs.new() method, which is used to create
1373 In particular, look at the jobs.new() method, which is used to create
1641 new jobs. This magic %bg function is just a convenience wrapper
1374 new jobs. This magic %bg function is just a convenience wrapper
1642 around jobs.new(), for expression-based jobs. If you want to create a
1375 around jobs.new(), for expression-based jobs. If you want to create a
1643 new job with an explicit function object and arguments, you must call
1376 new job with an explicit function object and arguments, you must call
1644 jobs.new() directly.
1377 jobs.new() directly.
1645
1378
1646 The jobs.new docstring also describes in detail several important
1379 The jobs.new docstring also describes in detail several important
1647 caveats associated with a thread-based model for background job
1380 caveats associated with a thread-based model for background job
1648 execution. Type jobs.new? for details.
1381 execution. Type jobs.new? for details.
1649
1382
1650 You can check the status of all jobs with jobs.status().
1383 You can check the status of all jobs with jobs.status().
1651
1384
1652 The jobs variable is set by IPython into the Python builtin namespace.
1385 The jobs variable is set by IPython into the Python builtin namespace.
1653 If you ever declare a variable named 'jobs', you will shadow this
1386 If you ever declare a variable named 'jobs', you will shadow this
1654 name. You can either delete your global jobs variable to regain
1387 name. You can either delete your global jobs variable to regain
1655 access to the job manager, or make a new name and assign it manually
1388 access to the job manager, or make a new name and assign it manually
1656 to the manager (stored in IPython's namespace). For example, to
1389 to the manager (stored in IPython's namespace). For example, to
1657 assign the job manager to the Jobs name, use:
1390 assign the job manager to the Jobs name, use:
1658
1391
1659 Jobs = __builtins__.jobs
1392 Jobs = __builtins__.jobs
1660
1393
1661 **%bookmark**::
1394 **%bookmark**::
1662
1395
1663 Manage IPython's bookmark system.
1396 Manage IPython's bookmark system.
1664
1397
1665 %bookmark <name> - set bookmark to current dir
1398 %bookmark <name> - set bookmark to current dir
1666 %bookmark <name> <dir> - set bookmark to <dir>
1399 %bookmark <name> <dir> - set bookmark to <dir>
1667 %bookmark -l - list all bookmarks
1400 %bookmark -l - list all bookmarks
1668 %bookmark -d <name> - remove bookmark
1401 %bookmark -d <name> - remove bookmark
1669 %bookmark -r - remove all bookmarks
1402 %bookmark -r - remove all bookmarks
1670
1403
1671 You can later on access a bookmarked folder with:
1404 You can later on access a bookmarked folder with:
1672 %cd -b <name>
1405 %cd -b <name>
1673 or simply '%cd <name>' if there is no directory called <name> AND
1406 or simply '%cd <name>' if there is no directory called <name> AND
1674 there is such a bookmark defined.
1407 there is such a bookmark defined.
1675
1408
1676 Your bookmarks persist through IPython sessions, but they are
1409 Your bookmarks persist through IPython sessions, but they are
1677 associated with each profile.
1410 associated with each profile.
1678
1411
1679 **%cd**::
1412 **%cd**::
1680
1413
1681 Change the current working directory.
1414 Change the current working directory.
1682
1415
1683 This command automatically maintains an internal list of directories
1416 This command automatically maintains an internal list of directories
1684 you visit during your IPython session, in the variable _dh. The
1417 you visit during your IPython session, in the variable _dh. The
1685 command %dhist shows this history nicely formatted. You can also
1418 command %dhist shows this history nicely formatted. You can also
1686 do 'cd -<tab>' to see directory history conveniently.
1419 do 'cd -<tab>' to see directory history conveniently.
1687
1420
1688 Usage:
1421 Usage:
1689
1422
1690 cd 'dir': changes to directory 'dir'.
1423 cd 'dir': changes to directory 'dir'.
1691
1424
1692 cd -: changes to the last visited directory.
1425 cd -: changes to the last visited directory.
1693
1426
1694 cd -<n>: changes to the n-th directory in the directory history.
1427 cd -<n>: changes to the n-th directory in the directory history.
1695
1428
1696 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
1429 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
1697 (note: cd <bookmark_name> is enough if there is no
1430 (note: cd <bookmark_name> is enough if there is no
1698 directory <bookmark_name>, but a bookmark with the name exists.)
1431 directory <bookmark_name>, but a bookmark with the name exists.)
1699 'cd -b <tab>' allows you to tab-complete bookmark names.
1432 'cd -b <tab>' allows you to tab-complete bookmark names.
1700
1433
1701 Options:
1434 Options:
1702
1435
1703 -q: quiet. Do not print the working directory after the cd command is
1436 -q: quiet. Do not print the working directory after the cd command is
1704 executed. By default IPython's cd command does print this directory,
1437 executed. By default IPython's cd command does print this directory,
1705 since the default prompts do not display path information.
1438 since the default prompts do not display path information.
1706
1439
1707 Note that !cd doesn't work for this purpose because the shell where
1440 Note that !cd doesn't work for this purpose because the shell where
1708 !command runs is immediately discarded after executing 'command'.
1441 !command runs is immediately discarded after executing 'command'.
1709
1442
1710 **%clear**::
1443 **%clear**::
1711
1444
1712 Clear various data (e.g. stored history data)
1445 Clear various data (e.g. stored history data)
1713
1446
1714 %clear out - clear output history
1447 %clear out - clear output history
1715 %clear in - clear input history
1448 %clear in - clear input history
1716 %clear shadow_compress - Compresses shadow history (to speed up ipython)
1449 %clear shadow_compress - Compresses shadow history (to speed up ipython)
1717 %clear shadow_nuke - permanently erase all entries in shadow history
1450 %clear shadow_nuke - permanently erase all entries in shadow history
1718 %clear dhist - clear dir history
1451 %clear dhist - clear dir history
1719
1452
1720 **%color_info**::
1453 **%color_info**::
1721
1454
1722 Toggle color_info.
1455 Toggle color_info.
1723
1456
1724 The color_info configuration parameter controls whether colors are
1457 The color_info configuration parameter controls whether colors are
1725 used for displaying object details (by things like %psource, %pfile or
1458 used for displaying object details (by things like %psource, %pfile or
1726 the '?' system). This function toggles this value with each call.
1459 the '?' system). This function toggles this value with each call.
1727
1460
1728 Note that unless you have a fairly recent pager (less works better
1461 Note that unless you have a fairly recent pager (less works better
1729 than more) in your system, using colored object information displays
1462 than more) in your system, using colored object information displays
1730 will not work properly. Test it and see.
1463 will not work properly. Test it and see.
1731
1464
1732 **%colors**::
1465 **%colors**::
1733
1466
1734 Switch color scheme for prompts, info system and exception handlers.
1467 Switch color scheme for prompts, info system and exception handlers.
1735
1468
1736 Currently implemented schemes: NoColor, Linux, LightBG.
1469 Currently implemented schemes: NoColor, Linux, LightBG.
1737
1470
1738 Color scheme names are not case-sensitive.
1471 Color scheme names are not case-sensitive.
1739
1472
1740 **%cpaste**::
1473 **%cpaste**::
1741
1474
1742 Allows you to paste & execute a pre-formatted code block from clipboard
1475 Allows you to paste & execute a pre-formatted code block from clipboard
1743
1476
1744 You must terminate the block with '--' (two minus-signs) alone on the
1477 You must terminate the block with '--' (two minus-signs) alone on the
1745 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
1478 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
1746 is the new sentinel for this operation)
1479 is the new sentinel for this operation)
1747
1480
1748 The block is dedented prior to execution to enable execution of method
1481 The block is dedented prior to execution to enable execution of method
1749 definitions. '>' and '+' characters at the beginning of a line are
1482 definitions. '>' and '+' characters at the beginning of a line are
1750 ignored, to allow pasting directly from e-mails or diff files. The
1483 ignored, to allow pasting directly from e-mails or diff files. The
1751 executed block is also assigned to variable named 'pasted_block' for
1484 executed block is also assigned to variable named 'pasted_block' for
1752 later editing with '%edit pasted_block'.
1485 later editing with '%edit pasted_block'.
1753
1486
1754 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
1487 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
1755 This assigns the pasted block to variable 'foo' as string, without
1488 This assigns the pasted block to variable 'foo' as string, without
1756 dedenting or executing it.
1489 dedenting or executing it.
1757
1490
1758 Do not be alarmed by garbled output on Windows (it's a readline bug).
1491 Do not be alarmed by garbled output on Windows (it's a readline bug).
1759 Just press enter and type -- (and press enter again) and the block
1492 Just press enter and type -- (and press enter again) and the block
1760 will be what was just pasted.
1493 will be what was just pasted.
1761
1494
1762 IPython statements (magics, shell escapes) are not supported (yet).
1495 IPython statements (magics, shell escapes) are not supported (yet).
1763
1496
1764 **%debug**::
1497 **%debug**::
1765
1498
1766 Activate the interactive debugger in post-mortem mode.
1499 Activate the interactive debugger in post-mortem mode.
1767
1500
1768 If an exception has just occurred, this lets you inspect its stack
1501 If an exception has just occurred, this lets you inspect its stack
1769 frames interactively. Note that this will always work only on the last
1502 frames interactively. Note that this will always work only on the last
1770 traceback that occurred, so you must call this quickly after an
1503 traceback that occurred, so you must call this quickly after an
1771 exception that you wish to inspect has fired, because if another one
1504 exception that you wish to inspect has fired, because if another one
1772 occurs, it clobbers the previous one.
1505 occurs, it clobbers the previous one.
1773
1506
1774 If you want IPython to automatically do this on every exception, see
1507 If you want IPython to automatically do this on every exception, see
1775 the %pdb magic for more details.
1508 the %pdb magic for more details.
1776
1509
1777 **%dhist**::
1510 **%dhist**::
1778
1511
1779 Print your history of visited directories.
1512 Print your history of visited directories.
1780
1513
1781 %dhist -> print full history\
1514 %dhist -> print full history\
1782 %dhist n -> print last n entries only\
1515 %dhist n -> print last n entries only\
1783 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\
1516 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\
1784
1517
1785 This history is automatically maintained by the %cd command, and
1518 This history is automatically maintained by the %cd command, and
1786 always available as the global list variable _dh. You can use %cd -<n>
1519 always available as the global list variable _dh. You can use %cd -<n>
1787 to go to directory number <n>.
1520 to go to directory number <n>.
1788
1521
1789 Note that most of time, you should view directory history by entering
1522 Note that most of time, you should view directory history by entering
1790 cd -<TAB>.
1523 cd -<TAB>.
1791
1524
1792 **%dirs**::
1525 **%dirs**::
1793
1526
1794 Return the current directory stack.
1527 Return the current directory stack.
1795
1528
1796 **%doctest_mode**::
1529 **%doctest_mode**::
1797
1530
1798 Toggle doctest mode on and off.
1531 Toggle doctest mode on and off.
1799
1532
1800 This mode allows you to toggle the prompt behavior between normal
1533 This mode allows you to toggle the prompt behavior between normal
1801 IPython prompts and ones that are as similar to the default IPython
1534 IPython prompts and ones that are as similar to the default IPython
1802 interpreter as possible.
1535 interpreter as possible.
1803
1536
1804 It also supports the pasting of code snippets that have leading '>>>'
1537 It also supports the pasting of code snippets that have leading '>>>'
1805 and '...' prompts in them. This means that you can paste doctests from
1538 and '...' prompts in them. This means that you can paste doctests from
1806 files or docstrings (even if they have leading whitespace), and the
1539 files or docstrings (even if they have leading whitespace), and the
1807 code will execute correctly. You can then use '%history -tn' to see
1540 code will execute correctly. You can then use '%history -tn' to see
1808 the translated history without line numbers; this will give you the
1541 the translated history without line numbers; this will give you the
1809 input after removal of all the leading prompts and whitespace, which
1542 input after removal of all the leading prompts and whitespace, which
1810 can be pasted back into an editor.
1543 can be pasted back into an editor.
1811
1544
1812 With these features, you can switch into this mode easily whenever you
1545 With these features, you can switch into this mode easily whenever you
1813 need to do testing and changes to doctests, without having to leave
1546 need to do testing and changes to doctests, without having to leave
1814 your existing IPython session.
1547 your existing IPython session.
1815
1548
1816 **%ed**::
1549 **%ed**::
1817
1550
1818 Alias to %edit.
1551 Alias to %edit.
1819
1552
1820 **%edit**::
1553 **%edit**::
1821
1554
1822 Bring up an editor and execute the resulting code.
1555 Bring up an editor and execute the resulting code.
1823
1556
1824 Usage:
1557 Usage:
1825 %edit [options] [args]
1558 %edit [options] [args]
1826
1559
1827 %edit runs IPython's editor hook. The default version of this hook is
1560 %edit runs IPython's editor hook. The default version of this hook is
1828 set to call the __IPYTHON__.rc.editor command. This is read from your
1561 set to call the __IPYTHON__.rc.editor command. This is read from your
1829 environment variable $EDITOR. If this isn't found, it will default to
1562 environment variable $EDITOR. If this isn't found, it will default to
1830 vi under Linux/Unix and to notepad under Windows. See the end of this
1563 vi under Linux/Unix and to notepad under Windows. See the end of this
1831 docstring for how to change the editor hook.
1564 docstring for how to change the editor hook.
1832
1565
1833 You can also set the value of this editor via the command line option
1566 You can also set the value of this editor via the command line option
1834 '-editor' or in your ipythonrc file. This is useful if you wish to use
1567 '-editor' or in your ipythonrc file. This is useful if you wish to use
1835 specifically for IPython an editor different from your typical default
1568 specifically for IPython an editor different from your typical default
1836 (and for Windows users who typically don't set environment variables).
1569 (and for Windows users who typically don't set environment variables).
1837
1570
1838 This command allows you to conveniently edit multi-line code right in
1571 This command allows you to conveniently edit multi-line code right in
1839 your IPython session.
1572 your IPython session.
1840
1573
1841 If called without arguments, %edit opens up an empty editor with a
1574 If called without arguments, %edit opens up an empty editor with a
1842 temporary file and will execute the contents of this file when you
1575 temporary file and will execute the contents of this file when you
1843 close it (don't forget to save it!).
1576 close it (don't forget to save it!).
1844
1577
1845
1578
1846 Options:
1579 Options:
1847
1580
1848 -n <number>: open the editor at a specified line number. By default,
1581 -n <number>: open the editor at a specified line number. By default,
1849 the IPython editor hook uses the unix syntax 'editor +N filename', but
1582 the IPython editor hook uses the unix syntax 'editor +N filename', but
1850 you can configure this by providing your own modified hook if your
1583 you can configure this by providing your own modified hook if your
1851 favorite editor supports line-number specifications with a different
1584 favorite editor supports line-number specifications with a different
1852 syntax.
1585 syntax.
1853
1586
1854 -p: this will call the editor with the same data as the previous time
1587 -p: this will call the editor with the same data as the previous time
1855 it was used, regardless of how long ago (in your current session) it
1588 it was used, regardless of how long ago (in your current session) it
1856 was.
1589 was.
1857
1590
1858 -r: use 'raw' input. This option only applies to input taken from the
1591 -r: use 'raw' input. This option only applies to input taken from the
1859 user's history. By default, the 'processed' history is used, so that
1592 user's history. By default, the 'processed' history is used, so that
1860 magics are loaded in their transformed version to valid Python. If
1593 magics are loaded in their transformed version to valid Python. If
1861 this option is given, the raw input as typed as the command line is
1594 this option is given, the raw input as typed as the command line is
1862 used instead. When you exit the editor, it will be executed by
1595 used instead. When you exit the editor, it will be executed by
1863 IPython's own processor.
1596 IPython's own processor.
1864
1597
1865 -x: do not execute the edited code immediately upon exit. This is
1598 -x: do not execute the edited code immediately upon exit. This is
1866 mainly useful if you are editing programs which need to be called with
1599 mainly useful if you are editing programs which need to be called with
1867 command line arguments, which you can then do using %run.
1600 command line arguments, which you can then do using %run.
1868
1601
1869
1602
1870 Arguments:
1603 Arguments:
1871
1604
1872 If arguments are given, the following possibilites exist:
1605 If arguments are given, the following possibilites exist:
1873
1606
1874 - The arguments are numbers or pairs of colon-separated numbers (like
1607 - The arguments are numbers or pairs of colon-separated numbers (like
1875 1 4:8 9). These are interpreted as lines of previous input to be
1608 1 4:8 9). These are interpreted as lines of previous input to be
1876 loaded into the editor. The syntax is the same of the %macro command.
1609 loaded into the editor. The syntax is the same of the %macro command.
1877
1610
1878 - If the argument doesn't start with a number, it is evaluated as a
1611 - If the argument doesn't start with a number, it is evaluated as a
1879 variable and its contents loaded into the editor. You can thus edit
1612 variable and its contents loaded into the editor. You can thus edit
1880 any string which contains python code (including the result of
1613 any string which contains python code (including the result of
1881 previous edits).
1614 previous edits).
1882
1615
1883 - If the argument is the name of an object (other than a string),
1616 - If the argument is the name of an object (other than a string),
1884 IPython will try to locate the file where it was defined and open the
1617 IPython will try to locate the file where it was defined and open the
1885 editor at the point where it is defined. You can use `%edit function`
1618 editor at the point where it is defined. You can use `%edit function`
1886 to load an editor exactly at the point where 'function' is defined,
1619 to load an editor exactly at the point where 'function' is defined,
1887 edit it and have the file be executed automatically.
1620 edit it and have the file be executed automatically.
1888
1621
1889 If the object is a macro (see %macro for details), this opens up your
1622 If the object is a macro (see %macro for details), this opens up your
1890 specified editor with a temporary file containing the macro's data.
1623 specified editor with a temporary file containing the macro's data.
1891 Upon exit, the macro is reloaded with the contents of the file.
1624 Upon exit, the macro is reloaded with the contents of the file.
1892
1625
1893 Note: opening at an exact line is only supported under Unix, and some
1626 Note: opening at an exact line is only supported under Unix, and some
1894 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1627 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1895 '+NUMBER' parameter necessary for this feature. Good editors like
1628 '+NUMBER' parameter necessary for this feature. Good editors like
1896 (X)Emacs, vi, jed, pico and joe all do.
1629 (X)Emacs, vi, jed, pico and joe all do.
1897
1630
1898 - If the argument is not found as a variable, IPython will look for a
1631 - If the argument is not found as a variable, IPython will look for a
1899 file with that name (adding .py if necessary) and load it into the
1632 file with that name (adding .py if necessary) and load it into the
1900 editor. It will execute its contents with execfile() when you exit,
1633 editor. It will execute its contents with execfile() when you exit,
1901 loading any code in the file into your interactive namespace.
1634 loading any code in the file into your interactive namespace.
1902
1635
1903 After executing your code, %edit will return as output the code you
1636 After executing your code, %edit will return as output the code you
1904 typed in the editor (except when it was an existing file). This way
1637 typed in the editor (except when it was an existing file). This way
1905 you can reload the code in further invocations of %edit as a variable,
1638 you can reload the code in further invocations of %edit as a variable,
1906 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1639 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1907 the output.
1640 the output.
1908
1641
1909 Note that %edit is also available through the alias %ed.
1642 Note that %edit is also available through the alias %ed.
1910
1643
1911 This is an example of creating a simple function inside the editor and
1644 This is an example of creating a simple function inside the editor and
1912 then modifying it. First, start up the editor:
1645 then modifying it. First, start up the editor:
1913
1646
1914 In [1]: ed\
1647 In [1]: ed\
1915 Editing... done. Executing edited code...\
1648 Editing... done. Executing edited code...\
1916 Out[1]: 'def foo():\n print "foo() was defined in an editing session"\n'
1649 Out[1]: 'def foo():\n print "foo() was defined in an editing session"\n'
1917
1650
1918 We can then call the function foo():
1651 We can then call the function foo():
1919
1652
1920 In [2]: foo()\
1653 In [2]: foo()\
1921 foo() was defined in an editing session
1654 foo() was defined in an editing session
1922
1655
1923 Now we edit foo. IPython automatically loads the editor with the
1656 Now we edit foo. IPython automatically loads the editor with the
1924 (temporary) file where foo() was previously defined:
1657 (temporary) file where foo() was previously defined:
1925
1658
1926 In [3]: ed foo\
1659 In [3]: ed foo\
1927 Editing... done. Executing edited code...
1660 Editing... done. Executing edited code...
1928
1661
1929 And if we call foo() again we get the modified version:
1662 And if we call foo() again we get the modified version:
1930
1663
1931 In [4]: foo()\
1664 In [4]: foo()\
1932 foo() has now been changed!
1665 foo() has now been changed!
1933
1666
1934 Here is an example of how to edit a code snippet successive
1667 Here is an example of how to edit a code snippet successive
1935 times. First we call the editor:
1668 times. First we call the editor:
1936
1669
1937 In [8]: ed\
1670 In [8]: ed\
1938 Editing... done. Executing edited code...\
1671 Editing... done. Executing edited code...\
1939 hello\
1672 hello\
1940 Out[8]: "print 'hello'\n"
1673 Out[8]: "print 'hello'\n"
1941
1674
1942 Now we call it again with the previous output (stored in _):
1675 Now we call it again with the previous output (stored in _):
1943
1676
1944 In [9]: ed _\
1677 In [9]: ed _\
1945 Editing... done. Executing edited code...\
1678 Editing... done. Executing edited code...\
1946 hello world\
1679 hello world\
1947 Out[9]: "print 'hello world'\n"
1680 Out[9]: "print 'hello world'\n"
1948
1681
1949 Now we call it with the output #8 (stored in _8, also as Out[8]):
1682 Now we call it with the output #8 (stored in _8, also as Out[8]):
1950
1683
1951 In [10]: ed _8\
1684 In [10]: ed _8\
1952 Editing... done. Executing edited code...\
1685 Editing... done. Executing edited code...\
1953 hello again\
1686 hello again\
1954 Out[10]: "print 'hello again'\n"
1687 Out[10]: "print 'hello again'\n"
1955
1688
1956
1689
1957 Changing the default editor hook:
1690 Changing the default editor hook:
1958
1691
1959 If you wish to write your own editor hook, you can put it in a
1692 If you wish to write your own editor hook, you can put it in a
1960 configuration file which you load at startup time. The default hook
1693 configuration file which you load at startup time. The default hook
1961 is defined in the IPython.hooks module, and you can use that as a
1694 is defined in the IPython.hooks module, and you can use that as a
1962 starting example for further modifications. That file also has
1695 starting example for further modifications. That file also has
1963 general instructions on how to set a new hook for use once you've
1696 general instructions on how to set a new hook for use once you've
1964 defined it.
1697 defined it.
1965
1698
1966 **%env**::
1699 **%env**::
1967
1700
1968 List environment variables.
1701 List environment variables.
1969
1702
1970 **%exit**::
1703 **%exit**::
1971
1704
1972 Exit IPython, confirming if configured to do so.
1705 Exit IPython, confirming if configured to do so.
1973
1706
1974 You can configure whether IPython asks for confirmation upon exit by
1707 You can configure whether IPython asks for confirmation upon exit by
1975 setting the confirm_exit flag in the ipythonrc file.
1708 setting the confirm_exit flag in the ipythonrc file.
1976
1709
1977 **%hist**::
1710 **%hist**::
1978
1711
1979 Alternate name for %history.
1712 Alternate name for %history.
1980
1713
1981 **%history**::
1714 **%history**::
1982
1715
1983 Print input history (_i<n> variables), with most recent last.
1716 Print input history (_i<n> variables), with most recent last.
1984
1717
1985 %history -> print at most 40 inputs (some may be multi-line)\
1718 %history -> print at most 40 inputs (some may be multi-line)\
1986 %history n -> print at most n inputs\
1719 %history n -> print at most n inputs\
1987 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\
1720 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\
1988
1721
1989 Each input's number <n> is shown, and is accessible as the
1722 Each input's number <n> is shown, and is accessible as the
1990 automatically generated variable _i<n>. Multi-line statements are
1723 automatically generated variable _i<n>. Multi-line statements are
1991 printed starting at a new line for easy copy/paste.
1724 printed starting at a new line for easy copy/paste.
1992
1725
1993
1726
1994 Options:
1727 Options:
1995
1728
1996 -n: do NOT print line numbers. This is useful if you want to get a
1729 -n: do NOT print line numbers. This is useful if you want to get a
1997 printout of many lines which can be directly pasted into a text
1730 printout of many lines which can be directly pasted into a text
1998 editor.
1731 editor.
1999
1732
2000 This feature is only available if numbered prompts are in use.
1733 This feature is only available if numbered prompts are in use.
2001
1734
2002 -t: (default) print the 'translated' history, as IPython understands it.
1735 -t: (default) print the 'translated' history, as IPython understands it.
2003 IPython filters your input and converts it all into valid Python source
1736 IPython filters your input and converts it all into valid Python source
2004 before executing it (things like magics or aliases are turned into
1737 before executing it (things like magics or aliases are turned into
2005 function calls, for example). With this option, you'll see the native
1738 function calls, for example). With this option, you'll see the native
2006 history instead of the user-entered version: '%cd /' will be seen as
1739 history instead of the user-entered version: '%cd /' will be seen as
2007 '_ip.magic("%cd /")' instead of '%cd /'.
1740 '_ip.magic("%cd /")' instead of '%cd /'.
2008
1741
2009 -r: print the 'raw' history, i.e. the actual commands you typed.
1742 -r: print the 'raw' history, i.e. the actual commands you typed.
2010
1743
2011 -g: treat the arg as a pattern to grep for in (full) history.
1744 -g: treat the arg as a pattern to grep for in (full) history.
2012 This includes the "shadow history" (almost all commands ever written).
1745 This includes the "shadow history" (almost all commands ever written).
2013 Use '%hist -g' to show full shadow history (may be very long).
1746 Use '%hist -g' to show full shadow history (may be very long).
2014 In shadow history, every index nuwber starts with 0.
1747 In shadow history, every index nuwber starts with 0.
2015
1748
2016 -f FILENAME: instead of printing the output to the screen, redirect it to
1749 -f FILENAME: instead of printing the output to the screen, redirect it to
2017 the given file. The file is always overwritten, though IPython asks for
1750 the given file. The file is always overwritten, though IPython asks for
2018 confirmation first if it already exists.
1751 confirmation first if it already exists.
2019
1752
2020 **%logoff**::
1753 **%logoff**::
2021
1754
2022 Temporarily stop logging.
1755 Temporarily stop logging.
2023
1756
2024 You must have previously started logging.
1757 You must have previously started logging.
2025
1758
2026 **%logon**::
1759 **%logon**::
2027
1760
2028 Restart logging.
1761 Restart logging.
2029
1762
2030 This function is for restarting logging which you've temporarily
1763 This function is for restarting logging which you've temporarily
2031 stopped with %logoff. For starting logging for the first time, you
1764 stopped with %logoff. For starting logging for the first time, you
2032 must use the %logstart function, which allows you to specify an
1765 must use the %logstart function, which allows you to specify an
2033 optional log filename.
1766 optional log filename.
2034
1767
2035 **%logstart**::
1768 **%logstart**::
2036
1769
2037 Start logging anywhere in a session.
1770 Start logging anywhere in a session.
2038
1771
2039 %logstart [-o|-r|-t] [log_name [log_mode]]
1772 %logstart [-o|-r|-t] [log_name [log_mode]]
2040
1773
2041 If no name is given, it defaults to a file named 'ipython_log.py' in your
1774 If no name is given, it defaults to a file named 'ipython_log.py' in your
2042 current directory, in 'rotate' mode (see below).
1775 current directory, in 'rotate' mode (see below).
2043
1776
2044 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
1777 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
2045 history up to that point and then continues logging.
1778 history up to that point and then continues logging.
2046
1779
2047 %logstart takes a second optional parameter: logging mode. This can be one
1780 %logstart takes a second optional parameter: logging mode. This can be one
2048 of (note that the modes are given unquoted):\
1781 of (note that the modes are given unquoted):\
2049 append: well, that says it.\
1782 append: well, that says it.\
2050 backup: rename (if exists) to name~ and start name.\
1783 backup: rename (if exists) to name~ and start name.\
2051 global: single logfile in your home dir, appended to.\
1784 global: single logfile in your home dir, appended to.\
2052 over : overwrite existing log.\
1785 over : overwrite existing log.\
2053 rotate: create rotating logs name.1~, name.2~, etc.
1786 rotate: create rotating logs name.1~, name.2~, etc.
2054
1787
2055 Options:
1788 Options:
2056
1789
2057 -o: log also IPython's output. In this mode, all commands which
1790 -o: log also IPython's output. In this mode, all commands which
2058 generate an Out[NN] prompt are recorded to the logfile, right after
1791 generate an Out[NN] prompt are recorded to the logfile, right after
2059 their corresponding input line. The output lines are always
1792 their corresponding input line. The output lines are always
2060 prepended with a '#[Out]# ' marker, so that the log remains valid
1793 prepended with a '#[Out]# ' marker, so that the log remains valid
2061 Python code.
1794 Python code.
2062
1795
2063 Since this marker is always the same, filtering only the output from
1796 Since this marker is always the same, filtering only the output from
2064 a log is very easy, using for example a simple awk call:
1797 a log is very easy, using for example a simple awk call:
2065
1798
2066 awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py
1799 awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py
2067
1800
2068 -r: log 'raw' input. Normally, IPython's logs contain the processed
1801 -r: log 'raw' input. Normally, IPython's logs contain the processed
2069 input, so that user lines are logged in their final form, converted
1802 input, so that user lines are logged in their final form, converted
2070 into valid Python. For example, %Exit is logged as
1803 into valid Python. For example, %Exit is logged as
2071 '_ip.magic("Exit"). If the -r flag is given, all input is logged
1804 '_ip.magic("Exit"). If the -r flag is given, all input is logged
2072 exactly as typed, with no transformations applied.
1805 exactly as typed, with no transformations applied.
2073
1806
2074 -t: put timestamps before each input line logged (these are put in
1807 -t: put timestamps before each input line logged (these are put in
2075 comments).
1808 comments).
2076
1809
2077 **%logstate**::
1810 **%logstate**::
2078
1811
2079 Print the status of the logging system.
1812 Print the status of the logging system.
2080
1813
2081 **%logstop**::
1814 **%logstop**::
2082
1815
2083 Fully stop logging and close log file.
1816 Fully stop logging and close log file.
2084
1817
2085 In order to start logging again, a new %logstart call needs to be made,
1818 In order to start logging again, a new %logstart call needs to be made,
2086 possibly (though not necessarily) with a new filename, mode and other
1819 possibly (though not necessarily) with a new filename, mode and other
2087 options.
1820 options.
2088
1821
2089 **%lsmagic**::
1822 **%lsmagic**::
2090
1823
2091 List currently available magic functions.
1824 List currently available magic functions.
2092
1825
2093 **%macro**::
1826 **%macro**::
2094
1827
2095 Define a set of input lines as a macro for future re-execution.
1828 Define a set of input lines as a macro for future re-execution.
2096
1829
2097 Usage:\
1830 Usage:\
2098 %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...
1831 %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...
2099
1832
2100 Options:
1833 Options:
2101
1834
2102 -r: use 'raw' input. By default, the 'processed' history is used,
1835 -r: use 'raw' input. By default, the 'processed' history is used,
2103 so that magics are loaded in their transformed version to valid
1836 so that magics are loaded in their transformed version to valid
2104 Python. If this option is given, the raw input as typed as the
1837 Python. If this option is given, the raw input as typed as the
2105 command line is used instead.
1838 command line is used instead.
2106
1839
2107 This will define a global variable called `name` which is a string
1840 This will define a global variable called `name` which is a string
2108 made of joining the slices and lines you specify (n1,n2,... numbers
1841 made of joining the slices and lines you specify (n1,n2,... numbers
2109 above) from your input history into a single string. This variable
1842 above) from your input history into a single string. This variable
2110 acts like an automatic function which re-executes those lines as if
1843 acts like an automatic function which re-executes those lines as if
2111 you had typed them. You just type 'name' at the prompt and the code
1844 you had typed them. You just type 'name' at the prompt and the code
2112 executes.
1845 executes.
2113
1846
2114 The notation for indicating number ranges is: n1-n2 means 'use line
1847 The notation for indicating number ranges is: n1-n2 means 'use line
2115 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
1848 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
2116 using the lines numbered 5,6 and 7.
1849 using the lines numbered 5,6 and 7.
2117
1850
2118 Note: as a 'hidden' feature, you can also use traditional python slice
1851 Note: as a 'hidden' feature, you can also use traditional python slice
2119 notation, where N:M means numbers N through M-1.
1852 notation, where N:M means numbers N through M-1.
2120
1853
2121 For example, if your history contains (%hist prints it):
1854 For example, if your history contains (%hist prints it):
2122
1855
2123 44: x=1\
1856 44: x=1\
2124 45: y=3\
1857 45: y=3\
2125 46: z=x+y\
1858 46: z=x+y\
2126 47: print x\
1859 47: print x\
2127 48: a=5\
1860 48: a=5\
2128 49: print 'x',x,'y',y\
1861 49: print 'x',x,'y',y\
2129
1862
2130 you can create a macro with lines 44 through 47 (included) and line 49
1863 you can create a macro with lines 44 through 47 (included) and line 49
2131 called my_macro with:
1864 called my_macro with:
2132
1865
2133 In [51]: %macro my_macro 44-47 49
1866 In [51]: %macro my_macro 44-47 49
2134
1867
2135 Now, typing `my_macro` (without quotes) will re-execute all this code
1868 Now, typing `my_macro` (without quotes) will re-execute all this code
2136 in one pass.
1869 in one pass.
2137
1870
2138 You don't need to give the line-numbers in order, and any given line
1871 You don't need to give the line-numbers in order, and any given line
2139 number can appear multiple times. You can assemble macros with any
1872 number can appear multiple times. You can assemble macros with any
2140 lines from your input history in any order.
1873 lines from your input history in any order.
2141
1874
2142 The macro is a simple object which holds its value in an attribute,
1875 The macro is a simple object which holds its value in an attribute,
2143 but IPython's display system checks for macros and executes them as
1876 but IPython's display system checks for macros and executes them as
2144 code instead of printing them when you type their name.
1877 code instead of printing them when you type their name.
2145
1878
2146 You can view a macro's contents by explicitly printing it with:
1879 You can view a macro's contents by explicitly printing it with:
2147
1880
2148 'print macro_name'.
1881 'print macro_name'.
2149
1882
2150 For one-off cases which DON'T contain magic function calls in them you
1883 For one-off cases which DON'T contain magic function calls in them you
2151 can obtain similar results by explicitly executing slices from your
1884 can obtain similar results by explicitly executing slices from your
2152 input history with:
1885 input history with:
2153
1886
2154 In [60]: exec In[44:48]+In[49]
1887 In [60]: exec In[44:48]+In[49]
2155
1888
2156 **%magic**::
1889 **%magic**::
2157
1890
2158 Print information about the magic function system.
1891 Print information about the magic function system.
2159
1892
2160 **%mglob**::
1893 **%mglob**::
2161
1894
2162 This program allows specifying filenames with "mglob" mechanism.
1895 This program allows specifying filenames with "mglob" mechanism.
2163 Supported syntax in globs (wilcard matching patterns)::
1896 Supported syntax in globs (wilcard matching patterns)::
2164
1897
2165 *.cpp ?ellowo*
1898 *.cpp ?ellowo*
2166 - obvious. Differs from normal glob in that dirs are not included.
1899 - obvious. Differs from normal glob in that dirs are not included.
2167 Unix users might want to write this as: "*.cpp" "?ellowo*"
1900 Unix users might want to write this as: "*.cpp" "?ellowo*"
2168 rec:/usr/share=*.txt,*.doc
1901 rec:/usr/share=*.txt,*.doc
2169 - get all *.txt and *.doc under /usr/share,
1902 - get all *.txt and *.doc under /usr/share,
2170 recursively
1903 recursively
2171 rec:/usr/share
1904 rec:/usr/share
2172 - All files under /usr/share, recursively
1905 - All files under /usr/share, recursively
2173 rec:*.py
1906 rec:*.py
2174 - All .py files under current working dir, recursively
1907 - All .py files under current working dir, recursively
2175 foo
1908 foo
2176 - File or dir foo
1909 - File or dir foo
2177 !*.bak readme*
1910 !*.bak readme*
2178 - readme*, exclude files ending with .bak
1911 - readme*, exclude files ending with .bak
2179 !.svn/ !.hg/ !*_Data/ rec:.
1912 !.svn/ !.hg/ !*_Data/ rec:.
2180 - Skip .svn, .hg, foo_Data dirs (and their subdirs) in recurse.
1913 - Skip .svn, .hg, foo_Data dirs (and their subdirs) in recurse.
2181 Trailing / is the key, \ does not work!
1914 Trailing / is the key, \ does not work!
2182 dir:foo
1915 dir:foo
2183 - the directory foo if it exists (not files in foo)
1916 - the directory foo if it exists (not files in foo)
2184 dir:*
1917 dir:*
2185 - all directories in current folder
1918 - all directories in current folder
2186 foo.py bar.* !h* rec:*.py
1919 foo.py bar.* !h* rec:*.py
2187 - Obvious. !h* exclusion only applies for rec:*.py.
1920 - Obvious. !h* exclusion only applies for rec:*.py.
2188 foo.py is *not* included twice.
1921 foo.py is *not* included twice.
2189 @filelist.txt
1922 @filelist.txt
2190 - All files listed in 'filelist.txt' file, on separate lines.
1923 - All files listed in 'filelist.txt' file, on separate lines.
2191
1924
2192 **%page**::
1925 **%page**::
2193
1926
2194 Pretty print the object and display it through a pager.
1927 Pretty print the object and display it through a pager.
2195
1928
2196 %page [options] OBJECT
1929 %page [options] OBJECT
2197
1930
2198 If no object is given, use _ (last output).
1931 If no object is given, use _ (last output).
2199
1932
2200 Options:
1933 Options:
2201
1934
2202 -r: page str(object), don't pretty-print it.
1935 -r: page str(object), don't pretty-print it.
2203
1936
2204 **%pdb**::
1937 **%pdb**::
2205
1938
2206 Control the automatic calling of the pdb interactive debugger.
1939 Control the automatic calling of the pdb interactive debugger.
2207
1940
2208 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1941 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
2209 argument it works as a toggle.
1942 argument it works as a toggle.
2210
1943
2211 When an exception is triggered, IPython can optionally call the
1944 When an exception is triggered, IPython can optionally call the
2212 interactive pdb debugger after the traceback printout. %pdb toggles
1945 interactive pdb debugger after the traceback printout. %pdb toggles
2213 this feature on and off.
1946 this feature on and off.
2214
1947
2215 The initial state of this feature is set in your ipythonrc
1948 The initial state of this feature is set in your ipythonrc
2216 configuration file (the variable is called 'pdb').
1949 configuration file (the variable is called 'pdb').
2217
1950
2218 If you want to just activate the debugger AFTER an exception has fired,
1951 If you want to just activate the debugger AFTER an exception has fired,
2219 without having to type '%pdb on' and rerunning your code, you can use
1952 without having to type '%pdb on' and rerunning your code, you can use
2220 the %debug magic.
1953 the %debug magic.
2221
1954
2222 **%pdef**::
1955 **%pdef**::
2223
1956
2224 Print the definition header for any callable object.
1957 Print the definition header for any callable object.
2225
1958
2226 If the object is a class, print the constructor information.
1959 If the object is a class, print the constructor information.
2227
1960
2228 **%pdoc**::
1961 **%pdoc**::
2229
1962
2230 Print the docstring for an object.
1963 Print the docstring for an object.
2231
1964
2232 If the given object is a class, it will print both the class and the
1965 If the given object is a class, it will print both the class and the
2233 constructor docstrings.
1966 constructor docstrings.
2234
1967
2235 **%pfile**::
1968 **%pfile**::
2236
1969
2237 Print (or run through pager) the file where an object is defined.
1970 Print (or run through pager) the file where an object is defined.
2238
1971
2239 The file opens at the line where the object definition begins. IPython
1972 The file opens at the line where the object definition begins. IPython
2240 will honor the environment variable PAGER if set, and otherwise will
1973 will honor the environment variable PAGER if set, and otherwise will
2241 do its best to print the file in a convenient form.
1974 do its best to print the file in a convenient form.
2242
1975
2243 If the given argument is not an object currently defined, IPython will
1976 If the given argument is not an object currently defined, IPython will
2244 try to interpret it as a filename (automatically adding a .py extension
1977 try to interpret it as a filename (automatically adding a .py extension
2245 if needed). You can thus use %pfile as a syntax highlighting code
1978 if needed). You can thus use %pfile as a syntax highlighting code
2246 viewer.
1979 viewer.
2247
1980
2248 **%pinfo**::
1981 **%pinfo**::
2249
1982
2250 Provide detailed information about an object.
1983 Provide detailed information about an object.
2251
1984
2252 '%pinfo object' is just a synonym for object? or ?object.
1985 '%pinfo object' is just a synonym for object? or ?object.
2253
1986
2254 **%popd**::
1987 **%popd**::
2255
1988
2256 Change to directory popped off the top of the stack.
1989 Change to directory popped off the top of the stack.
2257
1990
2258 **%profile**::
1991 **%profile**::
2259
1992
2260 Print your currently active IPyhton profile.
1993 Print your currently active IPyhton profile.
2261
1994
2262 **%prun**::
1995 **%prun**::
2263
1996
2264 Run a statement through the python code profiler.
1997 Run a statement through the python code profiler.
2265
1998
2266 Usage:\
1999 Usage:\
2267 %prun [options] statement
2000 %prun [options] statement
2268
2001
2269 The given statement (which doesn't require quote marks) is run via the
2002 The given statement (which doesn't require quote marks) is run via the
2270 python profiler in a manner similar to the profile.run() function.
2003 python profiler in a manner similar to the profile.run() function.
2271 Namespaces are internally managed to work correctly; profile.run
2004 Namespaces are internally managed to work correctly; profile.run
2272 cannot be used in IPython because it makes certain assumptions about
2005 cannot be used in IPython because it makes certain assumptions about
2273 namespaces which do not hold under IPython.
2006 namespaces which do not hold under IPython.
2274
2007
2275 Options:
2008 Options:
2276
2009
2277 -l <limit>: you can place restrictions on what or how much of the
2010 -l <limit>: you can place restrictions on what or how much of the
2278 profile gets printed. The limit value can be:
2011 profile gets printed. The limit value can be:
2279
2012
2280 * A string: only information for function names containing this string
2013 * A string: only information for function names containing this string
2281 is printed.
2014 is printed.
2282
2015
2283 * An integer: only these many lines are printed.
2016 * An integer: only these many lines are printed.
2284
2017
2285 * A float (between 0 and 1): this fraction of the report is printed
2018 * A float (between 0 and 1): this fraction of the report is printed
2286 (for example, use a limit of 0.4 to see the topmost 40% only).
2019 (for example, use a limit of 0.4 to see the topmost 40% only).
2287
2020
2288 You can combine several limits with repeated use of the option. For
2021 You can combine several limits with repeated use of the option. For
2289 example, '-l __init__ -l 5' will print only the topmost 5 lines of
2022 example, '-l __init__ -l 5' will print only the topmost 5 lines of
2290 information about class constructors.
2023 information about class constructors.
2291
2024
2292 -r: return the pstats.Stats object generated by the profiling. This
2025 -r: return the pstats.Stats object generated by the profiling. This
2293 object has all the information about the profile in it, and you can
2026 object has all the information about the profile in it, and you can
2294 later use it for further analysis or in other functions.
2027 later use it for further analysis or in other functions.
2295
2028
2296 -s <key>: sort profile by given key. You can provide more than one key
2029 -s <key>: sort profile by given key. You can provide more than one key
2297 by using the option several times: '-s key1 -s key2 -s key3...'. The
2030 by using the option several times: '-s key1 -s key2 -s key3...'. The
2298 default sorting key is 'time'.
2031 default sorting key is 'time'.
2299
2032
2300 The following is copied verbatim from the profile documentation
2033 The following is copied verbatim from the profile documentation
2301 referenced below:
2034 referenced below:
2302
2035
2303 When more than one key is provided, additional keys are used as
2036 When more than one key is provided, additional keys are used as
2304 secondary criteria when the there is equality in all keys selected
2037 secondary criteria when the there is equality in all keys selected
2305 before them.
2038 before them.
2306
2039
2307 Abbreviations can be used for any key names, as long as the
2040 Abbreviations can be used for any key names, as long as the
2308 abbreviation is unambiguous. The following are the keys currently
2041 abbreviation is unambiguous. The following are the keys currently
2309 defined:
2042 defined:
2310
2043
2311 Valid Arg Meaning\
2044 Valid Arg Meaning\
2312 "calls" call count\
2045 "calls" call count\
2313 "cumulative" cumulative time\
2046 "cumulative" cumulative time\
2314 "file" file name\
2047 "file" file name\
2315 "module" file name\
2048 "module" file name\
2316 "pcalls" primitive call count\
2049 "pcalls" primitive call count\
2317 "line" line number\
2050 "line" line number\
2318 "name" function name\
2051 "name" function name\
2319 "nfl" name/file/line\
2052 "nfl" name/file/line\
2320 "stdname" standard name\
2053 "stdname" standard name\
2321 "time" internal time
2054 "time" internal time
2322
2055
2323 Note that all sorts on statistics are in descending order (placing
2056 Note that all sorts on statistics are in descending order (placing
2324 most time consuming items first), where as name, file, and line number
2057 most time consuming items first), where as name, file, and line number
2325 searches are in ascending order (i.e., alphabetical). The subtle
2058 searches are in ascending order (i.e., alphabetical). The subtle
2326 distinction between "nfl" and "stdname" is that the standard name is a
2059 distinction between "nfl" and "stdname" is that the standard name is a
2327 sort of the name as printed, which means that the embedded line
2060 sort of the name as printed, which means that the embedded line
2328 numbers get compared in an odd way. For example, lines 3, 20, and 40
2061 numbers get compared in an odd way. For example, lines 3, 20, and 40
2329 would (if the file names were the same) appear in the string order
2062 would (if the file names were the same) appear in the string order
2330 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
2063 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
2331 line numbers. In fact, sort_stats("nfl") is the same as
2064 line numbers. In fact, sort_stats("nfl") is the same as
2332 sort_stats("name", "file", "line").
2065 sort_stats("name", "file", "line").
2333
2066
2334 -T <filename>: save profile results as shown on screen to a text
2067 -T <filename>: save profile results as shown on screen to a text
2335 file. The profile is still shown on screen.
2068 file. The profile is still shown on screen.
2336
2069
2337 -D <filename>: save (via dump_stats) profile statistics to given
2070 -D <filename>: save (via dump_stats) profile statistics to given
2338 filename. This data is in a format understod by the pstats module, and
2071 filename. This data is in a format understod by the pstats module, and
2339 is generated by a call to the dump_stats() method of profile
2072 is generated by a call to the dump_stats() method of profile
2340 objects. The profile is still shown on screen.
2073 objects. The profile is still shown on screen.
2341
2074
2342 If you want to run complete programs under the profiler's control, use
2075 If you want to run complete programs under the profiler's control, use
2343 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
2076 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
2344 contains profiler specific options as described here.
2077 contains profiler specific options as described here.
2345
2078
2346 You can read the complete documentation for the profile module with:\
2079 You can read the complete documentation for the profile module with:\
2347 In [1]: import profile; profile.help()
2080 In [1]: import profile; profile.help()
2348
2081
2349 **%psearch**::
2082 **%psearch**::
2350
2083
2351 Search for object in namespaces by wildcard.
2084 Search for object in namespaces by wildcard.
2352
2085
2353 %psearch [options] PATTERN [OBJECT TYPE]
2086 %psearch [options] PATTERN [OBJECT TYPE]
2354
2087
2355 Note: ? can be used as a synonym for %psearch, at the beginning or at
2088 Note: ? can be used as a synonym for %psearch, at the beginning or at
2356 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
2089 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
2357 rest of the command line must be unchanged (options come first), so
2090 rest of the command line must be unchanged (options come first), so
2358 for example the following forms are equivalent
2091 for example the following forms are equivalent
2359
2092
2360 %psearch -i a* function
2093 %psearch -i a* function
2361 -i a* function?
2094 -i a* function?
2362 ?-i a* function
2095 ?-i a* function
2363
2096
2364 Arguments:
2097 Arguments:
2365
2098
2366 PATTERN
2099 PATTERN
2367
2100
2368 where PATTERN is a string containing * as a wildcard similar to its
2101 where PATTERN is a string containing * as a wildcard similar to its
2369 use in a shell. The pattern is matched in all namespaces on the
2102 use in a shell. The pattern is matched in all namespaces on the
2370 search path. By default objects starting with a single _ are not
2103 search path. By default objects starting with a single _ are not
2371 matched, many IPython generated objects have a single
2104 matched, many IPython generated objects have a single
2372 underscore. The default is case insensitive matching. Matching is
2105 underscore. The default is case insensitive matching. Matching is
2373 also done on the attributes of objects and not only on the objects
2106 also done on the attributes of objects and not only on the objects
2374 in a module.
2107 in a module.
2375
2108
2376 [OBJECT TYPE]
2109 [OBJECT TYPE]
2377
2110
2378 Is the name of a python type from the types module. The name is
2111 Is the name of a python type from the types module. The name is
2379 given in lowercase without the ending type, ex. StringType is
2112 given in lowercase without the ending type, ex. StringType is
2380 written string. By adding a type here only objects matching the
2113 written string. By adding a type here only objects matching the
2381 given type are matched. Using all here makes the pattern match all
2114 given type are matched. Using all here makes the pattern match all
2382 types (this is the default).
2115 types (this is the default).
2383
2116
2384 Options:
2117 Options:
2385
2118
2386 -a: makes the pattern match even objects whose names start with a
2119 -a: makes the pattern match even objects whose names start with a
2387 single underscore. These names are normally ommitted from the
2120 single underscore. These names are normally ommitted from the
2388 search.
2121 search.
2389
2122
2390 -i/-c: make the pattern case insensitive/sensitive. If neither of
2123 -i/-c: make the pattern case insensitive/sensitive. If neither of
2391 these options is given, the default is read from your ipythonrc
2124 these options is given, the default is read from your ipythonrc
2392 file. The option name which sets this value is
2125 file. The option name which sets this value is
2393 'wildcards_case_sensitive'. If this option is not specified in your
2126 'wildcards_case_sensitive'. If this option is not specified in your
2394 ipythonrc file, IPython's internal default is to do a case sensitive
2127 ipythonrc file, IPython's internal default is to do a case sensitive
2395 search.
2128 search.
2396
2129
2397 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
2130 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
2398 specifiy can be searched in any of the following namespaces:
2131 specifiy can be searched in any of the following namespaces:
2399 'builtin', 'user', 'user_global','internal', 'alias', where
2132 'builtin', 'user', 'user_global','internal', 'alias', where
2400 'builtin' and 'user' are the search defaults. Note that you should
2133 'builtin' and 'user' are the search defaults. Note that you should
2401 not use quotes when specifying namespaces.
2134 not use quotes when specifying namespaces.
2402
2135
2403 'Builtin' contains the python module builtin, 'user' contains all
2136 'Builtin' contains the python module builtin, 'user' contains all
2404 user data, 'alias' only contain the shell aliases and no python
2137 user data, 'alias' only contain the shell aliases and no python
2405 objects, 'internal' contains objects used by IPython. The
2138 objects, 'internal' contains objects used by IPython. The
2406 'user_global' namespace is only used by embedded IPython instances,
2139 'user_global' namespace is only used by embedded IPython instances,
2407 and it contains module-level globals. You can add namespaces to the
2140 and it contains module-level globals. You can add namespaces to the
2408 search with -s or exclude them with -e (these options can be given
2141 search with -s or exclude them with -e (these options can be given
2409 more than once).
2142 more than once).
2410
2143
2411 Examples:
2144 Examples:
2412
2145
2413 %psearch a* -> objects beginning with an a
2146 %psearch a* -> objects beginning with an a
2414 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
2147 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
2415 %psearch a* function -> all functions beginning with an a
2148 %psearch a* function -> all functions beginning with an a
2416 %psearch re.e* -> objects beginning with an e in module re
2149 %psearch re.e* -> objects beginning with an e in module re
2417 %psearch r*.e* -> objects that start with e in modules starting in r
2150 %psearch r*.e* -> objects that start with e in modules starting in r
2418 %psearch r*.* string -> all strings in modules beginning with r
2151 %psearch r*.* string -> all strings in modules beginning with r
2419
2152
2420 Case sensitve search:
2153 Case sensitve search:
2421
2154
2422 %psearch -c a* list all object beginning with lower case a
2155 %psearch -c a* list all object beginning with lower case a
2423
2156
2424 Show objects beginning with a single _:
2157 Show objects beginning with a single _:
2425
2158
2426 %psearch -a _* list objects beginning with a single underscore
2159 %psearch -a _* list objects beginning with a single underscore
2427
2160
2428 **%psource**::
2161 **%psource**::
2429
2162
2430 Print (or run through pager) the source code for an object.
2163 Print (or run through pager) the source code for an object.
2431
2164
2432 **%pushd**::
2165 **%pushd**::
2433
2166
2434 Place the current dir on stack and change directory.
2167 Place the current dir on stack and change directory.
2435
2168
2436 Usage:\
2169 Usage:\
2437 %pushd ['dirname']
2170 %pushd ['dirname']
2438
2171
2439 **%pwd**::
2172 **%pwd**::
2440
2173
2441 Return the current working directory path.
2174 Return the current working directory path.
2442
2175
2443 **%pycat**::
2176 **%pycat**::
2444
2177
2445 Show a syntax-highlighted file through a pager.
2178 Show a syntax-highlighted file through a pager.
2446
2179
2447 This magic is similar to the cat utility, but it will assume the file
2180 This magic is similar to the cat utility, but it will assume the file
2448 to be Python source and will show it with syntax highlighting.
2181 to be Python source and will show it with syntax highlighting.
2449
2182
2450 **%quickref**::
2183 **%quickref**::
2451
2184
2452 Show a quick reference sheet
2185 Show a quick reference sheet
2453
2186
2454 **%quit**::
2187 **%quit**::
2455
2188
2456 Exit IPython, confirming if configured to do so (like %exit)
2189 Exit IPython, confirming if configured to do so (like %exit)
2457
2190
2458 **%r**::
2191 **%r**::
2459
2192
2460 Repeat previous input.
2193 Repeat previous input.
2461
2194
2462 Note: Consider using the more powerfull %rep instead!
2195 Note: Consider using the more powerfull %rep instead!
2463
2196
2464 If given an argument, repeats the previous command which starts with
2197 If given an argument, repeats the previous command which starts with
2465 the same string, otherwise it just repeats the previous input.
2198 the same string, otherwise it just repeats the previous input.
2466
2199
2467 Shell escaped commands (with ! as first character) are not recognized
2200 Shell escaped commands (with ! as first character) are not recognized
2468 by this system, only pure python code and magic commands.
2201 by this system, only pure python code and magic commands.
2469
2202
2470 **%rehashdir**::
2203 **%rehashdir**::
2471
2204
2472 Add executables in all specified dirs to alias table
2205 Add executables in all specified dirs to alias table
2473
2206
2474 Usage:
2207 Usage:
2475
2208
2476 %rehashdir c:/bin;c:/tools
2209 %rehashdir c:/bin;c:/tools
2477 - Add all executables under c:/bin and c:/tools to alias table, in
2210 - Add all executables under c:/bin and c:/tools to alias table, in
2478 order to make them directly executable from any directory.
2211 order to make them directly executable from any directory.
2479
2212
2480 Without arguments, add all executables in current directory.
2213 Without arguments, add all executables in current directory.
2481
2214
2482 **%rehashx**::
2215 **%rehashx**::
2483
2216
2484 Update the alias table with all executable files in $PATH.
2217 Update the alias table with all executable files in $PATH.
2485
2218
2486 This version explicitly checks that every entry in $PATH is a file
2219 This version explicitly checks that every entry in $PATH is a file
2487 with execute access (os.X_OK), so it is much slower than %rehash.
2220 with execute access (os.X_OK), so it is much slower than %rehash.
2488
2221
2489 Under Windows, it checks executability as a match agains a
2222 Under Windows, it checks executability as a match agains a
2490 '|'-separated string of extensions, stored in the IPython config
2223 '|'-separated string of extensions, stored in the IPython config
2491 variable win_exec_ext. This defaults to 'exe|com|bat'.
2224 variable win_exec_ext. This defaults to 'exe|com|bat'.
2492
2225
2493 This function also resets the root module cache of module completer,
2226 This function also resets the root module cache of module completer,
2494 used on slow filesystems.
2227 used on slow filesystems.
2495
2228
2496 **%rep**::
2229 **%rep**::
2497
2230
2498 Repeat a command, or get command to input line for editing
2231 Repeat a command, or get command to input line for editing
2499
2232
2500 - %rep (no arguments):
2233 - %rep (no arguments):
2501
2234
2502 Place a string version of last computation result (stored in the special '_'
2235 Place a string version of last computation result (stored in the special '_'
2503 variable) to the next input prompt. Allows you to create elaborate command
2236 variable) to the next input prompt. Allows you to create elaborate command
2504 lines without using copy-paste::
2237 lines without using copy-paste::
2505
2238
2506 $ l = ["hei", "vaan"]
2239 $ l = ["hei", "vaan"]
2507 $ "".join(l)
2240 $ "".join(l)
2508 ==> heivaan
2241 ==> heivaan
2509 $ %rep
2242 $ %rep
2510 $ heivaan_ <== cursor blinking
2243 $ heivaan_ <== cursor blinking
2511
2244
2512 %rep 45
2245 %rep 45
2513
2246
2514 Place history line 45 to next input prompt. Use %hist to find out the
2247 Place history line 45 to next input prompt. Use %hist to find out the
2515 number.
2248 number.
2516
2249
2517 %rep 1-4 6-7 3
2250 %rep 1-4 6-7 3
2518
2251
2519 Repeat the specified lines immediately. Input slice syntax is the same as
2252 Repeat the specified lines immediately. Input slice syntax is the same as
2520 in %macro and %save.
2253 in %macro and %save.
2521
2254
2522 %rep foo
2255 %rep foo
2523
2256
2524 Place the most recent line that has the substring "foo" to next input.
2257 Place the most recent line that has the substring "foo" to next input.
2525 (e.g. 'svn ci -m foobar').
2258 (e.g. 'svn ci -m foobar').
2526
2259
2527 **%reset**::
2260 **%reset**::
2528
2261
2529 Resets the namespace by removing all names defined by the user.
2262 Resets the namespace by removing all names defined by the user.
2530
2263
2531 Input/Output history are left around in case you need them.
2264 Input/Output history are left around in case you need them.
2532
2265
2533 **%run**::
2266 **%run**::
2534
2267
2535 Run the named file inside IPython as a program.
2268 Run the named file inside IPython as a program.
2536
2269
2537 Usage:\
2270 Usage:\
2538 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
2271 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
2539
2272
2540 Parameters after the filename are passed as command-line arguments to
2273 Parameters after the filename are passed as command-line arguments to
2541 the program (put in sys.argv). Then, control returns to IPython's
2274 the program (put in sys.argv). Then, control returns to IPython's
2542 prompt.
2275 prompt.
2543
2276
2544 This is similar to running at a system prompt:\
2277 This is similar to running at a system prompt:\
2545 $ python file args\
2278 $ python file args\
2546 but with the advantage of giving you IPython's tracebacks, and of
2279 but with the advantage of giving you IPython's tracebacks, and of
2547 loading all variables into your interactive namespace for further use
2280 loading all variables into your interactive namespace for further use
2548 (unless -p is used, see below).
2281 (unless -p is used, see below).
2549
2282
2550 The file is executed in a namespace initially consisting only of
2283 The file is executed in a namespace initially consisting only of
2551 __name__=='__main__' and sys.argv constructed as indicated. It thus
2284 __name__=='__main__' and sys.argv constructed as indicated. It thus
2552 sees its environment as if it were being run as a stand-alone program
2285 sees its environment as if it were being run as a stand-alone program
2553 (except for sharing global objects such as previously imported
2286 (except for sharing global objects such as previously imported
2554 modules). But after execution, the IPython interactive namespace gets
2287 modules). But after execution, the IPython interactive namespace gets
2555 updated with all variables defined in the program (except for __name__
2288 updated with all variables defined in the program (except for __name__
2556 and sys.argv). This allows for very convenient loading of code for
2289 and sys.argv). This allows for very convenient loading of code for
2557 interactive work, while giving each program a 'clean sheet' to run in.
2290 interactive work, while giving each program a 'clean sheet' to run in.
2558
2291
2559 Options:
2292 Options:
2560
2293
2561 -n: __name__ is NOT set to '__main__', but to the running file's name
2294 -n: __name__ is NOT set to '__main__', but to the running file's name
2562 without extension (as python does under import). This allows running
2295 without extension (as python does under import). This allows running
2563 scripts and reloading the definitions in them without calling code
2296 scripts and reloading the definitions in them without calling code
2564 protected by an ' if __name__ == "__main__" ' clause.
2297 protected by an ' if __name__ == "__main__" ' clause.
2565
2298
2566 -i: run the file in IPython's namespace instead of an empty one. This
2299 -i: run the file in IPython's namespace instead of an empty one. This
2567 is useful if you are experimenting with code written in a text editor
2300 is useful if you are experimenting with code written in a text editor
2568 which depends on variables defined interactively.
2301 which depends on variables defined interactively.
2569
2302
2570 -e: ignore sys.exit() calls or SystemExit exceptions in the script
2303 -e: ignore sys.exit() calls or SystemExit exceptions in the script
2571 being run. This is particularly useful if IPython is being used to
2304 being run. This is particularly useful if IPython is being used to
2572 run unittests, which always exit with a sys.exit() call. In such
2305 run unittests, which always exit with a sys.exit() call. In such
2573 cases you are interested in the output of the test results, not in
2306 cases you are interested in the output of the test results, not in
2574 seeing a traceback of the unittest module.
2307 seeing a traceback of the unittest module.
2575
2308
2576 -t: print timing information at the end of the run. IPython will give
2309 -t: print timing information at the end of the run. IPython will give
2577 you an estimated CPU time consumption for your script, which under
2310 you an estimated CPU time consumption for your script, which under
2578 Unix uses the resource module to avoid the wraparound problems of
2311 Unix uses the resource module to avoid the wraparound problems of
2579 time.clock(). Under Unix, an estimate of time spent on system tasks
2312 time.clock(). Under Unix, an estimate of time spent on system tasks
2580 is also given (for Windows platforms this is reported as 0.0).
2313 is also given (for Windows platforms this is reported as 0.0).
2581
2314
2582 If -t is given, an additional -N<N> option can be given, where <N>
2315 If -t is given, an additional -N<N> option can be given, where <N>
2583 must be an integer indicating how many times you want the script to
2316 must be an integer indicating how many times you want the script to
2584 run. The final timing report will include total and per run results.
2317 run. The final timing report will include total and per run results.
2585
2318
2586 For example (testing the script uniq_stable.py):
2319 For example (testing the script uniq_stable.py):
2587
2320
2588 In [1]: run -t uniq_stable
2321 In [1]: run -t uniq_stable
2589
2322
2590 IPython CPU timings (estimated):\
2323 IPython CPU timings (estimated):\
2591 User : 0.19597 s.\
2324 User : 0.19597 s.\
2592 System: 0.0 s.\
2325 System: 0.0 s.\
2593
2326
2594 In [2]: run -t -N5 uniq_stable
2327 In [2]: run -t -N5 uniq_stable
2595
2328
2596 IPython CPU timings (estimated):\
2329 IPython CPU timings (estimated):\
2597 Total runs performed: 5\
2330 Total runs performed: 5\
2598 Times : Total Per run\
2331 Times : Total Per run\
2599 User : 0.910862 s, 0.1821724 s.\
2332 User : 0.910862 s, 0.1821724 s.\
2600 System: 0.0 s, 0.0 s.
2333 System: 0.0 s, 0.0 s.
2601
2334
2602 -d: run your program under the control of pdb, the Python debugger.
2335 -d: run your program under the control of pdb, the Python debugger.
2603 This allows you to execute your program step by step, watch variables,
2336 This allows you to execute your program step by step, watch variables,
2604 etc. Internally, what IPython does is similar to calling:
2337 etc. Internally, what IPython does is similar to calling:
2605
2338
2606 pdb.run('execfile("YOURFILENAME")')
2339 pdb.run('execfile("YOURFILENAME")')
2607
2340
2608 with a breakpoint set on line 1 of your file. You can change the line
2341 with a breakpoint set on line 1 of your file. You can change the line
2609 number for this automatic breakpoint to be <N> by using the -bN option
2342 number for this automatic breakpoint to be <N> by using the -bN option
2610 (where N must be an integer). For example:
2343 (where N must be an integer). For example:
2611
2344
2612 %run -d -b40 myscript
2345 %run -d -b40 myscript
2613
2346
2614 will set the first breakpoint at line 40 in myscript.py. Note that
2347 will set the first breakpoint at line 40 in myscript.py. Note that
2615 the first breakpoint must be set on a line which actually does
2348 the first breakpoint must be set on a line which actually does
2616 something (not a comment or docstring) for it to stop execution.
2349 something (not a comment or docstring) for it to stop execution.
2617
2350
2618 When the pdb debugger starts, you will see a (Pdb) prompt. You must
2351 When the pdb debugger starts, you will see a (Pdb) prompt. You must
2619 first enter 'c' (without qoutes) to start execution up to the first
2352 first enter 'c' (without qoutes) to start execution up to the first
2620 breakpoint.
2353 breakpoint.
2621
2354
2622 Entering 'help' gives information about the use of the debugger. You
2355 Entering 'help' gives information about the use of the debugger. You
2623 can easily see pdb's full documentation with "import pdb;pdb.help()"
2356 can easily see pdb's full documentation with "import pdb;pdb.help()"
2624 at a prompt.
2357 at a prompt.
2625
2358
2626 -p: run program under the control of the Python profiler module (which
2359 -p: run program under the control of the Python profiler module (which
2627 prints a detailed report of execution times, function calls, etc).
2360 prints a detailed report of execution times, function calls, etc).
2628
2361
2629 You can pass other options after -p which affect the behavior of the
2362 You can pass other options after -p which affect the behavior of the
2630 profiler itself. See the docs for %prun for details.
2363 profiler itself. See the docs for %prun for details.
2631
2364
2632 In this mode, the program's variables do NOT propagate back to the
2365 In this mode, the program's variables do NOT propagate back to the
2633 IPython interactive namespace (because they remain in the namespace
2366 IPython interactive namespace (because they remain in the namespace
2634 where the profiler executes them).
2367 where the profiler executes them).
2635
2368
2636 Internally this triggers a call to %prun, see its documentation for
2369 Internally this triggers a call to %prun, see its documentation for
2637 details on the options available specifically for profiling.
2370 details on the options available specifically for profiling.
2638
2371
2639 There is one special usage for which the text above doesn't apply:
2372 There is one special usage for which the text above doesn't apply:
2640 if the filename ends with .ipy, the file is run as ipython script,
2373 if the filename ends with .ipy, the file is run as ipython script,
2641 just as if the commands were written on IPython prompt.
2374 just as if the commands were written on IPython prompt.
2642
2375
2643 **%runlog**::
2376 **%runlog**::
2644
2377
2645 Run files as logs.
2378 Run files as logs.
2646
2379
2647 Usage:\
2380 Usage:\
2648 %runlog file1 file2 ...
2381 %runlog file1 file2 ...
2649
2382
2650 Run the named files (treating them as log files) in sequence inside
2383 Run the named files (treating them as log files) in sequence inside
2651 the interpreter, and return to the prompt. This is much slower than
2384 the interpreter, and return to the prompt. This is much slower than
2652 %run because each line is executed in a try/except block, but it
2385 %run because each line is executed in a try/except block, but it
2653 allows running files with syntax errors in them.
2386 allows running files with syntax errors in them.
2654
2387
2655 Normally IPython will guess when a file is one of its own logfiles, so
2388 Normally IPython will guess when a file is one of its own logfiles, so
2656 you can typically use %run even for logs. This shorthand allows you to
2389 you can typically use %run even for logs. This shorthand allows you to
2657 force any file to be treated as a log file.
2390 force any file to be treated as a log file.
2658
2391
2659 **%save**::
2392 **%save**::
2660
2393
2661 Save a set of lines to a given filename.
2394 Save a set of lines to a given filename.
2662
2395
2663 Usage:\
2396 Usage:\
2664 %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
2397 %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
2665
2398
2666 Options:
2399 Options:
2667
2400
2668 -r: use 'raw' input. By default, the 'processed' history is used,
2401 -r: use 'raw' input. By default, the 'processed' history is used,
2669 so that magics are loaded in their transformed version to valid
2402 so that magics are loaded in their transformed version to valid
2670 Python. If this option is given, the raw input as typed as the
2403 Python. If this option is given, the raw input as typed as the
2671 command line is used instead.
2404 command line is used instead.
2672
2405
2673 This function uses the same syntax as %macro for line extraction, but
2406 This function uses the same syntax as %macro for line extraction, but
2674 instead of creating a macro it saves the resulting string to the
2407 instead of creating a macro it saves the resulting string to the
2675 filename you specify.
2408 filename you specify.
2676
2409
2677 It adds a '.py' extension to the file if you don't do so yourself, and
2410 It adds a '.py' extension to the file if you don't do so yourself, and
2678 it asks for confirmation before overwriting existing files.
2411 it asks for confirmation before overwriting existing files.
2679
2412
2680 **%sc**::
2413 **%sc**::
2681
2414
2682 Shell capture - execute a shell command and capture its output.
2415 Shell capture - execute a shell command and capture its output.
2683
2416
2684 DEPRECATED. Suboptimal, retained for backwards compatibility.
2417 DEPRECATED. Suboptimal, retained for backwards compatibility.
2685
2418
2686 You should use the form 'var = !command' instead. Example:
2419 You should use the form 'var = !command' instead. Example:
2687
2420
2688 "%sc -l myfiles = ls ~" should now be written as
2421 "%sc -l myfiles = ls ~" should now be written as
2689
2422
2690 "myfiles = !ls ~"
2423 "myfiles = !ls ~"
2691
2424
2692 myfiles.s, myfiles.l and myfiles.n still apply as documented
2425 myfiles.s, myfiles.l and myfiles.n still apply as documented
2693 below.
2426 below.
2694
2427
2695 --
2428 --
2696 %sc [options] varname=command
2429 %sc [options] varname=command
2697
2430
2698 IPython will run the given command using commands.getoutput(), and
2431 IPython will run the given command using commands.getoutput(), and
2699 will then update the user's interactive namespace with a variable
2432 will then update the user's interactive namespace with a variable
2700 called varname, containing the value of the call. Your command can
2433 called varname, containing the value of the call. Your command can
2701 contain shell wildcards, pipes, etc.
2434 contain shell wildcards, pipes, etc.
2702
2435
2703 The '=' sign in the syntax is mandatory, and the variable name you
2436 The '=' sign in the syntax is mandatory, and the variable name you
2704 supply must follow Python's standard conventions for valid names.
2437 supply must follow Python's standard conventions for valid names.
2705
2438
2706 (A special format without variable name exists for internal use)
2439 (A special format without variable name exists for internal use)
2707
2440
2708 Options:
2441 Options:
2709
2442
2710 -l: list output. Split the output on newlines into a list before
2443 -l: list output. Split the output on newlines into a list before
2711 assigning it to the given variable. By default the output is stored
2444 assigning it to the given variable. By default the output is stored
2712 as a single string.
2445 as a single string.
2713
2446
2714 -v: verbose. Print the contents of the variable.
2447 -v: verbose. Print the contents of the variable.
2715
2448
2716 In most cases you should not need to split as a list, because the
2449 In most cases you should not need to split as a list, because the
2717 returned value is a special type of string which can automatically
2450 returned value is a special type of string which can automatically
2718 provide its contents either as a list (split on newlines) or as a
2451 provide its contents either as a list (split on newlines) or as a
2719 space-separated string. These are convenient, respectively, either
2452 space-separated string. These are convenient, respectively, either
2720 for sequential processing or to be passed to a shell command.
2453 for sequential processing or to be passed to a shell command.
2721
2454
2722 For example:
2455 For example:
2723
2456
2724 # Capture into variable a
2457 # Capture into variable a
2725 In [9]: sc a=ls *py
2458 In [9]: sc a=ls *py
2726
2459
2727 # a is a string with embedded newlines
2460 # a is a string with embedded newlines
2728 In [10]: a
2461 In [10]: a
2729 Out[10]: 'setup.py win32_manual_post_install.py'
2462 Out[10]: 'setup.py win32_manual_post_install.py'
2730
2463
2731 # which can be seen as a list:
2464 # which can be seen as a list:
2732 In [11]: a.l
2465 In [11]: a.l
2733 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2466 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2734
2467
2735 # or as a whitespace-separated string:
2468 # or as a whitespace-separated string:
2736 In [12]: a.s
2469 In [12]: a.s
2737 Out[12]: 'setup.py win32_manual_post_install.py'
2470 Out[12]: 'setup.py win32_manual_post_install.py'
2738
2471
2739 # a.s is useful to pass as a single command line:
2472 # a.s is useful to pass as a single command line:
2740 In [13]: !wc -l $a.s
2473 In [13]: !wc -l $a.s
2741 146 setup.py
2474 146 setup.py
2742 130 win32_manual_post_install.py
2475 130 win32_manual_post_install.py
2743 276 total
2476 276 total
2744
2477
2745 # while the list form is useful to loop over:
2478 # while the list form is useful to loop over:
2746 In [14]: for f in a.l:
2479 In [14]: for f in a.l:
2747 ....: !wc -l $f
2480 ....: !wc -l $f
2748 ....:
2481 ....:
2749 146 setup.py
2482 146 setup.py
2750 130 win32_manual_post_install.py
2483 130 win32_manual_post_install.py
2751
2484
2752 Similiarly, the lists returned by the -l option are also special, in
2485 Similiarly, the lists returned by the -l option are also special, in
2753 the sense that you can equally invoke the .s attribute on them to
2486 the sense that you can equally invoke the .s attribute on them to
2754 automatically get a whitespace-separated string from their contents:
2487 automatically get a whitespace-separated string from their contents:
2755
2488
2756 In [1]: sc -l b=ls *py
2489 In [1]: sc -l b=ls *py
2757
2490
2758 In [2]: b
2491 In [2]: b
2759 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2492 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2760
2493
2761 In [3]: b.s
2494 In [3]: b.s
2762 Out[3]: 'setup.py win32_manual_post_install.py'
2495 Out[3]: 'setup.py win32_manual_post_install.py'
2763
2496
2764 In summary, both the lists and strings used for ouptut capture have
2497 In summary, both the lists and strings used for ouptut capture have
2765 the following special attributes:
2498 the following special attributes:
2766
2499
2767 .l (or .list) : value as list.
2500 .l (or .list) : value as list.
2768 .n (or .nlstr): value as newline-separated string.
2501 .n (or .nlstr): value as newline-separated string.
2769 .s (or .spstr): value as space-separated string.
2502 .s (or .spstr): value as space-separated string.
2770
2503
2771 **%store**::
2504 **%store**::
2772
2505
2773 Lightweight persistence for python variables.
2506 Lightweight persistence for python variables.
2774
2507
2775 Example:
2508 Example:
2776
2509
2777 ville@badger[~]|1> A = ['hello',10,'world']\
2510 ville@badger[~]|1> A = ['hello',10,'world']\
2778 ville@badger[~]|2> %store A\
2511 ville@badger[~]|2> %store A\
2779 ville@badger[~]|3> Exit
2512 ville@badger[~]|3> Exit
2780
2513
2781 (IPython session is closed and started again...)
2514 (IPython session is closed and started again...)
2782
2515
2783 ville@badger:~$ ipython -p pysh\
2516 ville@badger:~$ ipython -p pysh\
2784 ville@badger[~]|1> print A
2517 ville@badger[~]|1> print A
2785
2518
2786 ['hello', 10, 'world']
2519 ['hello', 10, 'world']
2787
2520
2788 Usage:
2521 Usage:
2789
2522
2790 %store - Show list of all variables and their current values\
2523 %store - Show list of all variables and their current values\
2791 %store <var> - Store the *current* value of the variable to disk\
2524 %store <var> - Store the *current* value of the variable to disk\
2792 %store -d <var> - Remove the variable and its value from storage\
2525 %store -d <var> - Remove the variable and its value from storage\
2793 %store -z - Remove all variables from storage\
2526 %store -z - Remove all variables from storage\
2794 %store -r - Refresh all variables from store (delete current vals)\
2527 %store -r - Refresh all variables from store (delete current vals)\
2795 %store foo >a.txt - Store value of foo to new file a.txt\
2528 %store foo >a.txt - Store value of foo to new file a.txt\
2796 %store foo >>a.txt - Append value of foo to file a.txt\
2529 %store foo >>a.txt - Append value of foo to file a.txt\
2797
2530
2798 It should be noted that if you change the value of a variable, you
2531 It should be noted that if you change the value of a variable, you
2799 need to %store it again if you want to persist the new value.
2532 need to %store it again if you want to persist the new value.
2800
2533
2801 Note also that the variables will need to be pickleable; most basic
2534 Note also that the variables will need to be pickleable; most basic
2802 python types can be safely %stored.
2535 python types can be safely %stored.
2803
2536
2804 Also aliases can be %store'd across sessions.
2537 Also aliases can be %store'd across sessions.
2805
2538
2806 **%sx**::
2539 **%sx**::
2807
2540
2808 Shell execute - run a shell command and capture its output.
2541 Shell execute - run a shell command and capture its output.
2809
2542
2810 %sx command
2543 %sx command
2811
2544
2812 IPython will run the given command using commands.getoutput(), and
2545 IPython will run the given command using commands.getoutput(), and
2813 return the result formatted as a list (split on '\n'). Since the
2546 return the result formatted as a list (split on '\n'). Since the
2814 output is _returned_, it will be stored in ipython's regular output
2547 output is _returned_, it will be stored in ipython's regular output
2815 cache Out[N] and in the '_N' automatic variables.
2548 cache Out[N] and in the '_N' automatic variables.
2816
2549
2817 Notes:
2550 Notes:
2818
2551
2819 1) If an input line begins with '!!', then %sx is automatically
2552 1) If an input line begins with '!!', then %sx is automatically
2820 invoked. That is, while:
2553 invoked. That is, while:
2821 !ls
2554 !ls
2822 causes ipython to simply issue system('ls'), typing
2555 causes ipython to simply issue system('ls'), typing
2823 !!ls
2556 !!ls
2824 is a shorthand equivalent to:
2557 is a shorthand equivalent to:
2825 %sx ls
2558 %sx ls
2826
2559
2827 2) %sx differs from %sc in that %sx automatically splits into a list,
2560 2) %sx differs from %sc in that %sx automatically splits into a list,
2828 like '%sc -l'. The reason for this is to make it as easy as possible
2561 like '%sc -l'. The reason for this is to make it as easy as possible
2829 to process line-oriented shell output via further python commands.
2562 to process line-oriented shell output via further python commands.
2830 %sc is meant to provide much finer control, but requires more
2563 %sc is meant to provide much finer control, but requires more
2831 typing.
2564 typing.
2832
2565
2833 3) Just like %sc -l, this is a list with special attributes:
2566 3) Just like %sc -l, this is a list with special attributes:
2834
2567
2835 .l (or .list) : value as list.
2568 .l (or .list) : value as list.
2836 .n (or .nlstr): value as newline-separated string.
2569 .n (or .nlstr): value as newline-separated string.
2837 .s (or .spstr): value as whitespace-separated string.
2570 .s (or .spstr): value as whitespace-separated string.
2838
2571
2839 This is very useful when trying to use such lists as arguments to
2572 This is very useful when trying to use such lists as arguments to
2840 system commands.
2573 system commands.
2841
2574
2842 **%system_verbose**::
2575 **%system_verbose**::
2843
2576
2844 Set verbose printing of system calls.
2577 Set verbose printing of system calls.
2845
2578
2846 If called without an argument, act as a toggle
2579 If called without an argument, act as a toggle
2847
2580
2848 **%time**::
2581 **%time**::
2849
2582
2850 Time execution of a Python statement or expression.
2583 Time execution of a Python statement or expression.
2851
2584
2852 The CPU and wall clock times are printed, and the value of the
2585 The CPU and wall clock times are printed, and the value of the
2853 expression (if any) is returned. Note that under Win32, system time
2586 expression (if any) is returned. Note that under Win32, system time
2854 is always reported as 0, since it can not be measured.
2587 is always reported as 0, since it can not be measured.
2855
2588
2856 This function provides very basic timing functionality. In Python
2589 This function provides very basic timing functionality. In Python
2857 2.3, the timeit module offers more control and sophistication, so this
2590 2.3, the timeit module offers more control and sophistication, so this
2858 could be rewritten to use it (patches welcome).
2591 could be rewritten to use it (patches welcome).
2859
2592
2860 Some examples:
2593 Some examples:
2861
2594
2862 In [1]: time 2**128
2595 In [1]: time 2**128
2863 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2596 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2864 Wall time: 0.00
2597 Wall time: 0.00
2865 Out[1]: 340282366920938463463374607431768211456L
2598 Out[1]: 340282366920938463463374607431768211456L
2866
2599
2867 In [2]: n = 1000000
2600 In [2]: n = 1000000
2868
2601
2869 In [3]: time sum(range(n))
2602 In [3]: time sum(range(n))
2870 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
2603 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
2871 Wall time: 1.37
2604 Wall time: 1.37
2872 Out[3]: 499999500000L
2605 Out[3]: 499999500000L
2873
2606
2874 In [4]: time print 'hello world'
2607 In [4]: time print 'hello world'
2875 hello world
2608 hello world
2876 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2609 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2877 Wall time: 0.00
2610 Wall time: 0.00
2878
2611
2879 Note that the time needed by Python to compile the given expression
2612 Note that the time needed by Python to compile the given expression
2880 will be reported if it is more than 0.1s. In this example, the
2613 will be reported if it is more than 0.1s. In this example, the
2881 actual exponentiation is done by Python at compilation time, so while
2614 actual exponentiation is done by Python at compilation time, so while
2882 the expression can take a noticeable amount of time to compute, that
2615 the expression can take a noticeable amount of time to compute, that
2883 time is purely due to the compilation:
2616 time is purely due to the compilation:
2884
2617
2885 In [5]: time 3**9999;
2618 In [5]: time 3**9999;
2886 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2619 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2887 Wall time: 0.00 s
2620 Wall time: 0.00 s
2888
2621
2889 In [6]: time 3**999999;
2622 In [6]: time 3**999999;
2890 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2623 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2891 Wall time: 0.00 s
2624 Wall time: 0.00 s
2892 Compiler : 0.78 s
2625 Compiler : 0.78 s
2893
2626
2894 **%timeit**::
2627 **%timeit**::
2895
2628
2896 Time execution of a Python statement or expression
2629 Time execution of a Python statement or expression
2897
2630
2898 Usage:\
2631 Usage:\
2899 %timeit [-n<N> -r<R> [-t|-c]] statement
2632 %timeit [-n<N> -r<R> [-t|-c]] statement
2900
2633
2901 Time execution of a Python statement or expression using the timeit
2634 Time execution of a Python statement or expression using the timeit
2902 module.
2635 module.
2903
2636
2904 Options:
2637 Options:
2905 -n<N>: execute the given statement <N> times in a loop. If this value
2638 -n<N>: execute the given statement <N> times in a loop. If this value
2906 is not given, a fitting value is chosen.
2639 is not given, a fitting value is chosen.
2907
2640
2908 -r<R>: repeat the loop iteration <R> times and take the best result.
2641 -r<R>: repeat the loop iteration <R> times and take the best result.
2909 Default: 3
2642 Default: 3
2910
2643
2911 -t: use time.time to measure the time, which is the default on Unix.
2644 -t: use time.time to measure the time, which is the default on Unix.
2912 This function measures wall time.
2645 This function measures wall time.
2913
2646
2914 -c: use time.clock to measure the time, which is the default on
2647 -c: use time.clock to measure the time, which is the default on
2915 Windows and measures wall time. On Unix, resource.getrusage is used
2648 Windows and measures wall time. On Unix, resource.getrusage is used
2916 instead and returns the CPU user time.
2649 instead and returns the CPU user time.
2917
2650
2918 -p<P>: use a precision of <P> digits to display the timing result.
2651 -p<P>: use a precision of <P> digits to display the timing result.
2919 Default: 3
2652 Default: 3
2920
2653
2921
2654
2922 Examples:\
2655 Examples:\
2923 In [1]: %timeit pass
2656 In [1]: %timeit pass
2924 10000000 loops, best of 3: 53.3 ns per loop
2657 10000000 loops, best of 3: 53.3 ns per loop
2925
2658
2926 In [2]: u = None
2659 In [2]: u = None
2927
2660
2928 In [3]: %timeit u is None
2661 In [3]: %timeit u is None
2929 10000000 loops, best of 3: 184 ns per loop
2662 10000000 loops, best of 3: 184 ns per loop
2930
2663
2931 In [4]: %timeit -r 4 u == None
2664 In [4]: %timeit -r 4 u == None
2932 1000000 loops, best of 4: 242 ns per loop
2665 1000000 loops, best of 4: 242 ns per loop
2933
2666
2934 In [5]: import time
2667 In [5]: import time
2935
2668
2936 In [6]: %timeit -n1 time.sleep(2)
2669 In [6]: %timeit -n1 time.sleep(2)
2937 1 loops, best of 3: 2 s per loop
2670 1 loops, best of 3: 2 s per loop
2938
2671
2939
2672
2940 The times reported by %timeit will be slightly higher than those
2673 The times reported by %timeit will be slightly higher than those
2941 reported by the timeit.py script when variables are accessed. This is
2674 reported by the timeit.py script when variables are accessed. This is
2942 due to the fact that %timeit executes the statement in the namespace
2675 due to the fact that %timeit executes the statement in the namespace
2943 of the shell, compared with timeit.py, which uses a single setup
2676 of the shell, compared with timeit.py, which uses a single setup
2944 statement to import function or create variables. Generally, the bias
2677 statement to import function or create variables. Generally, the bias
2945 does not matter as long as results from timeit.py are not mixed with
2678 does not matter as long as results from timeit.py are not mixed with
2946 those from %timeit.
2679 those from %timeit.
2947
2680
2948 **%unalias**::
2681 **%unalias**::
2949
2682
2950 Remove an alias
2683 Remove an alias
2951
2684
2952 **%upgrade**::
2685 **%upgrade**::
2953
2686
2954 Upgrade your IPython installation
2687 Upgrade your IPython installation
2955
2688
2956 This will copy the config files that don't yet exist in your
2689 This will copy the config files that don't yet exist in your
2957 ipython dir from the system config dir. Use this after upgrading
2690 ipython dir from the system config dir. Use this after upgrading
2958 IPython if you don't wish to delete your .ipython dir.
2691 IPython if you don't wish to delete your .ipython dir.
2959
2692
2960 Call with -nolegacy to get rid of ipythonrc* files (recommended for
2693 Call with -nolegacy to get rid of ipythonrc* files (recommended for
2961 new users)
2694 new users)
2962
2695
2963 **%which**::
2696 **%which**::
2964
2697
2965 %which <cmd> => search PATH for files matching cmd. Also scans aliases.
2698 %which <cmd> => search PATH for files matching cmd. Also scans aliases.
2966
2699
2967 Traverses PATH and prints all files (not just executables!) that match the
2700 Traverses PATH and prints all files (not just executables!) that match the
2968 pattern on command line. Probably more useful in finding stuff
2701 pattern on command line. Probably more useful in finding stuff
2969 interactively than 'which', which only prints the first matching item.
2702 interactively than 'which', which only prints the first matching item.
2970
2703
2971 Also discovers and expands aliases, so you'll see what will be executed
2704 Also discovers and expands aliases, so you'll see what will be executed
2972 when you call an alias.
2705 when you call an alias.
2973
2706
2974 Example:
2707 Example:
2975
2708
2976 [~]|62> %which d
2709 [~]|62> %which d
2977 d -> ls -F --color=auto
2710 d -> ls -F --color=auto
2978 == c:\cygwin\bin\ls.exe
2711 == c:\cygwin\bin\ls.exe
2979 c:\cygwin\bin\d.exe
2712 c:\cygwin\bin\d.exe
2980
2713
2981 [~]|64> %which diff*
2714 [~]|64> %which diff*
2982 diff3 -> diff3
2715 diff3 -> diff3
2983 == c:\cygwin\bin\diff3.exe
2716 == c:\cygwin\bin\diff3.exe
2984 diff -> diff
2717 diff -> diff
2985 == c:\cygwin\bin\diff.exe
2718 == c:\cygwin\bin\diff.exe
2986 c:\cygwin\bin\diff.exe
2719 c:\cygwin\bin\diff.exe
2987 c:\cygwin\bin\diff3.exe
2720 c:\cygwin\bin\diff3.exe
2988
2721
2989 **%who**::
2722 **%who**::
2990
2723
2991 Print all interactive variables, with some minimal formatting.
2724 Print all interactive variables, with some minimal formatting.
2992
2725
2993 If any arguments are given, only variables whose type matches one of
2726 If any arguments are given, only variables whose type matches one of
2994 these are printed. For example:
2727 these are printed. For example:
2995
2728
2996 %who function str
2729 %who function str
2997
2730
2998 will only list functions and strings, excluding all other types of
2731 will only list functions and strings, excluding all other types of
2999 variables. To find the proper type names, simply use type(var) at a
2732 variables. To find the proper type names, simply use type(var) at a
3000 command line to see how python prints type names. For example:
2733 command line to see how python prints type names. For example:
3001
2734
3002 In [1]: type('hello')\
2735 In [1]: type('hello')\
3003 Out[1]: <type 'str'>
2736 Out[1]: <type 'str'>
3004
2737
3005 indicates that the type name for strings is 'str'.
2738 indicates that the type name for strings is 'str'.
3006
2739
3007 %who always excludes executed names loaded through your configuration
2740 %who always excludes executed names loaded through your configuration
3008 file and things which are internal to IPython.
2741 file and things which are internal to IPython.
3009
2742
3010 This is deliberate, as typically you may load many modules and the
2743 This is deliberate, as typically you may load many modules and the
3011 purpose of %who is to show you only what you've manually defined.
2744 purpose of %who is to show you only what you've manually defined.
3012
2745
3013 **%who_ls**::
2746 **%who_ls**::
3014
2747
3015 Return a sorted list of all interactive variables.
2748 Return a sorted list of all interactive variables.
3016
2749
3017 If arguments are given, only variables of types matching these
2750 If arguments are given, only variables of types matching these
3018 arguments are returned.
2751 arguments are returned.
3019
2752
3020 **%whos**::
2753 **%whos**::
3021
2754
3022 Like %who, but gives some extra information about each variable.
2755 Like %who, but gives some extra information about each variable.
3023
2756
3024 The same type filtering of %who can be applied here.
2757 The same type filtering of %who can be applied here.
3025
2758
3026 For all variables, the type is printed. Additionally it prints:
2759 For all variables, the type is printed. Additionally it prints:
3027
2760
3028 - For {},[],(): their length.
2761 - For {},[],(): their length.
3029
2762
3030 - For numpy and Numeric arrays, a summary with shape, number of
2763 - For numpy and Numeric arrays, a summary with shape, number of
3031 elements, typecode and size in memory.
2764 elements, typecode and size in memory.
3032
2765
3033 - Everything else: a string representation, snipping their middle if
2766 - Everything else: a string representation, snipping their middle if
3034 too long.
2767 too long.
3035
2768
3036 **%xmode**::
2769 **%xmode**::
3037
2770
3038 Switch modes for the exception handlers.
2771 Switch modes for the exception handlers.
3039
2772
3040 Valid modes: Plain, Context and Verbose.
2773 Valid modes: Plain, Context and Verbose.
3041
2774
3042 If called without arguments, acts as a toggle.
2775 If called without arguments, acts as a toggle.
3043
2776
3044 .. magic_end
2777 .. magic_end
3045
2778
3046 Access to the standard Python help
2779 Access to the standard Python help
3047 ----------------------------------
2780 ----------------------------------
3048
2781
3049 As of Python 2.1, a help system is available with access to object
2782 As of Python 2.1, a help system is available with access to object
3050 docstrings and the Python manuals. Simply type 'help' (no quotes) to
2783 docstrings and the Python manuals. Simply type 'help' (no quotes) to
3051 access it. You can also type help(object) to obtain information about a
2784 access it. You can also type help(object) to obtain information about a
3052 given object, and help('keyword') for information on a keyword. As noted
2785 given object, and help('keyword') for information on a keyword. As noted
3053 in sec. `accessing help`_, you need to properly configure
2786 in sec. `accessing help`_, you need to properly configure
3054 your environment variable PYTHONDOCS for this feature to work correctly.
2787 your environment variable PYTHONDOCS for this feature to work correctly.
3055
2788
3056
2789
3057 Dynamic object information
2790 Dynamic object information
3058 --------------------------
2791 --------------------------
3059
2792
3060 Typing ?word or word? prints detailed information about an object. If
2793 Typing ?word or word? prints detailed information about an object. If
3061 certain strings in the object are too long (docstrings, code, etc.) they
2794 certain strings in the object are too long (docstrings, code, etc.) they
3062 get snipped in the center for brevity. This system gives access variable
2795 get snipped in the center for brevity. This system gives access variable
3063 types and values, full source code for any object (if available),
2796 types and values, full source code for any object (if available),
3064 function prototypes and other useful information.
2797 function prototypes and other useful information.
3065
2798
3066 Typing ??word or word?? gives access to the full information without
2799 Typing ??word or word?? gives access to the full information without
3067 snipping long strings. Long strings are sent to the screen through the
2800 snipping long strings. Long strings are sent to the screen through the
3068 less pager if longer than the screen and printed otherwise. On systems
2801 less pager if longer than the screen and printed otherwise. On systems
3069 lacking the less command, IPython uses a very basic internal pager.
2802 lacking the less command, IPython uses a very basic internal pager.
3070
2803
3071 The following magic functions are particularly useful for gathering
2804 The following magic functions are particularly useful for gathering
3072 information about your working environment. You can get more details by
2805 information about your working environment. You can get more details by
3073 typing %magic or querying them individually (use %function_name? with or
2806 typing %magic or querying them individually (use %function_name? with or
3074 without the %), this is just a summary:
2807 without the %), this is just a summary:
3075
2808
3076 * **%pdoc <object>**: Print (or run through a pager if too long) the
2809 * **%pdoc <object>**: Print (or run through a pager if too long) the
3077 docstring for an object. If the given object is a class, it will
2810 docstring for an object. If the given object is a class, it will
3078 print both the class and the constructor docstrings.
2811 print both the class and the constructor docstrings.
3079 * **%pdef <object>**: Print the definition header for any callable
2812 * **%pdef <object>**: Print the definition header for any callable
3080 object. If the object is a class, print the constructor information.
2813 object. If the object is a class, print the constructor information.
3081 * **%psource <object>**: Print (or run through a pager if too long)
2814 * **%psource <object>**: Print (or run through a pager if too long)
3082 the source code for an object.
2815 the source code for an object.
3083 * **%pfile <object>**: Show the entire source file where an object was
2816 * **%pfile <object>**: Show the entire source file where an object was
3084 defined via a pager, opening it at the line where the object
2817 defined via a pager, opening it at the line where the object
3085 definition begins.
2818 definition begins.
3086 * **%who/%whos**: These functions give information about identifiers
2819 * **%who/%whos**: These functions give information about identifiers
3087 you have defined interactively (not things you loaded or defined
2820 you have defined interactively (not things you loaded or defined
3088 in your configuration files). %who just prints a list of
2821 in your configuration files). %who just prints a list of
3089 identifiers and %whos prints a table with some basic details about
2822 identifiers and %whos prints a table with some basic details about
3090 each identifier.
2823 each identifier.
3091
2824
3092 Note that the dynamic object information functions (?/??, %pdoc, %pfile,
2825 Note that the dynamic object information functions (?/??, %pdoc, %pfile,
3093 %pdef, %psource) give you access to documentation even on things which
2826 %pdef, %psource) give you access to documentation even on things which
3094 are not really defined as separate identifiers. Try for example typing
2827 are not really defined as separate identifiers. Try for example typing
3095 {}.get? or after doing import os, type os.path.abspath??.
2828 {}.get? or after doing import os, type os.path.abspath??.
3096
2829
3097
2830
3098 .. _Readline:
2831 .. _Readline:
3099
2832
3100 Readline-based features
2833 Readline-based features
3101 -----------------------
2834 -----------------------
3102
2835
3103 These features require the GNU readline library, so they won't work if
2836 These features require the GNU readline library, so they won't work if
3104 your Python installation lacks readline support. We will first describe
2837 your Python installation lacks readline support. We will first describe
3105 the default behavior IPython uses, and then how to change it to suit
2838 the default behavior IPython uses, and then how to change it to suit
3106 your preferences.
2839 your preferences.
3107
2840
3108
2841
3109 Command line completion
2842 Command line completion
3110 +++++++++++++++++++++++
2843 +++++++++++++++++++++++
3111
2844
3112 At any time, hitting TAB will complete any available python commands or
2845 At any time, hitting TAB will complete any available python commands or
3113 variable names, and show you a list of the possible completions if
2846 variable names, and show you a list of the possible completions if
3114 there's no unambiguous one. It will also complete filenames in the
2847 there's no unambiguous one. It will also complete filenames in the
3115 current directory if no python names match what you've typed so far.
2848 current directory if no python names match what you've typed so far.
3116
2849
3117
2850
3118 Search command history
2851 Search command history
3119 ++++++++++++++++++++++
2852 ++++++++++++++++++++++
3120
2853
3121 IPython provides two ways for searching through previous input and thus
2854 IPython provides two ways for searching through previous input and thus
3122 reduce the need for repetitive typing:
2855 reduce the need for repetitive typing:
3123
2856
3124 1. Start typing, and then use Ctrl-p (previous,up) and Ctrl-n
2857 1. Start typing, and then use Ctrl-p (previous,up) and Ctrl-n
3125 (next,down) to search through only the history items that match
2858 (next,down) to search through only the history items that match
3126 what you've typed so far. If you use Ctrl-p/Ctrl-n at a blank
2859 what you've typed so far. If you use Ctrl-p/Ctrl-n at a blank
3127 prompt, they just behave like normal arrow keys.
2860 prompt, they just behave like normal arrow keys.
3128 2. Hit Ctrl-r: opens a search prompt. Begin typing and the system
2861 2. Hit Ctrl-r: opens a search prompt. Begin typing and the system
3129 searches your history for lines that contain what you've typed so
2862 searches your history for lines that contain what you've typed so
3130 far, completing as much as it can.
2863 far, completing as much as it can.
3131
2864
3132
2865
3133 Persistent command history across sessions
2866 Persistent command history across sessions
3134 ++++++++++++++++++++++++++++++++++++++++++
2867 ++++++++++++++++++++++++++++++++++++++++++
3135
2868
3136 IPython will save your input history when it leaves and reload it next
2869 IPython will save your input history when it leaves and reload it next
3137 time you restart it. By default, the history file is named
2870 time you restart it. By default, the history file is named
3138 $IPYTHONDIR/history, but if you've loaded a named profile,
2871 $IPYTHONDIR/history, but if you've loaded a named profile,
3139 '-PROFILE_NAME' is appended to the name. This allows you to keep
2872 '-PROFILE_NAME' is appended to the name. This allows you to keep
3140 separate histories related to various tasks: commands related to
2873 separate histories related to various tasks: commands related to
3141 numerical work will not be clobbered by a system shell history, for
2874 numerical work will not be clobbered by a system shell history, for
3142 example.
2875 example.
3143
2876
3144
2877
3145 Autoindent
2878 Autoindent
3146 ++++++++++
2879 ++++++++++
3147
2880
3148 IPython can recognize lines ending in ':' and indent the next line,
2881 IPython can recognize lines ending in ':' and indent the next line,
3149 while also un-indenting automatically after 'raise' or 'return'.
2882 while also un-indenting automatically after 'raise' or 'return'.
3150
2883
3151 This feature uses the readline library, so it will honor your ~/.inputrc
2884 This feature uses the readline library, so it will honor your ~/.inputrc
3152 configuration (or whatever file your INPUTRC variable points to). Adding
2885 configuration (or whatever file your INPUTRC variable points to). Adding
3153 the following lines to your .inputrc file can make indenting/unindenting
2886 the following lines to your .inputrc file can make indenting/unindenting
3154 more convenient (M-i indents, M-u unindents)::
2887 more convenient (M-i indents, M-u unindents)::
3155
2888
3156 $if Python
2889 $if Python
3157 "\M-i": " "
2890 "\M-i": " "
3158 "\M-u": "\d\d\d\d"
2891 "\M-u": "\d\d\d\d"
3159 $endif
2892 $endif
3160
2893
3161 Note that there are 4 spaces between the quote marks after "M-i" above.
2894 Note that there are 4 spaces between the quote marks after "M-i" above.
3162
2895
3163 Warning: this feature is ON by default, but it can cause problems with
2896 Warning: this feature is ON by default, but it can cause problems with
3164 the pasting of multi-line indented code (the pasted code gets
2897 the pasting of multi-line indented code (the pasted code gets
3165 re-indented on each line). A magic function %autoindent allows you to
2898 re-indented on each line). A magic function %autoindent allows you to
3166 toggle it on/off at runtime. You can also disable it permanently on in
2899 toggle it on/off at runtime. You can also disable it permanently on in
3167 your ipythonrc file (set autoindent 0).
2900 your ipythonrc file (set autoindent 0).
3168
2901
3169
2902
3170 Customizing readline behavior
2903 Customizing readline behavior
3171 +++++++++++++++++++++++++++++
2904 +++++++++++++++++++++++++++++
3172
2905
3173 All these features are based on the GNU readline library, which has an
2906 All these features are based on the GNU readline library, which has an
3174 extremely customizable interface. Normally, readline is configured via a
2907 extremely customizable interface. Normally, readline is configured via a
3175 file which defines the behavior of the library; the details of the
2908 file which defines the behavior of the library; the details of the
3176 syntax for this can be found in the readline documentation available
2909 syntax for this can be found in the readline documentation available
3177 with your system or on the Internet. IPython doesn't read this file (if
2910 with your system or on the Internet. IPython doesn't read this file (if
3178 it exists) directly, but it does support passing to readline valid
2911 it exists) directly, but it does support passing to readline valid
3179 options via a simple interface. In brief, you can customize readline by
2912 options via a simple interface. In brief, you can customize readline by
3180 setting the following options in your ipythonrc configuration file (note
2913 setting the following options in your ipythonrc configuration file (note
3181 that these options can not be specified at the command line):
2914 that these options can not be specified at the command line):
3182
2915
3183 * **readline_parse_and_bind**: this option can appear as many times as
2916 * **readline_parse_and_bind**: this option can appear as many times as
3184 you want, each time defining a string to be executed via a
2917 you want, each time defining a string to be executed via a
3185 readline.parse_and_bind() command. The syntax for valid commands
2918 readline.parse_and_bind() command. The syntax for valid commands
3186 of this kind can be found by reading the documentation for the GNU
2919 of this kind can be found by reading the documentation for the GNU
3187 readline library, as these commands are of the kind which readline
2920 readline library, as these commands are of the kind which readline
3188 accepts in its configuration file.
2921 accepts in its configuration file.
3189 * **readline_remove_delims**: a string of characters to be removed
2922 * **readline_remove_delims**: a string of characters to be removed
3190 from the default word-delimiters list used by readline, so that
2923 from the default word-delimiters list used by readline, so that
3191 completions may be performed on strings which contain them. Do not
2924 completions may be performed on strings which contain them. Do not
3192 change the default value unless you know what you're doing.
2925 change the default value unless you know what you're doing.
3193 * **readline_omit__names**: when tab-completion is enabled, hitting
2926 * **readline_omit__names**: when tab-completion is enabled, hitting
3194 <tab> after a '.' in a name will complete all attributes of an
2927 <tab> after a '.' in a name will complete all attributes of an
3195 object, including all the special methods whose names include
2928 object, including all the special methods whose names include
3196 double underscores (like __getitem__ or __class__). If you'd
2929 double underscores (like __getitem__ or __class__). If you'd
3197 rather not see these names by default, you can set this option to
2930 rather not see these names by default, you can set this option to
3198 1. Note that even when this option is set, you can still see those
2931 1. Note that even when this option is set, you can still see those
3199 names by explicitly typing a _ after the period and hitting <tab>:
2932 names by explicitly typing a _ after the period and hitting <tab>:
3200 'name._<tab>' will always complete attribute names starting with '_'.
2933 'name._<tab>' will always complete attribute names starting with '_'.
3201
2934
3202 This option is off by default so that new users see all
2935 This option is off by default so that new users see all
3203 attributes of any objects they are dealing with.
2936 attributes of any objects they are dealing with.
3204
2937
3205 You will find the default values along with a corresponding detailed
2938 You will find the default values along with a corresponding detailed
3206 explanation in your ipythonrc file.
2939 explanation in your ipythonrc file.
3207
2940
3208
2941
3209 Session logging and restoring
2942 Session logging and restoring
3210 -----------------------------
2943 -----------------------------
3211
2944
3212 You can log all input from a session either by starting IPython with
2945 You can log all input from a session either by starting IPython with
3213 the command line switches -log or -logfile (see sec. `command line
2946 the command line switches -log or -logfile (see sec. `command line
3214 options`_) or by activating the logging at any moment with the magic
2947 options`_) or by activating the logging at any moment with the magic
3215 function %logstart.
2948 function %logstart.
3216
2949
3217 Log files can later be reloaded with the -logplay option and IPython
2950 Log files can later be reloaded with the -logplay option and IPython
3218 will attempt to 'replay' the log by executing all the lines in it, thus
2951 will attempt to 'replay' the log by executing all the lines in it, thus
3219 restoring the state of a previous session. This feature is not quite
2952 restoring the state of a previous session. This feature is not quite
3220 perfect, but can still be useful in many cases.
2953 perfect, but can still be useful in many cases.
3221
2954
3222 The log files can also be used as a way to have a permanent record of
2955 The log files can also be used as a way to have a permanent record of
3223 any code you wrote while experimenting. Log files are regular text files
2956 any code you wrote while experimenting. Log files are regular text files
3224 which you can later open in your favorite text editor to extract code or
2957 which you can later open in your favorite text editor to extract code or
3225 to 'clean them up' before using them to replay a session.
2958 to 'clean them up' before using them to replay a session.
3226
2959
3227 The %logstart function for activating logging in mid-session is used as
2960 The %logstart function for activating logging in mid-session is used as
3228 follows:
2961 follows:
3229
2962
3230 %logstart [log_name [log_mode]]
2963 %logstart [log_name [log_mode]]
3231
2964
3232 If no name is given, it defaults to a file named 'log' in your
2965 If no name is given, it defaults to a file named 'log' in your
3233 IPYTHONDIR directory, in 'rotate' mode (see below).
2966 IPYTHONDIR directory, in 'rotate' mode (see below).
3234
2967
3235 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
2968 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
3236 history up to that point and then continues logging.
2969 history up to that point and then continues logging.
3237
2970
3238 %logstart takes a second optional parameter: logging mode. This can be
2971 %logstart takes a second optional parameter: logging mode. This can be
3239 one of (note that the modes are given unquoted):
2972 one of (note that the modes are given unquoted):
3240
2973
3241 * [over:] overwrite existing log_name.
2974 * [over:] overwrite existing log_name.
3242 * [backup:] rename (if exists) to log_name~ and start log_name.
2975 * [backup:] rename (if exists) to log_name~ and start log_name.
3243 * [append:] well, that says it.
2976 * [append:] well, that says it.
3244 * [rotate:] create rotating logs log_name.1~, log_name.2~, etc.
2977 * [rotate:] create rotating logs log_name.1~, log_name.2~, etc.
3245
2978
3246 The %logoff and %logon functions allow you to temporarily stop and
2979 The %logoff and %logon functions allow you to temporarily stop and
3247 resume logging to a file which had previously been started with
2980 resume logging to a file which had previously been started with
3248 %logstart. They will fail (with an explanation) if you try to use them
2981 %logstart. They will fail (with an explanation) if you try to use them
3249 before logging has been started.
2982 before logging has been started.
3250
2983
3251 System shell access
2984 System shell access
3252 -------------------
2985 -------------------
3253
2986
3254 Any input line beginning with a ! character is passed verbatim (minus
2987 Any input line beginning with a ! character is passed verbatim (minus
3255 the !, of course) to the underlying operating system. For example,
2988 the !, of course) to the underlying operating system. For example,
3256 typing !ls will run 'ls' in the current directory.
2989 typing !ls will run 'ls' in the current directory.
3257
2990
3258 Manual capture of command output
2991 Manual capture of command output
3259 --------------------------------
2992 --------------------------------
3260
2993
3261 If the input line begins with two exclamation marks, !!, the command is
2994 If the input line begins with two exclamation marks, !!, the command is
3262 executed but its output is captured and returned as a python list, split
2995 executed but its output is captured and returned as a python list, split
3263 on newlines. Any output sent by the subprocess to standard error is
2996 on newlines. Any output sent by the subprocess to standard error is
3264 printed separately, so that the resulting list only captures standard
2997 printed separately, so that the resulting list only captures standard
3265 output. The !! syntax is a shorthand for the %sx magic command.
2998 output. The !! syntax is a shorthand for the %sx magic command.
3266
2999
3267 Finally, the %sc magic (short for 'shell capture') is similar to %sx,
3000 Finally, the %sc magic (short for 'shell capture') is similar to %sx,
3268 but allowing more fine-grained control of the capture details, and
3001 but allowing more fine-grained control of the capture details, and
3269 storing the result directly into a named variable. The direct use of
3002 storing the result directly into a named variable. The direct use of
3270 %sc is now deprecated, and you should ise the ``var = !cmd`` syntax
3003 %sc is now deprecated, and you should ise the ``var = !cmd`` syntax
3271 instead.
3004 instead.
3272
3005
3273 IPython also allows you to expand the value of python variables when
3006 IPython also allows you to expand the value of python variables when
3274 making system calls. Any python variable or expression which you prepend
3007 making system calls. Any python variable or expression which you prepend
3275 with $ will get expanded before the system call is made::
3008 with $ will get expanded before the system call is made::
3276
3009
3277 In [1]: pyvar='Hello world'
3010 In [1]: pyvar='Hello world'
3278 In [2]: !echo "A python variable: $pyvar"
3011 In [2]: !echo "A python variable: $pyvar"
3279 A python variable: Hello world
3012 A python variable: Hello world
3280
3013
3281 If you want the shell to actually see a literal $, you need to type it
3014 If you want the shell to actually see a literal $, you need to type it
3282 twice::
3015 twice::
3283
3016
3284 In [3]: !echo "A system variable: $$HOME"
3017 In [3]: !echo "A system variable: $$HOME"
3285 A system variable: /home/fperez
3018 A system variable: /home/fperez
3286
3019
3287 You can pass arbitrary expressions, though you'll need to delimit them
3020 You can pass arbitrary expressions, though you'll need to delimit them
3288 with {} if there is ambiguity as to the extent of the expression::
3021 with {} if there is ambiguity as to the extent of the expression::
3289
3022
3290 In [5]: x=10
3023 In [5]: x=10
3291 In [6]: y=20
3024 In [6]: y=20
3292 In [13]: !echo $x+y
3025 In [13]: !echo $x+y
3293 10+y
3026 10+y
3294 In [7]: !echo ${x+y}
3027 In [7]: !echo ${x+y}
3295 30
3028 30
3296
3029
3297 Even object attributes can be expanded::
3030 Even object attributes can be expanded::
3298
3031
3299 In [12]: !echo $sys.argv
3032 In [12]: !echo $sys.argv
3300 [/home/fperez/usr/bin/ipython]
3033 [/home/fperez/usr/bin/ipython]
3301
3034
3302
3035
3303 System command aliases
3036 System command aliases
3304 ----------------------
3037 ----------------------
3305
3038
3306 The %alias magic function and the alias option in the ipythonrc
3039 The %alias magic function and the alias option in the ipythonrc
3307 configuration file allow you to define magic functions which are in fact
3040 configuration file allow you to define magic functions which are in fact
3308 system shell commands. These aliases can have parameters.
3041 system shell commands. These aliases can have parameters.
3309
3042
3310 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
3043 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
3311
3044
3312 Then, typing '%alias_name params' will execute the system command 'cmd
3045 Then, typing '%alias_name params' will execute the system command 'cmd
3313 params' (from your underlying operating system).
3046 params' (from your underlying operating system).
3314
3047
3315 You can also define aliases with parameters using %s specifiers (one per
3048 You can also define aliases with parameters using %s specifiers (one per
3316 parameter). The following example defines the %parts function as an
3049 parameter). The following example defines the %parts function as an
3317 alias to the command 'echo first %s second %s' where each %s will be
3050 alias to the command 'echo first %s second %s' where each %s will be
3318 replaced by a positional parameter to the call to %parts::
3051 replaced by a positional parameter to the call to %parts::
3319
3052
3320 In [1]: alias parts echo first %s second %s
3053 In [1]: alias parts echo first %s second %s
3321 In [2]: %parts A B
3054 In [2]: %parts A B
3322 first A second B
3055 first A second B
3323 In [3]: %parts A
3056 In [3]: %parts A
3324 Incorrect number of arguments: 2 expected.
3057 Incorrect number of arguments: 2 expected.
3325 parts is an alias to: 'echo first %s second %s'
3058 parts is an alias to: 'echo first %s second %s'
3326
3059
3327 If called with no parameters, %alias prints the table of currently
3060 If called with no parameters, %alias prints the table of currently
3328 defined aliases.
3061 defined aliases.
3329
3062
3330 The %rehash/rehashx magics allow you to load your entire $PATH as
3063 The %rehash/rehashx magics allow you to load your entire $PATH as
3331 ipython aliases. See their respective docstrings (or sec. 6.2
3064 ipython aliases. See their respective docstrings (or sec. 6.2
3332 <#sec:magic> for further details).
3065 <#sec:magic> for further details).
3333
3066
3334
3067
3335 .. _dreload:
3068 .. _dreload:
3336
3069
3337 Recursive reload
3070 Recursive reload
3338 ----------------
3071 ----------------
3339
3072
3340 The dreload function does a recursive reload of a module: changes made
3073 The dreload function does a recursive reload of a module: changes made
3341 to the module since you imported will actually be available without
3074 to the module since you imported will actually be available without
3342 having to exit.
3075 having to exit.
3343
3076
3344
3077
3345 Verbose and colored exception traceback printouts
3078 Verbose and colored exception traceback printouts
3346 -------------------------------------------------
3079 -------------------------------------------------
3347
3080
3348 IPython provides the option to see very detailed exception tracebacks,
3081 IPython provides the option to see very detailed exception tracebacks,
3349 which can be especially useful when debugging large programs. You can
3082 which can be especially useful when debugging large programs. You can
3350 run any Python file with the %run function to benefit from these
3083 run any Python file with the %run function to benefit from these
3351 detailed tracebacks. Furthermore, both normal and verbose tracebacks can
3084 detailed tracebacks. Furthermore, both normal and verbose tracebacks can
3352 be colored (if your terminal supports it) which makes them much easier
3085 be colored (if your terminal supports it) which makes them much easier
3353 to parse visually.
3086 to parse visually.
3354
3087
3355 See the magic xmode and colors functions for details (just type %magic).
3088 See the magic xmode and colors functions for details (just type %magic).
3356
3089
3357 These features are basically a terminal version of Ka-Ping Yee's cgitb
3090 These features are basically a terminal version of Ka-Ping Yee's cgitb
3358 module, now part of the standard Python library.
3091 module, now part of the standard Python library.
3359
3092
3360
3093
3361 .. _Input caching:
3094 .. _Input caching:
3362
3095
3363 Input caching system
3096 Input caching system
3364 --------------------
3097 --------------------
3365
3098
3366 IPython offers numbered prompts (In/Out) with input and output caching.
3099 IPython offers numbered prompts (In/Out) with input and output caching.
3367 All input is saved and can be retrieved as variables (besides the usual
3100 All input is saved and can be retrieved as variables (besides the usual
3368 arrow key recall).
3101 arrow key recall).
3369
3102
3370 The following GLOBAL variables always exist (so don't overwrite them!):
3103 The following GLOBAL variables always exist (so don't overwrite them!):
3371 _i: stores previous input. _ii: next previous. _iii: next-next previous.
3104 _i: stores previous input. _ii: next previous. _iii: next-next previous.
3372 _ih : a list of all input _ih[n] is the input from line n and this list
3105 _ih : a list of all input _ih[n] is the input from line n and this list
3373 is aliased to the global variable In. If you overwrite In with a
3106 is aliased to the global variable In. If you overwrite In with a
3374 variable of your own, you can remake the assignment to the internal list
3107 variable of your own, you can remake the assignment to the internal list
3375 with a simple 'In=_ih'.
3108 with a simple 'In=_ih'.
3376
3109
3377 Additionally, global variables named _i<n> are dynamically created (<n>
3110 Additionally, global variables named _i<n> are dynamically created (<n>
3378 being the prompt counter), such that
3111 being the prompt counter), such that
3379 _i<n> == _ih[<n>] == In[<n>].
3112 _i<n> == _ih[<n>] == In[<n>].
3380
3113
3381 For example, what you typed at prompt 14 is available as _i14, _ih[14]
3114 For example, what you typed at prompt 14 is available as _i14, _ih[14]
3382 and In[14].
3115 and In[14].
3383
3116
3384 This allows you to easily cut and paste multi line interactive prompts
3117 This allows you to easily cut and paste multi line interactive prompts
3385 by printing them out: they print like a clean string, without prompt
3118 by printing them out: they print like a clean string, without prompt
3386 characters. You can also manipulate them like regular variables (they
3119 characters. You can also manipulate them like regular variables (they
3387 are strings), modify or exec them (typing 'exec _i9' will re-execute the
3120 are strings), modify or exec them (typing 'exec _i9' will re-execute the
3388 contents of input prompt 9, 'exec In[9:14]+In[18]' will re-execute lines
3121 contents of input prompt 9, 'exec In[9:14]+In[18]' will re-execute lines
3389 9 through 13 and line 18).
3122 9 through 13 and line 18).
3390
3123
3391 You can also re-execute multiple lines of input easily by using the
3124 You can also re-execute multiple lines of input easily by using the
3392 magic %macro function (which automates the process and allows
3125 magic %macro function (which automates the process and allows
3393 re-execution without having to type 'exec' every time). The macro system
3126 re-execution without having to type 'exec' every time). The macro system
3394 also allows you to re-execute previous lines which include magic
3127 also allows you to re-execute previous lines which include magic
3395 function calls (which require special processing). Type %macro? or see
3128 function calls (which require special processing). Type %macro? or see
3396 sec. 6.2 <#sec:magic> for more details on the macro system.
3129 sec. 6.2 <#sec:magic> for more details on the macro system.
3397
3130
3398 A history function %hist allows you to see any part of your input
3131 A history function %hist allows you to see any part of your input
3399 history by printing a range of the _i variables.
3132 history by printing a range of the _i variables.
3400
3133
3401 .. _Output caching:
3134 .. _Output caching:
3402
3135
3403 Output caching system
3136 Output caching system
3404 ---------------------
3137 ---------------------
3405
3138
3406 For output that is returned from actions, a system similar to the input
3139 For output that is returned from actions, a system similar to the input
3407 cache exists but using _ instead of _i. Only actions that produce a
3140 cache exists but using _ instead of _i. Only actions that produce a
3408 result (NOT assignments, for example) are cached. If you are familiar
3141 result (NOT assignments, for example) are cached. If you are familiar
3409 with Mathematica, IPython's _ variables behave exactly like
3142 with Mathematica, IPython's _ variables behave exactly like
3410 Mathematica's % variables.
3143 Mathematica's % variables.
3411
3144
3412 The following GLOBAL variables always exist (so don't overwrite them!):
3145 The following GLOBAL variables always exist (so don't overwrite them!):
3413
3146
3414 * [_] (a single underscore) : stores previous output, like Python's
3147 * [_] (a single underscore) : stores previous output, like Python's
3415 default interpreter.
3148 default interpreter.
3416 * [__] (two underscores): next previous.
3149 * [__] (two underscores): next previous.
3417 * [___] (three underscores): next-next previous.
3150 * [___] (three underscores): next-next previous.
3418
3151
3419 Additionally, global variables named _<n> are dynamically created (<n>
3152 Additionally, global variables named _<n> are dynamically created (<n>
3420 being the prompt counter), such that the result of output <n> is always
3153 being the prompt counter), such that the result of output <n> is always
3421 available as _<n> (don't use the angle brackets, just the number, e.g.
3154 available as _<n> (don't use the angle brackets, just the number, e.g.
3422 _21).
3155 _21).
3423
3156
3424 These global variables are all stored in a global dictionary (not a
3157 These global variables are all stored in a global dictionary (not a
3425 list, since it only has entries for lines which returned a result)
3158 list, since it only has entries for lines which returned a result)
3426 available under the names _oh and Out (similar to _ih and In). So the
3159 available under the names _oh and Out (similar to _ih and In). So the
3427 output from line 12 can be obtained as _12, Out[12] or _oh[12]. If you
3160 output from line 12 can be obtained as _12, Out[12] or _oh[12]. If you
3428 accidentally overwrite the Out variable you can recover it by typing
3161 accidentally overwrite the Out variable you can recover it by typing
3429 'Out=_oh' at the prompt.
3162 'Out=_oh' at the prompt.
3430
3163
3431 This system obviously can potentially put heavy memory demands on your
3164 This system obviously can potentially put heavy memory demands on your
3432 system, since it prevents Python's garbage collector from removing any
3165 system, since it prevents Python's garbage collector from removing any
3433 previously computed results. You can control how many results are kept
3166 previously computed results. You can control how many results are kept
3434 in memory with the option (at the command line or in your ipythonrc
3167 in memory with the option (at the command line or in your ipythonrc
3435 file) cache_size. If you set it to 0, the whole system is completely
3168 file) cache_size. If you set it to 0, the whole system is completely
3436 disabled and the prompts revert to the classic '>>>' of normal Python.
3169 disabled and the prompts revert to the classic '>>>' of normal Python.
3437
3170
3438
3171
3439 Directory history
3172 Directory history
3440 -----------------
3173 -----------------
3441
3174
3442 Your history of visited directories is kept in the global list _dh, and
3175 Your history of visited directories is kept in the global list _dh, and
3443 the magic %cd command can be used to go to any entry in that list. The
3176 the magic %cd command can be used to go to any entry in that list. The
3444 %dhist command allows you to view this history. do ``cd -<TAB`` to
3177 %dhist command allows you to view this history. do ``cd -<TAB`` to
3445 conventiently view the directory history.
3178 conventiently view the directory history.
3446
3179
3447
3180
3448 Automatic parentheses and quotes
3181 Automatic parentheses and quotes
3449 --------------------------------
3182 --------------------------------
3450
3183
3451 These features were adapted from Nathan Gray's LazyPython. They are
3184 These features were adapted from Nathan Gray's LazyPython. They are
3452 meant to allow less typing for common situations.
3185 meant to allow less typing for common situations.
3453
3186
3454
3187
3455 Automatic parentheses
3188 Automatic parentheses
3456 ---------------------
3189 ---------------------
3457
3190
3458 Callable objects (i.e. functions, methods, etc) can be invoked like this
3191 Callable objects (i.e. functions, methods, etc) can be invoked like this
3459 (notice the commas between the arguments)::
3192 (notice the commas between the arguments)::
3460
3193
3461 >>> callable_ob arg1, arg2, arg3
3194 >>> callable_ob arg1, arg2, arg3
3462
3195
3463 and the input will be translated to this::
3196 and the input will be translated to this::
3464
3197
3465 -> callable_ob(arg1, arg2, arg3)
3198 -> callable_ob(arg1, arg2, arg3)
3466
3199
3467 You can force automatic parentheses by using '/' as the first character
3200 You can force automatic parentheses by using '/' as the first character
3468 of a line. For example::
3201 of a line. For example::
3469
3202
3470 >>> /globals # becomes 'globals()'
3203 >>> /globals # becomes 'globals()'
3471
3204
3472 Note that the '/' MUST be the first character on the line! This won't work::
3205 Note that the '/' MUST be the first character on the line! This won't work::
3473
3206
3474 >>> print /globals # syntax error
3207 >>> print /globals # syntax error
3475
3208
3476 In most cases the automatic algorithm should work, so you should rarely
3209 In most cases the automatic algorithm should work, so you should rarely
3477 need to explicitly invoke /. One notable exception is if you are trying
3210 need to explicitly invoke /. One notable exception is if you are trying
3478 to call a function with a list of tuples as arguments (the parenthesis
3211 to call a function with a list of tuples as arguments (the parenthesis
3479 will confuse IPython)::
3212 will confuse IPython)::
3480
3213
3481 In [1]: zip (1,2,3),(4,5,6) # won't work
3214 In [1]: zip (1,2,3),(4,5,6) # won't work
3482
3215
3483 but this will work::
3216 but this will work::
3484
3217
3485 In [2]: /zip (1,2,3),(4,5,6)
3218 In [2]: /zip (1,2,3),(4,5,6)
3486 ---> zip ((1,2,3),(4,5,6))
3219 ---> zip ((1,2,3),(4,5,6))
3487 Out[2]= [(1, 4), (2, 5), (3, 6)]
3220 Out[2]= [(1, 4), (2, 5), (3, 6)]
3488
3221
3489 IPython tells you that it has altered your command line by displaying
3222 IPython tells you that it has altered your command line by displaying
3490 the new command line preceded by ->. e.g.::
3223 the new command line preceded by ->. e.g.::
3491
3224
3492 In [18]: callable list
3225 In [18]: callable list
3493 ----> callable (list)
3226 ----> callable (list)
3494
3227
3495
3228
3496 Automatic quoting
3229 Automatic quoting
3497 -----------------
3230 -----------------
3498
3231
3499 You can force automatic quoting of a function's arguments by using ','
3232 You can force automatic quoting of a function's arguments by using ','
3500 or ';' as the first character of a line. For example::
3233 or ';' as the first character of a line. For example::
3501
3234
3502 >>> ,my_function /home/me # becomes my_function("/home/me")
3235 >>> ,my_function /home/me # becomes my_function("/home/me")
3503
3236
3504 If you use ';' instead, the whole argument is quoted as a single string
3237 If you use ';' instead, the whole argument is quoted as a single string
3505 (while ',' splits on whitespace)::
3238 (while ',' splits on whitespace)::
3506
3239
3507 >>> ,my_function a b c # becomes my_function("a","b","c")
3240 >>> ,my_function a b c # becomes my_function("a","b","c")
3508
3241
3509 >>> ;my_function a b c # becomes my_function("a b c")
3242 >>> ;my_function a b c # becomes my_function("a b c")
3510
3243
3511 Note that the ',' or ';' MUST be the first character on the line! This
3244 Note that the ',' or ';' MUST be the first character on the line! This
3512 won't work::
3245 won't work::
3513
3246
3514 >>> x = ,my_function /home/me # syntax error
3247 >>> x = ,my_function /home/me # syntax error
3515
3248
3516 .. customization:
3249 .. customization:
3517
3250
3518 Customization
3251 Customization
3519 =============
3252 =============
3520
3253
3521 There are 2 ways to configure IPython - the old way of using ipythonrc
3254 There are 2 ways to configure IPython - the old way of using ipythonrc
3522 files (an INI-file like format), and the new way that involves editing
3255 files (an INI-file like format), and the new way that involves editing
3523 your ipy_user_conf.py. Both configuration systems work at the same
3256 your ipy_user_conf.py. Both configuration systems work at the same
3524 time, so you can set your options in both, but if you are hesitating
3257 time, so you can set your options in both, but if you are hesitating
3525 about which alternative to choose, we recommend the ipy_user_conf.py
3258 about which alternative to choose, we recommend the ipy_user_conf.py
3526 approach, as it will give you more power and control in the long
3259 approach, as it will give you more power and control in the long
3527 run. However, there are few options such as pylab_import_all that can
3260 run. However, there are few options such as pylab_import_all that can
3528 only be specified in ipythonrc file or command line - the reason for
3261 only be specified in ipythonrc file or command line - the reason for
3529 this is that they are needed before IPython has been started up, and
3262 this is that they are needed before IPython has been started up, and
3530 the IPApi object used in ipy_user_conf.py is not yet available at that
3263 the IPApi object used in ipy_user_conf.py is not yet available at that
3531 time. A hybrid approach of specifying a few options in ipythonrc and
3264 time. A hybrid approach of specifying a few options in ipythonrc and
3532 doing the more advanced configuration in ipy_user_conf.py is also
3265 doing the more advanced configuration in ipy_user_conf.py is also
3533 possible.
3266 possible.
3534
3267
3535 The ipythonrc approach
3268 The ipythonrc approach
3536 ----------------------
3269 ----------------------
3537
3270
3538 As we've already mentioned, IPython reads a configuration file which can
3271 As we've already mentioned, IPython reads a configuration file which can
3539 be specified at the command line (-rcfile) or which by default is
3272 be specified at the command line (-rcfile) or which by default is
3540 assumed to be called ipythonrc. Such a file is looked for in the current
3273 assumed to be called ipythonrc. Such a file is looked for in the current
3541 directory where IPython is started and then in your IPYTHONDIR, which
3274 directory where IPython is started and then in your IPYTHONDIR, which
3542 allows you to have local configuration files for specific projects. In
3275 allows you to have local configuration files for specific projects. In
3543 this section we will call these types of configuration files simply
3276 this section we will call these types of configuration files simply
3544 rcfiles (short for resource configuration file).
3277 rcfiles (short for resource configuration file).
3545
3278
3546 The syntax of an rcfile is one of key-value pairs separated by
3279 The syntax of an rcfile is one of key-value pairs separated by
3547 whitespace, one per line. Lines beginning with a # are ignored as
3280 whitespace, one per line. Lines beginning with a # are ignored as
3548 comments, but comments can not be put on lines with data (the parser is
3281 comments, but comments can not be put on lines with data (the parser is
3549 fairly primitive). Note that these are not python files, and this is
3282 fairly primitive). Note that these are not python files, and this is
3550 deliberate, because it allows us to do some things which would be quite
3283 deliberate, because it allows us to do some things which would be quite
3551 tricky to implement if they were normal python files.
3284 tricky to implement if they were normal python files.
3552
3285
3553 First, an rcfile can contain permanent default values for almost all
3286 First, an rcfile can contain permanent default values for almost all
3554 command line options (except things like -help or -Version). Sec
3287 command line options (except things like -help or -Version). Sec
3555 `command line options`_ contains a description of all command-line
3288 `command line options`_ contains a description of all command-line
3556 options. However, values you explicitly specify at the command line
3289 options. However, values you explicitly specify at the command line
3557 override the values defined in the rcfile.
3290 override the values defined in the rcfile.
3558
3291
3559 Besides command line option values, the rcfile can specify values for
3292 Besides command line option values, the rcfile can specify values for
3560 certain extra special options which are not available at the command
3293 certain extra special options which are not available at the command
3561 line. These options are briefly described below.
3294 line. These options are briefly described below.
3562
3295
3563 Each of these options may appear as many times as you need it in the file.
3296 Each of these options may appear as many times as you need it in the file.
3564
3297
3565 * include <file1> <file2> ...: you can name other rcfiles you want
3298 * include <file1> <file2> ...: you can name other rcfiles you want
3566 to recursively load up to 15 levels (don't use the <> brackets in
3299 to recursively load up to 15 levels (don't use the <> brackets in
3567 your names!). This feature allows you to define a 'base' rcfile
3300 your names!). This feature allows you to define a 'base' rcfile
3568 with general options and special-purpose files which can be loaded
3301 with general options and special-purpose files which can be loaded
3569 only when needed with particular configuration options. To make
3302 only when needed with particular configuration options. To make
3570 this more convenient, IPython accepts the -profile <name> option
3303 this more convenient, IPython accepts the -profile <name> option
3571 (abbreviates to -p <name>) which tells it to look for an rcfile
3304 (abbreviates to -p <name>) which tells it to look for an rcfile
3572 named ipythonrc-<name>.
3305 named ipythonrc-<name>.
3573 * import_mod <mod1> <mod2> ...: import modules with 'import
3306 * import_mod <mod1> <mod2> ...: import modules with 'import
3574 <mod1>,<mod2>,...'
3307 <mod1>,<mod2>,...'
3575 * import_some <mod> <f1> <f2> ...: import functions with 'from
3308 * import_some <mod> <f1> <f2> ...: import functions with 'from
3576 <mod> import <f1>,<f2>,...'
3309 <mod> import <f1>,<f2>,...'
3577 * import_all <mod1> <mod2> ...: for each module listed import
3310 * import_all <mod1> <mod2> ...: for each module listed import
3578 functions with ``from <mod> import *``.
3311 functions with ``from <mod> import *``.
3579 * execute <python code>: give any single-line python code to be
3312 * execute <python code>: give any single-line python code to be
3580 executed.
3313 executed.
3581 * execfile <filename>: execute the python file given with an
3314 * execfile <filename>: execute the python file given with an
3582 'execfile(filename)' command. Username expansion is performed on
3315 'execfile(filename)' command. Username expansion is performed on
3583 the given names. So if you need any amount of extra fancy
3316 the given names. So if you need any amount of extra fancy
3584 customization that won't fit in any of the above 'canned' options,
3317 customization that won't fit in any of the above 'canned' options,
3585 you can just put it in a separate python file and execute it.
3318 you can just put it in a separate python file and execute it.
3586 * alias <alias_def>: this is equivalent to calling
3319 * alias <alias_def>: this is equivalent to calling
3587 '%alias <alias_def>' at the IPython command line. This way, from
3320 '%alias <alias_def>' at the IPython command line. This way, from
3588 within IPython you can do common system tasks without having to
3321 within IPython you can do common system tasks without having to
3589 exit it or use the ! escape. IPython isn't meant to be a shell
3322 exit it or use the ! escape. IPython isn't meant to be a shell
3590 replacement, but it is often very useful to be able to do things
3323 replacement, but it is often very useful to be able to do things
3591 with files while testing code. This gives you the flexibility to
3324 with files while testing code. This gives you the flexibility to
3592 have within IPython any aliases you may be used to under your
3325 have within IPython any aliases you may be used to under your
3593 normal system shell.
3326 normal system shell.
3594
3327
3595
3328
3596 .. _ipythonrc:
3329 .. _ipythonrc:
3597
3330
3598 Sample ipythonrc file
3331 Sample ipythonrc file
3599 ---------------------
3332 ---------------------
3600
3333
3601 The default rcfile, called ipythonrc and supplied in your IPYTHONDIR
3334 The default rcfile, called ipythonrc and supplied in your IPYTHONDIR
3602 directory contains lots of comments on all of these options. We
3335 directory contains lots of comments on all of these options. We
3603 reproduce it here for reference::
3336 reproduce it here for reference::
3604
3337
3605
3338
3606 # -*- Mode: Shell-Script -*- Not really, but shows comments correctly
3339 # -*- Mode: Shell-Script -*- Not really, but shows comments correctly
3607 # $Id: ipythonrc 2156 2007-03-19 02:32:19Z fperez $
3340 # $Id: ipythonrc 2156 2007-03-19 02:32:19Z fperez $
3608
3341
3609 #***************************************************************************
3342 #***************************************************************************
3610 #
3343 #
3611 # Configuration file for IPython -- ipythonrc format
3344 # Configuration file for IPython -- ipythonrc format
3612 #
3345 #
3613 # ===========================================================
3346 # ===========================================================
3614 # Deprecation note: you should look into modifying ipy_user_conf.py (located
3347 # Deprecation note: you should look into modifying ipy_user_conf.py (located
3615 # in ~/.ipython or ~/_ipython, depending on your platform) instead, it's a
3348 # in ~/.ipython or ~/_ipython, depending on your platform) instead, it's a
3616 # more flexible and robust (and better supported!) configuration
3349 # more flexible and robust (and better supported!) configuration
3617 # method.
3350 # method.
3618 # ===========================================================
3351 # ===========================================================
3619 #
3352 #
3620 # The format of this file is simply one of 'key value' lines.
3353 # The format of this file is simply one of 'key value' lines.
3621 # Lines containing only whitespace at the beginning and then a # are ignored
3354 # Lines containing only whitespace at the beginning and then a # are ignored
3622 # as comments. But comments can NOT be put on lines with data.
3355 # as comments. But comments can NOT be put on lines with data.
3623
3356
3624 # The meaning and use of each key are explained below.
3357 # The meaning and use of each key are explained below.
3625
3358
3626 #---------------------------------------------------------------------------
3359 #---------------------------------------------------------------------------
3627 # Section: included files
3360 # Section: included files
3628
3361
3629 # Put one or more *config* files (with the syntax of this file) you want to
3362 # Put one or more *config* files (with the syntax of this file) you want to
3630 # include. For keys with a unique value the outermost file has precedence. For
3363 # include. For keys with a unique value the outermost file has precedence. For
3631 # keys with multiple values, they all get assembled into a list which then
3364 # keys with multiple values, they all get assembled into a list which then
3632 # gets loaded by IPython.
3365 # gets loaded by IPython.
3633
3366
3634 # In this file, all lists of things should simply be space-separated.
3367 # In this file, all lists of things should simply be space-separated.
3635
3368
3636 # This allows you to build hierarchies of files which recursively load
3369 # This allows you to build hierarchies of files which recursively load
3637 # lower-level services. If this is your main ~/.ipython/ipythonrc file, you
3370 # lower-level services. If this is your main ~/.ipython/ipythonrc file, you
3638 # should only keep here basic things you always want available. Then you can
3371 # should only keep here basic things you always want available. Then you can
3639 # include it in every other special-purpose config file you create.
3372 # include it in every other special-purpose config file you create.
3640 include
3373 include
3641
3374
3642 #---------------------------------------------------------------------------
3375 #---------------------------------------------------------------------------
3643 # Section: startup setup
3376 # Section: startup setup
3644
3377
3645 # These are mostly things which parallel a command line option of the same
3378 # These are mostly things which parallel a command line option of the same
3646 # name.
3379 # name.
3647
3380
3648 # Keys in this section should only appear once. If any key from this section
3381 # Keys in this section should only appear once. If any key from this section
3649 # is encountered more than once, the last value remains, all earlier ones get
3382 # is encountered more than once, the last value remains, all earlier ones get
3650 # discarded.
3383 # discarded.
3651
3384
3652
3385
3653 # Automatic calling of callable objects. If set to 1 or 2, callable objects
3386 # Automatic calling of callable objects. If set to 1 or 2, callable objects
3654 # are automatically called when invoked at the command line, even if you don't
3387 # are automatically called when invoked at the command line, even if you don't
3655 # type parentheses. IPython adds the parentheses for you. For example:
3388 # type parentheses. IPython adds the parentheses for you. For example:
3656
3389
3657 #In [1]: str 45
3390 #In [1]: str 45
3658 #------> str(45)
3391 #------> str(45)
3659 #Out[1]: '45'
3392 #Out[1]: '45'
3660
3393
3661 # IPython reprints your line with '---->' indicating that it added
3394 # IPython reprints your line with '---->' indicating that it added
3662 # parentheses. While this option is very convenient for interactive use, it
3395 # parentheses. While this option is very convenient for interactive use, it
3663 # may occasionally cause problems with objects which have side-effects if
3396 # may occasionally cause problems with objects which have side-effects if
3664 # called unexpectedly.
3397 # called unexpectedly.
3665
3398
3666 # The valid values for autocall are:
3399 # The valid values for autocall are:
3667
3400
3668 # autocall 0 -> disabled (you can toggle it at runtime with the %autocall magic)
3401 # autocall 0 -> disabled (you can toggle it at runtime with the %autocall magic)
3669
3402
3670 # autocall 1 -> active, but do not apply if there are no arguments on the line.
3403 # autocall 1 -> active, but do not apply if there are no arguments on the line.
3671
3404
3672 # In this mode, you get:
3405 # In this mode, you get:
3673
3406
3674 #In [1]: callable
3407 #In [1]: callable
3675 #Out[1]: <built-in function callable>
3408 #Out[1]: <built-in function callable>
3676
3409
3677 #In [2]: callable 'hello'
3410 #In [2]: callable 'hello'
3678 #------> callable('hello')
3411 #------> callable('hello')
3679 #Out[2]: False
3412 #Out[2]: False
3680
3413
3681 # 2 -> Active always. Even if no arguments are present, the callable object
3414 # 2 -> Active always. Even if no arguments are present, the callable object
3682 # is called:
3415 # is called:
3683
3416
3684 #In [4]: callable
3417 #In [4]: callable
3685 #------> callable()
3418 #------> callable()
3686
3419
3687 # Note that even with autocall off, you can still use '/' at the start of a
3420 # Note that even with autocall off, you can still use '/' at the start of a
3688 # line to treat the first argument on the command line as a function and add
3421 # line to treat the first argument on the command line as a function and add
3689 # parentheses to it:
3422 # parentheses to it:
3690
3423
3691 #In [8]: /str 43
3424 #In [8]: /str 43
3692 #------> str(43)
3425 #------> str(43)
3693 #Out[8]: '43'
3426 #Out[8]: '43'
3694
3427
3695 autocall 1
3428 autocall 1
3696
3429
3697 # Auto-edit syntax errors. When you use the %edit magic in ipython to edit
3430 # Auto-edit syntax errors. When you use the %edit magic in ipython to edit
3698 # source code (see the 'editor' variable below), it is possible that you save
3431 # source code (see the 'editor' variable below), it is possible that you save
3699 # a file with syntax errors in it. If this variable is true, IPython will ask
3432 # a file with syntax errors in it. If this variable is true, IPython will ask
3700 # you whether to re-open the editor immediately to correct such an error.
3433 # you whether to re-open the editor immediately to correct such an error.
3701
3434
3702 autoedit_syntax 0
3435 autoedit_syntax 0
3703
3436
3704 # Auto-indent. IPython can recognize lines ending in ':' and indent the next
3437 # Auto-indent. IPython can recognize lines ending in ':' and indent the next
3705 # line, while also un-indenting automatically after 'raise' or 'return'.
3438 # line, while also un-indenting automatically after 'raise' or 'return'.
3706
3439
3707 # This feature uses the readline library, so it will honor your ~/.inputrc
3440 # This feature uses the readline library, so it will honor your ~/.inputrc
3708 # configuration (or whatever file your INPUTRC variable points to). Adding
3441 # configuration (or whatever file your INPUTRC variable points to). Adding
3709 # the following lines to your .inputrc file can make indent/unindenting more
3442 # the following lines to your .inputrc file can make indent/unindenting more
3710 # convenient (M-i indents, M-u unindents):
3443 # convenient (M-i indents, M-u unindents):
3711
3444
3712 # $if Python
3445 # $if Python
3713 # "\M-i": " "
3446 # "\M-i": " "
3714 # "\M-u": "\d\d\d\d"
3447 # "\M-u": "\d\d\d\d"
3715 # $endif
3448 # $endif
3716
3449
3717 # The feature is potentially a bit dangerous, because it can cause problems
3450 # The feature is potentially a bit dangerous, because it can cause problems
3718 # with pasting of indented code (the pasted code gets re-indented on each
3451 # with pasting of indented code (the pasted code gets re-indented on each
3719 # line). But it's a huge time-saver when working interactively. The magic
3452 # line). But it's a huge time-saver when working interactively. The magic
3720 # function %autoindent allows you to toggle it on/off at runtime.
3453 # function %autoindent allows you to toggle it on/off at runtime.
3721
3454
3722 autoindent 1
3455 autoindent 1
3723
3456
3724 # Auto-magic. This gives you access to all the magic functions without having
3457 # Auto-magic. This gives you access to all the magic functions without having
3725 # to prepend them with an % sign. If you define a variable with the same name
3458 # to prepend them with an % sign. If you define a variable with the same name
3726 # as a magic function (say who=1), you will need to access the magic function
3459 # as a magic function (say who=1), you will need to access the magic function
3727 # with % (%who in this example). However, if later you delete your variable
3460 # with % (%who in this example). However, if later you delete your variable
3728 # (del who), you'll recover the automagic calling form.
3461 # (del who), you'll recover the automagic calling form.
3729
3462
3730 # Considering that many magic functions provide a lot of shell-like
3463 # Considering that many magic functions provide a lot of shell-like
3731 # functionality, automagic gives you something close to a full Python+system
3464 # functionality, automagic gives you something close to a full Python+system
3732 # shell environment (and you can extend it further if you want).
3465 # shell environment (and you can extend it further if you want).
3733
3466
3734 automagic 1
3467 automagic 1
3735
3468
3736 # Size of the output cache. After this many entries are stored, the cache will
3469 # Size of the output cache. After this many entries are stored, the cache will
3737 # get flushed. Depending on the size of your intermediate calculations, you
3470 # get flushed. Depending on the size of your intermediate calculations, you
3738 # may have memory problems if you make it too big, since keeping things in the
3471 # may have memory problems if you make it too big, since keeping things in the
3739 # cache prevents Python from reclaiming the memory for old results. Experiment
3472 # cache prevents Python from reclaiming the memory for old results. Experiment
3740 # with a value that works well for you.
3473 # with a value that works well for you.
3741
3474
3742 # If you choose cache_size 0 IPython will revert to python's regular >>>
3475 # If you choose cache_size 0 IPython will revert to python's regular >>>
3743 # unnumbered prompt. You will still have _, __ and ___ for your last three
3476 # unnumbered prompt. You will still have _, __ and ___ for your last three
3744 # results, but that will be it. No dynamic _1, _2, etc. will be created. If
3477 # results, but that will be it. No dynamic _1, _2, etc. will be created. If
3745 # you are running on a slow machine or with very limited memory, this may
3478 # you are running on a slow machine or with very limited memory, this may
3746 # help.
3479 # help.
3747
3480
3748 cache_size 1000
3481 cache_size 1000
3749
3482
3750 # Classic mode: Setting 'classic 1' you lose many of IPython niceties,
3483 # Classic mode: Setting 'classic 1' you lose many of IPython niceties,
3751 # but that's your choice! Classic 1 -> same as IPython -classic.
3484 # but that's your choice! Classic 1 -> same as IPython -classic.
3752 # Note that this is _not_ the normal python interpreter, it's simply
3485 # Note that this is _not_ the normal python interpreter, it's simply
3753 # IPython emulating most of the classic interpreter's behavior.
3486 # IPython emulating most of the classic interpreter's behavior.
3754 classic 0
3487 classic 0
3755
3488
3756 # colors - Coloring option for prompts and traceback printouts.
3489 # colors - Coloring option for prompts and traceback printouts.
3757
3490
3758 # Currently available schemes: NoColor, Linux, LightBG.
3491 # Currently available schemes: NoColor, Linux, LightBG.
3759
3492
3760 # This option allows coloring the prompts and traceback printouts. This
3493 # This option allows coloring the prompts and traceback printouts. This
3761 # requires a terminal which can properly handle color escape sequences. If you
3494 # requires a terminal which can properly handle color escape sequences. If you
3762 # are having problems with this, use the NoColor scheme (uses no color escapes
3495 # are having problems with this, use the NoColor scheme (uses no color escapes
3763 # at all).
3496 # at all).
3764
3497
3765 # The Linux option works well in linux console type environments: dark
3498 # The Linux option works well in linux console type environments: dark
3766 # background with light fonts.
3499 # background with light fonts.
3767
3500
3768 # LightBG is similar to Linux but swaps dark/light colors to be more readable
3501 # LightBG is similar to Linux but swaps dark/light colors to be more readable
3769 # in light background terminals.
3502 # in light background terminals.
3770
3503
3771 # keep uncommented only the one you want:
3504 # keep uncommented only the one you want:
3772 colors Linux
3505 colors Linux
3773 #colors LightBG
3506 #colors LightBG
3774 #colors NoColor
3507 #colors NoColor
3775
3508
3776 ########################
3509 ########################
3777 # Note to Windows users
3510 # Note to Windows users
3778 #
3511 #
3779 # Color and readline support is avaialble to Windows users via Gary Bishop's
3512 # Color and readline support is avaialble to Windows users via Gary Bishop's
3780 # readline library. You can find Gary's tools at
3513 # readline library. You can find Gary's tools at
3781 # http://sourceforge.net/projects/uncpythontools.
3514 # http://sourceforge.net/projects/uncpythontools.
3782 # Note that his readline module requires in turn the ctypes library, available
3515 # Note that his readline module requires in turn the ctypes library, available
3783 # at http://starship.python.net/crew/theller/ctypes.
3516 # at http://starship.python.net/crew/theller/ctypes.
3784 ########################
3517 ########################
3785
3518
3786 # color_info: IPython can display information about objects via a set of
3519 # color_info: IPython can display information about objects via a set of
3787 # functions, and optionally can use colors for this, syntax highlighting
3520 # functions, and optionally can use colors for this, syntax highlighting
3788 # source code and various other elements. This information is passed through a
3521 # source code and various other elements. This information is passed through a
3789 # pager (it defaults to 'less' if $PAGER is not set).
3522 # pager (it defaults to 'less' if $PAGER is not set).
3790
3523
3791 # If your pager has problems, try to setting it to properly handle escapes
3524 # If your pager has problems, try to setting it to properly handle escapes
3792 # (see the less manpage for detail), or disable this option. The magic
3525 # (see the less manpage for detail), or disable this option. The magic
3793 # function %color_info allows you to toggle this interactively for testing.
3526 # function %color_info allows you to toggle this interactively for testing.
3794
3527
3795 color_info 1
3528 color_info 1
3796
3529
3797 # confirm_exit: set to 1 if you want IPython to confirm when you try to exit
3530 # confirm_exit: set to 1 if you want IPython to confirm when you try to exit
3798 # with an EOF (Control-d in Unix, Control-Z/Enter in Windows). Note that using
3531 # with an EOF (Control-d in Unix, Control-Z/Enter in Windows). Note that using
3799 # the magic functions %Exit or %Quit you can force a direct exit, bypassing
3532 # the magic functions %Exit or %Quit you can force a direct exit, bypassing
3800 # any confirmation.
3533 # any confirmation.
3801
3534
3802 confirm_exit 1
3535 confirm_exit 1
3803
3536
3804 # Use deep_reload() as a substitute for reload() by default. deep_reload() is
3537 # Use deep_reload() as a substitute for reload() by default. deep_reload() is
3805 # still available as dreload() and appears as a builtin.
3538 # still available as dreload() and appears as a builtin.
3806
3539
3807 deep_reload 0
3540 deep_reload 0
3808
3541
3809 # Which editor to use with the %edit command. If you leave this at 0, IPython
3542 # Which editor to use with the %edit command. If you leave this at 0, IPython
3810 # will honor your EDITOR environment variable. Since this editor is invoked on
3543 # will honor your EDITOR environment variable. Since this editor is invoked on
3811 # the fly by ipython and is meant for editing small code snippets, you may
3544 # the fly by ipython and is meant for editing small code snippets, you may
3812 # want to use a small, lightweight editor here.
3545 # want to use a small, lightweight editor here.
3813
3546
3814 # For Emacs users, setting up your Emacs server properly as described in the
3547 # For Emacs users, setting up your Emacs server properly as described in the
3815 # manual is a good idea. An alternative is to use jed, a very light editor
3548 # manual is a good idea. An alternative is to use jed, a very light editor
3816 # with much of the feel of Emacs (though not as powerful for heavy-duty work).
3549 # with much of the feel of Emacs (though not as powerful for heavy-duty work).
3817
3550
3818 editor 0
3551 editor 0
3819
3552
3820 # log 1 -> same as ipython -log. This automatically logs to ./ipython.log
3553 # log 1 -> same as ipython -log. This automatically logs to ./ipython.log
3821 log 0
3554 log 0
3822
3555
3823 # Same as ipython -Logfile YourLogfileName.
3556 # Same as ipython -Logfile YourLogfileName.
3824 # Don't use with log 1 (use one or the other)
3557 # Don't use with log 1 (use one or the other)
3825 logfile ''
3558 logfile ''
3826
3559
3827 # banner 0 -> same as ipython -nobanner
3560 # banner 0 -> same as ipython -nobanner
3828 banner 1
3561 banner 1
3829
3562
3830 # messages 0 -> same as ipython -nomessages
3563 # messages 0 -> same as ipython -nomessages
3831 messages 1
3564 messages 1
3832
3565
3833 # Automatically call the pdb debugger after every uncaught exception. If you
3566 # Automatically call the pdb debugger after every uncaught exception. If you
3834 # are used to debugging using pdb, this puts you automatically inside of it
3567 # are used to debugging using pdb, this puts you automatically inside of it
3835 # after any call (either in IPython or in code called by it) which triggers an
3568 # after any call (either in IPython or in code called by it) which triggers an
3836 # exception which goes uncaught.
3569 # exception which goes uncaught.
3837 pdb 0
3570 pdb 0
3838
3571
3839 # Enable the pprint module for printing. pprint tends to give a more readable
3572 # Enable the pprint module for printing. pprint tends to give a more readable
3840 # display (than print) for complex nested data structures.
3573 # display (than print) for complex nested data structures.
3841 pprint 1
3574 pprint 1
3842
3575
3843 # Prompt strings
3576 # Prompt strings
3844
3577
3845 # Most bash-like escapes can be used to customize IPython's prompts, as well as
3578 # Most bash-like escapes can be used to customize IPython's prompts, as well as
3846 # a few additional ones which are IPython-specific. All valid prompt escapes
3579 # a few additional ones which are IPython-specific. All valid prompt escapes
3847 # are described in detail in the Customization section of the IPython HTML/PDF
3580 # are described in detail in the Customization section of the IPython HTML/PDF
3848 # manual.
3581 # manual.
3849
3582
3850 # Use \# to represent the current prompt number, and quote them to protect
3583 # Use \# to represent the current prompt number, and quote them to protect
3851 # spaces.
3584 # spaces.
3852 prompt_in1 'In [\#]: '
3585 prompt_in1 'In [\#]: '
3853
3586
3854 # \D is replaced by as many dots as there are digits in the
3587 # \D is replaced by as many dots as there are digits in the
3855 # current value of \#.
3588 # current value of \#.
3856 prompt_in2 ' .\D.: '
3589 prompt_in2 ' .\D.: '
3857
3590
3858 prompt_out 'Out[\#]: '
3591 prompt_out 'Out[\#]: '
3859
3592
3860 # Select whether to left-pad the output prompts to match the length of the
3593 # Select whether to left-pad the output prompts to match the length of the
3861 # input ones. This allows you for example to use a simple '>' as an output
3594 # input ones. This allows you for example to use a simple '>' as an output
3862 # prompt, and yet have the output line up with the input. If set to false,
3595 # prompt, and yet have the output line up with the input. If set to false,
3863 # the output prompts will be unpadded (flush left).
3596 # the output prompts will be unpadded (flush left).
3864 prompts_pad_left 1
3597 prompts_pad_left 1
3865
3598
3866 # Pylab support: when ipython is started with the -pylab switch, by default it
3599 # Pylab support: when ipython is started with the -pylab switch, by default it
3867 # executes 'from matplotlib.pylab import *'. Set this variable to false if you
3600 # executes 'from matplotlib.pylab import *'. Set this variable to false if you
3868 # want to disable this behavior.
3601 # want to disable this behavior.
3869
3602
3870 # For details on pylab, see the matplotlib website:
3603 # For details on pylab, see the matplotlib website:
3871 # http://matplotlib.sf.net
3604 # http://matplotlib.sf.net
3872 pylab_import_all 1
3605 pylab_import_all 1
3873
3606
3874
3607
3875 # quick 1 -> same as ipython -quick
3608 # quick 1 -> same as ipython -quick
3876 quick 0
3609 quick 0
3877
3610
3878 # Use the readline library (1) or not (0). Most users will want this on, but
3611 # Use the readline library (1) or not (0). Most users will want this on, but
3879 # if you experience strange problems with line management (mainly when using
3612 # if you experience strange problems with line management (mainly when using
3880 # IPython inside Emacs buffers) you may try disabling it. Not having it on
3613 # IPython inside Emacs buffers) you may try disabling it. Not having it on
3881 # prevents you from getting command history with the arrow keys, searching and
3614 # prevents you from getting command history with the arrow keys, searching and
3882 # name completion using TAB.
3615 # name completion using TAB.
3883
3616
3884 readline 1
3617 readline 1
3885
3618
3886 # Screen Length: number of lines of your screen. This is used to control
3619 # Screen Length: number of lines of your screen. This is used to control
3887 # printing of very long strings. Strings longer than this number of lines will
3620 # printing of very long strings. Strings longer than this number of lines will
3888 # be paged with the less command instead of directly printed.
3621 # be paged with the less command instead of directly printed.
3889
3622
3890 # The default value for this is 0, which means IPython will auto-detect your
3623 # The default value for this is 0, which means IPython will auto-detect your
3891 # screen size every time it needs to print. If for some reason this isn't
3624 # screen size every time it needs to print. If for some reason this isn't
3892 # working well (it needs curses support), specify it yourself. Otherwise don't
3625 # working well (it needs curses support), specify it yourself. Otherwise don't
3893 # change the default.
3626 # change the default.
3894
3627
3895 screen_length 0
3628 screen_length 0
3896
3629
3897 # Prompt separators for input and output.
3630 # Prompt separators for input and output.
3898 # Use \n for newline explicitly, without quotes.
3631 # Use \n for newline explicitly, without quotes.
3899 # Use 0 (like at the cmd line) to turn off a given separator.
3632 # Use 0 (like at the cmd line) to turn off a given separator.
3900
3633
3901 # The structure of prompt printing is:
3634 # The structure of prompt printing is:
3902 # (SeparateIn)Input....
3635 # (SeparateIn)Input....
3903 # (SeparateOut)Output...
3636 # (SeparateOut)Output...
3904 # (SeparateOut2), # that is, no newline is printed after Out2
3637 # (SeparateOut2), # that is, no newline is printed after Out2
3905 # By choosing these you can organize your output any way you want.
3638 # By choosing these you can organize your output any way you want.
3906
3639
3907 separate_in \n
3640 separate_in \n
3908 separate_out 0
3641 separate_out 0
3909 separate_out2 0
3642 separate_out2 0
3910
3643
3911 # 'nosep 1' is a shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'.
3644 # 'nosep 1' is a shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'.
3912 # Simply removes all input/output separators, overriding the choices above.
3645 # Simply removes all input/output separators, overriding the choices above.
3913 nosep 0
3646 nosep 0
3914
3647
3915 # Wildcard searches - IPython has a system for searching names using
3648 # Wildcard searches - IPython has a system for searching names using
3916 # shell-like wildcards; type %psearch? for details. This variables sets
3649 # shell-like wildcards; type %psearch? for details. This variables sets
3917 # whether by default such searches should be case sensitive or not. You can
3650 # whether by default such searches should be case sensitive or not. You can
3918 # always override the default at the system command line or the IPython
3651 # always override the default at the system command line or the IPython
3919 # prompt.
3652 # prompt.
3920
3653
3921 wildcards_case_sensitive 1
3654 wildcards_case_sensitive 1
3922
3655
3923 # Object information: at what level of detail to display the string form of an
3656 # Object information: at what level of detail to display the string form of an
3924 # object. If set to 0, ipython will compute the string form of any object X,
3657 # object. If set to 0, ipython will compute the string form of any object X,
3925 # by calling str(X), when X? is typed. If set to 1, str(X) will only be
3658 # by calling str(X), when X? is typed. If set to 1, str(X) will only be
3926 # computed when X?? is given, and if set to 2 or higher, it will never be
3659 # computed when X?? is given, and if set to 2 or higher, it will never be
3927 # computed (there is no X??? level of detail). This is mostly of use to
3660 # computed (there is no X??? level of detail). This is mostly of use to
3928 # people who frequently manipulate objects whose string representation is
3661 # people who frequently manipulate objects whose string representation is
3929 # extremely expensive to compute.
3662 # extremely expensive to compute.
3930
3663
3931 object_info_string_level 0
3664 object_info_string_level 0
3932
3665
3933 # xmode - Exception reporting mode.
3666 # xmode - Exception reporting mode.
3934
3667
3935 # Valid modes: Plain, Context and Verbose.
3668 # Valid modes: Plain, Context and Verbose.
3936
3669
3937 # Plain: similar to python's normal traceback printing.
3670 # Plain: similar to python's normal traceback printing.
3938
3671
3939 # Context: prints 5 lines of context source code around each line in the
3672 # Context: prints 5 lines of context source code around each line in the
3940 # traceback.
3673 # traceback.
3941
3674
3942 # Verbose: similar to Context, but additionally prints the variables currently
3675 # Verbose: similar to Context, but additionally prints the variables currently
3943 # visible where the exception happened (shortening their strings if too
3676 # visible where the exception happened (shortening their strings if too
3944 # long). This can potentially be very slow, if you happen to have a huge data
3677 # long). This can potentially be very slow, if you happen to have a huge data
3945 # structure whose string representation is complex to compute. Your computer
3678 # structure whose string representation is complex to compute. Your computer
3946 # may appear to freeze for a while with cpu usage at 100%. If this occurs, you
3679 # may appear to freeze for a while with cpu usage at 100%. If this occurs, you
3947 # can cancel the traceback with Ctrl-C (maybe hitting it more than once).
3680 # can cancel the traceback with Ctrl-C (maybe hitting it more than once).
3948
3681
3949 #xmode Plain
3682 #xmode Plain
3950 xmode Context
3683 xmode Context
3951 #xmode Verbose
3684 #xmode Verbose
3952
3685
3953 # multi_line_specials: if true, allow magics, aliases and shell escapes (via
3686 # multi_line_specials: if true, allow magics, aliases and shell escapes (via
3954 # !cmd) to be used in multi-line input (like for loops). For example, if you
3687 # !cmd) to be used in multi-line input (like for loops). For example, if you
3955 # have this active, the following is valid in IPython:
3688 # have this active, the following is valid in IPython:
3956 #
3689 #
3957 #In [17]: for i in range(3):
3690 #In [17]: for i in range(3):
3958 # ....: mkdir $i
3691 # ....: mkdir $i
3959 # ....: !touch $i/hello
3692 # ....: !touch $i/hello
3960 # ....: ls -l $i
3693 # ....: ls -l $i
3961
3694
3962 multi_line_specials 1
3695 multi_line_specials 1
3963
3696
3964
3697
3965 # System calls: When IPython makes system calls (e.g. via special syntax like
3698 # System calls: When IPython makes system calls (e.g. via special syntax like
3966 # !cmd or !!cmd, or magics like %sc or %sx), it can print the command it is
3699 # !cmd or !!cmd, or magics like %sc or %sx), it can print the command it is
3967 # executing to standard output, prefixed by a header string.
3700 # executing to standard output, prefixed by a header string.
3968
3701
3969 system_header "IPython system call: "
3702 system_header "IPython system call: "
3970
3703
3971 system_verbose 1
3704 system_verbose 1
3972
3705
3973 # wxversion: request a specific wxPython version (used for -wthread)
3706 # wxversion: request a specific wxPython version (used for -wthread)
3974
3707
3975 # Set this to the value of wxPython you want to use, but note that this
3708 # Set this to the value of wxPython you want to use, but note that this
3976 # feature requires you to have the wxversion Python module to work. If you
3709 # feature requires you to have the wxversion Python module to work. If you
3977 # don't have the wxversion module (try 'import wxversion' at the prompt to
3710 # don't have the wxversion module (try 'import wxversion' at the prompt to
3978 # check) or simply want to leave the system to pick up the default, leave this
3711 # check) or simply want to leave the system to pick up the default, leave this
3979 # variable at 0.
3712 # variable at 0.
3980
3713
3981 wxversion 0
3714 wxversion 0
3982
3715
3983 #---------------------------------------------------------------------------
3716 #---------------------------------------------------------------------------
3984 # Section: Readline configuration (readline is not available for MS-Windows)
3717 # Section: Readline configuration (readline is not available for MS-Windows)
3985
3718
3986 # This is done via the following options:
3719 # This is done via the following options:
3987
3720
3988 # (i) readline_parse_and_bind: this option can appear as many times as you
3721 # (i) readline_parse_and_bind: this option can appear as many times as you
3989 # want, each time defining a string to be executed via a
3722 # want, each time defining a string to be executed via a
3990 # readline.parse_and_bind() command. The syntax for valid commands of this
3723 # readline.parse_and_bind() command. The syntax for valid commands of this
3991 # kind can be found by reading the documentation for the GNU readline library,
3724 # kind can be found by reading the documentation for the GNU readline library,
3992 # as these commands are of the kind which readline accepts in its
3725 # as these commands are of the kind which readline accepts in its
3993 # configuration file.
3726 # configuration file.
3994
3727
3995 # The TAB key can be used to complete names at the command line in one of two
3728 # The TAB key can be used to complete names at the command line in one of two
3996 # ways: 'complete' and 'menu-complete'. The difference is that 'complete' only
3729 # ways: 'complete' and 'menu-complete'. The difference is that 'complete' only
3997 # completes as much as possible while 'menu-complete' cycles through all
3730 # completes as much as possible while 'menu-complete' cycles through all
3998 # possible completions. Leave the one you prefer uncommented.
3731 # possible completions. Leave the one you prefer uncommented.
3999
3732
4000 readline_parse_and_bind tab: complete
3733 readline_parse_and_bind tab: complete
4001 #readline_parse_and_bind tab: menu-complete
3734 #readline_parse_and_bind tab: menu-complete
4002
3735
4003 # This binds Control-l to printing the list of all possible completions when
3736 # This binds Control-l to printing the list of all possible completions when
4004 # there is more than one (what 'complete' does when hitting TAB twice, or at
3737 # there is more than one (what 'complete' does when hitting TAB twice, or at
4005 # the first TAB if show-all-if-ambiguous is on)
3738 # the first TAB if show-all-if-ambiguous is on)
4006 readline_parse_and_bind "\C-l": possible-completions
3739 readline_parse_and_bind "\C-l": possible-completions
4007
3740
4008 # This forces readline to automatically print the above list when tab
3741 # This forces readline to automatically print the above list when tab
4009 # completion is set to 'complete'. You can still get this list manually by
3742 # completion is set to 'complete'. You can still get this list manually by
4010 # using the key bound to 'possible-completions' (Control-l by default) or by
3743 # using the key bound to 'possible-completions' (Control-l by default) or by
4011 # hitting TAB twice. Turning this on makes the printing happen at the first
3744 # hitting TAB twice. Turning this on makes the printing happen at the first
4012 # TAB.
3745 # TAB.
4013 readline_parse_and_bind set show-all-if-ambiguous on
3746 readline_parse_and_bind set show-all-if-ambiguous on
4014
3747
4015 # If you have TAB set to complete names, you can rebind any key (Control-o by
3748 # If you have TAB set to complete names, you can rebind any key (Control-o by
4016 # default) to insert a true TAB character.
3749 # default) to insert a true TAB character.
4017 readline_parse_and_bind "\C-o": tab-insert
3750 readline_parse_and_bind "\C-o": tab-insert
4018
3751
4019 # These commands allow you to indent/unindent easily, with the 4-space
3752 # These commands allow you to indent/unindent easily, with the 4-space
4020 # convention of the Python coding standards. Since IPython's internal
3753 # convention of the Python coding standards. Since IPython's internal
4021 # auto-indent system also uses 4 spaces, you should not change the number of
3754 # auto-indent system also uses 4 spaces, you should not change the number of
4022 # spaces in the code below.
3755 # spaces in the code below.
4023 readline_parse_and_bind "\M-i": " "
3756 readline_parse_and_bind "\M-i": " "
4024 readline_parse_and_bind "\M-o": "\d\d\d\d"
3757 readline_parse_and_bind "\M-o": "\d\d\d\d"
4025 readline_parse_and_bind "\M-I": "\d\d\d\d"
3758 readline_parse_and_bind "\M-I": "\d\d\d\d"
4026
3759
4027 # Bindings for incremental searches in the history. These searches use the
3760 # Bindings for incremental searches in the history. These searches use the
4028 # string typed so far on the command line and search anything in the previous
3761 # string typed so far on the command line and search anything in the previous
4029 # input history containing them.
3762 # input history containing them.
4030 readline_parse_and_bind "\C-r": reverse-search-history
3763 readline_parse_and_bind "\C-r": reverse-search-history
4031 readline_parse_and_bind "\C-s": forward-search-history
3764 readline_parse_and_bind "\C-s": forward-search-history
4032
3765
4033 # Bindings for completing the current line in the history of previous
3766 # Bindings for completing the current line in the history of previous
4034 # commands. This allows you to recall any previous command by typing its first
3767 # commands. This allows you to recall any previous command by typing its first
4035 # few letters and hitting Control-p, bypassing all intermediate commands which
3768 # few letters and hitting Control-p, bypassing all intermediate commands which
4036 # may be in the history (much faster than hitting up-arrow 50 times!)
3769 # may be in the history (much faster than hitting up-arrow 50 times!)
4037 readline_parse_and_bind "\C-p": history-search-backward
3770 readline_parse_and_bind "\C-p": history-search-backward
4038 readline_parse_and_bind "\C-n": history-search-forward
3771 readline_parse_and_bind "\C-n": history-search-forward
4039
3772
4040 # I also like to have the same functionality on the plain arrow keys. If you'd
3773 # I also like to have the same functionality on the plain arrow keys. If you'd
4041 # rather have the arrows use all the history (and not just match what you've
3774 # rather have the arrows use all the history (and not just match what you've
4042 # typed so far), comment out or delete the next two lines.
3775 # typed so far), comment out or delete the next two lines.
4043 readline_parse_and_bind "\e[A": history-search-backward
3776 readline_parse_and_bind "\e[A": history-search-backward
4044 readline_parse_and_bind "\e[B": history-search-forward
3777 readline_parse_and_bind "\e[B": history-search-forward
4045
3778
4046 # These are typically on by default under *nix, but not win32.
3779 # These are typically on by default under *nix, but not win32.
4047 readline_parse_and_bind "\C-k": kill-line
3780 readline_parse_and_bind "\C-k": kill-line
4048 readline_parse_and_bind "\C-u": unix-line-discard
3781 readline_parse_and_bind "\C-u": unix-line-discard
4049
3782
4050 # (ii) readline_remove_delims: a string of characters to be removed from the
3783 # (ii) readline_remove_delims: a string of characters to be removed from the
4051 # default word-delimiters list used by readline, so that completions may be
3784 # default word-delimiters list used by readline, so that completions may be
4052 # performed on strings which contain them.
3785 # performed on strings which contain them.
4053
3786
4054 readline_remove_delims -/~
3787 readline_remove_delims -/~
4055
3788
4056 # (iii) readline_merge_completions: whether to merge the result of all
3789 # (iii) readline_merge_completions: whether to merge the result of all
4057 # possible completions or not. If true, IPython will complete filenames,
3790 # possible completions or not. If true, IPython will complete filenames,
4058 # python names and aliases and return all possible completions. If you set it
3791 # python names and aliases and return all possible completions. If you set it
4059 # to false, each completer is used at a time, and only if it doesn't return
3792 # to false, each completer is used at a time, and only if it doesn't return
4060 # any completions is the next one used.
3793 # any completions is the next one used.
4061
3794
4062 # The default order is: [python_matches, file_matches, alias_matches]
3795 # The default order is: [python_matches, file_matches, alias_matches]
4063
3796
4064 readline_merge_completions 1
3797 readline_merge_completions 1
4065
3798
4066 # (iv) readline_omit__names: normally hitting <tab> after a '.' in a name
3799 # (iv) readline_omit__names: normally hitting <tab> after a '.' in a name
4067 # will complete all attributes of an object, including all the special methods
3800 # will complete all attributes of an object, including all the special methods
4068 # whose names start with single or double underscores (like __getitem__ or
3801 # whose names start with single or double underscores (like __getitem__ or
4069 # __class__).
3802 # __class__).
4070
3803
4071 # This variable allows you to control this completion behavior:
3804 # This variable allows you to control this completion behavior:
4072
3805
4073 # readline_omit__names 1 -> completion will omit showing any names starting
3806 # readline_omit__names 1 -> completion will omit showing any names starting
4074 # with two __, but it will still show names starting with one _.
3807 # with two __, but it will still show names starting with one _.
4075
3808
4076 # readline_omit__names 2 -> completion will omit all names beginning with one
3809 # readline_omit__names 2 -> completion will omit all names beginning with one
4077 # _ (which obviously means filtering out the double __ ones).
3810 # _ (which obviously means filtering out the double __ ones).
4078
3811
4079 # Even when this option is set, you can still see those names by explicitly
3812 # Even when this option is set, you can still see those names by explicitly
4080 # typing a _ after the period and hitting <tab>: 'name._<tab>' will always
3813 # typing a _ after the period and hitting <tab>: 'name._<tab>' will always
4081 # complete attribute names starting with '_'.
3814 # complete attribute names starting with '_'.
4082
3815
4083 # This option is off by default so that new users see all attributes of any
3816 # This option is off by default so that new users see all attributes of any
4084 # objects they are dealing with.
3817 # objects they are dealing with.
4085
3818
4086 readline_omit__names 0
3819 readline_omit__names 0
4087
3820
4088 #---------------------------------------------------------------------------
3821 #---------------------------------------------------------------------------
4089 # Section: modules to be loaded with 'import ...'
3822 # Section: modules to be loaded with 'import ...'
4090
3823
4091 # List, separated by spaces, the names of the modules you want to import
3824 # List, separated by spaces, the names of the modules you want to import
4092
3825
4093 # Example:
3826 # Example:
4094 # import_mod sys os
3827 # import_mod sys os
4095 # will produce internally the statements
3828 # will produce internally the statements
4096 # import sys
3829 # import sys
4097 # import os
3830 # import os
4098
3831
4099 # Each import is executed in its own try/except block, so if one module
3832 # Each import is executed in its own try/except block, so if one module
4100 # fails to load the others will still be ok.
3833 # fails to load the others will still be ok.
4101
3834
4102 import_mod
3835 import_mod
4103
3836
4104 #---------------------------------------------------------------------------
3837 #---------------------------------------------------------------------------
4105 # Section: modules to import some functions from: 'from ... import ...'
3838 # Section: modules to import some functions from: 'from ... import ...'
4106
3839
4107 # List, one per line, the modules for which you want only to import some
3840 # List, one per line, the modules for which you want only to import some
4108 # functions. Give the module name first and then the name of functions to be
3841 # functions. Give the module name first and then the name of functions to be
4109 # imported from that module.
3842 # imported from that module.
4110
3843
4111 # Example:
3844 # Example:
4112
3845
4113 # import_some IPython.genutils timing timings
3846 # import_some IPython.genutils timing timings
4114 # will produce internally the statement
3847 # will produce internally the statement
4115 # from IPython.genutils import timing, timings
3848 # from IPython.genutils import timing, timings
4116
3849
4117 # timing() and timings() are two IPython utilities for timing the execution of
3850 # timing() and timings() are two IPython utilities for timing the execution of
4118 # your own functions, which you may find useful. Just commment out the above
3851 # your own functions, which you may find useful. Just commment out the above
4119 # line if you want to test them.
3852 # line if you want to test them.
4120
3853
4121 # If you have more than one modules_some line, each gets its own try/except
3854 # If you have more than one modules_some line, each gets its own try/except
4122 # block (like modules, see above).
3855 # block (like modules, see above).
4123
3856
4124 import_some
3857 import_some
4125
3858
4126 #---------------------------------------------------------------------------
3859 #---------------------------------------------------------------------------
4127 # Section: modules to import all from : 'from ... import *'
3860 # Section: modules to import all from : 'from ... import *'
4128
3861
4129 # List (same syntax as import_mod above) those modules for which you want to
3862 # List (same syntax as import_mod above) those modules for which you want to
4130 # import all functions. Remember, this is a potentially dangerous thing to do,
3863 # import all functions. Remember, this is a potentially dangerous thing to do,
4131 # since it is very easy to overwrite names of things you need. Use with
3864 # since it is very easy to overwrite names of things you need. Use with
4132 # caution.
3865 # caution.
4133
3866
4134 # Example:
3867 # Example:
4135 # import_all sys os
3868 # import_all sys os
4136 # will produce internally the statements
3869 # will produce internally the statements
4137 # from sys import *
3870 # from sys import *
4138 # from os import *
3871 # from os import *
4139
3872
4140 # As before, each will be called in a separate try/except block.
3873 # As before, each will be called in a separate try/except block.
4141
3874
4142 import_all
3875 import_all
4143
3876
4144 #---------------------------------------------------------------------------
3877 #---------------------------------------------------------------------------
4145 # Section: Python code to execute.
3878 # Section: Python code to execute.
4146
3879
4147 # Put here code to be explicitly executed (keep it simple!)
3880 # Put here code to be explicitly executed (keep it simple!)
4148 # Put one line of python code per line. All whitespace is removed (this is a
3881 # Put one line of python code per line. All whitespace is removed (this is a
4149 # feature, not a bug), so don't get fancy building loops here.
3882 # feature, not a bug), so don't get fancy building loops here.
4150 # This is just for quick convenient creation of things you want available.
3883 # This is just for quick convenient creation of things you want available.
4151
3884
4152 # Example:
3885 # Example:
4153 # execute x = 1
3886 # execute x = 1
4154 # execute print 'hello world'; y = z = 'a'
3887 # execute print 'hello world'; y = z = 'a'
4155 # will produce internally
3888 # will produce internally
4156 # x = 1
3889 # x = 1
4157 # print 'hello world'; y = z = 'a'
3890 # print 'hello world'; y = z = 'a'
4158 # and each *line* (not each statement, we don't do python syntax parsing) is
3891 # and each *line* (not each statement, we don't do python syntax parsing) is
4159 # executed in its own try/except block.
3892 # executed in its own try/except block.
4160
3893
4161 execute
3894 execute
4162
3895
4163 # Note for the adventurous: you can use this to define your own names for the
3896 # Note for the adventurous: you can use this to define your own names for the
4164 # magic functions, by playing some namespace tricks:
3897 # magic functions, by playing some namespace tricks:
4165
3898
4166 # execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
3899 # execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
4167
3900
4168 # defines %pf as a new name for %profile.
3901 # defines %pf as a new name for %profile.
4169
3902
4170 #---------------------------------------------------------------------------
3903 #---------------------------------------------------------------------------
4171 # Section: Pyhton files to load and execute.
3904 # Section: Pyhton files to load and execute.
4172
3905
4173 # Put here the full names of files you want executed with execfile(file). If
3906 # Put here the full names of files you want executed with execfile(file). If
4174 # you want complicated initialization, just write whatever you want in a
3907 # you want complicated initialization, just write whatever you want in a
4175 # regular python file and load it from here.
3908 # regular python file and load it from here.
4176
3909
4177 # Filenames defined here (which *must* include the extension) are searched for
3910 # Filenames defined here (which *must* include the extension) are searched for
4178 # through all of sys.path. Since IPython adds your .ipython directory to
3911 # through all of sys.path. Since IPython adds your .ipython directory to
4179 # sys.path, they can also be placed in your .ipython dir and will be
3912 # sys.path, they can also be placed in your .ipython dir and will be
4180 # found. Otherwise (if you want to execute things not in .ipyton nor in
3913 # found. Otherwise (if you want to execute things not in .ipyton nor in
4181 # sys.path) give a full path (you can use ~, it gets expanded)
3914 # sys.path) give a full path (you can use ~, it gets expanded)
4182
3915
4183 # Example:
3916 # Example:
4184 # execfile file1.py ~/file2.py
3917 # execfile file1.py ~/file2.py
4185 # will generate
3918 # will generate
4186 # execfile('file1.py')
3919 # execfile('file1.py')
4187 # execfile('_path_to_your_home/file2.py')
3920 # execfile('_path_to_your_home/file2.py')
4188
3921
4189 # As before, each file gets its own try/except block.
3922 # As before, each file gets its own try/except block.
4190
3923
4191 execfile
3924 execfile
4192
3925
4193 # If you are feeling adventurous, you can even add functionality to IPython
3926 # If you are feeling adventurous, you can even add functionality to IPython
4194 # through here. IPython works through a global variable called __ip which
3927 # through here. IPython works through a global variable called __ip which
4195 # exists at the time when these files are read. If you know what you are doing
3928 # exists at the time when these files are read. If you know what you are doing
4196 # (read the source) you can add functions to __ip in files loaded here.
3929 # (read the source) you can add functions to __ip in files loaded here.
4197
3930
4198 # The file example-magic.py contains a simple but correct example. Try it:
3931 # The file example-magic.py contains a simple but correct example. Try it:
4199
3932
4200 # execfile example-magic.py
3933 # execfile example-magic.py
4201
3934
4202 # Look at the examples in IPython/iplib.py for more details on how these magic
3935 # Look at the examples in IPython/iplib.py for more details on how these magic
4203 # functions need to process their arguments.
3936 # functions need to process their arguments.
4204
3937
4205 #---------------------------------------------------------------------------
3938 #---------------------------------------------------------------------------
4206 # Section: aliases for system shell commands
3939 # Section: aliases for system shell commands
4207
3940
4208 # Here you can define your own names for system commands. The syntax is
3941 # Here you can define your own names for system commands. The syntax is
4209 # similar to that of the builtin %alias function:
3942 # similar to that of the builtin %alias function:
4210
3943
4211 # alias alias_name command_string
3944 # alias alias_name command_string
4212
3945
4213 # The resulting aliases are auto-generated magic functions (hence usable as
3946 # The resulting aliases are auto-generated magic functions (hence usable as
4214 # %alias_name)
3947 # %alias_name)
4215
3948
4216 # For example:
3949 # For example:
4217
3950
4218 # alias myls ls -la
3951 # alias myls ls -la
4219
3952
4220 # will define 'myls' as an alias for executing the system command 'ls -la'.
3953 # will define 'myls' as an alias for executing the system command 'ls -la'.
4221 # This allows you to customize IPython's environment to have the same aliases
3954 # This allows you to customize IPython's environment to have the same aliases
4222 # you are accustomed to from your own shell.
3955 # you are accustomed to from your own shell.
4223
3956
4224 # You can also define aliases with parameters using %s specifiers (one per
3957 # You can also define aliases with parameters using %s specifiers (one per
4225 # parameter):
3958 # parameter):
4226
3959
4227 # alias parts echo first %s second %s
3960 # alias parts echo first %s second %s
4228
3961
4229 # will give you in IPython:
3962 # will give you in IPython:
4230 # >>> %parts A B
3963 # >>> %parts A B
4231 # first A second B
3964 # first A second B
4232
3965
4233 # Use one 'alias' statement per alias you wish to define.
3966 # Use one 'alias' statement per alias you wish to define.
4234
3967
4235 # alias
3968 # alias
4236
3969
4237 #************************* end of file <ipythonrc> ************************
3970 #************************* end of file <ipythonrc> ************************
4238
3971
4239
3972
4240 ipy_user_conf.py
3973 ipy_user_conf.py
4241 ----------------
3974 ----------------
4242
3975
4243 There should be a simple template ipy_user_conf.py file in your
3976 There should be a simple template ipy_user_conf.py file in your
4244 ~/.ipython directory. It is a plain python module that is imported
3977 ~/.ipython directory. It is a plain python module that is imported
4245 during IPython startup, so you can do pretty much what you want there
3978 during IPython startup, so you can do pretty much what you want there
4246 - import modules, configure extensions, change options, define magic
3979 - import modules, configure extensions, change options, define magic
4247 commands, put variables and functions in the IPython namespace,
3980 commands, put variables and functions in the IPython namespace,
4248 etc. You use the IPython extension api object, acquired by
3981 etc. You use the IPython extension api object, acquired by
4249 IPython.ipapi.get() and documented in the "IPython extension API"
3982 IPython.ipapi.get() and documented in the "IPython extension API"
4250 chapter, to interact with IPython. A sample ipy_user_conf.py is listed
3983 chapter, to interact with IPython. A sample ipy_user_conf.py is listed
4251 below for reference::
3984 below for reference::
4252
3985
4253 # Most of your config files and extensions will probably start
3986 # Most of your config files and extensions will probably start
4254 # with this import
3987 # with this import
4255
3988
4256 import IPython.ipapi
3989 import IPython.ipapi
4257 ip = IPython.ipapi.get()
3990 ip = IPython.ipapi.get()
4258
3991
4259 # You probably want to uncomment this if you did %upgrade -nolegacy
3992 # You probably want to uncomment this if you did %upgrade -nolegacy
4260 # import ipy_defaults
3993 # import ipy_defaults
4261
3994
4262 import os
3995 import os
4263
3996
4264 def main():
3997 def main():
4265
3998
4266 #ip.dbg.debugmode = True
3999 #ip.dbg.debugmode = True
4267 ip.dbg.debug_stack()
4000 ip.dbg.debug_stack()
4268
4001
4269 # uncomment if you want to get ipython -p sh behaviour
4002 # uncomment if you want to get ipython -p sh behaviour
4270 # without having to use command line switches
4003 # without having to use command line switches
4271 import ipy_profile_sh
4004 import ipy_profile_sh
4272 import jobctrl
4005 import jobctrl
4273
4006
4274 # Configure your favourite editor?
4007 # Configure your favourite editor?
4275 # Good idea e.g. for %edit os.path.isfile
4008 # Good idea e.g. for %edit os.path.isfile
4276
4009
4277 #import ipy_editors
4010 #import ipy_editors
4278
4011
4279 # Choose one of these:
4012 # Choose one of these:
4280
4013
4281 #ipy_editors.scite()
4014 #ipy_editors.scite()
4282 #ipy_editors.scite('c:/opt/scite/scite.exe')
4015 #ipy_editors.scite('c:/opt/scite/scite.exe')
4283 #ipy_editors.komodo()
4016 #ipy_editors.komodo()
4284 #ipy_editors.idle()
4017 #ipy_editors.idle()
4285 # ... or many others, try 'ipy_editors??' after import to see them
4018 # ... or many others, try 'ipy_editors??' after import to see them
4286
4019
4287 # Or roll your own:
4020 # Or roll your own:
4288 #ipy_editors.install_editor("c:/opt/jed +$line $file")
4021 #ipy_editors.install_editor("c:/opt/jed +$line $file")
4289
4022
4290
4023
4291 o = ip.options
4024 o = ip.options
4292 # An example on how to set options
4025 # An example on how to set options
4293 #o.autocall = 1
4026 #o.autocall = 1
4294 o.system_verbose = 0
4027 o.system_verbose = 0
4295
4028
4296 #import_all("os sys")
4029 #import_all("os sys")
4297 #execf('~/_ipython/ns.py')
4030 #execf('~/_ipython/ns.py')
4298
4031
4299
4032
4300 # -- prompt
4033 # -- prompt
4301 # A different, more compact set of prompts from the default ones, that
4034 # A different, more compact set of prompts from the default ones, that
4302 # always show your current location in the filesystem:
4035 # always show your current location in the filesystem:
4303
4036
4304 #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
4037 #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
4305 #o.prompt_in2 = r'.\D: '
4038 #o.prompt_in2 = r'.\D: '
4306 #o.prompt_out = r'[\#] '
4039 #o.prompt_out = r'[\#] '
4307
4040
4308 # Try one of these color settings if you can't read the text easily
4041 # Try one of these color settings if you can't read the text easily
4309 # autoexec is a list of IPython commands to execute on startup
4042 # autoexec is a list of IPython commands to execute on startup
4310 #o.autoexec.append('%colors LightBG')
4043 #o.autoexec.append('%colors LightBG')
4311 #o.autoexec.append('%colors NoColor')
4044 #o.autoexec.append('%colors NoColor')
4312 o.autoexec.append('%colors Linux')
4045 o.autoexec.append('%colors Linux')
4313
4046
4314
4047
4315 # some config helper functions you can use
4048 # some config helper functions you can use
4316 def import_all(modules):
4049 def import_all(modules):
4317 """ Usage: import_all("os sys") """
4050 """ Usage: import_all("os sys") """
4318 for m in modules.split():
4051 for m in modules.split():
4319 ip.ex("from %s import *" % m)
4052 ip.ex("from %s import *" % m)
4320
4053
4321 def execf(fname):
4054 def execf(fname):
4322 """ Execute a file in user namespace """
4055 """ Execute a file in user namespace """
4323 ip.ex('execfile("%s")' % os.path.expanduser(fname))
4056 ip.ex('execfile("%s")' % os.path.expanduser(fname))
4324
4057
4325 main()
4058 main()
4326
4059
4327 .. _Prompts:
4060 .. _Prompts:
4328
4061
4329 Fine-tuning your prompt
4062 Fine-tuning your prompt
4330 -----------------------
4063 -----------------------
4331
4064
4332 IPython's prompts can be customized using a syntax similar to that of
4065 IPython's prompts can be customized using a syntax similar to that of
4333 the bash shell. Many of bash's escapes are supported, as well as a few
4066 the bash shell. Many of bash's escapes are supported, as well as a few
4334 additional ones. We list them below::
4067 additional ones. We list them below::
4335
4068
4336 \#
4069 \#
4337 the prompt/history count number. This escape is automatically
4070 the prompt/history count number. This escape is automatically
4338 wrapped in the coloring codes for the currently active color scheme.
4071 wrapped in the coloring codes for the currently active color scheme.
4339 \N
4072 \N
4340 the 'naked' prompt/history count number: this is just the number
4073 the 'naked' prompt/history count number: this is just the number
4341 itself, without any coloring applied to it. This lets you produce
4074 itself, without any coloring applied to it. This lets you produce
4342 numbered prompts with your own colors.
4075 numbered prompts with your own colors.
4343 \D
4076 \D
4344 the prompt/history count, with the actual digits replaced by dots.
4077 the prompt/history count, with the actual digits replaced by dots.
4345 Used mainly in continuation prompts (prompt_in2)
4078 Used mainly in continuation prompts (prompt_in2)
4346 \w
4079 \w
4347 the current working directory
4080 the current working directory
4348 \W
4081 \W
4349 the basename of current working directory
4082 the basename of current working directory
4350 \Xn
4083 \Xn
4351 where $n=0\ldots5.$ The current working directory, with $HOME
4084 where $n=0\ldots5.$ The current working directory, with $HOME
4352 replaced by ~, and filtered out to contain only $n$ path elements
4085 replaced by ~, and filtered out to contain only $n$ path elements
4353 \Yn
4086 \Yn
4354 Similar to \Xn, but with the $n+1$ element included if it is ~ (this
4087 Similar to \Xn, but with the $n+1$ element included if it is ~ (this
4355 is similar to the behavior of the %cn escapes in tcsh)
4088 is similar to the behavior of the %cn escapes in tcsh)
4356 \u
4089 \u
4357 the username of the current user
4090 the username of the current user
4358 \$
4091 \$
4359 if the effective UID is 0, a #, otherwise a $
4092 if the effective UID is 0, a #, otherwise a $
4360 \h
4093 \h
4361 the hostname up to the first '.'
4094 the hostname up to the first '.'
4362 \H
4095 \H
4363 the hostname
4096 the hostname
4364 \n
4097 \n
4365 a newline
4098 a newline
4366 \r
4099 \r
4367 a carriage return
4100 a carriage return
4368 \v
4101 \v
4369 IPython version string
4102 IPython version string
4370
4103
4371 In addition to these, ANSI color escapes can be insterted into the
4104 In addition to these, ANSI color escapes can be insterted into the
4372 prompts, as \C_ColorName. The list of valid color names is: Black, Blue,
4105 prompts, as \C_ColorName. The list of valid color names is: Black, Blue,
4373 Brown, Cyan, DarkGray, Green, LightBlue, LightCyan, LightGray,
4106 Brown, Cyan, DarkGray, Green, LightBlue, LightCyan, LightGray,
4374 LightGreen, LightPurple, LightRed, NoColor, Normal, Purple, Red, White,
4107 LightGreen, LightPurple, LightRed, NoColor, Normal, Purple, Red, White,
4375 Yellow.
4108 Yellow.
4376
4109
4377 Finally, IPython supports the evaluation of arbitrary expressions in
4110 Finally, IPython supports the evaluation of arbitrary expressions in
4378 your prompt string. The prompt strings are evaluated through the syntax
4111 your prompt string. The prompt strings are evaluated through the syntax
4379 of PEP 215, but basically you can use $x.y to expand the value of x.y,
4112 of PEP 215, but basically you can use $x.y to expand the value of x.y,
4380 and for more complicated expressions you can use braces: ${foo()+x} will
4113 and for more complicated expressions you can use braces: ${foo()+x} will
4381 call function foo and add to it the value of x, before putting the
4114 call function foo and add to it the value of x, before putting the
4382 result into your prompt. For example, using
4115 result into your prompt. For example, using
4383 prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: '
4116 prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: '
4384 will print the result of the uptime command on each prompt (assuming the
4117 will print the result of the uptime command on each prompt (assuming the
4385 commands module has been imported in your ipythonrc file).
4118 commands module has been imported in your ipythonrc file).
4386
4119
4387
4120
4388 Prompt examples
4121 Prompt examples
4389
4122
4390 The following options in an ipythonrc file will give you IPython's
4123 The following options in an ipythonrc file will give you IPython's
4391 default prompts::
4124 default prompts::
4392
4125
4393 prompt_in1 'In [\#]:'
4126 prompt_in1 'In [\#]:'
4394 prompt_in2 ' .\D.:'
4127 prompt_in2 ' .\D.:'
4395 prompt_out 'Out[\#]:'
4128 prompt_out 'Out[\#]:'
4396
4129
4397 which look like this::
4130 which look like this::
4398
4131
4399 In [1]: 1+2
4132 In [1]: 1+2
4400 Out[1]: 3
4133 Out[1]: 3
4401
4134
4402 In [2]: for i in (1,2,3):
4135 In [2]: for i in (1,2,3):
4403 ...: print i,
4136 ...: print i,
4404 ...:
4137 ...:
4405 1 2 3
4138 1 2 3
4406
4139
4407 These will give you a very colorful prompt with path information::
4140 These will give you a very colorful prompt with path information::
4408
4141
4409 #prompt_in1 '\C_Red\u\C_Blue[\C_Cyan\Y1\C_Blue]\C_LightGreen\#>'
4142 #prompt_in1 '\C_Red\u\C_Blue[\C_Cyan\Y1\C_Blue]\C_LightGreen\#>'
4410 prompt_in2 ' ..\D>'
4143 prompt_in2 ' ..\D>'
4411 prompt_out '<\#>'
4144 prompt_out '<\#>'
4412
4145
4413 which look like this::
4146 which look like this::
4414
4147
4415 fperez[~/ipython]1> 1+2
4148 fperez[~/ipython]1> 1+2
4416 <1> 3
4149 <1> 3
4417 fperez[~/ipython]2> for i in (1,2,3):
4150 fperez[~/ipython]2> for i in (1,2,3):
4418 ...> print i,
4151 ...> print i,
4419 ...>
4152 ...>
4420 1 2 3
4153 1 2 3
4421
4154
4422
4155
4423 .. _Profiles:
4156 .. _Profiles:
4424
4157
4425 IPython profiles
4158 IPython profiles
4426 ----------------
4159 ----------------
4427
4160
4428 As we already mentioned, IPython supports the -profile command-line
4161 As we already mentioned, IPython supports the -profile command-line
4429 option (see sec. `command line options`_). A profile is nothing more
4162 option (see sec. `command line options`_). A profile is nothing more
4430 than a particular configuration file like your basic ipythonrc one,
4163 than a particular configuration file like your basic ipythonrc one,
4431 but with particular customizations for a specific purpose. When you
4164 but with particular customizations for a specific purpose. When you
4432 start IPython with 'ipython -profile <name>', it assumes that in your
4165 start IPython with 'ipython -profile <name>', it assumes that in your
4433 IPYTHONDIR there is a file called ipythonrc-<name> or
4166 IPYTHONDIR there is a file called ipythonrc-<name> or
4434 ipy_profile_<name>.py, and loads it instead of the normal ipythonrc.
4167 ipy_profile_<name>.py, and loads it instead of the normal ipythonrc.
4435
4168
4436 This system allows you to maintain multiple configurations which load
4169 This system allows you to maintain multiple configurations which load
4437 modules, set options, define functions, etc. suitable for different
4170 modules, set options, define functions, etc. suitable for different
4438 tasks and activate them in a very simple manner. In order to avoid
4171 tasks and activate them in a very simple manner. In order to avoid
4439 having to repeat all of your basic options (common things that don't
4172 having to repeat all of your basic options (common things that don't
4440 change such as your color preferences, for example), any profile can
4173 change such as your color preferences, for example), any profile can
4441 include another configuration file. The most common way to use profiles
4174 include another configuration file. The most common way to use profiles
4442 is then to have each one include your basic ipythonrc file as a starting
4175 is then to have each one include your basic ipythonrc file as a starting
4443 point, and then add further customizations.
4176 point, and then add further customizations.
4444
4177
4445 IPython as your default Python environment
4178 IPython as your default Python environment
4446 ==========================================
4179 ==========================================
4447
4180
4448 Python honors the environment variable PYTHONSTARTUP and will execute at
4181 Python honors the environment variable PYTHONSTARTUP and will execute at
4449 startup the file referenced by this variable. If you put at the end of
4182 startup the file referenced by this variable. If you put at the end of
4450 this file the following two lines of code::
4183 this file the following two lines of code::
4451
4184
4452 import IPython
4185 import IPython
4453 IPython.Shell.IPShell().mainloop(sys_exit=1)
4186 IPython.Shell.IPShell().mainloop(sys_exit=1)
4454
4187
4455 then IPython will be your working environment anytime you start Python.
4188 then IPython will be your working environment anytime you start Python.
4456 The sys_exit=1 is needed to have IPython issue a call to sys.exit() when
4189 The sys_exit=1 is needed to have IPython issue a call to sys.exit() when
4457 it finishes, otherwise you'll be back at the normal Python '>>>'
4190 it finishes, otherwise you'll be back at the normal Python '>>>'
4458 prompt.
4191 prompt.
4459
4192
4460 This is probably useful to developers who manage multiple Python
4193 This is probably useful to developers who manage multiple Python
4461 versions and don't want to have correspondingly multiple IPython
4194 versions and don't want to have correspondingly multiple IPython
4462 versions. Note that in this mode, there is no way to pass IPython any
4195 versions. Note that in this mode, there is no way to pass IPython any
4463 command-line options, as those are trapped first by Python itself.
4196 command-line options, as those are trapped first by Python itself.
4464
4197
4465 .. _Embedding:
4198 .. _Embedding:
4466
4199
4467 Embedding IPython
4200 Embedding IPython
4468 =================
4201 =================
4469
4202
4470 It is possible to start an IPython instance inside your own Python
4203 It is possible to start an IPython instance inside your own Python
4471 programs. This allows you to evaluate dynamically the state of your
4204 programs. This allows you to evaluate dynamically the state of your
4472 code, operate with your variables, analyze them, etc. Note however that
4205 code, operate with your variables, analyze them, etc. Note however that
4473 any changes you make to values while in the shell do not propagate back
4206 any changes you make to values while in the shell do not propagate back
4474 to the running code, so it is safe to modify your values because you
4207 to the running code, so it is safe to modify your values because you
4475 won't break your code in bizarre ways by doing so.
4208 won't break your code in bizarre ways by doing so.
4476
4209
4477 This feature allows you to easily have a fully functional python
4210 This feature allows you to easily have a fully functional python
4478 environment for doing object introspection anywhere in your code with a
4211 environment for doing object introspection anywhere in your code with a
4479 simple function call. In some cases a simple print statement is enough,
4212 simple function call. In some cases a simple print statement is enough,
4480 but if you need to do more detailed analysis of a code fragment this
4213 but if you need to do more detailed analysis of a code fragment this
4481 feature can be very valuable.
4214 feature can be very valuable.
4482
4215
4483 It can also be useful in scientific computing situations where it is
4216 It can also be useful in scientific computing situations where it is
4484 common to need to do some automatic, computationally intensive part and
4217 common to need to do some automatic, computationally intensive part and
4485 then stop to look at data, plots, etc.
4218 then stop to look at data, plots, etc.
4486 Opening an IPython instance will give you full access to your data and
4219 Opening an IPython instance will give you full access to your data and
4487 functions, and you can resume program execution once you are done with
4220 functions, and you can resume program execution once you are done with
4488 the interactive part (perhaps to stop again later, as many times as
4221 the interactive part (perhaps to stop again later, as many times as
4489 needed).
4222 needed).
4490
4223
4491 The following code snippet is the bare minimum you need to include in
4224 The following code snippet is the bare minimum you need to include in
4492 your Python programs for this to work (detailed examples follow later)::
4225 your Python programs for this to work (detailed examples follow later)::
4493
4226
4494 from IPython.Shell import IPShellEmbed
4227 from IPython.Shell import IPShellEmbed
4495
4228
4496 ipshell = IPShellEmbed()
4229 ipshell = IPShellEmbed()
4497
4230
4498 ipshell() # this call anywhere in your program will start IPython
4231 ipshell() # this call anywhere in your program will start IPython
4499
4232
4500 You can run embedded instances even in code which is itself being run at
4233 You can run embedded instances even in code which is itself being run at
4501 the IPython interactive prompt with '%run <filename>'. Since it's easy
4234 the IPython interactive prompt with '%run <filename>'. Since it's easy
4502 to get lost as to where you are (in your top-level IPython or in your
4235 to get lost as to where you are (in your top-level IPython or in your
4503 embedded one), it's a good idea in such cases to set the in/out prompts
4236 embedded one), it's a good idea in such cases to set the in/out prompts
4504 to something different for the embedded instances. The code examples
4237 to something different for the embedded instances. The code examples
4505 below illustrate this.
4238 below illustrate this.
4506
4239
4507 You can also have multiple IPython instances in your program and open
4240 You can also have multiple IPython instances in your program and open
4508 them separately, for example with different options for data
4241 them separately, for example with different options for data
4509 presentation. If you close and open the same instance multiple times,
4242 presentation. If you close and open the same instance multiple times,
4510 its prompt counters simply continue from each execution to the next.
4243 its prompt counters simply continue from each execution to the next.
4511
4244
4512 Please look at the docstrings in the Shell.py module for more details on
4245 Please look at the docstrings in the Shell.py module for more details on
4513 the use of this system.
4246 the use of this system.
4514
4247
4515 The following sample file illustrating how to use the embedding
4248 The following sample file illustrating how to use the embedding
4516 functionality is provided in the examples directory as example-embed.py.
4249 functionality is provided in the examples directory as example-embed.py.
4517 It should be fairly self-explanatory::
4250 It should be fairly self-explanatory::
4518
4251
4519
4252
4520 #!/usr/bin/env python
4253 #!/usr/bin/env python
4521
4254
4522 """An example of how to embed an IPython shell into a running program.
4255 """An example of how to embed an IPython shell into a running program.
4523
4256
4524 Please see the documentation in the IPython.Shell module for more details.
4257 Please see the documentation in the IPython.Shell module for more details.
4525
4258
4526 The accompanying file example-embed-short.py has quick code fragments for
4259 The accompanying file example-embed-short.py has quick code fragments for
4527 embedding which you can cut and paste in your code once you understand how
4260 embedding which you can cut and paste in your code once you understand how
4528 things work.
4261 things work.
4529
4262
4530 The code in this file is deliberately extra-verbose, meant for learning."""
4263 The code in this file is deliberately extra-verbose, meant for learning."""
4531
4264
4532 # The basics to get you going:
4265 # The basics to get you going:
4533
4266
4534 # IPython sets the __IPYTHON__ variable so you can know if you have nested
4267 # IPython sets the __IPYTHON__ variable so you can know if you have nested
4535 # copies running.
4268 # copies running.
4536
4269
4537 # Try running this code both at the command line and from inside IPython (with
4270 # Try running this code both at the command line and from inside IPython (with
4538 # %run example-embed.py)
4271 # %run example-embed.py)
4539 try:
4272 try:
4540 __IPYTHON__
4273 __IPYTHON__
4541 except NameError:
4274 except NameError:
4542 nested = 0
4275 nested = 0
4543 args = ['']
4276 args = ['']
4544 else:
4277 else:
4545 print "Running nested copies of IPython."
4278 print "Running nested copies of IPython."
4546 print "The prompts for the nested copy have been modified"
4279 print "The prompts for the nested copy have been modified"
4547 nested = 1
4280 nested = 1
4548 # what the embedded instance will see as sys.argv:
4281 # what the embedded instance will see as sys.argv:
4549 args = ['-pi1','In <\\#>: ','-pi2',' .\\D.: ',
4282 args = ['-pi1','In <\\#>: ','-pi2',' .\\D.: ',
4550 '-po','Out<\\#>: ','-nosep']
4283 '-po','Out<\\#>: ','-nosep']
4551
4284
4552 # First import the embeddable shell class
4285 # First import the embeddable shell class
4553 from IPython.Shell import IPShellEmbed
4286 from IPython.Shell import IPShellEmbed
4554
4287
4555 # Now create an instance of the embeddable shell. The first argument is a
4288 # Now create an instance of the embeddable shell. The first argument is a
4556 # string with options exactly as you would type them if you were starting
4289 # string with options exactly as you would type them if you were starting
4557 # IPython at the system command line. Any parameters you want to define for
4290 # IPython at the system command line. Any parameters you want to define for
4558 # configuration can thus be specified here.
4291 # configuration can thus be specified here.
4559 ipshell = IPShellEmbed(args,
4292 ipshell = IPShellEmbed(args,
4560 banner = 'Dropping into IPython',
4293 banner = 'Dropping into IPython',
4561 exit_msg = 'Leaving Interpreter, back to program.')
4294 exit_msg = 'Leaving Interpreter, back to program.')
4562
4295
4563 # Make a second instance, you can have as many as you want.
4296 # Make a second instance, you can have as many as you want.
4564 if nested:
4297 if nested:
4565 args[1] = 'In2<\\#>'
4298 args[1] = 'In2<\\#>'
4566 else:
4299 else:
4567 args = ['-pi1','In2<\\#>: ','-pi2',' .\\D.: ',
4300 args = ['-pi1','In2<\\#>: ','-pi2',' .\\D.: ',
4568 '-po','Out<\\#>: ','-nosep']
4301 '-po','Out<\\#>: ','-nosep']
4569 ipshell2 = IPShellEmbed(args,banner = 'Second IPython instance.')
4302 ipshell2 = IPShellEmbed(args,banner = 'Second IPython instance.')
4570
4303
4571 print '\nHello. This is printed from the main controller program.\n'
4304 print '\nHello. This is printed from the main controller program.\n'
4572
4305
4573 # You can then call ipshell() anywhere you need it (with an optional
4306 # You can then call ipshell() anywhere you need it (with an optional
4574 # message):
4307 # message):
4575 ipshell('***Called from top level. '
4308 ipshell('***Called from top level. '
4576 'Hit Ctrl-D to exit interpreter and continue program.\n'
4309 'Hit Ctrl-D to exit interpreter and continue program.\n'
4577 'Note that if you use %kill_embedded, you can fully deactivate\n'
4310 'Note that if you use %kill_embedded, you can fully deactivate\n'
4578 'This embedded instance so it will never turn on again')
4311 'This embedded instance so it will never turn on again')
4579
4312
4580 print '\nBack in caller program, moving along...\n'
4313 print '\nBack in caller program, moving along...\n'
4581
4314
4582 #---------------------------------------------------------------------------
4315 #---------------------------------------------------------------------------
4583 # More details:
4316 # More details:
4584
4317
4585 # IPShellEmbed instances don't print the standard system banner and
4318 # IPShellEmbed instances don't print the standard system banner and
4586 # messages. The IPython banner (which actually may contain initialization
4319 # messages. The IPython banner (which actually may contain initialization
4587 # messages) is available as <instance>.IP.BANNER in case you want it.
4320 # messages) is available as <instance>.IP.BANNER in case you want it.
4588
4321
4589 # IPShellEmbed instances print the following information everytime they
4322 # IPShellEmbed instances print the following information everytime they
4590 # start:
4323 # start:
4591
4324
4592 # - A global startup banner.
4325 # - A global startup banner.
4593
4326
4594 # - A call-specific header string, which you can use to indicate where in the
4327 # - A call-specific header string, which you can use to indicate where in the
4595 # execution flow the shell is starting.
4328 # execution flow the shell is starting.
4596
4329
4597 # They also print an exit message every time they exit.
4330 # They also print an exit message every time they exit.
4598
4331
4599 # Both the startup banner and the exit message default to None, and can be set
4332 # Both the startup banner and the exit message default to None, and can be set
4600 # either at the instance constructor or at any other time with the
4333 # either at the instance constructor or at any other time with the
4601 # set_banner() and set_exit_msg() methods.
4334 # set_banner() and set_exit_msg() methods.
4602
4335
4603 # The shell instance can be also put in 'dummy' mode globally or on a per-call
4336 # The shell instance can be also put in 'dummy' mode globally or on a per-call
4604 # basis. This gives you fine control for debugging without having to change
4337 # basis. This gives you fine control for debugging without having to change
4605 # code all over the place.
4338 # code all over the place.
4606
4339
4607 # The code below illustrates all this.
4340 # The code below illustrates all this.
4608
4341
4609
4342
4610 # This is how the global banner and exit_msg can be reset at any point
4343 # This is how the global banner and exit_msg can be reset at any point
4611 ipshell.set_banner('Entering interpreter - New Banner')
4344 ipshell.set_banner('Entering interpreter - New Banner')
4612 ipshell.set_exit_msg('Leaving interpreter - New exit_msg')
4345 ipshell.set_exit_msg('Leaving interpreter - New exit_msg')
4613
4346
4614 def foo(m):
4347 def foo(m):
4615 s = 'spam'
4348 s = 'spam'
4616 ipshell('***In foo(). Try @whos, or print s or m:')
4349 ipshell('***In foo(). Try @whos, or print s or m:')
4617 print 'foo says m = ',m
4350 print 'foo says m = ',m
4618
4351
4619 def bar(n):
4352 def bar(n):
4620 s = 'eggs'
4353 s = 'eggs'
4621 ipshell('***In bar(). Try @whos, or print s or n:')
4354 ipshell('***In bar(). Try @whos, or print s or n:')
4622 print 'bar says n = ',n
4355 print 'bar says n = ',n
4623
4356
4624 # Some calls to the above functions which will trigger IPython:
4357 # Some calls to the above functions which will trigger IPython:
4625 print 'Main program calling foo("eggs")\n'
4358 print 'Main program calling foo("eggs")\n'
4626 foo('eggs')
4359 foo('eggs')
4627
4360
4628 # The shell can be put in 'dummy' mode where calls to it silently return. This
4361 # The shell can be put in 'dummy' mode where calls to it silently return. This
4629 # allows you, for example, to globally turn off debugging for a program with a
4362 # allows you, for example, to globally turn off debugging for a program with a
4630 # single call.
4363 # single call.
4631 ipshell.set_dummy_mode(1)
4364 ipshell.set_dummy_mode(1)
4632 print '\nTrying to call IPython which is now "dummy":'
4365 print '\nTrying to call IPython which is now "dummy":'
4633 ipshell()
4366 ipshell()
4634 print 'Nothing happened...'
4367 print 'Nothing happened...'
4635 # The global 'dummy' mode can still be overridden for a single call
4368 # The global 'dummy' mode can still be overridden for a single call
4636 print '\nOverriding dummy mode manually:'
4369 print '\nOverriding dummy mode manually:'
4637 ipshell(dummy=0)
4370 ipshell(dummy=0)
4638
4371
4639 # Reactivate the IPython shell
4372 # Reactivate the IPython shell
4640 ipshell.set_dummy_mode(0)
4373 ipshell.set_dummy_mode(0)
4641
4374
4642 print 'You can even have multiple embedded instances:'
4375 print 'You can even have multiple embedded instances:'
4643 ipshell2()
4376 ipshell2()
4644
4377
4645 print '\nMain program calling bar("spam")\n'
4378 print '\nMain program calling bar("spam")\n'
4646 bar('spam')
4379 bar('spam')
4647
4380
4648 print 'Main program finished. Bye!'
4381 print 'Main program finished. Bye!'
4649
4382
4650 #********************** End of file <example-embed.py> ***********************
4383 #********************** End of file <example-embed.py> ***********************
4651
4384
4652 Once you understand how the system functions, you can use the following
4385 Once you understand how the system functions, you can use the following
4653 code fragments in your programs which are ready for cut and paste::
4386 code fragments in your programs which are ready for cut and paste::
4654
4387
4655
4388
4656 """Quick code snippets for embedding IPython into other programs.
4389 """Quick code snippets for embedding IPython into other programs.
4657
4390
4658 See example-embed.py for full details, this file has the bare minimum code for
4391 See example-embed.py for full details, this file has the bare minimum code for
4659 cut and paste use once you understand how to use the system."""
4392 cut and paste use once you understand how to use the system."""
4660
4393
4661 #---------------------------------------------------------------------------
4394 #---------------------------------------------------------------------------
4662 # This code loads IPython but modifies a few things if it detects it's running
4395 # This code loads IPython but modifies a few things if it detects it's running
4663 # embedded in another IPython session (helps avoid confusion)
4396 # embedded in another IPython session (helps avoid confusion)
4664
4397
4665 try:
4398 try:
4666 __IPYTHON__
4399 __IPYTHON__
4667 except NameError:
4400 except NameError:
4668 argv = ['']
4401 argv = ['']
4669 banner = exit_msg = ''
4402 banner = exit_msg = ''
4670 else:
4403 else:
4671 # Command-line options for IPython (a list like sys.argv)
4404 # Command-line options for IPython (a list like sys.argv)
4672 argv = ['-pi1','In <\\#>:','-pi2',' .\\D.:','-po','Out<\\#>:']
4405 argv = ['-pi1','In <\\#>:','-pi2',' .\\D.:','-po','Out<\\#>:']
4673 banner = '*** Nested interpreter ***'
4406 banner = '*** Nested interpreter ***'
4674 exit_msg = '*** Back in main IPython ***'
4407 exit_msg = '*** Back in main IPython ***'
4675
4408
4676 # First import the embeddable shell class
4409 # First import the embeddable shell class
4677 from IPython.Shell import IPShellEmbed
4410 from IPython.Shell import IPShellEmbed
4678 # Now create the IPython shell instance. Put ipshell() anywhere in your code
4411 # Now create the IPython shell instance. Put ipshell() anywhere in your code
4679 # where you want it to open.
4412 # where you want it to open.
4680 ipshell = IPShellEmbed(argv,banner=banner,exit_msg=exit_msg)
4413 ipshell = IPShellEmbed(argv,banner=banner,exit_msg=exit_msg)
4681
4414
4682 #---------------------------------------------------------------------------
4415 #---------------------------------------------------------------------------
4683 # This code will load an embeddable IPython shell always with no changes for
4416 # This code will load an embeddable IPython shell always with no changes for
4684 # nested embededings.
4417 # nested embededings.
4685
4418
4686 from IPython.Shell import IPShellEmbed
4419 from IPython.Shell import IPShellEmbed
4687 ipshell = IPShellEmbed()
4420 ipshell = IPShellEmbed()
4688 # Now ipshell() will open IPython anywhere in the code.
4421 # Now ipshell() will open IPython anywhere in the code.
4689
4422
4690 #---------------------------------------------------------------------------
4423 #---------------------------------------------------------------------------
4691 # This code loads an embeddable shell only if NOT running inside
4424 # This code loads an embeddable shell only if NOT running inside
4692 # IPython. Inside IPython, the embeddable shell variable ipshell is just a
4425 # IPython. Inside IPython, the embeddable shell variable ipshell is just a
4693 # dummy function.
4426 # dummy function.
4694
4427
4695 try:
4428 try:
4696 __IPYTHON__
4429 __IPYTHON__
4697 except NameError:
4430 except NameError:
4698 from IPython.Shell import IPShellEmbed
4431 from IPython.Shell import IPShellEmbed
4699 ipshell = IPShellEmbed()
4432 ipshell = IPShellEmbed()
4700 # Now ipshell() will open IPython anywhere in the code
4433 # Now ipshell() will open IPython anywhere in the code
4701 else:
4434 else:
4702 # Define a dummy ipshell() so the same code doesn't crash inside an
4435 # Define a dummy ipshell() so the same code doesn't crash inside an
4703 # interactive IPython
4436 # interactive IPython
4704 def ipshell(): pass
4437 def ipshell(): pass
4705
4438
4706 #******************* End of file <example-embed-short.py> ********************
4439 #******************* End of file <example-embed-short.py> ********************
4707
4440
4708 Using the Python debugger (pdb)
4441 Using the Python debugger (pdb)
4709 ===============================
4442 ===============================
4710
4443
4711 Running entire programs via pdb
4444 Running entire programs via pdb
4712 -------------------------------
4445 -------------------------------
4713
4446
4714 pdb, the Python debugger, is a powerful interactive debugger which
4447 pdb, the Python debugger, is a powerful interactive debugger which
4715 allows you to step through code, set breakpoints, watch variables,
4448 allows you to step through code, set breakpoints, watch variables,
4716 etc. IPython makes it very easy to start any script under the control
4449 etc. IPython makes it very easy to start any script under the control
4717 of pdb, regardless of whether you have wrapped it into a 'main()'
4450 of pdb, regardless of whether you have wrapped it into a 'main()'
4718 function or not. For this, simply type '%run -d myscript' at an
4451 function or not. For this, simply type '%run -d myscript' at an
4719 IPython prompt. See the %run command's documentation (via '%run?' or
4452 IPython prompt. See the %run command's documentation (via '%run?' or
4720 in Sec. magic_ for more details, including how to control where pdb
4453 in Sec. magic_ for more details, including how to control where pdb
4721 will stop execution first.
4454 will stop execution first.
4722
4455
4723 For more information on the use of the pdb debugger, read the included
4456 For more information on the use of the pdb debugger, read the included
4724 pdb.doc file (part of the standard Python distribution). On a stock
4457 pdb.doc file (part of the standard Python distribution). On a stock
4725 Linux system it is located at /usr/lib/python2.3/pdb.doc, but the
4458 Linux system it is located at /usr/lib/python2.3/pdb.doc, but the
4726 easiest way to read it is by using the help() function of the pdb module
4459 easiest way to read it is by using the help() function of the pdb module
4727 as follows (in an IPython prompt):
4460 as follows (in an IPython prompt):
4728
4461
4729 In [1]: import pdb
4462 In [1]: import pdb
4730 In [2]: pdb.help()
4463 In [2]: pdb.help()
4731
4464
4732 This will load the pdb.doc document in a file viewer for you automatically.
4465 This will load the pdb.doc document in a file viewer for you automatically.
4733
4466
4734
4467
4735 Automatic invocation of pdb on exceptions
4468 Automatic invocation of pdb on exceptions
4736 -----------------------------------------
4469 -----------------------------------------
4737
4470
4738 IPython, if started with the -pdb option (or if the option is set in
4471 IPython, if started with the -pdb option (or if the option is set in
4739 your rc file) can call the Python pdb debugger every time your code
4472 your rc file) can call the Python pdb debugger every time your code
4740 triggers an uncaught exception. This feature
4473 triggers an uncaught exception. This feature
4741 can also be toggled at any time with the %pdb magic command. This can be
4474 can also be toggled at any time with the %pdb magic command. This can be
4742 extremely useful in order to find the origin of subtle bugs, because pdb
4475 extremely useful in order to find the origin of subtle bugs, because pdb
4743 opens up at the point in your code which triggered the exception, and
4476 opens up at the point in your code which triggered the exception, and
4744 while your program is at this point 'dead', all the data is still
4477 while your program is at this point 'dead', all the data is still
4745 available and you can walk up and down the stack frame and understand
4478 available and you can walk up and down the stack frame and understand
4746 the origin of the problem.
4479 the origin of the problem.
4747
4480
4748 Furthermore, you can use these debugging facilities both with the
4481 Furthermore, you can use these debugging facilities both with the
4749 embedded IPython mode and without IPython at all. For an embedded shell
4482 embedded IPython mode and without IPython at all. For an embedded shell
4750 (see sec. Embedding_), simply call the constructor with
4483 (see sec. Embedding_), simply call the constructor with
4751 '-pdb' in the argument string and automatically pdb will be called if an
4484 '-pdb' in the argument string and automatically pdb will be called if an
4752 uncaught exception is triggered by your code.
4485 uncaught exception is triggered by your code.
4753
4486
4754 For stand-alone use of the feature in your programs which do not use
4487 For stand-alone use of the feature in your programs which do not use
4755 IPython at all, put the following lines toward the top of your 'main'
4488 IPython at all, put the following lines toward the top of your 'main'
4756 routine::
4489 routine::
4757
4490
4758 import sys,IPython.ultraTB
4491 import sys,IPython.ultraTB
4759 sys.excepthook = IPython.ultraTB.FormattedTB(mode='Verbose',
4492 sys.excepthook = IPython.ultraTB.FormattedTB(mode='Verbose',
4760 color_scheme='Linux', call_pdb=1)
4493 color_scheme='Linux', call_pdb=1)
4761
4494
4762 The mode keyword can be either 'Verbose' or 'Plain', giving either very
4495 The mode keyword can be either 'Verbose' or 'Plain', giving either very
4763 detailed or normal tracebacks respectively. The color_scheme keyword can
4496 detailed or normal tracebacks respectively. The color_scheme keyword can
4764 be one of 'NoColor', 'Linux' (default) or 'LightBG'. These are the same
4497 be one of 'NoColor', 'Linux' (default) or 'LightBG'. These are the same
4765 options which can be set in IPython with -colors and -xmode.
4498 options which can be set in IPython with -colors and -xmode.
4766
4499
4767 This will give any of your programs detailed, colored tracebacks with
4500 This will give any of your programs detailed, colored tracebacks with
4768 automatic invocation of pdb.
4501 automatic invocation of pdb.
4769
4502
4770
4503
4771 Extensions for syntax processing
4504 Extensions for syntax processing
4772 ================================
4505 ================================
4773
4506
4774 This isn't for the faint of heart, because the potential for breaking
4507 This isn't for the faint of heart, because the potential for breaking
4775 things is quite high. But it can be a very powerful and useful feature.
4508 things is quite high. But it can be a very powerful and useful feature.
4776 In a nutshell, you can redefine the way IPython processes the user input
4509 In a nutshell, you can redefine the way IPython processes the user input
4777 line to accept new, special extensions to the syntax without needing to
4510 line to accept new, special extensions to the syntax without needing to
4778 change any of IPython's own code.
4511 change any of IPython's own code.
4779
4512
4780 In the IPython/Extensions directory you will find some examples
4513 In the IPython/Extensions directory you will find some examples
4781 supplied, which we will briefly describe now. These can be used 'as is'
4514 supplied, which we will briefly describe now. These can be used 'as is'
4782 (and both provide very useful functionality), or you can use them as a
4515 (and both provide very useful functionality), or you can use them as a
4783 starting point for writing your own extensions.
4516 starting point for writing your own extensions.
4784
4517
4785
4518
4786 Pasting of code starting with '>>> ' or '... '
4519 Pasting of code starting with '>>> ' or '... '
4787 ----------------------------------------------
4520 ----------------------------------------------
4788
4521
4789 In the python tutorial it is common to find code examples which have
4522 In the python tutorial it is common to find code examples which have
4790 been taken from real python sessions. The problem with those is that all
4523 been taken from real python sessions. The problem with those is that all
4791 the lines begin with either '>>> ' or '... ', which makes it impossible
4524 the lines begin with either '>>> ' or '... ', which makes it impossible
4792 to paste them all at once. One must instead do a line by line manual
4525 to paste them all at once. One must instead do a line by line manual
4793 copying, carefully removing the leading extraneous characters.
4526 copying, carefully removing the leading extraneous characters.
4794
4527
4795 This extension identifies those starting characters and removes them
4528 This extension identifies those starting characters and removes them
4796 from the input automatically, so that one can paste multi-line examples
4529 from the input automatically, so that one can paste multi-line examples
4797 directly into IPython, saving a lot of time. Please look at the file
4530 directly into IPython, saving a lot of time. Please look at the file
4798 InterpreterPasteInput.py in the IPython/Extensions directory for details
4531 InterpreterPasteInput.py in the IPython/Extensions directory for details
4799 on how this is done.
4532 on how this is done.
4800
4533
4801 IPython comes with a special profile enabling this feature, called
4534 IPython comes with a special profile enabling this feature, called
4802 tutorial. Simply start IPython via 'ipython -p tutorial' and the feature
4535 tutorial. Simply start IPython via 'ipython -p tutorial' and the feature
4803 will be available. In a normal IPython session you can activate the
4536 will be available. In a normal IPython session you can activate the
4804 feature by importing the corresponding module with:
4537 feature by importing the corresponding module with:
4805 In [1]: import IPython.Extensions.InterpreterPasteInput
4538 In [1]: import IPython.Extensions.InterpreterPasteInput
4806
4539
4807 The following is a 'screenshot' of how things work when this extension
4540 The following is a 'screenshot' of how things work when this extension
4808 is on, copying an example from the standard tutorial::
4541 is on, copying an example from the standard tutorial::
4809
4542
4810 IPython profile: tutorial
4543 IPython profile: tutorial
4811
4544
4812 *** Pasting of code with ">>>" or "..." has been enabled.
4545 *** Pasting of code with ">>>" or "..." has been enabled.
4813
4546
4814 In [1]: >>> def fib2(n): # return Fibonacci series up to n
4547 In [1]: >>> def fib2(n): # return Fibonacci series up to n
4815 ...: ... """Return a list containing the Fibonacci series up to
4548 ...: ... """Return a list containing the Fibonacci series up to
4816 n."""
4549 n."""
4817 ...: ... result = []
4550 ...: ... result = []
4818 ...: ... a, b = 0, 1
4551 ...: ... a, b = 0, 1
4819 ...: ... while b < n:
4552 ...: ... while b < n:
4820 ...: ... result.append(b) # see below
4553 ...: ... result.append(b) # see below
4821 ...: ... a, b = b, a+b
4554 ...: ... a, b = b, a+b
4822 ...: ... return result
4555 ...: ... return result
4823 ...:
4556 ...:
4824
4557
4825 In [2]: fib2(10)
4558 In [2]: fib2(10)
4826 Out[2]: [1, 1, 2, 3, 5, 8]
4559 Out[2]: [1, 1, 2, 3, 5, 8]
4827
4560
4828 Note that as currently written, this extension does not recognize
4561 Note that as currently written, this extension does not recognize
4829 IPython's prompts for pasting. Those are more complicated, since the
4562 IPython's prompts for pasting. Those are more complicated, since the
4830 user can change them very easily, they involve numbers and can vary in
4563 user can change them very easily, they involve numbers and can vary in
4831 length. One could however extract all the relevant information from the
4564 length. One could however extract all the relevant information from the
4832 IPython instance and build an appropriate regular expression. This is
4565 IPython instance and build an appropriate regular expression. This is
4833 left as an exercise for the reader.
4566 left as an exercise for the reader.
4834
4567
4835
4568
4836 Input of physical quantities with units
4569 Input of physical quantities with units
4837 ---------------------------------------
4570 ---------------------------------------
4838
4571
4839 The module PhysicalQInput allows a simplified form of input for physical
4572 The module PhysicalQInput allows a simplified form of input for physical
4840 quantities with units. This file is meant to be used in conjunction with
4573 quantities with units. This file is meant to be used in conjunction with
4841 the PhysicalQInteractive module (in the same directory) and
4574 the PhysicalQInteractive module (in the same directory) and
4842 Physics.PhysicalQuantities from Konrad Hinsen's ScientificPython
4575 Physics.PhysicalQuantities from Konrad Hinsen's ScientificPython
4843 (http://dirac.cnrs-orleans.fr/ScientificPython/).
4576 (http://dirac.cnrs-orleans.fr/ScientificPython/).
4844
4577
4845 The Physics.PhysicalQuantities module defines PhysicalQuantity objects,
4578 The Physics.PhysicalQuantities module defines PhysicalQuantity objects,
4846 but these must be declared as instances of a class. For example, to
4579 but these must be declared as instances of a class. For example, to
4847 define v as a velocity of 3 m/s, normally you would write::
4580 define v as a velocity of 3 m/s, normally you would write::
4848
4581
4849 In [1]: v = PhysicalQuantity(3,'m/s')
4582 In [1]: v = PhysicalQuantity(3,'m/s')
4850
4583
4851 Using the PhysicalQ_Input extension this can be input instead as:
4584 Using the PhysicalQ_Input extension this can be input instead as:
4852 In [1]: v = 3 m/s
4585 In [1]: v = 3 m/s
4853 which is much more convenient for interactive use (even though it is
4586 which is much more convenient for interactive use (even though it is
4854 blatantly invalid Python syntax).
4587 blatantly invalid Python syntax).
4855
4588
4856 The physics profile supplied with IPython (enabled via 'ipython -p
4589 The physics profile supplied with IPython (enabled via 'ipython -p
4857 physics') uses these extensions, which you can also activate with:
4590 physics') uses these extensions, which you can also activate with:
4858
4591
4859 from math import * # math MUST be imported BEFORE PhysicalQInteractive
4592 from math import * # math MUST be imported BEFORE PhysicalQInteractive
4860 from IPython.Extensions.PhysicalQInteractive import *
4593 from IPython.Extensions.PhysicalQInteractive import *
4861 import IPython.Extensions.PhysicalQInput
4594 import IPython.Extensions.PhysicalQInput
4862
4595
4863
4596
4864 IPython as a system shell - the 'Sh' profile
4597 IPython as a system shell - the 'Sh' profile
4865 ============================================
4598 ============================================
4866
4599
4867 The 'sh' profile optimizes IPython for system shell usage. Apart from
4600 The 'sh' profile optimizes IPython for system shell usage. Apart from
4868 certain job control functionality that is present in unix (ctrl+z does
4601 certain job control functionality that is present in unix (ctrl+z does
4869 "suspend"), the sh profile should provide you with most of the
4602 "suspend"), the sh profile should provide you with most of the
4870 functionality you use daily in system shell, and more. Invoke IPython
4603 functionality you use daily in system shell, and more. Invoke IPython
4871 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
4604 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
4872 the "pysh" shortcut in start menu.
4605 the "pysh" shortcut in start menu.
4873
4606
4874 If you want to use the features of sh profile as your defaults (which
4607 If you want to use the features of sh profile as your defaults (which
4875 might be a good idea if you use other profiles a lot of the time but
4608 might be a good idea if you use other profiles a lot of the time but
4876 still want the convenience of sh profile), add ``import ipy_profile_sh``
4609 still want the convenience of sh profile), add ``import ipy_profile_sh``
4877 to your ~/.ipython/ipy_user_conf.py.
4610 to your ~/.ipython/ipy_user_conf.py.
4878
4611
4879 The 'sh' profile is different from the default profile in that:
4612 The 'sh' profile is different from the default profile in that:
4880
4613
4881 * Prompt shows the current directory
4614 * Prompt shows the current directory
4882 * Spacing between prompts and input is more compact (no padding with
4615 * Spacing between prompts and input is more compact (no padding with
4883 empty lines). The startup banner is more compact as well.
4616 empty lines). The startup banner is more compact as well.
4884 * System commands are directly available (in alias table) without
4617 * System commands are directly available (in alias table) without
4885 requesting %rehashx - however, if you install new programs along
4618 requesting %rehashx - however, if you install new programs along
4886 your PATH, you might want to run %rehashx to update the persistent
4619 your PATH, you might want to run %rehashx to update the persistent
4887 alias table
4620 alias table
4888 * Macros are stored in raw format by default. That is, instead of
4621 * Macros are stored in raw format by default. That is, instead of
4889 '_ip.system("cat foo"), the macro will contain text 'cat foo')
4622 '_ip.system("cat foo"), the macro will contain text 'cat foo')
4890 * Autocall is in full mode
4623 * Autocall is in full mode
4891 * Calling "up" does "cd .."
4624 * Calling "up" does "cd .."
4892
4625
4893 The 'sh' profile is different from the now-obsolete (and unavailable)
4626 The 'sh' profile is different from the now-obsolete (and unavailable)
4894 'pysh' profile in that:
4627 'pysh' profile in that:
4895
4628
4896 * '$$var = command' and '$var = command' syntax is not supported
4629 * '$$var = command' and '$var = command' syntax is not supported
4897 * anymore. Use 'var = !command' instead (incidentally, this is
4630 * anymore. Use 'var = !command' instead (incidentally, this is
4898 * available in all IPython profiles). Note that !!command *will*
4631 * available in all IPython profiles). Note that !!command *will*
4899 * work.
4632 * work.
4900
4633
4901 Aliases
4634 Aliases
4902 -------
4635 -------
4903
4636
4904 All of your $PATH has been loaded as IPython aliases, so you should be
4637 All of your $PATH has been loaded as IPython aliases, so you should be
4905 able to type any normal system command and have it executed. See
4638 able to type any normal system command and have it executed. See
4906 %alias? and %unalias? for details on the alias facilities. See also
4639 %alias? and %unalias? for details on the alias facilities. See also
4907 %rehashx? for details on the mechanism used to load $PATH.
4640 %rehashx? for details on the mechanism used to load $PATH.
4908
4641
4909
4642
4910 Directory management
4643 Directory management
4911 --------------------
4644 --------------------
4912
4645
4913 Since each command passed by ipython to the underlying system is executed
4646 Since each command passed by ipython to the underlying system is executed
4914 in a subshell which exits immediately, you can NOT use !cd to navigate
4647 in a subshell which exits immediately, you can NOT use !cd to navigate
4915 the filesystem.
4648 the filesystem.
4916
4649
4917 IPython provides its own builtin '%cd' magic command to move in the
4650 IPython provides its own builtin '%cd' magic command to move in the
4918 filesystem (the % is not required with automagic on). It also maintains
4651 filesystem (the % is not required with automagic on). It also maintains
4919 a list of visited directories (use %dhist to see it) and allows direct
4652 a list of visited directories (use %dhist to see it) and allows direct
4920 switching to any of them. Type 'cd?' for more details.
4653 switching to any of them. Type 'cd?' for more details.
4921
4654
4922 %pushd, %popd and %dirs are provided for directory stack handling.
4655 %pushd, %popd and %dirs are provided for directory stack handling.
4923
4656
4924
4657
4925 Enabled extensions
4658 Enabled extensions
4926 ------------------
4659 ------------------
4927
4660
4928 Some extensions, listed below, are enabled as default in this profile.
4661 Some extensions, listed below, are enabled as default in this profile.
4929
4662
4930 envpersist
4663 envpersist
4931 ++++++++++
4664 ++++++++++
4932
4665
4933 %env can be used to "remember" environment variable manipulations. Examples::
4666 %env can be used to "remember" environment variable manipulations. Examples::
4934
4667
4935 %env - Show all environment variables
4668 %env - Show all environment variables
4936 %env VISUAL=jed - set VISUAL to jed
4669 %env VISUAL=jed - set VISUAL to jed
4937 %env PATH+=;/foo - append ;foo to PATH
4670 %env PATH+=;/foo - append ;foo to PATH
4938 %env PATH+=;/bar - also append ;bar to PATH
4671 %env PATH+=;/bar - also append ;bar to PATH
4939 %env PATH-=/wbin; - prepend /wbin; to PATH
4672 %env PATH-=/wbin; - prepend /wbin; to PATH
4940 %env -d VISUAL - forget VISUAL persistent val
4673 %env -d VISUAL - forget VISUAL persistent val
4941 %env -p - print all persistent env modifications
4674 %env -p - print all persistent env modifications
4942
4675
4943 ipy_which
4676 ipy_which
4944 +++++++++
4677 +++++++++
4945
4678
4946 %which magic command. Like 'which' in unix, but knows about ipython aliases.
4679 %which magic command. Like 'which' in unix, but knows about ipython aliases.
4947
4680
4948 Example::
4681 Example::
4949
4682
4950 [C:/ipython]|14> %which st
4683 [C:/ipython]|14> %which st
4951 st -> start .
4684 st -> start .
4952 [C:/ipython]|15> %which d
4685 [C:/ipython]|15> %which d
4953 d -> dir /w /og /on
4686 d -> dir /w /og /on
4954 [C:/ipython]|16> %which cp
4687 [C:/ipython]|16> %which cp
4955 cp -> cp
4688 cp -> cp
4956 == c:\bin\cp.exe
4689 == c:\bin\cp.exe
4957 c:\bin\cp.exe
4690 c:\bin\cp.exe
4958
4691
4959 ipy_app_completers
4692 ipy_app_completers
4960 ++++++++++++++++++
4693 ++++++++++++++++++
4961
4694
4962 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
4695 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
4963
4696
4964 ipy_rehashdir
4697 ipy_rehashdir
4965 +++++++++++++
4698 +++++++++++++
4966
4699
4967 Allows you to add system command aliases for commands that are not along your path. Let's say that you just installed Putty and want to be able to invoke it without adding it to path, you can create the alias for it with rehashdir::
4700 Allows you to add system command aliases for commands that are not along your path. Let's say that you just installed Putty and want to be able to invoke it without adding it to path, you can create the alias for it with rehashdir::
4968
4701
4969 [~]|22> cd c:/opt/PuTTY/
4702 [~]|22> cd c:/opt/PuTTY/
4970 [c:opt/PuTTY]|23> rehashdir .
4703 [c:opt/PuTTY]|23> rehashdir .
4971 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
4704 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
4972
4705
4973 Now, you can execute any of those commams directly::
4706 Now, you can execute any of those commams directly::
4974
4707
4975 [c:opt/PuTTY]|24> cd
4708 [c:opt/PuTTY]|24> cd
4976 [~]|25> putty
4709 [~]|25> putty
4977
4710
4978 (the putty window opens).
4711 (the putty window opens).
4979
4712
4980 If you want to store the alias so that it will always be available, do '%store putty'. If you want to %store all these aliases persistently, just do it in a for loop::
4713 If you want to store the alias so that it will always be available, do '%store putty'. If you want to %store all these aliases persistently, just do it in a for loop::
4981
4714
4982 [~]|27> for a in _23:
4715 [~]|27> for a in _23:
4983 |..> %store $a
4716 |..> %store $a
4984 |..>
4717 |..>
4985 |..>
4718 |..>
4986 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
4719 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
4987 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
4720 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
4988 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
4721 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
4989 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
4722 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
4990 ...
4723 ...
4991
4724
4992 mglob
4725 mglob
4993 +++++
4726 +++++
4994
4727
4995 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
4728 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
4996
4729
4997 [c:/ipython]|9> mglob *.py
4730 [c:/ipython]|9> mglob *.py
4998 [c:/ipython]|10> mglob *.py rec:*.txt
4731 [c:/ipython]|10> mglob *.py rec:*.txt
4999 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
4732 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
5000
4733
5001 Note that the first 2 calls will put the file list in result history (_, _9, _10), and the last one will assign it to 'workfiles'.
4734 Note that the first 2 calls will put the file list in result history (_, _9, _10), and the last one will assign it to 'workfiles'.
5002
4735
5003
4736
5004 Prompt customization
4737 Prompt customization
5005 --------------------
4738 --------------------
5006
4739
5007 The sh profile uses the following prompt configurations::
4740 The sh profile uses the following prompt configurations::
5008
4741
5009 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
4742 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
5010 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
4743 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
5011
4744
5012 You can change the prompt configuration to your liking by editing
4745 You can change the prompt configuration to your liking by editing
5013 ipy_user_conf.py.
4746 ipy_user_conf.py.
5014
4747
5015 String lists
4748 String lists
5016 ============
4749 ============
5017
4750
5018 String lists (IPython.genutils.SList) are handy way to process output
4751 String lists (IPython.genutils.SList) are handy way to process output
5019 from system commands. They are produced by ``var = !cmd`` syntax.
4752 from system commands. They are produced by ``var = !cmd`` syntax.
5020
4753
5021 First, we acquire the output of 'ls -l'::
4754 First, we acquire the output of 'ls -l'::
5022
4755
5023 [Q:doc/examples]|2> lines = !ls -l
4756 [Q:doc/examples]|2> lines = !ls -l
5024 ==
4757 ==
5025 ['total 23',
4758 ['total 23',
5026 '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
4759 '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
5027 '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
4760 '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
5028 '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
4761 '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
5029 '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
4762 '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
5030 '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
4763 '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
5031 '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
4764 '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
5032 '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
4765 '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
5033
4766
5034 Now, let's take a look at the contents of 'lines' (the first number is
4767 Now, let's take a look at the contents of 'lines' (the first number is
5035 the list element number)::
4768 the list element number)::
5036
4769
5037 [Q:doc/examples]|3> lines
4770 [Q:doc/examples]|3> lines
5038 <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
4771 <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
5039
4772
5040 0: total 23
4773 0: total 23
5041 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
4774 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
5042 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
4775 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
5043 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
4776 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
5044 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
4777 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
5045 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
4778 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
5046 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
4779 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
5047 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
4780 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
5048
4781
5049 Now, let's filter out the 'embed' lines::
4782 Now, let's filter out the 'embed' lines::
5050
4783
5051 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
4784 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
5052 [Q:doc/examples]|5> l2
4785 [Q:doc/examples]|5> l2
5053 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
4786 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
5054
4787
5055 0: total 23
4788 0: total 23
5056 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
4789 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
5057 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
4790 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
5058 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
4791 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
5059 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
4792 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
5060 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
4793 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
5061
4794
5062 Now, we want strings having just file names and permissions::
4795 Now, we want strings having just file names and permissions::
5063
4796
5064 [Q:doc/examples]|6> l2.fields(8,0)
4797 [Q:doc/examples]|6> l2.fields(8,0)
5065 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
4798 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
5066
4799
5067 0: total
4800 0: total
5068 1: example-demo.py -rw-rw-rw-
4801 1: example-demo.py -rw-rw-rw-
5069 2: example-gnuplot.py -rwxrwxrwx
4802 2: example-gnuplot.py -rwxrwxrwx
5070 3: extension.py -rwxrwxrwx
4803 3: extension.py -rwxrwxrwx
5071 4: seteditor.py -rwxrwxrwx
4804 4: seteditor.py -rwxrwxrwx
5072 5: seteditor.pyc -rwxrwxrwx
4805 5: seteditor.pyc -rwxrwxrwx
5073
4806
5074 Note how the line with 'total' does not raise IndexError.
4807 Note how the line with 'total' does not raise IndexError.
5075
4808
5076 If you want to split these (yielding lists), call fields() without
4809 If you want to split these (yielding lists), call fields() without
5077 arguments::
4810 arguments::
5078
4811
5079 [Q:doc/examples]|7> _.fields()
4812 [Q:doc/examples]|7> _.fields()
5080 <7>
4813 <7>
5081 [['total'],
4814 [['total'],
5082 ['example-demo.py', '-rw-rw-rw-'],
4815 ['example-demo.py', '-rw-rw-rw-'],
5083 ['example-gnuplot.py', '-rwxrwxrwx'],
4816 ['example-gnuplot.py', '-rwxrwxrwx'],
5084 ['extension.py', '-rwxrwxrwx'],
4817 ['extension.py', '-rwxrwxrwx'],
5085 ['seteditor.py', '-rwxrwxrwx'],
4818 ['seteditor.py', '-rwxrwxrwx'],
5086 ['seteditor.pyc', '-rwxrwxrwx']]
4819 ['seteditor.pyc', '-rwxrwxrwx']]
5087
4820
5088 If you want to pass these separated with spaces to a command (typical
4821 If you want to pass these separated with spaces to a command (typical
5089 for lists if files), use the .s property::
4822 for lists if files), use the .s property::
5090
4823
5091
4824
5092 [Q:doc/examples]|13> files = l2.fields(8).s
4825 [Q:doc/examples]|13> files = l2.fields(8).s
5093 [Q:doc/examples]|14> files
4826 [Q:doc/examples]|14> files
5094 <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
4827 <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
5095 [Q:doc/examples]|15> ls $files
4828 [Q:doc/examples]|15> ls $files
5096 example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
4829 example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
5097
4830
5098 SLists are inherited from normal python lists, so every list method is
4831 SLists are inherited from normal python lists, so every list method is
5099 available::
4832 available::
5100
4833
5101 [Q:doc/examples]|21> lines.append('hey')
4834 [Q:doc/examples]|21> lines.append('hey')
5102
4835
5103
4836
5104 Real world example: remove all files outside version control
4837 Real world example: remove all files outside version control
5105 ------------------------------------------------------------
4838 ------------------------------------------------------------
5106
4839
5107 First, capture output of "hg status"::
4840 First, capture output of "hg status"::
5108
4841
5109 [Q:/ipython]|28> out = !hg status
4842 [Q:/ipython]|28> out = !hg status
5110 ==
4843 ==
5111 ['M IPython\\Extensions\\ipy_kitcfg.py',
4844 ['M IPython\\Extensions\\ipy_kitcfg.py',
5112 'M IPython\\Extensions\\ipy_rehashdir.py',
4845 'M IPython\\Extensions\\ipy_rehashdir.py',
5113 ...
4846 ...
5114 '? build\\lib\\IPython\\Debugger.py',
4847 '? build\\lib\\IPython\\Debugger.py',
5115 '? build\\lib\\IPython\\Extensions\\InterpreterExec.py',
4848 '? build\\lib\\IPython\\Extensions\\InterpreterExec.py',
5116 '? build\\lib\\IPython\\Extensions\\InterpreterPasteInput.py',
4849 '? build\\lib\\IPython\\Extensions\\InterpreterPasteInput.py',
5117 ...
4850 ...
5118
4851
5119 (lines starting with ? are not under version control).
4852 (lines starting with ? are not under version control).
5120
4853
5121 ::
4854 ::
5122
4855
5123 [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
4856 [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
5124 [Q:/ipython]|36> junk
4857 [Q:/ipython]|36> junk
5125 <36> SList (.p, .n, .l, .s, .grep(), .fields() availab
4858 <36> SList (.p, .n, .l, .s, .grep(), .fields() availab
5126 ...
4859 ...
5127 10: build\bdist.win32\winexe\temp\_ctypes.py
4860 10: build\bdist.win32\winexe\temp\_ctypes.py
5128 11: build\bdist.win32\winexe\temp\_hashlib.py
4861 11: build\bdist.win32\winexe\temp\_hashlib.py
5129 12: build\bdist.win32\winexe\temp\_socket.py
4862 12: build\bdist.win32\winexe\temp\_socket.py
5130
4863
5131 Now we can just remove these files by doing 'rm $junk.s'.
4864 Now we can just remove these files by doing 'rm $junk.s'.
5132
4865
5133 The .s, .n, .p properties
4866 The .s, .n, .p properties
5134 -------------------------
4867 -------------------------
5135
4868
5136 The '.s' property returns one string where lines are separated by
4869 The '.s' property returns one string where lines are separated by
5137 single space (for convenient passing to system commands). The '.n'
4870 single space (for convenient passing to system commands). The '.n'
5138 property return one string where the lines are separated by '\n'
4871 property return one string where the lines are separated by '\n'
5139 (i.e. the original output of the function). If the items in string
4872 (i.e. the original output of the function). If the items in string
5140 list are file names, '.p' can be used to get a list of "path" objects
4873 list are file names, '.p' can be used to get a list of "path" objects
5141 for convenient file manipulation.
4874 for convenient file manipulation.
5142
4875
5143
4876
5144 Threading support
4877 Threading support
5145 =================
4878 =================
5146
4879
5147 WARNING: The threading support is still somewhat experimental, and it
4880 WARNING: The threading support is still somewhat experimental, and it
5148 has only seen reasonable testing under Linux. Threaded code is
4881 has only seen reasonable testing under Linux. Threaded code is
5149 particularly tricky to debug, and it tends to show extremely
4882 particularly tricky to debug, and it tends to show extremely
5150 platform-dependent behavior. Since I only have access to Linux machines,
4883 platform-dependent behavior. Since I only have access to Linux machines,
5151 I will have to rely on user's experiences and assistance for this area
4884 I will have to rely on user's experiences and assistance for this area
5152 of IPython to improve under other platforms.
4885 of IPython to improve under other platforms.
5153
4886
5154 IPython, via the -gthread , -qthread, -q4thread and -wthread options
4887 IPython, via the -gthread , -qthread, -q4thread and -wthread options
5155 (described in Sec. `Threading options`_), can run in
4888 (described in Sec. `Threading options`_), can run in
5156 multithreaded mode to support pyGTK, Qt3, Qt4 and WXPython applications
4889 multithreaded mode to support pyGTK, Qt3, Qt4 and WXPython applications
5157 respectively. These GUI toolkits need to control the python main loop of
4890 respectively. These GUI toolkits need to control the python main loop of
5158 execution, so under a normal Python interpreter, starting a pyGTK, Qt3,
4891 execution, so under a normal Python interpreter, starting a pyGTK, Qt3,
5159 Qt4 or WXPython application will immediately freeze the shell.
4892 Qt4 or WXPython application will immediately freeze the shell.
5160
4893
5161 IPython, with one of these options (you can only use one at a time),
4894 IPython, with one of these options (you can only use one at a time),
5162 separates the graphical loop and IPython's code execution run into
4895 separates the graphical loop and IPython's code execution run into
5163 different threads. This allows you to test interactively (with %run, for
4896 different threads. This allows you to test interactively (with %run, for
5164 example) your GUI code without blocking.
4897 example) your GUI code without blocking.
5165
4898
5166 A nice mini-tutorial on using IPython along with the Qt Designer
4899 A nice mini-tutorial on using IPython along with the Qt Designer
5167 application is available at the SciPy wiki:
4900 application is available at the SciPy wiki:
5168 http://www.scipy.org/Cookbook/Matplotlib/Qt_with_IPython_and_Designer.
4901 http://www.scipy.org/Cookbook/Matplotlib/Qt_with_IPython_and_Designer.
5169
4902
5170
4903
5171 Tk issues
4904 Tk issues
5172 ---------
4905 ---------
5173
4906
5174 As indicated in Sec. `Threading options`_, a special -tk option is
4907 As indicated in Sec. `Threading options`_, a special -tk option is
5175 provided to try and allow Tk graphical applications to coexist
4908 provided to try and allow Tk graphical applications to coexist
5176 interactively with WX, Qt or GTK ones. Whether this works at all,
4909 interactively with WX, Qt or GTK ones. Whether this works at all,
5177 however, is very platform and configuration dependent. Please
4910 however, is very platform and configuration dependent. Please
5178 experiment with simple test cases before committing to using this
4911 experiment with simple test cases before committing to using this
5179 combination of Tk and GTK/Qt/WX threading in a production environment.
4912 combination of Tk and GTK/Qt/WX threading in a production environment.
5180
4913
5181
4914
5182 I/O pitfalls
4915 I/O pitfalls
5183 ------------
4916 ------------
5184
4917
5185 Be mindful that the Python interpreter switches between threads every
4918 Be mindful that the Python interpreter switches between threads every
5186 $N$ bytecodes, where the default value as of Python 2.3 is $N=100.$ This
4919 $N$ bytecodes, where the default value as of Python 2.3 is $N=100.$ This
5187 value can be read by using the sys.getcheckinterval() function, and it
4920 value can be read by using the sys.getcheckinterval() function, and it
5188 can be reset via sys.setcheckinterval(N). This switching of threads can
4921 can be reset via sys.setcheckinterval(N). This switching of threads can
5189 cause subtly confusing effects if one of your threads is doing file I/O.
4922 cause subtly confusing effects if one of your threads is doing file I/O.
5190 In text mode, most systems only flush file buffers when they encounter a
4923 In text mode, most systems only flush file buffers when they encounter a
5191 '\n'. An instruction as simple as::
4924 '\n'. An instruction as simple as::
5192
4925
5193 print >> filehandle, ''hello world''
4926 print >> filehandle, ''hello world''
5194
4927
5195 actually consists of several bytecodes, so it is possible that the
4928 actually consists of several bytecodes, so it is possible that the
5196 newline does not reach your file before the next thread switch.
4929 newline does not reach your file before the next thread switch.
5197 Similarly, if you are writing to a file in binary mode, the file won't
4930 Similarly, if you are writing to a file in binary mode, the file won't
5198 be flushed until the buffer fills, and your other thread may see
4931 be flushed until the buffer fills, and your other thread may see
5199 apparently truncated files.
4932 apparently truncated files.
5200
4933
5201 For this reason, if you are using IPython's thread support and have (for
4934 For this reason, if you are using IPython's thread support and have (for
5202 example) a GUI application which will read data generated by files
4935 example) a GUI application which will read data generated by files
5203 written to from the IPython thread, the safest approach is to open all
4936 written to from the IPython thread, the safest approach is to open all
5204 of your files in unbuffered mode (the third argument to the file/open
4937 of your files in unbuffered mode (the third argument to the file/open
5205 function is the buffering value)::
4938 function is the buffering value)::
5206
4939
5207 filehandle = open(filename,mode,0)
4940 filehandle = open(filename,mode,0)
5208
4941
5209 This is obviously a brute force way of avoiding race conditions with the
4942 This is obviously a brute force way of avoiding race conditions with the
5210 file buffering. If you want to do it cleanly, and you have a resource
4943 file buffering. If you want to do it cleanly, and you have a resource
5211 which is being shared by the interactive IPython loop and your GUI
4944 which is being shared by the interactive IPython loop and your GUI
5212 thread, you should really handle it with thread locking and
4945 thread, you should really handle it with thread locking and
5213 syncrhonization properties. The Python documentation discusses these.
4946 syncrhonization properties. The Python documentation discusses these.
5214
4947
5215 .. _Interactive demos:
4948 .. _Interactive demos:
5216
4949
5217 Interactive demos with IPython
4950 Interactive demos with IPython
5218 ==============================
4951 ==============================
5219
4952
5220 IPython ships with a basic system for running scripts interactively in
4953 IPython ships with a basic system for running scripts interactively in
5221 sections, useful when presenting code to audiences. A few tags embedded
4954 sections, useful when presenting code to audiences. A few tags embedded
5222 in comments (so that the script remains valid Python code) divide a file
4955 in comments (so that the script remains valid Python code) divide a file
5223 into separate blocks, and the demo can be run one block at a time, with
4956 into separate blocks, and the demo can be run one block at a time, with
5224 IPython printing (with syntax highlighting) the block before executing
4957 IPython printing (with syntax highlighting) the block before executing
5225 it, and returning to the interactive prompt after each block. The
4958 it, and returning to the interactive prompt after each block. The
5226 interactive namespace is updated after each block is run with the
4959 interactive namespace is updated after each block is run with the
5227 contents of the demo's namespace.
4960 contents of the demo's namespace.
5228
4961
5229 This allows you to show a piece of code, run it and then execute
4962 This allows you to show a piece of code, run it and then execute
5230 interactively commands based on the variables just created. Once you
4963 interactively commands based on the variables just created. Once you
5231 want to continue, you simply execute the next block of the demo. The
4964 want to continue, you simply execute the next block of the demo. The
5232 following listing shows the markup necessary for dividing a script into
4965 following listing shows the markup necessary for dividing a script into
5233 sections for execution as a demo::
4966 sections for execution as a demo::
5234
4967
5235
4968
5236 """A simple interactive demo to illustrate the use of IPython's Demo class.
4969 """A simple interactive demo to illustrate the use of IPython's Demo class.
5237
4970
5238 Any python script can be run as a demo, but that does little more than showing
4971 Any python script can be run as a demo, but that does little more than showing
5239 it on-screen, syntax-highlighted in one shot. If you add a little simple
4972 it on-screen, syntax-highlighted in one shot. If you add a little simple
5240 markup, you can stop at specified intervals and return to the ipython prompt,
4973 markup, you can stop at specified intervals and return to the ipython prompt,
5241 resuming execution later.
4974 resuming execution later.
5242 """
4975 """
5243
4976
5244 print 'Hello, welcome to an interactive IPython demo.'
4977 print 'Hello, welcome to an interactive IPython demo.'
5245 print 'Executing this block should require confirmation before proceeding,'
4978 print 'Executing this block should require confirmation before proceeding,'
5246 print 'unless auto_all has been set to true in the demo object'
4979 print 'unless auto_all has been set to true in the demo object'
5247
4980
5248 # The mark below defines a block boundary, which is a point where IPython will
4981 # The mark below defines a block boundary, which is a point where IPython will
5249 # stop execution and return to the interactive prompt.
4982 # stop execution and return to the interactive prompt.
5250 # Note that in actual interactive execution,
4983 # Note that in actual interactive execution,
5251 # <demo> --- stop ---
4984 # <demo> --- stop ---
5252
4985
5253 x = 1
4986 x = 1
5254 y = 2
4987 y = 2
5255
4988
5256 # <demo> --- stop ---
4989 # <demo> --- stop ---
5257
4990
5258 # the mark below makes this block as silent
4991 # the mark below makes this block as silent
5259 # <demo> silent
4992 # <demo> silent
5260
4993
5261 print 'This is a silent block, which gets executed but not printed.'
4994 print 'This is a silent block, which gets executed but not printed.'
5262
4995
5263 # <demo> --- stop ---
4996 # <demo> --- stop ---
5264 # <demo> auto
4997 # <demo> auto
5265 print 'This is an automatic block.'
4998 print 'This is an automatic block.'
5266 print 'It is executed without asking for confirmation, but printed.'
4999 print 'It is executed without asking for confirmation, but printed.'
5267 z = x+y
5000 z = x+y
5268
5001
5269 print 'z=',x
5002 print 'z=',x
5270
5003
5271 # <demo> --- stop ---
5004 # <demo> --- stop ---
5272 # This is just another normal block.
5005 # This is just another normal block.
5273 print 'z is now:', z
5006 print 'z is now:', z
5274
5007
5275 print 'bye!'
5008 print 'bye!'
5276
5009
5277 In order to run a file as a demo, you must first make a Demo object out
5010 In order to run a file as a demo, you must first make a Demo object out
5278 of it. If the file is named myscript.py, the following code will make a
5011 of it. If the file is named myscript.py, the following code will make a
5279 demo::
5012 demo::
5280
5013
5281 from IPython.demo import Demo
5014 from IPython.demo import Demo
5282
5015
5283 mydemo = Demo('myscript.py')
5016 mydemo = Demo('myscript.py')
5284
5017
5285 This creates the mydemo object, whose blocks you run one at a time by
5018 This creates the mydemo object, whose blocks you run one at a time by
5286 simply calling the object with no arguments. If you have autocall active
5019 simply calling the object with no arguments. If you have autocall active
5287 in IPython (the default), all you need to do is type::
5020 in IPython (the default), all you need to do is type::
5288
5021
5289 mydemo
5022 mydemo
5290
5023
5291 and IPython will call it, executing each block. Demo objects can be
5024 and IPython will call it, executing each block. Demo objects can be
5292 restarted, you can move forward or back skipping blocks, re-execute the
5025 restarted, you can move forward or back skipping blocks, re-execute the
5293 last block, etc. Simply use the Tab key on a demo object to see its
5026 last block, etc. Simply use the Tab key on a demo object to see its
5294 methods, and call '?' on them to see their docstrings for more usage
5027 methods, and call '?' on them to see their docstrings for more usage
5295 details. In addition, the demo module itself contains a comprehensive
5028 details. In addition, the demo module itself contains a comprehensive
5296 docstring, which you can access via::
5029 docstring, which you can access via::
5297
5030
5298 from IPython import demo
5031 from IPython import demo
5299
5032
5300 demo?
5033 demo?
5301
5034
5302 Limitations: It is important to note that these demos are limited to
5035 Limitations: It is important to note that these demos are limited to
5303 fairly simple uses. In particular, you can not put division marks in
5036 fairly simple uses. In particular, you can not put division marks in
5304 indented code (loops, if statements, function definitions, etc.)
5037 indented code (loops, if statements, function definitions, etc.)
5305 Supporting something like this would basically require tracking the
5038 Supporting something like this would basically require tracking the
5306 internal execution state of the Python interpreter, so only top-level
5039 internal execution state of the Python interpreter, so only top-level
5307 divisions are allowed. If you want to be able to open an IPython
5040 divisions are allowed. If you want to be able to open an IPython
5308 instance at an arbitrary point in a program, you can use IPython's
5041 instance at an arbitrary point in a program, you can use IPython's
5309 embedding facilities, described in detail in Sec. 9
5042 embedding facilities, described in detail in Sec. 9
5310
5043
5311
5044
5312 .. _Matplotlib support:
5045 .. _Matplotlib support:
5313
5046
5314 Plotting with matplotlib
5047 Plotting with matplotlib
5315 ========================
5048 ========================
5316
5049
5317 The matplotlib library (http://matplotlib.sourceforge.net
5050 The matplotlib library (http://matplotlib.sourceforge.net
5318 http://matplotlib.sourceforge.net) provides high quality 2D plotting for
5051 http://matplotlib.sourceforge.net) provides high quality 2D plotting for
5319 Python. Matplotlib can produce plots on screen using a variety of GUI
5052 Python. Matplotlib can produce plots on screen using a variety of GUI
5320 toolkits, including Tk, GTK and WXPython. It also provides a number of
5053 toolkits, including Tk, GTK and WXPython. It also provides a number of
5321 commands useful for scientific computing, all with a syntax compatible
5054 commands useful for scientific computing, all with a syntax compatible
5322 with that of the popular Matlab program.
5055 with that of the popular Matlab program.
5323
5056
5324 IPython accepts the special option -pylab (Sec. `Command line
5057 IPython accepts the special option -pylab (Sec. `Command line
5325 options`_). This configures it to support matplotlib, honoring the
5058 options`_). This configures it to support matplotlib, honoring the
5326 settings in the .matplotlibrc file. IPython will detect the user's
5059 settings in the .matplotlibrc file. IPython will detect the user's
5327 choice of matplotlib GUI backend, and automatically select the proper
5060 choice of matplotlib GUI backend, and automatically select the proper
5328 threading model to prevent blocking. It also sets matplotlib in
5061 threading model to prevent blocking. It also sets matplotlib in
5329 interactive mode and modifies %run slightly, so that any
5062 interactive mode and modifies %run slightly, so that any
5330 matplotlib-based script can be executed using %run and the final
5063 matplotlib-based script can be executed using %run and the final
5331 show() command does not block the interactive shell.
5064 show() command does not block the interactive shell.
5332
5065
5333 The -pylab option must be given first in order for IPython to
5066 The -pylab option must be given first in order for IPython to
5334 configure its threading mode. However, you can still issue other
5067 configure its threading mode. However, you can still issue other
5335 options afterwards. This allows you to have a matplotlib-based
5068 options afterwards. This allows you to have a matplotlib-based
5336 environment customized with additional modules using the standard
5069 environment customized with additional modules using the standard
5337 IPython profile mechanism (Sec. Profiles_): ''ipython -pylab -p
5070 IPython profile mechanism (Sec. Profiles_): ''ipython -pylab -p
5338 myprofile'' will load the profile defined in ipythonrc-myprofile after
5071 myprofile'' will load the profile defined in ipythonrc-myprofile after
5339 configuring matplotlib.
5072 configuring matplotlib.
5340
5073
5341 IPython Extension Api
5074 IPython Extension Api
5342 =====================
5075 =====================
5343
5076
5344 IPython api (defined in IPython/ipapi.py) is the public api that
5077 IPython api (defined in IPython/ipapi.py) is the public api that
5345 should be used for
5078 should be used for
5346
5079
5347 * Configuration of user preferences (.ipython/ipy_user_conf.py)
5080 * Configuration of user preferences (.ipython/ipy_user_conf.py)
5348 * Creating new profiles (.ipython/ipy_profile_PROFILENAME.py)
5081 * Creating new profiles (.ipython/ipy_profile_PROFILENAME.py)
5349 * Writing extensions
5082 * Writing extensions
5350
5083
5351 Note that by using the extension api for configuration (editing
5084 Note that by using the extension api for configuration (editing
5352 ipy_user_conf.py instead of ipythonrc), you get better validity checks
5085 ipy_user_conf.py instead of ipythonrc), you get better validity checks
5353 and get richer functionality - for example, you can import an
5086 and get richer functionality - for example, you can import an
5354 extension and call functions in it to configure it for your purposes.
5087 extension and call functions in it to configure it for your purposes.
5355
5088
5356 For an example extension (the 'sh' profile), see
5089 For an example extension (the 'sh' profile), see
5357 IPython/Extensions/ipy_profile_sh.py.
5090 IPython/Extensions/ipy_profile_sh.py.
5358
5091
5359 For the last word on what's available, see the source code of
5092 For the last word on what's available, see the source code of
5360 IPython/ipapi.py.
5093 IPython/ipapi.py.
5361
5094
5362
5095
5363 Getting started
5096 Getting started
5364 ---------------
5097 ---------------
5365
5098
5366 If you want to define an extension, create a normal python module that
5099 If you want to define an extension, create a normal python module that
5367 can be imported. The module will access IPython functionality through
5100 can be imported. The module will access IPython functionality through
5368 the 'ip' object defined below.
5101 the 'ip' object defined below.
5369
5102
5370 If you are creating a new profile (e.g. foobar), name the module as
5103 If you are creating a new profile (e.g. foobar), name the module as
5371 'ipy_profile_foobar.py' and put it in your ~/.ipython directory. Then,
5104 'ipy_profile_foobar.py' and put it in your ~/.ipython directory. Then,
5372 when you start ipython with the '-p foobar' argument, the module is
5105 when you start ipython with the '-p foobar' argument, the module is
5373 automatically imported on ipython startup.
5106 automatically imported on ipython startup.
5374
5107
5375 If you are just doing some per-user configuration, you can either
5108 If you are just doing some per-user configuration, you can either
5376
5109
5377 * Put the commands directly into ipy_user_conf.py.
5110 * Put the commands directly into ipy_user_conf.py.
5378
5111
5379 * Create a new module with your customization code and import *that*
5112 * Create a new module with your customization code and import *that*
5380 module in ipy_user_conf.py. This is preferable to the first approach,
5113 module in ipy_user_conf.py. This is preferable to the first approach,
5381 because now you can reuse and distribute your customization code.
5114 because now you can reuse and distribute your customization code.
5382
5115
5383 Getting a handle to the api
5116 Getting a handle to the api
5384 ---------------------------
5117 ---------------------------
5385
5118
5386 Put this in the start of your module::
5119 Put this in the start of your module::
5387
5120
5388 #!python
5121 #!python
5389 import IPython.ipapi
5122 import IPython.ipapi
5390 ip = IPython.ipapi.get()
5123 ip = IPython.ipapi.get()
5391
5124
5392 The 'ip' object will then be used for accessing IPython
5125 The 'ip' object will then be used for accessing IPython
5393 functionality. 'ip' will mean this api object in all the following
5126 functionality. 'ip' will mean this api object in all the following
5394 code snippets. The same 'ip' that we just acquired is always
5127 code snippets. The same 'ip' that we just acquired is always
5395 accessible in interactive IPython sessions by the name _ip - play with
5128 accessible in interactive IPython sessions by the name _ip - play with
5396 it like this::
5129 it like this::
5397
5130
5398 [~\_ipython]|81> a = 10
5131 [~\_ipython]|81> a = 10
5399 [~\_ipython]|82> _ip.e
5132 [~\_ipython]|82> _ip.e
5400 _ip.ev _ip.ex _ip.expose_magic
5133 _ip.ev _ip.ex _ip.expose_magic
5401 [~\_ipython]|82> _ip.ev('a+13')
5134 [~\_ipython]|82> _ip.ev('a+13')
5402 <82> 23
5135 <82> 23
5403
5136
5404 The _ip object is also used in some examples in this document - it can
5137 The _ip object is also used in some examples in this document - it can
5405 be substituted by 'ip' in non-interactive use.
5138 be substituted by 'ip' in non-interactive use.
5406
5139
5407 Changing options
5140 Changing options
5408 ----------------
5141 ----------------
5409
5142
5410 The ip object has 'options' attribute that can be used te get/set
5143 The ip object has 'options' attribute that can be used te get/set
5411 configuration options (just as in the ipythonrc file)::
5144 configuration options (just as in the ipythonrc file)::
5412
5145
5413 o = ip.options
5146 o = ip.options
5414 o.autocall = 2
5147 o.autocall = 2
5415 o.automagic = 1
5148 o.automagic = 1
5416
5149
5417 Executing statements in IPython namespace with 'ex' and 'ev'
5150 Executing statements in IPython namespace with 'ex' and 'ev'
5418 ------------------------------------------------------------
5151 ------------------------------------------------------------
5419
5152
5420 Often, you want to e.g. import some module or define something that
5153 Often, you want to e.g. import some module or define something that
5421 should be visible in IPython namespace. Use ``ip.ev`` to
5154 should be visible in IPython namespace. Use ``ip.ev`` to
5422 *evaluate* (calculate the value of) expression and ``ip.ex`` to
5155 *evaluate* (calculate the value of) expression and ``ip.ex`` to
5423 '''execute''' a statement::
5156 '''execute''' a statement::
5424
5157
5425 # path module will be visible to the interactive session
5158 # path module will be visible to the interactive session
5426 ip.ex("from path import path" )
5159 ip.ex("from path import path" )
5427
5160
5428 # define a handy function 'up' that changes the working directory
5161 # define a handy function 'up' that changes the working directory
5429
5162
5430 ip.ex('import os')
5163 ip.ex('import os')
5431 ip.ex("def up(): os.chdir('..')")
5164 ip.ex("def up(): os.chdir('..')")
5432
5165
5433
5166
5434 # _i2 has the input history entry #2, print its value in uppercase.
5167 # _i2 has the input history entry #2, print its value in uppercase.
5435 print ip.ev('_i2.upper()')
5168 print ip.ev('_i2.upper()')
5436
5169
5437 Accessing the IPython namespace
5170 Accessing the IPython namespace
5438 -------------------------------
5171 -------------------------------
5439
5172
5440 ip.user_ns attribute has a dictionary containing the IPython global
5173 ip.user_ns attribute has a dictionary containing the IPython global
5441 namespace (the namespace visible in the interactive session).
5174 namespace (the namespace visible in the interactive session).
5442
5175
5443 ::
5176 ::
5444
5177
5445 [~\_ipython]|84> tauno = 555
5178 [~\_ipython]|84> tauno = 555
5446 [~\_ipython]|85> _ip.user_ns['tauno']
5179 [~\_ipython]|85> _ip.user_ns['tauno']
5447 <85> 555
5180 <85> 555
5448
5181
5449 Defining new magic commands
5182 Defining new magic commands
5450 ---------------------------
5183 ---------------------------
5451
5184
5452 The following example defines a new magic command, %impall. What the
5185 The following example defines a new magic command, %impall. What the
5453 command does should be obvious::
5186 command does should be obvious::
5454
5187
5455 def doimp(self, arg):
5188 def doimp(self, arg):
5456 ip = self.api
5189 ip = self.api
5457 ip.ex("import %s; reload(%s); from %s import *" % (
5190 ip.ex("import %s; reload(%s); from %s import *" % (
5458 arg,arg,arg)
5191 arg,arg,arg)
5459 )
5192 )
5460
5193
5461 ip.expose_magic('impall', doimp)
5194 ip.expose_magic('impall', doimp)
5462
5195
5463 Things to observe in this example:
5196 Things to observe in this example:
5464
5197
5465 * Define a function that implements the magic command using the
5198 * Define a function that implements the magic command using the
5466 ipapi methods defined in this document
5199 ipapi methods defined in this document
5467 * The first argument of the function is 'self', i.e. the
5200 * The first argument of the function is 'self', i.e. the
5468 interpreter object. It shouldn't be used directly. however.
5201 interpreter object. It shouldn't be used directly. however.
5469 The interpreter object is probably *not* going to remain stable
5202 The interpreter object is probably *not* going to remain stable
5470 through IPython versions.
5203 through IPython versions.
5471 * Access the ipapi through 'self.api' instead of the global 'ip' object.
5204 * Access the ipapi through 'self.api' instead of the global 'ip' object.
5472 * All the text following the magic command on the command line is
5205 * All the text following the magic command on the command line is
5473 contained in the second argument
5206 contained in the second argument
5474 * Expose the magic by ip.expose_magic()
5207 * Expose the magic by ip.expose_magic()
5475
5208
5476
5209
5477 Calling magic functions and system commands
5210 Calling magic functions and system commands
5478 -------------------------------------------
5211 -------------------------------------------
5479
5212
5480 Use ip.magic() to execute a magic function, and ip.system() to execute
5213 Use ip.magic() to execute a magic function, and ip.system() to execute
5481 a system command::
5214 a system command::
5482
5215
5483 # go to a bookmark
5216 # go to a bookmark
5484 ip.magic('%cd -b relfiles')
5217 ip.magic('%cd -b relfiles')
5485
5218
5486 # execute 'ls -F' system command. Interchangeable with os.system('ls'), really.
5219 # execute 'ls -F' system command. Interchangeable with os.system('ls'), really.
5487 ip.system('ls -F')
5220 ip.system('ls -F')
5488
5221
5489 Launching IPython instance from normal python code
5222 Launching IPython instance from normal python code
5490 --------------------------------------------------
5223 --------------------------------------------------
5491
5224
5492 Use ipapi.launch_new_instance() with an argument that specifies the
5225 Use ipapi.launch_new_instance() with an argument that specifies the
5493 namespace to use. This can be useful for trivially embedding IPython
5226 namespace to use. This can be useful for trivially embedding IPython
5494 into your program. Here's an example of normal python program test.py
5227 into your program. Here's an example of normal python program test.py
5495 ('''without''' an existing IPython session) that launches an IPython
5228 ('''without''' an existing IPython session) that launches an IPython
5496 interpreter and regains control when the interpreter is exited::
5229 interpreter and regains control when the interpreter is exited::
5497
5230
5498 [ipython]|1> cat test.py
5231 [ipython]|1> cat test.py
5499 my_ns = dict(
5232 my_ns = dict(
5500 kissa = 15,
5233 kissa = 15,
5501 koira = 16)
5234 koira = 16)
5502 import IPython.ipapi
5235 import IPython.ipapi
5503 print "launching IPython instance"
5236 print "launching IPython instance"
5504 IPython.ipapi.launch_new_instance(my_ns)
5237 IPython.ipapi.launch_new_instance(my_ns)
5505 print "Exited IPython instance!"
5238 print "Exited IPython instance!"
5506 print "New vals:",my_ns['kissa'], my_ns['koira']
5239 print "New vals:",my_ns['kissa'], my_ns['koira']
5507
5240
5508 And here's what it looks like when run (note how we don't start it
5241 And here's what it looks like when run (note how we don't start it
5509 from an ipython session)::
5242 from an ipython session)::
5510
5243
5511 Q:\ipython>python test.py
5244 Q:\ipython>python test.py
5512 launching IPython instance
5245 launching IPython instance
5513 Py 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] IPy 0.7.3b3.r1975
5246 Py 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] IPy 0.7.3b3.r1975
5514 [ipython]|1> kissa = 444
5247 [ipython]|1> kissa = 444
5515 [ipython]|2> koira = 555
5248 [ipython]|2> koira = 555
5516 [ipython]|3> Exit
5249 [ipython]|3> Exit
5517 Exited IPython instance!
5250 Exited IPython instance!
5518 New vals: 444 555
5251 New vals: 444 555
5519
5252
5520 Accessing unexposed functionality
5253 Accessing unexposed functionality
5521 ---------------------------------
5254 ---------------------------------
5522
5255
5523 There are still many features that are not exposed via the ipapi. If
5256 There are still many features that are not exposed via the ipapi. If
5524 you can't avoid using them, you can use the functionality in
5257 you can't avoid using them, you can use the functionality in
5525 InteractiveShell object (central IPython session class, defined in
5258 InteractiveShell object (central IPython session class, defined in
5526 iplib.py) through ip.IP.
5259 iplib.py) through ip.IP.
5527
5260
5528 For example::
5261 For example::
5529
5262
5530 [~]|7> _ip.IP.expand_aliases('np','myfile.py')
5263 [~]|7> _ip.IP.expand_aliases('np','myfile.py')
5531 <7> 'c:/opt/Notepad++/notepad++.exe myfile.py'
5264 <7> 'c:/opt/Notepad++/notepad++.exe myfile.py'
5532 [~]|8>
5265 [~]|8>
5533
5266
5534 Still, it's preferable that if you encounter such a feature, contact
5267 Still, it's preferable that if you encounter such a feature, contact
5535 the IPython team and request that the functionality be exposed in a
5268 the IPython team and request that the functionality be exposed in a
5536 future version of IPython. Things not in ipapi are more likely to
5269 future version of IPython. Things not in ipapi are more likely to
5537 change over time.
5270 change over time.
5538
5271
5539 Provided extensions
5272 Provided extensions
5540 ===================
5273 ===================
5541
5274
5542 You can see the list of available extensions (and profiles) by doing
5275 You can see the list of available extensions (and profiles) by doing
5543 ``import ipy_<TAB>``. Some extensions don't have the ``ipy_`` prefix in
5276 ``import ipy_<TAB>``. Some extensions don't have the ``ipy_`` prefix in
5544 module name, so you may need to see the contents of IPython/Extensions
5277 module name, so you may need to see the contents of IPython/Extensions
5545 folder to see what's available.
5278 folder to see what's available.
5546
5279
5547 You can see a brief documentation of an extension by looking at the
5280 You can see a brief documentation of an extension by looking at the
5548 module docstring::
5281 module docstring::
5549
5282
5550 [c:p/ipython_main]|190> import ipy_fsops
5283 [c:p/ipython_main]|190> import ipy_fsops
5551 [c:p/ipython_main]|191> ipy_fsops?
5284 [c:p/ipython_main]|191> ipy_fsops?
5552
5285
5553 ...
5286 ...
5554
5287
5555 Docstring:
5288 Docstring:
5556 File system operations
5289 File system operations
5557
5290
5558 Contains: Simple variants of normal unix shell commands (icp, imv, irm,
5291 Contains: Simple variants of normal unix shell commands (icp, imv, irm,
5559 imkdir, igrep).
5292 imkdir, igrep).
5560
5293
5561 You can also install your own extensions - the recommended way is to
5294 You can also install your own extensions - the recommended way is to
5562 just copy the module to ~/.ipython. Extensions are typically enabled
5295 just copy the module to ~/.ipython. Extensions are typically enabled
5563 by just importing them (e.g. in ipy_user_conf.py), but some extensions
5296 by just importing them (e.g. in ipy_user_conf.py), but some extensions
5564 require additional steps, for example::
5297 require additional steps, for example::
5565
5298
5566 [c:p]|192> import ipy_traits_completer
5299 [c:p]|192> import ipy_traits_completer
5567 [c:p]|193> ipy_traits_completer.activate()
5300 [c:p]|193> ipy_traits_completer.activate()
5568
5301
5569 Note that extensions, even if provided in the stock IPython
5302 Note that extensions, even if provided in the stock IPython
5570 installation, are not guaranteed to have the same requirements as the
5303 installation, are not guaranteed to have the same requirements as the
5571 rest of IPython - an extension may require external libraries or a
5304 rest of IPython - an extension may require external libraries or a
5572 newer version of Python than what IPython officially requires. An
5305 newer version of Python than what IPython officially requires. An
5573 extension may also be under a more restrictive license than IPython
5306 extension may also be under a more restrictive license than IPython
5574 (e.g. ipy_bzr is under GPL).
5307 (e.g. ipy_bzr is under GPL).
5575
5308
5576 Just for reference, the list of bundled extensions at the time of
5309 Just for reference, the list of bundled extensions at the time of
5577 writing is below:
5310 writing is below:
5578
5311
5579 astyle.py clearcmd.py envpersist.py ext_rescapture.py ibrowse.py
5312 astyle.py clearcmd.py envpersist.py ext_rescapture.py ibrowse.py
5580 igrid.py InterpreterExec.py InterpreterPasteInput.py ipipe.py
5313 igrid.py InterpreterExec.py InterpreterPasteInput.py ipipe.py
5581 ipy_app_completers.py ipy_autoreload.py ipy_bzr.py ipy_completers.py
5314 ipy_app_completers.py ipy_autoreload.py ipy_bzr.py ipy_completers.py
5582 ipy_constants.py ipy_defaults.py ipy_editors.py ipy_exportdb.py
5315 ipy_constants.py ipy_defaults.py ipy_editors.py ipy_exportdb.py
5583 ipy_extutil.py ipy_fsops.py ipy_gnuglobal.py ipy_kitcfg.py
5316 ipy_extutil.py ipy_fsops.py ipy_gnuglobal.py ipy_kitcfg.py
5584 ipy_legacy.py ipy_leo.py ipy_p4.py ipy_profile_doctest.py
5317 ipy_legacy.py ipy_leo.py ipy_p4.py ipy_profile_doctest.py
5585 ipy_profile_none.py ipy_profile_scipy.py ipy_profile_sh.py
5318 ipy_profile_none.py ipy_profile_scipy.py ipy_profile_sh.py
5586 ipy_profile_zope.py ipy_pydb.py ipy_rehashdir.py ipy_render.py
5319 ipy_profile_zope.py ipy_pydb.py ipy_rehashdir.py ipy_render.py
5587 ipy_server.py ipy_signals.py ipy_stock_completers.py
5320 ipy_server.py ipy_signals.py ipy_stock_completers.py
5588 ipy_system_conf.py ipy_traits_completer.py ipy_vimserver.py
5321 ipy_system_conf.py ipy_traits_completer.py ipy_vimserver.py
5589 ipy_which.py ipy_workdir.py jobctrl.py ledit.py numeric_formats.py
5322 ipy_which.py ipy_workdir.py jobctrl.py ledit.py numeric_formats.py
5590 PhysicalQInput.py PhysicalQInteractive.py pickleshare.py
5323 PhysicalQInput.py PhysicalQInteractive.py pickleshare.py
5591 pspersistence.py win32clip.py __init__.py
5324 pspersistence.py win32clip.py __init__.py
5592
5325
5593 Reporting bugs
5326 Reporting bugs
5594 ==============
5327 ==============
5595
5328
5596 Automatic crash reports
5329 Automatic crash reports
5597 -----------------------
5330 -----------------------
5598
5331
5599 Ideally, IPython itself shouldn't crash. It will catch exceptions
5332 Ideally, IPython itself shouldn't crash. It will catch exceptions
5600 produced by you, but bugs in its internals will still crash it.
5333 produced by you, but bugs in its internals will still crash it.
5601
5334
5602 In such a situation, IPython will leave a file named
5335 In such a situation, IPython will leave a file named
5603 IPython_crash_report.txt in your IPYTHONDIR directory (that way if
5336 IPython_crash_report.txt in your IPYTHONDIR directory (that way if
5604 crashes happen several times it won't litter many directories, the
5337 crashes happen several times it won't litter many directories, the
5605 post-mortem file is always located in the same place and new
5338 post-mortem file is always located in the same place and new
5606 occurrences just overwrite the previous one). If you can mail this
5339 occurrences just overwrite the previous one). If you can mail this
5607 file to the developers (see sec. credits_ for names and addresses), it
5340 file to the developers (see sec. credits_ for names and addresses), it
5608 will help us a lot in understanding the cause of the problem and
5341 will help us a lot in understanding the cause of the problem and
5609 fixing it sooner.
5342 fixing it sooner.
5610
5343
5611
5344
5612 The bug tracker
5345 The bug tracker
5613 ---------------
5346 ---------------
5614
5347
5615 IPython also has an online bug-tracker, located at
5348 IPython also has an online bug-tracker, located at
5616 http://projects.scipy.org/ipython/ipython/report/1. In addition to
5349 http://projects.scipy.org/ipython/ipython/report/1. In addition to
5617 mailing the developers, it would be a good idea to file a bug report
5350 mailing the developers, it would be a good idea to file a bug report
5618 here. This will ensure that the issue is properly followed to
5351 here. This will ensure that the issue is properly followed to
5619 conclusion. To report new bugs you will have to register first.
5352 conclusion. To report new bugs you will have to register first.
5620
5353
5621 You can also use this bug tracker to file feature requests.
5354 You can also use this bug tracker to file feature requests.
5622
5355
5623 Brief history
5356 Brief history
5624 =============
5357 =============
5625
5358
5626
5359
5627 Origins
5360 Origins
5628 -------
5361 -------
5629
5362
5630 The current IPython system grew out of the following three projects:
5363 The current IPython system grew out of the following three projects:
5631
5364
5632 * [ipython] by Fernando Pérez. I was working on adding
5365 * [ipython] by Fernando Pérez. I was working on adding
5633 Mathematica-type prompts and a flexible configuration system
5366 Mathematica-type prompts and a flexible configuration system
5634 (something better than $PYTHONSTARTUP) to the standard Python
5367 (something better than $PYTHONSTARTUP) to the standard Python
5635 interactive interpreter.
5368 interactive interpreter.
5636 * [IPP] by Janko Hauser. Very well organized, great usability. Had
5369 * [IPP] by Janko Hauser. Very well organized, great usability. Had
5637 an old help system. IPP was used as the 'container' code into
5370 an old help system. IPP was used as the 'container' code into
5638 which I added the functionality from ipython and LazyPython.
5371 which I added the functionality from ipython and LazyPython.
5639 * [LazyPython] by Nathan Gray. Simple but very powerful. The quick
5372 * [LazyPython] by Nathan Gray. Simple but very powerful. The quick
5640 syntax (auto parens, auto quotes) and verbose/colored tracebacks
5373 syntax (auto parens, auto quotes) and verbose/colored tracebacks
5641 were all taken from here.
5374 were all taken from here.
5642
5375
5643 When I found out about IPP and LazyPython I tried to join all three
5376 When I found out about IPP and LazyPython I tried to join all three
5644 into a unified system. I thought this could provide a very nice
5377 into a unified system. I thought this could provide a very nice
5645 working environment, both for regular programming and scientific
5378 working environment, both for regular programming and scientific
5646 computing: shell-like features, IDL/Matlab numerics, Mathematica-type
5379 computing: shell-like features, IDL/Matlab numerics, Mathematica-type
5647 prompt history and great object introspection and help facilities. I
5380 prompt history and great object introspection and help facilities. I
5648 think it worked reasonably well, though it was a lot more work than I
5381 think it worked reasonably well, though it was a lot more work than I
5649 had initially planned.
5382 had initially planned.
5650
5383
5651
5384
5652 Current status
5385 Current status
5653 --------------
5386 --------------
5654
5387
5655 The above listed features work, and quite well for the most part. But
5388 The above listed features work, and quite well for the most part. But
5656 until a major internal restructuring is done (see below), only bug
5389 until a major internal restructuring is done (see below), only bug
5657 fixing will be done, no other features will be added (unless very minor
5390 fixing will be done, no other features will be added (unless very minor
5658 and well localized in the cleaner parts of the code).
5391 and well localized in the cleaner parts of the code).
5659
5392
5660 IPython consists of some 18000 lines of pure python code, of which
5393 IPython consists of some 18000 lines of pure python code, of which
5661 roughly two thirds is reasonably clean. The rest is, messy code which
5394 roughly two thirds is reasonably clean. The rest is, messy code which
5662 needs a massive restructuring before any further major work is done.
5395 needs a massive restructuring before any further major work is done.
5663 Even the messy code is fairly well documented though, and most of the
5396 Even the messy code is fairly well documented though, and most of the
5664 problems in the (non-existent) class design are well pointed to by a
5397 problems in the (non-existent) class design are well pointed to by a
5665 PyChecker run. So the rewriting work isn't that bad, it will just be
5398 PyChecker run. So the rewriting work isn't that bad, it will just be
5666 time-consuming.
5399 time-consuming.
5667
5400
5668
5401
5669 Future
5402 Future
5670 ------
5403 ------
5671
5404
5672 See the separate new_design document for details. Ultimately, I would
5405 See the separate new_design document for details. Ultimately, I would
5673 like to see IPython become part of the standard Python distribution as a
5406 like to see IPython become part of the standard Python distribution as a
5674 'big brother with batteries' to the standard Python interactive
5407 'big brother with batteries' to the standard Python interactive
5675 interpreter. But that will never happen with the current state of the
5408 interpreter. But that will never happen with the current state of the
5676 code, so all contributions are welcome.
5409 code, so all contributions are welcome.
5677
5410
5678 License
5411 License
5679 =======
5412 =======
5680
5413
5681 IPython is released under the terms of the BSD license, whose general
5414 IPython is released under the terms of the BSD license, whose general
5682 form can be found at:
5415 form can be found at:
5683 http://www.opensource.org/licenses/bsd-license.php. The full text of the
5416 http://www.opensource.org/licenses/bsd-license.php. The full text of the
5684 IPython license is reproduced below::
5417 IPython license is reproduced below::
5685
5418
5686 IPython is released under a BSD-type license.
5419 IPython is released under a BSD-type license.
5687
5420
5688 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez
5421 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez
5689 <fperez@colorado.edu>.
5422 <fperez@colorado.edu>.
5690
5423
5691 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
5424 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
5692 Nathaniel Gray <n8gray@caltech.edu>.
5425 Nathaniel Gray <n8gray@caltech.edu>.
5693
5426
5694 All rights reserved.
5427 All rights reserved.
5695
5428
5696 Redistribution and use in source and binary forms, with or without
5429 Redistribution and use in source and binary forms, with or without
5697 modification, are permitted provided that the following conditions
5430 modification, are permitted provided that the following conditions
5698 are met:
5431 are met:
5699
5432
5700 a. Redistributions of source code must retain the above copyright
5433 a. Redistributions of source code must retain the above copyright
5701 notice, this list of conditions and the following disclaimer.
5434 notice, this list of conditions and the following disclaimer.
5702
5435
5703 b. Redistributions in binary form must reproduce the above copyright
5436 b. Redistributions in binary form must reproduce the above copyright
5704 notice, this list of conditions and the following disclaimer in the
5437 notice, this list of conditions and the following disclaimer in the
5705 documentation and/or other materials provided with the distribution.
5438 documentation and/or other materials provided with the distribution.
5706
5439
5707 c. Neither the name of the copyright holders nor the names of any
5440 c. Neither the name of the copyright holders nor the names of any
5708 contributors to this software may be used to endorse or promote
5441 contributors to this software may be used to endorse or promote
5709 products derived from this software without specific prior written
5442 products derived from this software without specific prior written
5710 permission.
5443 permission.
5711
5444
5712 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5445 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5713 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5446 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5714 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
5447 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
5715 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
5448 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
5716 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
5449 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
5717 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
5450 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
5718 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
5451 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
5719 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5452 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5720 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5453 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5721 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
5454 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
5722 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5455 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5723 POSSIBILITY OF SUCH DAMAGE.
5456 POSSIBILITY OF SUCH DAMAGE.
5724
5457
5725 Individual authors are the holders of the copyright for their code and
5458 Individual authors are the holders of the copyright for their code and
5726 are listed in each file.
5459 are listed in each file.
5727
5460
5728 Some files (DPyGetOpt.py, for example) may be licensed under different
5461 Some files (DPyGetOpt.py, for example) may be licensed under different
5729 conditions. Ultimately each file indicates clearly the conditions under
5462 conditions. Ultimately each file indicates clearly the conditions under
5730 which its author/authors have decided to publish the code.
5463 which its author/authors have decided to publish the code.
5731
5464
5732 Versions of IPython up to and including 0.6.3 were released under the
5465 Versions of IPython up to and including 0.6.3 were released under the
5733 GNU Lesser General Public License (LGPL), available at
5466 GNU Lesser General Public License (LGPL), available at
5734 http://www.gnu.org/copyleft/lesser.html.
5467 http://www.gnu.org/copyleft/lesser.html.
5735
5468
5736 Credits
5469 Credits
5737 =======
5470 =======
5738
5471
5739 IPython is mainly developed by Fernando Pérez
5472 IPython is mainly developed by Fernando Pérez
5740 <Fernando.Perez@colorado.edu>, but the project was born from mixing in
5473 <Fernando.Perez@colorado.edu>, but the project was born from mixing in
5741 Fernando's code with the IPP project by Janko Hauser
5474 Fernando's code with the IPP project by Janko Hauser
5742 <jhauser-AT-zscout.de> and LazyPython by Nathan Gray
5475 <jhauser-AT-zscout.de> and LazyPython by Nathan Gray
5743 <n8gray-AT-caltech.edu>. For all IPython-related requests, please
5476 <n8gray-AT-caltech.edu>. For all IPython-related requests, please
5744 contact Fernando.
5477 contact Fernando.
5745
5478
5746 As of early 2006, the following developers have joined the core team:
5479 As of early 2006, the following developers have joined the core team:
5747
5480
5748 * [Robert Kern] <rkern-AT-enthought.com>: co-mentored the 2005
5481 * [Robert Kern] <rkern-AT-enthought.com>: co-mentored the 2005
5749 Google Summer of Code project to develop python interactive
5482 Google Summer of Code project to develop python interactive
5750 notebooks (XML documents) and graphical interface. This project
5483 notebooks (XML documents) and graphical interface. This project
5751 was awarded to the students Tzanko Matev <tsanko-AT-gmail.com> and
5484 was awarded to the students Tzanko Matev <tsanko-AT-gmail.com> and
5752 Toni Alatalo <antont-AT-an.org>
5485 Toni Alatalo <antont-AT-an.org>
5753 * [Brian Granger] <bgranger-AT-scu.edu>: extending IPython to allow
5486 * [Brian Granger] <bgranger-AT-scu.edu>: extending IPython to allow
5754 support for interactive parallel computing.
5487 support for interactive parallel computing.
5755 * [Ville Vainio] <vivainio-AT-gmail.com>: Ville is the new
5488 * [Ville Vainio] <vivainio-AT-gmail.com>: Ville is the new
5756 maintainer for the main trunk of IPython after version 0.7.1.
5489 maintainer for the main trunk of IPython after version 0.7.1.
5757
5490
5758 User or development help should be requested via the IPython mailing lists:
5491 User or development help should be requested via the IPython mailing lists:
5759
5492
5760 *User list:*
5493 *User list:*
5761 http://scipy.net/mailman/listinfo/ipython-user
5494 http://scipy.net/mailman/listinfo/ipython-user
5762 *Developer's list:*
5495 *Developer's list:*
5763 http://scipy.net/mailman/listinfo/ipython-dev
5496 http://scipy.net/mailman/listinfo/ipython-dev
5764
5497
5765 The IPython project is also very grateful to:
5498 The IPython project is also very grateful to:
5766
5499
5767 Bill Bumgarner <bbum-AT-friday.com>: for providing the DPyGetOpt module
5500 Bill Bumgarner <bbum-AT-friday.com>: for providing the DPyGetOpt module
5768 which gives very powerful and convenient handling of command-line
5501 which gives very powerful and convenient handling of command-line
5769 options (light years ahead of what Python 2.1.1's getopt module does).
5502 options (light years ahead of what Python 2.1.1's getopt module does).
5770
5503
5771 Ka-Ping Yee <ping-AT-lfw.org>: for providing the Itpl module for
5504 Ka-Ping Yee <ping-AT-lfw.org>: for providing the Itpl module for
5772 convenient and powerful string interpolation with a much nicer syntax
5505 convenient and powerful string interpolation with a much nicer syntax
5773 than formatting through the '%' operator.
5506 than formatting through the '%' operator.
5774
5507
5775 Arnd Baecker <baecker-AT-physik.tu-dresden.de>: for his many very useful
5508 Arnd Baecker <baecker-AT-physik.tu-dresden.de>: for his many very useful
5776 suggestions and comments, and lots of help with testing and
5509 suggestions and comments, and lots of help with testing and
5777 documentation checking. Many of IPython's newer features are a result of
5510 documentation checking. Many of IPython's newer features are a result of
5778 discussions with him (bugs are still my fault, not his).
5511 discussions with him (bugs are still my fault, not his).
5779
5512
5780 Obviously Guido van Rossum and the whole Python development team, that
5513 Obviously Guido van Rossum and the whole Python development team, that
5781 goes without saying.
5514 goes without saying.
5782
5515
5783 IPython's website is generously hosted at http://ipython.scipy.orgby
5516 IPython's website is generously hosted at http://ipython.scipy.orgby
5784 Enthought (http://www.enthought.com). I am very grateful to them and all
5517 Enthought (http://www.enthought.com). I am very grateful to them and all
5785 of the SciPy team for their contribution.
5518 of the SciPy team for their contribution.
5786
5519
5787 Fernando would also like to thank Stephen Figgins <fig-AT-monitor.net>,
5520 Fernando would also like to thank Stephen Figgins <fig-AT-monitor.net>,
5788 an O'Reilly Python editor. His Oct/11/2001 article about IPP and
5521 an O'Reilly Python editor. His Oct/11/2001 article about IPP and
5789 LazyPython, was what got this project started. You can read it at:
5522 LazyPython, was what got this project started. You can read it at:
5790 http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html.
5523 http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html.
5791
5524
5792 And last but not least, all the kind IPython users who have emailed new
5525 And last but not least, all the kind IPython users who have emailed new
5793 code, bug reports, fixes, comments and ideas. A brief list follows,
5526 code, bug reports, fixes, comments and ideas. A brief list follows,
5794 please let me know if I have ommitted your name by accident:
5527 please let me know if I have ommitted your name by accident:
5795
5528
5796 * [Jack Moffit] <jack-AT-xiph.org> Bug fixes, including the infamous
5529 * [Jack Moffit] <jack-AT-xiph.org> Bug fixes, including the infamous
5797 color problem. This bug alone caused many lost hours and
5530 color problem. This bug alone caused many lost hours and
5798 frustration, many thanks to him for the fix. I've always been a
5531 frustration, many thanks to him for the fix. I've always been a
5799 fan of Ogg & friends, now I have one more reason to like these folks.
5532 fan of Ogg & friends, now I have one more reason to like these folks.
5800 Jack is also contributing with Debian packaging and many other
5533 Jack is also contributing with Debian packaging and many other
5801 things.
5534 things.
5802 * [Alexander Schmolck] <a.schmolck-AT-gmx.net> Emacs work, bug
5535 * [Alexander Schmolck] <a.schmolck-AT-gmx.net> Emacs work, bug
5803 reports, bug fixes, ideas, lots more. The ipython.el mode for
5536 reports, bug fixes, ideas, lots more. The ipython.el mode for
5804 (X)Emacs is Alex's code, providing full support for IPython under
5537 (X)Emacs is Alex's code, providing full support for IPython under
5805 (X)Emacs.
5538 (X)Emacs.
5806 * [Andrea Riciputi] <andrea.riciputi-AT-libero.it> Mac OSX
5539 * [Andrea Riciputi] <andrea.riciputi-AT-libero.it> Mac OSX
5807 information, Fink package management.
5540 information, Fink package management.
5808 * [Gary Bishop] <gb-AT-cs.unc.edu> Bug reports, and patches to work
5541 * [Gary Bishop] <gb-AT-cs.unc.edu> Bug reports, and patches to work
5809 around the exception handling idiosyncracies of WxPython. Readline
5542 around the exception handling idiosyncracies of WxPython. Readline
5810 and color support for Windows.
5543 and color support for Windows.
5811 * [Jeffrey Collins] <Jeff.Collins-AT-vexcel.com> Bug reports. Much
5544 * [Jeffrey Collins] <Jeff.Collins-AT-vexcel.com> Bug reports. Much
5812 improved readline support, including fixes for Python 2.3.
5545 improved readline support, including fixes for Python 2.3.
5813 * [Dryice Liu] <dryice-AT-liu.com.cn> FreeBSD port.
5546 * [Dryice Liu] <dryice-AT-liu.com.cn> FreeBSD port.
5814 * [Mike Heeter] <korora-AT-SDF.LONESTAR.ORG>
5547 * [Mike Heeter] <korora-AT-SDF.LONESTAR.ORG>
5815 * [Christopher Hart] <hart-AT-caltech.edu> PDB integration.
5548 * [Christopher Hart] <hart-AT-caltech.edu> PDB integration.
5816 * [Milan Zamazal] <pdm-AT-zamazal.org> Emacs info.
5549 * [Milan Zamazal] <pdm-AT-zamazal.org> Emacs info.
5817 * [Philip Hisley] <compsys-AT-starpower.net>
5550 * [Philip Hisley] <compsys-AT-starpower.net>
5818 * [Holger Krekel] <pyth-AT-devel.trillke.net> Tab completion, lots
5551 * [Holger Krekel] <pyth-AT-devel.trillke.net> Tab completion, lots
5819 more.
5552 more.
5820 * [Robin Siebler] <robinsiebler-AT-starband.net>
5553 * [Robin Siebler] <robinsiebler-AT-starband.net>
5821 * [Ralf Ahlbrink] <ralf_ahlbrink-AT-web.de>
5554 * [Ralf Ahlbrink] <ralf_ahlbrink-AT-web.de>
5822 * [Thorsten Kampe] <thorsten-AT-thorstenkampe.de>
5555 * [Thorsten Kampe] <thorsten-AT-thorstenkampe.de>
5823 * [Fredrik Kant] <fredrik.kant-AT-front.com> Windows setup.
5556 * [Fredrik Kant] <fredrik.kant-AT-front.com> Windows setup.
5824 * [Syver Enstad] <syver-en-AT-online.no> Windows setup.
5557 * [Syver Enstad] <syver-en-AT-online.no> Windows setup.
5825 * [Richard] <rxe-AT-renre-europe.com> Global embedding.
5558 * [Richard] <rxe-AT-renre-europe.com> Global embedding.
5826 * [Hayden Callow] <h.callow-AT-elec.canterbury.ac.nz> Gnuplot.py 1.6
5559 * [Hayden Callow] <h.callow-AT-elec.canterbury.ac.nz> Gnuplot.py 1.6
5827 compatibility.
5560 compatibility.
5828 * [Leonardo Santagada] <retype-AT-terra.com.br> Fixes for Windows
5561 * [Leonardo Santagada] <retype-AT-terra.com.br> Fixes for Windows
5829 installation.
5562 installation.
5830 * [Christopher Armstrong] <radix-AT-twistedmatrix.com> Bugfixes.
5563 * [Christopher Armstrong] <radix-AT-twistedmatrix.com> Bugfixes.
5831 * [Francois Pinard] <pinard-AT-iro.umontreal.ca> Code and
5564 * [Francois Pinard] <pinard-AT-iro.umontreal.ca> Code and
5832 documentation fixes.
5565 documentation fixes.
5833 * [Cory Dodt] <cdodt-AT-fcoe.k12.ca.us> Bug reports and Windows
5566 * [Cory Dodt] <cdodt-AT-fcoe.k12.ca.us> Bug reports and Windows
5834 ideas. Patches for Windows installer.
5567 ideas. Patches for Windows installer.
5835 * [Olivier Aubert] <oaubert-AT-bat710.univ-lyon1.fr> New magics.
5568 * [Olivier Aubert] <oaubert-AT-bat710.univ-lyon1.fr> New magics.
5836 * [King C. Shu] <kingshu-AT-myrealbox.com> Autoindent patch.
5569 * [King C. Shu] <kingshu-AT-myrealbox.com> Autoindent patch.
5837 * [Chris Drexler] <chris-AT-ac-drexler.de> Readline packages for
5570 * [Chris Drexler] <chris-AT-ac-drexler.de> Readline packages for
5838 Win32/CygWin.
5571 Win32/CygWin.
5839 * [Gustavo Cordova Avila] <gcordova-AT-sismex.com> EvalDict code for
5572 * [Gustavo Cordova Avila] <gcordova-AT-sismex.com> EvalDict code for
5840 nice, lightweight string interpolation.
5573 nice, lightweight string interpolation.
5841 * [Kasper Souren] <Kasper.Souren-AT-ircam.fr> Bug reports, ideas.
5574 * [Kasper Souren] <Kasper.Souren-AT-ircam.fr> Bug reports, ideas.
5842 * [Gever Tulley] <gever-AT-helium.com> Code contributions.
5575 * [Gever Tulley] <gever-AT-helium.com> Code contributions.
5843 * [Ralf Schmitt] <ralf-AT-brainbot.com> Bug reports & fixes.
5576 * [Ralf Schmitt] <ralf-AT-brainbot.com> Bug reports & fixes.
5844 * [Oliver Sander] <osander-AT-gmx.de> Bug reports.
5577 * [Oliver Sander] <osander-AT-gmx.de> Bug reports.
5845 * [Rod Holland] <rhh-AT-structurelabs.com> Bug reports and fixes to
5578 * [Rod Holland] <rhh-AT-structurelabs.com> Bug reports and fixes to
5846 logging module.
5579 logging module.
5847 * [Daniel 'Dang' Griffith] <pythondev-dang-AT-lazytwinacres.net>
5580 * [Daniel 'Dang' Griffith] <pythondev-dang-AT-lazytwinacres.net>
5848 Fixes, enhancement suggestions for system shell use.
5581 Fixes, enhancement suggestions for system shell use.
5849 * [Viktor Ransmayr] <viktor.ransmayr-AT-t-online.de> Tests and
5582 * [Viktor Ransmayr] <viktor.ransmayr-AT-t-online.de> Tests and
5850 reports on Windows installation issues. Contributed a true Windows
5583 reports on Windows installation issues. Contributed a true Windows
5851 binary installer.
5584 binary installer.
5852 * [Mike Salib] <msalib-AT-mit.edu> Help fixing a subtle bug related
5585 * [Mike Salib] <msalib-AT-mit.edu> Help fixing a subtle bug related
5853 to traceback printing.
5586 to traceback printing.
5854 * [W.J. van der Laan] <gnufnork-AT-hetdigitalegat.nl> Bash-like
5587 * [W.J. van der Laan] <gnufnork-AT-hetdigitalegat.nl> Bash-like
5855 prompt specials.
5588 prompt specials.
5856 * [Antoon Pardon] <Antoon.Pardon-AT-rece.vub.ac.be> Critical fix for
5589 * [Antoon Pardon] <Antoon.Pardon-AT-rece.vub.ac.be> Critical fix for
5857 the multithreaded IPython.
5590 the multithreaded IPython.
5858 * [John Hunter] <jdhunter-AT-nitace.bsd.uchicago.edu> Matplotlib
5591 * [John Hunter] <jdhunter-AT-nitace.bsd.uchicago.edu> Matplotlib
5859 author, helped with all the development of support for matplotlib
5592 author, helped with all the development of support for matplotlib
5860 in IPyhton, including making necessary changes to matplotlib itself.
5593 in IPyhton, including making necessary changes to matplotlib itself.
5861 * [Matthew Arnison] <maffew-AT-cat.org.au> Bug reports, '%run -d' idea.
5594 * [Matthew Arnison] <maffew-AT-cat.org.au> Bug reports, '%run -d' idea.
5862 * [Prabhu Ramachandran] <prabhu_r-AT-users.sourceforge.net> Help
5595 * [Prabhu Ramachandran] <prabhu_r-AT-users.sourceforge.net> Help
5863 with (X)Emacs support, threading patches, ideas...
5596 with (X)Emacs support, threading patches, ideas...
5864 * [Norbert Tretkowski] <tretkowski-AT-inittab.de> help with Debian
5597 * [Norbert Tretkowski] <tretkowski-AT-inittab.de> help with Debian
5865 packaging and distribution.
5598 packaging and distribution.
5866 * [George Sakkis] <gsakkis-AT-eden.rutgers.edu> New matcher for
5599 * [George Sakkis] <gsakkis-AT-eden.rutgers.edu> New matcher for
5867 tab-completing named arguments of user-defined functions.
5600 tab-completing named arguments of user-defined functions.
5868 * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu> Wildcard
5601 * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu> Wildcard
5869 support implementation for searching namespaces.
5602 support implementation for searching namespaces.
5870 * [Vivian De Smedt] <vivian-AT-vdesmedt.com> Debugger enhancements,
5603 * [Vivian De Smedt] <vivian-AT-vdesmedt.com> Debugger enhancements,
5871 so that when pdb is activated from within IPython, coloring, tab
5604 so that when pdb is activated from within IPython, coloring, tab
5872 completion and other features continue to work seamlessly.
5605 completion and other features continue to work seamlessly.
5873 * [Scott Tsai] <scottt958-AT-yahoo.com.tw> Support for automatic
5606 * [Scott Tsai] <scottt958-AT-yahoo.com.tw> Support for automatic
5874 editor invocation on syntax errors (see
5607 editor invocation on syntax errors (see
5875 http://www.scipy.net/roundup/ipython/issue36).
5608 http://www.scipy.net/roundup/ipython/issue36).
5876 * [Alexander Belchenko] <bialix-AT-ukr.net> Improvements for win32
5609 * [Alexander Belchenko] <bialix-AT-ukr.net> Improvements for win32
5877 paging system.
5610 paging system.
5878 * [Will Maier] <willmaier-AT-ml1.net> Official OpenBSD port.
5611 * [Will Maier] <willmaier-AT-ml1.net> Official OpenBSD port.
5879
5612
@@ -0,0 +1,3 b''
1 =============================
2 IPython Copyright and License
3 =============================
@@ -1,16 +1,14 b''
1 IPython kernel documentation
1 IPython kernel documentation
2 ============================
2 ============================
3
3
4 User Documentation
4 User Documentation
5 ------------------
5 ------------------
6
6
7 .. toctree::
7 .. toctree::
8 :maxdepth: 2
8 :maxdepth: 2
9
9
10 install.txt
11 parallel_intro.txt
10 parallel_intro.txt
12 parallel_multiengine.txt
11 parallel_multiengine.txt
13 parallel_task.txt
12 parallel_task.txt
14 parallel_mpi.txt
13 parallel_mpi.txt
15 changes.txt
14
16 faq.txt
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now