##// END OF EJS Templates
docs: update pdf docs author line and add introduction about authorship details
Ville M. Vainio -
Show More
@@ -1,132 +1,132 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 #
2 #
3 # IPython documentation build configuration file, created by
3 # IPython documentation build configuration file, created by
4 # sphinx-quickstart.py on Sat Mar 29 15:36:13 2008.
4 # sphinx-quickstart.py on Sat Mar 29 15:36:13 2008.
5 #
5 #
6 # This file is execfile()d with the current directory set to its containing dir.
6 # This file is execfile()d with the current directory set to its containing dir.
7 #
7 #
8 # The contents of this file are pickled, so don't put values in the namespace
8 # The contents of this file are pickled, so don't put values in the namespace
9 # that aren't pickleable (module imports are okay, they're removed automatically).
9 # that aren't pickleable (module imports are okay, they're removed automatically).
10 #
10 #
11 # All configuration values have a default value; values that are commented out
11 # All configuration values have a default value; values that are commented out
12 # serve to show the default value.
12 # serve to show the default value.
13
13
14 import sys
14 import sys
15
15
16 # If your extensions are in another directory, add it here.
16 # If your extensions are in another directory, add it here.
17 #sys.path.append('some/directory')
17 #sys.path.append('some/directory')
18
18
19 # General configuration
19 # General configuration
20 # ---------------------
20 # ---------------------
21
21
22 # Add any Sphinx extension module names here, as strings. They can be extensions
22 # Add any Sphinx extension module names here, as strings. They can be extensions
23 # coming with Sphinx (named 'sphinx.addons.*') or your custom ones.
23 # coming with Sphinx (named 'sphinx.addons.*') or your custom ones.
24 #extensions = []
24 #extensions = []
25
25
26 # Add any paths that contain templates here, relative to this directory.
26 # Add any paths that contain templates here, relative to this directory.
27 templates_path = ['_templates']
27 templates_path = ['_templates']
28
28
29 # The suffix of source filenames.
29 # The suffix of source filenames.
30 source_suffix = '.rst'
30 source_suffix = '.rst'
31
31
32 # The master toctree document.
32 # The master toctree document.
33 master_doc = 'ipython'
33 master_doc = 'ipython'
34
34
35 # General substitutions.
35 # General substitutions.
36 project = 'IPython'
36 project = 'IPython'
37 copyright = '2008, Fernando Perez'
37 copyright = '2008, Fernando Perez'
38
38
39 # The default replacements for |version| and |release|, also used in various
39 # The default replacements for |version| and |release|, also used in various
40 # other places throughout the built documents.
40 # other places throughout the built documents.
41 #
41 #
42 # The short X.Y version.
42 # The short X.Y version.
43 version = '0.8.3'
43 version = '0.8.3'
44 # The full version, including alpha/beta/rc tags.
44 # The full version, including alpha/beta/rc tags.
45 release = '0.8.3'
45 release = '0.8.3'
46
46
47 # There are two options for replacing |today|: either, you set today to some
47 # There are two options for replacing |today|: either, you set today to some
48 # non-false value, then it is used:
48 # non-false value, then it is used:
49 #today = ''
49 #today = ''
50 # Else, today_fmt is used as the format for a strftime call.
50 # Else, today_fmt is used as the format for a strftime call.
51 today_fmt = '%B %d, %Y'
51 today_fmt = '%B %d, %Y'
52
52
53 # List of documents that shouldn't be included in the build.
53 # List of documents that shouldn't be included in the build.
54 #unused_docs = []
54 #unused_docs = []
55
55
56 # If true, '()' will be appended to :func: etc. cross-reference text.
56 # If true, '()' will be appended to :func: etc. cross-reference text.
57 #add_function_parentheses = True
57 #add_function_parentheses = True
58
58
59 # If true, the current module name will be prepended to all description
59 # If true, the current module name will be prepended to all description
60 # unit titles (such as .. function::).
60 # unit titles (such as .. function::).
61 #add_module_names = True
61 #add_module_names = True
62
62
63 # If true, sectionauthor and moduleauthor directives will be shown in the
63 # If true, sectionauthor and moduleauthor directives will be shown in the
64 # output. They are ignored by default.
64 # output. They are ignored by default.
65 #show_authors = False
65 #show_authors = False
66
66
67 # The name of the Pygments (syntax highlighting) style to use.
67 # The name of the Pygments (syntax highlighting) style to use.
68 pygments_style = 'sphinx'
68 pygments_style = 'sphinx'
69
69
70
70
71 # Options for HTML output
71 # Options for HTML output
72 # -----------------------
72 # -----------------------
73
73
74 # The style sheet to use for HTML and HTML Help pages. A file of that name
74 # The style sheet to use for HTML and HTML Help pages. A file of that name
75 # must exist either in Sphinx' static/ path, or in one of the custom paths
75 # must exist either in Sphinx' static/ path, or in one of the custom paths
76 # given in html_static_path.
76 # given in html_static_path.
77 html_style = 'default.css'
77 html_style = 'default.css'
78
78
79 # Add any paths that contain custom static files (such as style sheets) here,
79 # Add any paths that contain custom static files (such as style sheets) here,
80 # relative to this directory. They are copied after the builtin static files,
80 # relative to this directory. They are copied after the builtin static files,
81 # so a file named "default.css" will overwrite the builtin "default.css".
81 # so a file named "default.css" will overwrite the builtin "default.css".
82 html_static_path = ['_static']
82 html_static_path = ['_static']
83
83
84 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
84 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
85 # using the given strftime format.
85 # using the given strftime format.
86 html_last_updated_fmt = '%b %d, %Y'
86 html_last_updated_fmt = '%b %d, %Y'
87
87
88 # If true, SmartyPants will be used to convert quotes and dashes to
88 # If true, SmartyPants will be used to convert quotes and dashes to
89 # typographically correct entities.
89 # typographically correct entities.
90 #html_use_smartypants = True
90 #html_use_smartypants = True
91
91
92 # Content template for the index page.
92 # Content template for the index page.
93 #html_index = ''
93 #html_index = ''
94
94
95 # Custom sidebar templates, maps document names to template names.
95 # Custom sidebar templates, maps document names to template names.
96 #html_sidebars = {}
96 #html_sidebars = {}
97
97
98 # Additional templates that should be rendered to pages, maps page names to
98 # Additional templates that should be rendered to pages, maps page names to
99 # template names.
99 # template names.
100 #html_additional_pages = {}
100 #html_additional_pages = {}
101
101
102 # If false, no module index is generated.
102 # If false, no module index is generated.
103 #html_use_modindex = True
103 #html_use_modindex = True
104
104
105 # If true, the reST sources are included in the HTML build as _sources/<name>.
105 # If true, the reST sources are included in the HTML build as _sources/<name>.
106 #html_copy_source = True
106 #html_copy_source = True
107
107
108 # Output file base name for HTML help builder.
108 # Output file base name for HTML help builder.
109 htmlhelp_basename = 'IPythondoc'
109 htmlhelp_basename = 'IPythondoc'
110
110
111
111
112 # Options for LaTeX output
112 # Options for LaTeX output
113 # ------------------------
113 # ------------------------
114
114
115 # The paper size ('letter' or 'a4').
115 # The paper size ('letter' or 'a4').
116 latex_paper_size = 'a4'
116 latex_paper_size = 'a4'
117
117
118 # The font size ('10pt', '11pt' or '12pt').
118 # The font size ('10pt', '11pt' or '12pt').
119 latex_font_size = '10pt'
119 latex_font_size = '10pt'
120
120
121 # Grouping the document tree into LaTeX files. List of tuples
121 # Grouping the document tree into LaTeX files. List of tuples
122 # (source start file, target name, title, author, document class [howto/manual]).
122 # (source start file, target name, title, author, document class [howto/manual]).
123 latex_documents = [('ipython','ipython.tex','IPython Documentation','Fernando Perez','manual')]
123 latex_documents = [('ipython','ipython.tex','IPython Documentation','Fernando Perez (and contributors)','manual')]
124
124
125 # Additional stuff for the LaTeX preamble.
125 # Additional stuff for the LaTeX preamble.
126 #latex_preamble = ''
126 #latex_preamble = ''
127
127
128 # Documents to append as an appendix to all manuals.
128 # Documents to append as an appendix to all manuals.
129 #latex_appendices = []
129 #latex_appendices = []
130
130
131 # If false, no module index is generated.
131 # If false, no module index is generated.
132 #latex_use_modindex = True
132 #latex_use_modindex = True
@@ -1,5860 +1,5875 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
21 ============
22
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
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
27 emerged, this manual has been updated to reflect that fact. Most of
28 the additions have been authored by Ville M. Vainio.
29
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
32 future. Some reST artifacts and bugs may still be apparent in the
33 documentation, but this should improve as the toolchain matures.
34
20 Overview
35 Overview
21 ========
36 ========
22
37
23 One of Python's most useful features is its interactive interpreter.
38 One of Python's most useful features is its interactive interpreter.
24 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
25 creating test files as is typical in most programming languages.
40 creating test files as is typical in most programming languages.
26 However, the interpreter supplied with the standard Python distribution
41 However, the interpreter supplied with the standard Python distribution
27 is somewhat limited for extended interactive use.
42 is somewhat limited for extended interactive use.
28
43
29 IPython is a free software project (released under the BSD license)
44 IPython is a free software project (released under the BSD license)
30 which tries to:
45 which tries to:
31
46
32 1. Provide an interactive shell superior to Python's default. IPython
47 1. Provide an interactive shell superior to Python's default. IPython
33 has many features for object introspection, system shell access,
48 has many features for object introspection, system shell access,
34 and its own special command system for adding functionality when
49 and its own special command system for adding functionality when
35 working interactively. It tries to be a very efficient environment
50 working interactively. It tries to be a very efficient environment
36 both for Python code development and for exploration of problems
51 both for Python code development and for exploration of problems
37 using Python objects (in situations like data analysis).
52 using Python objects (in situations like data analysis).
38 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
39 programs. IPython can be started with a single call from inside
54 programs. IPython can be started with a single call from inside
40 another program, providing access to the current namespace. This
55 another program, providing access to the current namespace. This
41 can be very useful both for debugging purposes and for situations
56 can be very useful both for debugging purposes and for situations
42 where a blend of batch-processing and interactive exploration are
57 where a blend of batch-processing and interactive exploration are
43 needed.
58 needed.
44 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
45 environment for other systems with Python as the underlying
60 environment for other systems with Python as the underlying
46 language. Specifically scientific environments like Mathematica,
61 language. Specifically scientific environments like Mathematica,
47 IDL and Matlab inspired its design, but similar ideas can be
62 IDL and Matlab inspired its design, but similar ideas can be
48 useful in many fields.
63 useful in many fields.
49 4. Allow interactive testing of threaded graphical toolkits. IPython
64 4. Allow interactive testing of threaded graphical toolkits. IPython
50 has support for interactive, non-blocking control of GTK, Qt and
65 has support for interactive, non-blocking control of GTK, Qt and
51 WX applications via special threading flags. The normal Python
66 WX applications via special threading flags. The normal Python
52 shell can only do this for Tkinter applications.
67 shell can only do this for Tkinter applications.
53
68
54
69
55 Main features
70 Main features
56 -------------
71 -------------
57
72
58 * Dynamic object introspection. One can access docstrings, function
73 * Dynamic object introspection. One can access docstrings, function
59 definition prototypes, source code, source files and other details
74 definition prototypes, source code, source files and other details
60 of any object accessible to the interpreter with a single
75 of any object accessible to the interpreter with a single
61 keystroke ('?', and using '??' provides additional detail).
76 keystroke ('?', and using '??' provides additional detail).
62 * Searching through modules and namespaces with '*' wildcards, both
77 * Searching through modules and namespaces with '*' wildcards, both
63 when using the '?' system and via the %psearch command.
78 when using the '?' system and via the %psearch command.
64 * Completion in the local namespace, by typing TAB at the prompt.
79 * Completion in the local namespace, by typing TAB at the prompt.
65 This works for keywords, modules, methods, variables and files in the
80 This works for keywords, modules, methods, variables and files in the
66 current directory. This is supported via the readline library, and
81 current directory. This is supported via the readline library, and
67 full access to configuring readline's behavior is provided.
82 full access to configuring readline's behavior is provided.
68 Custom completers can be implemented easily for different purposes
83 Custom completers can be implemented easily for different purposes
69 (system commands, magic arguments etc.)
84 (system commands, magic arguments etc.)
70 * Numbered input/output prompts with command history (persistent
85 * Numbered input/output prompts with command history (persistent
71 across sessions and tied to each profile), full searching in this
86 across sessions and tied to each profile), full searching in this
72 history and caching of all input and output.
87 history and caching of all input and output.
73 * User-extensible 'magic' commands. A set of commands prefixed with
88 * User-extensible 'magic' commands. A set of commands prefixed with
74 % is available for controlling IPython itself and provides
89 % is available for controlling IPython itself and provides
75 directory control, namespace information and many aliases to
90 directory control, namespace information and many aliases to
76 common system shell commands.
91 common system shell commands.
77 * Alias facility for defining your own system aliases.
92 * Alias facility for defining your own system aliases.
78 * Complete system shell access. Lines starting with ! are passed
93 * Complete system shell access. Lines starting with ! are passed
79 directly to the system shell, and using !! or var = !cmd
94 directly to the system shell, and using !! or var = !cmd
80 captures shell output into python variables for further use.
95 captures shell output into python variables for further use.
81 * Background execution of Python commands in a separate thread.
96 * Background execution of Python commands in a separate thread.
82 IPython has an internal job manager called jobs, and a
97 IPython has an internal job manager called jobs, and a
83 conveninence backgrounding magic function called %bg.
98 conveninence backgrounding magic function called %bg.
84 * The ability to expand python variables when calling the system
99 * The ability to expand python variables when calling the system
85 shell. In a shell command, any python variable prefixed with $ is
100 shell. In a shell command, any python variable prefixed with $ is
86 expanded. A double $$ allows passing a literal $ to the shell (for
101 expanded. A double $$ allows passing a literal $ to the shell (for
87 access to shell and environment variables like $PATH).
102 access to shell and environment variables like $PATH).
88 * Filesystem navigation, via a magic %cd command, along with a
103 * Filesystem navigation, via a magic %cd command, along with a
89 persistent bookmark system (using %bookmark) for fast access to
104 persistent bookmark system (using %bookmark) for fast access to
90 frequently visited directories.
105 frequently visited directories.
91 * A lightweight persistence framework via the %store command, which
106 * A lightweight persistence framework via the %store command, which
92 allows you to save arbitrary Python variables. These get restored
107 allows you to save arbitrary Python variables. These get restored
93 automatically when your session restarts.
108 automatically when your session restarts.
94 * Automatic indentation (optional) of code as you type (through the
109 * Automatic indentation (optional) of code as you type (through the
95 readline library).
110 readline library).
96 * Macro system for quickly re-executing multiple lines of previous
111 * Macro system for quickly re-executing multiple lines of previous
97 input with a single name. Macros can be stored persistently via
112 input with a single name. Macros can be stored persistently via
98 %store and edited via %edit.
113 %store and edited via %edit.
99 * 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
100 programs). Logs can optionally timestamp all input, and also store
115 programs). Logs can optionally timestamp all input, and also store
101 session output (marked as comments, so the log remains valid
116 session output (marked as comments, so the log remains valid
102 Python source code).
117 Python source code).
103 * Session restoring: logs can be replayed to restore a previous
118 * Session restoring: logs can be replayed to restore a previous
104 session to the state where you left it.
119 session to the state where you left it.
105 * Verbose and colored exception traceback printouts. Easier to parse
120 * Verbose and colored exception traceback printouts. Easier to parse
106 visually, and in verbose mode they produce a lot of useful
121 visually, and in verbose mode they produce a lot of useful
107 debugging information (basically a terminal version of the cgitb
122 debugging information (basically a terminal version of the cgitb
108 module).
123 module).
109 * Auto-parentheses: callable objects can be executed without
124 * Auto-parentheses: callable objects can be executed without
110 parentheses: 'sin 3' is automatically converted to 'sin(3)'.
125 parentheses: 'sin 3' is automatically converted to 'sin(3)'.
111 * Auto-quoting: using ',' or ';' as the first character forces
126 * Auto-quoting: using ',' or ';' as the first character forces
112 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
113 automatically 'my_function("a","b")', while ';my_function a b'
128 automatically 'my_function("a","b")', while ';my_function a b'
114 becomes 'my_function("a b")'.
129 becomes 'my_function("a b")'.
115 * Extensible input syntax. You can define filters that pre-process
130 * Extensible input syntax. You can define filters that pre-process
116 user input to simplify input in special situations. This allows
131 user input to simplify input in special situations. This allows
117 for example pasting multi-line code fragments which start with
132 for example pasting multi-line code fragments which start with
118 '>>>' or '...' such as those from other python sessions or the
133 '>>>' or '...' such as those from other python sessions or the
119 standard Python documentation.
134 standard Python documentation.
120 * Flexible configuration system. It uses a configuration file which
135 * Flexible configuration system. It uses a configuration file which
121 allows permanent setting of all command-line options, module
136 allows permanent setting of all command-line options, module
122 loading, code and file execution. The system allows recursive file
137 loading, code and file execution. The system allows recursive file
123 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
124 which load other customizations for particular projects.
139 which load other customizations for particular projects.
125 * 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
126 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
127 providing interactive abilities to your programs with knowledge
142 providing interactive abilities to your programs with knowledge
128 about the local namespaces (very useful in debugging and data
143 about the local namespaces (very useful in debugging and data
129 analysis situations).
144 analysis situations).
130 * 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
131 version of the Python debugger (pdb) every time there is an
146 version of the Python debugger (pdb) every time there is an
132 uncaught exception. This drops you inside the code which triggered
147 uncaught exception. This drops you inside the code which triggered
133 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
134 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
135 %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
136 pdb's control, automatically setting initial breakpoints for you.
151 pdb's control, automatically setting initial breakpoints for you.
137 This version of pdb has IPython-specific improvements, including
152 This version of pdb has IPython-specific improvements, including
138 tab-completion and traceback coloring support. For even easier
153 tab-completion and traceback coloring support. For even easier
139 debugger access, try %debug after seeing an exception. winpdb is
154 debugger access, try %debug after seeing an exception. winpdb is
140 also supported, see ipy_winpdb extension.
155 also supported, see ipy_winpdb extension.
141 * Profiler support. You can run single statements (similar to
156 * Profiler support. You can run single statements (similar to
142 profile.run()) or complete programs under the profiler's control.
157 profile.run()) or complete programs under the profiler's control.
143 While this is possible with standard cProfile or profile modules,
158 While this is possible with standard cProfile or profile modules,
144 IPython wraps this functionality with magic commands (see '%prun'
159 IPython wraps this functionality with magic commands (see '%prun'
145 and '%run -p') convenient for rapid interactive work.
160 and '%run -p') convenient for rapid interactive work.
146 * Doctest support. The special %doctest_mode command toggles a mode
161 * Doctest support. The special %doctest_mode command toggles a mode
147 that allows you to paste existing doctests (with leading '>>>'
162 that allows you to paste existing doctests (with leading '>>>'
148 prompts and whitespace) and uses doctest-compatible prompts and
163 prompts and whitespace) and uses doctest-compatible prompts and
149 output, so you can use IPython sessions as doctest code.
164 output, so you can use IPython sessions as doctest code.
150
165
151
166
152 Portability and Python requirements
167 Portability and Python requirements
153 -----------------------------------
168 -----------------------------------
154
169
155 Python requirements: IPython requires with Python version 2.3 or newer.
170 Python requirements: IPython requires with Python version 2.3 or newer.
156 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
157 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
158 use that.
173 use that.
159
174
160 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
161 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
162 a port exists thanks to Dryice Liu).
177 a port exists thanks to Dryice Liu).
163
178
164 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
165 at Lawrence Livermore for the information). Thanks to Andrea Riciputi,
180 at Lawrence Livermore for the information). Thanks to Andrea Riciputi,
166 Fink support is available.
181 Fink support is available.
167
182
168 CygWin: it works mostly OK, though some users have reported problems
183 CygWin: it works mostly OK, though some users have reported problems
169 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
170 far, you may want to disable colors permanently in the ipythonrc
185 far, you may want to disable colors permanently in the ipythonrc
171 configuration file if you experience problems. If you have proper color
186 configuration file if you experience problems. If you have proper color
172 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
173 issue can be resolved for all users.
188 issue can be resolved for all users.
174
189
175 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
176 behave similarly. Section "Installation under windows" describes
191 behave similarly. Section "Installation under windows" describes
177 installation details for Windows, including some additional tools needed
192 installation details for Windows, including some additional tools needed
178 on this platform.
193 on this platform.
179
194
180 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
181 least on WinME).
196 least on WinME).
182
197
183 Location
198 Location
184 ========
199 --------
185
200
186 IPython is generously hosted at http://ipython.scipy.org by the
201 IPython is generously hosted at http://ipython.scipy.org by the
187 Enthought, Inc and the SciPy project. This site offers downloads,
202 Enthought, Inc and the SciPy project. This site offers downloads,
188 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
189 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
190 team for their contribution.
205 team for their contribution.
191
206
192 Installation
207 Installation
193 ============
208 ============
194
209
195 Instant instructions
210 Instant instructions
196 --------------------
211 --------------------
197
212
198 If you are of the impatient kind, under Linux/Unix simply untar/unzip
213 If you are of the impatient kind, under Linux/Unix simply untar/unzip
199 the download, then install with 'python setup.py install'. Under
214 the download, then install with 'python setup.py install'. Under
200 Windows, double-click on the provided .exe binary installer.
215 Windows, double-click on the provided .exe binary installer.
201
216
202 Then, take a look at Customization_ section for configuring things
217 Then, take a look at Customization_ section for configuring things
203 optimally and `Quick tips`_ for quick tips on efficient use of
218 optimally and `Quick tips`_ for quick tips on efficient use of
204 IPython. You can later refer to the rest of the manual for all the
219 IPython. You can later refer to the rest of the manual for all the
205 gory details.
220 gory details.
206
221
207 See the notes in upgrading_ section for upgrading IPython versions.
222 See the notes in upgrading_ section for upgrading IPython versions.
208
223
209
224
210 Detailed Unix instructions (Linux, Mac OS X, etc.)
225 Detailed Unix instructions (Linux, Mac OS X, etc.)
211
226
212 For RPM based systems, simply install the supplied package in the usual
227 For RPM based systems, simply install the supplied package in the usual
213 manner. If you download the tar archive, the process is:
228 manner. If you download the tar archive, the process is:
214
229
215 1. Unzip/untar the ipython-XXX.tar.gz file wherever you want (XXX is
230 1. Unzip/untar the ipython-XXX.tar.gz file wherever you want (XXX is
216 the version number). It will make a directory called ipython-XXX.
231 the version number). It will make a directory called ipython-XXX.
217 Change into that directory where you will find the files README
232 Change into that directory where you will find the files README
218 and setup.py. Once you've completed the installation, you can
233 and setup.py. Once you've completed the installation, you can
219 safely remove this directory.
234 safely remove this directory.
220 2. If you are installing over a previous installation of version
235 2. If you are installing over a previous installation of version
221 0.2.0 or earlier, first remove your $HOME/.ipython directory,
236 0.2.0 or earlier, first remove your $HOME/.ipython directory,
222 since the configuration file format has changed somewhat (the '='
237 since the configuration file format has changed somewhat (the '='
223 were removed from all option specifications). Or you can call
238 were removed from all option specifications). Or you can call
224 ipython with the -upgrade option and it will do this automatically
239 ipython with the -upgrade option and it will do this automatically
225 for you.
240 for you.
226 3. IPython uses distutils, so you can install it by simply typing at
241 3. IPython uses distutils, so you can install it by simply typing at
227 the system prompt (don't type the $)::
242 the system prompt (don't type the $)::
228
243
229 $ python setup.py install
244 $ python setup.py install
230
245
231 Note that this assumes you have root access to your machine. If
246 Note that this assumes you have root access to your machine. If
232 you don't have root access or don't want IPython to go in the
247 you don't have root access or don't want IPython to go in the
233 default python directories, you'll need to use the ``--home`` option
248 default python directories, you'll need to use the ``--home`` option
234 (or ``--prefix``). For example::
249 (or ``--prefix``). For example::
235
250
236 $ python setup.py install --home $HOME/local
251 $ python setup.py install --home $HOME/local
237
252
238 will install IPython into $HOME/local and its subdirectories
253 will install IPython into $HOME/local and its subdirectories
239 (creating them if necessary).
254 (creating them if necessary).
240 You can type::
255 You can type::
241
256
242 $ python setup.py --help
257 $ python setup.py --help
243
258
244 for more details.
259 for more details.
245
260
246 Note that if you change the default location for ``--home`` at
261 Note that if you change the default location for ``--home`` at
247 installation, IPython may end up installed at a location which is
262 installation, IPython may end up installed at a location which is
248 not part of your $PYTHONPATH environment variable. In this case,
263 not part of your $PYTHONPATH environment variable. In this case,
249 you'll need to configure this variable to include the actual
264 you'll need to configure this variable to include the actual
250 directory where the IPython/ directory ended (typically the value
265 directory where the IPython/ directory ended (typically the value
251 you give to ``--home`` plus /lib/python).
266 you give to ``--home`` plus /lib/python).
252
267
253
268
254 Mac OSX information
269 Mac OSX information
255 -------------------
270 -------------------
256
271
257 Under OSX, there is a choice you need to make. Apple ships its own build
272 Under OSX, there is a choice you need to make. Apple ships its own build
258 of Python, which lives in the core OSX filesystem hierarchy. You can
273 of Python, which lives in the core OSX filesystem hierarchy. You can
259 also manually install a separate Python, either purely by hand
274 also manually install a separate Python, either purely by hand
260 (typically in /usr/local) or by using Fink, which puts everything under
275 (typically in /usr/local) or by using Fink, which puts everything under
261 /sw. Which route to follow is a matter of personal preference, as I've
276 /sw. Which route to follow is a matter of personal preference, as I've
262 seen users who favor each of the approaches. Here I will simply list the
277 seen users who favor each of the approaches. Here I will simply list the
263 known installation issues under OSX, along with their solutions.
278 known installation issues under OSX, along with their solutions.
264
279
265 This page: http://geosci.uchicago.edu/~tobis/pylab.html contains
280 This page: http://geosci.uchicago.edu/~tobis/pylab.html contains
266 information on this topic, with additional details on how to make
281 information on this topic, with additional details on how to make
267 IPython and matplotlib play nicely under OSX.
282 IPython and matplotlib play nicely under OSX.
268
283
269 To run IPython and readline on OSX "Leopard" system python, see the
284 To run IPython and readline on OSX "Leopard" system python, see the
270 wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard
285 wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard
271
286
272
287
273 GUI problems
288 GUI problems
274 ------------
289 ------------
275
290
276 The following instructions apply to an install of IPython under OSX from
291 The following instructions apply to an install of IPython under OSX from
277 unpacking the .tar.gz distribution and installing it for the default
292 unpacking the .tar.gz distribution and installing it for the default
278 Python interpreter shipped by Apple. If you are using a fink install,
293 Python interpreter shipped by Apple. If you are using a fink install,
279 fink will take care of these details for you, by installing IPython
294 fink will take care of these details for you, by installing IPython
280 against fink's Python.
295 against fink's Python.
281
296
282 IPython offers various forms of support for interacting with graphical
297 IPython offers various forms of support for interacting with graphical
283 applications from the command line, from simple Tk apps (which are in
298 applications from the command line, from simple Tk apps (which are in
284 principle always supported by Python) to interactive control of WX, Qt
299 principle always supported by Python) to interactive control of WX, Qt
285 and GTK apps. Under OSX, however, this requires that ipython is
300 and GTK apps. Under OSX, however, this requires that ipython is
286 installed by calling the special pythonw script at installation time,
301 installed by calling the special pythonw script at installation time,
287 which takes care of coordinating things with Apple's graphical environment.
302 which takes care of coordinating things with Apple's graphical environment.
288
303
289 So when installing under OSX, it is best to use the following command::
304 So when installing under OSX, it is best to use the following command::
290
305
291 $ sudo pythonw setup.py install --install-scripts=/usr/local/bin
306 $ sudo pythonw setup.py install --install-scripts=/usr/local/bin
292
307
293 or
308 or
294
309
295 $ sudo pythonw setup.py install --install-scripts=/usr/bin
310 $ sudo pythonw setup.py install --install-scripts=/usr/bin
296
311
297 depending on where you like to keep hand-installed executables.
312 depending on where you like to keep hand-installed executables.
298
313
299 The resulting script will have an appropriate shebang line (the first
314 The resulting script will have an appropriate shebang line (the first
300 line in the script whic begins with #!...) such that the ipython
315 line in the script whic begins with #!...) such that the ipython
301 interpreter can interact with the OS X GUI. If the installed version
316 interpreter can interact with the OS X GUI. If the installed version
302 does not work and has a shebang line that points to, for example, just
317 does not work and has a shebang line that points to, for example, just
303 /usr/bin/python, then you might have a stale, cached version in your
318 /usr/bin/python, then you might have a stale, cached version in your
304 build/scripts-<python-version> directory. Delete that directory and
319 build/scripts-<python-version> directory. Delete that directory and
305 rerun the setup.py.
320 rerun the setup.py.
306
321
307 It is also a good idea to use the special flag ``--install-scripts`` as
322 It is also a good idea to use the special flag ``--install-scripts`` as
308 indicated above, to ensure that the ipython scripts end up in a location
323 indicated above, to ensure that the ipython scripts end up in a location
309 which is part of your $PATH. Otherwise Apple's Python will put the
324 which is part of your $PATH. Otherwise Apple's Python will put the
310 scripts in an internal directory not available by default at the command
325 scripts in an internal directory not available by default at the command
311 line (if you use /usr/local/bin, you need to make sure this is in your
326 line (if you use /usr/local/bin, you need to make sure this is in your
312 $PATH, which may not be true by default).
327 $PATH, which may not be true by default).
313
328
314
329
315 Readline problems
330 Readline problems
316 -----------------
331 -----------------
317
332
318 By default, the Python version shipped by Apple does not include the
333 By default, the Python version shipped by Apple does not include the
319 readline library, so central to IPython's behavior. If you install
334 readline library, so central to IPython's behavior. If you install
320 IPython against Apple's Python, you will not have arrow keys, tab
335 IPython against Apple's Python, you will not have arrow keys, tab
321 completion, etc. For Mac OSX 10.3 (Panther), you can find a prebuilt
336 completion, etc. For Mac OSX 10.3 (Panther), you can find a prebuilt
322 readline library here:
337 readline library here:
323 http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip
338 http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip
324
339
325 If you are using OSX 10.4 (Tiger), after installing this package you
340 If you are using OSX 10.4 (Tiger), after installing this package you
326 need to either:
341 need to either:
327
342
328 1. move readline.so from /Library/Python/2.3 to
343 1. move readline.so from /Library/Python/2.3 to
329 /Library/Python/2.3/site-packages, or
344 /Library/Python/2.3/site-packages, or
330 2. install http://pythonmac.org/packages/TigerPython23Compat.pkg.zip
345 2. install http://pythonmac.org/packages/TigerPython23Compat.pkg.zip
331
346
332 Users installing against Fink's Python or a properly hand-built one
347 Users installing against Fink's Python or a properly hand-built one
333 should not have this problem.
348 should not have this problem.
334
349
335
350
336 DarwinPorts
351 DarwinPorts
337 -----------
352 -----------
338
353
339 I report here a message from an OSX user, who suggests an alternative
354 I report here a message from an OSX user, who suggests an alternative
340 means of using IPython under this operating system with good results.
355 means of using IPython under this operating system with good results.
341 Please let me know of any updates that may be useful for this section.
356 Please let me know of any updates that may be useful for this section.
342 His message is reproduced verbatim below:
357 His message is reproduced verbatim below:
343
358
344 From: Markus Banfi <markus.banfi-AT-mospheira.net>
359 From: Markus Banfi <markus.banfi-AT-mospheira.net>
345
360
346 As a MacOS X (10.4.2) user I prefer to install software using
361 As a MacOS X (10.4.2) user I prefer to install software using
347 DawinPorts instead of Fink. I had no problems installing ipython
362 DawinPorts instead of Fink. I had no problems installing ipython
348 with DarwinPorts. It's just:
363 with DarwinPorts. It's just:
349
364
350 sudo port install py-ipython
365 sudo port install py-ipython
351
366
352 It automatically resolved all dependencies (python24, readline,
367 It automatically resolved all dependencies (python24, readline,
353 py-readline). So far I did not encounter any problems with the
368 py-readline). So far I did not encounter any problems with the
354 DarwinPorts port of ipython.
369 DarwinPorts port of ipython.
355
370
356
371
357
372
358 Windows instructions
373 Windows instructions
359 --------------------
374 --------------------
360
375
361 Some of IPython's very useful features are:
376 Some of IPython's very useful features are:
362
377
363 * Integrated readline support (Tab-based file, object and attribute
378 * Integrated readline support (Tab-based file, object and attribute
364 completion, input history across sessions, editable command line,
379 completion, input history across sessions, editable command line,
365 etc.)
380 etc.)
366 * Coloring of prompts, code and tracebacks.
381 * Coloring of prompts, code and tracebacks.
367
382
368 .. _pyreadline:
383 .. _pyreadline:
369
384
370 These, by default, are only available under Unix-like operating systems.
385 These, by default, are only available under Unix-like operating systems.
371 However, thanks to Gary Bishop's work, Windows XP/2k users can also
386 However, thanks to Gary Bishop's work, Windows XP/2k users can also
372 benefit from them. His readline library originally implemented both GNU
387 benefit from them. His readline library originally implemented both GNU
373 readline functionality and color support, so that IPython under Windows
388 readline functionality and color support, so that IPython under Windows
374 XP/2k can be as friendly and powerful as under Unix-like environments.
389 XP/2k can be as friendly and powerful as under Unix-like environments.
375
390
376 This library, now named PyReadline, has been absorbed by the IPython
391 This library, now named PyReadline, has been absorbed by the IPython
377 team (Jörgen Stenarson, in particular), and it continues to be developed
392 team (Jörgen Stenarson, in particular), and it continues to be developed
378 with new features, as well as being distributed directly from the
393 with new features, as well as being distributed directly from the
379 IPython site.
394 IPython site.
380
395
381 The PyReadline extension requires CTypes and the windows IPython
396 The PyReadline extension requires CTypes and the windows IPython
382 installer needs PyWin32, so in all you need:
397 installer needs PyWin32, so in all you need:
383
398
384 1. PyWin32 from http://sourceforge.net/projects/pywin32.
399 1. PyWin32 from http://sourceforge.net/projects/pywin32.
385 2. PyReadline for Windows from
400 2. PyReadline for Windows from
386 http://ipython.scipy.org/moin/PyReadline/Intro. That page contains
401 http://ipython.scipy.org/moin/PyReadline/Intro. That page contains
387 further details on using and configuring the system to your liking.
402 further details on using and configuring the system to your liking.
388 3. Finally, only if you are using Python 2.3 or 2.4, you need CTypes
403 3. Finally, only if you are using Python 2.3 or 2.4, you need CTypes
389 from http://starship.python.net/crew/theller/ctypes(you must use
404 from http://starship.python.net/crew/theller/ctypes(you must use
390 version 0.9.1 or newer). This package is included in Python 2.5,
405 version 0.9.1 or newer). This package is included in Python 2.5,
391 so you don't need to manually get it if your Python version is 2.5
406 so you don't need to manually get it if your Python version is 2.5
392 or newer.
407 or newer.
393
408
394 Warning about a broken readline-like library: several users have
409 Warning about a broken readline-like library: several users have
395 reported problems stemming from using the pseudo-readline library at
410 reported problems stemming from using the pseudo-readline library at
396 http://newcenturycomputers.net/projects/readline.html. This is a broken
411 http://newcenturycomputers.net/projects/readline.html. This is a broken
397 library which, while called readline, only implements an incomplete
412 library which, while called readline, only implements an incomplete
398 subset of the readline API. Since it is still called readline, it fools
413 subset of the readline API. Since it is still called readline, it fools
399 IPython's detection mechanisms and causes unpredictable crashes later.
414 IPython's detection mechanisms and causes unpredictable crashes later.
400 If you wish to use IPython under Windows, you must NOT use this library,
415 If you wish to use IPython under Windows, you must NOT use this library,
401 which for all purposes is (at least as of version 1.6) terminally broken.
416 which for all purposes is (at least as of version 1.6) terminally broken.
402
417
403
418
404 Installation procedure
419 Installation procedure
405 ----------------------
420 ----------------------
406
421
407 Once you have the above installed, from the IPython download directory
422 Once you have the above installed, from the IPython download directory
408 grab the ipython-XXX.win32.exe file, where XXX represents the version
423 grab the ipython-XXX.win32.exe file, where XXX represents the version
409 number. This is a regular windows executable installer, which you can
424 number. This is a regular windows executable installer, which you can
410 simply double-click to install. It will add an entry for IPython to your
425 simply double-click to install. It will add an entry for IPython to your
411 Start Menu, as well as registering IPython in the Windows list of
426 Start Menu, as well as registering IPython in the Windows list of
412 applications, so you can later uninstall it from the Control Panel.
427 applications, so you can later uninstall it from the Control Panel.
413
428
414 IPython tries to install the configuration information in a directory
429 IPython tries to install the configuration information in a directory
415 named .ipython (_ipython under Windows) located in your 'home'
430 named .ipython (_ipython under Windows) located in your 'home'
416 directory. IPython sets this directory by looking for a HOME environment
431 directory. IPython sets this directory by looking for a HOME environment
417 variable; if such a variable does not exist, it uses HOMEDRIVE\HOMEPATH
432 variable; if such a variable does not exist, it uses HOMEDRIVE\HOMEPATH
418 (these are always defined by Windows). This typically gives something
433 (these are always defined by Windows). This typically gives something
419 like C:\Documents and Settings\YourUserName, but your local details may
434 like C:\Documents and Settings\YourUserName, but your local details may
420 vary. In this directory you will find all the files that configure
435 vary. In this directory you will find all the files that configure
421 IPython's defaults, and you can put there your profiles and extensions.
436 IPython's defaults, and you can put there your profiles and extensions.
422 This directory is automatically added by IPython to sys.path, so
437 This directory is automatically added by IPython to sys.path, so
423 anything you place there can be found by import statements.
438 anything you place there can be found by import statements.
424
439
425
440
426 Upgrading
441 Upgrading
427 ---------
442 ---------
428
443
429 For an IPython upgrade, you should first uninstall the previous version.
444 For an IPython upgrade, you should first uninstall the previous version.
430 This will ensure that all files and directories (such as the
445 This will ensure that all files and directories (such as the
431 documentation) which carry embedded version strings in their names are
446 documentation) which carry embedded version strings in their names are
432 properly removed.
447 properly removed.
433
448
434
449
435 Manual installation under Win32
450 Manual installation under Win32
436 -------------------------------
451 -------------------------------
437
452
438 In case the automatic installer does not work for some reason, you can
453 In case the automatic installer does not work for some reason, you can
439 download the ipython-XXX.tar.gz file, which contains the full IPython
454 download the ipython-XXX.tar.gz file, which contains the full IPython
440 source distribution (the popular WinZip can read .tar.gz files). After
455 source distribution (the popular WinZip can read .tar.gz files). After
441 uncompressing the archive, you can install it at a command terminal just
456 uncompressing the archive, you can install it at a command terminal just
442 like any other Python module, by using 'python setup.py install'.
457 like any other Python module, by using 'python setup.py install'.
443
458
444 After the installation, run the supplied win32_manual_post_install.py
459 After the installation, run the supplied win32_manual_post_install.py
445 script, which creates the necessary Start Menu shortcuts for you.
460 script, which creates the necessary Start Menu shortcuts for you.
446
461
447
462
448 .. upgrading:
463 .. upgrading:
449
464
450 Upgrading from a previous version
465 Upgrading from a previous version
451 ---------------------------------
466 ---------------------------------
452
467
453 If you are upgrading from a previous version of IPython, you may want
468 If you are upgrading from a previous version of IPython, you may want
454 to upgrade the contents of your ~/.ipython directory. Just run
469 to upgrade the contents of your ~/.ipython directory. Just run
455 %upgrade, look at the diffs and delete the suggested files manually,
470 %upgrade, look at the diffs and delete the suggested files manually,
456 if you think you can lose the old versions. %upgrade will never
471 if you think you can lose the old versions. %upgrade will never
457 overwrite or delete anything.
472 overwrite or delete anything.
458
473
459 Initial configuration of your environment
474 Initial configuration of your environment
460 =========================================
475 =========================================
461
476
462 This section will help you set various things in your environment for
477 This section will help you set various things in your environment for
463 your IPython sessions to be as efficient as possible. All of IPython's
478 your IPython sessions to be as efficient as possible. All of IPython's
464 configuration information, along with several example files, is stored
479 configuration information, along with several example files, is stored
465 in a directory named by default $HOME/.ipython. You can change this by
480 in a directory named by default $HOME/.ipython. You can change this by
466 defining the environment variable IPYTHONDIR, or at runtime with the
481 defining the environment variable IPYTHONDIR, or at runtime with the
467 command line option -ipythondir.
482 command line option -ipythondir.
468
483
469 If all goes well, the first time you run IPython it should
484 If all goes well, the first time you run IPython it should
470 automatically create a user copy of the config directory for you,
485 automatically create a user copy of the config directory for you,
471 based on its builtin defaults. You can look at the files it creates to
486 based on its builtin defaults. You can look at the files it creates to
472 learn more about configuring the system. The main file you will modify
487 learn more about configuring the system. The main file you will modify
473 to configure IPython's behavior is called ipythonrc (with a .ini
488 to configure IPython's behavior is called ipythonrc (with a .ini
474 extension under Windows), included for reference in `ipythonrc`_
489 extension under Windows), included for reference in `ipythonrc`_
475 section. This file is very commented and has many variables you can
490 section. This file is very commented and has many variables you can
476 change to suit your taste, you can find more details in
491 change to suit your taste, you can find more details in
477 Sec. customization_. Here we discuss the basic things you will want to
492 Sec. customization_. Here we discuss the basic things you will want to
478 make sure things are working properly from the beginning.
493 make sure things are working properly from the beginning.
479
494
480
495
481 .. _Accessing help:
496 .. _Accessing help:
482
497
483 Access to the Python help system
498 Access to the Python help system
484 --------------------------------
499 --------------------------------
485
500
486 This is true for Python in general (not just for IPython): you should
501 This is true for Python in general (not just for IPython): you should
487 have an environment variable called PYTHONDOCS pointing to the directory
502 have an environment variable called PYTHONDOCS pointing to the directory
488 where your HTML Python documentation lives. In my system it's
503 where your HTML Python documentation lives. In my system it's
489 /usr/share/doc/python-docs-2.3.4/html, check your local details or ask
504 /usr/share/doc/python-docs-2.3.4/html, check your local details or ask
490 your systems administrator.
505 your systems administrator.
491
506
492 This is the directory which holds the HTML version of the Python
507 This is the directory which holds the HTML version of the Python
493 manuals. Unfortunately it seems that different Linux distributions
508 manuals. Unfortunately it seems that different Linux distributions
494 package these files differently, so you may have to look around a bit.
509 package these files differently, so you may have to look around a bit.
495 Below I show the contents of this directory on my system for reference::
510 Below I show the contents of this directory on my system for reference::
496
511
497 [html]> ls
512 [html]> ls
498 about.dat acks.html dist/ ext/ index.html lib/ modindex.html
513 about.dat acks.html dist/ ext/ index.html lib/ modindex.html
499 stdabout.dat tut/ about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
514 stdabout.dat tut/ about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
500
515
501 You should really make sure this variable is correctly set so that
516 You should really make sure this variable is correctly set so that
502 Python's pydoc-based help system works. It is a powerful and convenient
517 Python's pydoc-based help system works. It is a powerful and convenient
503 system with full access to the Python manuals and all modules accessible
518 system with full access to the Python manuals and all modules accessible
504 to you.
519 to you.
505
520
506 Under Windows it seems that pydoc finds the documentation automatically,
521 Under Windows it seems that pydoc finds the documentation automatically,
507 so no extra setup appears necessary.
522 so no extra setup appears necessary.
508
523
509
524
510 Editor
525 Editor
511 ------
526 ------
512
527
513 The %edit command (and its alias %ed) will invoke the editor set in your
528 The %edit command (and its alias %ed) will invoke the editor set in your
514 environment as EDITOR. If this variable is not set, it will default to
529 environment as EDITOR. If this variable is not set, it will default to
515 vi under Linux/Unix and to notepad under Windows. You may want to set
530 vi under Linux/Unix and to notepad under Windows. You may want to set
516 this variable properly and to a lightweight editor which doesn't take
531 this variable properly and to a lightweight editor which doesn't take
517 too long to start (that is, something other than a new instance of
532 too long to start (that is, something other than a new instance of
518 Emacs). This way you can edit multi-line code quickly and with the power
533 Emacs). This way you can edit multi-line code quickly and with the power
519 of a real editor right inside IPython.
534 of a real editor right inside IPython.
520
535
521 If you are a dedicated Emacs user, you should set up the Emacs server so
536 If you are a dedicated Emacs user, you should set up the Emacs server so
522 that new requests are handled by the original process. This means that
537 that new requests are handled by the original process. This means that
523 almost no time is spent in handling the request (assuming an Emacs
538 almost no time is spent in handling the request (assuming an Emacs
524 process is already running). For this to work, you need to set your
539 process is already running). For this to work, you need to set your
525 EDITOR environment variable to 'emacsclient'. The code below, supplied
540 EDITOR environment variable to 'emacsclient'. The code below, supplied
526 by Francois Pinard, can then be used in your .emacs file to enable the
541 by Francois Pinard, can then be used in your .emacs file to enable the
527 server::
542 server::
528
543
529 (defvar server-buffer-clients)
544 (defvar server-buffer-clients)
530 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
545 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
531 (server-start)
546 (server-start)
532 (defun fp-kill-server-with-buffer-routine ()
547 (defun fp-kill-server-with-buffer-routine ()
533 (and server-buffer-clients (server-done)))
548 (and server-buffer-clients (server-done)))
534 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
549 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
535
550
536 You can also set the value of this editor via the commmand-line option
551 You can also set the value of this editor via the commmand-line option
537 '-editor' or in your ipythonrc file. This is useful if you wish to use
552 '-editor' or in your ipythonrc file. This is useful if you wish to use
538 specifically for IPython an editor different from your typical default
553 specifically for IPython an editor different from your typical default
539 (and for Windows users who tend to use fewer environment variables).
554 (and for Windows users who tend to use fewer environment variables).
540
555
541
556
542 Color
557 Color
543 -----
558 -----
544
559
545 The default IPython configuration has most bells and whistles turned on
560 The default IPython configuration has most bells and whistles turned on
546 (they're pretty safe). But there's one that may cause problems on some
561 (they're pretty safe). But there's one that may cause problems on some
547 systems: the use of color on screen for displaying information. This is
562 systems: the use of color on screen for displaying information. This is
548 very useful, since IPython can show prompts and exception tracebacks
563 very useful, since IPython can show prompts and exception tracebacks
549 with various colors, display syntax-highlighted source code, and in
564 with various colors, display syntax-highlighted source code, and in
550 general make it easier to visually parse information.
565 general make it easier to visually parse information.
551
566
552 The following terminals seem to handle the color sequences fine:
567 The following terminals seem to handle the color sequences fine:
553
568
554 * Linux main text console, KDE Konsole, Gnome Terminal, E-term,
569 * Linux main text console, KDE Konsole, Gnome Terminal, E-term,
555 rxvt, xterm.
570 rxvt, xterm.
556 * CDE terminal (tested under Solaris). This one boldfaces light colors.
571 * CDE terminal (tested under Solaris). This one boldfaces light colors.
557 * (X)Emacs buffers. See the emacs_ section for more details on
572 * (X)Emacs buffers. See the emacs_ section for more details on
558 using IPython with (X)Emacs.
573 using IPython with (X)Emacs.
559 * A Windows (XP/2k) command prompt with pyreadline_.
574 * A Windows (XP/2k) command prompt with pyreadline_.
560 * A Windows (XP/2k) CygWin shell. Although some users have reported
575 * A Windows (XP/2k) CygWin shell. Although some users have reported
561 problems; it is not clear whether there is an issue for everyone
576 problems; it is not clear whether there is an issue for everyone
562 or only under specific configurations. If you have full color
577 or only under specific configurations. If you have full color
563 support under cygwin, please post to the IPython mailing list so
578 support under cygwin, please post to the IPython mailing list so
564 this issue can be resolved for all users.
579 this issue can be resolved for all users.
565
580
566 These have shown problems:
581 These have shown problems:
567
582
568 * Windows command prompt in WinXP/2k logged into a Linux machine via
583 * Windows command prompt in WinXP/2k logged into a Linux machine via
569 telnet or ssh.
584 telnet or ssh.
570 * Windows native command prompt in WinXP/2k, without Gary Bishop's
585 * Windows native command prompt in WinXP/2k, without Gary Bishop's
571 extensions. Once Gary's readline library is installed, the normal
586 extensions. Once Gary's readline library is installed, the normal
572 WinXP/2k command prompt works perfectly.
587 WinXP/2k command prompt works perfectly.
573
588
574 Currently the following color schemes are available:
589 Currently the following color schemes are available:
575
590
576 * NoColor: uses no color escapes at all (all escapes are empty '' ''
591 * NoColor: uses no color escapes at all (all escapes are empty '' ''
577 strings). This 'scheme' is thus fully safe to use in any terminal.
592 strings). This 'scheme' is thus fully safe to use in any terminal.
578 * Linux: works well in Linux console type environments: dark
593 * Linux: works well in Linux console type environments: dark
579 background with light fonts. It uses bright colors for
594 background with light fonts. It uses bright colors for
580 information, so it is difficult to read if you have a light
595 information, so it is difficult to read if you have a light
581 colored background.
596 colored background.
582 * LightBG: the basic colors are similar to those in the Linux scheme
597 * LightBG: the basic colors are similar to those in the Linux scheme
583 but darker. It is easy to read in terminals with light backgrounds.
598 but darker. It is easy to read in terminals with light backgrounds.
584
599
585 IPython uses colors for two main groups of things: prompts and
600 IPython uses colors for two main groups of things: prompts and
586 tracebacks which are directly printed to the terminal, and the object
601 tracebacks which are directly printed to the terminal, and the object
587 introspection system which passes large sets of data through a pager.
602 introspection system which passes large sets of data through a pager.
588
603
589
604
590 Input/Output prompts and exception tracebacks
605 Input/Output prompts and exception tracebacks
591 ---------------------------------------------
606 ---------------------------------------------
592
607
593 You can test whether the colored prompts and tracebacks work on your
608 You can test whether the colored prompts and tracebacks work on your
594 system interactively by typing '%colors Linux' at the prompt (use
609 system interactively by typing '%colors Linux' at the prompt (use
595 '%colors LightBG' if your terminal has a light background). If the input
610 '%colors LightBG' if your terminal has a light background). If the input
596 prompt shows garbage like::
611 prompt shows garbage like::
597
612
598 [0;32mIn [[1;32m1[0;32m]: [0;00m
613 [0;32mIn [[1;32m1[0;32m]: [0;00m
599
614
600 instead of (in color) something like::
615 instead of (in color) something like::
601
616
602 In [1]:
617 In [1]:
603
618
604 this means that your terminal doesn't properly handle color escape
619 this means that your terminal doesn't properly handle color escape
605 sequences. You can go to a 'no color' mode by typing '%colors NoColor'.
620 sequences. You can go to a 'no color' mode by typing '%colors NoColor'.
606
621
607 You can try using a different terminal emulator program (Emacs users,
622 You can try using a different terminal emulator program (Emacs users,
608 see below). To permanently set your color preferences, edit the file
623 see below). To permanently set your color preferences, edit the file
609 $HOME/.ipython/ipythonrc and set the colors option to the desired value.
624 $HOME/.ipython/ipythonrc and set the colors option to the desired value.
610
625
611
626
612 Object details (types, docstrings, source code, etc.)
627 Object details (types, docstrings, source code, etc.)
613 -----------------------------------------------------
628 -----------------------------------------------------
614
629
615 IPython has a set of special functions for studying the objects you
630 IPython has a set of special functions for studying the objects you
616 are working with, discussed in detail in Sec. `dynamic object
631 are working with, discussed in detail in Sec. `dynamic object
617 information`_. But this system relies on passing information which is
632 information`_. But this system relies on passing information which is
618 longer than your screen through a data pager, such as the common Unix
633 longer than your screen through a data pager, such as the common Unix
619 less and more programs. In order to be able to see this information in
634 less and more programs. In order to be able to see this information in
620 color, your pager needs to be properly configured. I strongly
635 color, your pager needs to be properly configured. I strongly
621 recommend using less instead of more, as it seems that more simply can
636 recommend using less instead of more, as it seems that more simply can
622 not understand colored text correctly.
637 not understand colored text correctly.
623
638
624 In order to configure less as your default pager, do the following:
639 In order to configure less as your default pager, do the following:
625
640
626 1. Set the environment PAGER variable to less.
641 1. Set the environment PAGER variable to less.
627 2. Set the environment LESS variable to -r (plus any other options
642 2. Set the environment LESS variable to -r (plus any other options
628 you always want to pass to less by default). This tells less to
643 you always want to pass to less by default). This tells less to
629 properly interpret control sequences, which is how color
644 properly interpret control sequences, which is how color
630 information is given to your terminal.
645 information is given to your terminal.
631
646
632 For the csh or tcsh shells, add to your ~/.cshrc file the lines::
647 For the csh or tcsh shells, add to your ~/.cshrc file the lines::
633
648
634 setenv PAGER less
649 setenv PAGER less
635 setenv LESS -r
650 setenv LESS -r
636
651
637 There is similar syntax for other Unix shells, look at your system
652 There is similar syntax for other Unix shells, look at your system
638 documentation for details.
653 documentation for details.
639
654
640 If you are on a system which lacks proper data pagers (such as Windows),
655 If you are on a system which lacks proper data pagers (such as Windows),
641 IPython will use a very limited builtin pager.
656 IPython will use a very limited builtin pager.
642
657
643 .. _emacs:
658 .. _emacs:
644
659
645 (X)Emacs configuration
660 (X)Emacs configuration
646 ----------------------
661 ----------------------
647
662
648 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran,
663 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran,
649 currently (X)Emacs and IPython get along very well.
664 currently (X)Emacs and IPython get along very well.
650
665
651 Important note: You will need to use a recent enough version of
666 Important note: You will need to use a recent enough version of
652 python-mode.el, along with the file ipython.el. You can check that the
667 python-mode.el, along with the file ipython.el. You can check that the
653 version you have of python-mode.el is new enough by either looking at
668 version you have of python-mode.el is new enough by either looking at
654 the revision number in the file itself, or asking for it in (X)Emacs via
669 the revision number in the file itself, or asking for it in (X)Emacs via
655 M-x py-version. Versions 4.68 and newer contain the necessary fixes for
670 M-x py-version. Versions 4.68 and newer contain the necessary fixes for
656 proper IPython support.
671 proper IPython support.
657
672
658 The file ipython.el is included with the IPython distribution, in the
673 The file ipython.el is included with the IPython distribution, in the
659 documentation directory (where this manual resides in PDF and HTML
674 documentation directory (where this manual resides in PDF and HTML
660 formats).
675 formats).
661
676
662 Once you put these files in your Emacs path, all you need in your .emacs
677 Once you put these files in your Emacs path, all you need in your .emacs
663 file is::
678 file is::
664
679
665 (require 'ipython)
680 (require 'ipython)
666
681
667 This should give you full support for executing code snippets via
682 This should give you full support for executing code snippets via
668 IPython, opening IPython as your Python shell via C-c !, etc.
683 IPython, opening IPython as your Python shell via C-c !, etc.
669
684
670 If you happen to get garbage instead of colored prompts as described in
685 If you happen to get garbage instead of colored prompts as described in
671 the previous section, you may need to set also in your .emacs file::
686 the previous section, you may need to set also in your .emacs file::
672
687
673 (setq ansi-color-for-comint-mode t)
688 (setq ansi-color-for-comint-mode t)
674
689
675
690
676 Notes:
691 Notes:
677
692
678 * There is one caveat you should be aware of: you must start the
693 * There is one caveat you should be aware of: you must start the
679 IPython shell before attempting to execute any code regions via
694 IPython shell before attempting to execute any code regions via
680 ``C-c |``. Simply type C-c ! to start IPython before passing any code
695 ``C-c |``. Simply type C-c ! to start IPython before passing any code
681 regions to the interpreter, and you shouldn't experience any
696 regions to the interpreter, and you shouldn't experience any
682 problems.
697 problems.
683 This is due to a bug in Python itself, which has been fixed for
698 This is due to a bug in Python itself, which has been fixed for
684 Python 2.3, but exists as of Python 2.2.2 (reported as SF bug [
699 Python 2.3, but exists as of Python 2.2.2 (reported as SF bug [
685 737947 ]).
700 737947 ]).
686 * The (X)Emacs support is maintained by Alexander Schmolck, so all
701 * The (X)Emacs support is maintained by Alexander Schmolck, so all
687 comments/requests should be directed to him through the IPython
702 comments/requests should be directed to him through the IPython
688 mailing lists.
703 mailing lists.
689 * This code is still somewhat experimental so it's a bit rough
704 * This code is still somewhat experimental so it's a bit rough
690 around the edges (although in practice, it works quite well).
705 around the edges (although in practice, it works quite well).
691 * Be aware that if you customize py-python-command previously, this
706 * Be aware that if you customize py-python-command previously, this
692 value will override what ipython.el does (because loading the
707 value will override what ipython.el does (because loading the
693 customization variables comes later).
708 customization variables comes later).
694
709
695 .. Quick tips:
710 .. Quick tips:
696
711
697 Quick tips
712 Quick tips
698 ==========
713 ==========
699
714
700 IPython can be used as an improved replacement for the Python prompt,
715 IPython can be used as an improved replacement for the Python prompt,
701 and for that you don't really need to read any more of this manual. But
716 and for that you don't really need to read any more of this manual. But
702 in this section we'll try to summarize a few tips on how to make the
717 in this section we'll try to summarize a few tips on how to make the
703 most effective use of it for everyday Python development, highlighting
718 most effective use of it for everyday Python development, highlighting
704 things you might miss in the rest of the manual (which is getting long).
719 things you might miss in the rest of the manual (which is getting long).
705 We'll give references to parts in the manual which provide more detail
720 We'll give references to parts in the manual which provide more detail
706 when appropriate.
721 when appropriate.
707
722
708 The following article by Jeremy Jones provides an introductory tutorial
723 The following article by Jeremy Jones provides an introductory tutorial
709 about IPython:
724 about IPython:
710 http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html
725 http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html
711
726
712 * The TAB key. TAB-completion, especially for attributes, is a
727 * The TAB key. TAB-completion, especially for attributes, is a
713 convenient way to explore the structure of any object you're
728 convenient way to explore the structure of any object you're
714 dealing with. Simply type object_name.<TAB> and a list of the
729 dealing with. Simply type object_name.<TAB> and a list of the
715 object's attributes will be printed (see readline_ for
730 object's attributes will be printed (see readline_ for
716 more). Tab completion also works on
731 more). Tab completion also works on
717 file and directory names, which combined with IPython's alias
732 file and directory names, which combined with IPython's alias
718 system allows you to do from within IPython many of the things you
733 system allows you to do from within IPython many of the things you
719 normally would need the system shell for.
734 normally would need the system shell for.
720 * Explore your objects. Typing object_name? will print all sorts of
735 * Explore your objects. Typing object_name? will print all sorts of
721 details about any object, including docstrings, function
736 details about any object, including docstrings, function
722 definition lines (for call arguments) and constructor details for
737 definition lines (for call arguments) and constructor details for
723 classes. The magic commands %pdoc, %pdef, %psource and %pfile will
738 classes. The magic commands %pdoc, %pdef, %psource and %pfile will
724 respectively print the docstring, function definition line, full
739 respectively print the docstring, function definition line, full
725 source code and the complete file for any object (when they can be
740 source code and the complete file for any object (when they can be
726 found). If automagic is on (it is by default), you don't need to
741 found). If automagic is on (it is by default), you don't need to
727 type the '%' explicitly. See sec. `dynamic object information`_
742 type the '%' explicitly. See sec. `dynamic object information`_
728 for more.
743 for more.
729 * The %run magic command allows you to run any python script and
744 * The %run magic command allows you to run any python script and
730 load all of its data directly into the interactive namespace.
745 load all of its data directly into the interactive namespace.
731 Since the file is re-read from disk each time, changes you make to
746 Since the file is re-read from disk each time, changes you make to
732 it are reflected immediately (in contrast to the behavior of
747 it are reflected immediately (in contrast to the behavior of
733 import). I rarely use import for code I am testing, relying on
748 import). I rarely use import for code I am testing, relying on
734 %run instead. See magic_ section for more on this
749 %run instead. See magic_ section for more on this
735 and other magic commands, or type the name of any magic command
750 and other magic commands, or type the name of any magic command
736 and ? to get details on it. See also sec. dreload_ for a
751 and ? to get details on it. See also sec. dreload_ for a
737 recursive reload command.
752 recursive reload command.
738 %run also has special flags for timing the execution of your
753 %run also has special flags for timing the execution of your
739 scripts (-t) and for executing them under the control of either
754 scripts (-t) and for executing them under the control of either
740 Python's pdb debugger (-d) or profiler (-p). With all of these,
755 Python's pdb debugger (-d) or profiler (-p). With all of these,
741 %run can be used as the main tool for efficient interactive
756 %run can be used as the main tool for efficient interactive
742 development of code which you write in your editor of choice.
757 development of code which you write in your editor of choice.
743 * Use the Python debugger, pdb. The %pdb
758 * Use the Python debugger, pdb. The %pdb
744 command allows you to toggle on and off the automatic invocation
759 command allows you to toggle on and off the automatic invocation
745 of an IPython-enhanced pdb debugger (with coloring, tab completion
760 of an IPython-enhanced pdb debugger (with coloring, tab completion
746 and more) at any uncaught exception. The advantage of this is that
761 and more) at any uncaught exception. The advantage of this is that
747 pdb starts inside the function where the exception occurred, with
762 pdb starts inside the function where the exception occurred, with
748 all data still available. You can print variables, see code,
763 all data still available. You can print variables, see code,
749 execute statements and even walk up and down the call stack to
764 execute statements and even walk up and down the call stack to
750 track down the true source of the problem (which often is many
765 track down the true source of the problem (which often is many
751 layers in the stack above where the exception gets triggered).
766 layers in the stack above where the exception gets triggered).
752 Running programs with %run and pdb active can be an efficient to
767 Running programs with %run and pdb active can be an efficient to
753 develop and debug code, in many cases eliminating the need for
768 develop and debug code, in many cases eliminating the need for
754 print statements or external debugging tools. I often simply put a
769 print statements or external debugging tools. I often simply put a
755 1/0 in a place where I want to take a look so that pdb gets
770 1/0 in a place where I want to take a look so that pdb gets
756 called, quickly view whatever variables I need to or test various
771 called, quickly view whatever variables I need to or test various
757 pieces of code and then remove the 1/0.
772 pieces of code and then remove the 1/0.
758 Note also that '%run -d' activates pdb and automatically sets
773 Note also that '%run -d' activates pdb and automatically sets
759 initial breakpoints for you to step through your code, watch
774 initial breakpoints for you to step through your code, watch
760 variables, etc. See Sec. `Output caching`_ for
775 variables, etc. See Sec. `Output caching`_ for
761 details.
776 details.
762 * Use the output cache. All output results are automatically stored
777 * Use the output cache. All output results are automatically stored
763 in a global dictionary named Out and variables named _1, _2, etc.
778 in a global dictionary named Out and variables named _1, _2, etc.
764 alias them. For example, the result of input line 4 is available
779 alias them. For example, the result of input line 4 is available
765 either as Out[4] or as _4. Additionally, three variables named _,
780 either as Out[4] or as _4. Additionally, three variables named _,
766 __ and ___ are always kept updated with the for the last three
781 __ and ___ are always kept updated with the for the last three
767 results. This allows you to recall any previous result and further
782 results. This allows you to recall any previous result and further
768 use it for new calculations. See Sec. `Output caching`_ for more.
783 use it for new calculations. See Sec. `Output caching`_ for more.
769 * Put a ';' at the end of a line to supress the printing of output.
784 * Put a ';' at the end of a line to supress the printing of output.
770 This is useful when doing calculations which generate long output
785 This is useful when doing calculations which generate long output
771 you are not interested in seeing. The _* variables and the Out[]
786 you are not interested in seeing. The _* variables and the Out[]
772 list do get updated with the contents of the output, even if it is
787 list do get updated with the contents of the output, even if it is
773 not printed. You can thus still access the generated results this
788 not printed. You can thus still access the generated results this
774 way for further processing.
789 way for further processing.
775 * A similar system exists for caching input. All input is stored in
790 * A similar system exists for caching input. All input is stored in
776 a global list called In , so you can re-execute lines 22 through
791 a global list called In , so you can re-execute lines 22 through
777 28 plus line 34 by typing 'exec In[22:29]+In[34]' (using Python
792 28 plus line 34 by typing 'exec In[22:29]+In[34]' (using Python
778 slicing notation). If you need to execute the same set of lines
793 slicing notation). If you need to execute the same set of lines
779 often, you can assign them to a macro with the %macro function.
794 often, you can assign them to a macro with the %macro function.
780 See sec. `Input caching`_ for more.
795 See sec. `Input caching`_ for more.
781 * Use your input history. The %hist command can show you all
796 * Use your input history. The %hist command can show you all
782 previous input, without line numbers if desired (option -n) so you
797 previous input, without line numbers if desired (option -n) so you
783 can directly copy and paste code either back in IPython or in a
798 can directly copy and paste code either back in IPython or in a
784 text editor. You can also save all your history by turning on
799 text editor. You can also save all your history by turning on
785 logging via %logstart; these logs can later be either reloaded as
800 logging via %logstart; these logs can later be either reloaded as
786 IPython sessions or used as code for your programs.
801 IPython sessions or used as code for your programs.
787 * Define your own system aliases. Even though IPython gives you
802 * Define your own system aliases. Even though IPython gives you
788 access to your system shell via the ! prefix, it is convenient to
803 access to your system shell via the ! prefix, it is convenient to
789 have aliases to the system commands you use most often. This
804 have aliases to the system commands you use most often. This
790 allows you to work seamlessly from inside IPython with the same
805 allows you to work seamlessly from inside IPython with the same
791 commands you are used to in your system shell.
806 commands you are used to in your system shell.
792 IPython comes with some pre-defined aliases and a complete system
807 IPython comes with some pre-defined aliases and a complete system
793 for changing directories, both via a stack (see %pushd, %popd and
808 for changing directories, both via a stack (see %pushd, %popd and
794 %dhist) and via direct %cd. The latter keeps a history of visited
809 %dhist) and via direct %cd. The latter keeps a history of visited
795 directories and allows you to go to any previously visited one.
810 directories and allows you to go to any previously visited one.
796 * Use Python to manipulate the results of system commands. The '!!'
811 * Use Python to manipulate the results of system commands. The '!!'
797 special syntax, and the %sc and %sx magic commands allow you to
812 special syntax, and the %sc and %sx magic commands allow you to
798 capture system output into Python variables.
813 capture system output into Python variables.
799 * Expand python variables when calling the shell (either via '!' and
814 * Expand python variables when calling the shell (either via '!' and
800 '!!' or via aliases) by prepending a $ in front of them. You can
815 '!!' or via aliases) by prepending a $ in front of them. You can
801 also expand complete python expressions. See
816 also expand complete python expressions. See
802 `System shell access`_ for more.
817 `System shell access`_ for more.
803 * Use profiles to maintain different configurations (modules to
818 * Use profiles to maintain different configurations (modules to
804 load, function definitions, option settings) for particular tasks.
819 load, function definitions, option settings) for particular tasks.
805 You can then have customized versions of IPython for specific
820 You can then have customized versions of IPython for specific
806 purposes. See sec. profiles_ for more.
821 purposes. See sec. profiles_ for more.
807 * Embed IPython in your programs. A few lines of code are enough to
822 * Embed IPython in your programs. A few lines of code are enough to
808 load a complete IPython inside your own programs, giving you the
823 load a complete IPython inside your own programs, giving you the
809 ability to work with your data interactively after automatic
824 ability to work with your data interactively after automatic
810 processing has been completed. See sec. embedding_
825 processing has been completed. See sec. embedding_
811 for more.
826 for more.
812 * Use the Python profiler. When dealing with performance issues, the
827 * Use the Python profiler. When dealing with performance issues, the
813 %run command with a -p option allows you to run complete programs
828 %run command with a -p option allows you to run complete programs
814 under the control of the Python profiler. The %prun command does a
829 under the control of the Python profiler. The %prun command does a
815 similar job for single Python expressions (like function calls).
830 similar job for single Python expressions (like function calls).
816 * Use the IPython.demo.Demo class to load any Python script as an
831 * Use the IPython.demo.Demo class to load any Python script as an
817 interactive demo. With a minimal amount of simple markup, you can
832 interactive demo. With a minimal amount of simple markup, you can
818 control the execution of the script, stopping as needed. See
833 control the execution of the script, stopping as needed. See
819 sec. `interactive demos`_ for more.
834 sec. `interactive demos`_ for more.
820 * Run your doctests from within IPython for development and
835 * Run your doctests from within IPython for development and
821 debugging. The special %doctest_mode command toggles a mode where
836 debugging. The special %doctest_mode command toggles a mode where
822 the prompt, output and exceptions display matches as closely as
837 the prompt, output and exceptions display matches as closely as
823 possible that of the default Python interpreter. In addition, this
838 possible that of the default Python interpreter. In addition, this
824 mode allows you to directly paste in code that contains leading
839 mode allows you to directly paste in code that contains leading
825 '>>>' prompts, even if they have extra leading whitespace (as is
840 '>>>' prompts, even if they have extra leading whitespace (as is
826 common in doctest files). This combined with the '%history -tn'
841 common in doctest files). This combined with the '%history -tn'
827 call to see your translated history (with these extra prompts
842 call to see your translated history (with these extra prompts
828 removed and no line numbers) allows for an easy doctest workflow,
843 removed and no line numbers) allows for an easy doctest workflow,
829 where you can go from doctest to interactive execution to pasting
844 where you can go from doctest to interactive execution to pasting
830 into valid Python code as needed.
845 into valid Python code as needed.
831
846
832
847
833 Source code handling tips
848 Source code handling tips
834 -------------------------
849 -------------------------
835
850
836 IPython is a line-oriented program, without full control of the
851 IPython is a line-oriented program, without full control of the
837 terminal. Therefore, it doesn't support true multiline editing. However,
852 terminal. Therefore, it doesn't support true multiline editing. However,
838 it has a number of useful tools to help you in dealing effectively with
853 it has a number of useful tools to help you in dealing effectively with
839 more complex editing.
854 more complex editing.
840
855
841 The %edit command gives a reasonable approximation of multiline editing,
856 The %edit command gives a reasonable approximation of multiline editing,
842 by invoking your favorite editor on the spot. IPython will execute the
857 by invoking your favorite editor on the spot. IPython will execute the
843 code you type in there as if it were typed interactively. Type %edit?
858 code you type in there as if it were typed interactively. Type %edit?
844 for the full details on the edit command.
859 for the full details on the edit command.
845
860
846 If you have typed various commands during a session, which you'd like to
861 If you have typed various commands during a session, which you'd like to
847 reuse, IPython provides you with a number of tools. Start by using %hist
862 reuse, IPython provides you with a number of tools. Start by using %hist
848 to see your input history, so you can see the line numbers of all input.
863 to see your input history, so you can see the line numbers of all input.
849 Let us say that you'd like to reuse lines 10 through 20, plus lines 24
864 Let us say that you'd like to reuse lines 10 through 20, plus lines 24
850 and 28. All the commands below can operate on these with the syntax::
865 and 28. All the commands below can operate on these with the syntax::
851
866
852 %command 10-20 24 28
867 %command 10-20 24 28
853
868
854 where the command given can be:
869 where the command given can be:
855
870
856 * %macro <macroname>: this stores the lines into a variable which,
871 * %macro <macroname>: this stores the lines into a variable which,
857 when called at the prompt, re-executes the input. Macros can be
872 when called at the prompt, re-executes the input. Macros can be
858 edited later using '%edit macroname', and they can be stored
873 edited later using '%edit macroname', and they can be stored
859 persistently across sessions with '%store macroname' (the storage
874 persistently across sessions with '%store macroname' (the storage
860 system is per-profile). The combination of quick macros,
875 system is per-profile). The combination of quick macros,
861 persistent storage and editing, allows you to easily refine
876 persistent storage and editing, allows you to easily refine
862 quick-and-dirty interactive input into permanent utilities, always
877 quick-and-dirty interactive input into permanent utilities, always
863 available both in IPython and as files for general reuse.
878 available both in IPython and as files for general reuse.
864 * %edit: this will open a text editor with those lines pre-loaded
879 * %edit: this will open a text editor with those lines pre-loaded
865 for further modification. It will then execute the resulting
880 for further modification. It will then execute the resulting
866 file's contents as if you had typed it at the prompt.
881 file's contents as if you had typed it at the prompt.
867 * %save <filename>: this saves the lines directly to a named file on
882 * %save <filename>: this saves the lines directly to a named file on
868 disk.
883 disk.
869
884
870 While %macro saves input lines into memory for interactive re-execution,
885 While %macro saves input lines into memory for interactive re-execution,
871 sometimes you'd like to save your input directly to a file. The %save
886 sometimes you'd like to save your input directly to a file. The %save
872 magic does this: its input sytnax is the same as %macro, but it saves
887 magic does this: its input sytnax is the same as %macro, but it saves
873 your input directly to a Python file. Note that the %logstart command
888 your input directly to a Python file. Note that the %logstart command
874 also saves input, but it logs all input to disk (though you can
889 also saves input, but it logs all input to disk (though you can
875 temporarily suspend it and reactivate it with %logoff/%logon); %save
890 temporarily suspend it and reactivate it with %logoff/%logon); %save
876 allows you to select which lines of input you need to save.
891 allows you to select which lines of input you need to save.
877
892
878
893
879 Lightweight 'version control'
894 Lightweight 'version control'
880 -----------------------------
895 -----------------------------
881
896
882 When you call %edit with no arguments, IPython opens an empty editor
897 When you call %edit with no arguments, IPython opens an empty editor
883 with a temporary file, and it returns the contents of your editing
898 with a temporary file, and it returns the contents of your editing
884 session as a string variable. Thanks to IPython's output caching
899 session as a string variable. Thanks to IPython's output caching
885 mechanism, this is automatically stored::
900 mechanism, this is automatically stored::
886
901
887 In [1]: %edit
902 In [1]: %edit
888
903
889 IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py
904 IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py
890
905
891 Editing... done. Executing edited code...
906 Editing... done. Executing edited code...
892
907
893 hello - this is a temporary file
908 hello - this is a temporary file
894
909
895 Out[1]: "print 'hello - this is a temporary file'\n"
910 Out[1]: "print 'hello - this is a temporary file'\n"
896
911
897 Now, if you call '%edit -p', IPython tries to open an editor with the
912 Now, if you call '%edit -p', IPython tries to open an editor with the
898 same data as the last time you used %edit. So if you haven't used %edit
913 same data as the last time you used %edit. So if you haven't used %edit
899 in the meantime, this same contents will reopen; however, it will be
914 in the meantime, this same contents will reopen; however, it will be
900 done in a new file. This means that if you make changes and you later
915 done in a new file. This means that if you make changes and you later
901 want to find an old version, you can always retrieve it by using its
916 want to find an old version, you can always retrieve it by using its
902 output number, via '%edit _NN', where NN is the number of the output
917 output number, via '%edit _NN', where NN is the number of the output
903 prompt.
918 prompt.
904
919
905 Continuing with the example above, this should illustrate this idea::
920 Continuing with the example above, this should illustrate this idea::
906
921
907 In [2]: edit -p
922 In [2]: edit -p
908
923
909 IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py
924 IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py
910
925
911 Editing... done. Executing edited code...
926 Editing... done. Executing edited code...
912
927
913 hello - now I made some changes
928 hello - now I made some changes
914
929
915 Out[2]: "print 'hello - now I made some changes'\n"
930 Out[2]: "print 'hello - now I made some changes'\n"
916
931
917 In [3]: edit _1
932 In [3]: edit _1
918
933
919 IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py
934 IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py
920
935
921 Editing... done. Executing edited code...
936 Editing... done. Executing edited code...
922
937
923 hello - this is a temporary file
938 hello - this is a temporary file
924
939
925 IPython version control at work :)
940 IPython version control at work :)
926
941
927 Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n"
942 Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n"
928
943
929
944
930 This section was written after a contribution by Alexander Belchenko on
945 This section was written after a contribution by Alexander Belchenko on
931 the IPython user list.
946 the IPython user list.
932
947
933
948
934 Effective logging
949 Effective logging
935 -----------------
950 -----------------
936
951
937 A very useful suggestion sent in by Robert Kern follows:
952 A very useful suggestion sent in by Robert Kern follows:
938
953
939 I recently happened on a nifty way to keep tidy per-project log files. I
954 I recently happened on a nifty way to keep tidy per-project log files. I
940 made a profile for my project (which is called "parkfield").
955 made a profile for my project (which is called "parkfield").
941
956
942 include ipythonrc
957 include ipythonrc
943
958
944 # cancel earlier logfile invocation:
959 # cancel earlier logfile invocation:
945
960
946 logfile ''
961 logfile ''
947
962
948 execute import time
963 execute import time
949
964
950 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
965 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
951
966
952 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
967 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
953
968
954 I also added a shell alias for convenience:
969 I also added a shell alias for convenience:
955
970
956 alias parkfield="ipython -pylab -profile parkfield"
971 alias parkfield="ipython -pylab -profile parkfield"
957
972
958 Now I have a nice little directory with everything I ever type in,
973 Now I have a nice little directory with everything I ever type in,
959 organized by project and date.
974 organized by project and date.
960
975
961 Contribute your own: If you have your own favorite tip on using IPython
976 Contribute your own: If you have your own favorite tip on using IPython
962 efficiently for a certain task (especially things which can't be done in
977 efficiently for a certain task (especially things which can't be done in
963 the normal Python interpreter), don't hesitate to send it!
978 the normal Python interpreter), don't hesitate to send it!
964
979
965 .. _Command line options:
980 .. _Command line options:
966
981
967 Command-line use
982 Command-line use
968 ================
983 ================
969
984
970 You start IPython with the command::
985 You start IPython with the command::
971
986
972 $ ipython [options] files
987 $ ipython [options] files
973
988
974 If invoked with no options, it executes all the files listed in sequence
989 If invoked with no options, it executes all the files listed in sequence
975 and drops you into the interpreter while still acknowledging any options
990 and drops you into the interpreter while still acknowledging any options
976 you may have set in your ipythonrc file. This behavior is different from
991 you may have set in your ipythonrc file. This behavior is different from
977 standard Python, which when called as python -i will only execute one
992 standard Python, which when called as python -i will only execute one
978 file and ignore your configuration setup.
993 file and ignore your configuration setup.
979
994
980 Please note that some of the configuration options are not available at
995 Please note that some of the configuration options are not available at
981 the command line, simply because they are not practical here. Look into
996 the command line, simply because they are not practical here. Look into
982 your ipythonrc configuration file for details on those. This file
997 your ipythonrc configuration file for details on those. This file
983 typically installed in the $HOME/.ipython directory. For Windows users,
998 typically installed in the $HOME/.ipython directory. For Windows users,
984 $HOME resolves to C:\\Documents and Settings\\YourUserName in most
999 $HOME resolves to C:\\Documents and Settings\\YourUserName in most
985 instances. In the rest of this text, we will refer to this directory as
1000 instances. In the rest of this text, we will refer to this directory as
986 IPYTHONDIR.
1001 IPYTHONDIR.
987
1002
988 .. _Threading options:
1003 .. _Threading options:
989
1004
990
1005
991 Special Threading Options
1006 Special Threading Options
992 -------------------------
1007 -------------------------
993
1008
994 The following special options are ONLY valid at the beginning of the
1009 The following special options are ONLY valid at the beginning of the
995 command line, and not later. This is because they control the initial-
1010 command line, and not later. This is because they control the initial-
996 ization of ipython itself, before the normal option-handling mechanism
1011 ization of ipython itself, before the normal option-handling mechanism
997 is active.
1012 is active.
998
1013
999 -gthread, -qthread, -q4thread, -wthread, -pylab:
1014 -gthread, -qthread, -q4thread, -wthread, -pylab:
1000 Only one of these can be given, and it can only be given as
1015 Only one of these can be given, and it can only be given as
1001 the first option passed to IPython (it will have no effect in
1016 the first option passed to IPython (it will have no effect in
1002 any other position). They provide threading support for the
1017 any other position). They provide threading support for the
1003 GTK, Qt (versions 3 and 4) and WXPython toolkits, and for the
1018 GTK, Qt (versions 3 and 4) and WXPython toolkits, and for the
1004 matplotlib library.
1019 matplotlib library.
1005
1020
1006 With any of the first four options, IPython starts running a
1021 With any of the first four options, IPython starts running a
1007 separate thread for the graphical toolkit's operation, so that
1022 separate thread for the graphical toolkit's operation, so that
1008 you can open and control graphical elements from within an
1023 you can open and control graphical elements from within an
1009 IPython command line, without blocking. All four provide
1024 IPython command line, without blocking. All four provide
1010 essentially the same functionality, respectively for GTK, Qt3,
1025 essentially the same functionality, respectively for GTK, Qt3,
1011 Qt4 and WXWidgets (via their Python interfaces).
1026 Qt4 and WXWidgets (via their Python interfaces).
1012
1027
1013 Note that with -wthread, you can additionally use the
1028 Note that with -wthread, you can additionally use the
1014 -wxversion option to request a specific version of wx to be
1029 -wxversion option to request a specific version of wx to be
1015 used. This requires that you have the wxversion Python module
1030 used. This requires that you have the wxversion Python module
1016 installed, which is part of recent wxPython distributions.
1031 installed, which is part of recent wxPython distributions.
1017
1032
1018 If -pylab is given, IPython loads special support for the mat
1033 If -pylab is given, IPython loads special support for the mat
1019 plotlib library (http://matplotlib.sourceforge.net), allowing
1034 plotlib library (http://matplotlib.sourceforge.net), allowing
1020 interactive usage of any of its backends as defined in the
1035 interactive usage of any of its backends as defined in the
1021 user's ~/.matplotlib/matplotlibrc file. It automatically
1036 user's ~/.matplotlib/matplotlibrc file. It automatically
1022 activates GTK, Qt or WX threading for IPyhton if the choice of
1037 activates GTK, Qt or WX threading for IPyhton if the choice of
1023 matplotlib backend requires it. It also modifies the %run
1038 matplotlib backend requires it. It also modifies the %run
1024 command to correctly execute (without blocking) any
1039 command to correctly execute (without blocking) any
1025 matplotlib-based script which calls show() at the end.
1040 matplotlib-based script which calls show() at the end.
1026
1041
1027 -tk
1042 -tk
1028 The -g/q/q4/wthread options, and -pylab (if matplotlib is
1043 The -g/q/q4/wthread options, and -pylab (if matplotlib is
1029 configured to use GTK, Qt3, Qt4 or WX), will normally block Tk
1044 configured to use GTK, Qt3, Qt4 or WX), will normally block Tk
1030 graphical interfaces. This means that when either GTK, Qt or WX
1045 graphical interfaces. This means that when either GTK, Qt or WX
1031 threading is active, any attempt to open a Tk GUI will result in a
1046 threading is active, any attempt to open a Tk GUI will result in a
1032 dead window, and possibly cause the Python interpreter to crash.
1047 dead window, and possibly cause the Python interpreter to crash.
1033 An extra option, -tk, is available to address this issue. It can
1048 An extra option, -tk, is available to address this issue. It can
1034 only be given as a second option after any of the above (-gthread,
1049 only be given as a second option after any of the above (-gthread,
1035 -wthread or -pylab).
1050 -wthread or -pylab).
1036
1051
1037 If -tk is given, IPython will try to coordinate Tk threading
1052 If -tk is given, IPython will try to coordinate Tk threading
1038 with GTK, Qt or WX. This is however potentially unreliable, and
1053 with GTK, Qt or WX. This is however potentially unreliable, and
1039 you will have to test on your platform and Python configuration to
1054 you will have to test on your platform and Python configuration to
1040 determine whether it works for you. Debian users have reported
1055 determine whether it works for you. Debian users have reported
1041 success, apparently due to the fact that Debian builds all of Tcl,
1056 success, apparently due to the fact that Debian builds all of Tcl,
1042 Tk, Tkinter and Python with pthreads support. Under other Linux
1057 Tk, Tkinter and Python with pthreads support. Under other Linux
1043 environments (such as Fedora Core 2/3), this option has caused
1058 environments (such as Fedora Core 2/3), this option has caused
1044 random crashes and lockups of the Python interpreter. Under other
1059 random crashes and lockups of the Python interpreter. Under other
1045 operating systems (Mac OSX and Windows), you'll need to try it to
1060 operating systems (Mac OSX and Windows), you'll need to try it to
1046 find out, since currently no user reports are available.
1061 find out, since currently no user reports are available.
1047
1062
1048 There is unfortunately no way for IPython to determine at run time
1063 There is unfortunately no way for IPython to determine at run time
1049 whether -tk will work reliably or not, so you will need to do some
1064 whether -tk will work reliably or not, so you will need to do some
1050 experiments before relying on it for regular work.
1065 experiments before relying on it for regular work.
1051
1066
1052
1067
1053
1068
1054 Regular Options
1069 Regular Options
1055 ---------------
1070 ---------------
1056
1071
1057 After the above threading options have been given, regular options can
1072 After the above threading options have been given, regular options can
1058 follow in any order. All options can be abbreviated to their shortest
1073 follow in any order. All options can be abbreviated to their shortest
1059 non-ambiguous form and are case-sensitive. One or two dashes can be
1074 non-ambiguous form and are case-sensitive. One or two dashes can be
1060 used. Some options have an alternate short form, indicated after a ``|``.
1075 used. Some options have an alternate short form, indicated after a ``|``.
1061
1076
1062 Most options can also be set from your ipythonrc configuration file. See
1077 Most options can also be set from your ipythonrc configuration file. See
1063 the provided example for more details on what the options do. Options
1078 the provided example for more details on what the options do. Options
1064 given at the command line override the values set in the ipythonrc file.
1079 given at the command line override the values set in the ipythonrc file.
1065
1080
1066 All options with a [no] prepended can be specified in negated form
1081 All options with a [no] prepended can be specified in negated form
1067 (-nooption instead of -option) to turn the feature off.
1082 (-nooption instead of -option) to turn the feature off.
1068
1083
1069 -help print a help message and exit.
1084 -help print a help message and exit.
1070
1085
1071 -pylab
1086 -pylab
1072 this can only be given as the first option passed to IPython
1087 this can only be given as the first option passed to IPython
1073 (it will have no effect in any other position). It adds
1088 (it will have no effect in any other position). It adds
1074 special support for the matplotlib library
1089 special support for the matplotlib library
1075 (http://matplotlib.sourceforge.ne), allowing interactive usage
1090 (http://matplotlib.sourceforge.ne), allowing interactive usage
1076 of any of its backends as defined in the user's .matplotlibrc
1091 of any of its backends as defined in the user's .matplotlibrc
1077 file. It automatically activates GTK or WX threading for
1092 file. It automatically activates GTK or WX threading for
1078 IPyhton if the choice of matplotlib backend requires it. It
1093 IPyhton if the choice of matplotlib backend requires it. It
1079 also modifies the %run command to correctly execute (without
1094 also modifies the %run command to correctly execute (without
1080 blocking) any matplotlib-based script which calls show() at
1095 blocking) any matplotlib-based script which calls show() at
1081 the end. See `Matplotlib support`_ for more details.
1096 the end. See `Matplotlib support`_ for more details.
1082
1097
1083 -autocall <val>
1098 -autocall <val>
1084 Make IPython automatically call any callable object even if you
1099 Make IPython automatically call any callable object even if you
1085 didn't type explicit parentheses. For example, 'str 43' becomes
1100 didn't type explicit parentheses. For example, 'str 43' becomes
1086 'str(43)' automatically. The value can be '0' to disable the feature,
1101 'str(43)' automatically. The value can be '0' to disable the feature,
1087 '1' for smart autocall, where it is not applied if there are no more
1102 '1' for smart autocall, where it is not applied if there are no more
1088 arguments on the line, and '2' for full autocall, where all callable
1103 arguments on the line, and '2' for full autocall, where all callable
1089 objects are automatically called (even if no arguments are
1104 objects are automatically called (even if no arguments are
1090 present). The default is '1'.
1105 present). The default is '1'.
1091
1106
1092 -[no]autoindent
1107 -[no]autoindent
1093 Turn automatic indentation on/off.
1108 Turn automatic indentation on/off.
1094
1109
1095 -[no]automagic
1110 -[no]automagic
1096 make magic commands automatic (without needing their first character
1111 make magic commands automatic (without needing their first character
1097 to be %). Type %magic at the IPython prompt for more information.
1112 to be %). Type %magic at the IPython prompt for more information.
1098
1113
1099 -[no]autoedit_syntax
1114 -[no]autoedit_syntax
1100 When a syntax error occurs after editing a file, automatically
1115 When a syntax error occurs after editing a file, automatically
1101 open the file to the trouble causing line for convenient
1116 open the file to the trouble causing line for convenient
1102 fixing.
1117 fixing.
1103
1118
1104 -[no]banner Print the initial information banner (default on).
1119 -[no]banner Print the initial information banner (default on).
1105
1120
1106 -c <command>
1121 -c <command>
1107 execute the given command string. This is similar to the -c
1122 execute the given command string. This is similar to the -c
1108 option in the normal Python interpreter.
1123 option in the normal Python interpreter.
1109
1124
1110 -cache_size, cs <n>
1125 -cache_size, cs <n>
1111 size of the output cache (maximum number of entries to hold in
1126 size of the output cache (maximum number of entries to hold in
1112 memory). The default is 1000, you can change it permanently in your
1127 memory). The default is 1000, you can change it permanently in your
1113 config file. Setting it to 0 completely disables the caching system,
1128 config file. Setting it to 0 completely disables the caching system,
1114 and the minimum value accepted is 20 (if you provide a value less than
1129 and the minimum value accepted is 20 (if you provide a value less than
1115 20, it is reset to 0 and a warning is issued) This limit is defined
1130 20, it is reset to 0 and a warning is issued) This limit is defined
1116 because otherwise you'll spend more time re-flushing a too small cache
1131 because otherwise you'll spend more time re-flushing a too small cache
1117 than working.
1132 than working.
1118
1133
1119 -classic, cl
1134 -classic, cl
1120 Gives IPython a similar feel to the classic Python
1135 Gives IPython a similar feel to the classic Python
1121 prompt.
1136 prompt.
1122
1137
1123 -colors <scheme>
1138 -colors <scheme>
1124 Color scheme for prompts and exception reporting. Currently
1139 Color scheme for prompts and exception reporting. Currently
1125 implemented: NoColor, Linux and LightBG.
1140 implemented: NoColor, Linux and LightBG.
1126
1141
1127 -[no]color_info
1142 -[no]color_info
1128 IPython can display information about objects via a set of functions,
1143 IPython can display information about objects via a set of functions,
1129 and optionally can use colors for this, syntax highlighting source
1144 and optionally can use colors for this, syntax highlighting source
1130 code and various other elements. However, because this information is
1145 code and various other elements. However, because this information is
1131 passed through a pager (like 'less') and many pagers get confused with
1146 passed through a pager (like 'less') and many pagers get confused with
1132 color codes, this option is off by default. You can test it and turn
1147 color codes, this option is off by default. You can test it and turn
1133 it on permanently in your ipythonrc file if it works for you. As a
1148 it on permanently in your ipythonrc file if it works for you. As a
1134 reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
1149 reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
1135 that in RedHat 7.2 doesn't.
1150 that in RedHat 7.2 doesn't.
1136
1151
1137 Test it and turn it on permanently if it works with your
1152 Test it and turn it on permanently if it works with your
1138 system. The magic function %color_info allows you to toggle this
1153 system. The magic function %color_info allows you to toggle this
1139 interactively for testing.
1154 interactively for testing.
1140
1155
1141 -[no]debug
1156 -[no]debug
1142 Show information about the loading process. Very useful to pin down
1157 Show information about the loading process. Very useful to pin down
1143 problems with your configuration files or to get details about
1158 problems with your configuration files or to get details about
1144 session restores.
1159 session restores.
1145
1160
1146 -[no]deep_reload:
1161 -[no]deep_reload:
1147 IPython can use the deep_reload module which reloads changes in
1162 IPython can use the deep_reload module which reloads changes in
1148 modules recursively (it replaces the reload() function, so you don't
1163 modules recursively (it replaces the reload() function, so you don't
1149 need to change anything to use it). deep_reload() forces a full
1164 need to change anything to use it). deep_reload() forces a full
1150 reload of modules whose code may have changed, which the default
1165 reload of modules whose code may have changed, which the default
1151 reload() function does not.
1166 reload() function does not.
1152
1167
1153 When deep_reload is off, IPython will use the normal reload(),
1168 When deep_reload is off, IPython will use the normal reload(),
1154 but deep_reload will still be available as dreload(). This
1169 but deep_reload will still be available as dreload(). This
1155 feature is off by default [which means that you have both
1170 feature is off by default [which means that you have both
1156 normal reload() and dreload()].
1171 normal reload() and dreload()].
1157
1172
1158 -editor <name>
1173 -editor <name>
1159 Which editor to use with the %edit command. By default,
1174 Which editor to use with the %edit command. By default,
1160 IPython will honor your EDITOR environment variable (if not
1175 IPython will honor your EDITOR environment variable (if not
1161 set, vi is the Unix default and notepad the Windows one).
1176 set, vi is the Unix default and notepad the Windows one).
1162 Since this editor is invoked on the fly by IPython and is
1177 Since this editor is invoked on the fly by IPython and is
1163 meant for editing small code snippets, you may want to use a
1178 meant for editing small code snippets, you may want to use a
1164 small, lightweight editor here (in case your default EDITOR is
1179 small, lightweight editor here (in case your default EDITOR is
1165 something like Emacs).
1180 something like Emacs).
1166
1181
1167 -ipythondir <name>
1182 -ipythondir <name>
1168 name of your IPython configuration directory IPYTHONDIR. This
1183 name of your IPython configuration directory IPYTHONDIR. This
1169 can also be specified through the environment variable
1184 can also be specified through the environment variable
1170 IPYTHONDIR.
1185 IPYTHONDIR.
1171
1186
1172 -log, l
1187 -log, l
1173 generate a log file of all input. The file is named
1188 generate a log file of all input. The file is named
1174 ipython_log.py in your current directory (which prevents logs
1189 ipython_log.py in your current directory (which prevents logs
1175 from multiple IPython sessions from trampling each other). You
1190 from multiple IPython sessions from trampling each other). You
1176 can use this to later restore a session by loading your
1191 can use this to later restore a session by loading your
1177 logfile as a file to be executed with option -logplay (see
1192 logfile as a file to be executed with option -logplay (see
1178 below).
1193 below).
1179
1194
1180 -logfile, lf <name> specify the name of your logfile.
1195 -logfile, lf <name> specify the name of your logfile.
1181
1196
1182 -logplay, lp <name>
1197 -logplay, lp <name>
1183
1198
1184 you can replay a previous log. For restoring a session as close as
1199 you can replay a previous log. For restoring a session as close as
1185 possible to the state you left it in, use this option (don't just run
1200 possible to the state you left it in, use this option (don't just run
1186 the logfile). With -logplay, IPython will try to reconstruct the
1201 the logfile). With -logplay, IPython will try to reconstruct the
1187 previous working environment in full, not just execute the commands in
1202 previous working environment in full, not just execute the commands in
1188 the logfile.
1203 the logfile.
1189
1204
1190 When a session is restored, logging is automatically turned on
1205 When a session is restored, logging is automatically turned on
1191 again with the name of the logfile it was invoked with (it is
1206 again with the name of the logfile it was invoked with (it is
1192 read from the log header). So once you've turned logging on for
1207 read from the log header). So once you've turned logging on for
1193 a session, you can quit IPython and reload it as many times as
1208 a session, you can quit IPython and reload it as many times as
1194 you want and it will continue to log its history and restore
1209 you want and it will continue to log its history and restore
1195 from the beginning every time.
1210 from the beginning every time.
1196
1211
1197 Caveats: there are limitations in this option. The history
1212 Caveats: there are limitations in this option. The history
1198 variables _i*,_* and _dh don't get restored properly. In the
1213 variables _i*,_* and _dh don't get restored properly. In the
1199 future we will try to implement full session saving by writing
1214 future we will try to implement full session saving by writing
1200 and retrieving a 'snapshot' of the memory state of IPython. But
1215 and retrieving a 'snapshot' of the memory state of IPython. But
1201 our first attempts failed because of inherent limitations of
1216 our first attempts failed because of inherent limitations of
1202 Python's Pickle module, so this may have to wait.
1217 Python's Pickle module, so this may have to wait.
1203
1218
1204 -[no]messages
1219 -[no]messages
1205 Print messages which IPython collects about its startup
1220 Print messages which IPython collects about its startup
1206 process (default on).
1221 process (default on).
1207
1222
1208 -[no]pdb
1223 -[no]pdb
1209 Automatically call the pdb debugger after every uncaught
1224 Automatically call the pdb debugger after every uncaught
1210 exception. If you are used to debugging using pdb, this puts
1225 exception. If you are used to debugging using pdb, this puts
1211 you automatically inside of it after any call (either in
1226 you automatically inside of it after any call (either in
1212 IPython or in code called by it) which triggers an exception
1227 IPython or in code called by it) which triggers an exception
1213 which goes uncaught.
1228 which goes uncaught.
1214
1229
1215 -[no]pprint
1230 -[no]pprint
1216 ipython can optionally use the pprint (pretty printer) module
1231 ipython can optionally use the pprint (pretty printer) module
1217 for displaying results. pprint tends to give a nicer display
1232 for displaying results. pprint tends to give a nicer display
1218 of nested data structures. If you like it, you can turn it on
1233 of nested data structures. If you like it, you can turn it on
1219 permanently in your config file (default off).
1234 permanently in your config file (default off).
1220
1235
1221 -profile, p <name>
1236 -profile, p <name>
1222
1237
1223 assume that your config file is ipythonrc-<name> or
1238 assume that your config file is ipythonrc-<name> or
1224 ipy_profile_<name>.py (looks in current dir first, then in
1239 ipy_profile_<name>.py (looks in current dir first, then in
1225 IPYTHONDIR). This is a quick way to keep and load multiple
1240 IPYTHONDIR). This is a quick way to keep and load multiple
1226 config files for different tasks, especially if you use the
1241 config files for different tasks, especially if you use the
1227 include option of config files. You can keep a basic
1242 include option of config files. You can keep a basic
1228 IPYTHONDIR/ipythonrc file and then have other 'profiles' which
1243 IPYTHONDIR/ipythonrc file and then have other 'profiles' which
1229 include this one and load extra things for particular
1244 include this one and load extra things for particular
1230 tasks. For example:
1245 tasks. For example:
1231
1246
1232 1. $HOME/.ipython/ipythonrc : load basic things you always want.
1247 1. $HOME/.ipython/ipythonrc : load basic things you always want.
1233 2. $HOME/.ipython/ipythonrc-math : load (1) and basic math-related modules.
1248 2. $HOME/.ipython/ipythonrc-math : load (1) and basic math-related modules.
1234 3. $HOME/.ipython/ipythonrc-numeric : load (1) and Numeric and plotting modules.
1249 3. $HOME/.ipython/ipythonrc-numeric : load (1) and Numeric and plotting modules.
1235
1250
1236 Since it is possible to create an endless loop by having
1251 Since it is possible to create an endless loop by having
1237 circular file inclusions, IPython will stop if it reaches 15
1252 circular file inclusions, IPython will stop if it reaches 15
1238 recursive inclusions.
1253 recursive inclusions.
1239
1254
1240 -prompt_in1, pi1 <string>
1255 -prompt_in1, pi1 <string>
1241 Specify the string used for input prompts. Note that if you
1256 Specify the string used for input prompts. Note that if you
1242 are using numbered prompts, the number is represented with a
1257 are using numbered prompts, the number is represented with a
1243 '\#' in the string. Don't forget to quote strings with spaces
1258 '\#' in the string. Don't forget to quote strings with spaces
1244 embedded in them. Default: 'In [\#]:'. Sec. Prompts_
1259 embedded in them. Default: 'In [\#]:'. Sec. Prompts_
1245 discusses in detail all the available escapes to customize
1260 discusses in detail all the available escapes to customize
1246 your prompts.
1261 your prompts.
1247
1262
1248 -prompt_in2, pi2 <string>
1263 -prompt_in2, pi2 <string>
1249 Similar to the previous option, but used for the continuation
1264 Similar to the previous option, but used for the continuation
1250 prompts. The special sequence '\D' is similar to '\#', but
1265 prompts. The special sequence '\D' is similar to '\#', but
1251 with all digits replaced dots (so you can have your
1266 with all digits replaced dots (so you can have your
1252 continuation prompt aligned with your input prompt). Default:
1267 continuation prompt aligned with your input prompt). Default:
1253 ' .\D.:' (note three spaces at the start for alignment with
1268 ' .\D.:' (note three spaces at the start for alignment with
1254 'In [\#]').
1269 'In [\#]').
1255
1270
1256 -prompt_out,po <string>
1271 -prompt_out,po <string>
1257 String used for output prompts, also uses numbers like
1272 String used for output prompts, also uses numbers like
1258 prompt_in1. Default: 'Out[\#]:'
1273 prompt_in1. Default: 'Out[\#]:'
1259
1274
1260 -quick start in bare bones mode (no config file loaded).
1275 -quick start in bare bones mode (no config file loaded).
1261
1276
1262 -rcfile <name>
1277 -rcfile <name>
1263 name of your IPython resource configuration file. Normally
1278 name of your IPython resource configuration file. Normally
1264 IPython loads ipythonrc (from current directory) or
1279 IPython loads ipythonrc (from current directory) or
1265 IPYTHONDIR/ipythonrc.
1280 IPYTHONDIR/ipythonrc.
1266
1281
1267 If the loading of your config file fails, IPython starts with
1282 If the loading of your config file fails, IPython starts with
1268 a bare bones configuration (no modules loaded at all).
1283 a bare bones configuration (no modules loaded at all).
1269
1284
1270 -[no]readline
1285 -[no]readline
1271 use the readline library, which is needed to support name
1286 use the readline library, which is needed to support name
1272 completion and command history, among other things. It is
1287 completion and command history, among other things. It is
1273 enabled by default, but may cause problems for users of
1288 enabled by default, but may cause problems for users of
1274 X/Emacs in Python comint or shell buffers.
1289 X/Emacs in Python comint or shell buffers.
1275
1290
1276 Note that X/Emacs 'eterm' buffers (opened with M-x term) support
1291 Note that X/Emacs 'eterm' buffers (opened with M-x term) support
1277 IPython's readline and syntax coloring fine, only 'emacs' (M-x
1292 IPython's readline and syntax coloring fine, only 'emacs' (M-x
1278 shell and C-c !) buffers do not.
1293 shell and C-c !) buffers do not.
1279
1294
1280 -screen_length, sl <n>
1295 -screen_length, sl <n>
1281 number of lines of your screen. This is used to control
1296 number of lines of your screen. This is used to control
1282 printing of very long strings. Strings longer than this number
1297 printing of very long strings. Strings longer than this number
1283 of lines will be sent through a pager instead of directly
1298 of lines will be sent through a pager instead of directly
1284 printed.
1299 printed.
1285
1300
1286 The default value for this is 0, which means IPython will
1301 The default value for this is 0, which means IPython will
1287 auto-detect your screen size every time it needs to print certain
1302 auto-detect your screen size every time it needs to print certain
1288 potentially long strings (this doesn't change the behavior of the
1303 potentially long strings (this doesn't change the behavior of the
1289 'print' keyword, it's only triggered internally). If for some
1304 'print' keyword, it's only triggered internally). If for some
1290 reason this isn't working well (it needs curses support), specify
1305 reason this isn't working well (it needs curses support), specify
1291 it yourself. Otherwise don't change the default.
1306 it yourself. Otherwise don't change the default.
1292
1307
1293 -separate_in, si <string>
1308 -separate_in, si <string>
1294
1309
1295 separator before input prompts.
1310 separator before input prompts.
1296 Default: '\n'
1311 Default: '\n'
1297
1312
1298 -separate_out, so <string>
1313 -separate_out, so <string>
1299 separator before output prompts.
1314 separator before output prompts.
1300 Default: nothing.
1315 Default: nothing.
1301
1316
1302 -separate_out2, so2
1317 -separate_out2, so2
1303 separator after output prompts.
1318 separator after output prompts.
1304 Default: nothing.
1319 Default: nothing.
1305 For these three options, use the value 0 to specify no separator.
1320 For these three options, use the value 0 to specify no separator.
1306
1321
1307 -nosep
1322 -nosep
1308 shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2
1323 shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2
1309 0'. Simply removes all input/output separators.
1324 0'. Simply removes all input/output separators.
1310
1325
1311 -upgrade
1326 -upgrade
1312 allows you to upgrade your IPYTHONDIR configuration when you
1327 allows you to upgrade your IPYTHONDIR configuration when you
1313 install a new version of IPython. Since new versions may
1328 install a new version of IPython. Since new versions may
1314 include new command line options or example files, this copies
1329 include new command line options or example files, this copies
1315 updated ipythonrc-type files. However, it backs up (with a
1330 updated ipythonrc-type files. However, it backs up (with a
1316 .old extension) all files which it overwrites so that you can
1331 .old extension) all files which it overwrites so that you can
1317 merge back any customizations you might have in your personal
1332 merge back any customizations you might have in your personal
1318 files. Note that you should probably use %upgrade instead,
1333 files. Note that you should probably use %upgrade instead,
1319 it's a safer alternative.
1334 it's a safer alternative.
1320
1335
1321
1336
1322 -Version print version information and exit.
1337 -Version print version information and exit.
1323
1338
1324 -wxversion <string>
1339 -wxversion <string>
1325 Select a specific version of wxPython (used in conjunction
1340 Select a specific version of wxPython (used in conjunction
1326 with -wthread). Requires the wxversion module, part of recent
1341 with -wthread). Requires the wxversion module, part of recent
1327 wxPython distributions
1342 wxPython distributions
1328
1343
1329 -xmode <modename>
1344 -xmode <modename>
1330
1345
1331 Mode for exception reporting.
1346 Mode for exception reporting.
1332
1347
1333 Valid modes: Plain, Context and Verbose.
1348 Valid modes: Plain, Context and Verbose.
1334
1349
1335 * Plain: similar to python's normal traceback printing.
1350 * Plain: similar to python's normal traceback printing.
1336 * Context: prints 5 lines of context source code around each
1351 * Context: prints 5 lines of context source code around each
1337 line in the traceback.
1352 line in the traceback.
1338 * Verbose: similar to Context, but additionally prints the
1353 * Verbose: similar to Context, but additionally prints the
1339 variables currently visible where the exception happened
1354 variables currently visible where the exception happened
1340 (shortening their strings if too long). This can potentially be
1355 (shortening their strings if too long). This can potentially be
1341 very slow, if you happen to have a huge data structure whose
1356 very slow, if you happen to have a huge data structure whose
1342 string representation is complex to compute. Your computer may
1357 string representation is complex to compute. Your computer may
1343 appear to freeze for a while with cpu usage at 100%. If this
1358 appear to freeze for a while with cpu usage at 100%. If this
1344 occurs, you can cancel the traceback with Ctrl-C (maybe hitting it
1359 occurs, you can cancel the traceback with Ctrl-C (maybe hitting it
1345 more than once).
1360 more than once).
1346
1361
1347 Interactive use
1362 Interactive use
1348 ===============
1363 ===============
1349
1364
1350 Warning: IPython relies on the existence of a global variable called
1365 Warning: IPython relies on the existence of a global variable called
1351 _ip which controls the shell itself. If you redefine _ip to anything,
1366 _ip which controls the shell itself. If you redefine _ip to anything,
1352 bizarre behavior will quickly occur.
1367 bizarre behavior will quickly occur.
1353
1368
1354 Other than the above warning, IPython is meant to work as a drop-in
1369 Other than the above warning, IPython is meant to work as a drop-in
1355 replacement for the standard interactive interpreter. As such, any code
1370 replacement for the standard interactive interpreter. As such, any code
1356 which is valid python should execute normally under IPython (cases where
1371 which is valid python should execute normally under IPython (cases where
1357 this is not true should be reported as bugs). It does, however, offer
1372 this is not true should be reported as bugs). It does, however, offer
1358 many features which are not available at a standard python prompt. What
1373 many features which are not available at a standard python prompt. What
1359 follows is a list of these.
1374 follows is a list of these.
1360
1375
1361
1376
1362 Caution for Windows users
1377 Caution for Windows users
1363 -------------------------
1378 -------------------------
1364
1379
1365 Windows, unfortunately, uses the '\' character as a path
1380 Windows, unfortunately, uses the '\' character as a path
1366 separator. This is a terrible choice, because '\' also represents the
1381 separator. This is a terrible choice, because '\' also represents the
1367 escape character in most modern programming languages, including
1382 escape character in most modern programming languages, including
1368 Python. For this reason, using '/' character is recommended if you
1383 Python. For this reason, using '/' character is recommended if you
1369 have problems with ``\``. However, in Windows commands '/' flags
1384 have problems with ``\``. However, in Windows commands '/' flags
1370 options, so you can not use it for the root directory. This means that
1385 options, so you can not use it for the root directory. This means that
1371 paths beginning at the root must be typed in a contrived manner like:
1386 paths beginning at the root must be typed in a contrived manner like:
1372 ``%copy \opt/foo/bar.txt \tmp``
1387 ``%copy \opt/foo/bar.txt \tmp``
1373
1388
1374 .. _magic:
1389 .. _magic:
1375
1390
1376 Magic command system
1391 Magic command system
1377 --------------------
1392 --------------------
1378
1393
1379 IPython will treat any line whose first character is a % as a special
1394 IPython will treat any line whose first character is a % as a special
1380 call to a 'magic' function. These allow you to control the behavior of
1395 call to a 'magic' function. These allow you to control the behavior of
1381 IPython itself, plus a lot of system-type features. They are all
1396 IPython itself, plus a lot of system-type features. They are all
1382 prefixed with a % character, but parameters are given without
1397 prefixed with a % character, but parameters are given without
1383 parentheses or quotes.
1398 parentheses or quotes.
1384
1399
1385 Example: typing '%cd mydir' (without the quotes) changes you working
1400 Example: typing '%cd mydir' (without the quotes) changes you working
1386 directory to 'mydir', if it exists.
1401 directory to 'mydir', if it exists.
1387
1402
1388 If you have 'automagic' enabled (in your ipythonrc file, via the command
1403 If you have 'automagic' enabled (in your ipythonrc file, via the command
1389 line option -automagic or with the %automagic function), you don't need
1404 line option -automagic or with the %automagic function), you don't need
1390 to type in the % explicitly. IPython will scan its internal list of
1405 to type in the % explicitly. IPython will scan its internal list of
1391 magic functions and call one if it exists. With automagic on you can
1406 magic functions and call one if it exists. With automagic on you can
1392 then just type 'cd mydir' to go to directory 'mydir'. The automagic
1407 then just type 'cd mydir' to go to directory 'mydir'. The automagic
1393 system has the lowest possible precedence in name searches, so defining
1408 system has the lowest possible precedence in name searches, so defining
1394 an identifier with the same name as an existing magic function will
1409 an identifier with the same name as an existing magic function will
1395 shadow it for automagic use. You can still access the shadowed magic
1410 shadow it for automagic use. You can still access the shadowed magic
1396 function by explicitly using the % character at the beginning of the line.
1411 function by explicitly using the % character at the beginning of the line.
1397
1412
1398 An example (with automagic on) should clarify all this::
1413 An example (with automagic on) should clarify all this::
1399
1414
1400 In [1]: cd ipython # %cd is called by automagic
1415 In [1]: cd ipython # %cd is called by automagic
1401
1416
1402 /home/fperez/ipython
1417 /home/fperez/ipython
1403
1418
1404 In [2]: cd=1 # now cd is just a variable
1419 In [2]: cd=1 # now cd is just a variable
1405
1420
1406 In [3]: cd .. # and doesn't work as a function anymore
1421 In [3]: cd .. # and doesn't work as a function anymore
1407
1422
1408 ------------------------------
1423 ------------------------------
1409
1424
1410 File "<console>", line 1
1425 File "<console>", line 1
1411
1426
1412 cd ..
1427 cd ..
1413
1428
1414 ^
1429 ^
1415
1430
1416 SyntaxError: invalid syntax
1431 SyntaxError: invalid syntax
1417
1432
1418 In [4]: %cd .. # but %cd always works
1433 In [4]: %cd .. # but %cd always works
1419
1434
1420 /home/fperez
1435 /home/fperez
1421
1436
1422 In [5]: del cd # if you remove the cd variable
1437 In [5]: del cd # if you remove the cd variable
1423
1438
1424 In [6]: cd ipython # automagic can work again
1439 In [6]: cd ipython # automagic can work again
1425
1440
1426 /home/fperez/ipython
1441 /home/fperez/ipython
1427
1442
1428 You can define your own magic functions to extend the system. The
1443 You can define your own magic functions to extend the system. The
1429 following example defines a new magic command, %impall::
1444 following example defines a new magic command, %impall::
1430
1445
1431 import IPython.ipapi
1446 import IPython.ipapi
1432
1447
1433 ip = IPython.ipapi.get()
1448 ip = IPython.ipapi.get()
1434
1449
1435 def doimp(self, arg):
1450 def doimp(self, arg):
1436
1451
1437 ip = self.api
1452 ip = self.api
1438
1453
1439 ip.ex("import %s; reload(%s); from %s import *" % (
1454 ip.ex("import %s; reload(%s); from %s import *" % (
1440
1455
1441 arg,arg,arg)
1456 arg,arg,arg)
1442
1457
1443 )
1458 )
1444
1459
1445 ip.expose_magic('impall', doimp)
1460 ip.expose_magic('impall', doimp)
1446
1461
1447 You can also define your own aliased names for magic functions. In your
1462 You can also define your own aliased names for magic functions. In your
1448 ipythonrc file, placing a line like:
1463 ipythonrc file, placing a line like:
1449
1464
1450 execute __IP.magic_cl = __IP.magic_clear
1465 execute __IP.magic_cl = __IP.magic_clear
1451
1466
1452 will define %cl as a new name for %clear.
1467 will define %cl as a new name for %clear.
1453
1468
1454 Type %magic for more information, including a list of all available
1469 Type %magic for more information, including a list of all available
1455 magic functions at any time and their docstrings. You can also type
1470 magic functions at any time and their docstrings. You can also type
1456 %magic_function_name? (see sec. 6.4 <#sec:dyn-object-info> for
1471 %magic_function_name? (see sec. 6.4 <#sec:dyn-object-info> for
1457 information on the '?' system) to get information about any particular
1472 information on the '?' system) to get information about any particular
1458 magic function you are interested in.
1473 magic function you are interested in.
1459
1474
1460
1475
1461 Magic commands
1476 Magic commands
1462 --------------
1477 --------------
1463
1478
1464 The rest of this section is automatically generated for each release
1479 The rest of this section is automatically generated for each release
1465 from the docstrings in the IPython code. Therefore the formatting is
1480 from the docstrings in the IPython code. Therefore the formatting is
1466 somewhat minimal, but this method has the advantage of having
1481 somewhat minimal, but this method has the advantage of having
1467 information always in sync with the code.
1482 information always in sync with the code.
1468
1483
1469 A list of all the magic commands available in IPython's default
1484 A list of all the magic commands available in IPython's default
1470 installation follows. This is similar to what you'll see by simply
1485 installation follows. This is similar to what you'll see by simply
1471 typing %magic at the prompt, but that will also give you information
1486 typing %magic at the prompt, but that will also give you information
1472 about magic commands you may have added as part of your personal
1487 about magic commands you may have added as part of your personal
1473 customizations.
1488 customizations.
1474
1489
1475 .. magic_start
1490 .. magic_start
1476
1491
1477 **%Exit**::
1492 **%Exit**::
1478
1493
1479 Exit IPython without confirmation.
1494 Exit IPython without confirmation.
1480
1495
1481 **%Pprint**::
1496 **%Pprint**::
1482
1497
1483 Toggle pretty printing on/off.
1498 Toggle pretty printing on/off.
1484
1499
1485 **%alias**::
1500 **%alias**::
1486
1501
1487 Define an alias for a system command.
1502 Define an alias for a system command.
1488
1503
1489 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
1504 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
1490
1505
1491 Then, typing 'alias_name params' will execute the system command 'cmd
1506 Then, typing 'alias_name params' will execute the system command 'cmd
1492 params' (from your underlying operating system).
1507 params' (from your underlying operating system).
1493
1508
1494 Aliases have lower precedence than magic functions and Python normal
1509 Aliases have lower precedence than magic functions and Python normal
1495 variables, so if 'foo' is both a Python variable and an alias, the
1510 variables, so if 'foo' is both a Python variable and an alias, the
1496 alias can not be executed until 'del foo' removes the Python variable.
1511 alias can not be executed until 'del foo' removes the Python variable.
1497
1512
1498 You can use the %l specifier in an alias definition to represent the
1513 You can use the %l specifier in an alias definition to represent the
1499 whole line when the alias is called. For example:
1514 whole line when the alias is called. For example:
1500
1515
1501 In [2]: alias all echo "Input in brackets: <%l>"\
1516 In [2]: alias all echo "Input in brackets: <%l>"\
1502 In [3]: all hello world\
1517 In [3]: all hello world\
1503 Input in brackets: <hello world>
1518 Input in brackets: <hello world>
1504
1519
1505 You can also define aliases with parameters using %s specifiers (one
1520 You can also define aliases with parameters using %s specifiers (one
1506 per parameter):
1521 per parameter):
1507
1522
1508 In [1]: alias parts echo first %s second %s\
1523 In [1]: alias parts echo first %s second %s\
1509 In [2]: %parts A B\
1524 In [2]: %parts A B\
1510 first A second B\
1525 first A second B\
1511 In [3]: %parts A\
1526 In [3]: %parts A\
1512 Incorrect number of arguments: 2 expected.\
1527 Incorrect number of arguments: 2 expected.\
1513 parts is an alias to: 'echo first %s second %s'
1528 parts is an alias to: 'echo first %s second %s'
1514
1529
1515 Note that %l and %s are mutually exclusive. You can only use one or
1530 Note that %l and %s are mutually exclusive. You can only use one or
1516 the other in your aliases.
1531 the other in your aliases.
1517
1532
1518 Aliases expand Python variables just like system calls using ! or !!
1533 Aliases expand Python variables just like system calls using ! or !!
1519 do: all expressions prefixed with '$' get expanded. For details of
1534 do: all expressions prefixed with '$' get expanded. For details of
1520 the semantic rules, see PEP-215:
1535 the semantic rules, see PEP-215:
1521 http://www.python.org/peps/pep-0215.html. This is the library used by
1536 http://www.python.org/peps/pep-0215.html. This is the library used by
1522 IPython for variable expansion. If you want to access a true shell
1537 IPython for variable expansion. If you want to access a true shell
1523 variable, an extra $ is necessary to prevent its expansion by IPython:
1538 variable, an extra $ is necessary to prevent its expansion by IPython:
1524
1539
1525 In [6]: alias show echo\
1540 In [6]: alias show echo\
1526 In [7]: PATH='A Python string'\
1541 In [7]: PATH='A Python string'\
1527 In [8]: show $PATH\
1542 In [8]: show $PATH\
1528 A Python string\
1543 A Python string\
1529 In [9]: show $$PATH\
1544 In [9]: show $$PATH\
1530 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1545 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1531
1546
1532 You can use the alias facility to acess all of $PATH. See the %rehash
1547 You can use the alias facility to acess all of $PATH. See the %rehash
1533 and %rehashx functions, which automatically create aliases for the
1548 and %rehashx functions, which automatically create aliases for the
1534 contents of your $PATH.
1549 contents of your $PATH.
1535
1550
1536 If called with no parameters, %alias prints the current alias table.
1551 If called with no parameters, %alias prints the current alias table.
1537
1552
1538 **%autocall**::
1553 **%autocall**::
1539
1554
1540 Make functions callable without having to type parentheses.
1555 Make functions callable without having to type parentheses.
1541
1556
1542 Usage:
1557 Usage:
1543
1558
1544 %autocall [mode]
1559 %autocall [mode]
1545
1560
1546 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
1561 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
1547 value is toggled on and off (remembering the previous state).
1562 value is toggled on and off (remembering the previous state).
1548
1563
1549 In more detail, these values mean:
1564 In more detail, these values mean:
1550
1565
1551 0 -> fully disabled
1566 0 -> fully disabled
1552
1567
1553 1 -> active, but do not apply if there are no arguments on the line.
1568 1 -> active, but do not apply if there are no arguments on the line.
1554
1569
1555 In this mode, you get:
1570 In this mode, you get:
1556
1571
1557 In [1]: callable
1572 In [1]: callable
1558 Out[1]: <built-in function callable>
1573 Out[1]: <built-in function callable>
1559
1574
1560 In [2]: callable 'hello'
1575 In [2]: callable 'hello'
1561 ------> callable('hello')
1576 ------> callable('hello')
1562 Out[2]: False
1577 Out[2]: False
1563
1578
1564 2 -> Active always. Even if no arguments are present, the callable
1579 2 -> Active always. Even if no arguments are present, the callable
1565 object is called:
1580 object is called:
1566
1581
1567 In [4]: callable
1582 In [4]: callable
1568 ------> callable()
1583 ------> callable()
1569
1584
1570 Note that even with autocall off, you can still use '/' at the start of
1585 Note that even with autocall off, you can still use '/' at the start of
1571 a line to treat the first argument on the command line as a function
1586 a line to treat the first argument on the command line as a function
1572 and add parentheses to it:
1587 and add parentheses to it:
1573
1588
1574 In [8]: /str 43
1589 In [8]: /str 43
1575 ------> str(43)
1590 ------> str(43)
1576 Out[8]: '43'
1591 Out[8]: '43'
1577
1592
1578 **%autoindent**::
1593 **%autoindent**::
1579
1594
1580 Toggle autoindent on/off (if available).
1595 Toggle autoindent on/off (if available).
1581
1596
1582 **%automagic**::
1597 **%automagic**::
1583
1598
1584 Make magic functions callable without having to type the initial %.
1599 Make magic functions callable without having to type the initial %.
1585
1600
1586 Without argumentsl toggles on/off (when off, you must call it as
1601 Without argumentsl toggles on/off (when off, you must call it as
1587 %automagic, of course). With arguments it sets the value, and you can
1602 %automagic, of course). With arguments it sets the value, and you can
1588 use any of (case insensitive):
1603 use any of (case insensitive):
1589
1604
1590 - on,1,True: to activate
1605 - on,1,True: to activate
1591
1606
1592 - off,0,False: to deactivate.
1607 - off,0,False: to deactivate.
1593
1608
1594 Note that magic functions have lowest priority, so if there's a
1609 Note that magic functions have lowest priority, so if there's a
1595 variable whose name collides with that of a magic fn, automagic won't
1610 variable whose name collides with that of a magic fn, automagic won't
1596 work for that function (you get the variable instead). However, if you
1611 work for that function (you get the variable instead). However, if you
1597 delete the variable (del var), the previously shadowed magic function
1612 delete the variable (del var), the previously shadowed magic function
1598 becomes visible to automagic again.
1613 becomes visible to automagic again.
1599
1614
1600 **%bg**::
1615 **%bg**::
1601
1616
1602 Run a job in the background, in a separate thread.
1617 Run a job in the background, in a separate thread.
1603
1618
1604 For example,
1619 For example,
1605
1620
1606 %bg myfunc(x,y,z=1)
1621 %bg myfunc(x,y,z=1)
1607
1622
1608 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
1623 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
1609 execution starts, a message will be printed indicating the job
1624 execution starts, a message will be printed indicating the job
1610 number. If your job number is 5, you can use
1625 number. If your job number is 5, you can use
1611
1626
1612 myvar = jobs.result(5) or myvar = jobs[5].result
1627 myvar = jobs.result(5) or myvar = jobs[5].result
1613
1628
1614 to assign this result to variable 'myvar'.
1629 to assign this result to variable 'myvar'.
1615
1630
1616 IPython has a job manager, accessible via the 'jobs' object. You can
1631 IPython has a job manager, accessible via the 'jobs' object. You can
1617 type jobs? to get more information about it, and use jobs.<TAB> to see
1632 type jobs? to get more information about it, and use jobs.<TAB> to see
1618 its attributes. All attributes not starting with an underscore are
1633 its attributes. All attributes not starting with an underscore are
1619 meant for public use.
1634 meant for public use.
1620
1635
1621 In particular, look at the jobs.new() method, which is used to create
1636 In particular, look at the jobs.new() method, which is used to create
1622 new jobs. This magic %bg function is just a convenience wrapper
1637 new jobs. This magic %bg function is just a convenience wrapper
1623 around jobs.new(), for expression-based jobs. If you want to create a
1638 around jobs.new(), for expression-based jobs. If you want to create a
1624 new job with an explicit function object and arguments, you must call
1639 new job with an explicit function object and arguments, you must call
1625 jobs.new() directly.
1640 jobs.new() directly.
1626
1641
1627 The jobs.new docstring also describes in detail several important
1642 The jobs.new docstring also describes in detail several important
1628 caveats associated with a thread-based model for background job
1643 caveats associated with a thread-based model for background job
1629 execution. Type jobs.new? for details.
1644 execution. Type jobs.new? for details.
1630
1645
1631 You can check the status of all jobs with jobs.status().
1646 You can check the status of all jobs with jobs.status().
1632
1647
1633 The jobs variable is set by IPython into the Python builtin namespace.
1648 The jobs variable is set by IPython into the Python builtin namespace.
1634 If you ever declare a variable named 'jobs', you will shadow this
1649 If you ever declare a variable named 'jobs', you will shadow this
1635 name. You can either delete your global jobs variable to regain
1650 name. You can either delete your global jobs variable to regain
1636 access to the job manager, or make a new name and assign it manually
1651 access to the job manager, or make a new name and assign it manually
1637 to the manager (stored in IPython's namespace). For example, to
1652 to the manager (stored in IPython's namespace). For example, to
1638 assign the job manager to the Jobs name, use:
1653 assign the job manager to the Jobs name, use:
1639
1654
1640 Jobs = __builtins__.jobs
1655 Jobs = __builtins__.jobs
1641
1656
1642 **%bookmark**::
1657 **%bookmark**::
1643
1658
1644 Manage IPython's bookmark system.
1659 Manage IPython's bookmark system.
1645
1660
1646 %bookmark <name> - set bookmark to current dir
1661 %bookmark <name> - set bookmark to current dir
1647 %bookmark <name> <dir> - set bookmark to <dir>
1662 %bookmark <name> <dir> - set bookmark to <dir>
1648 %bookmark -l - list all bookmarks
1663 %bookmark -l - list all bookmarks
1649 %bookmark -d <name> - remove bookmark
1664 %bookmark -d <name> - remove bookmark
1650 %bookmark -r - remove all bookmarks
1665 %bookmark -r - remove all bookmarks
1651
1666
1652 You can later on access a bookmarked folder with:
1667 You can later on access a bookmarked folder with:
1653 %cd -b <name>
1668 %cd -b <name>
1654 or simply '%cd <name>' if there is no directory called <name> AND
1669 or simply '%cd <name>' if there is no directory called <name> AND
1655 there is such a bookmark defined.
1670 there is such a bookmark defined.
1656
1671
1657 Your bookmarks persist through IPython sessions, but they are
1672 Your bookmarks persist through IPython sessions, but they are
1658 associated with each profile.
1673 associated with each profile.
1659
1674
1660 **%cd**::
1675 **%cd**::
1661
1676
1662 Change the current working directory.
1677 Change the current working directory.
1663
1678
1664 This command automatically maintains an internal list of directories
1679 This command automatically maintains an internal list of directories
1665 you visit during your IPython session, in the variable _dh. The
1680 you visit during your IPython session, in the variable _dh. The
1666 command %dhist shows this history nicely formatted. You can also
1681 command %dhist shows this history nicely formatted. You can also
1667 do 'cd -<tab>' to see directory history conveniently.
1682 do 'cd -<tab>' to see directory history conveniently.
1668
1683
1669 Usage:
1684 Usage:
1670
1685
1671 cd 'dir': changes to directory 'dir'.
1686 cd 'dir': changes to directory 'dir'.
1672
1687
1673 cd -: changes to the last visited directory.
1688 cd -: changes to the last visited directory.
1674
1689
1675 cd -<n>: changes to the n-th directory in the directory history.
1690 cd -<n>: changes to the n-th directory in the directory history.
1676
1691
1677 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
1692 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
1678 (note: cd <bookmark_name> is enough if there is no
1693 (note: cd <bookmark_name> is enough if there is no
1679 directory <bookmark_name>, but a bookmark with the name exists.)
1694 directory <bookmark_name>, but a bookmark with the name exists.)
1680 'cd -b <tab>' allows you to tab-complete bookmark names.
1695 'cd -b <tab>' allows you to tab-complete bookmark names.
1681
1696
1682 Options:
1697 Options:
1683
1698
1684 -q: quiet. Do not print the working directory after the cd command is
1699 -q: quiet. Do not print the working directory after the cd command is
1685 executed. By default IPython's cd command does print this directory,
1700 executed. By default IPython's cd command does print this directory,
1686 since the default prompts do not display path information.
1701 since the default prompts do not display path information.
1687
1702
1688 Note that !cd doesn't work for this purpose because the shell where
1703 Note that !cd doesn't work for this purpose because the shell where
1689 !command runs is immediately discarded after executing 'command'.
1704 !command runs is immediately discarded after executing 'command'.
1690
1705
1691 **%clear**::
1706 **%clear**::
1692
1707
1693 Clear various data (e.g. stored history data)
1708 Clear various data (e.g. stored history data)
1694
1709
1695 %clear out - clear output history
1710 %clear out - clear output history
1696 %clear in - clear input history
1711 %clear in - clear input history
1697 %clear shadow_compress - Compresses shadow history (to speed up ipython)
1712 %clear shadow_compress - Compresses shadow history (to speed up ipython)
1698 %clear shadow_nuke - permanently erase all entries in shadow history
1713 %clear shadow_nuke - permanently erase all entries in shadow history
1699 %clear dhist - clear dir history
1714 %clear dhist - clear dir history
1700
1715
1701 **%color_info**::
1716 **%color_info**::
1702
1717
1703 Toggle color_info.
1718 Toggle color_info.
1704
1719
1705 The color_info configuration parameter controls whether colors are
1720 The color_info configuration parameter controls whether colors are
1706 used for displaying object details (by things like %psource, %pfile or
1721 used for displaying object details (by things like %psource, %pfile or
1707 the '?' system). This function toggles this value with each call.
1722 the '?' system). This function toggles this value with each call.
1708
1723
1709 Note that unless you have a fairly recent pager (less works better
1724 Note that unless you have a fairly recent pager (less works better
1710 than more) in your system, using colored object information displays
1725 than more) in your system, using colored object information displays
1711 will not work properly. Test it and see.
1726 will not work properly. Test it and see.
1712
1727
1713 **%colors**::
1728 **%colors**::
1714
1729
1715 Switch color scheme for prompts, info system and exception handlers.
1730 Switch color scheme for prompts, info system and exception handlers.
1716
1731
1717 Currently implemented schemes: NoColor, Linux, LightBG.
1732 Currently implemented schemes: NoColor, Linux, LightBG.
1718
1733
1719 Color scheme names are not case-sensitive.
1734 Color scheme names are not case-sensitive.
1720
1735
1721 **%cpaste**::
1736 **%cpaste**::
1722
1737
1723 Allows you to paste & execute a pre-formatted code block from clipboard
1738 Allows you to paste & execute a pre-formatted code block from clipboard
1724
1739
1725 You must terminate the block with '--' (two minus-signs) alone on the
1740 You must terminate the block with '--' (two minus-signs) alone on the
1726 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
1741 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
1727 is the new sentinel for this operation)
1742 is the new sentinel for this operation)
1728
1743
1729 The block is dedented prior to execution to enable execution of method
1744 The block is dedented prior to execution to enable execution of method
1730 definitions. '>' and '+' characters at the beginning of a line are
1745 definitions. '>' and '+' characters at the beginning of a line are
1731 ignored, to allow pasting directly from e-mails or diff files. The
1746 ignored, to allow pasting directly from e-mails or diff files. The
1732 executed block is also assigned to variable named 'pasted_block' for
1747 executed block is also assigned to variable named 'pasted_block' for
1733 later editing with '%edit pasted_block'.
1748 later editing with '%edit pasted_block'.
1734
1749
1735 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
1750 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
1736 This assigns the pasted block to variable 'foo' as string, without
1751 This assigns the pasted block to variable 'foo' as string, without
1737 dedenting or executing it.
1752 dedenting or executing it.
1738
1753
1739 Do not be alarmed by garbled output on Windows (it's a readline bug).
1754 Do not be alarmed by garbled output on Windows (it's a readline bug).
1740 Just press enter and type -- (and press enter again) and the block
1755 Just press enter and type -- (and press enter again) and the block
1741 will be what was just pasted.
1756 will be what was just pasted.
1742
1757
1743 IPython statements (magics, shell escapes) are not supported (yet).
1758 IPython statements (magics, shell escapes) are not supported (yet).
1744
1759
1745 **%debug**::
1760 **%debug**::
1746
1761
1747 Activate the interactive debugger in post-mortem mode.
1762 Activate the interactive debugger in post-mortem mode.
1748
1763
1749 If an exception has just occurred, this lets you inspect its stack
1764 If an exception has just occurred, this lets you inspect its stack
1750 frames interactively. Note that this will always work only on the last
1765 frames interactively. Note that this will always work only on the last
1751 traceback that occurred, so you must call this quickly after an
1766 traceback that occurred, so you must call this quickly after an
1752 exception that you wish to inspect has fired, because if another one
1767 exception that you wish to inspect has fired, because if another one
1753 occurs, it clobbers the previous one.
1768 occurs, it clobbers the previous one.
1754
1769
1755 If you want IPython to automatically do this on every exception, see
1770 If you want IPython to automatically do this on every exception, see
1756 the %pdb magic for more details.
1771 the %pdb magic for more details.
1757
1772
1758 **%dhist**::
1773 **%dhist**::
1759
1774
1760 Print your history of visited directories.
1775 Print your history of visited directories.
1761
1776
1762 %dhist -> print full history\
1777 %dhist -> print full history\
1763 %dhist n -> print last n entries only\
1778 %dhist n -> print last n entries only\
1764 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\
1779 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\
1765
1780
1766 This history is automatically maintained by the %cd command, and
1781 This history is automatically maintained by the %cd command, and
1767 always available as the global list variable _dh. You can use %cd -<n>
1782 always available as the global list variable _dh. You can use %cd -<n>
1768 to go to directory number <n>.
1783 to go to directory number <n>.
1769
1784
1770 Note that most of time, you should view directory history by entering
1785 Note that most of time, you should view directory history by entering
1771 cd -<TAB>.
1786 cd -<TAB>.
1772
1787
1773 **%dirs**::
1788 **%dirs**::
1774
1789
1775 Return the current directory stack.
1790 Return the current directory stack.
1776
1791
1777 **%doctest_mode**::
1792 **%doctest_mode**::
1778
1793
1779 Toggle doctest mode on and off.
1794 Toggle doctest mode on and off.
1780
1795
1781 This mode allows you to toggle the prompt behavior between normal
1796 This mode allows you to toggle the prompt behavior between normal
1782 IPython prompts and ones that are as similar to the default IPython
1797 IPython prompts and ones that are as similar to the default IPython
1783 interpreter as possible.
1798 interpreter as possible.
1784
1799
1785 It also supports the pasting of code snippets that have leading '>>>'
1800 It also supports the pasting of code snippets that have leading '>>>'
1786 and '...' prompts in them. This means that you can paste doctests from
1801 and '...' prompts in them. This means that you can paste doctests from
1787 files or docstrings (even if they have leading whitespace), and the
1802 files or docstrings (even if they have leading whitespace), and the
1788 code will execute correctly. You can then use '%history -tn' to see
1803 code will execute correctly. You can then use '%history -tn' to see
1789 the translated history without line numbers; this will give you the
1804 the translated history without line numbers; this will give you the
1790 input after removal of all the leading prompts and whitespace, which
1805 input after removal of all the leading prompts and whitespace, which
1791 can be pasted back into an editor.
1806 can be pasted back into an editor.
1792
1807
1793 With these features, you can switch into this mode easily whenever you
1808 With these features, you can switch into this mode easily whenever you
1794 need to do testing and changes to doctests, without having to leave
1809 need to do testing and changes to doctests, without having to leave
1795 your existing IPython session.
1810 your existing IPython session.
1796
1811
1797 **%ed**::
1812 **%ed**::
1798
1813
1799 Alias to %edit.
1814 Alias to %edit.
1800
1815
1801 **%edit**::
1816 **%edit**::
1802
1817
1803 Bring up an editor and execute the resulting code.
1818 Bring up an editor and execute the resulting code.
1804
1819
1805 Usage:
1820 Usage:
1806 %edit [options] [args]
1821 %edit [options] [args]
1807
1822
1808 %edit runs IPython's editor hook. The default version of this hook is
1823 %edit runs IPython's editor hook. The default version of this hook is
1809 set to call the __IPYTHON__.rc.editor command. This is read from your
1824 set to call the __IPYTHON__.rc.editor command. This is read from your
1810 environment variable $EDITOR. If this isn't found, it will default to
1825 environment variable $EDITOR. If this isn't found, it will default to
1811 vi under Linux/Unix and to notepad under Windows. See the end of this
1826 vi under Linux/Unix and to notepad under Windows. See the end of this
1812 docstring for how to change the editor hook.
1827 docstring for how to change the editor hook.
1813
1828
1814 You can also set the value of this editor via the command line option
1829 You can also set the value of this editor via the command line option
1815 '-editor' or in your ipythonrc file. This is useful if you wish to use
1830 '-editor' or in your ipythonrc file. This is useful if you wish to use
1816 specifically for IPython an editor different from your typical default
1831 specifically for IPython an editor different from your typical default
1817 (and for Windows users who typically don't set environment variables).
1832 (and for Windows users who typically don't set environment variables).
1818
1833
1819 This command allows you to conveniently edit multi-line code right in
1834 This command allows you to conveniently edit multi-line code right in
1820 your IPython session.
1835 your IPython session.
1821
1836
1822 If called without arguments, %edit opens up an empty editor with a
1837 If called without arguments, %edit opens up an empty editor with a
1823 temporary file and will execute the contents of this file when you
1838 temporary file and will execute the contents of this file when you
1824 close it (don't forget to save it!).
1839 close it (don't forget to save it!).
1825
1840
1826
1841
1827 Options:
1842 Options:
1828
1843
1829 -n <number>: open the editor at a specified line number. By default,
1844 -n <number>: open the editor at a specified line number. By default,
1830 the IPython editor hook uses the unix syntax 'editor +N filename', but
1845 the IPython editor hook uses the unix syntax 'editor +N filename', but
1831 you can configure this by providing your own modified hook if your
1846 you can configure this by providing your own modified hook if your
1832 favorite editor supports line-number specifications with a different
1847 favorite editor supports line-number specifications with a different
1833 syntax.
1848 syntax.
1834
1849
1835 -p: this will call the editor with the same data as the previous time
1850 -p: this will call the editor with the same data as the previous time
1836 it was used, regardless of how long ago (in your current session) it
1851 it was used, regardless of how long ago (in your current session) it
1837 was.
1852 was.
1838
1853
1839 -r: use 'raw' input. This option only applies to input taken from the
1854 -r: use 'raw' input. This option only applies to input taken from the
1840 user's history. By default, the 'processed' history is used, so that
1855 user's history. By default, the 'processed' history is used, so that
1841 magics are loaded in their transformed version to valid Python. If
1856 magics are loaded in their transformed version to valid Python. If
1842 this option is given, the raw input as typed as the command line is
1857 this option is given, the raw input as typed as the command line is
1843 used instead. When you exit the editor, it will be executed by
1858 used instead. When you exit the editor, it will be executed by
1844 IPython's own processor.
1859 IPython's own processor.
1845
1860
1846 -x: do not execute the edited code immediately upon exit. This is
1861 -x: do not execute the edited code immediately upon exit. This is
1847 mainly useful if you are editing programs which need to be called with
1862 mainly useful if you are editing programs which need to be called with
1848 command line arguments, which you can then do using %run.
1863 command line arguments, which you can then do using %run.
1849
1864
1850
1865
1851 Arguments:
1866 Arguments:
1852
1867
1853 If arguments are given, the following possibilites exist:
1868 If arguments are given, the following possibilites exist:
1854
1869
1855 - The arguments are numbers or pairs of colon-separated numbers (like
1870 - The arguments are numbers or pairs of colon-separated numbers (like
1856 1 4:8 9). These are interpreted as lines of previous input to be
1871 1 4:8 9). These are interpreted as lines of previous input to be
1857 loaded into the editor. The syntax is the same of the %macro command.
1872 loaded into the editor. The syntax is the same of the %macro command.
1858
1873
1859 - If the argument doesn't start with a number, it is evaluated as a
1874 - If the argument doesn't start with a number, it is evaluated as a
1860 variable and its contents loaded into the editor. You can thus edit
1875 variable and its contents loaded into the editor. You can thus edit
1861 any string which contains python code (including the result of
1876 any string which contains python code (including the result of
1862 previous edits).
1877 previous edits).
1863
1878
1864 - If the argument is the name of an object (other than a string),
1879 - If the argument is the name of an object (other than a string),
1865 IPython will try to locate the file where it was defined and open the
1880 IPython will try to locate the file where it was defined and open the
1866 editor at the point where it is defined. You can use `%edit function`
1881 editor at the point where it is defined. You can use `%edit function`
1867 to load an editor exactly at the point where 'function' is defined,
1882 to load an editor exactly at the point where 'function' is defined,
1868 edit it and have the file be executed automatically.
1883 edit it and have the file be executed automatically.
1869
1884
1870 If the object is a macro (see %macro for details), this opens up your
1885 If the object is a macro (see %macro for details), this opens up your
1871 specified editor with a temporary file containing the macro's data.
1886 specified editor with a temporary file containing the macro's data.
1872 Upon exit, the macro is reloaded with the contents of the file.
1887 Upon exit, the macro is reloaded with the contents of the file.
1873
1888
1874 Note: opening at an exact line is only supported under Unix, and some
1889 Note: opening at an exact line is only supported under Unix, and some
1875 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1890 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1876 '+NUMBER' parameter necessary for this feature. Good editors like
1891 '+NUMBER' parameter necessary for this feature. Good editors like
1877 (X)Emacs, vi, jed, pico and joe all do.
1892 (X)Emacs, vi, jed, pico and joe all do.
1878
1893
1879 - If the argument is not found as a variable, IPython will look for a
1894 - If the argument is not found as a variable, IPython will look for a
1880 file with that name (adding .py if necessary) and load it into the
1895 file with that name (adding .py if necessary) and load it into the
1881 editor. It will execute its contents with execfile() when you exit,
1896 editor. It will execute its contents with execfile() when you exit,
1882 loading any code in the file into your interactive namespace.
1897 loading any code in the file into your interactive namespace.
1883
1898
1884 After executing your code, %edit will return as output the code you
1899 After executing your code, %edit will return as output the code you
1885 typed in the editor (except when it was an existing file). This way
1900 typed in the editor (except when it was an existing file). This way
1886 you can reload the code in further invocations of %edit as a variable,
1901 you can reload the code in further invocations of %edit as a variable,
1887 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1902 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1888 the output.
1903 the output.
1889
1904
1890 Note that %edit is also available through the alias %ed.
1905 Note that %edit is also available through the alias %ed.
1891
1906
1892 This is an example of creating a simple function inside the editor and
1907 This is an example of creating a simple function inside the editor and
1893 then modifying it. First, start up the editor:
1908 then modifying it. First, start up the editor:
1894
1909
1895 In [1]: ed\
1910 In [1]: ed\
1896 Editing... done. Executing edited code...\
1911 Editing... done. Executing edited code...\
1897 Out[1]: 'def foo():\n print "foo() was defined in an editing session"\n'
1912 Out[1]: 'def foo():\n print "foo() was defined in an editing session"\n'
1898
1913
1899 We can then call the function foo():
1914 We can then call the function foo():
1900
1915
1901 In [2]: foo()\
1916 In [2]: foo()\
1902 foo() was defined in an editing session
1917 foo() was defined in an editing session
1903
1918
1904 Now we edit foo. IPython automatically loads the editor with the
1919 Now we edit foo. IPython automatically loads the editor with the
1905 (temporary) file where foo() was previously defined:
1920 (temporary) file where foo() was previously defined:
1906
1921
1907 In [3]: ed foo\
1922 In [3]: ed foo\
1908 Editing... done. Executing edited code...
1923 Editing... done. Executing edited code...
1909
1924
1910 And if we call foo() again we get the modified version:
1925 And if we call foo() again we get the modified version:
1911
1926
1912 In [4]: foo()\
1927 In [4]: foo()\
1913 foo() has now been changed!
1928 foo() has now been changed!
1914
1929
1915 Here is an example of how to edit a code snippet successive
1930 Here is an example of how to edit a code snippet successive
1916 times. First we call the editor:
1931 times. First we call the editor:
1917
1932
1918 In [8]: ed\
1933 In [8]: ed\
1919 Editing... done. Executing edited code...\
1934 Editing... done. Executing edited code...\
1920 hello\
1935 hello\
1921 Out[8]: "print 'hello'\n"
1936 Out[8]: "print 'hello'\n"
1922
1937
1923 Now we call it again with the previous output (stored in _):
1938 Now we call it again with the previous output (stored in _):
1924
1939
1925 In [9]: ed _\
1940 In [9]: ed _\
1926 Editing... done. Executing edited code...\
1941 Editing... done. Executing edited code...\
1927 hello world\
1942 hello world\
1928 Out[9]: "print 'hello world'\n"
1943 Out[9]: "print 'hello world'\n"
1929
1944
1930 Now we call it with the output #8 (stored in _8, also as Out[8]):
1945 Now we call it with the output #8 (stored in _8, also as Out[8]):
1931
1946
1932 In [10]: ed _8\
1947 In [10]: ed _8\
1933 Editing... done. Executing edited code...\
1948 Editing... done. Executing edited code...\
1934 hello again\
1949 hello again\
1935 Out[10]: "print 'hello again'\n"
1950 Out[10]: "print 'hello again'\n"
1936
1951
1937
1952
1938 Changing the default editor hook:
1953 Changing the default editor hook:
1939
1954
1940 If you wish to write your own editor hook, you can put it in a
1955 If you wish to write your own editor hook, you can put it in a
1941 configuration file which you load at startup time. The default hook
1956 configuration file which you load at startup time. The default hook
1942 is defined in the IPython.hooks module, and you can use that as a
1957 is defined in the IPython.hooks module, and you can use that as a
1943 starting example for further modifications. That file also has
1958 starting example for further modifications. That file also has
1944 general instructions on how to set a new hook for use once you've
1959 general instructions on how to set a new hook for use once you've
1945 defined it.
1960 defined it.
1946
1961
1947 **%env**::
1962 **%env**::
1948
1963
1949 List environment variables.
1964 List environment variables.
1950
1965
1951 **%exit**::
1966 **%exit**::
1952
1967
1953 Exit IPython, confirming if configured to do so.
1968 Exit IPython, confirming if configured to do so.
1954
1969
1955 You can configure whether IPython asks for confirmation upon exit by
1970 You can configure whether IPython asks for confirmation upon exit by
1956 setting the confirm_exit flag in the ipythonrc file.
1971 setting the confirm_exit flag in the ipythonrc file.
1957
1972
1958 **%hist**::
1973 **%hist**::
1959
1974
1960 Alternate name for %history.
1975 Alternate name for %history.
1961
1976
1962 **%history**::
1977 **%history**::
1963
1978
1964 Print input history (_i<n> variables), with most recent last.
1979 Print input history (_i<n> variables), with most recent last.
1965
1980
1966 %history -> print at most 40 inputs (some may be multi-line)\
1981 %history -> print at most 40 inputs (some may be multi-line)\
1967 %history n -> print at most n inputs\
1982 %history n -> print at most n inputs\
1968 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\
1983 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\
1969
1984
1970 Each input's number <n> is shown, and is accessible as the
1985 Each input's number <n> is shown, and is accessible as the
1971 automatically generated variable _i<n>. Multi-line statements are
1986 automatically generated variable _i<n>. Multi-line statements are
1972 printed starting at a new line for easy copy/paste.
1987 printed starting at a new line for easy copy/paste.
1973
1988
1974
1989
1975 Options:
1990 Options:
1976
1991
1977 -n: do NOT print line numbers. This is useful if you want to get a
1992 -n: do NOT print line numbers. This is useful if you want to get a
1978 printout of many lines which can be directly pasted into a text
1993 printout of many lines which can be directly pasted into a text
1979 editor.
1994 editor.
1980
1995
1981 This feature is only available if numbered prompts are in use.
1996 This feature is only available if numbered prompts are in use.
1982
1997
1983 -t: (default) print the 'translated' history, as IPython understands it.
1998 -t: (default) print the 'translated' history, as IPython understands it.
1984 IPython filters your input and converts it all into valid Python source
1999 IPython filters your input and converts it all into valid Python source
1985 before executing it (things like magics or aliases are turned into
2000 before executing it (things like magics or aliases are turned into
1986 function calls, for example). With this option, you'll see the native
2001 function calls, for example). With this option, you'll see the native
1987 history instead of the user-entered version: '%cd /' will be seen as
2002 history instead of the user-entered version: '%cd /' will be seen as
1988 '_ip.magic("%cd /")' instead of '%cd /'.
2003 '_ip.magic("%cd /")' instead of '%cd /'.
1989
2004
1990 -r: print the 'raw' history, i.e. the actual commands you typed.
2005 -r: print the 'raw' history, i.e. the actual commands you typed.
1991
2006
1992 -g: treat the arg as a pattern to grep for in (full) history.
2007 -g: treat the arg as a pattern to grep for in (full) history.
1993 This includes the "shadow history" (almost all commands ever written).
2008 This includes the "shadow history" (almost all commands ever written).
1994 Use '%hist -g' to show full shadow history (may be very long).
2009 Use '%hist -g' to show full shadow history (may be very long).
1995 In shadow history, every index nuwber starts with 0.
2010 In shadow history, every index nuwber starts with 0.
1996
2011
1997 -f FILENAME: instead of printing the output to the screen, redirect it to
2012 -f FILENAME: instead of printing the output to the screen, redirect it to
1998 the given file. The file is always overwritten, though IPython asks for
2013 the given file. The file is always overwritten, though IPython asks for
1999 confirmation first if it already exists.
2014 confirmation first if it already exists.
2000
2015
2001 **%logoff**::
2016 **%logoff**::
2002
2017
2003 Temporarily stop logging.
2018 Temporarily stop logging.
2004
2019
2005 You must have previously started logging.
2020 You must have previously started logging.
2006
2021
2007 **%logon**::
2022 **%logon**::
2008
2023
2009 Restart logging.
2024 Restart logging.
2010
2025
2011 This function is for restarting logging which you've temporarily
2026 This function is for restarting logging which you've temporarily
2012 stopped with %logoff. For starting logging for the first time, you
2027 stopped with %logoff. For starting logging for the first time, you
2013 must use the %logstart function, which allows you to specify an
2028 must use the %logstart function, which allows you to specify an
2014 optional log filename.
2029 optional log filename.
2015
2030
2016 **%logstart**::
2031 **%logstart**::
2017
2032
2018 Start logging anywhere in a session.
2033 Start logging anywhere in a session.
2019
2034
2020 %logstart [-o|-r|-t] [log_name [log_mode]]
2035 %logstart [-o|-r|-t] [log_name [log_mode]]
2021
2036
2022 If no name is given, it defaults to a file named 'ipython_log.py' in your
2037 If no name is given, it defaults to a file named 'ipython_log.py' in your
2023 current directory, in 'rotate' mode (see below).
2038 current directory, in 'rotate' mode (see below).
2024
2039
2025 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
2040 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
2026 history up to that point and then continues logging.
2041 history up to that point and then continues logging.
2027
2042
2028 %logstart takes a second optional parameter: logging mode. This can be one
2043 %logstart takes a second optional parameter: logging mode. This can be one
2029 of (note that the modes are given unquoted):\
2044 of (note that the modes are given unquoted):\
2030 append: well, that says it.\
2045 append: well, that says it.\
2031 backup: rename (if exists) to name~ and start name.\
2046 backup: rename (if exists) to name~ and start name.\
2032 global: single logfile in your home dir, appended to.\
2047 global: single logfile in your home dir, appended to.\
2033 over : overwrite existing log.\
2048 over : overwrite existing log.\
2034 rotate: create rotating logs name.1~, name.2~, etc.
2049 rotate: create rotating logs name.1~, name.2~, etc.
2035
2050
2036 Options:
2051 Options:
2037
2052
2038 -o: log also IPython's output. In this mode, all commands which
2053 -o: log also IPython's output. In this mode, all commands which
2039 generate an Out[NN] prompt are recorded to the logfile, right after
2054 generate an Out[NN] prompt are recorded to the logfile, right after
2040 their corresponding input line. The output lines are always
2055 their corresponding input line. The output lines are always
2041 prepended with a '#[Out]# ' marker, so that the log remains valid
2056 prepended with a '#[Out]# ' marker, so that the log remains valid
2042 Python code.
2057 Python code.
2043
2058
2044 Since this marker is always the same, filtering only the output from
2059 Since this marker is always the same, filtering only the output from
2045 a log is very easy, using for example a simple awk call:
2060 a log is very easy, using for example a simple awk call:
2046
2061
2047 awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py
2062 awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py
2048
2063
2049 -r: log 'raw' input. Normally, IPython's logs contain the processed
2064 -r: log 'raw' input. Normally, IPython's logs contain the processed
2050 input, so that user lines are logged in their final form, converted
2065 input, so that user lines are logged in their final form, converted
2051 into valid Python. For example, %Exit is logged as
2066 into valid Python. For example, %Exit is logged as
2052 '_ip.magic("Exit"). If the -r flag is given, all input is logged
2067 '_ip.magic("Exit"). If the -r flag is given, all input is logged
2053 exactly as typed, with no transformations applied.
2068 exactly as typed, with no transformations applied.
2054
2069
2055 -t: put timestamps before each input line logged (these are put in
2070 -t: put timestamps before each input line logged (these are put in
2056 comments).
2071 comments).
2057
2072
2058 **%logstate**::
2073 **%logstate**::
2059
2074
2060 Print the status of the logging system.
2075 Print the status of the logging system.
2061
2076
2062 **%logstop**::
2077 **%logstop**::
2063
2078
2064 Fully stop logging and close log file.
2079 Fully stop logging and close log file.
2065
2080
2066 In order to start logging again, a new %logstart call needs to be made,
2081 In order to start logging again, a new %logstart call needs to be made,
2067 possibly (though not necessarily) with a new filename, mode and other
2082 possibly (though not necessarily) with a new filename, mode and other
2068 options.
2083 options.
2069
2084
2070 **%lsmagic**::
2085 **%lsmagic**::
2071
2086
2072 List currently available magic functions.
2087 List currently available magic functions.
2073
2088
2074 **%macro**::
2089 **%macro**::
2075
2090
2076 Define a set of input lines as a macro for future re-execution.
2091 Define a set of input lines as a macro for future re-execution.
2077
2092
2078 Usage:\
2093 Usage:\
2079 %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...
2094 %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...
2080
2095
2081 Options:
2096 Options:
2082
2097
2083 -r: use 'raw' input. By default, the 'processed' history is used,
2098 -r: use 'raw' input. By default, the 'processed' history is used,
2084 so that magics are loaded in their transformed version to valid
2099 so that magics are loaded in their transformed version to valid
2085 Python. If this option is given, the raw input as typed as the
2100 Python. If this option is given, the raw input as typed as the
2086 command line is used instead.
2101 command line is used instead.
2087
2102
2088 This will define a global variable called `name` which is a string
2103 This will define a global variable called `name` which is a string
2089 made of joining the slices and lines you specify (n1,n2,... numbers
2104 made of joining the slices and lines you specify (n1,n2,... numbers
2090 above) from your input history into a single string. This variable
2105 above) from your input history into a single string. This variable
2091 acts like an automatic function which re-executes those lines as if
2106 acts like an automatic function which re-executes those lines as if
2092 you had typed them. You just type 'name' at the prompt and the code
2107 you had typed them. You just type 'name' at the prompt and the code
2093 executes.
2108 executes.
2094
2109
2095 The notation for indicating number ranges is: n1-n2 means 'use line
2110 The notation for indicating number ranges is: n1-n2 means 'use line
2096 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
2111 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
2097 using the lines numbered 5,6 and 7.
2112 using the lines numbered 5,6 and 7.
2098
2113
2099 Note: as a 'hidden' feature, you can also use traditional python slice
2114 Note: as a 'hidden' feature, you can also use traditional python slice
2100 notation, where N:M means numbers N through M-1.
2115 notation, where N:M means numbers N through M-1.
2101
2116
2102 For example, if your history contains (%hist prints it):
2117 For example, if your history contains (%hist prints it):
2103
2118
2104 44: x=1\
2119 44: x=1\
2105 45: y=3\
2120 45: y=3\
2106 46: z=x+y\
2121 46: z=x+y\
2107 47: print x\
2122 47: print x\
2108 48: a=5\
2123 48: a=5\
2109 49: print 'x',x,'y',y\
2124 49: print 'x',x,'y',y\
2110
2125
2111 you can create a macro with lines 44 through 47 (included) and line 49
2126 you can create a macro with lines 44 through 47 (included) and line 49
2112 called my_macro with:
2127 called my_macro with:
2113
2128
2114 In [51]: %macro my_macro 44-47 49
2129 In [51]: %macro my_macro 44-47 49
2115
2130
2116 Now, typing `my_macro` (without quotes) will re-execute all this code
2131 Now, typing `my_macro` (without quotes) will re-execute all this code
2117 in one pass.
2132 in one pass.
2118
2133
2119 You don't need to give the line-numbers in order, and any given line
2134 You don't need to give the line-numbers in order, and any given line
2120 number can appear multiple times. You can assemble macros with any
2135 number can appear multiple times. You can assemble macros with any
2121 lines from your input history in any order.
2136 lines from your input history in any order.
2122
2137
2123 The macro is a simple object which holds its value in an attribute,
2138 The macro is a simple object which holds its value in an attribute,
2124 but IPython's display system checks for macros and executes them as
2139 but IPython's display system checks for macros and executes them as
2125 code instead of printing them when you type their name.
2140 code instead of printing them when you type their name.
2126
2141
2127 You can view a macro's contents by explicitly printing it with:
2142 You can view a macro's contents by explicitly printing it with:
2128
2143
2129 'print macro_name'.
2144 'print macro_name'.
2130
2145
2131 For one-off cases which DON'T contain magic function calls in them you
2146 For one-off cases which DON'T contain magic function calls in them you
2132 can obtain similar results by explicitly executing slices from your
2147 can obtain similar results by explicitly executing slices from your
2133 input history with:
2148 input history with:
2134
2149
2135 In [60]: exec In[44:48]+In[49]
2150 In [60]: exec In[44:48]+In[49]
2136
2151
2137 **%magic**::
2152 **%magic**::
2138
2153
2139 Print information about the magic function system.
2154 Print information about the magic function system.
2140
2155
2141 **%mglob**::
2156 **%mglob**::
2142
2157
2143 This program allows specifying filenames with "mglob" mechanism.
2158 This program allows specifying filenames with "mglob" mechanism.
2144 Supported syntax in globs (wilcard matching patterns)::
2159 Supported syntax in globs (wilcard matching patterns)::
2145
2160
2146 *.cpp ?ellowo*
2161 *.cpp ?ellowo*
2147 - obvious. Differs from normal glob in that dirs are not included.
2162 - obvious. Differs from normal glob in that dirs are not included.
2148 Unix users might want to write this as: "*.cpp" "?ellowo*"
2163 Unix users might want to write this as: "*.cpp" "?ellowo*"
2149 rec:/usr/share=*.txt,*.doc
2164 rec:/usr/share=*.txt,*.doc
2150 - get all *.txt and *.doc under /usr/share,
2165 - get all *.txt and *.doc under /usr/share,
2151 recursively
2166 recursively
2152 rec:/usr/share
2167 rec:/usr/share
2153 - All files under /usr/share, recursively
2168 - All files under /usr/share, recursively
2154 rec:*.py
2169 rec:*.py
2155 - All .py files under current working dir, recursively
2170 - All .py files under current working dir, recursively
2156 foo
2171 foo
2157 - File or dir foo
2172 - File or dir foo
2158 !*.bak readme*
2173 !*.bak readme*
2159 - readme*, exclude files ending with .bak
2174 - readme*, exclude files ending with .bak
2160 !.svn/ !.hg/ !*_Data/ rec:.
2175 !.svn/ !.hg/ !*_Data/ rec:.
2161 - Skip .svn, .hg, foo_Data dirs (and their subdirs) in recurse.
2176 - Skip .svn, .hg, foo_Data dirs (and their subdirs) in recurse.
2162 Trailing / is the key, \ does not work!
2177 Trailing / is the key, \ does not work!
2163 dir:foo
2178 dir:foo
2164 - the directory foo if it exists (not files in foo)
2179 - the directory foo if it exists (not files in foo)
2165 dir:*
2180 dir:*
2166 - all directories in current folder
2181 - all directories in current folder
2167 foo.py bar.* !h* rec:*.py
2182 foo.py bar.* !h* rec:*.py
2168 - Obvious. !h* exclusion only applies for rec:*.py.
2183 - Obvious. !h* exclusion only applies for rec:*.py.
2169 foo.py is *not* included twice.
2184 foo.py is *not* included twice.
2170 @filelist.txt
2185 @filelist.txt
2171 - All files listed in 'filelist.txt' file, on separate lines.
2186 - All files listed in 'filelist.txt' file, on separate lines.
2172
2187
2173 **%page**::
2188 **%page**::
2174
2189
2175 Pretty print the object and display it through a pager.
2190 Pretty print the object and display it through a pager.
2176
2191
2177 %page [options] OBJECT
2192 %page [options] OBJECT
2178
2193
2179 If no object is given, use _ (last output).
2194 If no object is given, use _ (last output).
2180
2195
2181 Options:
2196 Options:
2182
2197
2183 -r: page str(object), don't pretty-print it.
2198 -r: page str(object), don't pretty-print it.
2184
2199
2185 **%pdb**::
2200 **%pdb**::
2186
2201
2187 Control the automatic calling of the pdb interactive debugger.
2202 Control the automatic calling of the pdb interactive debugger.
2188
2203
2189 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
2204 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
2190 argument it works as a toggle.
2205 argument it works as a toggle.
2191
2206
2192 When an exception is triggered, IPython can optionally call the
2207 When an exception is triggered, IPython can optionally call the
2193 interactive pdb debugger after the traceback printout. %pdb toggles
2208 interactive pdb debugger after the traceback printout. %pdb toggles
2194 this feature on and off.
2209 this feature on and off.
2195
2210
2196 The initial state of this feature is set in your ipythonrc
2211 The initial state of this feature is set in your ipythonrc
2197 configuration file (the variable is called 'pdb').
2212 configuration file (the variable is called 'pdb').
2198
2213
2199 If you want to just activate the debugger AFTER an exception has fired,
2214 If you want to just activate the debugger AFTER an exception has fired,
2200 without having to type '%pdb on' and rerunning your code, you can use
2215 without having to type '%pdb on' and rerunning your code, you can use
2201 the %debug magic.
2216 the %debug magic.
2202
2217
2203 **%pdef**::
2218 **%pdef**::
2204
2219
2205 Print the definition header for any callable object.
2220 Print the definition header for any callable object.
2206
2221
2207 If the object is a class, print the constructor information.
2222 If the object is a class, print the constructor information.
2208
2223
2209 **%pdoc**::
2224 **%pdoc**::
2210
2225
2211 Print the docstring for an object.
2226 Print the docstring for an object.
2212
2227
2213 If the given object is a class, it will print both the class and the
2228 If the given object is a class, it will print both the class and the
2214 constructor docstrings.
2229 constructor docstrings.
2215
2230
2216 **%pfile**::
2231 **%pfile**::
2217
2232
2218 Print (or run through pager) the file where an object is defined.
2233 Print (or run through pager) the file where an object is defined.
2219
2234
2220 The file opens at the line where the object definition begins. IPython
2235 The file opens at the line where the object definition begins. IPython
2221 will honor the environment variable PAGER if set, and otherwise will
2236 will honor the environment variable PAGER if set, and otherwise will
2222 do its best to print the file in a convenient form.
2237 do its best to print the file in a convenient form.
2223
2238
2224 If the given argument is not an object currently defined, IPython will
2239 If the given argument is not an object currently defined, IPython will
2225 try to interpret it as a filename (automatically adding a .py extension
2240 try to interpret it as a filename (automatically adding a .py extension
2226 if needed). You can thus use %pfile as a syntax highlighting code
2241 if needed). You can thus use %pfile as a syntax highlighting code
2227 viewer.
2242 viewer.
2228
2243
2229 **%pinfo**::
2244 **%pinfo**::
2230
2245
2231 Provide detailed information about an object.
2246 Provide detailed information about an object.
2232
2247
2233 '%pinfo object' is just a synonym for object? or ?object.
2248 '%pinfo object' is just a synonym for object? or ?object.
2234
2249
2235 **%popd**::
2250 **%popd**::
2236
2251
2237 Change to directory popped off the top of the stack.
2252 Change to directory popped off the top of the stack.
2238
2253
2239 **%profile**::
2254 **%profile**::
2240
2255
2241 Print your currently active IPyhton profile.
2256 Print your currently active IPyhton profile.
2242
2257
2243 **%prun**::
2258 **%prun**::
2244
2259
2245 Run a statement through the python code profiler.
2260 Run a statement through the python code profiler.
2246
2261
2247 Usage:\
2262 Usage:\
2248 %prun [options] statement
2263 %prun [options] statement
2249
2264
2250 The given statement (which doesn't require quote marks) is run via the
2265 The given statement (which doesn't require quote marks) is run via the
2251 python profiler in a manner similar to the profile.run() function.
2266 python profiler in a manner similar to the profile.run() function.
2252 Namespaces are internally managed to work correctly; profile.run
2267 Namespaces are internally managed to work correctly; profile.run
2253 cannot be used in IPython because it makes certain assumptions about
2268 cannot be used in IPython because it makes certain assumptions about
2254 namespaces which do not hold under IPython.
2269 namespaces which do not hold under IPython.
2255
2270
2256 Options:
2271 Options:
2257
2272
2258 -l <limit>: you can place restrictions on what or how much of the
2273 -l <limit>: you can place restrictions on what or how much of the
2259 profile gets printed. The limit value can be:
2274 profile gets printed. The limit value can be:
2260
2275
2261 * A string: only information for function names containing this string
2276 * A string: only information for function names containing this string
2262 is printed.
2277 is printed.
2263
2278
2264 * An integer: only these many lines are printed.
2279 * An integer: only these many lines are printed.
2265
2280
2266 * A float (between 0 and 1): this fraction of the report is printed
2281 * A float (between 0 and 1): this fraction of the report is printed
2267 (for example, use a limit of 0.4 to see the topmost 40% only).
2282 (for example, use a limit of 0.4 to see the topmost 40% only).
2268
2283
2269 You can combine several limits with repeated use of the option. For
2284 You can combine several limits with repeated use of the option. For
2270 example, '-l __init__ -l 5' will print only the topmost 5 lines of
2285 example, '-l __init__ -l 5' will print only the topmost 5 lines of
2271 information about class constructors.
2286 information about class constructors.
2272
2287
2273 -r: return the pstats.Stats object generated by the profiling. This
2288 -r: return the pstats.Stats object generated by the profiling. This
2274 object has all the information about the profile in it, and you can
2289 object has all the information about the profile in it, and you can
2275 later use it for further analysis or in other functions.
2290 later use it for further analysis or in other functions.
2276
2291
2277 -s <key>: sort profile by given key. You can provide more than one key
2292 -s <key>: sort profile by given key. You can provide more than one key
2278 by using the option several times: '-s key1 -s key2 -s key3...'. The
2293 by using the option several times: '-s key1 -s key2 -s key3...'. The
2279 default sorting key is 'time'.
2294 default sorting key is 'time'.
2280
2295
2281 The following is copied verbatim from the profile documentation
2296 The following is copied verbatim from the profile documentation
2282 referenced below:
2297 referenced below:
2283
2298
2284 When more than one key is provided, additional keys are used as
2299 When more than one key is provided, additional keys are used as
2285 secondary criteria when the there is equality in all keys selected
2300 secondary criteria when the there is equality in all keys selected
2286 before them.
2301 before them.
2287
2302
2288 Abbreviations can be used for any key names, as long as the
2303 Abbreviations can be used for any key names, as long as the
2289 abbreviation is unambiguous. The following are the keys currently
2304 abbreviation is unambiguous. The following are the keys currently
2290 defined:
2305 defined:
2291
2306
2292 Valid Arg Meaning\
2307 Valid Arg Meaning\
2293 "calls" call count\
2308 "calls" call count\
2294 "cumulative" cumulative time\
2309 "cumulative" cumulative time\
2295 "file" file name\
2310 "file" file name\
2296 "module" file name\
2311 "module" file name\
2297 "pcalls" primitive call count\
2312 "pcalls" primitive call count\
2298 "line" line number\
2313 "line" line number\
2299 "name" function name\
2314 "name" function name\
2300 "nfl" name/file/line\
2315 "nfl" name/file/line\
2301 "stdname" standard name\
2316 "stdname" standard name\
2302 "time" internal time
2317 "time" internal time
2303
2318
2304 Note that all sorts on statistics are in descending order (placing
2319 Note that all sorts on statistics are in descending order (placing
2305 most time consuming items first), where as name, file, and line number
2320 most time consuming items first), where as name, file, and line number
2306 searches are in ascending order (i.e., alphabetical). The subtle
2321 searches are in ascending order (i.e., alphabetical). The subtle
2307 distinction between "nfl" and "stdname" is that the standard name is a
2322 distinction between "nfl" and "stdname" is that the standard name is a
2308 sort of the name as printed, which means that the embedded line
2323 sort of the name as printed, which means that the embedded line
2309 numbers get compared in an odd way. For example, lines 3, 20, and 40
2324 numbers get compared in an odd way. For example, lines 3, 20, and 40
2310 would (if the file names were the same) appear in the string order
2325 would (if the file names were the same) appear in the string order
2311 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
2326 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
2312 line numbers. In fact, sort_stats("nfl") is the same as
2327 line numbers. In fact, sort_stats("nfl") is the same as
2313 sort_stats("name", "file", "line").
2328 sort_stats("name", "file", "line").
2314
2329
2315 -T <filename>: save profile results as shown on screen to a text
2330 -T <filename>: save profile results as shown on screen to a text
2316 file. The profile is still shown on screen.
2331 file. The profile is still shown on screen.
2317
2332
2318 -D <filename>: save (via dump_stats) profile statistics to given
2333 -D <filename>: save (via dump_stats) profile statistics to given
2319 filename. This data is in a format understod by the pstats module, and
2334 filename. This data is in a format understod by the pstats module, and
2320 is generated by a call to the dump_stats() method of profile
2335 is generated by a call to the dump_stats() method of profile
2321 objects. The profile is still shown on screen.
2336 objects. The profile is still shown on screen.
2322
2337
2323 If you want to run complete programs under the profiler's control, use
2338 If you want to run complete programs under the profiler's control, use
2324 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
2339 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
2325 contains profiler specific options as described here.
2340 contains profiler specific options as described here.
2326
2341
2327 You can read the complete documentation for the profile module with:\
2342 You can read the complete documentation for the profile module with:\
2328 In [1]: import profile; profile.help()
2343 In [1]: import profile; profile.help()
2329
2344
2330 **%psearch**::
2345 **%psearch**::
2331
2346
2332 Search for object in namespaces by wildcard.
2347 Search for object in namespaces by wildcard.
2333
2348
2334 %psearch [options] PATTERN [OBJECT TYPE]
2349 %psearch [options] PATTERN [OBJECT TYPE]
2335
2350
2336 Note: ? can be used as a synonym for %psearch, at the beginning or at
2351 Note: ? can be used as a synonym for %psearch, at the beginning or at
2337 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
2352 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
2338 rest of the command line must be unchanged (options come first), so
2353 rest of the command line must be unchanged (options come first), so
2339 for example the following forms are equivalent
2354 for example the following forms are equivalent
2340
2355
2341 %psearch -i a* function
2356 %psearch -i a* function
2342 -i a* function?
2357 -i a* function?
2343 ?-i a* function
2358 ?-i a* function
2344
2359
2345 Arguments:
2360 Arguments:
2346
2361
2347 PATTERN
2362 PATTERN
2348
2363
2349 where PATTERN is a string containing * as a wildcard similar to its
2364 where PATTERN is a string containing * as a wildcard similar to its
2350 use in a shell. The pattern is matched in all namespaces on the
2365 use in a shell. The pattern is matched in all namespaces on the
2351 search path. By default objects starting with a single _ are not
2366 search path. By default objects starting with a single _ are not
2352 matched, many IPython generated objects have a single
2367 matched, many IPython generated objects have a single
2353 underscore. The default is case insensitive matching. Matching is
2368 underscore. The default is case insensitive matching. Matching is
2354 also done on the attributes of objects and not only on the objects
2369 also done on the attributes of objects and not only on the objects
2355 in a module.
2370 in a module.
2356
2371
2357 [OBJECT TYPE]
2372 [OBJECT TYPE]
2358
2373
2359 Is the name of a python type from the types module. The name is
2374 Is the name of a python type from the types module. The name is
2360 given in lowercase without the ending type, ex. StringType is
2375 given in lowercase without the ending type, ex. StringType is
2361 written string. By adding a type here only objects matching the
2376 written string. By adding a type here only objects matching the
2362 given type are matched. Using all here makes the pattern match all
2377 given type are matched. Using all here makes the pattern match all
2363 types (this is the default).
2378 types (this is the default).
2364
2379
2365 Options:
2380 Options:
2366
2381
2367 -a: makes the pattern match even objects whose names start with a
2382 -a: makes the pattern match even objects whose names start with a
2368 single underscore. These names are normally ommitted from the
2383 single underscore. These names are normally ommitted from the
2369 search.
2384 search.
2370
2385
2371 -i/-c: make the pattern case insensitive/sensitive. If neither of
2386 -i/-c: make the pattern case insensitive/sensitive. If neither of
2372 these options is given, the default is read from your ipythonrc
2387 these options is given, the default is read from your ipythonrc
2373 file. The option name which sets this value is
2388 file. The option name which sets this value is
2374 'wildcards_case_sensitive'. If this option is not specified in your
2389 'wildcards_case_sensitive'. If this option is not specified in your
2375 ipythonrc file, IPython's internal default is to do a case sensitive
2390 ipythonrc file, IPython's internal default is to do a case sensitive
2376 search.
2391 search.
2377
2392
2378 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
2393 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
2379 specifiy can be searched in any of the following namespaces:
2394 specifiy can be searched in any of the following namespaces:
2380 'builtin', 'user', 'user_global','internal', 'alias', where
2395 'builtin', 'user', 'user_global','internal', 'alias', where
2381 'builtin' and 'user' are the search defaults. Note that you should
2396 'builtin' and 'user' are the search defaults. Note that you should
2382 not use quotes when specifying namespaces.
2397 not use quotes when specifying namespaces.
2383
2398
2384 'Builtin' contains the python module builtin, 'user' contains all
2399 'Builtin' contains the python module builtin, 'user' contains all
2385 user data, 'alias' only contain the shell aliases and no python
2400 user data, 'alias' only contain the shell aliases and no python
2386 objects, 'internal' contains objects used by IPython. The
2401 objects, 'internal' contains objects used by IPython. The
2387 'user_global' namespace is only used by embedded IPython instances,
2402 'user_global' namespace is only used by embedded IPython instances,
2388 and it contains module-level globals. You can add namespaces to the
2403 and it contains module-level globals. You can add namespaces to the
2389 search with -s or exclude them with -e (these options can be given
2404 search with -s or exclude them with -e (these options can be given
2390 more than once).
2405 more than once).
2391
2406
2392 Examples:
2407 Examples:
2393
2408
2394 %psearch a* -> objects beginning with an a
2409 %psearch a* -> objects beginning with an a
2395 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
2410 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
2396 %psearch a* function -> all functions beginning with an a
2411 %psearch a* function -> all functions beginning with an a
2397 %psearch re.e* -> objects beginning with an e in module re
2412 %psearch re.e* -> objects beginning with an e in module re
2398 %psearch r*.e* -> objects that start with e in modules starting in r
2413 %psearch r*.e* -> objects that start with e in modules starting in r
2399 %psearch r*.* string -> all strings in modules beginning with r
2414 %psearch r*.* string -> all strings in modules beginning with r
2400
2415
2401 Case sensitve search:
2416 Case sensitve search:
2402
2417
2403 %psearch -c a* list all object beginning with lower case a
2418 %psearch -c a* list all object beginning with lower case a
2404
2419
2405 Show objects beginning with a single _:
2420 Show objects beginning with a single _:
2406
2421
2407 %psearch -a _* list objects beginning with a single underscore
2422 %psearch -a _* list objects beginning with a single underscore
2408
2423
2409 **%psource**::
2424 **%psource**::
2410
2425
2411 Print (or run through pager) the source code for an object.
2426 Print (or run through pager) the source code for an object.
2412
2427
2413 **%pushd**::
2428 **%pushd**::
2414
2429
2415 Place the current dir on stack and change directory.
2430 Place the current dir on stack and change directory.
2416
2431
2417 Usage:\
2432 Usage:\
2418 %pushd ['dirname']
2433 %pushd ['dirname']
2419
2434
2420 **%pwd**::
2435 **%pwd**::
2421
2436
2422 Return the current working directory path.
2437 Return the current working directory path.
2423
2438
2424 **%pycat**::
2439 **%pycat**::
2425
2440
2426 Show a syntax-highlighted file through a pager.
2441 Show a syntax-highlighted file through a pager.
2427
2442
2428 This magic is similar to the cat utility, but it will assume the file
2443 This magic is similar to the cat utility, but it will assume the file
2429 to be Python source and will show it with syntax highlighting.
2444 to be Python source and will show it with syntax highlighting.
2430
2445
2431 **%quickref**::
2446 **%quickref**::
2432
2447
2433 Show a quick reference sheet
2448 Show a quick reference sheet
2434
2449
2435 **%quit**::
2450 **%quit**::
2436
2451
2437 Exit IPython, confirming if configured to do so (like %exit)
2452 Exit IPython, confirming if configured to do so (like %exit)
2438
2453
2439 **%r**::
2454 **%r**::
2440
2455
2441 Repeat previous input.
2456 Repeat previous input.
2442
2457
2443 Note: Consider using the more powerfull %rep instead!
2458 Note: Consider using the more powerfull %rep instead!
2444
2459
2445 If given an argument, repeats the previous command which starts with
2460 If given an argument, repeats the previous command which starts with
2446 the same string, otherwise it just repeats the previous input.
2461 the same string, otherwise it just repeats the previous input.
2447
2462
2448 Shell escaped commands (with ! as first character) are not recognized
2463 Shell escaped commands (with ! as first character) are not recognized
2449 by this system, only pure python code and magic commands.
2464 by this system, only pure python code and magic commands.
2450
2465
2451 **%rehashdir**::
2466 **%rehashdir**::
2452
2467
2453 Add executables in all specified dirs to alias table
2468 Add executables in all specified dirs to alias table
2454
2469
2455 Usage:
2470 Usage:
2456
2471
2457 %rehashdir c:/bin;c:/tools
2472 %rehashdir c:/bin;c:/tools
2458 - Add all executables under c:/bin and c:/tools to alias table, in
2473 - Add all executables under c:/bin and c:/tools to alias table, in
2459 order to make them directly executable from any directory.
2474 order to make them directly executable from any directory.
2460
2475
2461 Without arguments, add all executables in current directory.
2476 Without arguments, add all executables in current directory.
2462
2477
2463 **%rehashx**::
2478 **%rehashx**::
2464
2479
2465 Update the alias table with all executable files in $PATH.
2480 Update the alias table with all executable files in $PATH.
2466
2481
2467 This version explicitly checks that every entry in $PATH is a file
2482 This version explicitly checks that every entry in $PATH is a file
2468 with execute access (os.X_OK), so it is much slower than %rehash.
2483 with execute access (os.X_OK), so it is much slower than %rehash.
2469
2484
2470 Under Windows, it checks executability as a match agains a
2485 Under Windows, it checks executability as a match agains a
2471 '|'-separated string of extensions, stored in the IPython config
2486 '|'-separated string of extensions, stored in the IPython config
2472 variable win_exec_ext. This defaults to 'exe|com|bat'.
2487 variable win_exec_ext. This defaults to 'exe|com|bat'.
2473
2488
2474 This function also resets the root module cache of module completer,
2489 This function also resets the root module cache of module completer,
2475 used on slow filesystems.
2490 used on slow filesystems.
2476
2491
2477 **%rep**::
2492 **%rep**::
2478
2493
2479 Repeat a command, or get command to input line for editing
2494 Repeat a command, or get command to input line for editing
2480
2495
2481 - %rep (no arguments):
2496 - %rep (no arguments):
2482
2497
2483 Place a string version of last computation result (stored in the special '_'
2498 Place a string version of last computation result (stored in the special '_'
2484 variable) to the next input prompt. Allows you to create elaborate command
2499 variable) to the next input prompt. Allows you to create elaborate command
2485 lines without using copy-paste::
2500 lines without using copy-paste::
2486
2501
2487 $ l = ["hei", "vaan"]
2502 $ l = ["hei", "vaan"]
2488 $ "".join(l)
2503 $ "".join(l)
2489 ==> heivaan
2504 ==> heivaan
2490 $ %rep
2505 $ %rep
2491 $ heivaan_ <== cursor blinking
2506 $ heivaan_ <== cursor blinking
2492
2507
2493 %rep 45
2508 %rep 45
2494
2509
2495 Place history line 45 to next input prompt. Use %hist to find out the
2510 Place history line 45 to next input prompt. Use %hist to find out the
2496 number.
2511 number.
2497
2512
2498 %rep 1-4 6-7 3
2513 %rep 1-4 6-7 3
2499
2514
2500 Repeat the specified lines immediately. Input slice syntax is the same as
2515 Repeat the specified lines immediately. Input slice syntax is the same as
2501 in %macro and %save.
2516 in %macro and %save.
2502
2517
2503 %rep foo
2518 %rep foo
2504
2519
2505 Place the most recent line that has the substring "foo" to next input.
2520 Place the most recent line that has the substring "foo" to next input.
2506 (e.g. 'svn ci -m foobar').
2521 (e.g. 'svn ci -m foobar').
2507
2522
2508 **%reset**::
2523 **%reset**::
2509
2524
2510 Resets the namespace by removing all names defined by the user.
2525 Resets the namespace by removing all names defined by the user.
2511
2526
2512 Input/Output history are left around in case you need them.
2527 Input/Output history are left around in case you need them.
2513
2528
2514 **%run**::
2529 **%run**::
2515
2530
2516 Run the named file inside IPython as a program.
2531 Run the named file inside IPython as a program.
2517
2532
2518 Usage:\
2533 Usage:\
2519 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
2534 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
2520
2535
2521 Parameters after the filename are passed as command-line arguments to
2536 Parameters after the filename are passed as command-line arguments to
2522 the program (put in sys.argv). Then, control returns to IPython's
2537 the program (put in sys.argv). Then, control returns to IPython's
2523 prompt.
2538 prompt.
2524
2539
2525 This is similar to running at a system prompt:\
2540 This is similar to running at a system prompt:\
2526 $ python file args\
2541 $ python file args\
2527 but with the advantage of giving you IPython's tracebacks, and of
2542 but with the advantage of giving you IPython's tracebacks, and of
2528 loading all variables into your interactive namespace for further use
2543 loading all variables into your interactive namespace for further use
2529 (unless -p is used, see below).
2544 (unless -p is used, see below).
2530
2545
2531 The file is executed in a namespace initially consisting only of
2546 The file is executed in a namespace initially consisting only of
2532 __name__=='__main__' and sys.argv constructed as indicated. It thus
2547 __name__=='__main__' and sys.argv constructed as indicated. It thus
2533 sees its environment as if it were being run as a stand-alone program
2548 sees its environment as if it were being run as a stand-alone program
2534 (except for sharing global objects such as previously imported
2549 (except for sharing global objects such as previously imported
2535 modules). But after execution, the IPython interactive namespace gets
2550 modules). But after execution, the IPython interactive namespace gets
2536 updated with all variables defined in the program (except for __name__
2551 updated with all variables defined in the program (except for __name__
2537 and sys.argv). This allows for very convenient loading of code for
2552 and sys.argv). This allows for very convenient loading of code for
2538 interactive work, while giving each program a 'clean sheet' to run in.
2553 interactive work, while giving each program a 'clean sheet' to run in.
2539
2554
2540 Options:
2555 Options:
2541
2556
2542 -n: __name__ is NOT set to '__main__', but to the running file's name
2557 -n: __name__ is NOT set to '__main__', but to the running file's name
2543 without extension (as python does under import). This allows running
2558 without extension (as python does under import). This allows running
2544 scripts and reloading the definitions in them without calling code
2559 scripts and reloading the definitions in them without calling code
2545 protected by an ' if __name__ == "__main__" ' clause.
2560 protected by an ' if __name__ == "__main__" ' clause.
2546
2561
2547 -i: run the file in IPython's namespace instead of an empty one. This
2562 -i: run the file in IPython's namespace instead of an empty one. This
2548 is useful if you are experimenting with code written in a text editor
2563 is useful if you are experimenting with code written in a text editor
2549 which depends on variables defined interactively.
2564 which depends on variables defined interactively.
2550
2565
2551 -e: ignore sys.exit() calls or SystemExit exceptions in the script
2566 -e: ignore sys.exit() calls or SystemExit exceptions in the script
2552 being run. This is particularly useful if IPython is being used to
2567 being run. This is particularly useful if IPython is being used to
2553 run unittests, which always exit with a sys.exit() call. In such
2568 run unittests, which always exit with a sys.exit() call. In such
2554 cases you are interested in the output of the test results, not in
2569 cases you are interested in the output of the test results, not in
2555 seeing a traceback of the unittest module.
2570 seeing a traceback of the unittest module.
2556
2571
2557 -t: print timing information at the end of the run. IPython will give
2572 -t: print timing information at the end of the run. IPython will give
2558 you an estimated CPU time consumption for your script, which under
2573 you an estimated CPU time consumption for your script, which under
2559 Unix uses the resource module to avoid the wraparound problems of
2574 Unix uses the resource module to avoid the wraparound problems of
2560 time.clock(). Under Unix, an estimate of time spent on system tasks
2575 time.clock(). Under Unix, an estimate of time spent on system tasks
2561 is also given (for Windows platforms this is reported as 0.0).
2576 is also given (for Windows platforms this is reported as 0.0).
2562
2577
2563 If -t is given, an additional -N<N> option can be given, where <N>
2578 If -t is given, an additional -N<N> option can be given, where <N>
2564 must be an integer indicating how many times you want the script to
2579 must be an integer indicating how many times you want the script to
2565 run. The final timing report will include total and per run results.
2580 run. The final timing report will include total and per run results.
2566
2581
2567 For example (testing the script uniq_stable.py):
2582 For example (testing the script uniq_stable.py):
2568
2583
2569 In [1]: run -t uniq_stable
2584 In [1]: run -t uniq_stable
2570
2585
2571 IPython CPU timings (estimated):\
2586 IPython CPU timings (estimated):\
2572 User : 0.19597 s.\
2587 User : 0.19597 s.\
2573 System: 0.0 s.\
2588 System: 0.0 s.\
2574
2589
2575 In [2]: run -t -N5 uniq_stable
2590 In [2]: run -t -N5 uniq_stable
2576
2591
2577 IPython CPU timings (estimated):\
2592 IPython CPU timings (estimated):\
2578 Total runs performed: 5\
2593 Total runs performed: 5\
2579 Times : Total Per run\
2594 Times : Total Per run\
2580 User : 0.910862 s, 0.1821724 s.\
2595 User : 0.910862 s, 0.1821724 s.\
2581 System: 0.0 s, 0.0 s.
2596 System: 0.0 s, 0.0 s.
2582
2597
2583 -d: run your program under the control of pdb, the Python debugger.
2598 -d: run your program under the control of pdb, the Python debugger.
2584 This allows you to execute your program step by step, watch variables,
2599 This allows you to execute your program step by step, watch variables,
2585 etc. Internally, what IPython does is similar to calling:
2600 etc. Internally, what IPython does is similar to calling:
2586
2601
2587 pdb.run('execfile("YOURFILENAME")')
2602 pdb.run('execfile("YOURFILENAME")')
2588
2603
2589 with a breakpoint set on line 1 of your file. You can change the line
2604 with a breakpoint set on line 1 of your file. You can change the line
2590 number for this automatic breakpoint to be <N> by using the -bN option
2605 number for this automatic breakpoint to be <N> by using the -bN option
2591 (where N must be an integer). For example:
2606 (where N must be an integer). For example:
2592
2607
2593 %run -d -b40 myscript
2608 %run -d -b40 myscript
2594
2609
2595 will set the first breakpoint at line 40 in myscript.py. Note that
2610 will set the first breakpoint at line 40 in myscript.py. Note that
2596 the first breakpoint must be set on a line which actually does
2611 the first breakpoint must be set on a line which actually does
2597 something (not a comment or docstring) for it to stop execution.
2612 something (not a comment or docstring) for it to stop execution.
2598
2613
2599 When the pdb debugger starts, you will see a (Pdb) prompt. You must
2614 When the pdb debugger starts, you will see a (Pdb) prompt. You must
2600 first enter 'c' (without qoutes) to start execution up to the first
2615 first enter 'c' (without qoutes) to start execution up to the first
2601 breakpoint.
2616 breakpoint.
2602
2617
2603 Entering 'help' gives information about the use of the debugger. You
2618 Entering 'help' gives information about the use of the debugger. You
2604 can easily see pdb's full documentation with "import pdb;pdb.help()"
2619 can easily see pdb's full documentation with "import pdb;pdb.help()"
2605 at a prompt.
2620 at a prompt.
2606
2621
2607 -p: run program under the control of the Python profiler module (which
2622 -p: run program under the control of the Python profiler module (which
2608 prints a detailed report of execution times, function calls, etc).
2623 prints a detailed report of execution times, function calls, etc).
2609
2624
2610 You can pass other options after -p which affect the behavior of the
2625 You can pass other options after -p which affect the behavior of the
2611 profiler itself. See the docs for %prun for details.
2626 profiler itself. See the docs for %prun for details.
2612
2627
2613 In this mode, the program's variables do NOT propagate back to the
2628 In this mode, the program's variables do NOT propagate back to the
2614 IPython interactive namespace (because they remain in the namespace
2629 IPython interactive namespace (because they remain in the namespace
2615 where the profiler executes them).
2630 where the profiler executes them).
2616
2631
2617 Internally this triggers a call to %prun, see its documentation for
2632 Internally this triggers a call to %prun, see its documentation for
2618 details on the options available specifically for profiling.
2633 details on the options available specifically for profiling.
2619
2634
2620 There is one special usage for which the text above doesn't apply:
2635 There is one special usage for which the text above doesn't apply:
2621 if the filename ends with .ipy, the file is run as ipython script,
2636 if the filename ends with .ipy, the file is run as ipython script,
2622 just as if the commands were written on IPython prompt.
2637 just as if the commands were written on IPython prompt.
2623
2638
2624 **%runlog**::
2639 **%runlog**::
2625
2640
2626 Run files as logs.
2641 Run files as logs.
2627
2642
2628 Usage:\
2643 Usage:\
2629 %runlog file1 file2 ...
2644 %runlog file1 file2 ...
2630
2645
2631 Run the named files (treating them as log files) in sequence inside
2646 Run the named files (treating them as log files) in sequence inside
2632 the interpreter, and return to the prompt. This is much slower than
2647 the interpreter, and return to the prompt. This is much slower than
2633 %run because each line is executed in a try/except block, but it
2648 %run because each line is executed in a try/except block, but it
2634 allows running files with syntax errors in them.
2649 allows running files with syntax errors in them.
2635
2650
2636 Normally IPython will guess when a file is one of its own logfiles, so
2651 Normally IPython will guess when a file is one of its own logfiles, so
2637 you can typically use %run even for logs. This shorthand allows you to
2652 you can typically use %run even for logs. This shorthand allows you to
2638 force any file to be treated as a log file.
2653 force any file to be treated as a log file.
2639
2654
2640 **%save**::
2655 **%save**::
2641
2656
2642 Save a set of lines to a given filename.
2657 Save a set of lines to a given filename.
2643
2658
2644 Usage:\
2659 Usage:\
2645 %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
2660 %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
2646
2661
2647 Options:
2662 Options:
2648
2663
2649 -r: use 'raw' input. By default, the 'processed' history is used,
2664 -r: use 'raw' input. By default, the 'processed' history is used,
2650 so that magics are loaded in their transformed version to valid
2665 so that magics are loaded in their transformed version to valid
2651 Python. If this option is given, the raw input as typed as the
2666 Python. If this option is given, the raw input as typed as the
2652 command line is used instead.
2667 command line is used instead.
2653
2668
2654 This function uses the same syntax as %macro for line extraction, but
2669 This function uses the same syntax as %macro for line extraction, but
2655 instead of creating a macro it saves the resulting string to the
2670 instead of creating a macro it saves the resulting string to the
2656 filename you specify.
2671 filename you specify.
2657
2672
2658 It adds a '.py' extension to the file if you don't do so yourself, and
2673 It adds a '.py' extension to the file if you don't do so yourself, and
2659 it asks for confirmation before overwriting existing files.
2674 it asks for confirmation before overwriting existing files.
2660
2675
2661 **%sc**::
2676 **%sc**::
2662
2677
2663 Shell capture - execute a shell command and capture its output.
2678 Shell capture - execute a shell command and capture its output.
2664
2679
2665 DEPRECATED. Suboptimal, retained for backwards compatibility.
2680 DEPRECATED. Suboptimal, retained for backwards compatibility.
2666
2681
2667 You should use the form 'var = !command' instead. Example:
2682 You should use the form 'var = !command' instead. Example:
2668
2683
2669 "%sc -l myfiles = ls ~" should now be written as
2684 "%sc -l myfiles = ls ~" should now be written as
2670
2685
2671 "myfiles = !ls ~"
2686 "myfiles = !ls ~"
2672
2687
2673 myfiles.s, myfiles.l and myfiles.n still apply as documented
2688 myfiles.s, myfiles.l and myfiles.n still apply as documented
2674 below.
2689 below.
2675
2690
2676 --
2691 --
2677 %sc [options] varname=command
2692 %sc [options] varname=command
2678
2693
2679 IPython will run the given command using commands.getoutput(), and
2694 IPython will run the given command using commands.getoutput(), and
2680 will then update the user's interactive namespace with a variable
2695 will then update the user's interactive namespace with a variable
2681 called varname, containing the value of the call. Your command can
2696 called varname, containing the value of the call. Your command can
2682 contain shell wildcards, pipes, etc.
2697 contain shell wildcards, pipes, etc.
2683
2698
2684 The '=' sign in the syntax is mandatory, and the variable name you
2699 The '=' sign in the syntax is mandatory, and the variable name you
2685 supply must follow Python's standard conventions for valid names.
2700 supply must follow Python's standard conventions for valid names.
2686
2701
2687 (A special format without variable name exists for internal use)
2702 (A special format without variable name exists for internal use)
2688
2703
2689 Options:
2704 Options:
2690
2705
2691 -l: list output. Split the output on newlines into a list before
2706 -l: list output. Split the output on newlines into a list before
2692 assigning it to the given variable. By default the output is stored
2707 assigning it to the given variable. By default the output is stored
2693 as a single string.
2708 as a single string.
2694
2709
2695 -v: verbose. Print the contents of the variable.
2710 -v: verbose. Print the contents of the variable.
2696
2711
2697 In most cases you should not need to split as a list, because the
2712 In most cases you should not need to split as a list, because the
2698 returned value is a special type of string which can automatically
2713 returned value is a special type of string which can automatically
2699 provide its contents either as a list (split on newlines) or as a
2714 provide its contents either as a list (split on newlines) or as a
2700 space-separated string. These are convenient, respectively, either
2715 space-separated string. These are convenient, respectively, either
2701 for sequential processing or to be passed to a shell command.
2716 for sequential processing or to be passed to a shell command.
2702
2717
2703 For example:
2718 For example:
2704
2719
2705 # Capture into variable a
2720 # Capture into variable a
2706 In [9]: sc a=ls *py
2721 In [9]: sc a=ls *py
2707
2722
2708 # a is a string with embedded newlines
2723 # a is a string with embedded newlines
2709 In [10]: a
2724 In [10]: a
2710 Out[10]: 'setup.py win32_manual_post_install.py'
2725 Out[10]: 'setup.py win32_manual_post_install.py'
2711
2726
2712 # which can be seen as a list:
2727 # which can be seen as a list:
2713 In [11]: a.l
2728 In [11]: a.l
2714 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2729 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2715
2730
2716 # or as a whitespace-separated string:
2731 # or as a whitespace-separated string:
2717 In [12]: a.s
2732 In [12]: a.s
2718 Out[12]: 'setup.py win32_manual_post_install.py'
2733 Out[12]: 'setup.py win32_manual_post_install.py'
2719
2734
2720 # a.s is useful to pass as a single command line:
2735 # a.s is useful to pass as a single command line:
2721 In [13]: !wc -l $a.s
2736 In [13]: !wc -l $a.s
2722 146 setup.py
2737 146 setup.py
2723 130 win32_manual_post_install.py
2738 130 win32_manual_post_install.py
2724 276 total
2739 276 total
2725
2740
2726 # while the list form is useful to loop over:
2741 # while the list form is useful to loop over:
2727 In [14]: for f in a.l:
2742 In [14]: for f in a.l:
2728 ....: !wc -l $f
2743 ....: !wc -l $f
2729 ....:
2744 ....:
2730 146 setup.py
2745 146 setup.py
2731 130 win32_manual_post_install.py
2746 130 win32_manual_post_install.py
2732
2747
2733 Similiarly, the lists returned by the -l option are also special, in
2748 Similiarly, the lists returned by the -l option are also special, in
2734 the sense that you can equally invoke the .s attribute on them to
2749 the sense that you can equally invoke the .s attribute on them to
2735 automatically get a whitespace-separated string from their contents:
2750 automatically get a whitespace-separated string from their contents:
2736
2751
2737 In [1]: sc -l b=ls *py
2752 In [1]: sc -l b=ls *py
2738
2753
2739 In [2]: b
2754 In [2]: b
2740 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2755 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2741
2756
2742 In [3]: b.s
2757 In [3]: b.s
2743 Out[3]: 'setup.py win32_manual_post_install.py'
2758 Out[3]: 'setup.py win32_manual_post_install.py'
2744
2759
2745 In summary, both the lists and strings used for ouptut capture have
2760 In summary, both the lists and strings used for ouptut capture have
2746 the following special attributes:
2761 the following special attributes:
2747
2762
2748 .l (or .list) : value as list.
2763 .l (or .list) : value as list.
2749 .n (or .nlstr): value as newline-separated string.
2764 .n (or .nlstr): value as newline-separated string.
2750 .s (or .spstr): value as space-separated string.
2765 .s (or .spstr): value as space-separated string.
2751
2766
2752 **%store**::
2767 **%store**::
2753
2768
2754 Lightweight persistence for python variables.
2769 Lightweight persistence for python variables.
2755
2770
2756 Example:
2771 Example:
2757
2772
2758 ville@badger[~]|1> A = ['hello',10,'world']\
2773 ville@badger[~]|1> A = ['hello',10,'world']\
2759 ville@badger[~]|2> %store A\
2774 ville@badger[~]|2> %store A\
2760 ville@badger[~]|3> Exit
2775 ville@badger[~]|3> Exit
2761
2776
2762 (IPython session is closed and started again...)
2777 (IPython session is closed and started again...)
2763
2778
2764 ville@badger:~$ ipython -p pysh\
2779 ville@badger:~$ ipython -p pysh\
2765 ville@badger[~]|1> print A
2780 ville@badger[~]|1> print A
2766
2781
2767 ['hello', 10, 'world']
2782 ['hello', 10, 'world']
2768
2783
2769 Usage:
2784 Usage:
2770
2785
2771 %store - Show list of all variables and their current values\
2786 %store - Show list of all variables and their current values\
2772 %store <var> - Store the *current* value of the variable to disk\
2787 %store <var> - Store the *current* value of the variable to disk\
2773 %store -d <var> - Remove the variable and its value from storage\
2788 %store -d <var> - Remove the variable and its value from storage\
2774 %store -z - Remove all variables from storage\
2789 %store -z - Remove all variables from storage\
2775 %store -r - Refresh all variables from store (delete current vals)\
2790 %store -r - Refresh all variables from store (delete current vals)\
2776 %store foo >a.txt - Store value of foo to new file a.txt\
2791 %store foo >a.txt - Store value of foo to new file a.txt\
2777 %store foo >>a.txt - Append value of foo to file a.txt\
2792 %store foo >>a.txt - Append value of foo to file a.txt\
2778
2793
2779 It should be noted that if you change the value of a variable, you
2794 It should be noted that if you change the value of a variable, you
2780 need to %store it again if you want to persist the new value.
2795 need to %store it again if you want to persist the new value.
2781
2796
2782 Note also that the variables will need to be pickleable; most basic
2797 Note also that the variables will need to be pickleable; most basic
2783 python types can be safely %stored.
2798 python types can be safely %stored.
2784
2799
2785 Also aliases can be %store'd across sessions.
2800 Also aliases can be %store'd across sessions.
2786
2801
2787 **%sx**::
2802 **%sx**::
2788
2803
2789 Shell execute - run a shell command and capture its output.
2804 Shell execute - run a shell command and capture its output.
2790
2805
2791 %sx command
2806 %sx command
2792
2807
2793 IPython will run the given command using commands.getoutput(), and
2808 IPython will run the given command using commands.getoutput(), and
2794 return the result formatted as a list (split on '\n'). Since the
2809 return the result formatted as a list (split on '\n'). Since the
2795 output is _returned_, it will be stored in ipython's regular output
2810 output is _returned_, it will be stored in ipython's regular output
2796 cache Out[N] and in the '_N' automatic variables.
2811 cache Out[N] and in the '_N' automatic variables.
2797
2812
2798 Notes:
2813 Notes:
2799
2814
2800 1) If an input line begins with '!!', then %sx is automatically
2815 1) If an input line begins with '!!', then %sx is automatically
2801 invoked. That is, while:
2816 invoked. That is, while:
2802 !ls
2817 !ls
2803 causes ipython to simply issue system('ls'), typing
2818 causes ipython to simply issue system('ls'), typing
2804 !!ls
2819 !!ls
2805 is a shorthand equivalent to:
2820 is a shorthand equivalent to:
2806 %sx ls
2821 %sx ls
2807
2822
2808 2) %sx differs from %sc in that %sx automatically splits into a list,
2823 2) %sx differs from %sc in that %sx automatically splits into a list,
2809 like '%sc -l'. The reason for this is to make it as easy as possible
2824 like '%sc -l'. The reason for this is to make it as easy as possible
2810 to process line-oriented shell output via further python commands.
2825 to process line-oriented shell output via further python commands.
2811 %sc is meant to provide much finer control, but requires more
2826 %sc is meant to provide much finer control, but requires more
2812 typing.
2827 typing.
2813
2828
2814 3) Just like %sc -l, this is a list with special attributes:
2829 3) Just like %sc -l, this is a list with special attributes:
2815
2830
2816 .l (or .list) : value as list.
2831 .l (or .list) : value as list.
2817 .n (or .nlstr): value as newline-separated string.
2832 .n (or .nlstr): value as newline-separated string.
2818 .s (or .spstr): value as whitespace-separated string.
2833 .s (or .spstr): value as whitespace-separated string.
2819
2834
2820 This is very useful when trying to use such lists as arguments to
2835 This is very useful when trying to use such lists as arguments to
2821 system commands.
2836 system commands.
2822
2837
2823 **%system_verbose**::
2838 **%system_verbose**::
2824
2839
2825 Set verbose printing of system calls.
2840 Set verbose printing of system calls.
2826
2841
2827 If called without an argument, act as a toggle
2842 If called without an argument, act as a toggle
2828
2843
2829 **%time**::
2844 **%time**::
2830
2845
2831 Time execution of a Python statement or expression.
2846 Time execution of a Python statement or expression.
2832
2847
2833 The CPU and wall clock times are printed, and the value of the
2848 The CPU and wall clock times are printed, and the value of the
2834 expression (if any) is returned. Note that under Win32, system time
2849 expression (if any) is returned. Note that under Win32, system time
2835 is always reported as 0, since it can not be measured.
2850 is always reported as 0, since it can not be measured.
2836
2851
2837 This function provides very basic timing functionality. In Python
2852 This function provides very basic timing functionality. In Python
2838 2.3, the timeit module offers more control and sophistication, so this
2853 2.3, the timeit module offers more control and sophistication, so this
2839 could be rewritten to use it (patches welcome).
2854 could be rewritten to use it (patches welcome).
2840
2855
2841 Some examples:
2856 Some examples:
2842
2857
2843 In [1]: time 2**128
2858 In [1]: time 2**128
2844 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2859 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2845 Wall time: 0.00
2860 Wall time: 0.00
2846 Out[1]: 340282366920938463463374607431768211456L
2861 Out[1]: 340282366920938463463374607431768211456L
2847
2862
2848 In [2]: n = 1000000
2863 In [2]: n = 1000000
2849
2864
2850 In [3]: time sum(range(n))
2865 In [3]: time sum(range(n))
2851 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
2866 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
2852 Wall time: 1.37
2867 Wall time: 1.37
2853 Out[3]: 499999500000L
2868 Out[3]: 499999500000L
2854
2869
2855 In [4]: time print 'hello world'
2870 In [4]: time print 'hello world'
2856 hello world
2871 hello world
2857 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2872 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2858 Wall time: 0.00
2873 Wall time: 0.00
2859
2874
2860 Note that the time needed by Python to compile the given expression
2875 Note that the time needed by Python to compile the given expression
2861 will be reported if it is more than 0.1s. In this example, the
2876 will be reported if it is more than 0.1s. In this example, the
2862 actual exponentiation is done by Python at compilation time, so while
2877 actual exponentiation is done by Python at compilation time, so while
2863 the expression can take a noticeable amount of time to compute, that
2878 the expression can take a noticeable amount of time to compute, that
2864 time is purely due to the compilation:
2879 time is purely due to the compilation:
2865
2880
2866 In [5]: time 3**9999;
2881 In [5]: time 3**9999;
2867 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2882 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2868 Wall time: 0.00 s
2883 Wall time: 0.00 s
2869
2884
2870 In [6]: time 3**999999;
2885 In [6]: time 3**999999;
2871 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2886 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
2872 Wall time: 0.00 s
2887 Wall time: 0.00 s
2873 Compiler : 0.78 s
2888 Compiler : 0.78 s
2874
2889
2875 **%timeit**::
2890 **%timeit**::
2876
2891
2877 Time execution of a Python statement or expression
2892 Time execution of a Python statement or expression
2878
2893
2879 Usage:\
2894 Usage:\
2880 %timeit [-n<N> -r<R> [-t|-c]] statement
2895 %timeit [-n<N> -r<R> [-t|-c]] statement
2881
2896
2882 Time execution of a Python statement or expression using the timeit
2897 Time execution of a Python statement or expression using the timeit
2883 module.
2898 module.
2884
2899
2885 Options:
2900 Options:
2886 -n<N>: execute the given statement <N> times in a loop. If this value
2901 -n<N>: execute the given statement <N> times in a loop. If this value
2887 is not given, a fitting value is chosen.
2902 is not given, a fitting value is chosen.
2888
2903
2889 -r<R>: repeat the loop iteration <R> times and take the best result.
2904 -r<R>: repeat the loop iteration <R> times and take the best result.
2890 Default: 3
2905 Default: 3
2891
2906
2892 -t: use time.time to measure the time, which is the default on Unix.
2907 -t: use time.time to measure the time, which is the default on Unix.
2893 This function measures wall time.
2908 This function measures wall time.
2894
2909
2895 -c: use time.clock to measure the time, which is the default on
2910 -c: use time.clock to measure the time, which is the default on
2896 Windows and measures wall time. On Unix, resource.getrusage is used
2911 Windows and measures wall time. On Unix, resource.getrusage is used
2897 instead and returns the CPU user time.
2912 instead and returns the CPU user time.
2898
2913
2899 -p<P>: use a precision of <P> digits to display the timing result.
2914 -p<P>: use a precision of <P> digits to display the timing result.
2900 Default: 3
2915 Default: 3
2901
2916
2902
2917
2903 Examples:\
2918 Examples:\
2904 In [1]: %timeit pass
2919 In [1]: %timeit pass
2905 10000000 loops, best of 3: 53.3 ns per loop
2920 10000000 loops, best of 3: 53.3 ns per loop
2906
2921
2907 In [2]: u = None
2922 In [2]: u = None
2908
2923
2909 In [3]: %timeit u is None
2924 In [3]: %timeit u is None
2910 10000000 loops, best of 3: 184 ns per loop
2925 10000000 loops, best of 3: 184 ns per loop
2911
2926
2912 In [4]: %timeit -r 4 u == None
2927 In [4]: %timeit -r 4 u == None
2913 1000000 loops, best of 4: 242 ns per loop
2928 1000000 loops, best of 4: 242 ns per loop
2914
2929
2915 In [5]: import time
2930 In [5]: import time
2916
2931
2917 In [6]: %timeit -n1 time.sleep(2)
2932 In [6]: %timeit -n1 time.sleep(2)
2918 1 loops, best of 3: 2 s per loop
2933 1 loops, best of 3: 2 s per loop
2919
2934
2920
2935
2921 The times reported by %timeit will be slightly higher than those
2936 The times reported by %timeit will be slightly higher than those
2922 reported by the timeit.py script when variables are accessed. This is
2937 reported by the timeit.py script when variables are accessed. This is
2923 due to the fact that %timeit executes the statement in the namespace
2938 due to the fact that %timeit executes the statement in the namespace
2924 of the shell, compared with timeit.py, which uses a single setup
2939 of the shell, compared with timeit.py, which uses a single setup
2925 statement to import function or create variables. Generally, the bias
2940 statement to import function or create variables. Generally, the bias
2926 does not matter as long as results from timeit.py are not mixed with
2941 does not matter as long as results from timeit.py are not mixed with
2927 those from %timeit.
2942 those from %timeit.
2928
2943
2929 **%unalias**::
2944 **%unalias**::
2930
2945
2931 Remove an alias
2946 Remove an alias
2932
2947
2933 **%upgrade**::
2948 **%upgrade**::
2934
2949
2935 Upgrade your IPython installation
2950 Upgrade your IPython installation
2936
2951
2937 This will copy the config files that don't yet exist in your
2952 This will copy the config files that don't yet exist in your
2938 ipython dir from the system config dir. Use this after upgrading
2953 ipython dir from the system config dir. Use this after upgrading
2939 IPython if you don't wish to delete your .ipython dir.
2954 IPython if you don't wish to delete your .ipython dir.
2940
2955
2941 Call with -nolegacy to get rid of ipythonrc* files (recommended for
2956 Call with -nolegacy to get rid of ipythonrc* files (recommended for
2942 new users)
2957 new users)
2943
2958
2944 **%which**::
2959 **%which**::
2945
2960
2946 %which <cmd> => search PATH for files matching cmd. Also scans aliases.
2961 %which <cmd> => search PATH for files matching cmd. Also scans aliases.
2947
2962
2948 Traverses PATH and prints all files (not just executables!) that match the
2963 Traverses PATH and prints all files (not just executables!) that match the
2949 pattern on command line. Probably more useful in finding stuff
2964 pattern on command line. Probably more useful in finding stuff
2950 interactively than 'which', which only prints the first matching item.
2965 interactively than 'which', which only prints the first matching item.
2951
2966
2952 Also discovers and expands aliases, so you'll see what will be executed
2967 Also discovers and expands aliases, so you'll see what will be executed
2953 when you call an alias.
2968 when you call an alias.
2954
2969
2955 Example:
2970 Example:
2956
2971
2957 [~]|62> %which d
2972 [~]|62> %which d
2958 d -> ls -F --color=auto
2973 d -> ls -F --color=auto
2959 == c:\cygwin\bin\ls.exe
2974 == c:\cygwin\bin\ls.exe
2960 c:\cygwin\bin\d.exe
2975 c:\cygwin\bin\d.exe
2961
2976
2962 [~]|64> %which diff*
2977 [~]|64> %which diff*
2963 diff3 -> diff3
2978 diff3 -> diff3
2964 == c:\cygwin\bin\diff3.exe
2979 == c:\cygwin\bin\diff3.exe
2965 diff -> diff
2980 diff -> diff
2966 == c:\cygwin\bin\diff.exe
2981 == c:\cygwin\bin\diff.exe
2967 c:\cygwin\bin\diff.exe
2982 c:\cygwin\bin\diff.exe
2968 c:\cygwin\bin\diff3.exe
2983 c:\cygwin\bin\diff3.exe
2969
2984
2970 **%who**::
2985 **%who**::
2971
2986
2972 Print all interactive variables, with some minimal formatting.
2987 Print all interactive variables, with some minimal formatting.
2973
2988
2974 If any arguments are given, only variables whose type matches one of
2989 If any arguments are given, only variables whose type matches one of
2975 these are printed. For example:
2990 these are printed. For example:
2976
2991
2977 %who function str
2992 %who function str
2978
2993
2979 will only list functions and strings, excluding all other types of
2994 will only list functions and strings, excluding all other types of
2980 variables. To find the proper type names, simply use type(var) at a
2995 variables. To find the proper type names, simply use type(var) at a
2981 command line to see how python prints type names. For example:
2996 command line to see how python prints type names. For example:
2982
2997
2983 In [1]: type('hello')\
2998 In [1]: type('hello')\
2984 Out[1]: <type 'str'>
2999 Out[1]: <type 'str'>
2985
3000
2986 indicates that the type name for strings is 'str'.
3001 indicates that the type name for strings is 'str'.
2987
3002
2988 %who always excludes executed names loaded through your configuration
3003 %who always excludes executed names loaded through your configuration
2989 file and things which are internal to IPython.
3004 file and things which are internal to IPython.
2990
3005
2991 This is deliberate, as typically you may load many modules and the
3006 This is deliberate, as typically you may load many modules and the
2992 purpose of %who is to show you only what you've manually defined.
3007 purpose of %who is to show you only what you've manually defined.
2993
3008
2994 **%who_ls**::
3009 **%who_ls**::
2995
3010
2996 Return a sorted list of all interactive variables.
3011 Return a sorted list of all interactive variables.
2997
3012
2998 If arguments are given, only variables of types matching these
3013 If arguments are given, only variables of types matching these
2999 arguments are returned.
3014 arguments are returned.
3000
3015
3001 **%whos**::
3016 **%whos**::
3002
3017
3003 Like %who, but gives some extra information about each variable.
3018 Like %who, but gives some extra information about each variable.
3004
3019
3005 The same type filtering of %who can be applied here.
3020 The same type filtering of %who can be applied here.
3006
3021
3007 For all variables, the type is printed. Additionally it prints:
3022 For all variables, the type is printed. Additionally it prints:
3008
3023
3009 - For {},[],(): their length.
3024 - For {},[],(): their length.
3010
3025
3011 - For numpy and Numeric arrays, a summary with shape, number of
3026 - For numpy and Numeric arrays, a summary with shape, number of
3012 elements, typecode and size in memory.
3027 elements, typecode and size in memory.
3013
3028
3014 - Everything else: a string representation, snipping their middle if
3029 - Everything else: a string representation, snipping their middle if
3015 too long.
3030 too long.
3016
3031
3017 **%xmode**::
3032 **%xmode**::
3018
3033
3019 Switch modes for the exception handlers.
3034 Switch modes for the exception handlers.
3020
3035
3021 Valid modes: Plain, Context and Verbose.
3036 Valid modes: Plain, Context and Verbose.
3022
3037
3023 If called without arguments, acts as a toggle.
3038 If called without arguments, acts as a toggle.
3024
3039
3025 .. magic_end
3040 .. magic_end
3026
3041
3027 Access to the standard Python help
3042 Access to the standard Python help
3028 ----------------------------------
3043 ----------------------------------
3029
3044
3030 As of Python 2.1, a help system is available with access to object
3045 As of Python 2.1, a help system is available with access to object
3031 docstrings and the Python manuals. Simply type 'help' (no quotes) to
3046 docstrings and the Python manuals. Simply type 'help' (no quotes) to
3032 access it. You can also type help(object) to obtain information about a
3047 access it. You can also type help(object) to obtain information about a
3033 given object, and help('keyword') for information on a keyword. As noted
3048 given object, and help('keyword') for information on a keyword. As noted
3034 in sec. `accessing help`_, you need to properly configure
3049 in sec. `accessing help`_, you need to properly configure
3035 your environment variable PYTHONDOCS for this feature to work correctly.
3050 your environment variable PYTHONDOCS for this feature to work correctly.
3036
3051
3037
3052
3038 Dynamic object information
3053 Dynamic object information
3039 --------------------------
3054 --------------------------
3040
3055
3041 Typing ?word or word? prints detailed information about an object. If
3056 Typing ?word or word? prints detailed information about an object. If
3042 certain strings in the object are too long (docstrings, code, etc.) they
3057 certain strings in the object are too long (docstrings, code, etc.) they
3043 get snipped in the center for brevity. This system gives access variable
3058 get snipped in the center for brevity. This system gives access variable
3044 types and values, full source code for any object (if available),
3059 types and values, full source code for any object (if available),
3045 function prototypes and other useful information.
3060 function prototypes and other useful information.
3046
3061
3047 Typing ??word or word?? gives access to the full information without
3062 Typing ??word or word?? gives access to the full information without
3048 snipping long strings. Long strings are sent to the screen through the
3063 snipping long strings. Long strings are sent to the screen through the
3049 less pager if longer than the screen and printed otherwise. On systems
3064 less pager if longer than the screen and printed otherwise. On systems
3050 lacking the less command, IPython uses a very basic internal pager.
3065 lacking the less command, IPython uses a very basic internal pager.
3051
3066
3052 The following magic functions are particularly useful for gathering
3067 The following magic functions are particularly useful for gathering
3053 information about your working environment. You can get more details by
3068 information about your working environment. You can get more details by
3054 typing %magic or querying them individually (use %function_name? with or
3069 typing %magic or querying them individually (use %function_name? with or
3055 without the %), this is just a summary:
3070 without the %), this is just a summary:
3056
3071
3057 * **%pdoc <object>**: Print (or run through a pager if too long) the
3072 * **%pdoc <object>**: Print (or run through a pager if too long) the
3058 docstring for an object. If the given object is a class, it will
3073 docstring for an object. If the given object is a class, it will
3059 print both the class and the constructor docstrings.
3074 print both the class and the constructor docstrings.
3060 * **%pdef <object>**: Print the definition header for any callable
3075 * **%pdef <object>**: Print the definition header for any callable
3061 object. If the object is a class, print the constructor information.
3076 object. If the object is a class, print the constructor information.
3062 * **%psource <object>**: Print (or run through a pager if too long)
3077 * **%psource <object>**: Print (or run through a pager if too long)
3063 the source code for an object.
3078 the source code for an object.
3064 * **%pfile <object>**: Show the entire source file where an object was
3079 * **%pfile <object>**: Show the entire source file where an object was
3065 defined via a pager, opening it at the line where the object
3080 defined via a pager, opening it at the line where the object
3066 definition begins.
3081 definition begins.
3067 * **%who/%whos**: These functions give information about identifiers
3082 * **%who/%whos**: These functions give information about identifiers
3068 you have defined interactively (not things you loaded or defined
3083 you have defined interactively (not things you loaded or defined
3069 in your configuration files). %who just prints a list of
3084 in your configuration files). %who just prints a list of
3070 identifiers and %whos prints a table with some basic details about
3085 identifiers and %whos prints a table with some basic details about
3071 each identifier.
3086 each identifier.
3072
3087
3073 Note that the dynamic object information functions (?/??, %pdoc, %pfile,
3088 Note that the dynamic object information functions (?/??, %pdoc, %pfile,
3074 %pdef, %psource) give you access to documentation even on things which
3089 %pdef, %psource) give you access to documentation even on things which
3075 are not really defined as separate identifiers. Try for example typing
3090 are not really defined as separate identifiers. Try for example typing
3076 {}.get? or after doing import os, type os.path.abspath??.
3091 {}.get? or after doing import os, type os.path.abspath??.
3077
3092
3078
3093
3079 .. _Readline:
3094 .. _Readline:
3080
3095
3081 Readline-based features
3096 Readline-based features
3082 -----------------------
3097 -----------------------
3083
3098
3084 These features require the GNU readline library, so they won't work if
3099 These features require the GNU readline library, so they won't work if
3085 your Python installation lacks readline support. We will first describe
3100 your Python installation lacks readline support. We will first describe
3086 the default behavior IPython uses, and then how to change it to suit
3101 the default behavior IPython uses, and then how to change it to suit
3087 your preferences.
3102 your preferences.
3088
3103
3089
3104
3090 Command line completion
3105 Command line completion
3091 +++++++++++++++++++++++
3106 +++++++++++++++++++++++
3092
3107
3093 At any time, hitting TAB will complete any available python commands or
3108 At any time, hitting TAB will complete any available python commands or
3094 variable names, and show you a list of the possible completions if
3109 variable names, and show you a list of the possible completions if
3095 there's no unambiguous one. It will also complete filenames in the
3110 there's no unambiguous one. It will also complete filenames in the
3096 current directory if no python names match what you've typed so far.
3111 current directory if no python names match what you've typed so far.
3097
3112
3098
3113
3099 Search command history
3114 Search command history
3100 ++++++++++++++++++++++
3115 ++++++++++++++++++++++
3101
3116
3102 IPython provides two ways for searching through previous input and thus
3117 IPython provides two ways for searching through previous input and thus
3103 reduce the need for repetitive typing:
3118 reduce the need for repetitive typing:
3104
3119
3105 1. Start typing, and then use Ctrl-p (previous,up) and Ctrl-n
3120 1. Start typing, and then use Ctrl-p (previous,up) and Ctrl-n
3106 (next,down) to search through only the history items that match
3121 (next,down) to search through only the history items that match
3107 what you've typed so far. If you use Ctrl-p/Ctrl-n at a blank
3122 what you've typed so far. If you use Ctrl-p/Ctrl-n at a blank
3108 prompt, they just behave like normal arrow keys.
3123 prompt, they just behave like normal arrow keys.
3109 2. Hit Ctrl-r: opens a search prompt. Begin typing and the system
3124 2. Hit Ctrl-r: opens a search prompt. Begin typing and the system
3110 searches your history for lines that contain what you've typed so
3125 searches your history for lines that contain what you've typed so
3111 far, completing as much as it can.
3126 far, completing as much as it can.
3112
3127
3113
3128
3114 Persistent command history across sessions
3129 Persistent command history across sessions
3115 ++++++++++++++++++++++++++++++++++++++++++
3130 ++++++++++++++++++++++++++++++++++++++++++
3116
3131
3117 IPython will save your input history when it leaves and reload it next
3132 IPython will save your input history when it leaves and reload it next
3118 time you restart it. By default, the history file is named
3133 time you restart it. By default, the history file is named
3119 $IPYTHONDIR/history, but if you've loaded a named profile,
3134 $IPYTHONDIR/history, but if you've loaded a named profile,
3120 '-PROFILE_NAME' is appended to the name. This allows you to keep
3135 '-PROFILE_NAME' is appended to the name. This allows you to keep
3121 separate histories related to various tasks: commands related to
3136 separate histories related to various tasks: commands related to
3122 numerical work will not be clobbered by a system shell history, for
3137 numerical work will not be clobbered by a system shell history, for
3123 example.
3138 example.
3124
3139
3125
3140
3126 Autoindent
3141 Autoindent
3127 ++++++++++
3142 ++++++++++
3128
3143
3129 IPython can recognize lines ending in ':' and indent the next line,
3144 IPython can recognize lines ending in ':' and indent the next line,
3130 while also un-indenting automatically after 'raise' or 'return'.
3145 while also un-indenting automatically after 'raise' or 'return'.
3131
3146
3132 This feature uses the readline library, so it will honor your ~/.inputrc
3147 This feature uses the readline library, so it will honor your ~/.inputrc
3133 configuration (or whatever file your INPUTRC variable points to). Adding
3148 configuration (or whatever file your INPUTRC variable points to). Adding
3134 the following lines to your .inputrc file can make indenting/unindenting
3149 the following lines to your .inputrc file can make indenting/unindenting
3135 more convenient (M-i indents, M-u unindents)::
3150 more convenient (M-i indents, M-u unindents)::
3136
3151
3137 $if Python
3152 $if Python
3138 "\M-i": " "
3153 "\M-i": " "
3139 "\M-u": "\d\d\d\d"
3154 "\M-u": "\d\d\d\d"
3140 $endif
3155 $endif
3141
3156
3142 Note that there are 4 spaces between the quote marks after "M-i" above.
3157 Note that there are 4 spaces between the quote marks after "M-i" above.
3143
3158
3144 Warning: this feature is ON by default, but it can cause problems with
3159 Warning: this feature is ON by default, but it can cause problems with
3145 the pasting of multi-line indented code (the pasted code gets
3160 the pasting of multi-line indented code (the pasted code gets
3146 re-indented on each line). A magic function %autoindent allows you to
3161 re-indented on each line). A magic function %autoindent allows you to
3147 toggle it on/off at runtime. You can also disable it permanently on in
3162 toggle it on/off at runtime. You can also disable it permanently on in
3148 your ipythonrc file (set autoindent 0).
3163 your ipythonrc file (set autoindent 0).
3149
3164
3150
3165
3151 Customizing readline behavior
3166 Customizing readline behavior
3152 +++++++++++++++++++++++++++++
3167 +++++++++++++++++++++++++++++
3153
3168
3154 All these features are based on the GNU readline library, which has an
3169 All these features are based on the GNU readline library, which has an
3155 extremely customizable interface. Normally, readline is configured via a
3170 extremely customizable interface. Normally, readline is configured via a
3156 file which defines the behavior of the library; the details of the
3171 file which defines the behavior of the library; the details of the
3157 syntax for this can be found in the readline documentation available
3172 syntax for this can be found in the readline documentation available
3158 with your system or on the Internet. IPython doesn't read this file (if
3173 with your system or on the Internet. IPython doesn't read this file (if
3159 it exists) directly, but it does support passing to readline valid
3174 it exists) directly, but it does support passing to readline valid
3160 options via a simple interface. In brief, you can customize readline by
3175 options via a simple interface. In brief, you can customize readline by
3161 setting the following options in your ipythonrc configuration file (note
3176 setting the following options in your ipythonrc configuration file (note
3162 that these options can not be specified at the command line):
3177 that these options can not be specified at the command line):
3163
3178
3164 * **readline_parse_and_bind**: this option can appear as many times as
3179 * **readline_parse_and_bind**: this option can appear as many times as
3165 you want, each time defining a string to be executed via a
3180 you want, each time defining a string to be executed via a
3166 readline.parse_and_bind() command. The syntax for valid commands
3181 readline.parse_and_bind() command. The syntax for valid commands
3167 of this kind can be found by reading the documentation for the GNU
3182 of this kind can be found by reading the documentation for the GNU
3168 readline library, as these commands are of the kind which readline
3183 readline library, as these commands are of the kind which readline
3169 accepts in its configuration file.
3184 accepts in its configuration file.
3170 * **readline_remove_delims**: a string of characters to be removed
3185 * **readline_remove_delims**: a string of characters to be removed
3171 from the default word-delimiters list used by readline, so that
3186 from the default word-delimiters list used by readline, so that
3172 completions may be performed on strings which contain them. Do not
3187 completions may be performed on strings which contain them. Do not
3173 change the default value unless you know what you're doing.
3188 change the default value unless you know what you're doing.
3174 * **readline_omit__names**: when tab-completion is enabled, hitting
3189 * **readline_omit__names**: when tab-completion is enabled, hitting
3175 <tab> after a '.' in a name will complete all attributes of an
3190 <tab> after a '.' in a name will complete all attributes of an
3176 object, including all the special methods whose names include
3191 object, including all the special methods whose names include
3177 double underscores (like __getitem__ or __class__). If you'd
3192 double underscores (like __getitem__ or __class__). If you'd
3178 rather not see these names by default, you can set this option to
3193 rather not see these names by default, you can set this option to
3179 1. Note that even when this option is set, you can still see those
3194 1. Note that even when this option is set, you can still see those
3180 names by explicitly typing a _ after the period and hitting <tab>:
3195 names by explicitly typing a _ after the period and hitting <tab>:
3181 'name._<tab>' will always complete attribute names starting with '_'.
3196 'name._<tab>' will always complete attribute names starting with '_'.
3182
3197
3183 This option is off by default so that new users see all
3198 This option is off by default so that new users see all
3184 attributes of any objects they are dealing with.
3199 attributes of any objects they are dealing with.
3185
3200
3186 You will find the default values along with a corresponding detailed
3201 You will find the default values along with a corresponding detailed
3187 explanation in your ipythonrc file.
3202 explanation in your ipythonrc file.
3188
3203
3189
3204
3190 Session logging and restoring
3205 Session logging and restoring
3191 -----------------------------
3206 -----------------------------
3192
3207
3193 You can log all input from a session either by starting IPython with
3208 You can log all input from a session either by starting IPython with
3194 the command line switches -log or -logfile (see sec. `command line
3209 the command line switches -log or -logfile (see sec. `command line
3195 options`_) or by activating the logging at any moment with the magic
3210 options`_) or by activating the logging at any moment with the magic
3196 function %logstart.
3211 function %logstart.
3197
3212
3198 Log files can later be reloaded with the -logplay option and IPython
3213 Log files can later be reloaded with the -logplay option and IPython
3199 will attempt to 'replay' the log by executing all the lines in it, thus
3214 will attempt to 'replay' the log by executing all the lines in it, thus
3200 restoring the state of a previous session. This feature is not quite
3215 restoring the state of a previous session. This feature is not quite
3201 perfect, but can still be useful in many cases.
3216 perfect, but can still be useful in many cases.
3202
3217
3203 The log files can also be used as a way to have a permanent record of
3218 The log files can also be used as a way to have a permanent record of
3204 any code you wrote while experimenting. Log files are regular text files
3219 any code you wrote while experimenting. Log files are regular text files
3205 which you can later open in your favorite text editor to extract code or
3220 which you can later open in your favorite text editor to extract code or
3206 to 'clean them up' before using them to replay a session.
3221 to 'clean them up' before using them to replay a session.
3207
3222
3208 The %logstart function for activating logging in mid-session is used as
3223 The %logstart function for activating logging in mid-session is used as
3209 follows:
3224 follows:
3210
3225
3211 %logstart [log_name [log_mode]]
3226 %logstart [log_name [log_mode]]
3212
3227
3213 If no name is given, it defaults to a file named 'log' in your
3228 If no name is given, it defaults to a file named 'log' in your
3214 IPYTHONDIR directory, in 'rotate' mode (see below).
3229 IPYTHONDIR directory, in 'rotate' mode (see below).
3215
3230
3216 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
3231 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
3217 history up to that point and then continues logging.
3232 history up to that point and then continues logging.
3218
3233
3219 %logstart takes a second optional parameter: logging mode. This can be
3234 %logstart takes a second optional parameter: logging mode. This can be
3220 one of (note that the modes are given unquoted):
3235 one of (note that the modes are given unquoted):
3221
3236
3222 * [over:] overwrite existing log_name.
3237 * [over:] overwrite existing log_name.
3223 * [backup:] rename (if exists) to log_name~ and start log_name.
3238 * [backup:] rename (if exists) to log_name~ and start log_name.
3224 * [append:] well, that says it.
3239 * [append:] well, that says it.
3225 * [rotate:] create rotating logs log_name.1~, log_name.2~, etc.
3240 * [rotate:] create rotating logs log_name.1~, log_name.2~, etc.
3226
3241
3227 The %logoff and %logon functions allow you to temporarily stop and
3242 The %logoff and %logon functions allow you to temporarily stop and
3228 resume logging to a file which had previously been started with
3243 resume logging to a file which had previously been started with
3229 %logstart. They will fail (with an explanation) if you try to use them
3244 %logstart. They will fail (with an explanation) if you try to use them
3230 before logging has been started.
3245 before logging has been started.
3231
3246
3232 System shell access
3247 System shell access
3233 -------------------
3248 -------------------
3234
3249
3235 Any input line beginning with a ! character is passed verbatim (minus
3250 Any input line beginning with a ! character is passed verbatim (minus
3236 the !, of course) to the underlying operating system. For example,
3251 the !, of course) to the underlying operating system. For example,
3237 typing !ls will run 'ls' in the current directory.
3252 typing !ls will run 'ls' in the current directory.
3238
3253
3239 Manual capture of command output
3254 Manual capture of command output
3240 --------------------------------
3255 --------------------------------
3241
3256
3242 If the input line begins with two exclamation marks, !!, the command is
3257 If the input line begins with two exclamation marks, !!, the command is
3243 executed but its output is captured and returned as a python list, split
3258 executed but its output is captured and returned as a python list, split
3244 on newlines. Any output sent by the subprocess to standard error is
3259 on newlines. Any output sent by the subprocess to standard error is
3245 printed separately, so that the resulting list only captures standard
3260 printed separately, so that the resulting list only captures standard
3246 output. The !! syntax is a shorthand for the %sx magic command.
3261 output. The !! syntax is a shorthand for the %sx magic command.
3247
3262
3248 Finally, the %sc magic (short for 'shell capture') is similar to %sx,
3263 Finally, the %sc magic (short for 'shell capture') is similar to %sx,
3249 but allowing more fine-grained control of the capture details, and
3264 but allowing more fine-grained control of the capture details, and
3250 storing the result directly into a named variable. The direct use of
3265 storing the result directly into a named variable. The direct use of
3251 %sc is now deprecated, and you should ise the ``var = !cmd`` syntax
3266 %sc is now deprecated, and you should ise the ``var = !cmd`` syntax
3252 instead.
3267 instead.
3253
3268
3254 IPython also allows you to expand the value of python variables when
3269 IPython also allows you to expand the value of python variables when
3255 making system calls. Any python variable or expression which you prepend
3270 making system calls. Any python variable or expression which you prepend
3256 with $ will get expanded before the system call is made::
3271 with $ will get expanded before the system call is made::
3257
3272
3258 In [1]: pyvar='Hello world'
3273 In [1]: pyvar='Hello world'
3259 In [2]: !echo "A python variable: $pyvar"
3274 In [2]: !echo "A python variable: $pyvar"
3260 A python variable: Hello world
3275 A python variable: Hello world
3261
3276
3262 If you want the shell to actually see a literal $, you need to type it
3277 If you want the shell to actually see a literal $, you need to type it
3263 twice::
3278 twice::
3264
3279
3265 In [3]: !echo "A system variable: $$HOME"
3280 In [3]: !echo "A system variable: $$HOME"
3266 A system variable: /home/fperez
3281 A system variable: /home/fperez
3267
3282
3268 You can pass arbitrary expressions, though you'll need to delimit them
3283 You can pass arbitrary expressions, though you'll need to delimit them
3269 with {} if there is ambiguity as to the extent of the expression::
3284 with {} if there is ambiguity as to the extent of the expression::
3270
3285
3271 In [5]: x=10
3286 In [5]: x=10
3272 In [6]: y=20
3287 In [6]: y=20
3273 In [13]: !echo $x+y
3288 In [13]: !echo $x+y
3274 10+y
3289 10+y
3275 In [7]: !echo ${x+y}
3290 In [7]: !echo ${x+y}
3276 30
3291 30
3277
3292
3278 Even object attributes can be expanded::
3293 Even object attributes can be expanded::
3279
3294
3280 In [12]: !echo $sys.argv
3295 In [12]: !echo $sys.argv
3281 [/home/fperez/usr/bin/ipython]
3296 [/home/fperez/usr/bin/ipython]
3282
3297
3283
3298
3284 System command aliases
3299 System command aliases
3285 ----------------------
3300 ----------------------
3286
3301
3287 The %alias magic function and the alias option in the ipythonrc
3302 The %alias magic function and the alias option in the ipythonrc
3288 configuration file allow you to define magic functions which are in fact
3303 configuration file allow you to define magic functions which are in fact
3289 system shell commands. These aliases can have parameters.
3304 system shell commands. These aliases can have parameters.
3290
3305
3291 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
3306 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
3292
3307
3293 Then, typing '%alias_name params' will execute the system command 'cmd
3308 Then, typing '%alias_name params' will execute the system command 'cmd
3294 params' (from your underlying operating system).
3309 params' (from your underlying operating system).
3295
3310
3296 You can also define aliases with parameters using %s specifiers (one per
3311 You can also define aliases with parameters using %s specifiers (one per
3297 parameter). The following example defines the %parts function as an
3312 parameter). The following example defines the %parts function as an
3298 alias to the command 'echo first %s second %s' where each %s will be
3313 alias to the command 'echo first %s second %s' where each %s will be
3299 replaced by a positional parameter to the call to %parts::
3314 replaced by a positional parameter to the call to %parts::
3300
3315
3301 In [1]: alias parts echo first %s second %s
3316 In [1]: alias parts echo first %s second %s
3302 In [2]: %parts A B
3317 In [2]: %parts A B
3303 first A second B
3318 first A second B
3304 In [3]: %parts A
3319 In [3]: %parts A
3305 Incorrect number of arguments: 2 expected.
3320 Incorrect number of arguments: 2 expected.
3306 parts is an alias to: 'echo first %s second %s'
3321 parts is an alias to: 'echo first %s second %s'
3307
3322
3308 If called with no parameters, %alias prints the table of currently
3323 If called with no parameters, %alias prints the table of currently
3309 defined aliases.
3324 defined aliases.
3310
3325
3311 The %rehash/rehashx magics allow you to load your entire $PATH as
3326 The %rehash/rehashx magics allow you to load your entire $PATH as
3312 ipython aliases. See their respective docstrings (or sec. 6.2
3327 ipython aliases. See their respective docstrings (or sec. 6.2
3313 <#sec:magic> for further details).
3328 <#sec:magic> for further details).
3314
3329
3315
3330
3316 .. _dreload:
3331 .. _dreload:
3317
3332
3318 Recursive reload
3333 Recursive reload
3319 ----------------
3334 ----------------
3320
3335
3321 The dreload function does a recursive reload of a module: changes made
3336 The dreload function does a recursive reload of a module: changes made
3322 to the module since you imported will actually be available without
3337 to the module since you imported will actually be available without
3323 having to exit.
3338 having to exit.
3324
3339
3325
3340
3326 Verbose and colored exception traceback printouts
3341 Verbose and colored exception traceback printouts
3327 -------------------------------------------------
3342 -------------------------------------------------
3328
3343
3329 IPython provides the option to see very detailed exception tracebacks,
3344 IPython provides the option to see very detailed exception tracebacks,
3330 which can be especially useful when debugging large programs. You can
3345 which can be especially useful when debugging large programs. You can
3331 run any Python file with the %run function to benefit from these
3346 run any Python file with the %run function to benefit from these
3332 detailed tracebacks. Furthermore, both normal and verbose tracebacks can
3347 detailed tracebacks. Furthermore, both normal and verbose tracebacks can
3333 be colored (if your terminal supports it) which makes them much easier
3348 be colored (if your terminal supports it) which makes them much easier
3334 to parse visually.
3349 to parse visually.
3335
3350
3336 See the magic xmode and colors functions for details (just type %magic).
3351 See the magic xmode and colors functions for details (just type %magic).
3337
3352
3338 These features are basically a terminal version of Ka-Ping Yee's cgitb
3353 These features are basically a terminal version of Ka-Ping Yee's cgitb
3339 module, now part of the standard Python library.
3354 module, now part of the standard Python library.
3340
3355
3341
3356
3342 .. _Input caching:
3357 .. _Input caching:
3343
3358
3344 Input caching system
3359 Input caching system
3345 --------------------
3360 --------------------
3346
3361
3347 IPython offers numbered prompts (In/Out) with input and output caching.
3362 IPython offers numbered prompts (In/Out) with input and output caching.
3348 All input is saved and can be retrieved as variables (besides the usual
3363 All input is saved and can be retrieved as variables (besides the usual
3349 arrow key recall).
3364 arrow key recall).
3350
3365
3351 The following GLOBAL variables always exist (so don't overwrite them!):
3366 The following GLOBAL variables always exist (so don't overwrite them!):
3352 _i: stores previous input. _ii: next previous. _iii: next-next previous.
3367 _i: stores previous input. _ii: next previous. _iii: next-next previous.
3353 _ih : a list of all input _ih[n] is the input from line n and this list
3368 _ih : a list of all input _ih[n] is the input from line n and this list
3354 is aliased to the global variable In. If you overwrite In with a
3369 is aliased to the global variable In. If you overwrite In with a
3355 variable of your own, you can remake the assignment to the internal list
3370 variable of your own, you can remake the assignment to the internal list
3356 with a simple 'In=_ih'.
3371 with a simple 'In=_ih'.
3357
3372
3358 Additionally, global variables named _i<n> are dynamically created (<n>
3373 Additionally, global variables named _i<n> are dynamically created (<n>
3359 being the prompt counter), such that
3374 being the prompt counter), such that
3360 _i<n> == _ih[<n>] == In[<n>].
3375 _i<n> == _ih[<n>] == In[<n>].
3361
3376
3362 For example, what you typed at prompt 14 is available as _i14, _ih[14]
3377 For example, what you typed at prompt 14 is available as _i14, _ih[14]
3363 and In[14].
3378 and In[14].
3364
3379
3365 This allows you to easily cut and paste multi line interactive prompts
3380 This allows you to easily cut and paste multi line interactive prompts
3366 by printing them out: they print like a clean string, without prompt
3381 by printing them out: they print like a clean string, without prompt
3367 characters. You can also manipulate them like regular variables (they
3382 characters. You can also manipulate them like regular variables (they
3368 are strings), modify or exec them (typing 'exec _i9' will re-execute the
3383 are strings), modify or exec them (typing 'exec _i9' will re-execute the
3369 contents of input prompt 9, 'exec In[9:14]+In[18]' will re-execute lines
3384 contents of input prompt 9, 'exec In[9:14]+In[18]' will re-execute lines
3370 9 through 13 and line 18).
3385 9 through 13 and line 18).
3371
3386
3372 You can also re-execute multiple lines of input easily by using the
3387 You can also re-execute multiple lines of input easily by using the
3373 magic %macro function (which automates the process and allows
3388 magic %macro function (which automates the process and allows
3374 re-execution without having to type 'exec' every time). The macro system
3389 re-execution without having to type 'exec' every time). The macro system
3375 also allows you to re-execute previous lines which include magic
3390 also allows you to re-execute previous lines which include magic
3376 function calls (which require special processing). Type %macro? or see
3391 function calls (which require special processing). Type %macro? or see
3377 sec. 6.2 <#sec:magic> for more details on the macro system.
3392 sec. 6.2 <#sec:magic> for more details on the macro system.
3378
3393
3379 A history function %hist allows you to see any part of your input
3394 A history function %hist allows you to see any part of your input
3380 history by printing a range of the _i variables.
3395 history by printing a range of the _i variables.
3381
3396
3382 .. _Output caching:
3397 .. _Output caching:
3383
3398
3384 Output caching system
3399 Output caching system
3385 ---------------------
3400 ---------------------
3386
3401
3387 For output that is returned from actions, a system similar to the input
3402 For output that is returned from actions, a system similar to the input
3388 cache exists but using _ instead of _i. Only actions that produce a
3403 cache exists but using _ instead of _i. Only actions that produce a
3389 result (NOT assignments, for example) are cached. If you are familiar
3404 result (NOT assignments, for example) are cached. If you are familiar
3390 with Mathematica, IPython's _ variables behave exactly like
3405 with Mathematica, IPython's _ variables behave exactly like
3391 Mathematica's % variables.
3406 Mathematica's % variables.
3392
3407
3393 The following GLOBAL variables always exist (so don't overwrite them!):
3408 The following GLOBAL variables always exist (so don't overwrite them!):
3394
3409
3395 * [_] (a single underscore) : stores previous output, like Python's
3410 * [_] (a single underscore) : stores previous output, like Python's
3396 default interpreter.
3411 default interpreter.
3397 * [__] (two underscores): next previous.
3412 * [__] (two underscores): next previous.
3398 * [___] (three underscores): next-next previous.
3413 * [___] (three underscores): next-next previous.
3399
3414
3400 Additionally, global variables named _<n> are dynamically created (<n>
3415 Additionally, global variables named _<n> are dynamically created (<n>
3401 being the prompt counter), such that the result of output <n> is always
3416 being the prompt counter), such that the result of output <n> is always
3402 available as _<n> (don't use the angle brackets, just the number, e.g.
3417 available as _<n> (don't use the angle brackets, just the number, e.g.
3403 _21).
3418 _21).
3404
3419
3405 These global variables are all stored in a global dictionary (not a
3420 These global variables are all stored in a global dictionary (not a
3406 list, since it only has entries for lines which returned a result)
3421 list, since it only has entries for lines which returned a result)
3407 available under the names _oh and Out (similar to _ih and In). So the
3422 available under the names _oh and Out (similar to _ih and In). So the
3408 output from line 12 can be obtained as _12, Out[12] or _oh[12]. If you
3423 output from line 12 can be obtained as _12, Out[12] or _oh[12]. If you
3409 accidentally overwrite the Out variable you can recover it by typing
3424 accidentally overwrite the Out variable you can recover it by typing
3410 'Out=_oh' at the prompt.
3425 'Out=_oh' at the prompt.
3411
3426
3412 This system obviously can potentially put heavy memory demands on your
3427 This system obviously can potentially put heavy memory demands on your
3413 system, since it prevents Python's garbage collector from removing any
3428 system, since it prevents Python's garbage collector from removing any
3414 previously computed results. You can control how many results are kept
3429 previously computed results. You can control how many results are kept
3415 in memory with the option (at the command line or in your ipythonrc
3430 in memory with the option (at the command line or in your ipythonrc
3416 file) cache_size. If you set it to 0, the whole system is completely
3431 file) cache_size. If you set it to 0, the whole system is completely
3417 disabled and the prompts revert to the classic '>>>' of normal Python.
3432 disabled and the prompts revert to the classic '>>>' of normal Python.
3418
3433
3419
3434
3420 Directory history
3435 Directory history
3421 -----------------
3436 -----------------
3422
3437
3423 Your history of visited directories is kept in the global list _dh, and
3438 Your history of visited directories is kept in the global list _dh, and
3424 the magic %cd command can be used to go to any entry in that list. The
3439 the magic %cd command can be used to go to any entry in that list. The
3425 %dhist command allows you to view this history. do ``cd -<TAB`` to
3440 %dhist command allows you to view this history. do ``cd -<TAB`` to
3426 conventiently view the directory history.
3441 conventiently view the directory history.
3427
3442
3428
3443
3429 Automatic parentheses and quotes
3444 Automatic parentheses and quotes
3430 --------------------------------
3445 --------------------------------
3431
3446
3432 These features were adapted from Nathan Gray's LazyPython. They are
3447 These features were adapted from Nathan Gray's LazyPython. They are
3433 meant to allow less typing for common situations.
3448 meant to allow less typing for common situations.
3434
3449
3435
3450
3436 Automatic parentheses
3451 Automatic parentheses
3437 ---------------------
3452 ---------------------
3438
3453
3439 Callable objects (i.e. functions, methods, etc) can be invoked like this
3454 Callable objects (i.e. functions, methods, etc) can be invoked like this
3440 (notice the commas between the arguments)::
3455 (notice the commas between the arguments)::
3441
3456
3442 >>> callable_ob arg1, arg2, arg3
3457 >>> callable_ob arg1, arg2, arg3
3443
3458
3444 and the input will be translated to this::
3459 and the input will be translated to this::
3445
3460
3446 -> callable_ob(arg1, arg2, arg3)
3461 -> callable_ob(arg1, arg2, arg3)
3447
3462
3448 You can force automatic parentheses by using '/' as the first character
3463 You can force automatic parentheses by using '/' as the first character
3449 of a line. For example::
3464 of a line. For example::
3450
3465
3451 >>> /globals # becomes 'globals()'
3466 >>> /globals # becomes 'globals()'
3452
3467
3453 Note that the '/' MUST be the first character on the line! This won't work::
3468 Note that the '/' MUST be the first character on the line! This won't work::
3454
3469
3455 >>> print /globals # syntax error
3470 >>> print /globals # syntax error
3456
3471
3457 In most cases the automatic algorithm should work, so you should rarely
3472 In most cases the automatic algorithm should work, so you should rarely
3458 need to explicitly invoke /. One notable exception is if you are trying
3473 need to explicitly invoke /. One notable exception is if you are trying
3459 to call a function with a list of tuples as arguments (the parenthesis
3474 to call a function with a list of tuples as arguments (the parenthesis
3460 will confuse IPython)::
3475 will confuse IPython)::
3461
3476
3462 In [1]: zip (1,2,3),(4,5,6) # won't work
3477 In [1]: zip (1,2,3),(4,5,6) # won't work
3463
3478
3464 but this will work::
3479 but this will work::
3465
3480
3466 In [2]: /zip (1,2,3),(4,5,6)
3481 In [2]: /zip (1,2,3),(4,5,6)
3467 ---> zip ((1,2,3),(4,5,6))
3482 ---> zip ((1,2,3),(4,5,6))
3468 Out[2]= [(1, 4), (2, 5), (3, 6)]
3483 Out[2]= [(1, 4), (2, 5), (3, 6)]
3469
3484
3470 IPython tells you that it has altered your command line by displaying
3485 IPython tells you that it has altered your command line by displaying
3471 the new command line preceded by ->. e.g.::
3486 the new command line preceded by ->. e.g.::
3472
3487
3473 In [18]: callable list
3488 In [18]: callable list
3474 ----> callable (list)
3489 ----> callable (list)
3475
3490
3476
3491
3477 Automatic quoting
3492 Automatic quoting
3478 -----------------
3493 -----------------
3479
3494
3480 You can force automatic quoting of a function's arguments by using ','
3495 You can force automatic quoting of a function's arguments by using ','
3481 or ';' as the first character of a line. For example::
3496 or ';' as the first character of a line. For example::
3482
3497
3483 >>> ,my_function /home/me # becomes my_function("/home/me")
3498 >>> ,my_function /home/me # becomes my_function("/home/me")
3484
3499
3485 If you use ';' instead, the whole argument is quoted as a single string
3500 If you use ';' instead, the whole argument is quoted as a single string
3486 (while ',' splits on whitespace)::
3501 (while ',' splits on whitespace)::
3487
3502
3488 >>> ,my_function a b c # becomes my_function("a","b","c")
3503 >>> ,my_function a b c # becomes my_function("a","b","c")
3489
3504
3490 >>> ;my_function a b c # becomes my_function("a b c")
3505 >>> ;my_function a b c # becomes my_function("a b c")
3491
3506
3492 Note that the ',' or ';' MUST be the first character on the line! This
3507 Note that the ',' or ';' MUST be the first character on the line! This
3493 won't work::
3508 won't work::
3494
3509
3495 >>> x = ,my_function /home/me # syntax error
3510 >>> x = ,my_function /home/me # syntax error
3496
3511
3497 .. customization:
3512 .. customization:
3498
3513
3499 Customization
3514 Customization
3500 =============
3515 =============
3501
3516
3502 There are 2 ways to configure IPython - the old way of using ipythonrc
3517 There are 2 ways to configure IPython - the old way of using ipythonrc
3503 files (an INI-file like format), and the new way that involves editing
3518 files (an INI-file like format), and the new way that involves editing
3504 your ipy_user_conf.py. Both configuration systems work at the same
3519 your ipy_user_conf.py. Both configuration systems work at the same
3505 time, so you can set your options in both, but if you are hesitating
3520 time, so you can set your options in both, but if you are hesitating
3506 about which alternative to choose, we recommend the ipy_user_conf.py
3521 about which alternative to choose, we recommend the ipy_user_conf.py
3507 approach, as it will give you more power and control in the long
3522 approach, as it will give you more power and control in the long
3508 run. However, there are few options such as pylab_import_all that can
3523 run. However, there are few options such as pylab_import_all that can
3509 only be specified in ipythonrc file or command line - the reason for
3524 only be specified in ipythonrc file or command line - the reason for
3510 this is that they are needed before IPython has been started up, and
3525 this is that they are needed before IPython has been started up, and
3511 the IPApi object used in ipy_user_conf.py is not yet available at that
3526 the IPApi object used in ipy_user_conf.py is not yet available at that
3512 time. A hybrid approach of specifying a few options in ipythonrc and
3527 time. A hybrid approach of specifying a few options in ipythonrc and
3513 doing the more advanced configuration in ipy_user_conf.py is also
3528 doing the more advanced configuration in ipy_user_conf.py is also
3514 possible.
3529 possible.
3515
3530
3516 The ipythonrc approach
3531 The ipythonrc approach
3517 ----------------------
3532 ----------------------
3518
3533
3519 As we've already mentioned, IPython reads a configuration file which can
3534 As we've already mentioned, IPython reads a configuration file which can
3520 be specified at the command line (-rcfile) or which by default is
3535 be specified at the command line (-rcfile) or which by default is
3521 assumed to be called ipythonrc. Such a file is looked for in the current
3536 assumed to be called ipythonrc. Such a file is looked for in the current
3522 directory where IPython is started and then in your IPYTHONDIR, which
3537 directory where IPython is started and then in your IPYTHONDIR, which
3523 allows you to have local configuration files for specific projects. In
3538 allows you to have local configuration files for specific projects. In
3524 this section we will call these types of configuration files simply
3539 this section we will call these types of configuration files simply
3525 rcfiles (short for resource configuration file).
3540 rcfiles (short for resource configuration file).
3526
3541
3527 The syntax of an rcfile is one of key-value pairs separated by
3542 The syntax of an rcfile is one of key-value pairs separated by
3528 whitespace, one per line. Lines beginning with a # are ignored as
3543 whitespace, one per line. Lines beginning with a # are ignored as
3529 comments, but comments can not be put on lines with data (the parser is
3544 comments, but comments can not be put on lines with data (the parser is
3530 fairly primitive). Note that these are not python files, and this is
3545 fairly primitive). Note that these are not python files, and this is
3531 deliberate, because it allows us to do some things which would be quite
3546 deliberate, because it allows us to do some things which would be quite
3532 tricky to implement if they were normal python files.
3547 tricky to implement if they were normal python files.
3533
3548
3534 First, an rcfile can contain permanent default values for almost all
3549 First, an rcfile can contain permanent default values for almost all
3535 command line options (except things like -help or -Version). Sec
3550 command line options (except things like -help or -Version). Sec
3536 `command line options`_ contains a description of all command-line
3551 `command line options`_ contains a description of all command-line
3537 options. However, values you explicitly specify at the command line
3552 options. However, values you explicitly specify at the command line
3538 override the values defined in the rcfile.
3553 override the values defined in the rcfile.
3539
3554
3540 Besides command line option values, the rcfile can specify values for
3555 Besides command line option values, the rcfile can specify values for
3541 certain extra special options which are not available at the command
3556 certain extra special options which are not available at the command
3542 line. These options are briefly described below.
3557 line. These options are briefly described below.
3543
3558
3544 Each of these options may appear as many times as you need it in the file.
3559 Each of these options may appear as many times as you need it in the file.
3545
3560
3546 * include <file1> <file2> ...: you can name other rcfiles you want
3561 * include <file1> <file2> ...: you can name other rcfiles you want
3547 to recursively load up to 15 levels (don't use the <> brackets in
3562 to recursively load up to 15 levels (don't use the <> brackets in
3548 your names!). This feature allows you to define a 'base' rcfile
3563 your names!). This feature allows you to define a 'base' rcfile
3549 with general options and special-purpose files which can be loaded
3564 with general options and special-purpose files which can be loaded
3550 only when needed with particular configuration options. To make
3565 only when needed with particular configuration options. To make
3551 this more convenient, IPython accepts the -profile <name> option
3566 this more convenient, IPython accepts the -profile <name> option
3552 (abbreviates to -p <name>) which tells it to look for an rcfile
3567 (abbreviates to -p <name>) which tells it to look for an rcfile
3553 named ipythonrc-<name>.
3568 named ipythonrc-<name>.
3554 * import_mod <mod1> <mod2> ...: import modules with 'import
3569 * import_mod <mod1> <mod2> ...: import modules with 'import
3555 <mod1>,<mod2>,...'
3570 <mod1>,<mod2>,...'
3556 * import_some <mod> <f1> <f2> ...: import functions with 'from
3571 * import_some <mod> <f1> <f2> ...: import functions with 'from
3557 <mod> import <f1>,<f2>,...'
3572 <mod> import <f1>,<f2>,...'
3558 * import_all <mod1> <mod2> ...: for each module listed import
3573 * import_all <mod1> <mod2> ...: for each module listed import
3559 functions with ``from <mod> import *``.
3574 functions with ``from <mod> import *``.
3560 * execute <python code>: give any single-line python code to be
3575 * execute <python code>: give any single-line python code to be
3561 executed.
3576 executed.
3562 * execfile <filename>: execute the python file given with an
3577 * execfile <filename>: execute the python file given with an
3563 'execfile(filename)' command. Username expansion is performed on
3578 'execfile(filename)' command. Username expansion is performed on
3564 the given names. So if you need any amount of extra fancy
3579 the given names. So if you need any amount of extra fancy
3565 customization that won't fit in any of the above 'canned' options,
3580 customization that won't fit in any of the above 'canned' options,
3566 you can just put it in a separate python file and execute it.
3581 you can just put it in a separate python file and execute it.
3567 * alias <alias_def>: this is equivalent to calling
3582 * alias <alias_def>: this is equivalent to calling
3568 '%alias <alias_def>' at the IPython command line. This way, from
3583 '%alias <alias_def>' at the IPython command line. This way, from
3569 within IPython you can do common system tasks without having to
3584 within IPython you can do common system tasks without having to
3570 exit it or use the ! escape. IPython isn't meant to be a shell
3585 exit it or use the ! escape. IPython isn't meant to be a shell
3571 replacement, but it is often very useful to be able to do things
3586 replacement, but it is often very useful to be able to do things
3572 with files while testing code. This gives you the flexibility to
3587 with files while testing code. This gives you the flexibility to
3573 have within IPython any aliases you may be used to under your
3588 have within IPython any aliases you may be used to under your
3574 normal system shell.
3589 normal system shell.
3575
3590
3576
3591
3577 .. _ipythonrc:
3592 .. _ipythonrc:
3578
3593
3579 Sample ipythonrc file
3594 Sample ipythonrc file
3580 ---------------------
3595 ---------------------
3581
3596
3582 The default rcfile, called ipythonrc and supplied in your IPYTHONDIR
3597 The default rcfile, called ipythonrc and supplied in your IPYTHONDIR
3583 directory contains lots of comments on all of these options. We
3598 directory contains lots of comments on all of these options. We
3584 reproduce it here for reference::
3599 reproduce it here for reference::
3585
3600
3586
3601
3587 # -*- Mode: Shell-Script -*- Not really, but shows comments correctly
3602 # -*- Mode: Shell-Script -*- Not really, but shows comments correctly
3588 # $Id: ipythonrc 2156 2007-03-19 02:32:19Z fperez $
3603 # $Id: ipythonrc 2156 2007-03-19 02:32:19Z fperez $
3589
3604
3590 #***************************************************************************
3605 #***************************************************************************
3591 #
3606 #
3592 # Configuration file for IPython -- ipythonrc format
3607 # Configuration file for IPython -- ipythonrc format
3593 #
3608 #
3594 # ===========================================================
3609 # ===========================================================
3595 # Deprecation note: you should look into modifying ipy_user_conf.py (located
3610 # Deprecation note: you should look into modifying ipy_user_conf.py (located
3596 # in ~/.ipython or ~/_ipython, depending on your platform) instead, it's a
3611 # in ~/.ipython or ~/_ipython, depending on your platform) instead, it's a
3597 # more flexible and robust (and better supported!) configuration
3612 # more flexible and robust (and better supported!) configuration
3598 # method.
3613 # method.
3599 # ===========================================================
3614 # ===========================================================
3600 #
3615 #
3601 # The format of this file is simply one of 'key value' lines.
3616 # The format of this file is simply one of 'key value' lines.
3602 # Lines containing only whitespace at the beginning and then a # are ignored
3617 # Lines containing only whitespace at the beginning and then a # are ignored
3603 # as comments. But comments can NOT be put on lines with data.
3618 # as comments. But comments can NOT be put on lines with data.
3604
3619
3605 # The meaning and use of each key are explained below.
3620 # The meaning and use of each key are explained below.
3606
3621
3607 #---------------------------------------------------------------------------
3622 #---------------------------------------------------------------------------
3608 # Section: included files
3623 # Section: included files
3609
3624
3610 # Put one or more *config* files (with the syntax of this file) you want to
3625 # Put one or more *config* files (with the syntax of this file) you want to
3611 # include. For keys with a unique value the outermost file has precedence. For
3626 # include. For keys with a unique value the outermost file has precedence. For
3612 # keys with multiple values, they all get assembled into a list which then
3627 # keys with multiple values, they all get assembled into a list which then
3613 # gets loaded by IPython.
3628 # gets loaded by IPython.
3614
3629
3615 # In this file, all lists of things should simply be space-separated.
3630 # In this file, all lists of things should simply be space-separated.
3616
3631
3617 # This allows you to build hierarchies of files which recursively load
3632 # This allows you to build hierarchies of files which recursively load
3618 # lower-level services. If this is your main ~/.ipython/ipythonrc file, you
3633 # lower-level services. If this is your main ~/.ipython/ipythonrc file, you
3619 # should only keep here basic things you always want available. Then you can
3634 # should only keep here basic things you always want available. Then you can
3620 # include it in every other special-purpose config file you create.
3635 # include it in every other special-purpose config file you create.
3621 include
3636 include
3622
3637
3623 #---------------------------------------------------------------------------
3638 #---------------------------------------------------------------------------
3624 # Section: startup setup
3639 # Section: startup setup
3625
3640
3626 # These are mostly things which parallel a command line option of the same
3641 # These are mostly things which parallel a command line option of the same
3627 # name.
3642 # name.
3628
3643
3629 # Keys in this section should only appear once. If any key from this section
3644 # Keys in this section should only appear once. If any key from this section
3630 # is encountered more than once, the last value remains, all earlier ones get
3645 # is encountered more than once, the last value remains, all earlier ones get
3631 # discarded.
3646 # discarded.
3632
3647
3633
3648
3634 # Automatic calling of callable objects. If set to 1 or 2, callable objects
3649 # Automatic calling of callable objects. If set to 1 or 2, callable objects
3635 # are automatically called when invoked at the command line, even if you don't
3650 # are automatically called when invoked at the command line, even if you don't
3636 # type parentheses. IPython adds the parentheses for you. For example:
3651 # type parentheses. IPython adds the parentheses for you. For example:
3637
3652
3638 #In [1]: str 45
3653 #In [1]: str 45
3639 #------> str(45)
3654 #------> str(45)
3640 #Out[1]: '45'
3655 #Out[1]: '45'
3641
3656
3642 # IPython reprints your line with '---->' indicating that it added
3657 # IPython reprints your line with '---->' indicating that it added
3643 # parentheses. While this option is very convenient for interactive use, it
3658 # parentheses. While this option is very convenient for interactive use, it
3644 # may occasionally cause problems with objects which have side-effects if
3659 # may occasionally cause problems with objects which have side-effects if
3645 # called unexpectedly.
3660 # called unexpectedly.
3646
3661
3647 # The valid values for autocall are:
3662 # The valid values for autocall are:
3648
3663
3649 # autocall 0 -> disabled (you can toggle it at runtime with the %autocall magic)
3664 # autocall 0 -> disabled (you can toggle it at runtime with the %autocall magic)
3650
3665
3651 # autocall 1 -> active, but do not apply if there are no arguments on the line.
3666 # autocall 1 -> active, but do not apply if there are no arguments on the line.
3652
3667
3653 # In this mode, you get:
3668 # In this mode, you get:
3654
3669
3655 #In [1]: callable
3670 #In [1]: callable
3656 #Out[1]: <built-in function callable>
3671 #Out[1]: <built-in function callable>
3657
3672
3658 #In [2]: callable 'hello'
3673 #In [2]: callable 'hello'
3659 #------> callable('hello')
3674 #------> callable('hello')
3660 #Out[2]: False
3675 #Out[2]: False
3661
3676
3662 # 2 -> Active always. Even if no arguments are present, the callable object
3677 # 2 -> Active always. Even if no arguments are present, the callable object
3663 # is called:
3678 # is called:
3664
3679
3665 #In [4]: callable
3680 #In [4]: callable
3666 #------> callable()
3681 #------> callable()
3667
3682
3668 # Note that even with autocall off, you can still use '/' at the start of a
3683 # Note that even with autocall off, you can still use '/' at the start of a
3669 # line to treat the first argument on the command line as a function and add
3684 # line to treat the first argument on the command line as a function and add
3670 # parentheses to it:
3685 # parentheses to it:
3671
3686
3672 #In [8]: /str 43
3687 #In [8]: /str 43
3673 #------> str(43)
3688 #------> str(43)
3674 #Out[8]: '43'
3689 #Out[8]: '43'
3675
3690
3676 autocall 1
3691 autocall 1
3677
3692
3678 # Auto-edit syntax errors. When you use the %edit magic in ipython to edit
3693 # Auto-edit syntax errors. When you use the %edit magic in ipython to edit
3679 # source code (see the 'editor' variable below), it is possible that you save
3694 # source code (see the 'editor' variable below), it is possible that you save
3680 # a file with syntax errors in it. If this variable is true, IPython will ask
3695 # a file with syntax errors in it. If this variable is true, IPython will ask
3681 # you whether to re-open the editor immediately to correct such an error.
3696 # you whether to re-open the editor immediately to correct such an error.
3682
3697
3683 autoedit_syntax 0
3698 autoedit_syntax 0
3684
3699
3685 # Auto-indent. IPython can recognize lines ending in ':' and indent the next
3700 # Auto-indent. IPython can recognize lines ending in ':' and indent the next
3686 # line, while also un-indenting automatically after 'raise' or 'return'.
3701 # line, while also un-indenting automatically after 'raise' or 'return'.
3687
3702
3688 # This feature uses the readline library, so it will honor your ~/.inputrc
3703 # This feature uses the readline library, so it will honor your ~/.inputrc
3689 # configuration (or whatever file your INPUTRC variable points to). Adding
3704 # configuration (or whatever file your INPUTRC variable points to). Adding
3690 # the following lines to your .inputrc file can make indent/unindenting more
3705 # the following lines to your .inputrc file can make indent/unindenting more
3691 # convenient (M-i indents, M-u unindents):
3706 # convenient (M-i indents, M-u unindents):
3692
3707
3693 # $if Python
3708 # $if Python
3694 # "\M-i": " "
3709 # "\M-i": " "
3695 # "\M-u": "\d\d\d\d"
3710 # "\M-u": "\d\d\d\d"
3696 # $endif
3711 # $endif
3697
3712
3698 # The feature is potentially a bit dangerous, because it can cause problems
3713 # The feature is potentially a bit dangerous, because it can cause problems
3699 # with pasting of indented code (the pasted code gets re-indented on each
3714 # with pasting of indented code (the pasted code gets re-indented on each
3700 # line). But it's a huge time-saver when working interactively. The magic
3715 # line). But it's a huge time-saver when working interactively. The magic
3701 # function %autoindent allows you to toggle it on/off at runtime.
3716 # function %autoindent allows you to toggle it on/off at runtime.
3702
3717
3703 autoindent 1
3718 autoindent 1
3704
3719
3705 # Auto-magic. This gives you access to all the magic functions without having
3720 # Auto-magic. This gives you access to all the magic functions without having
3706 # to prepend them with an % sign. If you define a variable with the same name
3721 # to prepend them with an % sign. If you define a variable with the same name
3707 # as a magic function (say who=1), you will need to access the magic function
3722 # as a magic function (say who=1), you will need to access the magic function
3708 # with % (%who in this example). However, if later you delete your variable
3723 # with % (%who in this example). However, if later you delete your variable
3709 # (del who), you'll recover the automagic calling form.
3724 # (del who), you'll recover the automagic calling form.
3710
3725
3711 # Considering that many magic functions provide a lot of shell-like
3726 # Considering that many magic functions provide a lot of shell-like
3712 # functionality, automagic gives you something close to a full Python+system
3727 # functionality, automagic gives you something close to a full Python+system
3713 # shell environment (and you can extend it further if you want).
3728 # shell environment (and you can extend it further if you want).
3714
3729
3715 automagic 1
3730 automagic 1
3716
3731
3717 # Size of the output cache. After this many entries are stored, the cache will
3732 # Size of the output cache. After this many entries are stored, the cache will
3718 # get flushed. Depending on the size of your intermediate calculations, you
3733 # get flushed. Depending on the size of your intermediate calculations, you
3719 # may have memory problems if you make it too big, since keeping things in the
3734 # may have memory problems if you make it too big, since keeping things in the
3720 # cache prevents Python from reclaiming the memory for old results. Experiment
3735 # cache prevents Python from reclaiming the memory for old results. Experiment
3721 # with a value that works well for you.
3736 # with a value that works well for you.
3722
3737
3723 # If you choose cache_size 0 IPython will revert to python's regular >>>
3738 # If you choose cache_size 0 IPython will revert to python's regular >>>
3724 # unnumbered prompt. You will still have _, __ and ___ for your last three
3739 # unnumbered prompt. You will still have _, __ and ___ for your last three
3725 # results, but that will be it. No dynamic _1, _2, etc. will be created. If
3740 # results, but that will be it. No dynamic _1, _2, etc. will be created. If
3726 # you are running on a slow machine or with very limited memory, this may
3741 # you are running on a slow machine or with very limited memory, this may
3727 # help.
3742 # help.
3728
3743
3729 cache_size 1000
3744 cache_size 1000
3730
3745
3731 # Classic mode: Setting 'classic 1' you lose many of IPython niceties,
3746 # Classic mode: Setting 'classic 1' you lose many of IPython niceties,
3732 # but that's your choice! Classic 1 -> same as IPython -classic.
3747 # but that's your choice! Classic 1 -> same as IPython -classic.
3733 # Note that this is _not_ the normal python interpreter, it's simply
3748 # Note that this is _not_ the normal python interpreter, it's simply
3734 # IPython emulating most of the classic interpreter's behavior.
3749 # IPython emulating most of the classic interpreter's behavior.
3735 classic 0
3750 classic 0
3736
3751
3737 # colors - Coloring option for prompts and traceback printouts.
3752 # colors - Coloring option for prompts and traceback printouts.
3738
3753
3739 # Currently available schemes: NoColor, Linux, LightBG.
3754 # Currently available schemes: NoColor, Linux, LightBG.
3740
3755
3741 # This option allows coloring the prompts and traceback printouts. This
3756 # This option allows coloring the prompts and traceback printouts. This
3742 # requires a terminal which can properly handle color escape sequences. If you
3757 # requires a terminal which can properly handle color escape sequences. If you
3743 # are having problems with this, use the NoColor scheme (uses no color escapes
3758 # are having problems with this, use the NoColor scheme (uses no color escapes
3744 # at all).
3759 # at all).
3745
3760
3746 # The Linux option works well in linux console type environments: dark
3761 # The Linux option works well in linux console type environments: dark
3747 # background with light fonts.
3762 # background with light fonts.
3748
3763
3749 # LightBG is similar to Linux but swaps dark/light colors to be more readable
3764 # LightBG is similar to Linux but swaps dark/light colors to be more readable
3750 # in light background terminals.
3765 # in light background terminals.
3751
3766
3752 # keep uncommented only the one you want:
3767 # keep uncommented only the one you want:
3753 colors Linux
3768 colors Linux
3754 #colors LightBG
3769 #colors LightBG
3755 #colors NoColor
3770 #colors NoColor
3756
3771
3757 ########################
3772 ########################
3758 # Note to Windows users
3773 # Note to Windows users
3759 #
3774 #
3760 # Color and readline support is avaialble to Windows users via Gary Bishop's
3775 # Color and readline support is avaialble to Windows users via Gary Bishop's
3761 # readline library. You can find Gary's tools at
3776 # readline library. You can find Gary's tools at
3762 # http://sourceforge.net/projects/uncpythontools.
3777 # http://sourceforge.net/projects/uncpythontools.
3763 # Note that his readline module requires in turn the ctypes library, available
3778 # Note that his readline module requires in turn the ctypes library, available
3764 # at http://starship.python.net/crew/theller/ctypes.
3779 # at http://starship.python.net/crew/theller/ctypes.
3765 ########################
3780 ########################
3766
3781
3767 # color_info: IPython can display information about objects via a set of
3782 # color_info: IPython can display information about objects via a set of
3768 # functions, and optionally can use colors for this, syntax highlighting
3783 # functions, and optionally can use colors for this, syntax highlighting
3769 # source code and various other elements. This information is passed through a
3784 # source code and various other elements. This information is passed through a
3770 # pager (it defaults to 'less' if $PAGER is not set).
3785 # pager (it defaults to 'less' if $PAGER is not set).
3771
3786
3772 # If your pager has problems, try to setting it to properly handle escapes
3787 # If your pager has problems, try to setting it to properly handle escapes
3773 # (see the less manpage for detail), or disable this option. The magic
3788 # (see the less manpage for detail), or disable this option. The magic
3774 # function %color_info allows you to toggle this interactively for testing.
3789 # function %color_info allows you to toggle this interactively for testing.
3775
3790
3776 color_info 1
3791 color_info 1
3777
3792
3778 # confirm_exit: set to 1 if you want IPython to confirm when you try to exit
3793 # confirm_exit: set to 1 if you want IPython to confirm when you try to exit
3779 # with an EOF (Control-d in Unix, Control-Z/Enter in Windows). Note that using
3794 # with an EOF (Control-d in Unix, Control-Z/Enter in Windows). Note that using
3780 # the magic functions %Exit or %Quit you can force a direct exit, bypassing
3795 # the magic functions %Exit or %Quit you can force a direct exit, bypassing
3781 # any confirmation.
3796 # any confirmation.
3782
3797
3783 confirm_exit 1
3798 confirm_exit 1
3784
3799
3785 # Use deep_reload() as a substitute for reload() by default. deep_reload() is
3800 # Use deep_reload() as a substitute for reload() by default. deep_reload() is
3786 # still available as dreload() and appears as a builtin.
3801 # still available as dreload() and appears as a builtin.
3787
3802
3788 deep_reload 0
3803 deep_reload 0
3789
3804
3790 # Which editor to use with the %edit command. If you leave this at 0, IPython
3805 # Which editor to use with the %edit command. If you leave this at 0, IPython
3791 # will honor your EDITOR environment variable. Since this editor is invoked on
3806 # will honor your EDITOR environment variable. Since this editor is invoked on
3792 # the fly by ipython and is meant for editing small code snippets, you may
3807 # the fly by ipython and is meant for editing small code snippets, you may
3793 # want to use a small, lightweight editor here.
3808 # want to use a small, lightweight editor here.
3794
3809
3795 # For Emacs users, setting up your Emacs server properly as described in the
3810 # For Emacs users, setting up your Emacs server properly as described in the
3796 # manual is a good idea. An alternative is to use jed, a very light editor
3811 # manual is a good idea. An alternative is to use jed, a very light editor
3797 # with much of the feel of Emacs (though not as powerful for heavy-duty work).
3812 # with much of the feel of Emacs (though not as powerful for heavy-duty work).
3798
3813
3799 editor 0
3814 editor 0
3800
3815
3801 # log 1 -> same as ipython -log. This automatically logs to ./ipython.log
3816 # log 1 -> same as ipython -log. This automatically logs to ./ipython.log
3802 log 0
3817 log 0
3803
3818
3804 # Same as ipython -Logfile YourLogfileName.
3819 # Same as ipython -Logfile YourLogfileName.
3805 # Don't use with log 1 (use one or the other)
3820 # Don't use with log 1 (use one or the other)
3806 logfile ''
3821 logfile ''
3807
3822
3808 # banner 0 -> same as ipython -nobanner
3823 # banner 0 -> same as ipython -nobanner
3809 banner 1
3824 banner 1
3810
3825
3811 # messages 0 -> same as ipython -nomessages
3826 # messages 0 -> same as ipython -nomessages
3812 messages 1
3827 messages 1
3813
3828
3814 # Automatically call the pdb debugger after every uncaught exception. If you
3829 # Automatically call the pdb debugger after every uncaught exception. If you
3815 # are used to debugging using pdb, this puts you automatically inside of it
3830 # are used to debugging using pdb, this puts you automatically inside of it
3816 # after any call (either in IPython or in code called by it) which triggers an
3831 # after any call (either in IPython or in code called by it) which triggers an
3817 # exception which goes uncaught.
3832 # exception which goes uncaught.
3818 pdb 0
3833 pdb 0
3819
3834
3820 # Enable the pprint module for printing. pprint tends to give a more readable
3835 # Enable the pprint module for printing. pprint tends to give a more readable
3821 # display (than print) for complex nested data structures.
3836 # display (than print) for complex nested data structures.
3822 pprint 1
3837 pprint 1
3823
3838
3824 # Prompt strings
3839 # Prompt strings
3825
3840
3826 # Most bash-like escapes can be used to customize IPython's prompts, as well as
3841 # Most bash-like escapes can be used to customize IPython's prompts, as well as
3827 # a few additional ones which are IPython-specific. All valid prompt escapes
3842 # a few additional ones which are IPython-specific. All valid prompt escapes
3828 # are described in detail in the Customization section of the IPython HTML/PDF
3843 # are described in detail in the Customization section of the IPython HTML/PDF
3829 # manual.
3844 # manual.
3830
3845
3831 # Use \# to represent the current prompt number, and quote them to protect
3846 # Use \# to represent the current prompt number, and quote them to protect
3832 # spaces.
3847 # spaces.
3833 prompt_in1 'In [\#]: '
3848 prompt_in1 'In [\#]: '
3834
3849
3835 # \D is replaced by as many dots as there are digits in the
3850 # \D is replaced by as many dots as there are digits in the
3836 # current value of \#.
3851 # current value of \#.
3837 prompt_in2 ' .\D.: '
3852 prompt_in2 ' .\D.: '
3838
3853
3839 prompt_out 'Out[\#]: '
3854 prompt_out 'Out[\#]: '
3840
3855
3841 # Select whether to left-pad the output prompts to match the length of the
3856 # Select whether to left-pad the output prompts to match the length of the
3842 # input ones. This allows you for example to use a simple '>' as an output
3857 # input ones. This allows you for example to use a simple '>' as an output
3843 # prompt, and yet have the output line up with the input. If set to false,
3858 # prompt, and yet have the output line up with the input. If set to false,
3844 # the output prompts will be unpadded (flush left).
3859 # the output prompts will be unpadded (flush left).
3845 prompts_pad_left 1
3860 prompts_pad_left 1
3846
3861
3847 # Pylab support: when ipython is started with the -pylab switch, by default it
3862 # Pylab support: when ipython is started with the -pylab switch, by default it
3848 # executes 'from matplotlib.pylab import *'. Set this variable to false if you
3863 # executes 'from matplotlib.pylab import *'. Set this variable to false if you
3849 # want to disable this behavior.
3864 # want to disable this behavior.
3850
3865
3851 # For details on pylab, see the matplotlib website:
3866 # For details on pylab, see the matplotlib website:
3852 # http://matplotlib.sf.net
3867 # http://matplotlib.sf.net
3853 pylab_import_all 1
3868 pylab_import_all 1
3854
3869
3855
3870
3856 # quick 1 -> same as ipython -quick
3871 # quick 1 -> same as ipython -quick
3857 quick 0
3872 quick 0
3858
3873
3859 # Use the readline library (1) or not (0). Most users will want this on, but
3874 # Use the readline library (1) or not (0). Most users will want this on, but
3860 # if you experience strange problems with line management (mainly when using
3875 # if you experience strange problems with line management (mainly when using
3861 # IPython inside Emacs buffers) you may try disabling it. Not having it on
3876 # IPython inside Emacs buffers) you may try disabling it. Not having it on
3862 # prevents you from getting command history with the arrow keys, searching and
3877 # prevents you from getting command history with the arrow keys, searching and
3863 # name completion using TAB.
3878 # name completion using TAB.
3864
3879
3865 readline 1
3880 readline 1
3866
3881
3867 # Screen Length: number of lines of your screen. This is used to control
3882 # Screen Length: number of lines of your screen. This is used to control
3868 # printing of very long strings. Strings longer than this number of lines will
3883 # printing of very long strings. Strings longer than this number of lines will
3869 # be paged with the less command instead of directly printed.
3884 # be paged with the less command instead of directly printed.
3870
3885
3871 # The default value for this is 0, which means IPython will auto-detect your
3886 # The default value for this is 0, which means IPython will auto-detect your
3872 # screen size every time it needs to print. If for some reason this isn't
3887 # screen size every time it needs to print. If for some reason this isn't
3873 # working well (it needs curses support), specify it yourself. Otherwise don't
3888 # working well (it needs curses support), specify it yourself. Otherwise don't
3874 # change the default.
3889 # change the default.
3875
3890
3876 screen_length 0
3891 screen_length 0
3877
3892
3878 # Prompt separators for input and output.
3893 # Prompt separators for input and output.
3879 # Use \n for newline explicitly, without quotes.
3894 # Use \n for newline explicitly, without quotes.
3880 # Use 0 (like at the cmd line) to turn off a given separator.
3895 # Use 0 (like at the cmd line) to turn off a given separator.
3881
3896
3882 # The structure of prompt printing is:
3897 # The structure of prompt printing is:
3883 # (SeparateIn)Input....
3898 # (SeparateIn)Input....
3884 # (SeparateOut)Output...
3899 # (SeparateOut)Output...
3885 # (SeparateOut2), # that is, no newline is printed after Out2
3900 # (SeparateOut2), # that is, no newline is printed after Out2
3886 # By choosing these you can organize your output any way you want.
3901 # By choosing these you can organize your output any way you want.
3887
3902
3888 separate_in \n
3903 separate_in \n
3889 separate_out 0
3904 separate_out 0
3890 separate_out2 0
3905 separate_out2 0
3891
3906
3892 # 'nosep 1' is a shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'.
3907 # 'nosep 1' is a shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'.
3893 # Simply removes all input/output separators, overriding the choices above.
3908 # Simply removes all input/output separators, overriding the choices above.
3894 nosep 0
3909 nosep 0
3895
3910
3896 # Wildcard searches - IPython has a system for searching names using
3911 # Wildcard searches - IPython has a system for searching names using
3897 # shell-like wildcards; type %psearch? for details. This variables sets
3912 # shell-like wildcards; type %psearch? for details. This variables sets
3898 # whether by default such searches should be case sensitive or not. You can
3913 # whether by default such searches should be case sensitive or not. You can
3899 # always override the default at the system command line or the IPython
3914 # always override the default at the system command line or the IPython
3900 # prompt.
3915 # prompt.
3901
3916
3902 wildcards_case_sensitive 1
3917 wildcards_case_sensitive 1
3903
3918
3904 # Object information: at what level of detail to display the string form of an
3919 # Object information: at what level of detail to display the string form of an
3905 # object. If set to 0, ipython will compute the string form of any object X,
3920 # object. If set to 0, ipython will compute the string form of any object X,
3906 # by calling str(X), when X? is typed. If set to 1, str(X) will only be
3921 # by calling str(X), when X? is typed. If set to 1, str(X) will only be
3907 # computed when X?? is given, and if set to 2 or higher, it will never be
3922 # computed when X?? is given, and if set to 2 or higher, it will never be
3908 # computed (there is no X??? level of detail). This is mostly of use to
3923 # computed (there is no X??? level of detail). This is mostly of use to
3909 # people who frequently manipulate objects whose string representation is
3924 # people who frequently manipulate objects whose string representation is
3910 # extremely expensive to compute.
3925 # extremely expensive to compute.
3911
3926
3912 object_info_string_level 0
3927 object_info_string_level 0
3913
3928
3914 # xmode - Exception reporting mode.
3929 # xmode - Exception reporting mode.
3915
3930
3916 # Valid modes: Plain, Context and Verbose.
3931 # Valid modes: Plain, Context and Verbose.
3917
3932
3918 # Plain: similar to python's normal traceback printing.
3933 # Plain: similar to python's normal traceback printing.
3919
3934
3920 # Context: prints 5 lines of context source code around each line in the
3935 # Context: prints 5 lines of context source code around each line in the
3921 # traceback.
3936 # traceback.
3922
3937
3923 # Verbose: similar to Context, but additionally prints the variables currently
3938 # Verbose: similar to Context, but additionally prints the variables currently
3924 # visible where the exception happened (shortening their strings if too
3939 # visible where the exception happened (shortening their strings if too
3925 # long). This can potentially be very slow, if you happen to have a huge data
3940 # long). This can potentially be very slow, if you happen to have a huge data
3926 # structure whose string representation is complex to compute. Your computer
3941 # structure whose string representation is complex to compute. Your computer
3927 # may appear to freeze for a while with cpu usage at 100%. If this occurs, you
3942 # may appear to freeze for a while with cpu usage at 100%. If this occurs, you
3928 # can cancel the traceback with Ctrl-C (maybe hitting it more than once).
3943 # can cancel the traceback with Ctrl-C (maybe hitting it more than once).
3929
3944
3930 #xmode Plain
3945 #xmode Plain
3931 xmode Context
3946 xmode Context
3932 #xmode Verbose
3947 #xmode Verbose
3933
3948
3934 # multi_line_specials: if true, allow magics, aliases and shell escapes (via
3949 # multi_line_specials: if true, allow magics, aliases and shell escapes (via
3935 # !cmd) to be used in multi-line input (like for loops). For example, if you
3950 # !cmd) to be used in multi-line input (like for loops). For example, if you
3936 # have this active, the following is valid in IPython:
3951 # have this active, the following is valid in IPython:
3937 #
3952 #
3938 #In [17]: for i in range(3):
3953 #In [17]: for i in range(3):
3939 # ....: mkdir $i
3954 # ....: mkdir $i
3940 # ....: !touch $i/hello
3955 # ....: !touch $i/hello
3941 # ....: ls -l $i
3956 # ....: ls -l $i
3942
3957
3943 multi_line_specials 1
3958 multi_line_specials 1
3944
3959
3945
3960
3946 # System calls: When IPython makes system calls (e.g. via special syntax like
3961 # System calls: When IPython makes system calls (e.g. via special syntax like
3947 # !cmd or !!cmd, or magics like %sc or %sx), it can print the command it is
3962 # !cmd or !!cmd, or magics like %sc or %sx), it can print the command it is
3948 # executing to standard output, prefixed by a header string.
3963 # executing to standard output, prefixed by a header string.
3949
3964
3950 system_header "IPython system call: "
3965 system_header "IPython system call: "
3951
3966
3952 system_verbose 1
3967 system_verbose 1
3953
3968
3954 # wxversion: request a specific wxPython version (used for -wthread)
3969 # wxversion: request a specific wxPython version (used for -wthread)
3955
3970
3956 # Set this to the value of wxPython you want to use, but note that this
3971 # Set this to the value of wxPython you want to use, but note that this
3957 # feature requires you to have the wxversion Python module to work. If you
3972 # feature requires you to have the wxversion Python module to work. If you
3958 # don't have the wxversion module (try 'import wxversion' at the prompt to
3973 # don't have the wxversion module (try 'import wxversion' at the prompt to
3959 # check) or simply want to leave the system to pick up the default, leave this
3974 # check) or simply want to leave the system to pick up the default, leave this
3960 # variable at 0.
3975 # variable at 0.
3961
3976
3962 wxversion 0
3977 wxversion 0
3963
3978
3964 #---------------------------------------------------------------------------
3979 #---------------------------------------------------------------------------
3965 # Section: Readline configuration (readline is not available for MS-Windows)
3980 # Section: Readline configuration (readline is not available for MS-Windows)
3966
3981
3967 # This is done via the following options:
3982 # This is done via the following options:
3968
3983
3969 # (i) readline_parse_and_bind: this option can appear as many times as you
3984 # (i) readline_parse_and_bind: this option can appear as many times as you
3970 # want, each time defining a string to be executed via a
3985 # want, each time defining a string to be executed via a
3971 # readline.parse_and_bind() command. The syntax for valid commands of this
3986 # readline.parse_and_bind() command. The syntax for valid commands of this
3972 # kind can be found by reading the documentation for the GNU readline library,
3987 # kind can be found by reading the documentation for the GNU readline library,
3973 # as these commands are of the kind which readline accepts in its
3988 # as these commands are of the kind which readline accepts in its
3974 # configuration file.
3989 # configuration file.
3975
3990
3976 # The TAB key can be used to complete names at the command line in one of two
3991 # The TAB key can be used to complete names at the command line in one of two
3977 # ways: 'complete' and 'menu-complete'. The difference is that 'complete' only
3992 # ways: 'complete' and 'menu-complete'. The difference is that 'complete' only
3978 # completes as much as possible while 'menu-complete' cycles through all
3993 # completes as much as possible while 'menu-complete' cycles through all
3979 # possible completions. Leave the one you prefer uncommented.
3994 # possible completions. Leave the one you prefer uncommented.
3980
3995
3981 readline_parse_and_bind tab: complete
3996 readline_parse_and_bind tab: complete
3982 #readline_parse_and_bind tab: menu-complete
3997 #readline_parse_and_bind tab: menu-complete
3983
3998
3984 # This binds Control-l to printing the list of all possible completions when
3999 # This binds Control-l to printing the list of all possible completions when
3985 # there is more than one (what 'complete' does when hitting TAB twice, or at
4000 # there is more than one (what 'complete' does when hitting TAB twice, or at
3986 # the first TAB if show-all-if-ambiguous is on)
4001 # the first TAB if show-all-if-ambiguous is on)
3987 readline_parse_and_bind "\C-l": possible-completions
4002 readline_parse_and_bind "\C-l": possible-completions
3988
4003
3989 # This forces readline to automatically print the above list when tab
4004 # This forces readline to automatically print the above list when tab
3990 # completion is set to 'complete'. You can still get this list manually by
4005 # completion is set to 'complete'. You can still get this list manually by
3991 # using the key bound to 'possible-completions' (Control-l by default) or by
4006 # using the key bound to 'possible-completions' (Control-l by default) or by
3992 # hitting TAB twice. Turning this on makes the printing happen at the first
4007 # hitting TAB twice. Turning this on makes the printing happen at the first
3993 # TAB.
4008 # TAB.
3994 readline_parse_and_bind set show-all-if-ambiguous on
4009 readline_parse_and_bind set show-all-if-ambiguous on
3995
4010
3996 # If you have TAB set to complete names, you can rebind any key (Control-o by
4011 # If you have TAB set to complete names, you can rebind any key (Control-o by
3997 # default) to insert a true TAB character.
4012 # default) to insert a true TAB character.
3998 readline_parse_and_bind "\C-o": tab-insert
4013 readline_parse_and_bind "\C-o": tab-insert
3999
4014
4000 # These commands allow you to indent/unindent easily, with the 4-space
4015 # These commands allow you to indent/unindent easily, with the 4-space
4001 # convention of the Python coding standards. Since IPython's internal
4016 # convention of the Python coding standards. Since IPython's internal
4002 # auto-indent system also uses 4 spaces, you should not change the number of
4017 # auto-indent system also uses 4 spaces, you should not change the number of
4003 # spaces in the code below.
4018 # spaces in the code below.
4004 readline_parse_and_bind "\M-i": " "
4019 readline_parse_and_bind "\M-i": " "
4005 readline_parse_and_bind "\M-o": "\d\d\d\d"
4020 readline_parse_and_bind "\M-o": "\d\d\d\d"
4006 readline_parse_and_bind "\M-I": "\d\d\d\d"
4021 readline_parse_and_bind "\M-I": "\d\d\d\d"
4007
4022
4008 # Bindings for incremental searches in the history. These searches use the
4023 # Bindings for incremental searches in the history. These searches use the
4009 # string typed so far on the command line and search anything in the previous
4024 # string typed so far on the command line and search anything in the previous
4010 # input history containing them.
4025 # input history containing them.
4011 readline_parse_and_bind "\C-r": reverse-search-history
4026 readline_parse_and_bind "\C-r": reverse-search-history
4012 readline_parse_and_bind "\C-s": forward-search-history
4027 readline_parse_and_bind "\C-s": forward-search-history
4013
4028
4014 # Bindings for completing the current line in the history of previous
4029 # Bindings for completing the current line in the history of previous
4015 # commands. This allows you to recall any previous command by typing its first
4030 # commands. This allows you to recall any previous command by typing its first
4016 # few letters and hitting Control-p, bypassing all intermediate commands which
4031 # few letters and hitting Control-p, bypassing all intermediate commands which
4017 # may be in the history (much faster than hitting up-arrow 50 times!)
4032 # may be in the history (much faster than hitting up-arrow 50 times!)
4018 readline_parse_and_bind "\C-p": history-search-backward
4033 readline_parse_and_bind "\C-p": history-search-backward
4019 readline_parse_and_bind "\C-n": history-search-forward
4034 readline_parse_and_bind "\C-n": history-search-forward
4020
4035
4021 # I also like to have the same functionality on the plain arrow keys. If you'd
4036 # I also like to have the same functionality on the plain arrow keys. If you'd
4022 # rather have the arrows use all the history (and not just match what you've
4037 # rather have the arrows use all the history (and not just match what you've
4023 # typed so far), comment out or delete the next two lines.
4038 # typed so far), comment out or delete the next two lines.
4024 readline_parse_and_bind "\e[A": history-search-backward
4039 readline_parse_and_bind "\e[A": history-search-backward
4025 readline_parse_and_bind "\e[B": history-search-forward
4040 readline_parse_and_bind "\e[B": history-search-forward
4026
4041
4027 # These are typically on by default under *nix, but not win32.
4042 # These are typically on by default under *nix, but not win32.
4028 readline_parse_and_bind "\C-k": kill-line
4043 readline_parse_and_bind "\C-k": kill-line
4029 readline_parse_and_bind "\C-u": unix-line-discard
4044 readline_parse_and_bind "\C-u": unix-line-discard
4030
4045
4031 # (ii) readline_remove_delims: a string of characters to be removed from the
4046 # (ii) readline_remove_delims: a string of characters to be removed from the
4032 # default word-delimiters list used by readline, so that completions may be
4047 # default word-delimiters list used by readline, so that completions may be
4033 # performed on strings which contain them.
4048 # performed on strings which contain them.
4034
4049
4035 readline_remove_delims -/~
4050 readline_remove_delims -/~
4036
4051
4037 # (iii) readline_merge_completions: whether to merge the result of all
4052 # (iii) readline_merge_completions: whether to merge the result of all
4038 # possible completions or not. If true, IPython will complete filenames,
4053 # possible completions or not. If true, IPython will complete filenames,
4039 # python names and aliases and return all possible completions. If you set it
4054 # python names and aliases and return all possible completions. If you set it
4040 # to false, each completer is used at a time, and only if it doesn't return
4055 # to false, each completer is used at a time, and only if it doesn't return
4041 # any completions is the next one used.
4056 # any completions is the next one used.
4042
4057
4043 # The default order is: [python_matches, file_matches, alias_matches]
4058 # The default order is: [python_matches, file_matches, alias_matches]
4044
4059
4045 readline_merge_completions 1
4060 readline_merge_completions 1
4046
4061
4047 # (iv) readline_omit__names: normally hitting <tab> after a '.' in a name
4062 # (iv) readline_omit__names: normally hitting <tab> after a '.' in a name
4048 # will complete all attributes of an object, including all the special methods
4063 # will complete all attributes of an object, including all the special methods
4049 # whose names start with single or double underscores (like __getitem__ or
4064 # whose names start with single or double underscores (like __getitem__ or
4050 # __class__).
4065 # __class__).
4051
4066
4052 # This variable allows you to control this completion behavior:
4067 # This variable allows you to control this completion behavior:
4053
4068
4054 # readline_omit__names 1 -> completion will omit showing any names starting
4069 # readline_omit__names 1 -> completion will omit showing any names starting
4055 # with two __, but it will still show names starting with one _.
4070 # with two __, but it will still show names starting with one _.
4056
4071
4057 # readline_omit__names 2 -> completion will omit all names beginning with one
4072 # readline_omit__names 2 -> completion will omit all names beginning with one
4058 # _ (which obviously means filtering out the double __ ones).
4073 # _ (which obviously means filtering out the double __ ones).
4059
4074
4060 # Even when this option is set, you can still see those names by explicitly
4075 # Even when this option is set, you can still see those names by explicitly
4061 # typing a _ after the period and hitting <tab>: 'name._<tab>' will always
4076 # typing a _ after the period and hitting <tab>: 'name._<tab>' will always
4062 # complete attribute names starting with '_'.
4077 # complete attribute names starting with '_'.
4063
4078
4064 # This option is off by default so that new users see all attributes of any
4079 # This option is off by default so that new users see all attributes of any
4065 # objects they are dealing with.
4080 # objects they are dealing with.
4066
4081
4067 readline_omit__names 0
4082 readline_omit__names 0
4068
4083
4069 #---------------------------------------------------------------------------
4084 #---------------------------------------------------------------------------
4070 # Section: modules to be loaded with 'import ...'
4085 # Section: modules to be loaded with 'import ...'
4071
4086
4072 # List, separated by spaces, the names of the modules you want to import
4087 # List, separated by spaces, the names of the modules you want to import
4073
4088
4074 # Example:
4089 # Example:
4075 # import_mod sys os
4090 # import_mod sys os
4076 # will produce internally the statements
4091 # will produce internally the statements
4077 # import sys
4092 # import sys
4078 # import os
4093 # import os
4079
4094
4080 # Each import is executed in its own try/except block, so if one module
4095 # Each import is executed in its own try/except block, so if one module
4081 # fails to load the others will still be ok.
4096 # fails to load the others will still be ok.
4082
4097
4083 import_mod
4098 import_mod
4084
4099
4085 #---------------------------------------------------------------------------
4100 #---------------------------------------------------------------------------
4086 # Section: modules to import some functions from: 'from ... import ...'
4101 # Section: modules to import some functions from: 'from ... import ...'
4087
4102
4088 # List, one per line, the modules for which you want only to import some
4103 # List, one per line, the modules for which you want only to import some
4089 # functions. Give the module name first and then the name of functions to be
4104 # functions. Give the module name first and then the name of functions to be
4090 # imported from that module.
4105 # imported from that module.
4091
4106
4092 # Example:
4107 # Example:
4093
4108
4094 # import_some IPython.genutils timing timings
4109 # import_some IPython.genutils timing timings
4095 # will produce internally the statement
4110 # will produce internally the statement
4096 # from IPython.genutils import timing, timings
4111 # from IPython.genutils import timing, timings
4097
4112
4098 # timing() and timings() are two IPython utilities for timing the execution of
4113 # timing() and timings() are two IPython utilities for timing the execution of
4099 # your own functions, which you may find useful. Just commment out the above
4114 # your own functions, which you may find useful. Just commment out the above
4100 # line if you want to test them.
4115 # line if you want to test them.
4101
4116
4102 # If you have more than one modules_some line, each gets its own try/except
4117 # If you have more than one modules_some line, each gets its own try/except
4103 # block (like modules, see above).
4118 # block (like modules, see above).
4104
4119
4105 import_some
4120 import_some
4106
4121
4107 #---------------------------------------------------------------------------
4122 #---------------------------------------------------------------------------
4108 # Section: modules to import all from : 'from ... import *'
4123 # Section: modules to import all from : 'from ... import *'
4109
4124
4110 # List (same syntax as import_mod above) those modules for which you want to
4125 # List (same syntax as import_mod above) those modules for which you want to
4111 # import all functions. Remember, this is a potentially dangerous thing to do,
4126 # import all functions. Remember, this is a potentially dangerous thing to do,
4112 # since it is very easy to overwrite names of things you need. Use with
4127 # since it is very easy to overwrite names of things you need. Use with
4113 # caution.
4128 # caution.
4114
4129
4115 # Example:
4130 # Example:
4116 # import_all sys os
4131 # import_all sys os
4117 # will produce internally the statements
4132 # will produce internally the statements
4118 # from sys import *
4133 # from sys import *
4119 # from os import *
4134 # from os import *
4120
4135
4121 # As before, each will be called in a separate try/except block.
4136 # As before, each will be called in a separate try/except block.
4122
4137
4123 import_all
4138 import_all
4124
4139
4125 #---------------------------------------------------------------------------
4140 #---------------------------------------------------------------------------
4126 # Section: Python code to execute.
4141 # Section: Python code to execute.
4127
4142
4128 # Put here code to be explicitly executed (keep it simple!)
4143 # Put here code to be explicitly executed (keep it simple!)
4129 # Put one line of python code per line. All whitespace is removed (this is a
4144 # Put one line of python code per line. All whitespace is removed (this is a
4130 # feature, not a bug), so don't get fancy building loops here.
4145 # feature, not a bug), so don't get fancy building loops here.
4131 # This is just for quick convenient creation of things you want available.
4146 # This is just for quick convenient creation of things you want available.
4132
4147
4133 # Example:
4148 # Example:
4134 # execute x = 1
4149 # execute x = 1
4135 # execute print 'hello world'; y = z = 'a'
4150 # execute print 'hello world'; y = z = 'a'
4136 # will produce internally
4151 # will produce internally
4137 # x = 1
4152 # x = 1
4138 # print 'hello world'; y = z = 'a'
4153 # print 'hello world'; y = z = 'a'
4139 # and each *line* (not each statement, we don't do python syntax parsing) is
4154 # and each *line* (not each statement, we don't do python syntax parsing) is
4140 # executed in its own try/except block.
4155 # executed in its own try/except block.
4141
4156
4142 execute
4157 execute
4143
4158
4144 # Note for the adventurous: you can use this to define your own names for the
4159 # Note for the adventurous: you can use this to define your own names for the
4145 # magic functions, by playing some namespace tricks:
4160 # magic functions, by playing some namespace tricks:
4146
4161
4147 # execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
4162 # execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
4148
4163
4149 # defines %pf as a new name for %profile.
4164 # defines %pf as a new name for %profile.
4150
4165
4151 #---------------------------------------------------------------------------
4166 #---------------------------------------------------------------------------
4152 # Section: Pyhton files to load and execute.
4167 # Section: Pyhton files to load and execute.
4153
4168
4154 # Put here the full names of files you want executed with execfile(file). If
4169 # Put here the full names of files you want executed with execfile(file). If
4155 # you want complicated initialization, just write whatever you want in a
4170 # you want complicated initialization, just write whatever you want in a
4156 # regular python file and load it from here.
4171 # regular python file and load it from here.
4157
4172
4158 # Filenames defined here (which *must* include the extension) are searched for
4173 # Filenames defined here (which *must* include the extension) are searched for
4159 # through all of sys.path. Since IPython adds your .ipython directory to
4174 # through all of sys.path. Since IPython adds your .ipython directory to
4160 # sys.path, they can also be placed in your .ipython dir and will be
4175 # sys.path, they can also be placed in your .ipython dir and will be
4161 # found. Otherwise (if you want to execute things not in .ipyton nor in
4176 # found. Otherwise (if you want to execute things not in .ipyton nor in
4162 # sys.path) give a full path (you can use ~, it gets expanded)
4177 # sys.path) give a full path (you can use ~, it gets expanded)
4163
4178
4164 # Example:
4179 # Example:
4165 # execfile file1.py ~/file2.py
4180 # execfile file1.py ~/file2.py
4166 # will generate
4181 # will generate
4167 # execfile('file1.py')
4182 # execfile('file1.py')
4168 # execfile('_path_to_your_home/file2.py')
4183 # execfile('_path_to_your_home/file2.py')
4169
4184
4170 # As before, each file gets its own try/except block.
4185 # As before, each file gets its own try/except block.
4171
4186
4172 execfile
4187 execfile
4173
4188
4174 # If you are feeling adventurous, you can even add functionality to IPython
4189 # If you are feeling adventurous, you can even add functionality to IPython
4175 # through here. IPython works through a global variable called __ip which
4190 # through here. IPython works through a global variable called __ip which
4176 # exists at the time when these files are read. If you know what you are doing
4191 # exists at the time when these files are read. If you know what you are doing
4177 # (read the source) you can add functions to __ip in files loaded here.
4192 # (read the source) you can add functions to __ip in files loaded here.
4178
4193
4179 # The file example-magic.py contains a simple but correct example. Try it:
4194 # The file example-magic.py contains a simple but correct example. Try it:
4180
4195
4181 # execfile example-magic.py
4196 # execfile example-magic.py
4182
4197
4183 # Look at the examples in IPython/iplib.py for more details on how these magic
4198 # Look at the examples in IPython/iplib.py for more details on how these magic
4184 # functions need to process their arguments.
4199 # functions need to process their arguments.
4185
4200
4186 #---------------------------------------------------------------------------
4201 #---------------------------------------------------------------------------
4187 # Section: aliases for system shell commands
4202 # Section: aliases for system shell commands
4188
4203
4189 # Here you can define your own names for system commands. The syntax is
4204 # Here you can define your own names for system commands. The syntax is
4190 # similar to that of the builtin %alias function:
4205 # similar to that of the builtin %alias function:
4191
4206
4192 # alias alias_name command_string
4207 # alias alias_name command_string
4193
4208
4194 # The resulting aliases are auto-generated magic functions (hence usable as
4209 # The resulting aliases are auto-generated magic functions (hence usable as
4195 # %alias_name)
4210 # %alias_name)
4196
4211
4197 # For example:
4212 # For example:
4198
4213
4199 # alias myls ls -la
4214 # alias myls ls -la
4200
4215
4201 # will define 'myls' as an alias for executing the system command 'ls -la'.
4216 # will define 'myls' as an alias for executing the system command 'ls -la'.
4202 # This allows you to customize IPython's environment to have the same aliases
4217 # This allows you to customize IPython's environment to have the same aliases
4203 # you are accustomed to from your own shell.
4218 # you are accustomed to from your own shell.
4204
4219
4205 # You can also define aliases with parameters using %s specifiers (one per
4220 # You can also define aliases with parameters using %s specifiers (one per
4206 # parameter):
4221 # parameter):
4207
4222
4208 # alias parts echo first %s second %s
4223 # alias parts echo first %s second %s
4209
4224
4210 # will give you in IPython:
4225 # will give you in IPython:
4211 # >>> %parts A B
4226 # >>> %parts A B
4212 # first A second B
4227 # first A second B
4213
4228
4214 # Use one 'alias' statement per alias you wish to define.
4229 # Use one 'alias' statement per alias you wish to define.
4215
4230
4216 # alias
4231 # alias
4217
4232
4218 #************************* end of file <ipythonrc> ************************
4233 #************************* end of file <ipythonrc> ************************
4219
4234
4220
4235
4221 ipy_user_conf.py
4236 ipy_user_conf.py
4222 ----------------
4237 ----------------
4223
4238
4224 There should be a simple template ipy_user_conf.py file in your
4239 There should be a simple template ipy_user_conf.py file in your
4225 ~/.ipython directory. It is a plain python module that is imported
4240 ~/.ipython directory. It is a plain python module that is imported
4226 during IPython startup, so you can do pretty much what you want there
4241 during IPython startup, so you can do pretty much what you want there
4227 - import modules, configure extensions, change options, define magic
4242 - import modules, configure extensions, change options, define magic
4228 commands, put variables and functions in the IPython namespace,
4243 commands, put variables and functions in the IPython namespace,
4229 etc. You use the IPython extension api object, acquired by
4244 etc. You use the IPython extension api object, acquired by
4230 IPython.ipapi.get() and documented in the "IPython extension API"
4245 IPython.ipapi.get() and documented in the "IPython extension API"
4231 chapter, to interact with IPython. A sample ipy_user_conf.py is listed
4246 chapter, to interact with IPython. A sample ipy_user_conf.py is listed
4232 below for reference::
4247 below for reference::
4233
4248
4234 # Most of your config files and extensions will probably start
4249 # Most of your config files and extensions will probably start
4235 # with this import
4250 # with this import
4236
4251
4237 import IPython.ipapi
4252 import IPython.ipapi
4238 ip = IPython.ipapi.get()
4253 ip = IPython.ipapi.get()
4239
4254
4240 # You probably want to uncomment this if you did %upgrade -nolegacy
4255 # You probably want to uncomment this if you did %upgrade -nolegacy
4241 # import ipy_defaults
4256 # import ipy_defaults
4242
4257
4243 import os
4258 import os
4244
4259
4245 def main():
4260 def main():
4246
4261
4247 #ip.dbg.debugmode = True
4262 #ip.dbg.debugmode = True
4248 ip.dbg.debug_stack()
4263 ip.dbg.debug_stack()
4249
4264
4250 # uncomment if you want to get ipython -p sh behaviour
4265 # uncomment if you want to get ipython -p sh behaviour
4251 # without having to use command line switches
4266 # without having to use command line switches
4252 import ipy_profile_sh
4267 import ipy_profile_sh
4253 import jobctrl
4268 import jobctrl
4254
4269
4255 # Configure your favourite editor?
4270 # Configure your favourite editor?
4256 # Good idea e.g. for %edit os.path.isfile
4271 # Good idea e.g. for %edit os.path.isfile
4257
4272
4258 #import ipy_editors
4273 #import ipy_editors
4259
4274
4260 # Choose one of these:
4275 # Choose one of these:
4261
4276
4262 #ipy_editors.scite()
4277 #ipy_editors.scite()
4263 #ipy_editors.scite('c:/opt/scite/scite.exe')
4278 #ipy_editors.scite('c:/opt/scite/scite.exe')
4264 #ipy_editors.komodo()
4279 #ipy_editors.komodo()
4265 #ipy_editors.idle()
4280 #ipy_editors.idle()
4266 # ... or many others, try 'ipy_editors??' after import to see them
4281 # ... or many others, try 'ipy_editors??' after import to see them
4267
4282
4268 # Or roll your own:
4283 # Or roll your own:
4269 #ipy_editors.install_editor("c:/opt/jed +$line $file")
4284 #ipy_editors.install_editor("c:/opt/jed +$line $file")
4270
4285
4271
4286
4272 o = ip.options
4287 o = ip.options
4273 # An example on how to set options
4288 # An example on how to set options
4274 #o.autocall = 1
4289 #o.autocall = 1
4275 o.system_verbose = 0
4290 o.system_verbose = 0
4276
4291
4277 #import_all("os sys")
4292 #import_all("os sys")
4278 #execf('~/_ipython/ns.py')
4293 #execf('~/_ipython/ns.py')
4279
4294
4280
4295
4281 # -- prompt
4296 # -- prompt
4282 # A different, more compact set of prompts from the default ones, that
4297 # A different, more compact set of prompts from the default ones, that
4283 # always show your current location in the filesystem:
4298 # always show your current location in the filesystem:
4284
4299
4285 #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
4300 #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
4286 #o.prompt_in2 = r'.\D: '
4301 #o.prompt_in2 = r'.\D: '
4287 #o.prompt_out = r'[\#] '
4302 #o.prompt_out = r'[\#] '
4288
4303
4289 # Try one of these color settings if you can't read the text easily
4304 # Try one of these color settings if you can't read the text easily
4290 # autoexec is a list of IPython commands to execute on startup
4305 # autoexec is a list of IPython commands to execute on startup
4291 #o.autoexec.append('%colors LightBG')
4306 #o.autoexec.append('%colors LightBG')
4292 #o.autoexec.append('%colors NoColor')
4307 #o.autoexec.append('%colors NoColor')
4293 o.autoexec.append('%colors Linux')
4308 o.autoexec.append('%colors Linux')
4294
4309
4295
4310
4296 # some config helper functions you can use
4311 # some config helper functions you can use
4297 def import_all(modules):
4312 def import_all(modules):
4298 """ Usage: import_all("os sys") """
4313 """ Usage: import_all("os sys") """
4299 for m in modules.split():
4314 for m in modules.split():
4300 ip.ex("from %s import *" % m)
4315 ip.ex("from %s import *" % m)
4301
4316
4302 def execf(fname):
4317 def execf(fname):
4303 """ Execute a file in user namespace """
4318 """ Execute a file in user namespace """
4304 ip.ex('execfile("%s")' % os.path.expanduser(fname))
4319 ip.ex('execfile("%s")' % os.path.expanduser(fname))
4305
4320
4306 main()
4321 main()
4307
4322
4308 .. _Prompts:
4323 .. _Prompts:
4309
4324
4310 Fine-tuning your prompt
4325 Fine-tuning your prompt
4311 -----------------------
4326 -----------------------
4312
4327
4313 IPython's prompts can be customized using a syntax similar to that of
4328 IPython's prompts can be customized using a syntax similar to that of
4314 the bash shell. Many of bash's escapes are supported, as well as a few
4329 the bash shell. Many of bash's escapes are supported, as well as a few
4315 additional ones. We list them below::
4330 additional ones. We list them below::
4316
4331
4317 \#
4332 \#
4318 the prompt/history count number. This escape is automatically
4333 the prompt/history count number. This escape is automatically
4319 wrapped in the coloring codes for the currently active color scheme.
4334 wrapped in the coloring codes for the currently active color scheme.
4320 \N
4335 \N
4321 the 'naked' prompt/history count number: this is just the number
4336 the 'naked' prompt/history count number: this is just the number
4322 itself, without any coloring applied to it. This lets you produce
4337 itself, without any coloring applied to it. This lets you produce
4323 numbered prompts with your own colors.
4338 numbered prompts with your own colors.
4324 \D
4339 \D
4325 the prompt/history count, with the actual digits replaced by dots.
4340 the prompt/history count, with the actual digits replaced by dots.
4326 Used mainly in continuation prompts (prompt_in2)
4341 Used mainly in continuation prompts (prompt_in2)
4327 \w
4342 \w
4328 the current working directory
4343 the current working directory
4329 \W
4344 \W
4330 the basename of current working directory
4345 the basename of current working directory
4331 \Xn
4346 \Xn
4332 where $n=0\ldots5.$ The current working directory, with $HOME
4347 where $n=0\ldots5.$ The current working directory, with $HOME
4333 replaced by ~, and filtered out to contain only $n$ path elements
4348 replaced by ~, and filtered out to contain only $n$ path elements
4334 \Yn
4349 \Yn
4335 Similar to \Xn, but with the $n+1$ element included if it is ~ (this
4350 Similar to \Xn, but with the $n+1$ element included if it is ~ (this
4336 is similar to the behavior of the %cn escapes in tcsh)
4351 is similar to the behavior of the %cn escapes in tcsh)
4337 \u
4352 \u
4338 the username of the current user
4353 the username of the current user
4339 \$
4354 \$
4340 if the effective UID is 0, a #, otherwise a $
4355 if the effective UID is 0, a #, otherwise a $
4341 \h
4356 \h
4342 the hostname up to the first '.'
4357 the hostname up to the first '.'
4343 \H
4358 \H
4344 the hostname
4359 the hostname
4345 \n
4360 \n
4346 a newline
4361 a newline
4347 \r
4362 \r
4348 a carriage return
4363 a carriage return
4349 \v
4364 \v
4350 IPython version string
4365 IPython version string
4351
4366
4352 In addition to these, ANSI color escapes can be insterted into the
4367 In addition to these, ANSI color escapes can be insterted into the
4353 prompts, as \C_ColorName. The list of valid color names is: Black, Blue,
4368 prompts, as \C_ColorName. The list of valid color names is: Black, Blue,
4354 Brown, Cyan, DarkGray, Green, LightBlue, LightCyan, LightGray,
4369 Brown, Cyan, DarkGray, Green, LightBlue, LightCyan, LightGray,
4355 LightGreen, LightPurple, LightRed, NoColor, Normal, Purple, Red, White,
4370 LightGreen, LightPurple, LightRed, NoColor, Normal, Purple, Red, White,
4356 Yellow.
4371 Yellow.
4357
4372
4358 Finally, IPython supports the evaluation of arbitrary expressions in
4373 Finally, IPython supports the evaluation of arbitrary expressions in
4359 your prompt string. The prompt strings are evaluated through the syntax
4374 your prompt string. The prompt strings are evaluated through the syntax
4360 of PEP 215, but basically you can use $x.y to expand the value of x.y,
4375 of PEP 215, but basically you can use $x.y to expand the value of x.y,
4361 and for more complicated expressions you can use braces: ${foo()+x} will
4376 and for more complicated expressions you can use braces: ${foo()+x} will
4362 call function foo and add to it the value of x, before putting the
4377 call function foo and add to it the value of x, before putting the
4363 result into your prompt. For example, using
4378 result into your prompt. For example, using
4364 prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: '
4379 prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: '
4365 will print the result of the uptime command on each prompt (assuming the
4380 will print the result of the uptime command on each prompt (assuming the
4366 commands module has been imported in your ipythonrc file).
4381 commands module has been imported in your ipythonrc file).
4367
4382
4368
4383
4369 Prompt examples
4384 Prompt examples
4370
4385
4371 The following options in an ipythonrc file will give you IPython's
4386 The following options in an ipythonrc file will give you IPython's
4372 default prompts::
4387 default prompts::
4373
4388
4374 prompt_in1 'In [\#]:'
4389 prompt_in1 'In [\#]:'
4375 prompt_in2 ' .\D.:'
4390 prompt_in2 ' .\D.:'
4376 prompt_out 'Out[\#]:'
4391 prompt_out 'Out[\#]:'
4377
4392
4378 which look like this::
4393 which look like this::
4379
4394
4380 In [1]: 1+2
4395 In [1]: 1+2
4381 Out[1]: 3
4396 Out[1]: 3
4382
4397
4383 In [2]: for i in (1,2,3):
4398 In [2]: for i in (1,2,3):
4384 ...: print i,
4399 ...: print i,
4385 ...:
4400 ...:
4386 1 2 3
4401 1 2 3
4387
4402
4388 These will give you a very colorful prompt with path information::
4403 These will give you a very colorful prompt with path information::
4389
4404
4390 #prompt_in1 '\C_Red\u\C_Blue[\C_Cyan\Y1\C_Blue]\C_LightGreen\#>'
4405 #prompt_in1 '\C_Red\u\C_Blue[\C_Cyan\Y1\C_Blue]\C_LightGreen\#>'
4391 prompt_in2 ' ..\D>'
4406 prompt_in2 ' ..\D>'
4392 prompt_out '<\#>'
4407 prompt_out '<\#>'
4393
4408
4394 which look like this::
4409 which look like this::
4395
4410
4396 fperez[~/ipython]1> 1+2
4411 fperez[~/ipython]1> 1+2
4397 <1> 3
4412 <1> 3
4398 fperez[~/ipython]2> for i in (1,2,3):
4413 fperez[~/ipython]2> for i in (1,2,3):
4399 ...> print i,
4414 ...> print i,
4400 ...>
4415 ...>
4401 1 2 3
4416 1 2 3
4402
4417
4403
4418
4404 .. _Profiles:
4419 .. _Profiles:
4405
4420
4406 IPython profiles
4421 IPython profiles
4407 ----------------
4422 ----------------
4408
4423
4409 As we already mentioned, IPython supports the -profile command-line
4424 As we already mentioned, IPython supports the -profile command-line
4410 option (see sec. `command line options`_). A profile is nothing more
4425 option (see sec. `command line options`_). A profile is nothing more
4411 than a particular configuration file like your basic ipythonrc one,
4426 than a particular configuration file like your basic ipythonrc one,
4412 but with particular customizations for a specific purpose. When you
4427 but with particular customizations for a specific purpose. When you
4413 start IPython with 'ipython -profile <name>', it assumes that in your
4428 start IPython with 'ipython -profile <name>', it assumes that in your
4414 IPYTHONDIR there is a file called ipythonrc-<name> or
4429 IPYTHONDIR there is a file called ipythonrc-<name> or
4415 ipy_profile_<name>.py, and loads it instead of the normal ipythonrc.
4430 ipy_profile_<name>.py, and loads it instead of the normal ipythonrc.
4416
4431
4417 This system allows you to maintain multiple configurations which load
4432 This system allows you to maintain multiple configurations which load
4418 modules, set options, define functions, etc. suitable for different
4433 modules, set options, define functions, etc. suitable for different
4419 tasks and activate them in a very simple manner. In order to avoid
4434 tasks and activate them in a very simple manner. In order to avoid
4420 having to repeat all of your basic options (common things that don't
4435 having to repeat all of your basic options (common things that don't
4421 change such as your color preferences, for example), any profile can
4436 change such as your color preferences, for example), any profile can
4422 include another configuration file. The most common way to use profiles
4437 include another configuration file. The most common way to use profiles
4423 is then to have each one include your basic ipythonrc file as a starting
4438 is then to have each one include your basic ipythonrc file as a starting
4424 point, and then add further customizations.
4439 point, and then add further customizations.
4425
4440
4426 IPython as your default Python environment
4441 IPython as your default Python environment
4427 ==========================================
4442 ==========================================
4428
4443
4429 Python honors the environment variable PYTHONSTARTUP and will execute at
4444 Python honors the environment variable PYTHONSTARTUP and will execute at
4430 startup the file referenced by this variable. If you put at the end of
4445 startup the file referenced by this variable. If you put at the end of
4431 this file the following two lines of code::
4446 this file the following two lines of code::
4432
4447
4433 import IPython
4448 import IPython
4434 IPython.Shell.IPShell().mainloop(sys_exit=1)
4449 IPython.Shell.IPShell().mainloop(sys_exit=1)
4435
4450
4436 then IPython will be your working environment anytime you start Python.
4451 then IPython will be your working environment anytime you start Python.
4437 The sys_exit=1 is needed to have IPython issue a call to sys.exit() when
4452 The sys_exit=1 is needed to have IPython issue a call to sys.exit() when
4438 it finishes, otherwise you'll be back at the normal Python '>>>'
4453 it finishes, otherwise you'll be back at the normal Python '>>>'
4439 prompt.
4454 prompt.
4440
4455
4441 This is probably useful to developers who manage multiple Python
4456 This is probably useful to developers who manage multiple Python
4442 versions and don't want to have correspondingly multiple IPython
4457 versions and don't want to have correspondingly multiple IPython
4443 versions. Note that in this mode, there is no way to pass IPython any
4458 versions. Note that in this mode, there is no way to pass IPython any
4444 command-line options, as those are trapped first by Python itself.
4459 command-line options, as those are trapped first by Python itself.
4445
4460
4446 .. _Embedding:
4461 .. _Embedding:
4447
4462
4448 Embedding IPython
4463 Embedding IPython
4449 =================
4464 =================
4450
4465
4451 It is possible to start an IPython instance inside your own Python
4466 It is possible to start an IPython instance inside your own Python
4452 programs. This allows you to evaluate dynamically the state of your
4467 programs. This allows you to evaluate dynamically the state of your
4453 code, operate with your variables, analyze them, etc. Note however that
4468 code, operate with your variables, analyze them, etc. Note however that
4454 any changes you make to values while in the shell do not propagate back
4469 any changes you make to values while in the shell do not propagate back
4455 to the running code, so it is safe to modify your values because you
4470 to the running code, so it is safe to modify your values because you
4456 won't break your code in bizarre ways by doing so.
4471 won't break your code in bizarre ways by doing so.
4457
4472
4458 This feature allows you to easily have a fully functional python
4473 This feature allows you to easily have a fully functional python
4459 environment for doing object introspection anywhere in your code with a
4474 environment for doing object introspection anywhere in your code with a
4460 simple function call. In some cases a simple print statement is enough,
4475 simple function call. In some cases a simple print statement is enough,
4461 but if you need to do more detailed analysis of a code fragment this
4476 but if you need to do more detailed analysis of a code fragment this
4462 feature can be very valuable.
4477 feature can be very valuable.
4463
4478
4464 It can also be useful in scientific computing situations where it is
4479 It can also be useful in scientific computing situations where it is
4465 common to need to do some automatic, computationally intensive part and
4480 common to need to do some automatic, computationally intensive part and
4466 then stop to look at data, plots, etc.
4481 then stop to look at data, plots, etc.
4467 Opening an IPython instance will give you full access to your data and
4482 Opening an IPython instance will give you full access to your data and
4468 functions, and you can resume program execution once you are done with
4483 functions, and you can resume program execution once you are done with
4469 the interactive part (perhaps to stop again later, as many times as
4484 the interactive part (perhaps to stop again later, as many times as
4470 needed).
4485 needed).
4471
4486
4472 The following code snippet is the bare minimum you need to include in
4487 The following code snippet is the bare minimum you need to include in
4473 your Python programs for this to work (detailed examples follow later)::
4488 your Python programs for this to work (detailed examples follow later)::
4474
4489
4475 from IPython.Shell import IPShellEmbed
4490 from IPython.Shell import IPShellEmbed
4476
4491
4477 ipshell = IPShellEmbed()
4492 ipshell = IPShellEmbed()
4478
4493
4479 ipshell() # this call anywhere in your program will start IPython
4494 ipshell() # this call anywhere in your program will start IPython
4480
4495
4481 You can run embedded instances even in code which is itself being run at
4496 You can run embedded instances even in code which is itself being run at
4482 the IPython interactive prompt with '%run <filename>'. Since it's easy
4497 the IPython interactive prompt with '%run <filename>'. Since it's easy
4483 to get lost as to where you are (in your top-level IPython or in your
4498 to get lost as to where you are (in your top-level IPython or in your
4484 embedded one), it's a good idea in such cases to set the in/out prompts
4499 embedded one), it's a good idea in such cases to set the in/out prompts
4485 to something different for the embedded instances. The code examples
4500 to something different for the embedded instances. The code examples
4486 below illustrate this.
4501 below illustrate this.
4487
4502
4488 You can also have multiple IPython instances in your program and open
4503 You can also have multiple IPython instances in your program and open
4489 them separately, for example with different options for data
4504 them separately, for example with different options for data
4490 presentation. If you close and open the same instance multiple times,
4505 presentation. If you close and open the same instance multiple times,
4491 its prompt counters simply continue from each execution to the next.
4506 its prompt counters simply continue from each execution to the next.
4492
4507
4493 Please look at the docstrings in the Shell.py module for more details on
4508 Please look at the docstrings in the Shell.py module for more details on
4494 the use of this system.
4509 the use of this system.
4495
4510
4496 The following sample file illustrating how to use the embedding
4511 The following sample file illustrating how to use the embedding
4497 functionality is provided in the examples directory as example-embed.py.
4512 functionality is provided in the examples directory as example-embed.py.
4498 It should be fairly self-explanatory::
4513 It should be fairly self-explanatory::
4499
4514
4500
4515
4501 #!/usr/bin/env python
4516 #!/usr/bin/env python
4502
4517
4503 """An example of how to embed an IPython shell into a running program.
4518 """An example of how to embed an IPython shell into a running program.
4504
4519
4505 Please see the documentation in the IPython.Shell module for more details.
4520 Please see the documentation in the IPython.Shell module for more details.
4506
4521
4507 The accompanying file example-embed-short.py has quick code fragments for
4522 The accompanying file example-embed-short.py has quick code fragments for
4508 embedding which you can cut and paste in your code once you understand how
4523 embedding which you can cut and paste in your code once you understand how
4509 things work.
4524 things work.
4510
4525
4511 The code in this file is deliberately extra-verbose, meant for learning."""
4526 The code in this file is deliberately extra-verbose, meant for learning."""
4512
4527
4513 # The basics to get you going:
4528 # The basics to get you going:
4514
4529
4515 # IPython sets the __IPYTHON__ variable so you can know if you have nested
4530 # IPython sets the __IPYTHON__ variable so you can know if you have nested
4516 # copies running.
4531 # copies running.
4517
4532
4518 # Try running this code both at the command line and from inside IPython (with
4533 # Try running this code both at the command line and from inside IPython (with
4519 # %run example-embed.py)
4534 # %run example-embed.py)
4520 try:
4535 try:
4521 __IPYTHON__
4536 __IPYTHON__
4522 except NameError:
4537 except NameError:
4523 nested = 0
4538 nested = 0
4524 args = ['']
4539 args = ['']
4525 else:
4540 else:
4526 print "Running nested copies of IPython."
4541 print "Running nested copies of IPython."
4527 print "The prompts for the nested copy have been modified"
4542 print "The prompts for the nested copy have been modified"
4528 nested = 1
4543 nested = 1
4529 # what the embedded instance will see as sys.argv:
4544 # what the embedded instance will see as sys.argv:
4530 args = ['-pi1','In <\\#>: ','-pi2',' .\\D.: ',
4545 args = ['-pi1','In <\\#>: ','-pi2',' .\\D.: ',
4531 '-po','Out<\\#>: ','-nosep']
4546 '-po','Out<\\#>: ','-nosep']
4532
4547
4533 # First import the embeddable shell class
4548 # First import the embeddable shell class
4534 from IPython.Shell import IPShellEmbed
4549 from IPython.Shell import IPShellEmbed
4535
4550
4536 # Now create an instance of the embeddable shell. The first argument is a
4551 # Now create an instance of the embeddable shell. The first argument is a
4537 # string with options exactly as you would type them if you were starting
4552 # string with options exactly as you would type them if you were starting
4538 # IPython at the system command line. Any parameters you want to define for
4553 # IPython at the system command line. Any parameters you want to define for
4539 # configuration can thus be specified here.
4554 # configuration can thus be specified here.
4540 ipshell = IPShellEmbed(args,
4555 ipshell = IPShellEmbed(args,
4541 banner = 'Dropping into IPython',
4556 banner = 'Dropping into IPython',
4542 exit_msg = 'Leaving Interpreter, back to program.')
4557 exit_msg = 'Leaving Interpreter, back to program.')
4543
4558
4544 # Make a second instance, you can have as many as you want.
4559 # Make a second instance, you can have as many as you want.
4545 if nested:
4560 if nested:
4546 args[1] = 'In2<\\#>'
4561 args[1] = 'In2<\\#>'
4547 else:
4562 else:
4548 args = ['-pi1','In2<\\#>: ','-pi2',' .\\D.: ',
4563 args = ['-pi1','In2<\\#>: ','-pi2',' .\\D.: ',
4549 '-po','Out<\\#>: ','-nosep']
4564 '-po','Out<\\#>: ','-nosep']
4550 ipshell2 = IPShellEmbed(args,banner = 'Second IPython instance.')
4565 ipshell2 = IPShellEmbed(args,banner = 'Second IPython instance.')
4551
4566
4552 print '\nHello. This is printed from the main controller program.\n'
4567 print '\nHello. This is printed from the main controller program.\n'
4553
4568
4554 # You can then call ipshell() anywhere you need it (with an optional
4569 # You can then call ipshell() anywhere you need it (with an optional
4555 # message):
4570 # message):
4556 ipshell('***Called from top level. '
4571 ipshell('***Called from top level. '
4557 'Hit Ctrl-D to exit interpreter and continue program.\n'
4572 'Hit Ctrl-D to exit interpreter and continue program.\n'
4558 'Note that if you use %kill_embedded, you can fully deactivate\n'
4573 'Note that if you use %kill_embedded, you can fully deactivate\n'
4559 'This embedded instance so it will never turn on again')
4574 'This embedded instance so it will never turn on again')
4560
4575
4561 print '\nBack in caller program, moving along...\n'
4576 print '\nBack in caller program, moving along...\n'
4562
4577
4563 #---------------------------------------------------------------------------
4578 #---------------------------------------------------------------------------
4564 # More details:
4579 # More details:
4565
4580
4566 # IPShellEmbed instances don't print the standard system banner and
4581 # IPShellEmbed instances don't print the standard system banner and
4567 # messages. The IPython banner (which actually may contain initialization
4582 # messages. The IPython banner (which actually may contain initialization
4568 # messages) is available as <instance>.IP.BANNER in case you want it.
4583 # messages) is available as <instance>.IP.BANNER in case you want it.
4569
4584
4570 # IPShellEmbed instances print the following information everytime they
4585 # IPShellEmbed instances print the following information everytime they
4571 # start:
4586 # start:
4572
4587
4573 # - A global startup banner.
4588 # - A global startup banner.
4574
4589
4575 # - A call-specific header string, which you can use to indicate where in the
4590 # - A call-specific header string, which you can use to indicate where in the
4576 # execution flow the shell is starting.
4591 # execution flow the shell is starting.
4577
4592
4578 # They also print an exit message every time they exit.
4593 # They also print an exit message every time they exit.
4579
4594
4580 # Both the startup banner and the exit message default to None, and can be set
4595 # Both the startup banner and the exit message default to None, and can be set
4581 # either at the instance constructor or at any other time with the
4596 # either at the instance constructor or at any other time with the
4582 # set_banner() and set_exit_msg() methods.
4597 # set_banner() and set_exit_msg() methods.
4583
4598
4584 # The shell instance can be also put in 'dummy' mode globally or on a per-call
4599 # The shell instance can be also put in 'dummy' mode globally or on a per-call
4585 # basis. This gives you fine control for debugging without having to change
4600 # basis. This gives you fine control for debugging without having to change
4586 # code all over the place.
4601 # code all over the place.
4587
4602
4588 # The code below illustrates all this.
4603 # The code below illustrates all this.
4589
4604
4590
4605
4591 # This is how the global banner and exit_msg can be reset at any point
4606 # This is how the global banner and exit_msg can be reset at any point
4592 ipshell.set_banner('Entering interpreter - New Banner')
4607 ipshell.set_banner('Entering interpreter - New Banner')
4593 ipshell.set_exit_msg('Leaving interpreter - New exit_msg')
4608 ipshell.set_exit_msg('Leaving interpreter - New exit_msg')
4594
4609
4595 def foo(m):
4610 def foo(m):
4596 s = 'spam'
4611 s = 'spam'
4597 ipshell('***In foo(). Try @whos, or print s or m:')
4612 ipshell('***In foo(). Try @whos, or print s or m:')
4598 print 'foo says m = ',m
4613 print 'foo says m = ',m
4599
4614
4600 def bar(n):
4615 def bar(n):
4601 s = 'eggs'
4616 s = 'eggs'
4602 ipshell('***In bar(). Try @whos, or print s or n:')
4617 ipshell('***In bar(). Try @whos, or print s or n:')
4603 print 'bar says n = ',n
4618 print 'bar says n = ',n
4604
4619
4605 # Some calls to the above functions which will trigger IPython:
4620 # Some calls to the above functions which will trigger IPython:
4606 print 'Main program calling foo("eggs")\n'
4621 print 'Main program calling foo("eggs")\n'
4607 foo('eggs')
4622 foo('eggs')
4608
4623
4609 # The shell can be put in 'dummy' mode where calls to it silently return. This
4624 # The shell can be put in 'dummy' mode where calls to it silently return. This
4610 # allows you, for example, to globally turn off debugging for a program with a
4625 # allows you, for example, to globally turn off debugging for a program with a
4611 # single call.
4626 # single call.
4612 ipshell.set_dummy_mode(1)
4627 ipshell.set_dummy_mode(1)
4613 print '\nTrying to call IPython which is now "dummy":'
4628 print '\nTrying to call IPython which is now "dummy":'
4614 ipshell()
4629 ipshell()
4615 print 'Nothing happened...'
4630 print 'Nothing happened...'
4616 # The global 'dummy' mode can still be overridden for a single call
4631 # The global 'dummy' mode can still be overridden for a single call
4617 print '\nOverriding dummy mode manually:'
4632 print '\nOverriding dummy mode manually:'
4618 ipshell(dummy=0)
4633 ipshell(dummy=0)
4619
4634
4620 # Reactivate the IPython shell
4635 # Reactivate the IPython shell
4621 ipshell.set_dummy_mode(0)
4636 ipshell.set_dummy_mode(0)
4622
4637
4623 print 'You can even have multiple embedded instances:'
4638 print 'You can even have multiple embedded instances:'
4624 ipshell2()
4639 ipshell2()
4625
4640
4626 print '\nMain program calling bar("spam")\n'
4641 print '\nMain program calling bar("spam")\n'
4627 bar('spam')
4642 bar('spam')
4628
4643
4629 print 'Main program finished. Bye!'
4644 print 'Main program finished. Bye!'
4630
4645
4631 #********************** End of file <example-embed.py> ***********************
4646 #********************** End of file <example-embed.py> ***********************
4632
4647
4633 Once you understand how the system functions, you can use the following
4648 Once you understand how the system functions, you can use the following
4634 code fragments in your programs which are ready for cut and paste::
4649 code fragments in your programs which are ready for cut and paste::
4635
4650
4636
4651
4637 """Quick code snippets for embedding IPython into other programs.
4652 """Quick code snippets for embedding IPython into other programs.
4638
4653
4639 See example-embed.py for full details, this file has the bare minimum code for
4654 See example-embed.py for full details, this file has the bare minimum code for
4640 cut and paste use once you understand how to use the system."""
4655 cut and paste use once you understand how to use the system."""
4641
4656
4642 #---------------------------------------------------------------------------
4657 #---------------------------------------------------------------------------
4643 # This code loads IPython but modifies a few things if it detects it's running
4658 # This code loads IPython but modifies a few things if it detects it's running
4644 # embedded in another IPython session (helps avoid confusion)
4659 # embedded in another IPython session (helps avoid confusion)
4645
4660
4646 try:
4661 try:
4647 __IPYTHON__
4662 __IPYTHON__
4648 except NameError:
4663 except NameError:
4649 argv = ['']
4664 argv = ['']
4650 banner = exit_msg = ''
4665 banner = exit_msg = ''
4651 else:
4666 else:
4652 # Command-line options for IPython (a list like sys.argv)
4667 # Command-line options for IPython (a list like sys.argv)
4653 argv = ['-pi1','In <\\#>:','-pi2',' .\\D.:','-po','Out<\\#>:']
4668 argv = ['-pi1','In <\\#>:','-pi2',' .\\D.:','-po','Out<\\#>:']
4654 banner = '*** Nested interpreter ***'
4669 banner = '*** Nested interpreter ***'
4655 exit_msg = '*** Back in main IPython ***'
4670 exit_msg = '*** Back in main IPython ***'
4656
4671
4657 # First import the embeddable shell class
4672 # First import the embeddable shell class
4658 from IPython.Shell import IPShellEmbed
4673 from IPython.Shell import IPShellEmbed
4659 # Now create the IPython shell instance. Put ipshell() anywhere in your code
4674 # Now create the IPython shell instance. Put ipshell() anywhere in your code
4660 # where you want it to open.
4675 # where you want it to open.
4661 ipshell = IPShellEmbed(argv,banner=banner,exit_msg=exit_msg)
4676 ipshell = IPShellEmbed(argv,banner=banner,exit_msg=exit_msg)
4662
4677
4663 #---------------------------------------------------------------------------
4678 #---------------------------------------------------------------------------
4664 # This code will load an embeddable IPython shell always with no changes for
4679 # This code will load an embeddable IPython shell always with no changes for
4665 # nested embededings.
4680 # nested embededings.
4666
4681
4667 from IPython.Shell import IPShellEmbed
4682 from IPython.Shell import IPShellEmbed
4668 ipshell = IPShellEmbed()
4683 ipshell = IPShellEmbed()
4669 # Now ipshell() will open IPython anywhere in the code.
4684 # Now ipshell() will open IPython anywhere in the code.
4670
4685
4671 #---------------------------------------------------------------------------
4686 #---------------------------------------------------------------------------
4672 # This code loads an embeddable shell only if NOT running inside
4687 # This code loads an embeddable shell only if NOT running inside
4673 # IPython. Inside IPython, the embeddable shell variable ipshell is just a
4688 # IPython. Inside IPython, the embeddable shell variable ipshell is just a
4674 # dummy function.
4689 # dummy function.
4675
4690
4676 try:
4691 try:
4677 __IPYTHON__
4692 __IPYTHON__
4678 except NameError:
4693 except NameError:
4679 from IPython.Shell import IPShellEmbed
4694 from IPython.Shell import IPShellEmbed
4680 ipshell = IPShellEmbed()
4695 ipshell = IPShellEmbed()
4681 # Now ipshell() will open IPython anywhere in the code
4696 # Now ipshell() will open IPython anywhere in the code
4682 else:
4697 else:
4683 # Define a dummy ipshell() so the same code doesn't crash inside an
4698 # Define a dummy ipshell() so the same code doesn't crash inside an
4684 # interactive IPython
4699 # interactive IPython
4685 def ipshell(): pass
4700 def ipshell(): pass
4686
4701
4687 #******************* End of file <example-embed-short.py> ********************
4702 #******************* End of file <example-embed-short.py> ********************
4688
4703
4689 Using the Python debugger (pdb)
4704 Using the Python debugger (pdb)
4690 ===============================
4705 ===============================
4691
4706
4692 Running entire programs via pdb
4707 Running entire programs via pdb
4693 -------------------------------
4708 -------------------------------
4694
4709
4695 pdb, the Python debugger, is a powerful interactive debugger which
4710 pdb, the Python debugger, is a powerful interactive debugger which
4696 allows you to step through code, set breakpoints, watch variables,
4711 allows you to step through code, set breakpoints, watch variables,
4697 etc. IPython makes it very easy to start any script under the control
4712 etc. IPython makes it very easy to start any script under the control
4698 of pdb, regardless of whether you have wrapped it into a 'main()'
4713 of pdb, regardless of whether you have wrapped it into a 'main()'
4699 function or not. For this, simply type '%run -d myscript' at an
4714 function or not. For this, simply type '%run -d myscript' at an
4700 IPython prompt. See the %run command's documentation (via '%run?' or
4715 IPython prompt. See the %run command's documentation (via '%run?' or
4701 in Sec. magic_ for more details, including how to control where pdb
4716 in Sec. magic_ for more details, including how to control where pdb
4702 will stop execution first.
4717 will stop execution first.
4703
4718
4704 For more information on the use of the pdb debugger, read the included
4719 For more information on the use of the pdb debugger, read the included
4705 pdb.doc file (part of the standard Python distribution). On a stock
4720 pdb.doc file (part of the standard Python distribution). On a stock
4706 Linux system it is located at /usr/lib/python2.3/pdb.doc, but the
4721 Linux system it is located at /usr/lib/python2.3/pdb.doc, but the
4707 easiest way to read it is by using the help() function of the pdb module
4722 easiest way to read it is by using the help() function of the pdb module
4708 as follows (in an IPython prompt):
4723 as follows (in an IPython prompt):
4709
4724
4710 In [1]: import pdb
4725 In [1]: import pdb
4711 In [2]: pdb.help()
4726 In [2]: pdb.help()
4712
4727
4713 This will load the pdb.doc document in a file viewer for you automatically.
4728 This will load the pdb.doc document in a file viewer for you automatically.
4714
4729
4715
4730
4716 Automatic invocation of pdb on exceptions
4731 Automatic invocation of pdb on exceptions
4717 -----------------------------------------
4732 -----------------------------------------
4718
4733
4719 IPython, if started with the -pdb option (or if the option is set in
4734 IPython, if started with the -pdb option (or if the option is set in
4720 your rc file) can call the Python pdb debugger every time your code
4735 your rc file) can call the Python pdb debugger every time your code
4721 triggers an uncaught exception. This feature
4736 triggers an uncaught exception. This feature
4722 can also be toggled at any time with the %pdb magic command. This can be
4737 can also be toggled at any time with the %pdb magic command. This can be
4723 extremely useful in order to find the origin of subtle bugs, because pdb
4738 extremely useful in order to find the origin of subtle bugs, because pdb
4724 opens up at the point in your code which triggered the exception, and
4739 opens up at the point in your code which triggered the exception, and
4725 while your program is at this point 'dead', all the data is still
4740 while your program is at this point 'dead', all the data is still
4726 available and you can walk up and down the stack frame and understand
4741 available and you can walk up and down the stack frame and understand
4727 the origin of the problem.
4742 the origin of the problem.
4728
4743
4729 Furthermore, you can use these debugging facilities both with the
4744 Furthermore, you can use these debugging facilities both with the
4730 embedded IPython mode and without IPython at all. For an embedded shell
4745 embedded IPython mode and without IPython at all. For an embedded shell
4731 (see sec. Embedding_), simply call the constructor with
4746 (see sec. Embedding_), simply call the constructor with
4732 '-pdb' in the argument string and automatically pdb will be called if an
4747 '-pdb' in the argument string and automatically pdb will be called if an
4733 uncaught exception is triggered by your code.
4748 uncaught exception is triggered by your code.
4734
4749
4735 For stand-alone use of the feature in your programs which do not use
4750 For stand-alone use of the feature in your programs which do not use
4736 IPython at all, put the following lines toward the top of your 'main'
4751 IPython at all, put the following lines toward the top of your 'main'
4737 routine::
4752 routine::
4738
4753
4739 import sys,IPython.ultraTB
4754 import sys,IPython.ultraTB
4740 sys.excepthook = IPython.ultraTB.FormattedTB(mode='Verbose',
4755 sys.excepthook = IPython.ultraTB.FormattedTB(mode='Verbose',
4741 color_scheme='Linux', call_pdb=1)
4756 color_scheme='Linux', call_pdb=1)
4742
4757
4743 The mode keyword can be either 'Verbose' or 'Plain', giving either very
4758 The mode keyword can be either 'Verbose' or 'Plain', giving either very
4744 detailed or normal tracebacks respectively. The color_scheme keyword can
4759 detailed or normal tracebacks respectively. The color_scheme keyword can
4745 be one of 'NoColor', 'Linux' (default) or 'LightBG'. These are the same
4760 be one of 'NoColor', 'Linux' (default) or 'LightBG'. These are the same
4746 options which can be set in IPython with -colors and -xmode.
4761 options which can be set in IPython with -colors and -xmode.
4747
4762
4748 This will give any of your programs detailed, colored tracebacks with
4763 This will give any of your programs detailed, colored tracebacks with
4749 automatic invocation of pdb.
4764 automatic invocation of pdb.
4750
4765
4751
4766
4752 Extensions for syntax processing
4767 Extensions for syntax processing
4753 ================================
4768 ================================
4754
4769
4755 This isn't for the faint of heart, because the potential for breaking
4770 This isn't for the faint of heart, because the potential for breaking
4756 things is quite high. But it can be a very powerful and useful feature.
4771 things is quite high. But it can be a very powerful and useful feature.
4757 In a nutshell, you can redefine the way IPython processes the user input
4772 In a nutshell, you can redefine the way IPython processes the user input
4758 line to accept new, special extensions to the syntax without needing to
4773 line to accept new, special extensions to the syntax without needing to
4759 change any of IPython's own code.
4774 change any of IPython's own code.
4760
4775
4761 In the IPython/Extensions directory you will find some examples
4776 In the IPython/Extensions directory you will find some examples
4762 supplied, which we will briefly describe now. These can be used 'as is'
4777 supplied, which we will briefly describe now. These can be used 'as is'
4763 (and both provide very useful functionality), or you can use them as a
4778 (and both provide very useful functionality), or you can use them as a
4764 starting point for writing your own extensions.
4779 starting point for writing your own extensions.
4765
4780
4766
4781
4767 Pasting of code starting with '>>> ' or '... '
4782 Pasting of code starting with '>>> ' or '... '
4768 ----------------------------------------------
4783 ----------------------------------------------
4769
4784
4770 In the python tutorial it is common to find code examples which have
4785 In the python tutorial it is common to find code examples which have
4771 been taken from real python sessions. The problem with those is that all
4786 been taken from real python sessions. The problem with those is that all
4772 the lines begin with either '>>> ' or '... ', which makes it impossible
4787 the lines begin with either '>>> ' or '... ', which makes it impossible
4773 to paste them all at once. One must instead do a line by line manual
4788 to paste them all at once. One must instead do a line by line manual
4774 copying, carefully removing the leading extraneous characters.
4789 copying, carefully removing the leading extraneous characters.
4775
4790
4776 This extension identifies those starting characters and removes them
4791 This extension identifies those starting characters and removes them
4777 from the input automatically, so that one can paste multi-line examples
4792 from the input automatically, so that one can paste multi-line examples
4778 directly into IPython, saving a lot of time. Please look at the file
4793 directly into IPython, saving a lot of time. Please look at the file
4779 InterpreterPasteInput.py in the IPython/Extensions directory for details
4794 InterpreterPasteInput.py in the IPython/Extensions directory for details
4780 on how this is done.
4795 on how this is done.
4781
4796
4782 IPython comes with a special profile enabling this feature, called
4797 IPython comes with a special profile enabling this feature, called
4783 tutorial. Simply start IPython via 'ipython -p tutorial' and the feature
4798 tutorial. Simply start IPython via 'ipython -p tutorial' and the feature
4784 will be available. In a normal IPython session you can activate the
4799 will be available. In a normal IPython session you can activate the
4785 feature by importing the corresponding module with:
4800 feature by importing the corresponding module with:
4786 In [1]: import IPython.Extensions.InterpreterPasteInput
4801 In [1]: import IPython.Extensions.InterpreterPasteInput
4787
4802
4788 The following is a 'screenshot' of how things work when this extension
4803 The following is a 'screenshot' of how things work when this extension
4789 is on, copying an example from the standard tutorial::
4804 is on, copying an example from the standard tutorial::
4790
4805
4791 IPython profile: tutorial
4806 IPython profile: tutorial
4792
4807
4793 *** Pasting of code with ">>>" or "..." has been enabled.
4808 *** Pasting of code with ">>>" or "..." has been enabled.
4794
4809
4795 In [1]: >>> def fib2(n): # return Fibonacci series up to n
4810 In [1]: >>> def fib2(n): # return Fibonacci series up to n
4796 ...: ... """Return a list containing the Fibonacci series up to
4811 ...: ... """Return a list containing the Fibonacci series up to
4797 n."""
4812 n."""
4798 ...: ... result = []
4813 ...: ... result = []
4799 ...: ... a, b = 0, 1
4814 ...: ... a, b = 0, 1
4800 ...: ... while b < n:
4815 ...: ... while b < n:
4801 ...: ... result.append(b) # see below
4816 ...: ... result.append(b) # see below
4802 ...: ... a, b = b, a+b
4817 ...: ... a, b = b, a+b
4803 ...: ... return result
4818 ...: ... return result
4804 ...:
4819 ...:
4805
4820
4806 In [2]: fib2(10)
4821 In [2]: fib2(10)
4807 Out[2]: [1, 1, 2, 3, 5, 8]
4822 Out[2]: [1, 1, 2, 3, 5, 8]
4808
4823
4809 Note that as currently written, this extension does not recognize
4824 Note that as currently written, this extension does not recognize
4810 IPython's prompts for pasting. Those are more complicated, since the
4825 IPython's prompts for pasting. Those are more complicated, since the
4811 user can change them very easily, they involve numbers and can vary in
4826 user can change them very easily, they involve numbers and can vary in
4812 length. One could however extract all the relevant information from the
4827 length. One could however extract all the relevant information from the
4813 IPython instance and build an appropriate regular expression. This is
4828 IPython instance and build an appropriate regular expression. This is
4814 left as an exercise for the reader.
4829 left as an exercise for the reader.
4815
4830
4816
4831
4817 Input of physical quantities with units
4832 Input of physical quantities with units
4818 ---------------------------------------
4833 ---------------------------------------
4819
4834
4820 The module PhysicalQInput allows a simplified form of input for physical
4835 The module PhysicalQInput allows a simplified form of input for physical
4821 quantities with units. This file is meant to be used in conjunction with
4836 quantities with units. This file is meant to be used in conjunction with
4822 the PhysicalQInteractive module (in the same directory) and
4837 the PhysicalQInteractive module (in the same directory) and
4823 Physics.PhysicalQuantities from Konrad Hinsen's ScientificPython
4838 Physics.PhysicalQuantities from Konrad Hinsen's ScientificPython
4824 (http://dirac.cnrs-orleans.fr/ScientificPython/).
4839 (http://dirac.cnrs-orleans.fr/ScientificPython/).
4825
4840
4826 The Physics.PhysicalQuantities module defines PhysicalQuantity objects,
4841 The Physics.PhysicalQuantities module defines PhysicalQuantity objects,
4827 but these must be declared as instances of a class. For example, to
4842 but these must be declared as instances of a class. For example, to
4828 define v as a velocity of 3 m/s, normally you would write::
4843 define v as a velocity of 3 m/s, normally you would write::
4829
4844
4830 In [1]: v = PhysicalQuantity(3,'m/s')
4845 In [1]: v = PhysicalQuantity(3,'m/s')
4831
4846
4832 Using the PhysicalQ_Input extension this can be input instead as:
4847 Using the PhysicalQ_Input extension this can be input instead as:
4833 In [1]: v = 3 m/s
4848 In [1]: v = 3 m/s
4834 which is much more convenient for interactive use (even though it is
4849 which is much more convenient for interactive use (even though it is
4835 blatantly invalid Python syntax).
4850 blatantly invalid Python syntax).
4836
4851
4837 The physics profile supplied with IPython (enabled via 'ipython -p
4852 The physics profile supplied with IPython (enabled via 'ipython -p
4838 physics') uses these extensions, which you can also activate with:
4853 physics') uses these extensions, which you can also activate with:
4839
4854
4840 from math import * # math MUST be imported BEFORE PhysicalQInteractive
4855 from math import * # math MUST be imported BEFORE PhysicalQInteractive
4841 from IPython.Extensions.PhysicalQInteractive import *
4856 from IPython.Extensions.PhysicalQInteractive import *
4842 import IPython.Extensions.PhysicalQInput
4857 import IPython.Extensions.PhysicalQInput
4843
4858
4844
4859
4845 IPython as a system shell - the 'Sh' profile
4860 IPython as a system shell - the 'Sh' profile
4846 ============================================
4861 ============================================
4847
4862
4848 The 'sh' profile optimizes IPython for system shell usage. Apart from
4863 The 'sh' profile optimizes IPython for system shell usage. Apart from
4849 certain job control functionality that is present in unix (ctrl+z does
4864 certain job control functionality that is present in unix (ctrl+z does
4850 "suspend"), the sh profile should provide you with most of the
4865 "suspend"), the sh profile should provide you with most of the
4851 functionality you use daily in system shell, and more. Invoke IPython
4866 functionality you use daily in system shell, and more. Invoke IPython
4852 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
4867 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
4853 the "pysh" shortcut in start menu.
4868 the "pysh" shortcut in start menu.
4854
4869
4855 If you want to use the features of sh profile as your defaults (which
4870 If you want to use the features of sh profile as your defaults (which
4856 might be a good idea if you use other profiles a lot of the time but
4871 might be a good idea if you use other profiles a lot of the time but
4857 still want the convenience of sh profile), add ``import ipy_profile_sh``
4872 still want the convenience of sh profile), add ``import ipy_profile_sh``
4858 to your ~/.ipython/ipy_user_conf.py.
4873 to your ~/.ipython/ipy_user_conf.py.
4859
4874
4860 The 'sh' profile is different from the default profile in that:
4875 The 'sh' profile is different from the default profile in that:
4861
4876
4862 * Prompt shows the current directory
4877 * Prompt shows the current directory
4863 * Spacing between prompts and input is more compact (no padding with
4878 * Spacing between prompts and input is more compact (no padding with
4864 empty lines). The startup banner is more compact as well.
4879 empty lines). The startup banner is more compact as well.
4865 * System commands are directly available (in alias table) without
4880 * System commands are directly available (in alias table) without
4866 requesting %rehashx - however, if you install new programs along
4881 requesting %rehashx - however, if you install new programs along
4867 your PATH, you might want to run %rehashx to update the persistent
4882 your PATH, you might want to run %rehashx to update the persistent
4868 alias table
4883 alias table
4869 * Macros are stored in raw format by default. That is, instead of
4884 * Macros are stored in raw format by default. That is, instead of
4870 '_ip.system("cat foo"), the macro will contain text 'cat foo')
4885 '_ip.system("cat foo"), the macro will contain text 'cat foo')
4871 * Autocall is in full mode
4886 * Autocall is in full mode
4872 * Calling "up" does "cd .."
4887 * Calling "up" does "cd .."
4873
4888
4874 The 'sh' profile is different from the now-obsolete (and unavailable)
4889 The 'sh' profile is different from the now-obsolete (and unavailable)
4875 'pysh' profile in that:
4890 'pysh' profile in that:
4876
4891
4877 * '$$var = command' and '$var = command' syntax is not supported
4892 * '$$var = command' and '$var = command' syntax is not supported
4878 * anymore. Use 'var = !command' instead (incidentally, this is
4893 * anymore. Use 'var = !command' instead (incidentally, this is
4879 * available in all IPython profiles). Note that !!command *will*
4894 * available in all IPython profiles). Note that !!command *will*
4880 * work.
4895 * work.
4881
4896
4882 Aliases
4897 Aliases
4883 -------
4898 -------
4884
4899
4885 All of your $PATH has been loaded as IPython aliases, so you should be
4900 All of your $PATH has been loaded as IPython aliases, so you should be
4886 able to type any normal system command and have it executed. See
4901 able to type any normal system command and have it executed. See
4887 %alias? and %unalias? for details on the alias facilities. See also
4902 %alias? and %unalias? for details on the alias facilities. See also
4888 %rehashx? for details on the mechanism used to load $PATH.
4903 %rehashx? for details on the mechanism used to load $PATH.
4889
4904
4890
4905
4891 Directory management
4906 Directory management
4892 --------------------
4907 --------------------
4893
4908
4894 Since each command passed by ipython to the underlying system is executed
4909 Since each command passed by ipython to the underlying system is executed
4895 in a subshell which exits immediately, you can NOT use !cd to navigate
4910 in a subshell which exits immediately, you can NOT use !cd to navigate
4896 the filesystem.
4911 the filesystem.
4897
4912
4898 IPython provides its own builtin '%cd' magic command to move in the
4913 IPython provides its own builtin '%cd' magic command to move in the
4899 filesystem (the % is not required with automagic on). It also maintains
4914 filesystem (the % is not required with automagic on). It also maintains
4900 a list of visited directories (use %dhist to see it) and allows direct
4915 a list of visited directories (use %dhist to see it) and allows direct
4901 switching to any of them. Type 'cd?' for more details.
4916 switching to any of them. Type 'cd?' for more details.
4902
4917
4903 %pushd, %popd and %dirs are provided for directory stack handling.
4918 %pushd, %popd and %dirs are provided for directory stack handling.
4904
4919
4905
4920
4906 Enabled extensions
4921 Enabled extensions
4907 ------------------
4922 ------------------
4908
4923
4909 Some extensions, listed below, are enabled as default in this profile.
4924 Some extensions, listed below, are enabled as default in this profile.
4910
4925
4911 envpersist
4926 envpersist
4912 ++++++++++
4927 ++++++++++
4913
4928
4914 %env can be used to "remember" environment variable manipulations. Examples::
4929 %env can be used to "remember" environment variable manipulations. Examples::
4915
4930
4916 %env - Show all environment variables
4931 %env - Show all environment variables
4917 %env VISUAL=jed - set VISUAL to jed
4932 %env VISUAL=jed - set VISUAL to jed
4918 %env PATH+=;/foo - append ;foo to PATH
4933 %env PATH+=;/foo - append ;foo to PATH
4919 %env PATH+=;/bar - also append ;bar to PATH
4934 %env PATH+=;/bar - also append ;bar to PATH
4920 %env PATH-=/wbin; - prepend /wbin; to PATH
4935 %env PATH-=/wbin; - prepend /wbin; to PATH
4921 %env -d VISUAL - forget VISUAL persistent val
4936 %env -d VISUAL - forget VISUAL persistent val
4922 %env -p - print all persistent env modifications
4937 %env -p - print all persistent env modifications
4923
4938
4924 ipy_which
4939 ipy_which
4925 +++++++++
4940 +++++++++
4926
4941
4927 %which magic command. Like 'which' in unix, but knows about ipython aliases.
4942 %which magic command. Like 'which' in unix, but knows about ipython aliases.
4928
4943
4929 Example::
4944 Example::
4930
4945
4931 [C:/ipython]|14> %which st
4946 [C:/ipython]|14> %which st
4932 st -> start .
4947 st -> start .
4933 [C:/ipython]|15> %which d
4948 [C:/ipython]|15> %which d
4934 d -> dir /w /og /on
4949 d -> dir /w /og /on
4935 [C:/ipython]|16> %which cp
4950 [C:/ipython]|16> %which cp
4936 cp -> cp
4951 cp -> cp
4937 == c:\bin\cp.exe
4952 == c:\bin\cp.exe
4938 c:\bin\cp.exe
4953 c:\bin\cp.exe
4939
4954
4940 ipy_app_completers
4955 ipy_app_completers
4941 ++++++++++++++++++
4956 ++++++++++++++++++
4942
4957
4943 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
4958 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
4944
4959
4945 ipy_rehashdir
4960 ipy_rehashdir
4946 +++++++++++++
4961 +++++++++++++
4947
4962
4948 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::
4963 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::
4949
4964
4950 [~]|22> cd c:/opt/PuTTY/
4965 [~]|22> cd c:/opt/PuTTY/
4951 [c:opt/PuTTY]|23> rehashdir .
4966 [c:opt/PuTTY]|23> rehashdir .
4952 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
4967 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
4953
4968
4954 Now, you can execute any of those commams directly::
4969 Now, you can execute any of those commams directly::
4955
4970
4956 [c:opt/PuTTY]|24> cd
4971 [c:opt/PuTTY]|24> cd
4957 [~]|25> putty
4972 [~]|25> putty
4958
4973
4959 (the putty window opens).
4974 (the putty window opens).
4960
4975
4961 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::
4976 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::
4962
4977
4963 [~]|27> for a in _23:
4978 [~]|27> for a in _23:
4964 |..> %store $a
4979 |..> %store $a
4965 |..>
4980 |..>
4966 |..>
4981 |..>
4967 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
4982 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
4968 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
4983 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
4969 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
4984 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
4970 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
4985 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
4971 ...
4986 ...
4972
4987
4973 mglob
4988 mglob
4974 +++++
4989 +++++
4975
4990
4976 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
4991 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
4977
4992
4978 [c:/ipython]|9> mglob *.py
4993 [c:/ipython]|9> mglob *.py
4979 [c:/ipython]|10> mglob *.py rec:*.txt
4994 [c:/ipython]|10> mglob *.py rec:*.txt
4980 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
4995 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
4981
4996
4982 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'.
4997 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'.
4983
4998
4984
4999
4985 Prompt customization
5000 Prompt customization
4986 --------------------
5001 --------------------
4987
5002
4988 The sh profile uses the following prompt configurations::
5003 The sh profile uses the following prompt configurations::
4989
5004
4990 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
5005 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
4991 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
5006 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
4992
5007
4993 You can change the prompt configuration to your liking by editing
5008 You can change the prompt configuration to your liking by editing
4994 ipy_user_conf.py.
5009 ipy_user_conf.py.
4995
5010
4996 String lists
5011 String lists
4997 ============
5012 ============
4998
5013
4999 String lists (IPython.genutils.SList) are handy way to process output
5014 String lists (IPython.genutils.SList) are handy way to process output
5000 from system commands. They are produced by ``var = !cmd`` syntax.
5015 from system commands. They are produced by ``var = !cmd`` syntax.
5001
5016
5002 First, we acquire the output of 'ls -l'::
5017 First, we acquire the output of 'ls -l'::
5003
5018
5004 [Q:doc/examples]|2> lines = !ls -l
5019 [Q:doc/examples]|2> lines = !ls -l
5005 ==
5020 ==
5006 ['total 23',
5021 ['total 23',
5007 '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
5022 '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
5008 '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
5023 '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
5009 '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
5024 '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
5010 '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
5025 '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
5011 '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
5026 '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
5012 '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
5027 '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
5013 '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
5028 '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
5014
5029
5015 Now, let's take a look at the contents of 'lines' (the first number is
5030 Now, let's take a look at the contents of 'lines' (the first number is
5016 the list element number)::
5031 the list element number)::
5017
5032
5018 [Q:doc/examples]|3> lines
5033 [Q:doc/examples]|3> lines
5019 <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
5034 <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
5020
5035
5021 0: total 23
5036 0: total 23
5022 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
5037 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
5023 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
5038 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
5024 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
5039 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
5025 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
5040 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
5026 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
5041 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
5027 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
5042 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
5028 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
5043 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
5029
5044
5030 Now, let's filter out the 'embed' lines::
5045 Now, let's filter out the 'embed' lines::
5031
5046
5032 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
5047 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
5033 [Q:doc/examples]|5> l2
5048 [Q:doc/examples]|5> l2
5034 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
5049 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
5035
5050
5036 0: total 23
5051 0: total 23
5037 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
5052 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
5038 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
5053 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
5039 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
5054 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
5040 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
5055 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
5041 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
5056 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
5042
5057
5043 Now, we want strings having just file names and permissions::
5058 Now, we want strings having just file names and permissions::
5044
5059
5045 [Q:doc/examples]|6> l2.fields(8,0)
5060 [Q:doc/examples]|6> l2.fields(8,0)
5046 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
5061 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
5047
5062
5048 0: total
5063 0: total
5049 1: example-demo.py -rw-rw-rw-
5064 1: example-demo.py -rw-rw-rw-
5050 2: example-gnuplot.py -rwxrwxrwx
5065 2: example-gnuplot.py -rwxrwxrwx
5051 3: extension.py -rwxrwxrwx
5066 3: extension.py -rwxrwxrwx
5052 4: seteditor.py -rwxrwxrwx
5067 4: seteditor.py -rwxrwxrwx
5053 5: seteditor.pyc -rwxrwxrwx
5068 5: seteditor.pyc -rwxrwxrwx
5054
5069
5055 Note how the line with 'total' does not raise IndexError.
5070 Note how the line with 'total' does not raise IndexError.
5056
5071
5057 If you want to split these (yielding lists), call fields() without
5072 If you want to split these (yielding lists), call fields() without
5058 arguments::
5073 arguments::
5059
5074
5060 [Q:doc/examples]|7> _.fields()
5075 [Q:doc/examples]|7> _.fields()
5061 <7>
5076 <7>
5062 [['total'],
5077 [['total'],
5063 ['example-demo.py', '-rw-rw-rw-'],
5078 ['example-demo.py', '-rw-rw-rw-'],
5064 ['example-gnuplot.py', '-rwxrwxrwx'],
5079 ['example-gnuplot.py', '-rwxrwxrwx'],
5065 ['extension.py', '-rwxrwxrwx'],
5080 ['extension.py', '-rwxrwxrwx'],
5066 ['seteditor.py', '-rwxrwxrwx'],
5081 ['seteditor.py', '-rwxrwxrwx'],
5067 ['seteditor.pyc', '-rwxrwxrwx']]
5082 ['seteditor.pyc', '-rwxrwxrwx']]
5068
5083
5069 If you want to pass these separated with spaces to a command (typical
5084 If you want to pass these separated with spaces to a command (typical
5070 for lists if files), use the .s property::
5085 for lists if files), use the .s property::
5071
5086
5072
5087
5073 [Q:doc/examples]|13> files = l2.fields(8).s
5088 [Q:doc/examples]|13> files = l2.fields(8).s
5074 [Q:doc/examples]|14> files
5089 [Q:doc/examples]|14> files
5075 <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
5090 <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
5076 [Q:doc/examples]|15> ls $files
5091 [Q:doc/examples]|15> ls $files
5077 example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
5092 example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
5078
5093
5079 SLists are inherited from normal python lists, so every list method is
5094 SLists are inherited from normal python lists, so every list method is
5080 available::
5095 available::
5081
5096
5082 [Q:doc/examples]|21> lines.append('hey')
5097 [Q:doc/examples]|21> lines.append('hey')
5083
5098
5084
5099
5085 Real world example: remove all files outside version control
5100 Real world example: remove all files outside version control
5086 ------------------------------------------------------------
5101 ------------------------------------------------------------
5087
5102
5088 First, capture output of "hg status"::
5103 First, capture output of "hg status"::
5089
5104
5090 [Q:/ipython]|28> out = !hg status
5105 [Q:/ipython]|28> out = !hg status
5091 ==
5106 ==
5092 ['M IPython\\Extensions\\ipy_kitcfg.py',
5107 ['M IPython\\Extensions\\ipy_kitcfg.py',
5093 'M IPython\\Extensions\\ipy_rehashdir.py',
5108 'M IPython\\Extensions\\ipy_rehashdir.py',
5094 ...
5109 ...
5095 '? build\\lib\\IPython\\Debugger.py',
5110 '? build\\lib\\IPython\\Debugger.py',
5096 '? build\\lib\\IPython\\Extensions\\InterpreterExec.py',
5111 '? build\\lib\\IPython\\Extensions\\InterpreterExec.py',
5097 '? build\\lib\\IPython\\Extensions\\InterpreterPasteInput.py',
5112 '? build\\lib\\IPython\\Extensions\\InterpreterPasteInput.py',
5098 ...
5113 ...
5099
5114
5100 (lines starting with ? are not under version control).
5115 (lines starting with ? are not under version control).
5101
5116
5102 ::
5117 ::
5103
5118
5104 [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
5119 [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
5105 [Q:/ipython]|36> junk
5120 [Q:/ipython]|36> junk
5106 <36> SList (.p, .n, .l, .s, .grep(), .fields() availab
5121 <36> SList (.p, .n, .l, .s, .grep(), .fields() availab
5107 ...
5122 ...
5108 10: build\bdist.win32\winexe\temp\_ctypes.py
5123 10: build\bdist.win32\winexe\temp\_ctypes.py
5109 11: build\bdist.win32\winexe\temp\_hashlib.py
5124 11: build\bdist.win32\winexe\temp\_hashlib.py
5110 12: build\bdist.win32\winexe\temp\_socket.py
5125 12: build\bdist.win32\winexe\temp\_socket.py
5111
5126
5112 Now we can just remove these files by doing 'rm $junk.s'.
5127 Now we can just remove these files by doing 'rm $junk.s'.
5113
5128
5114 The .s, .n, .p properties
5129 The .s, .n, .p properties
5115 -------------------------
5130 -------------------------
5116
5131
5117 The '.s' property returns one string where lines are separated by
5132 The '.s' property returns one string where lines are separated by
5118 single space (for convenient passing to system commands). The '.n'
5133 single space (for convenient passing to system commands). The '.n'
5119 property return one string where the lines are separated by '\n'
5134 property return one string where the lines are separated by '\n'
5120 (i.e. the original output of the function). If the items in string
5135 (i.e. the original output of the function). If the items in string
5121 list are file names, '.p' can be used to get a list of "path" objects
5136 list are file names, '.p' can be used to get a list of "path" objects
5122 for convenient file manipulation.
5137 for convenient file manipulation.
5123
5138
5124
5139
5125 Threading support
5140 Threading support
5126 =================
5141 =================
5127
5142
5128 WARNING: The threading support is still somewhat experimental, and it
5143 WARNING: The threading support is still somewhat experimental, and it
5129 has only seen reasonable testing under Linux. Threaded code is
5144 has only seen reasonable testing under Linux. Threaded code is
5130 particularly tricky to debug, and it tends to show extremely
5145 particularly tricky to debug, and it tends to show extremely
5131 platform-dependent behavior. Since I only have access to Linux machines,
5146 platform-dependent behavior. Since I only have access to Linux machines,
5132 I will have to rely on user's experiences and assistance for this area
5147 I will have to rely on user's experiences and assistance for this area
5133 of IPython to improve under other platforms.
5148 of IPython to improve under other platforms.
5134
5149
5135 IPython, via the -gthread , -qthread, -q4thread and -wthread options
5150 IPython, via the -gthread , -qthread, -q4thread and -wthread options
5136 (described in Sec. `Threading options`_), can run in
5151 (described in Sec. `Threading options`_), can run in
5137 multithreaded mode to support pyGTK, Qt3, Qt4 and WXPython applications
5152 multithreaded mode to support pyGTK, Qt3, Qt4 and WXPython applications
5138 respectively. These GUI toolkits need to control the python main loop of
5153 respectively. These GUI toolkits need to control the python main loop of
5139 execution, so under a normal Python interpreter, starting a pyGTK, Qt3,
5154 execution, so under a normal Python interpreter, starting a pyGTK, Qt3,
5140 Qt4 or WXPython application will immediately freeze the shell.
5155 Qt4 or WXPython application will immediately freeze the shell.
5141
5156
5142 IPython, with one of these options (you can only use one at a time),
5157 IPython, with one of these options (you can only use one at a time),
5143 separates the graphical loop and IPython's code execution run into
5158 separates the graphical loop and IPython's code execution run into
5144 different threads. This allows you to test interactively (with %run, for
5159 different threads. This allows you to test interactively (with %run, for
5145 example) your GUI code without blocking.
5160 example) your GUI code without blocking.
5146
5161
5147 A nice mini-tutorial on using IPython along with the Qt Designer
5162 A nice mini-tutorial on using IPython along with the Qt Designer
5148 application is available at the SciPy wiki:
5163 application is available at the SciPy wiki:
5149 http://www.scipy.org/Cookbook/Matplotlib/Qt_with_IPython_and_Designer.
5164 http://www.scipy.org/Cookbook/Matplotlib/Qt_with_IPython_and_Designer.
5150
5165
5151
5166
5152 Tk issues
5167 Tk issues
5153 ---------
5168 ---------
5154
5169
5155 As indicated in Sec. `Threading options`_, a special -tk option is
5170 As indicated in Sec. `Threading options`_, a special -tk option is
5156 provided to try and allow Tk graphical applications to coexist
5171 provided to try and allow Tk graphical applications to coexist
5157 interactively with WX, Qt or GTK ones. Whether this works at all,
5172 interactively with WX, Qt or GTK ones. Whether this works at all,
5158 however, is very platform and configuration dependent. Please
5173 however, is very platform and configuration dependent. Please
5159 experiment with simple test cases before committing to using this
5174 experiment with simple test cases before committing to using this
5160 combination of Tk and GTK/Qt/WX threading in a production environment.
5175 combination of Tk and GTK/Qt/WX threading in a production environment.
5161
5176
5162
5177
5163 I/O pitfalls
5178 I/O pitfalls
5164 ------------
5179 ------------
5165
5180
5166 Be mindful that the Python interpreter switches between threads every
5181 Be mindful that the Python interpreter switches between threads every
5167 $N$ bytecodes, where the default value as of Python 2.3 is $N=100.$ This
5182 $N$ bytecodes, where the default value as of Python 2.3 is $N=100.$ This
5168 value can be read by using the sys.getcheckinterval() function, and it
5183 value can be read by using the sys.getcheckinterval() function, and it
5169 can be reset via sys.setcheckinterval(N). This switching of threads can
5184 can be reset via sys.setcheckinterval(N). This switching of threads can
5170 cause subtly confusing effects if one of your threads is doing file I/O.
5185 cause subtly confusing effects if one of your threads is doing file I/O.
5171 In text mode, most systems only flush file buffers when they encounter a
5186 In text mode, most systems only flush file buffers when they encounter a
5172 '\n'. An instruction as simple as::
5187 '\n'. An instruction as simple as::
5173
5188
5174 print >> filehandle, ''hello world''
5189 print >> filehandle, ''hello world''
5175
5190
5176 actually consists of several bytecodes, so it is possible that the
5191 actually consists of several bytecodes, so it is possible that the
5177 newline does not reach your file before the next thread switch.
5192 newline does not reach your file before the next thread switch.
5178 Similarly, if you are writing to a file in binary mode, the file won't
5193 Similarly, if you are writing to a file in binary mode, the file won't
5179 be flushed until the buffer fills, and your other thread may see
5194 be flushed until the buffer fills, and your other thread may see
5180 apparently truncated files.
5195 apparently truncated files.
5181
5196
5182 For this reason, if you are using IPython's thread support and have (for
5197 For this reason, if you are using IPython's thread support and have (for
5183 example) a GUI application which will read data generated by files
5198 example) a GUI application which will read data generated by files
5184 written to from the IPython thread, the safest approach is to open all
5199 written to from the IPython thread, the safest approach is to open all
5185 of your files in unbuffered mode (the third argument to the file/open
5200 of your files in unbuffered mode (the third argument to the file/open
5186 function is the buffering value)::
5201 function is the buffering value)::
5187
5202
5188 filehandle = open(filename,mode,0)
5203 filehandle = open(filename,mode,0)
5189
5204
5190 This is obviously a brute force way of avoiding race conditions with the
5205 This is obviously a brute force way of avoiding race conditions with the
5191 file buffering. If you want to do it cleanly, and you have a resource
5206 file buffering. If you want to do it cleanly, and you have a resource
5192 which is being shared by the interactive IPython loop and your GUI
5207 which is being shared by the interactive IPython loop and your GUI
5193 thread, you should really handle it with thread locking and
5208 thread, you should really handle it with thread locking and
5194 syncrhonization properties. The Python documentation discusses these.
5209 syncrhonization properties. The Python documentation discusses these.
5195
5210
5196 .. _Interactive demos:
5211 .. _Interactive demos:
5197
5212
5198 Interactive demos with IPython
5213 Interactive demos with IPython
5199 ==============================
5214 ==============================
5200
5215
5201 IPython ships with a basic system for running scripts interactively in
5216 IPython ships with a basic system for running scripts interactively in
5202 sections, useful when presenting code to audiences. A few tags embedded
5217 sections, useful when presenting code to audiences. A few tags embedded
5203 in comments (so that the script remains valid Python code) divide a file
5218 in comments (so that the script remains valid Python code) divide a file
5204 into separate blocks, and the demo can be run one block at a time, with
5219 into separate blocks, and the demo can be run one block at a time, with
5205 IPython printing (with syntax highlighting) the block before executing
5220 IPython printing (with syntax highlighting) the block before executing
5206 it, and returning to the interactive prompt after each block. The
5221 it, and returning to the interactive prompt after each block. The
5207 interactive namespace is updated after each block is run with the
5222 interactive namespace is updated after each block is run with the
5208 contents of the demo's namespace.
5223 contents of the demo's namespace.
5209
5224
5210 This allows you to show a piece of code, run it and then execute
5225 This allows you to show a piece of code, run it and then execute
5211 interactively commands based on the variables just created. Once you
5226 interactively commands based on the variables just created. Once you
5212 want to continue, you simply execute the next block of the demo. The
5227 want to continue, you simply execute the next block of the demo. The
5213 following listing shows the markup necessary for dividing a script into
5228 following listing shows the markup necessary for dividing a script into
5214 sections for execution as a demo::
5229 sections for execution as a demo::
5215
5230
5216
5231
5217 """A simple interactive demo to illustrate the use of IPython's Demo class.
5232 """A simple interactive demo to illustrate the use of IPython's Demo class.
5218
5233
5219 Any python script can be run as a demo, but that does little more than showing
5234 Any python script can be run as a demo, but that does little more than showing
5220 it on-screen, syntax-highlighted in one shot. If you add a little simple
5235 it on-screen, syntax-highlighted in one shot. If you add a little simple
5221 markup, you can stop at specified intervals and return to the ipython prompt,
5236 markup, you can stop at specified intervals and return to the ipython prompt,
5222 resuming execution later.
5237 resuming execution later.
5223 """
5238 """
5224
5239
5225 print 'Hello, welcome to an interactive IPython demo.'
5240 print 'Hello, welcome to an interactive IPython demo.'
5226 print 'Executing this block should require confirmation before proceeding,'
5241 print 'Executing this block should require confirmation before proceeding,'
5227 print 'unless auto_all has been set to true in the demo object'
5242 print 'unless auto_all has been set to true in the demo object'
5228
5243
5229 # The mark below defines a block boundary, which is a point where IPython will
5244 # The mark below defines a block boundary, which is a point where IPython will
5230 # stop execution and return to the interactive prompt.
5245 # stop execution and return to the interactive prompt.
5231 # Note that in actual interactive execution,
5246 # Note that in actual interactive execution,
5232 # <demo> --- stop ---
5247 # <demo> --- stop ---
5233
5248
5234 x = 1
5249 x = 1
5235 y = 2
5250 y = 2
5236
5251
5237 # <demo> --- stop ---
5252 # <demo> --- stop ---
5238
5253
5239 # the mark below makes this block as silent
5254 # the mark below makes this block as silent
5240 # <demo> silent
5255 # <demo> silent
5241
5256
5242 print 'This is a silent block, which gets executed but not printed.'
5257 print 'This is a silent block, which gets executed but not printed.'
5243
5258
5244 # <demo> --- stop ---
5259 # <demo> --- stop ---
5245 # <demo> auto
5260 # <demo> auto
5246 print 'This is an automatic block.'
5261 print 'This is an automatic block.'
5247 print 'It is executed without asking for confirmation, but printed.'
5262 print 'It is executed without asking for confirmation, but printed.'
5248 z = x+y
5263 z = x+y
5249
5264
5250 print 'z=',x
5265 print 'z=',x
5251
5266
5252 # <demo> --- stop ---
5267 # <demo> --- stop ---
5253 # This is just another normal block.
5268 # This is just another normal block.
5254 print 'z is now:', z
5269 print 'z is now:', z
5255
5270
5256 print 'bye!'
5271 print 'bye!'
5257
5272
5258 In order to run a file as a demo, you must first make a Demo object out
5273 In order to run a file as a demo, you must first make a Demo object out
5259 of it. If the file is named myscript.py, the following code will make a
5274 of it. If the file is named myscript.py, the following code will make a
5260 demo::
5275 demo::
5261
5276
5262 from IPython.demo import Demo
5277 from IPython.demo import Demo
5263
5278
5264 mydemo = Demo('myscript.py')
5279 mydemo = Demo('myscript.py')
5265
5280
5266 This creates the mydemo object, whose blocks you run one at a time by
5281 This creates the mydemo object, whose blocks you run one at a time by
5267 simply calling the object with no arguments. If you have autocall active
5282 simply calling the object with no arguments. If you have autocall active
5268 in IPython (the default), all you need to do is type::
5283 in IPython (the default), all you need to do is type::
5269
5284
5270 mydemo
5285 mydemo
5271
5286
5272 and IPython will call it, executing each block. Demo objects can be
5287 and IPython will call it, executing each block. Demo objects can be
5273 restarted, you can move forward or back skipping blocks, re-execute the
5288 restarted, you can move forward or back skipping blocks, re-execute the
5274 last block, etc. Simply use the Tab key on a demo object to see its
5289 last block, etc. Simply use the Tab key on a demo object to see its
5275 methods, and call '?' on them to see their docstrings for more usage
5290 methods, and call '?' on them to see their docstrings for more usage
5276 details. In addition, the demo module itself contains a comprehensive
5291 details. In addition, the demo module itself contains a comprehensive
5277 docstring, which you can access via::
5292 docstring, which you can access via::
5278
5293
5279 from IPython import demo
5294 from IPython import demo
5280
5295
5281 demo?
5296 demo?
5282
5297
5283 Limitations: It is important to note that these demos are limited to
5298 Limitations: It is important to note that these demos are limited to
5284 fairly simple uses. In particular, you can not put division marks in
5299 fairly simple uses. In particular, you can not put division marks in
5285 indented code (loops, if statements, function definitions, etc.)
5300 indented code (loops, if statements, function definitions, etc.)
5286 Supporting something like this would basically require tracking the
5301 Supporting something like this would basically require tracking the
5287 internal execution state of the Python interpreter, so only top-level
5302 internal execution state of the Python interpreter, so only top-level
5288 divisions are allowed. If you want to be able to open an IPython
5303 divisions are allowed. If you want to be able to open an IPython
5289 instance at an arbitrary point in a program, you can use IPython's
5304 instance at an arbitrary point in a program, you can use IPython's
5290 embedding facilities, described in detail in Sec. 9
5305 embedding facilities, described in detail in Sec. 9
5291
5306
5292
5307
5293 .. _Matplotlib support:
5308 .. _Matplotlib support:
5294
5309
5295 Plotting with matplotlib
5310 Plotting with matplotlib
5296 ========================
5311 ========================
5297
5312
5298 The matplotlib library (http://matplotlib.sourceforge.net
5313 The matplotlib library (http://matplotlib.sourceforge.net
5299 http://matplotlib.sourceforge.net) provides high quality 2D plotting for
5314 http://matplotlib.sourceforge.net) provides high quality 2D plotting for
5300 Python. Matplotlib can produce plots on screen using a variety of GUI
5315 Python. Matplotlib can produce plots on screen using a variety of GUI
5301 toolkits, including Tk, GTK and WXPython. It also provides a number of
5316 toolkits, including Tk, GTK and WXPython. It also provides a number of
5302 commands useful for scientific computing, all with a syntax compatible
5317 commands useful for scientific computing, all with a syntax compatible
5303 with that of the popular Matlab program.
5318 with that of the popular Matlab program.
5304
5319
5305 IPython accepts the special option -pylab (Sec. `Command line
5320 IPython accepts the special option -pylab (Sec. `Command line
5306 options`_). This configures it to support matplotlib, honoring the
5321 options`_). This configures it to support matplotlib, honoring the
5307 settings in the .matplotlibrc file. IPython will detect the user's
5322 settings in the .matplotlibrc file. IPython will detect the user's
5308 choice of matplotlib GUI backend, and automatically select the proper
5323 choice of matplotlib GUI backend, and automatically select the proper
5309 threading model to prevent blocking. It also sets matplotlib in
5324 threading model to prevent blocking. It also sets matplotlib in
5310 interactive mode and modifies %run slightly, so that any
5325 interactive mode and modifies %run slightly, so that any
5311 matplotlib-based script can be executed using %run and the final
5326 matplotlib-based script can be executed using %run and the final
5312 show() command does not block the interactive shell.
5327 show() command does not block the interactive shell.
5313
5328
5314 The -pylab option must be given first in order for IPython to
5329 The -pylab option must be given first in order for IPython to
5315 configure its threading mode. However, you can still issue other
5330 configure its threading mode. However, you can still issue other
5316 options afterwards. This allows you to have a matplotlib-based
5331 options afterwards. This allows you to have a matplotlib-based
5317 environment customized with additional modules using the standard
5332 environment customized with additional modules using the standard
5318 IPython profile mechanism (Sec. Profiles_): ''ipython -pylab -p
5333 IPython profile mechanism (Sec. Profiles_): ''ipython -pylab -p
5319 myprofile'' will load the profile defined in ipythonrc-myprofile after
5334 myprofile'' will load the profile defined in ipythonrc-myprofile after
5320 configuring matplotlib.
5335 configuring matplotlib.
5321
5336
5322 IPython Extension Api
5337 IPython Extension Api
5323 =====================
5338 =====================
5324
5339
5325 IPython api (defined in IPython/ipapi.py) is the public api that
5340 IPython api (defined in IPython/ipapi.py) is the public api that
5326 should be used for
5341 should be used for
5327
5342
5328 * Configuration of user preferences (.ipython/ipy_user_conf.py)
5343 * Configuration of user preferences (.ipython/ipy_user_conf.py)
5329 * Creating new profiles (.ipython/ipy_profile_PROFILENAME.py)
5344 * Creating new profiles (.ipython/ipy_profile_PROFILENAME.py)
5330 * Writing extensions
5345 * Writing extensions
5331
5346
5332 Note that by using the extension api for configuration (editing
5347 Note that by using the extension api for configuration (editing
5333 ipy_user_conf.py instead of ipythonrc), you get better validity checks
5348 ipy_user_conf.py instead of ipythonrc), you get better validity checks
5334 and get richer functionality - for example, you can import an
5349 and get richer functionality - for example, you can import an
5335 extension and call functions in it to configure it for your purposes.
5350 extension and call functions in it to configure it for your purposes.
5336
5351
5337 For an example extension (the 'sh' profile), see
5352 For an example extension (the 'sh' profile), see
5338 IPython/Extensions/ipy_profile_sh.py.
5353 IPython/Extensions/ipy_profile_sh.py.
5339
5354
5340 For the last word on what's available, see the source code of
5355 For the last word on what's available, see the source code of
5341 IPython/ipapi.py.
5356 IPython/ipapi.py.
5342
5357
5343
5358
5344 Getting started
5359 Getting started
5345 ---------------
5360 ---------------
5346
5361
5347 If you want to define an extension, create a normal python module that
5362 If you want to define an extension, create a normal python module that
5348 can be imported. The module will access IPython functionality through
5363 can be imported. The module will access IPython functionality through
5349 the 'ip' object defined below.
5364 the 'ip' object defined below.
5350
5365
5351 If you are creating a new profile (e.g. foobar), name the module as
5366 If you are creating a new profile (e.g. foobar), name the module as
5352 'ipy_profile_foobar.py' and put it in your ~/.ipython directory. Then,
5367 'ipy_profile_foobar.py' and put it in your ~/.ipython directory. Then,
5353 when you start ipython with the '-p foobar' argument, the module is
5368 when you start ipython with the '-p foobar' argument, the module is
5354 automatically imported on ipython startup.
5369 automatically imported on ipython startup.
5355
5370
5356 If you are just doing some per-user configuration, you can either
5371 If you are just doing some per-user configuration, you can either
5357
5372
5358 * Put the commands directly into ipy_user_conf.py.
5373 * Put the commands directly into ipy_user_conf.py.
5359
5374
5360 * Create a new module with your customization code and import *that*
5375 * Create a new module with your customization code and import *that*
5361 module in ipy_user_conf.py. This is preferable to the first approach,
5376 module in ipy_user_conf.py. This is preferable to the first approach,
5362 because now you can reuse and distribute your customization code.
5377 because now you can reuse and distribute your customization code.
5363
5378
5364 Getting a handle to the api
5379 Getting a handle to the api
5365 ---------------------------
5380 ---------------------------
5366
5381
5367 Put this in the start of your module::
5382 Put this in the start of your module::
5368
5383
5369 #!python
5384 #!python
5370 import IPython.ipapi
5385 import IPython.ipapi
5371 ip = IPython.ipapi.get()
5386 ip = IPython.ipapi.get()
5372
5387
5373 The 'ip' object will then be used for accessing IPython
5388 The 'ip' object will then be used for accessing IPython
5374 functionality. 'ip' will mean this api object in all the following
5389 functionality. 'ip' will mean this api object in all the following
5375 code snippets. The same 'ip' that we just acquired is always
5390 code snippets. The same 'ip' that we just acquired is always
5376 accessible in interactive IPython sessions by the name _ip - play with
5391 accessible in interactive IPython sessions by the name _ip - play with
5377 it like this::
5392 it like this::
5378
5393
5379 [~\_ipython]|81> a = 10
5394 [~\_ipython]|81> a = 10
5380 [~\_ipython]|82> _ip.e
5395 [~\_ipython]|82> _ip.e
5381 _ip.ev _ip.ex _ip.expose_magic
5396 _ip.ev _ip.ex _ip.expose_magic
5382 [~\_ipython]|82> _ip.ev('a+13')
5397 [~\_ipython]|82> _ip.ev('a+13')
5383 <82> 23
5398 <82> 23
5384
5399
5385 The _ip object is also used in some examples in this document - it can
5400 The _ip object is also used in some examples in this document - it can
5386 be substituted by 'ip' in non-interactive use.
5401 be substituted by 'ip' in non-interactive use.
5387
5402
5388 Changing options
5403 Changing options
5389 ----------------
5404 ----------------
5390
5405
5391 The ip object has 'options' attribute that can be used te get/set
5406 The ip object has 'options' attribute that can be used te get/set
5392 configuration options (just as in the ipythonrc file)::
5407 configuration options (just as in the ipythonrc file)::
5393
5408
5394 o = ip.options
5409 o = ip.options
5395 o.autocall = 2
5410 o.autocall = 2
5396 o.automagic = 1
5411 o.automagic = 1
5397
5412
5398 Executing statements in IPython namespace with 'ex' and 'ev'
5413 Executing statements in IPython namespace with 'ex' and 'ev'
5399 ------------------------------------------------------------
5414 ------------------------------------------------------------
5400
5415
5401 Often, you want to e.g. import some module or define something that
5416 Often, you want to e.g. import some module or define something that
5402 should be visible in IPython namespace. Use ``ip.ev`` to
5417 should be visible in IPython namespace. Use ``ip.ev`` to
5403 *evaluate* (calculate the value of) expression and ``ip.ex`` to
5418 *evaluate* (calculate the value of) expression and ``ip.ex`` to
5404 '''execute''' a statement::
5419 '''execute''' a statement::
5405
5420
5406 # path module will be visible to the interactive session
5421 # path module will be visible to the interactive session
5407 ip.ex("from path import path" )
5422 ip.ex("from path import path" )
5408
5423
5409 # define a handy function 'up' that changes the working directory
5424 # define a handy function 'up' that changes the working directory
5410
5425
5411 ip.ex('import os')
5426 ip.ex('import os')
5412 ip.ex("def up(): os.chdir('..')")
5427 ip.ex("def up(): os.chdir('..')")
5413
5428
5414
5429
5415 # _i2 has the input history entry #2, print its value in uppercase.
5430 # _i2 has the input history entry #2, print its value in uppercase.
5416 print ip.ev('_i2.upper()')
5431 print ip.ev('_i2.upper()')
5417
5432
5418 Accessing the IPython namespace
5433 Accessing the IPython namespace
5419 -------------------------------
5434 -------------------------------
5420
5435
5421 ip.user_ns attribute has a dictionary containing the IPython global
5436 ip.user_ns attribute has a dictionary containing the IPython global
5422 namespace (the namespace visible in the interactive session).
5437 namespace (the namespace visible in the interactive session).
5423
5438
5424 ::
5439 ::
5425
5440
5426 [~\_ipython]|84> tauno = 555
5441 [~\_ipython]|84> tauno = 555
5427 [~\_ipython]|85> _ip.user_ns['tauno']
5442 [~\_ipython]|85> _ip.user_ns['tauno']
5428 <85> 555
5443 <85> 555
5429
5444
5430 Defining new magic commands
5445 Defining new magic commands
5431 ---------------------------
5446 ---------------------------
5432
5447
5433 The following example defines a new magic command, %impall. What the
5448 The following example defines a new magic command, %impall. What the
5434 command does should be obvious::
5449 command does should be obvious::
5435
5450
5436 def doimp(self, arg):
5451 def doimp(self, arg):
5437 ip = self.api
5452 ip = self.api
5438 ip.ex("import %s; reload(%s); from %s import *" % (
5453 ip.ex("import %s; reload(%s); from %s import *" % (
5439 arg,arg,arg)
5454 arg,arg,arg)
5440 )
5455 )
5441
5456
5442 ip.expose_magic('impall', doimp)
5457 ip.expose_magic('impall', doimp)
5443
5458
5444 Things to observe in this example:
5459 Things to observe in this example:
5445
5460
5446 * Define a function that implements the magic command using the
5461 * Define a function that implements the magic command using the
5447 ipapi methods defined in this document
5462 ipapi methods defined in this document
5448 * The first argument of the function is 'self', i.e. the
5463 * The first argument of the function is 'self', i.e. the
5449 interpreter object. It shouldn't be used directly. however.
5464 interpreter object. It shouldn't be used directly. however.
5450 The interpreter object is probably *not* going to remain stable
5465 The interpreter object is probably *not* going to remain stable
5451 through IPython versions.
5466 through IPython versions.
5452 * Access the ipapi through 'self.api' instead of the global 'ip' object.
5467 * Access the ipapi through 'self.api' instead of the global 'ip' object.
5453 * All the text following the magic command on the command line is
5468 * All the text following the magic command on the command line is
5454 contained in the second argument
5469 contained in the second argument
5455 * Expose the magic by ip.expose_magic()
5470 * Expose the magic by ip.expose_magic()
5456
5471
5457
5472
5458 Calling magic functions and system commands
5473 Calling magic functions and system commands
5459 -------------------------------------------
5474 -------------------------------------------
5460
5475
5461 Use ip.magic() to execute a magic function, and ip.system() to execute
5476 Use ip.magic() to execute a magic function, and ip.system() to execute
5462 a system command::
5477 a system command::
5463
5478
5464 # go to a bookmark
5479 # go to a bookmark
5465 ip.magic('%cd -b relfiles')
5480 ip.magic('%cd -b relfiles')
5466
5481
5467 # execute 'ls -F' system command. Interchangeable with os.system('ls'), really.
5482 # execute 'ls -F' system command. Interchangeable with os.system('ls'), really.
5468 ip.system('ls -F')
5483 ip.system('ls -F')
5469
5484
5470 Launching IPython instance from normal python code
5485 Launching IPython instance from normal python code
5471 --------------------------------------------------
5486 --------------------------------------------------
5472
5487
5473 Use ipapi.launch_new_instance() with an argument that specifies the
5488 Use ipapi.launch_new_instance() with an argument that specifies the
5474 namespace to use. This can be useful for trivially embedding IPython
5489 namespace to use. This can be useful for trivially embedding IPython
5475 into your program. Here's an example of normal python program test.py
5490 into your program. Here's an example of normal python program test.py
5476 ('''without''' an existing IPython session) that launches an IPython
5491 ('''without''' an existing IPython session) that launches an IPython
5477 interpreter and regains control when the interpreter is exited::
5492 interpreter and regains control when the interpreter is exited::
5478
5493
5479 [ipython]|1> cat test.py
5494 [ipython]|1> cat test.py
5480 my_ns = dict(
5495 my_ns = dict(
5481 kissa = 15,
5496 kissa = 15,
5482 koira = 16)
5497 koira = 16)
5483 import IPython.ipapi
5498 import IPython.ipapi
5484 print "launching IPython instance"
5499 print "launching IPython instance"
5485 IPython.ipapi.launch_new_instance(my_ns)
5500 IPython.ipapi.launch_new_instance(my_ns)
5486 print "Exited IPython instance!"
5501 print "Exited IPython instance!"
5487 print "New vals:",my_ns['kissa'], my_ns['koira']
5502 print "New vals:",my_ns['kissa'], my_ns['koira']
5488
5503
5489 And here's what it looks like when run (note how we don't start it
5504 And here's what it looks like when run (note how we don't start it
5490 from an ipython session)::
5505 from an ipython session)::
5491
5506
5492 Q:\ipython>python test.py
5507 Q:\ipython>python test.py
5493 launching IPython instance
5508 launching IPython instance
5494 Py 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] IPy 0.7.3b3.r1975
5509 Py 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] IPy 0.7.3b3.r1975
5495 [ipython]|1> kissa = 444
5510 [ipython]|1> kissa = 444
5496 [ipython]|2> koira = 555
5511 [ipython]|2> koira = 555
5497 [ipython]|3> Exit
5512 [ipython]|3> Exit
5498 Exited IPython instance!
5513 Exited IPython instance!
5499 New vals: 444 555
5514 New vals: 444 555
5500
5515
5501 Accessing unexposed functionality
5516 Accessing unexposed functionality
5502 ---------------------------------
5517 ---------------------------------
5503
5518
5504 There are still many features that are not exposed via the ipapi. If
5519 There are still many features that are not exposed via the ipapi. If
5505 you can't avoid using them, you can use the functionality in
5520 you can't avoid using them, you can use the functionality in
5506 InteractiveShell object (central IPython session class, defined in
5521 InteractiveShell object (central IPython session class, defined in
5507 iplib.py) through ip.IP.
5522 iplib.py) through ip.IP.
5508
5523
5509 For example::
5524 For example::
5510
5525
5511 [~]|7> _ip.IP.expand_aliases('np','myfile.py')
5526 [~]|7> _ip.IP.expand_aliases('np','myfile.py')
5512 <7> 'c:/opt/Notepad++/notepad++.exe myfile.py'
5527 <7> 'c:/opt/Notepad++/notepad++.exe myfile.py'
5513 [~]|8>
5528 [~]|8>
5514
5529
5515 Still, it's preferable that if you encounter such a feature, contact
5530 Still, it's preferable that if you encounter such a feature, contact
5516 the IPython team and request that the functionality be exposed in a
5531 the IPython team and request that the functionality be exposed in a
5517 future version of IPython. Things not in ipapi are more likely to
5532 future version of IPython. Things not in ipapi are more likely to
5518 change over time.
5533 change over time.
5519
5534
5520 Provided extensions
5535 Provided extensions
5521 ===================
5536 ===================
5522
5537
5523 You can see the list of available extensions (and profiles) by doing
5538 You can see the list of available extensions (and profiles) by doing
5524 ``import ipy_<TAB>``. Some extensions don't have the ``ipy_`` prefix in
5539 ``import ipy_<TAB>``. Some extensions don't have the ``ipy_`` prefix in
5525 module name, so you may need to see the contents of IPython/Extensions
5540 module name, so you may need to see the contents of IPython/Extensions
5526 folder to see what's available.
5541 folder to see what's available.
5527
5542
5528 You can see a brief documentation of an extension by looking at the
5543 You can see a brief documentation of an extension by looking at the
5529 module docstring::
5544 module docstring::
5530
5545
5531 [c:p/ipython_main]|190> import ipy_fsops
5546 [c:p/ipython_main]|190> import ipy_fsops
5532 [c:p/ipython_main]|191> ipy_fsops?
5547 [c:p/ipython_main]|191> ipy_fsops?
5533
5548
5534 ...
5549 ...
5535
5550
5536 Docstring:
5551 Docstring:
5537 File system operations
5552 File system operations
5538
5553
5539 Contains: Simple variants of normal unix shell commands (icp, imv, irm,
5554 Contains: Simple variants of normal unix shell commands (icp, imv, irm,
5540 imkdir, igrep).
5555 imkdir, igrep).
5541
5556
5542 You can also install your own extensions - the recommended way is to
5557 You can also install your own extensions - the recommended way is to
5543 just copy the module to ~/.ipython. Extensions are typically enabled
5558 just copy the module to ~/.ipython. Extensions are typically enabled
5544 by just importing them (e.g. in ipy_user_conf.py), but some extensions
5559 by just importing them (e.g. in ipy_user_conf.py), but some extensions
5545 require additional steps, for example::
5560 require additional steps, for example::
5546
5561
5547 [c:p]|192> import ipy_traits_completer
5562 [c:p]|192> import ipy_traits_completer
5548 [c:p]|193> ipy_traits_completer.activate()
5563 [c:p]|193> ipy_traits_completer.activate()
5549
5564
5550 Note that extensions, even if provided in the stock IPython
5565 Note that extensions, even if provided in the stock IPython
5551 installation, are not guaranteed to have the same requirements as the
5566 installation, are not guaranteed to have the same requirements as the
5552 rest of IPython - an extension may require external libraries or a
5567 rest of IPython - an extension may require external libraries or a
5553 newer version of Python than what IPython officially requires. An
5568 newer version of Python than what IPython officially requires. An
5554 extension may also be under a more restrictive license than IPython
5569 extension may also be under a more restrictive license than IPython
5555 (e.g. ipy_bzr is under GPL).
5570 (e.g. ipy_bzr is under GPL).
5556
5571
5557 Just for reference, the list of bundled extensions at the time of
5572 Just for reference, the list of bundled extensions at the time of
5558 writing is below:
5573 writing is below:
5559
5574
5560 astyle.py clearcmd.py envpersist.py ext_rescapture.py ibrowse.py
5575 astyle.py clearcmd.py envpersist.py ext_rescapture.py ibrowse.py
5561 igrid.py InterpreterExec.py InterpreterPasteInput.py ipipe.py
5576 igrid.py InterpreterExec.py InterpreterPasteInput.py ipipe.py
5562 ipy_app_completers.py ipy_autoreload.py ipy_bzr.py ipy_completers.py
5577 ipy_app_completers.py ipy_autoreload.py ipy_bzr.py ipy_completers.py
5563 ipy_constants.py ipy_defaults.py ipy_editors.py ipy_exportdb.py
5578 ipy_constants.py ipy_defaults.py ipy_editors.py ipy_exportdb.py
5564 ipy_extutil.py ipy_fsops.py ipy_gnuglobal.py ipy_kitcfg.py
5579 ipy_extutil.py ipy_fsops.py ipy_gnuglobal.py ipy_kitcfg.py
5565 ipy_legacy.py ipy_leo.py ipy_p4.py ipy_profile_doctest.py
5580 ipy_legacy.py ipy_leo.py ipy_p4.py ipy_profile_doctest.py
5566 ipy_profile_none.py ipy_profile_scipy.py ipy_profile_sh.py
5581 ipy_profile_none.py ipy_profile_scipy.py ipy_profile_sh.py
5567 ipy_profile_zope.py ipy_pydb.py ipy_rehashdir.py ipy_render.py
5582 ipy_profile_zope.py ipy_pydb.py ipy_rehashdir.py ipy_render.py
5568 ipy_server.py ipy_signals.py ipy_stock_completers.py
5583 ipy_server.py ipy_signals.py ipy_stock_completers.py
5569 ipy_system_conf.py ipy_traits_completer.py ipy_vimserver.py
5584 ipy_system_conf.py ipy_traits_completer.py ipy_vimserver.py
5570 ipy_which.py ipy_workdir.py jobctrl.py ledit.py numeric_formats.py
5585 ipy_which.py ipy_workdir.py jobctrl.py ledit.py numeric_formats.py
5571 PhysicalQInput.py PhysicalQInteractive.py pickleshare.py
5586 PhysicalQInput.py PhysicalQInteractive.py pickleshare.py
5572 pspersistence.py win32clip.py __init__.py
5587 pspersistence.py win32clip.py __init__.py
5573
5588
5574 Reporting bugs
5589 Reporting bugs
5575 ==============
5590 ==============
5576
5591
5577 Automatic crash reports
5592 Automatic crash reports
5578 -----------------------
5593 -----------------------
5579
5594
5580 Ideally, IPython itself shouldn't crash. It will catch exceptions
5595 Ideally, IPython itself shouldn't crash. It will catch exceptions
5581 produced by you, but bugs in its internals will still crash it.
5596 produced by you, but bugs in its internals will still crash it.
5582
5597
5583 In such a situation, IPython will leave a file named
5598 In such a situation, IPython will leave a file named
5584 IPython_crash_report.txt in your IPYTHONDIR directory (that way if
5599 IPython_crash_report.txt in your IPYTHONDIR directory (that way if
5585 crashes happen several times it won't litter many directories, the
5600 crashes happen several times it won't litter many directories, the
5586 post-mortem file is always located in the same place and new
5601 post-mortem file is always located in the same place and new
5587 occurrences just overwrite the previous one). If you can mail this
5602 occurrences just overwrite the previous one). If you can mail this
5588 file to the developers (see sec. credits_ for names and addresses), it
5603 file to the developers (see sec. credits_ for names and addresses), it
5589 will help us a lot in understanding the cause of the problem and
5604 will help us a lot in understanding the cause of the problem and
5590 fixing it sooner.
5605 fixing it sooner.
5591
5606
5592
5607
5593 The bug tracker
5608 The bug tracker
5594 ---------------
5609 ---------------
5595
5610
5596 IPython also has an online bug-tracker, located at
5611 IPython also has an online bug-tracker, located at
5597 http://projects.scipy.org/ipython/ipython/report/1. In addition to
5612 http://projects.scipy.org/ipython/ipython/report/1. In addition to
5598 mailing the developers, it would be a good idea to file a bug report
5613 mailing the developers, it would be a good idea to file a bug report
5599 here. This will ensure that the issue is properly followed to
5614 here. This will ensure that the issue is properly followed to
5600 conclusion. To report new bugs you will have to register first.
5615 conclusion. To report new bugs you will have to register first.
5601
5616
5602 You can also use this bug tracker to file feature requests.
5617 You can also use this bug tracker to file feature requests.
5603
5618
5604 Brief history
5619 Brief history
5605 =============
5620 =============
5606
5621
5607
5622
5608 Origins
5623 Origins
5609 -------
5624 -------
5610
5625
5611 The current IPython system grew out of the following three projects:
5626 The current IPython system grew out of the following three projects:
5612
5627
5613 * [ipython] by Fernando Pérez. I was working on adding
5628 * [ipython] by Fernando Pérez. I was working on adding
5614 Mathematica-type prompts and a flexible configuration system
5629 Mathematica-type prompts and a flexible configuration system
5615 (something better than $PYTHONSTARTUP) to the standard Python
5630 (something better than $PYTHONSTARTUP) to the standard Python
5616 interactive interpreter.
5631 interactive interpreter.
5617 * [IPP] by Janko Hauser. Very well organized, great usability. Had
5632 * [IPP] by Janko Hauser. Very well organized, great usability. Had
5618 an old help system. IPP was used as the 'container' code into
5633 an old help system. IPP was used as the 'container' code into
5619 which I added the functionality from ipython and LazyPython.
5634 which I added the functionality from ipython and LazyPython.
5620 * [LazyPython] by Nathan Gray. Simple but very powerful. The quick
5635 * [LazyPython] by Nathan Gray. Simple but very powerful. The quick
5621 syntax (auto parens, auto quotes) and verbose/colored tracebacks
5636 syntax (auto parens, auto quotes) and verbose/colored tracebacks
5622 were all taken from here.
5637 were all taken from here.
5623
5638
5624 When I found out about IPP and LazyPython I tried to join all three
5639 When I found out about IPP and LazyPython I tried to join all three
5625 into a unified system. I thought this could provide a very nice
5640 into a unified system. I thought this could provide a very nice
5626 working environment, both for regular programming and scientific
5641 working environment, both for regular programming and scientific
5627 computing: shell-like features, IDL/Matlab numerics, Mathematica-type
5642 computing: shell-like features, IDL/Matlab numerics, Mathematica-type
5628 prompt history and great object introspection and help facilities. I
5643 prompt history and great object introspection and help facilities. I
5629 think it worked reasonably well, though it was a lot more work than I
5644 think it worked reasonably well, though it was a lot more work than I
5630 had initially planned.
5645 had initially planned.
5631
5646
5632
5647
5633 Current status
5648 Current status
5634 --------------
5649 --------------
5635
5650
5636 The above listed features work, and quite well for the most part. But
5651 The above listed features work, and quite well for the most part. But
5637 until a major internal restructuring is done (see below), only bug
5652 until a major internal restructuring is done (see below), only bug
5638 fixing will be done, no other features will be added (unless very minor
5653 fixing will be done, no other features will be added (unless very minor
5639 and well localized in the cleaner parts of the code).
5654 and well localized in the cleaner parts of the code).
5640
5655
5641 IPython consists of some 18000 lines of pure python code, of which
5656 IPython consists of some 18000 lines of pure python code, of which
5642 roughly two thirds is reasonably clean. The rest is, messy code which
5657 roughly two thirds is reasonably clean. The rest is, messy code which
5643 needs a massive restructuring before any further major work is done.
5658 needs a massive restructuring before any further major work is done.
5644 Even the messy code is fairly well documented though, and most of the
5659 Even the messy code is fairly well documented though, and most of the
5645 problems in the (non-existent) class design are well pointed to by a
5660 problems in the (non-existent) class design are well pointed to by a
5646 PyChecker run. So the rewriting work isn't that bad, it will just be
5661 PyChecker run. So the rewriting work isn't that bad, it will just be
5647 time-consuming.
5662 time-consuming.
5648
5663
5649
5664
5650 Future
5665 Future
5651 ------
5666 ------
5652
5667
5653 See the separate new_design document for details. Ultimately, I would
5668 See the separate new_design document for details. Ultimately, I would
5654 like to see IPython become part of the standard Python distribution as a
5669 like to see IPython become part of the standard Python distribution as a
5655 'big brother with batteries' to the standard Python interactive
5670 'big brother with batteries' to the standard Python interactive
5656 interpreter. But that will never happen with the current state of the
5671 interpreter. But that will never happen with the current state of the
5657 code, so all contributions are welcome.
5672 code, so all contributions are welcome.
5658
5673
5659 License
5674 License
5660 =======
5675 =======
5661
5676
5662 IPython is released under the terms of the BSD license, whose general
5677 IPython is released under the terms of the BSD license, whose general
5663 form can be found at:
5678 form can be found at:
5664 http://www.opensource.org/licenses/bsd-license.php. The full text of the
5679 http://www.opensource.org/licenses/bsd-license.php. The full text of the
5665 IPython license is reproduced below::
5680 IPython license is reproduced below::
5666
5681
5667 IPython is released under a BSD-type license.
5682 IPython is released under a BSD-type license.
5668
5683
5669 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez
5684 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez
5670 <fperez@colorado.edu>.
5685 <fperez@colorado.edu>.
5671
5686
5672 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
5687 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
5673 Nathaniel Gray <n8gray@caltech.edu>.
5688 Nathaniel Gray <n8gray@caltech.edu>.
5674
5689
5675 All rights reserved.
5690 All rights reserved.
5676
5691
5677 Redistribution and use in source and binary forms, with or without
5692 Redistribution and use in source and binary forms, with or without
5678 modification, are permitted provided that the following conditions
5693 modification, are permitted provided that the following conditions
5679 are met:
5694 are met:
5680
5695
5681 a. Redistributions of source code must retain the above copyright
5696 a. Redistributions of source code must retain the above copyright
5682 notice, this list of conditions and the following disclaimer.
5697 notice, this list of conditions and the following disclaimer.
5683
5698
5684 b. Redistributions in binary form must reproduce the above copyright
5699 b. Redistributions in binary form must reproduce the above copyright
5685 notice, this list of conditions and the following disclaimer in the
5700 notice, this list of conditions and the following disclaimer in the
5686 documentation and/or other materials provided with the distribution.
5701 documentation and/or other materials provided with the distribution.
5687
5702
5688 c. Neither the name of the copyright holders nor the names of any
5703 c. Neither the name of the copyright holders nor the names of any
5689 contributors to this software may be used to endorse or promote
5704 contributors to this software may be used to endorse or promote
5690 products derived from this software without specific prior written
5705 products derived from this software without specific prior written
5691 permission.
5706 permission.
5692
5707
5693 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5708 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5694 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5709 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5695 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
5710 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
5696 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
5711 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
5697 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
5712 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
5698 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
5713 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
5699 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
5714 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
5700 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5715 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5701 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5716 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5702 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
5717 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
5703 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5718 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5704 POSSIBILITY OF SUCH DAMAGE.
5719 POSSIBILITY OF SUCH DAMAGE.
5705
5720
5706 Individual authors are the holders of the copyright for their code and
5721 Individual authors are the holders of the copyright for their code and
5707 are listed in each file.
5722 are listed in each file.
5708
5723
5709 Some files (DPyGetOpt.py, for example) may be licensed under different
5724 Some files (DPyGetOpt.py, for example) may be licensed under different
5710 conditions. Ultimately each file indicates clearly the conditions under
5725 conditions. Ultimately each file indicates clearly the conditions under
5711 which its author/authors have decided to publish the code.
5726 which its author/authors have decided to publish the code.
5712
5727
5713 Versions of IPython up to and including 0.6.3 were released under the
5728 Versions of IPython up to and including 0.6.3 were released under the
5714 GNU Lesser General Public License (LGPL), available at
5729 GNU Lesser General Public License (LGPL), available at
5715 http://www.gnu.org/copyleft/lesser.html.
5730 http://www.gnu.org/copyleft/lesser.html.
5716
5731
5717 Credits
5732 Credits
5718 =======
5733 =======
5719
5734
5720 IPython is mainly developed by Fernando Pérez
5735 IPython is mainly developed by Fernando Pérez
5721 <Fernando.Perez@colorado.edu>, but the project was born from mixing in
5736 <Fernando.Perez@colorado.edu>, but the project was born from mixing in
5722 Fernando's code with the IPP project by Janko Hauser
5737 Fernando's code with the IPP project by Janko Hauser
5723 <jhauser-AT-zscout.de> and LazyPython by Nathan Gray
5738 <jhauser-AT-zscout.de> and LazyPython by Nathan Gray
5724 <n8gray-AT-caltech.edu>. For all IPython-related requests, please
5739 <n8gray-AT-caltech.edu>. For all IPython-related requests, please
5725 contact Fernando.
5740 contact Fernando.
5726
5741
5727 As of early 2006, the following developers have joined the core team:
5742 As of early 2006, the following developers have joined the core team:
5728
5743
5729 * [Robert Kern] <rkern-AT-enthought.com>: co-mentored the 2005
5744 * [Robert Kern] <rkern-AT-enthought.com>: co-mentored the 2005
5730 Google Summer of Code project to develop python interactive
5745 Google Summer of Code project to develop python interactive
5731 notebooks (XML documents) and graphical interface. This project
5746 notebooks (XML documents) and graphical interface. This project
5732 was awarded to the students Tzanko Matev <tsanko-AT-gmail.com> and
5747 was awarded to the students Tzanko Matev <tsanko-AT-gmail.com> and
5733 Toni Alatalo <antont-AT-an.org>
5748 Toni Alatalo <antont-AT-an.org>
5734 * [Brian Granger] <bgranger-AT-scu.edu>: extending IPython to allow
5749 * [Brian Granger] <bgranger-AT-scu.edu>: extending IPython to allow
5735 support for interactive parallel computing.
5750 support for interactive parallel computing.
5736 * [Ville Vainio] <vivainio-AT-gmail.com>: Ville is the new
5751 * [Ville Vainio] <vivainio-AT-gmail.com>: Ville is the new
5737 maintainer for the main trunk of IPython after version 0.7.1.
5752 maintainer for the main trunk of IPython after version 0.7.1.
5738
5753
5739 User or development help should be requested via the IPython mailing lists:
5754 User or development help should be requested via the IPython mailing lists:
5740
5755
5741 *User list:*
5756 *User list:*
5742 http://scipy.net/mailman/listinfo/ipython-user
5757 http://scipy.net/mailman/listinfo/ipython-user
5743 *Developer's list:*
5758 *Developer's list:*
5744 http://scipy.net/mailman/listinfo/ipython-dev
5759 http://scipy.net/mailman/listinfo/ipython-dev
5745
5760
5746 The IPython project is also very grateful to:
5761 The IPython project is also very grateful to:
5747
5762
5748 Bill Bumgarner <bbum-AT-friday.com>: for providing the DPyGetOpt module
5763 Bill Bumgarner <bbum-AT-friday.com>: for providing the DPyGetOpt module
5749 which gives very powerful and convenient handling of command-line
5764 which gives very powerful and convenient handling of command-line
5750 options (light years ahead of what Python 2.1.1's getopt module does).
5765 options (light years ahead of what Python 2.1.1's getopt module does).
5751
5766
5752 Ka-Ping Yee <ping-AT-lfw.org>: for providing the Itpl module for
5767 Ka-Ping Yee <ping-AT-lfw.org>: for providing the Itpl module for
5753 convenient and powerful string interpolation with a much nicer syntax
5768 convenient and powerful string interpolation with a much nicer syntax
5754 than formatting through the '%' operator.
5769 than formatting through the '%' operator.
5755
5770
5756 Arnd Baecker <baecker-AT-physik.tu-dresden.de>: for his many very useful
5771 Arnd Baecker <baecker-AT-physik.tu-dresden.de>: for his many very useful
5757 suggestions and comments, and lots of help with testing and
5772 suggestions and comments, and lots of help with testing and
5758 documentation checking. Many of IPython's newer features are a result of
5773 documentation checking. Many of IPython's newer features are a result of
5759 discussions with him (bugs are still my fault, not his).
5774 discussions with him (bugs are still my fault, not his).
5760
5775
5761 Obviously Guido van Rossum and the whole Python development team, that
5776 Obviously Guido van Rossum and the whole Python development team, that
5762 goes without saying.
5777 goes without saying.
5763
5778
5764 IPython's website is generously hosted at http://ipython.scipy.orgby
5779 IPython's website is generously hosted at http://ipython.scipy.orgby
5765 Enthought (http://www.enthought.com). I am very grateful to them and all
5780 Enthought (http://www.enthought.com). I am very grateful to them and all
5766 of the SciPy team for their contribution.
5781 of the SciPy team for their contribution.
5767
5782
5768 Fernando would also like to thank Stephen Figgins <fig-AT-monitor.net>,
5783 Fernando would also like to thank Stephen Figgins <fig-AT-monitor.net>,
5769 an O'Reilly Python editor. His Oct/11/2001 article about IPP and
5784 an O'Reilly Python editor. His Oct/11/2001 article about IPP and
5770 LazyPython, was what got this project started. You can read it at:
5785 LazyPython, was what got this project started. You can read it at:
5771 http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html.
5786 http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html.
5772
5787
5773 And last but not least, all the kind IPython users who have emailed new
5788 And last but not least, all the kind IPython users who have emailed new
5774 code, bug reports, fixes, comments and ideas. A brief list follows,
5789 code, bug reports, fixes, comments and ideas. A brief list follows,
5775 please let me know if I have ommitted your name by accident:
5790 please let me know if I have ommitted your name by accident:
5776
5791
5777 * [Jack Moffit] <jack-AT-xiph.org> Bug fixes, including the infamous
5792 * [Jack Moffit] <jack-AT-xiph.org> Bug fixes, including the infamous
5778 color problem. This bug alone caused many lost hours and
5793 color problem. This bug alone caused many lost hours and
5779 frustration, many thanks to him for the fix. I've always been a
5794 frustration, many thanks to him for the fix. I've always been a
5780 fan of Ogg & friends, now I have one more reason to like these folks.
5795 fan of Ogg & friends, now I have one more reason to like these folks.
5781 Jack is also contributing with Debian packaging and many other
5796 Jack is also contributing with Debian packaging and many other
5782 things.
5797 things.
5783 * [Alexander Schmolck] <a.schmolck-AT-gmx.net> Emacs work, bug
5798 * [Alexander Schmolck] <a.schmolck-AT-gmx.net> Emacs work, bug
5784 reports, bug fixes, ideas, lots more. The ipython.el mode for
5799 reports, bug fixes, ideas, lots more. The ipython.el mode for
5785 (X)Emacs is Alex's code, providing full support for IPython under
5800 (X)Emacs is Alex's code, providing full support for IPython under
5786 (X)Emacs.
5801 (X)Emacs.
5787 * [Andrea Riciputi] <andrea.riciputi-AT-libero.it> Mac OSX
5802 * [Andrea Riciputi] <andrea.riciputi-AT-libero.it> Mac OSX
5788 information, Fink package management.
5803 information, Fink package management.
5789 * [Gary Bishop] <gb-AT-cs.unc.edu> Bug reports, and patches to work
5804 * [Gary Bishop] <gb-AT-cs.unc.edu> Bug reports, and patches to work
5790 around the exception handling idiosyncracies of WxPython. Readline
5805 around the exception handling idiosyncracies of WxPython. Readline
5791 and color support for Windows.
5806 and color support for Windows.
5792 * [Jeffrey Collins] <Jeff.Collins-AT-vexcel.com> Bug reports. Much
5807 * [Jeffrey Collins] <Jeff.Collins-AT-vexcel.com> Bug reports. Much
5793 improved readline support, including fixes for Python 2.3.
5808 improved readline support, including fixes for Python 2.3.
5794 * [Dryice Liu] <dryice-AT-liu.com.cn> FreeBSD port.
5809 * [Dryice Liu] <dryice-AT-liu.com.cn> FreeBSD port.
5795 * [Mike Heeter] <korora-AT-SDF.LONESTAR.ORG>
5810 * [Mike Heeter] <korora-AT-SDF.LONESTAR.ORG>
5796 * [Christopher Hart] <hart-AT-caltech.edu> PDB integration.
5811 * [Christopher Hart] <hart-AT-caltech.edu> PDB integration.
5797 * [Milan Zamazal] <pdm-AT-zamazal.org> Emacs info.
5812 * [Milan Zamazal] <pdm-AT-zamazal.org> Emacs info.
5798 * [Philip Hisley] <compsys-AT-starpower.net>
5813 * [Philip Hisley] <compsys-AT-starpower.net>
5799 * [Holger Krekel] <pyth-AT-devel.trillke.net> Tab completion, lots
5814 * [Holger Krekel] <pyth-AT-devel.trillke.net> Tab completion, lots
5800 more.
5815 more.
5801 * [Robin Siebler] <robinsiebler-AT-starband.net>
5816 * [Robin Siebler] <robinsiebler-AT-starband.net>
5802 * [Ralf Ahlbrink] <ralf_ahlbrink-AT-web.de>
5817 * [Ralf Ahlbrink] <ralf_ahlbrink-AT-web.de>
5803 * [Thorsten Kampe] <thorsten-AT-thorstenkampe.de>
5818 * [Thorsten Kampe] <thorsten-AT-thorstenkampe.de>
5804 * [Fredrik Kant] <fredrik.kant-AT-front.com> Windows setup.
5819 * [Fredrik Kant] <fredrik.kant-AT-front.com> Windows setup.
5805 * [Syver Enstad] <syver-en-AT-online.no> Windows setup.
5820 * [Syver Enstad] <syver-en-AT-online.no> Windows setup.
5806 * [Richard] <rxe-AT-renre-europe.com> Global embedding.
5821 * [Richard] <rxe-AT-renre-europe.com> Global embedding.
5807 * [Hayden Callow] <h.callow-AT-elec.canterbury.ac.nz> Gnuplot.py 1.6
5822 * [Hayden Callow] <h.callow-AT-elec.canterbury.ac.nz> Gnuplot.py 1.6
5808 compatibility.
5823 compatibility.
5809 * [Leonardo Santagada] <retype-AT-terra.com.br> Fixes for Windows
5824 * [Leonardo Santagada] <retype-AT-terra.com.br> Fixes for Windows
5810 installation.
5825 installation.
5811 * [Christopher Armstrong] <radix-AT-twistedmatrix.com> Bugfixes.
5826 * [Christopher Armstrong] <radix-AT-twistedmatrix.com> Bugfixes.
5812 * [Francois Pinard] <pinard-AT-iro.umontreal.ca> Code and
5827 * [Francois Pinard] <pinard-AT-iro.umontreal.ca> Code and
5813 documentation fixes.
5828 documentation fixes.
5814 * [Cory Dodt] <cdodt-AT-fcoe.k12.ca.us> Bug reports and Windows
5829 * [Cory Dodt] <cdodt-AT-fcoe.k12.ca.us> Bug reports and Windows
5815 ideas. Patches for Windows installer.
5830 ideas. Patches for Windows installer.
5816 * [Olivier Aubert] <oaubert-AT-bat710.univ-lyon1.fr> New magics.
5831 * [Olivier Aubert] <oaubert-AT-bat710.univ-lyon1.fr> New magics.
5817 * [King C. Shu] <kingshu-AT-myrealbox.com> Autoindent patch.
5832 * [King C. Shu] <kingshu-AT-myrealbox.com> Autoindent patch.
5818 * [Chris Drexler] <chris-AT-ac-drexler.de> Readline packages for
5833 * [Chris Drexler] <chris-AT-ac-drexler.de> Readline packages for
5819 Win32/CygWin.
5834 Win32/CygWin.
5820 * [Gustavo Cordova Avila] <gcordova-AT-sismex.com> EvalDict code for
5835 * [Gustavo Cordova Avila] <gcordova-AT-sismex.com> EvalDict code for
5821 nice, lightweight string interpolation.
5836 nice, lightweight string interpolation.
5822 * [Kasper Souren] <Kasper.Souren-AT-ircam.fr> Bug reports, ideas.
5837 * [Kasper Souren] <Kasper.Souren-AT-ircam.fr> Bug reports, ideas.
5823 * [Gever Tulley] <gever-AT-helium.com> Code contributions.
5838 * [Gever Tulley] <gever-AT-helium.com> Code contributions.
5824 * [Ralf Schmitt] <ralf-AT-brainbot.com> Bug reports & fixes.
5839 * [Ralf Schmitt] <ralf-AT-brainbot.com> Bug reports & fixes.
5825 * [Oliver Sander] <osander-AT-gmx.de> Bug reports.
5840 * [Oliver Sander] <osander-AT-gmx.de> Bug reports.
5826 * [Rod Holland] <rhh-AT-structurelabs.com> Bug reports and fixes to
5841 * [Rod Holland] <rhh-AT-structurelabs.com> Bug reports and fixes to
5827 logging module.
5842 logging module.
5828 * [Daniel 'Dang' Griffith] <pythondev-dang-AT-lazytwinacres.net>
5843 * [Daniel 'Dang' Griffith] <pythondev-dang-AT-lazytwinacres.net>
5829 Fixes, enhancement suggestions for system shell use.
5844 Fixes, enhancement suggestions for system shell use.
5830 * [Viktor Ransmayr] <viktor.ransmayr-AT-t-online.de> Tests and
5845 * [Viktor Ransmayr] <viktor.ransmayr-AT-t-online.de> Tests and
5831 reports on Windows installation issues. Contributed a true Windows
5846 reports on Windows installation issues. Contributed a true Windows
5832 binary installer.
5847 binary installer.
5833 * [Mike Salib] <msalib-AT-mit.edu> Help fixing a subtle bug related
5848 * [Mike Salib] <msalib-AT-mit.edu> Help fixing a subtle bug related
5834 to traceback printing.
5849 to traceback printing.
5835 * [W.J. van der Laan] <gnufnork-AT-hetdigitalegat.nl> Bash-like
5850 * [W.J. van der Laan] <gnufnork-AT-hetdigitalegat.nl> Bash-like
5836 prompt specials.
5851 prompt specials.
5837 * [Antoon Pardon] <Antoon.Pardon-AT-rece.vub.ac.be> Critical fix for
5852 * [Antoon Pardon] <Antoon.Pardon-AT-rece.vub.ac.be> Critical fix for
5838 the multithreaded IPython.
5853 the multithreaded IPython.
5839 * [John Hunter] <jdhunter-AT-nitace.bsd.uchicago.edu> Matplotlib
5854 * [John Hunter] <jdhunter-AT-nitace.bsd.uchicago.edu> Matplotlib
5840 author, helped with all the development of support for matplotlib
5855 author, helped with all the development of support for matplotlib
5841 in IPyhton, including making necessary changes to matplotlib itself.
5856 in IPyhton, including making necessary changes to matplotlib itself.
5842 * [Matthew Arnison] <maffew-AT-cat.org.au> Bug reports, '%run -d' idea.
5857 * [Matthew Arnison] <maffew-AT-cat.org.au> Bug reports, '%run -d' idea.
5843 * [Prabhu Ramachandran] <prabhu_r-AT-users.sourceforge.net> Help
5858 * [Prabhu Ramachandran] <prabhu_r-AT-users.sourceforge.net> Help
5844 with (X)Emacs support, threading patches, ideas...
5859 with (X)Emacs support, threading patches, ideas...
5845 * [Norbert Tretkowski] <tretkowski-AT-inittab.de> help with Debian
5860 * [Norbert Tretkowski] <tretkowski-AT-inittab.de> help with Debian
5846 packaging and distribution.
5861 packaging and distribution.
5847 * [George Sakkis] <gsakkis-AT-eden.rutgers.edu> New matcher for
5862 * [George Sakkis] <gsakkis-AT-eden.rutgers.edu> New matcher for
5848 tab-completing named arguments of user-defined functions.
5863 tab-completing named arguments of user-defined functions.
5849 * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu> Wildcard
5864 * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu> Wildcard
5850 support implementation for searching namespaces.
5865 support implementation for searching namespaces.
5851 * [Vivian De Smedt] <vivian-AT-vdesmedt.com> Debugger enhancements,
5866 * [Vivian De Smedt] <vivian-AT-vdesmedt.com> Debugger enhancements,
5852 so that when pdb is activated from within IPython, coloring, tab
5867 so that when pdb is activated from within IPython, coloring, tab
5853 completion and other features continue to work seamlessly.
5868 completion and other features continue to work seamlessly.
5854 * [Scott Tsai] <scottt958-AT-yahoo.com.tw> Support for automatic
5869 * [Scott Tsai] <scottt958-AT-yahoo.com.tw> Support for automatic
5855 editor invocation on syntax errors (see
5870 editor invocation on syntax errors (see
5856 http://www.scipy.net/roundup/ipython/issue36).
5871 http://www.scipy.net/roundup/ipython/issue36).
5857 * [Alexander Belchenko] <bialix-AT-ukr.net> Improvements for win32
5872 * [Alexander Belchenko] <bialix-AT-ukr.net> Improvements for win32
5858 paging system.
5873 paging system.
5859 * [Will Maier] <willmaier-AT-ml1.net> Official OpenBSD port.
5874 * [Will Maier] <willmaier-AT-ml1.net> Official OpenBSD port.
5860
5875
General Comments 0
You need to be logged in to leave comments. Login now