Show More
This diff has been collapsed as it changes many lines, (546 lines changed) Show them Hide them | |||||
@@ -1,5022 +1,5402 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 | Welcome to IPython's documentation! |
|
5 | Welcome to IPython's 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 | Overview |
|
20 | Overview | |
21 | ======== |
|
21 | ======== | |
22 |
|
22 | |||
23 | One of Python's most useful features is its interactive interpreter. |
|
23 | One of Python's most useful features is its interactive interpreter. | |
24 | This system allows very fast testing of ideas without the overhead of |
|
24 | This system allows very fast testing of ideas without the overhead of | |
25 | creating test files as is typical in most programming languages. |
|
25 | creating test files as is typical in most programming languages. | |
26 | However, the interpreter supplied with the standard Python distribution |
|
26 | However, the interpreter supplied with the standard Python distribution | |
27 | is somewhat limited for extended interactive use. |
|
27 | is somewhat limited for extended interactive use. | |
28 |
|
28 | |||
29 | IPython is a free software project (released under the BSD license) |
|
29 | IPython is a free software project (released under the BSD license) | |
30 | which tries to: |
|
30 | which tries to: | |
31 |
|
31 | |||
32 | 1. Provide an interactive shell superior to Python's default. IPython |
|
32 | 1. Provide an interactive shell superior to Python's default. IPython | |
33 | has many features for object introspection, system shell access, |
|
33 | has many features for object introspection, system shell access, | |
34 | and its own special command system for adding functionality when |
|
34 | and its own special command system for adding functionality when | |
35 | working interactively. It tries to be a very efficient environment |
|
35 | working interactively. It tries to be a very efficient environment | |
36 | both for Python code development and for exploration of problems |
|
36 | both for Python code development and for exploration of problems | |
37 | using Python objects (in situations like data analysis). |
|
37 | using Python objects (in situations like data analysis). | |
38 | 2. Serve as an embeddable, ready to use interpreter for your own |
|
38 | 2. Serve as an embeddable, ready to use interpreter for your own | |
39 | programs. IPython can be started with a single call from inside |
|
39 | programs. IPython can be started with a single call from inside | |
40 | another program, providing access to the current namespace. This |
|
40 | another program, providing access to the current namespace. This | |
41 | can be very useful both for debugging purposes and for situations |
|
41 | can be very useful both for debugging purposes and for situations | |
42 | where a blend of batch-processing and interactive exploration are |
|
42 | where a blend of batch-processing and interactive exploration are | |
43 | needed. |
|
43 | needed. | |
44 | 3. Offer a flexible framework which can be used as the base |
|
44 | 3. Offer a flexible framework which can be used as the base | |
45 | environment for other systems with Python as the underlying |
|
45 | environment for other systems with Python as the underlying | |
46 | language. Specifically scientific environments like Mathematica, |
|
46 | language. Specifically scientific environments like Mathematica, | |
47 | IDL and Matlab inspired its design, but similar ideas can be |
|
47 | IDL and Matlab inspired its design, but similar ideas can be | |
48 | useful in many fields. |
|
48 | useful in many fields. | |
49 | 4. Allow interactive testing of threaded graphical toolkits. IPython |
|
49 | 4. Allow interactive testing of threaded graphical toolkits. IPython | |
50 | has support for interactive, non-blocking control of GTK, Qt and |
|
50 | has support for interactive, non-blocking control of GTK, Qt and | |
51 | WX applications via special threading flags. The normal Python |
|
51 | WX applications via special threading flags. The normal Python | |
52 | shell can only do this for Tkinter applications. |
|
52 | shell can only do this for Tkinter applications. | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | Main features |
|
55 | Main features | |
|
56 | ------------- | |||
56 |
|
57 | |||
57 | * Dynamic object introspection. One can access docstrings, function |
|
58 | * Dynamic object introspection. One can access docstrings, function | |
58 | definition prototypes, source code, source files and other details |
|
59 | definition prototypes, source code, source files and other details | |
59 | of any object accessible to the interpreter with a single |
|
60 | of any object accessible to the interpreter with a single | |
60 | keystroke ('?', and using '??' provides additional detail). |
|
61 | keystroke ('?', and using '??' provides additional detail). | |
61 | * Searching through modules and namespaces with '*' wildcards, both |
|
62 | * Searching through modules and namespaces with '*' wildcards, both | |
62 | when using the '?' system and via the %psearch command. |
|
63 | when using the '?' system and via the %psearch command. | |
63 | * Completion in the local namespace, by typing TAB at the prompt. |
|
64 | * Completion in the local namespace, by typing TAB at the prompt. | |
64 | This works for keywords, methods, variables and files in the |
|
65 | This works for keywords, methods, variables and files in the | |
65 | current directory. This is supported via the readline library, and |
|
66 | current directory. This is supported via the readline library, and | |
66 | full access to configuring readline's behavior is provided. |
|
67 | full access to configuring readline's behavior is provided. | |
67 | * Numbered input/output prompts with command history (persistent |
|
68 | * Numbered input/output prompts with command history (persistent | |
68 | across sessions and tied to each profile), full searching in this |
|
69 | across sessions and tied to each profile), full searching in this | |
69 | history and caching of all input and output. |
|
70 | history and caching of all input and output. | |
70 | * User-extensible 'magic' commands. A set of commands prefixed with |
|
71 | * User-extensible 'magic' commands. A set of commands prefixed with | |
71 | % is available for controlling IPython itself and provides |
|
72 | % is available for controlling IPython itself and provides | |
72 | directory control, namespace information and many aliases to |
|
73 | directory control, namespace information and many aliases to | |
73 | common system shell commands. |
|
74 | common system shell commands. | |
74 | * Alias facility for defining your own system aliases. |
|
75 | * Alias facility for defining your own system aliases. | |
75 | * Complete system shell access. Lines starting with ! are passed |
|
76 | * Complete system shell access. Lines starting with ! are passed | |
76 | directly to the system shell, and using !! captures shell output |
|
77 | directly to the system shell, and using !! captures shell output | |
77 | into python variables for further use. |
|
78 | into python variables for further use. | |
78 | * Background execution of Python commands in a separate thread. |
|
79 | * Background execution of Python commands in a separate thread. | |
79 | IPython has an internal job manager called jobs, and a |
|
80 | IPython has an internal job manager called jobs, and a | |
80 | conveninence backgrounding magic function called %bg. |
|
81 | conveninence backgrounding magic function called %bg. | |
81 | * The ability to expand python variables when calling the system |
|
82 | * The ability to expand python variables when calling the system | |
82 | shell. In a shell command, any python variable prefixed with $ is |
|
83 | shell. In a shell command, any python variable prefixed with $ is | |
83 | expanded. A double $$ allows passing a literal $ to the shell (for |
|
84 | expanded. A double $$ allows passing a literal $ to the shell (for | |
84 | access to shell and environment variables like $PATH). |
|
85 | access to shell and environment variables like $PATH). | |
85 | * Filesystem navigation, via a magic %cd command, along with a |
|
86 | * Filesystem navigation, via a magic %cd command, along with a | |
86 | persistent bookmark system (using %bookmark) for fast access to |
|
87 | persistent bookmark system (using %bookmark) for fast access to | |
87 | frequently visited directories. |
|
88 | frequently visited directories. | |
88 | * A lightweight persistence framework via the %store command, which |
|
89 | * A lightweight persistence framework via the %store command, which | |
89 | allows you to save arbitrary Python variables. These get restored |
|
90 | allows you to save arbitrary Python variables. These get restored | |
90 | automatically when your session restarts. |
|
91 | automatically when your session restarts. | |
91 | * Automatic indentation (optional) of code as you type (through the |
|
92 | * Automatic indentation (optional) of code as you type (through the | |
92 | readline library). |
|
93 | readline library). | |
93 | * Macro system for quickly re-executing multiple lines of previous |
|
94 | * Macro system for quickly re-executing multiple lines of previous | |
94 | input with a single name. Macros can be stored persistently via |
|
95 | input with a single name. Macros can be stored persistently via | |
95 | %store and edited via %edit. |
|
96 | %store and edited via %edit. | |
96 | * Session logging (you can then later use these logs as code in your |
|
97 | * Session logging (you can then later use these logs as code in your | |
97 | programs). Logs can optionally timestamp all input, and also store |
|
98 | programs). Logs can optionally timestamp all input, and also store | |
98 | session output (marked as comments, so the log remains valid |
|
99 | session output (marked as comments, so the log remains valid | |
99 | Python source code). |
|
100 | Python source code). | |
100 | * Session restoring: logs can be replayed to restore a previous |
|
101 | * Session restoring: logs can be replayed to restore a previous | |
101 | session to the state where you left it. |
|
102 | session to the state where you left it. | |
102 | * Verbose and colored exception traceback printouts. Easier to parse |
|
103 | * Verbose and colored exception traceback printouts. Easier to parse | |
103 | visually, and in verbose mode they produce a lot of useful |
|
104 | visually, and in verbose mode they produce a lot of useful | |
104 | debugging information (basically a terminal version of the cgitb |
|
105 | debugging information (basically a terminal version of the cgitb | |
105 | module). |
|
106 | module). | |
106 | * Auto-parentheses: callable objects can be executed without |
|
107 | * Auto-parentheses: callable objects can be executed without | |
107 | parentheses: 'sin 3' is automatically converted to 'sin(3)'. |
|
108 | parentheses: 'sin 3' is automatically converted to 'sin(3)'. | |
108 | * Auto-quoting: using ',' or ';' as the first character forces |
|
109 | * Auto-quoting: using ',' or ';' as the first character forces | |
109 | auto-quoting of the rest of the line: ',my_function a b' becomes |
|
110 | auto-quoting of the rest of the line: ',my_function a b' becomes | |
110 | automatically 'my_function("a","b")', while ';my_function a b' |
|
111 | automatically 'my_function("a","b")', while ';my_function a b' | |
111 | becomes 'my_function("a b")'. |
|
112 | becomes 'my_function("a b")'. | |
112 | * Extensible input syntax. You can define filters that pre-process |
|
113 | * Extensible input syntax. You can define filters that pre-process | |
113 | user input to simplify input in special situations. This allows |
|
114 | user input to simplify input in special situations. This allows | |
114 | for example pasting multi-line code fragments which start with |
|
115 | for example pasting multi-line code fragments which start with | |
115 | '>>>' or '...' such as those from other python sessions or the |
|
116 | '>>>' or '...' such as those from other python sessions or the | |
116 | standard Python documentation. |
|
117 | standard Python documentation. | |
117 | * Flexible configuration system. It uses a configuration file which |
|
118 | * Flexible configuration system. It uses a configuration file which | |
118 | allows permanent setting of all command-line options, module |
|
119 | allows permanent setting of all command-line options, module | |
119 | loading, code and file execution. The system allows recursive file |
|
120 | loading, code and file execution. The system allows recursive file | |
120 | inclusion, so you can have a base file with defaults and layers |
|
121 | inclusion, so you can have a base file with defaults and layers | |
121 | which load other customizations for particular projects. |
|
122 | which load other customizations for particular projects. | |
122 | * Embeddable. You can call IPython as a python shell inside your own |
|
123 | * Embeddable. You can call IPython as a python shell inside your own | |
123 | python programs. This can be used both for debugging code or for |
|
124 | python programs. This can be used both for debugging code or for | |
124 | providing interactive abilities to your programs with knowledge |
|
125 | providing interactive abilities to your programs with knowledge | |
125 | about the local namespaces (very useful in debugging and data |
|
126 | about the local namespaces (very useful in debugging and data | |
126 | analysis situations). |
|
127 | analysis situations). | |
127 | * Easy debugger access. You can set IPython to call up an enhanced |
|
128 | * Easy debugger access. You can set IPython to call up an enhanced | |
128 | version of the Python debugger (pdb) every time there is an |
|
129 | version of the Python debugger (pdb) every time there is an | |
129 | uncaught exception. This drops you inside the code which triggered |
|
130 | uncaught exception. This drops you inside the code which triggered | |
130 | the exception with all the data live and it is possible to |
|
131 | the exception with all the data live and it is possible to | |
131 | navigate the stack to rapidly isolate the source of a bug. The |
|
132 | navigate the stack to rapidly isolate the source of a bug. The | |
132 | %run magic command -with the -d option- can run any script under |
|
133 | %run magic command -with the -d option- can run any script under | |
133 | pdb's control, automatically setting initial breakpoints for you. |
|
134 | pdb's control, automatically setting initial breakpoints for you. | |
134 | This version of pdb has IPython-specific improvements, including |
|
135 | This version of pdb has IPython-specific improvements, including | |
135 | tab-completion and traceback coloring support. |
|
136 | tab-completion and traceback coloring support. | |
136 | * Profiler support. You can run single statements (similar to |
|
137 | * Profiler support. You can run single statements (similar to | |
137 | profile.run()) or complete programs under the profiler's control. |
|
138 | profile.run()) or complete programs under the profiler's control. | |
138 | While this is possible with standard cProfile or profile modules, |
|
139 | While this is possible with standard cProfile or profile modules, | |
139 | IPython wraps this functionality with magic commands (see '%prun' |
|
140 | IPython wraps this functionality with magic commands (see '%prun' | |
140 | and '%run -p') convenient for rapid interactive work. |
|
141 | and '%run -p') convenient for rapid interactive work. | |
141 | * Doctest support. The special %doctest_mode command toggles a mode |
|
142 | * Doctest support. The special %doctest_mode command toggles a mode | |
142 | that allows you to paste existing doctests (with leading '>>>' |
|
143 | that allows you to paste existing doctests (with leading '>>>' | |
143 | prompts and whitespace) and uses doctest-compatible prompts and |
|
144 | prompts and whitespace) and uses doctest-compatible prompts and | |
144 | output, so you can use IPython sessions as doctest code. |
|
145 | output, so you can use IPython sessions as doctest code. | |
145 |
|
146 | |||
146 |
|
147 | |||
147 | Portability and Python requirements |
|
148 | Portability and Python requirements | |
148 | ----------------------------------- |
|
149 | ----------------------------------- | |
149 |
|
150 | |||
150 | Python requirements: IPython requires with Python version 2.3 or newer. |
|
151 | Python requirements: IPython requires with Python version 2.3 or newer. | |
151 | If you are still using Python 2.2 and can not upgrade, the last version |
|
152 | If you are still using Python 2.2 and can not upgrade, the last version | |
152 | of IPython which worked with Python 2.2 was 0.6.15, so you will have to |
|
153 | of IPython which worked with Python 2.2 was 0.6.15, so you will have to | |
153 | use that. |
|
154 | use that. | |
154 |
|
155 | |||
155 | IPython is developed under Linux, but it should work in any reasonable |
|
156 | IPython is developed under Linux, but it should work in any reasonable | |
156 | Unix-type system (tested OK under Solaris and the BSD family, for which |
|
157 | Unix-type system (tested OK under Solaris and the BSD family, for which | |
157 | a port exists thanks to Dryice Liu). |
|
158 | a port exists thanks to Dryice Liu). | |
158 |
|
159 | |||
159 | Mac OS X: it works, apparently without any problems (thanks to Jim Boyle |
|
160 | Mac OS X: it works, apparently without any problems (thanks to Jim Boyle | |
160 | at Lawrence Livermore for the information). Thanks to Andrea Riciputi, |
|
161 | at Lawrence Livermore for the information). Thanks to Andrea Riciputi, | |
161 | Fink support is available. |
|
162 | Fink support is available. | |
162 |
|
163 | |||
163 | CygWin: it works mostly OK, though some users have reported problems |
|
164 | CygWin: it works mostly OK, though some users have reported problems | |
164 | with prompt coloring. No satisfactory solution to this has been found so |
|
165 | with prompt coloring. No satisfactory solution to this has been found so | |
165 | far, you may want to disable colors permanently in the ipythonrc |
|
166 | far, you may want to disable colors permanently in the ipythonrc | |
166 | configuration file if you experience problems. If you have proper color |
|
167 | configuration file if you experience problems. If you have proper color | |
167 | support under cygwin, please post to the IPython mailing list so this |
|
168 | support under cygwin, please post to the IPython mailing list so this | |
168 | issue can be resolved for all users. |
|
169 | issue can be resolved for all users. | |
169 |
|
170 | |||
170 | Windows: it works well under Windows XP/2k, and I suspect NT should |
|
171 | Windows: it works well under Windows XP/2k, and I suspect NT should | |
171 | behave similarly. Section 2.3 <node2.html#sub:Under-Windows> describes |
|
172 | behave similarly. Section 2.3 <node2.html#sub:Under-Windows> describes | |
172 | installation details for Windows, including some additional tools needed |
|
173 | installation details for Windows, including some additional tools needed | |
173 | on this platform. |
|
174 | on this platform. | |
174 |
|
175 | |||
175 | Windows 9x support is present, and has been reported to work fine (at |
|
176 | Windows 9x support is present, and has been reported to work fine (at | |
176 | least on WinME). |
|
177 | least on WinME). | |
177 |
|
178 | |||
178 | Note, that I have very little access to and experience with Windows |
|
179 | Note, that I have very little access to and experience with Windows | |
179 | development. However, an excellent group of Win32 users (led by Ville |
|
180 | development. However, an excellent group of Win32 users (led by Ville | |
180 | Vainio), consistently contribute bugfixes and platform-specific |
|
181 | Vainio), consistently contribute bugfixes and platform-specific | |
181 | enhancements, so they more than make up for my deficiencies on that |
|
182 | enhancements, so they more than make up for my deficiencies on that | |
182 | front. In fact, Win32 users report using IPython as a system shell (see |
|
183 | front. In fact, Win32 users report using IPython as a system shell (see | |
183 | Sec. 12 <node12.html#sec:IPython-as-shell> for details), as it offers a |
|
184 | Sec. 12 <node12.html#sec:IPython-as-shell> for details), as it offers a | |
184 | level of control and features which the default cmd.exe doesn't provide. |
|
185 | level of control and features which the default cmd.exe doesn't provide. | |
185 |
|
186 | |||
186 |
|
187 | |||
187 | Location |
|
188 | Location | |
188 | ======== |
|
189 | ======== | |
189 |
|
190 | |||
190 | IPython is generously hosted at http://ipython.scipy.org by the |
|
191 | IPython is generously hosted at http://ipython.scipy.org by the | |
191 | Enthought, Inc and the SciPy project. This site offers downloads, |
|
192 | Enthought, Inc and the SciPy project. This site offers downloads, | |
192 | subversion access, mailing lists and a bug tracking system. I am very |
|
193 | subversion access, mailing lists and a bug tracking system. I am very | |
193 | grateful to Enthought (http://www.enthought.com) and all of the SciPy |
|
194 | grateful to Enthought (http://www.enthought.com) and all of the SciPy | |
194 | team for their contribution. |
|
195 | team for their contribution. | |
195 |
|
196 | |||
196 | Installation |
|
197 | Installation | |
197 | ============ |
|
198 | ============ | |
198 |
|
199 | |||
199 | Instant instructions |
|
200 | Instant instructions | |
200 | -------------------- |
|
201 | -------------------- | |
201 |
|
202 | |||
202 | If you are of the impatient kind, under Linux/Unix simply untar/unzip |
|
203 | If you are of the impatient kind, under Linux/Unix simply untar/unzip | |
203 | the download, then install with 'python setup.py install'. Under |
|
204 | the download, then install with 'python setup.py install'. Under | |
204 | Windows, double-click on the provided .exe binary installer. |
|
205 | Windows, double-click on the provided .exe binary installer. | |
205 |
|
206 | |||
206 | Then, take a look at Sections 3 <node3.html#sec:good_config> for |
|
207 | Then, take a look at Sections 3 <node3.html#sec:good_config> for | |
207 | configuring things optimally and 4 <node4.html#sec:quick_tips> for quick |
|
208 | configuring things optimally and 4 <node4.html#sec:quick_tips> for quick | |
208 | tips on efficient use of IPython. You can later refer to the rest of the |
|
209 | tips on efficient use of IPython. You can later refer to the rest of the | |
209 | manual for all the gory details. |
|
210 | manual for all the gory details. | |
210 |
|
211 | |||
211 | See the notes in sec. 2.4 <#sec:upgrade> for upgrading IPython versions. |
|
212 | See the notes in sec. 2.4 <#sec:upgrade> for upgrading IPython versions. | |
212 |
|
213 | |||
213 |
|
214 | |||
214 | Detailed Unix instructions (Linux, Mac OS X, etc.) |
|
215 | Detailed Unix instructions (Linux, Mac OS X, etc.) | |
215 |
|
216 | |||
216 | For RPM based systems, simply install the supplied package in the usual |
|
217 | For RPM based systems, simply install the supplied package in the usual | |
217 | manner. If you download the tar archive, the process is: |
|
218 | manner. If you download the tar archive, the process is: | |
218 |
|
219 | |||
219 | 1. Unzip/untar the ipython-XXX.tar.gz file wherever you want (XXX is |
|
220 | 1. Unzip/untar the ipython-XXX.tar.gz file wherever you want (XXX is | |
220 | the version number). It will make a directory called ipython-XXX. |
|
221 | the version number). It will make a directory called ipython-XXX. | |
221 | Change into that directory where you will find the files README |
|
222 | Change into that directory where you will find the files README | |
222 | and setup.py. Once you've completed the installation, you can |
|
223 | and setup.py. Once you've completed the installation, you can | |
223 | safely remove this directory. |
|
224 | safely remove this directory. | |
224 | 2. If you are installing over a previous installation of version |
|
225 | 2. If you are installing over a previous installation of version | |
225 | 0.2.0 or earlier, first remove your $HOME/.ipython directory, |
|
226 | 0.2.0 or earlier, first remove your $HOME/.ipython directory, | |
226 | since the configuration file format has changed somewhat (the '=' |
|
227 | since the configuration file format has changed somewhat (the '=' | |
227 | were removed from all option specifications). Or you can call |
|
228 | were removed from all option specifications). Or you can call | |
228 | ipython with the -upgrade option and it will do this automatically |
|
229 | ipython with the -upgrade option and it will do this automatically | |
229 | for you. |
|
230 | for you. | |
230 | 3. IPython uses distutils, so you can install it by simply typing at |
|
231 | 3. IPython uses distutils, so you can install it by simply typing at | |
231 | the system prompt (don't type the $):: |
|
232 | the system prompt (don't type the $):: | |
232 |
|
233 | |||
233 | $ python setup.py install |
|
234 | $ python setup.py install | |
234 |
|
235 | |||
235 | Note that this assumes you have root access to your machine. If |
|
236 | Note that this assumes you have root access to your machine. If | |
236 | you don't have root access or don't want IPython to go in the |
|
237 | you don't have root access or don't want IPython to go in the | |
237 | default python directories, you'll need to use the ``--home`` option |
|
238 | default python directories, you'll need to use the ``--home`` option | |
238 | (or ``--prefix``). For example:: |
|
239 | (or ``--prefix``). For example:: | |
239 |
|
240 | |||
240 | $ python setup.py install --home $HOME/local |
|
241 | $ python setup.py install --home $HOME/local | |
241 |
|
242 | |||
242 | will install IPython into $HOME/local and its subdirectories |
|
243 | will install IPython into $HOME/local and its subdirectories | |
243 | (creating them if necessary). |
|
244 | (creating them if necessary). | |
244 | You can type:: |
|
245 | You can type:: | |
245 |
|
246 | |||
246 | $ python setup.py --help |
|
247 | $ python setup.py --help | |
247 |
|
248 | |||
248 | for more details. |
|
249 | for more details. | |
249 |
|
250 | |||
250 | Note that if you change the default location for ``--home`` at |
|
251 | Note that if you change the default location for ``--home`` at | |
251 | installation, IPython may end up installed at a location which is |
|
252 | installation, IPython may end up installed at a location which is | |
252 | not part of your $PYTHONPATH environment variable. In this case, |
|
253 | not part of your $PYTHONPATH environment variable. In this case, | |
253 | you'll need to configure this variable to include the actual |
|
254 | you'll need to configure this variable to include the actual | |
254 | directory where the IPython/ directory ended (typically the value |
|
255 | directory where the IPython/ directory ended (typically the value | |
255 | you give to ``--home`` plus /lib/python). |
|
256 | you give to ``--home`` plus /lib/python). | |
256 |
|
257 | |||
257 |
|
258 | |||
258 | Mac OSX information |
|
259 | Mac OSX information | |
259 | ------------------- |
|
260 | ------------------- | |
260 |
|
261 | |||
261 | Under OSX, there is a choice you need to make. Apple ships its own build |
|
262 | Under OSX, there is a choice you need to make. Apple ships its own build | |
262 | of Python, which lives in the core OSX filesystem hierarchy. You can |
|
263 | of Python, which lives in the core OSX filesystem hierarchy. You can | |
263 | also manually install a separate Python, either purely by hand |
|
264 | also manually install a separate Python, either purely by hand | |
264 | (typically in /usr/local) or by using Fink, which puts everything under |
|
265 | (typically in /usr/local) or by using Fink, which puts everything under | |
265 | /sw. Which route to follow is a matter of personal preference, as I've |
|
266 | /sw. Which route to follow is a matter of personal preference, as I've | |
266 | seen users who favor each of the approaches. Here I will simply list the |
|
267 | seen users who favor each of the approaches. Here I will simply list the | |
267 | known installation issues under OSX, along with their solutions. |
|
268 | known installation issues under OSX, along with their solutions. | |
268 |
|
269 | |||
269 | This page: http://geosci.uchicago.edu/~tobis/pylab.html contains |
|
270 | This page: http://geosci.uchicago.edu/~tobis/pylab.html contains | |
270 | information on this topic, with additional details on how to make |
|
271 | information on this topic, with additional details on how to make | |
271 | IPython and matplotlib play nicely under OSX. |
|
272 | IPython and matplotlib play nicely under OSX. | |
272 |
|
273 | |||
273 |
|
274 | |||
274 | GUI problems |
|
275 | GUI problems | |
275 | ------------ |
|
276 | ------------ | |
276 |
|
277 | |||
277 | The following instructions apply to an install of IPython under OSX from |
|
278 | The following instructions apply to an install of IPython under OSX from | |
278 | unpacking the .tar.gz distribution and installing it for the default |
|
279 | unpacking the .tar.gz distribution and installing it for the default | |
279 | Python interpreter shipped by Apple. If you are using a fink install, |
|
280 | Python interpreter shipped by Apple. If you are using a fink install, | |
280 | fink will take care of these details for you, by installing IPython |
|
281 | fink will take care of these details for you, by installing IPython | |
281 | against fink's Python. |
|
282 | against fink's Python. | |
282 |
|
283 | |||
283 | IPython offers various forms of support for interacting with graphical |
|
284 | IPython offers various forms of support for interacting with graphical | |
284 | applications from the command line, from simple Tk apps (which are in |
|
285 | applications from the command line, from simple Tk apps (which are in | |
285 | principle always supported by Python) to interactive control of WX, Qt |
|
286 | principle always supported by Python) to interactive control of WX, Qt | |
286 | and GTK apps. Under OSX, however, this requires that ipython is |
|
287 | and GTK apps. Under OSX, however, this requires that ipython is | |
287 | installed by calling the special pythonw script at installation time, |
|
288 | installed by calling the special pythonw script at installation time, | |
288 | which takes care of coordinating things with Apple's graphical environment. |
|
289 | which takes care of coordinating things with Apple's graphical environment. | |
289 |
|
290 | |||
290 | So when installing under OSX, it is best to use the following command:: |
|
291 | So when installing under OSX, it is best to use the following command:: | |
291 |
|
292 | |||
292 | $ sudo pythonw setup.py install --install-scripts=/usr/local/bin |
|
293 | $ sudo pythonw setup.py install --install-scripts=/usr/local/bin | |
293 |
|
294 | |||
294 | or |
|
295 | or | |
295 |
|
296 | |||
296 | $ sudo pythonw setup.py install --install-scripts=/usr/bin |
|
297 | $ sudo pythonw setup.py install --install-scripts=/usr/bin | |
297 |
|
298 | |||
298 | depending on where you like to keep hand-installed executables. |
|
299 | depending on where you like to keep hand-installed executables. | |
299 |
|
300 | |||
300 | The resulting script will have an appropriate shebang line (the first |
|
301 | The resulting script will have an appropriate shebang line (the first | |
301 | line in the script whic begins with #!...) such that the ipython |
|
302 | line in the script whic begins with #!...) such that the ipython | |
302 | interpreter can interact with the OS X GUI. If the installed version |
|
303 | interpreter can interact with the OS X GUI. If the installed version | |
303 | does not work and has a shebang line that points to, for example, just |
|
304 | does not work and has a shebang line that points to, for example, just | |
304 | /usr/bin/python, then you might have a stale, cached version in your |
|
305 | /usr/bin/python, then you might have a stale, cached version in your | |
305 | build/scripts-<python-version> directory. Delete that directory and |
|
306 | build/scripts-<python-version> directory. Delete that directory and | |
306 | rerun the setup.py. |
|
307 | rerun the setup.py. | |
307 |
|
308 | |||
308 | It is also a good idea to use the special flag ``--install-scripts`` as |
|
309 | It is also a good idea to use the special flag ``--install-scripts`` as | |
309 | indicated above, to ensure that the ipython scripts end up in a location |
|
310 | indicated above, to ensure that the ipython scripts end up in a location | |
310 | which is part of your $PATH. Otherwise Apple's Python will put the |
|
311 | which is part of your $PATH. Otherwise Apple's Python will put the | |
311 | scripts in an internal directory not available by default at the command |
|
312 | scripts in an internal directory not available by default at the command | |
312 | line (if you use /usr/local/bin, you need to make sure this is in your |
|
313 | line (if you use /usr/local/bin, you need to make sure this is in your | |
313 | $PATH, which may not be true by default). |
|
314 | $PATH, which may not be true by default). | |
314 |
|
315 | |||
315 |
|
316 | |||
316 | Readline problems |
|
317 | Readline problems | |
317 | ----------------- |
|
318 | ----------------- | |
318 |
|
319 | |||
319 | By default, the Python version shipped by Apple does not include the |
|
320 | By default, the Python version shipped by Apple does not include the | |
320 | readline library, so central to IPython's behavior. If you install |
|
321 | readline library, so central to IPython's behavior. If you install | |
321 | IPython against Apple's Python, you will not have arrow keys, tab |
|
322 | IPython against Apple's Python, you will not have arrow keys, tab | |
322 | completion, etc. For Mac OSX 10.3 (Panther), you can find a prebuilt |
|
323 | completion, etc. For Mac OSX 10.3 (Panther), you can find a prebuilt | |
323 | readline library here: |
|
324 | readline library here: | |
324 | http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip |
|
325 | http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip | |
325 |
|
326 | |||
326 | If you are using OSX 10.4 (Tiger), after installing this package you |
|
327 | If you are using OSX 10.4 (Tiger), after installing this package you | |
327 | need to either: |
|
328 | need to either: | |
328 |
|
329 | |||
329 | 1. move readline.so from /Library/Python/2.3 to |
|
330 | 1. move readline.so from /Library/Python/2.3 to | |
330 | /Library/Python/2.3/site-packages, or |
|
331 | /Library/Python/2.3/site-packages, or | |
331 | 2. install http://pythonmac.org/packages/TigerPython23Compat.pkg.zip |
|
332 | 2. install http://pythonmac.org/packages/TigerPython23Compat.pkg.zip | |
332 |
|
333 | |||
333 | Users installing against Fink's Python or a properly hand-built one |
|
334 | Users installing against Fink's Python or a properly hand-built one | |
334 | should not have this problem. |
|
335 | should not have this problem. | |
335 |
|
336 | |||
336 |
|
337 | |||
337 | DarwinPorts |
|
338 | DarwinPorts | |
338 | ----------- |
|
339 | ----------- | |
339 |
|
340 | |||
340 | I report here a message from an OSX user, who suggests an alternative |
|
341 | I report here a message from an OSX user, who suggests an alternative | |
341 | means of using IPython under this operating system with good results. |
|
342 | means of using IPython under this operating system with good results. | |
342 | Please let me know of any updates that may be useful for this section. |
|
343 | Please let me know of any updates that may be useful for this section. | |
343 | His message is reproduced verbatim below: |
|
344 | His message is reproduced verbatim below: | |
344 |
|
345 | |||
345 | From: Markus Banfi <markus.banfi-AT-mospheira.net> |
|
346 | From: Markus Banfi <markus.banfi-AT-mospheira.net> | |
346 |
|
347 | |||
347 | As a MacOS X (10.4.2) user I prefer to install software using |
|
348 | As a MacOS X (10.4.2) user I prefer to install software using | |
348 | DawinPorts instead of Fink. I had no problems installing ipython |
|
349 | DawinPorts instead of Fink. I had no problems installing ipython | |
349 | with DarwinPorts. It's just: |
|
350 | with DarwinPorts. It's just: | |
350 |
|
351 | |||
351 | sudo port install py-ipython |
|
352 | sudo port install py-ipython | |
352 |
|
353 | |||
353 | It automatically resolved all dependencies (python24, readline, |
|
354 | It automatically resolved all dependencies (python24, readline, | |
354 | py-readline). So far I did not encounter any problems with the |
|
355 | py-readline). So far I did not encounter any problems with the | |
355 | DarwinPorts port of ipython. |
|
356 | DarwinPorts port of ipython. | |
356 |
|
357 | |||
357 |
|
358 | |||
358 |
|
359 | |||
359 | Windows instructions |
|
360 | Windows instructions | |
360 | -------------------- |
|
361 | -------------------- | |
361 |
|
362 | |||
362 | Some of IPython's very useful features are: |
|
363 | Some of IPython's very useful features are: | |
363 |
|
364 | |||
364 | * Integrated readline support (Tab-based file, object and attribute |
|
365 | * Integrated readline support (Tab-based file, object and attribute | |
365 | completion, input history across sessions, editable command line, |
|
366 | completion, input history across sessions, editable command line, | |
366 | etc.) |
|
367 | etc.) | |
367 | * Coloring of prompts, code and tracebacks. |
|
368 | * Coloring of prompts, code and tracebacks. | |
368 |
|
369 | |||
369 | These, by default, are only available under Unix-like operating systems. |
|
370 | These, by default, are only available under Unix-like operating systems. | |
370 | However, thanks to Gary Bishop's work, Windows XP/2k users can also |
|
371 | However, thanks to Gary Bishop's work, Windows XP/2k users can also | |
371 | benefit from them. His readline library originally implemented both GNU |
|
372 | benefit from them. His readline library originally implemented both GNU | |
372 | readline functionality and color support, so that IPython under Windows |
|
373 | readline functionality and color support, so that IPython under Windows | |
373 | XP/2k can be as friendly and powerful as under Unix-like environments. |
|
374 | XP/2k can be as friendly and powerful as under Unix-like environments. | |
374 |
|
375 | |||
375 | This library, now named PyReadline, has been absorbed by the IPython |
|
376 | This library, now named PyReadline, has been absorbed by the IPython | |
376 | team (Jörgen Stenarson, in particular), and it continues to be developed |
|
377 | team (Jörgen Stenarson, in particular), and it continues to be developed | |
377 | with new features, as well as being distributed directly from the |
|
378 | with new features, as well as being distributed directly from the | |
378 | IPython site. |
|
379 | IPython site. | |
379 |
|
380 | |||
380 | The PyReadline extension requires CTypes and the windows IPython |
|
381 | The PyReadline extension requires CTypes and the windows IPython | |
381 | installer needs PyWin32, so in all you need: |
|
382 | installer needs PyWin32, so in all you need: | |
382 |
|
383 | |||
383 | 1. PyWin32 from http://sourceforge.net/projects/pywin32. |
|
384 | 1. PyWin32 from http://sourceforge.net/projects/pywin32. | |
384 | 2. PyReadline for Windows from |
|
385 | 2. PyReadline for Windows from | |
385 | http://ipython.scipy.org/moin/PyReadline/Intro. That page contains |
|
386 | http://ipython.scipy.org/moin/PyReadline/Intro. That page contains | |
386 | further details on using and configuring the system to your liking. |
|
387 | further details on using and configuring the system to your liking. | |
387 | 3. Finally, only if you are using Python 2.3 or 2.4, you need CTypes |
|
388 | 3. Finally, only if you are using Python 2.3 or 2.4, you need CTypes | |
388 | from http://starship.python.net/crew/theller/ctypes(you must use |
|
389 | from http://starship.python.net/crew/theller/ctypes(you must use | |
389 | version 0.9.1 or newer). This package is included in Python 2.5, |
|
390 | version 0.9.1 or newer). This package is included in Python 2.5, | |
390 | so you don't need to manually get it if your Python version is 2.5 |
|
391 | so you don't need to manually get it if your Python version is 2.5 | |
391 | or newer. |
|
392 | or newer. | |
392 |
|
393 | |||
393 | Warning about a broken readline-like library: several users have |
|
394 | Warning about a broken readline-like library: several users have | |
394 | reported problems stemming from using the pseudo-readline library at |
|
395 | reported problems stemming from using the pseudo-readline library at | |
395 | http://newcenturycomputers.net/projects/readline.html. This is a broken |
|
396 | http://newcenturycomputers.net/projects/readline.html. This is a broken | |
396 | library which, while called readline, only implements an incomplete |
|
397 | library which, while called readline, only implements an incomplete | |
397 | subset of the readline API. Since it is still called readline, it fools |
|
398 | subset of the readline API. Since it is still called readline, it fools | |
398 | IPython's detection mechanisms and causes unpredictable crashes later. |
|
399 | IPython's detection mechanisms and causes unpredictable crashes later. | |
399 | If you wish to use IPython under Windows, you must NOT use this library, |
|
400 | If you wish to use IPython under Windows, you must NOT use this library, | |
400 | which for all purposes is (at least as of version 1.6) terminally broken. |
|
401 | which for all purposes is (at least as of version 1.6) terminally broken. | |
401 |
|
402 | |||
402 |
|
403 | |||
403 | Installation procedure |
|
404 | Installation procedure | |
404 | ---------------------- |
|
405 | ---------------------- | |
405 |
|
406 | |||
406 | Once you have the above installed, from the IPython download directory |
|
407 | Once you have the above installed, from the IPython download directory | |
407 | grab the ipython-XXX.win32.exe file, where XXX represents the version |
|
408 | grab the ipython-XXX.win32.exe file, where XXX represents the version | |
408 | number. This is a regular windows executable installer, which you can |
|
409 | number. This is a regular windows executable installer, which you can | |
409 | simply double-click to install. It will add an entry for IPython to your |
|
410 | simply double-click to install. It will add an entry for IPython to your | |
410 | Start Menu, as well as registering IPython in the Windows list of |
|
411 | Start Menu, as well as registering IPython in the Windows list of | |
411 | applications, so you can later uninstall it from the Control Panel. |
|
412 | applications, so you can later uninstall it from the Control Panel. | |
412 |
|
413 | |||
413 | IPython tries to install the configuration information in a directory |
|
414 | IPython tries to install the configuration information in a directory | |
414 | named .ipython (_ipython under Windows) located in your 'home' |
|
415 | named .ipython (_ipython under Windows) located in your 'home' | |
415 | directory. IPython sets this directory by looking for a HOME environment |
|
416 | directory. IPython sets this directory by looking for a HOME environment | |
416 | variable; if such a variable does not exist, it uses HOMEDRIVE\HOMEPATH |
|
417 | variable; if such a variable does not exist, it uses HOMEDRIVE\HOMEPATH | |
417 | (these are always defined by Windows). This typically gives something |
|
418 | (these are always defined by Windows). This typically gives something | |
418 | like C:\Documents and Settings\YourUserName, but your local details may |
|
419 | like C:\Documents and Settings\YourUserName, but your local details may | |
419 | vary. In this directory you will find all the files that configure |
|
420 | vary. In this directory you will find all the files that configure | |
420 | IPython's defaults, and you can put there your profiles and extensions. |
|
421 | IPython's defaults, and you can put there your profiles and extensions. | |
421 | This directory is automatically added by IPython to sys.path, so |
|
422 | This directory is automatically added by IPython to sys.path, so | |
422 | anything you place there can be found by import statements. |
|
423 | anything you place there can be found by import statements. | |
423 |
|
424 | |||
424 |
|
425 | |||
425 | Upgrading |
|
426 | Upgrading | |
426 | --------- |
|
427 | --------- | |
427 |
|
428 | |||
428 | For an IPython upgrade, you should first uninstall the previous version. |
|
429 | For an IPython upgrade, you should first uninstall the previous version. | |
429 | This will ensure that all files and directories (such as the |
|
430 | This will ensure that all files and directories (such as the | |
430 | documentation) which carry embedded version strings in their names are |
|
431 | documentation) which carry embedded version strings in their names are | |
431 | properly removed. |
|
432 | properly removed. | |
432 |
|
433 | |||
433 |
|
434 | |||
434 | Manual installation under Win32 |
|
435 | Manual installation under Win32 | |
435 | ------------------------------- |
|
436 | ------------------------------- | |
436 |
|
437 | |||
437 | In case the automatic installer does not work for some reason, you can |
|
438 | In case the automatic installer does not work for some reason, you can | |
438 | download the ipython-XXX.tar.gz file, which contains the full IPython |
|
439 | download the ipython-XXX.tar.gz file, which contains the full IPython | |
439 | source distribution (the popular WinZip can read .tar.gz files). After |
|
440 | source distribution (the popular WinZip can read .tar.gz files). After | |
440 | uncompressing the archive, you can install it at a command terminal just |
|
441 | uncompressing the archive, you can install it at a command terminal just | |
441 | like any other Python module, by using 'python setup.py install'. |
|
442 | like any other Python module, by using 'python setup.py install'. | |
442 |
|
443 | |||
443 | After the installation, run the supplied win32_manual_post_install.py |
|
444 | After the installation, run the supplied win32_manual_post_install.py | |
444 | script, which creates the necessary Start Menu shortcuts for you. |
|
445 | script, which creates the necessary Start Menu shortcuts for you. | |
445 |
|
446 | |||
446 |
|
447 | |||
447 |
|
448 | |||
448 | Upgrading from a previous version |
|
449 | Upgrading from a previous version | |
449 | --------------------------------- |
|
450 | --------------------------------- | |
450 |
|
451 | |||
451 | If you are upgrading from a previous version of IPython, after doing the |
|
452 | If you are upgrading from a previous version of IPython, after doing the | |
452 | routine installation described above, you should call IPython with the |
|
453 | routine installation described above, you should call IPython with the | |
453 | -upgrade option the first time you run your new copy. This will |
|
454 | -upgrade option the first time you run your new copy. This will | |
454 | automatically update your configuration directory while preserving |
|
455 | automatically update your configuration directory while preserving | |
455 | copies of your old files. You can then later merge back any personal |
|
456 | copies of your old files. You can then later merge back any personal | |
456 | customizations you may have made into the new files. It is a good idea |
|
457 | customizations you may have made into the new files. It is a good idea | |
457 | to do this as there may be new options available in the new |
|
458 | to do this as there may be new options available in the new | |
458 | configuration files which you will not have. |
|
459 | configuration files which you will not have. | |
459 |
|
460 | |||
460 | Under Windows, if you don't know how to call python scripts with |
|
461 | Under Windows, if you don't know how to call python scripts with | |
461 | arguments from a command line, simply delete the old config directory |
|
462 | arguments from a command line, simply delete the old config directory | |
462 | and IPython will make a new one. Win2k and WinXP users will find it in |
|
463 | and IPython will make a new one. Win2k and WinXP users will find it in | |
463 | C:\Documents and Settings\YourUserName\_ipython, and Win 9x users under |
|
464 | C:\Documents and Settings\YourUserName\_ipython, and Win 9x users under | |
464 | C:\Program Files\IPython\_ipython. |
|
465 | C:\Program Files\IPython\_ipython. | |
465 |
|
466 | |||
466 | Initial configuration of your environment |
|
467 | Initial configuration of your environment | |
467 | ========================================= |
|
468 | ========================================= | |
468 |
|
469 | |||
469 | This section will help you set various things in your environment for |
|
470 | This section will help you set various things in your environment for | |
470 | your IPython sessions to be as efficient as possible. All of IPython's |
|
471 | your IPython sessions to be as efficient as possible. All of IPython's | |
471 | configuration information, along with several example files, is stored |
|
472 | configuration information, along with several example files, is stored | |
472 | in a directory named by default $HOME/.ipython. You can change this by |
|
473 | in a directory named by default $HOME/.ipython. You can change this by | |
473 | defining the environment variable IPYTHONDIR, or at runtime with the |
|
474 | defining the environment variable IPYTHONDIR, or at runtime with the | |
474 | command line option -ipythondir. |
|
475 | command line option -ipythondir. | |
475 |
|
476 | |||
476 | If all goes well, the first time you run IPython it should automatically |
|
477 | If all goes well, the first time you run IPython it should automatically | |
477 | create a user copy of the config directory for you, based on its builtin |
|
478 | create a user copy of the config directory for you, based on its builtin | |
478 | defaults. You can look at the files it creates to learn more about |
|
479 | defaults. You can look at the files it creates to learn more about | |
479 | configuring the system. The main file you will modify to configure |
|
480 | configuring the system. The main file you will modify to configure | |
480 | IPython's behavior is called ipythonrc (with a .ini extension under |
|
481 | IPython's behavior is called ipythonrc (with a .ini extension under | |
481 | Windows), included for reference in Sec. 7.1 |
|
482 | Windows), included for reference in Sec. 7.1 | |
482 | <node7.html#sec:ipytonrc-sample>. This file is very commented and has |
|
483 | <node7.html#sec:ipytonrc-sample>. This file is very commented and has | |
483 | many variables you can change to suit your taste, you can find more |
|
484 | many variables you can change to suit your taste, you can find more | |
484 | details in Sec. 7 <node7.html#sec:customization>. Here we discuss the |
|
485 | details in Sec. 7 <node7.html#sec:customization>. Here we discuss the | |
485 | basic things you will want to make sure things are working properly from |
|
486 | basic things you will want to make sure things are working properly from | |
486 | the beginning. |
|
487 | the beginning. | |
487 |
|
488 | |||
488 |
|
489 | |||
489 |
|
490 | |||
490 | Access to the Python help system |
|
491 | Access to the Python help system | |
491 | -------------------------------- |
|
492 | -------------------------------- | |
492 |
|
493 | |||
493 | This is true for Python in general (not just for IPython): you should |
|
494 | This is true for Python in general (not just for IPython): you should | |
494 | have an environment variable called PYTHONDOCS pointing to the directory |
|
495 | have an environment variable called PYTHONDOCS pointing to the directory | |
495 | where your HTML Python documentation lives. In my system it's |
|
496 | where your HTML Python documentation lives. In my system it's | |
496 | /usr/share/doc/python-docs-2.3.4/html, check your local details or ask |
|
497 | /usr/share/doc/python-docs-2.3.4/html, check your local details or ask | |
497 | your systems administrator. |
|
498 | your systems administrator. | |
498 |
|
499 | |||
499 | This is the directory which holds the HTML version of the Python |
|
500 | This is the directory which holds the HTML version of the Python | |
500 | manuals. Unfortunately it seems that different Linux distributions |
|
501 | manuals. Unfortunately it seems that different Linux distributions | |
501 | package these files differently, so you may have to look around a bit. |
|
502 | package these files differently, so you may have to look around a bit. | |
502 | Below I show the contents of this directory on my system for reference:: |
|
503 | Below I show the contents of this directory on my system for reference:: | |
503 |
|
504 | |||
504 | [html]> ls |
|
505 | [html]> ls | |
505 | about.dat acks.html dist/ ext/ index.html lib/ modindex.html |
|
506 | about.dat acks.html dist/ ext/ index.html lib/ modindex.html | |
506 | stdabout.dat tut/ about.html api/ doc/ icons/ inst/ mac/ ref/ style.css |
|
507 | stdabout.dat tut/ about.html api/ doc/ icons/ inst/ mac/ ref/ style.css | |
507 |
|
508 | |||
508 | You should really make sure this variable is correctly set so that |
|
509 | You should really make sure this variable is correctly set so that | |
509 | Python's pydoc-based help system works. It is a powerful and convenient |
|
510 | Python's pydoc-based help system works. It is a powerful and convenient | |
510 | system with full access to the Python manuals and all modules accessible |
|
511 | system with full access to the Python manuals and all modules accessible | |
511 | to you. |
|
512 | to you. | |
512 |
|
513 | |||
513 | Under Windows it seems that pydoc finds the documentation automatically, |
|
514 | Under Windows it seems that pydoc finds the documentation automatically, | |
514 | so no extra setup appears necessary. |
|
515 | so no extra setup appears necessary. | |
515 |
|
516 | |||
516 |
|
517 | |||
517 | Editor |
|
518 | Editor | |
518 | ------ |
|
519 | ------ | |
519 |
|
520 | |||
520 | The %edit command (and its alias %ed) will invoke the editor set in your |
|
521 | The %edit command (and its alias %ed) will invoke the editor set in your | |
521 | environment as EDITOR. If this variable is not set, it will default to |
|
522 | environment as EDITOR. If this variable is not set, it will default to | |
522 | vi under Linux/Unix and to notepad under Windows. You may want to set |
|
523 | vi under Linux/Unix and to notepad under Windows. You may want to set | |
523 | this variable properly and to a lightweight editor which doesn't take |
|
524 | this variable properly and to a lightweight editor which doesn't take | |
524 | too long to start (that is, something other than a new instance of |
|
525 | too long to start (that is, something other than a new instance of | |
525 | Emacs). This way you can edit multi-line code quickly and with the power |
|
526 | Emacs). This way you can edit multi-line code quickly and with the power | |
526 | of a real editor right inside IPython. |
|
527 | of a real editor right inside IPython. | |
527 |
|
528 | |||
528 | If you are a dedicated Emacs user, you should set up the Emacs server so |
|
529 | If you are a dedicated Emacs user, you should set up the Emacs server so | |
529 | that new requests are handled by the original process. This means that |
|
530 | that new requests are handled by the original process. This means that | |
530 | almost no time is spent in handling the request (assuming an Emacs |
|
531 | almost no time is spent in handling the request (assuming an Emacs | |
531 | process is already running). For this to work, you need to set your |
|
532 | process is already running). For this to work, you need to set your | |
532 | EDITOR environment variable to 'emacsclient'. The code below, supplied |
|
533 | EDITOR environment variable to 'emacsclient'. The code below, supplied | |
533 | by Francois Pinard, can then be used in your .emacs file to enable the |
|
534 | by Francois Pinard, can then be used in your .emacs file to enable the | |
534 | server:: |
|
535 | server:: | |
535 |
|
536 | |||
536 | (defvar server-buffer-clients) |
|
537 | (defvar server-buffer-clients) | |
537 | (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm)) |
|
538 | (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm)) | |
538 | (server-start) |
|
539 | (server-start) | |
539 | (defun fp-kill-server-with-buffer-routine () |
|
540 | (defun fp-kill-server-with-buffer-routine () | |
540 | (and server-buffer-clients (server-done))) |
|
541 | (and server-buffer-clients (server-done))) | |
541 | (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine)) |
|
542 | (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine)) | |
542 |
|
543 | |||
543 | You can also set the value of this editor via the commmand-line option |
|
544 | You can also set the value of this editor via the commmand-line option | |
544 | '-editor' or in your ipythonrc file. This is useful if you wish to use |
|
545 | '-editor' or in your ipythonrc file. This is useful if you wish to use | |
545 | specifically for IPython an editor different from your typical default |
|
546 | specifically for IPython an editor different from your typical default | |
546 | (and for Windows users who tend to use fewer environment variables). |
|
547 | (and for Windows users who tend to use fewer environment variables). | |
547 |
|
548 | |||
548 |
|
549 | |||
549 | Color |
|
550 | Color | |
550 | ----- |
|
551 | ----- | |
551 |
|
552 | |||
552 | The default IPython configuration has most bells and whistles turned on |
|
553 | The default IPython configuration has most bells and whistles turned on | |
553 | (they're pretty safe). But there's one that may cause problems on some |
|
554 | (they're pretty safe). But there's one that may cause problems on some | |
554 | systems: the use of color on screen for displaying information. This is |
|
555 | systems: the use of color on screen for displaying information. This is | |
555 | very useful, since IPython can show prompts and exception tracebacks |
|
556 | very useful, since IPython can show prompts and exception tracebacks | |
556 | with various colors, display syntax-highlighted source code, and in |
|
557 | with various colors, display syntax-highlighted source code, and in | |
557 | general make it easier to visually parse information. |
|
558 | general make it easier to visually parse information. | |
558 |
|
559 | |||
559 | The following terminals seem to handle the color sequences fine: |
|
560 | The following terminals seem to handle the color sequences fine: | |
560 |
|
561 | |||
561 | * Linux main text console, KDE Konsole, Gnome Terminal, E-term, |
|
562 | * Linux main text console, KDE Konsole, Gnome Terminal, E-term, | |
562 | rxvt, xterm. |
|
563 | rxvt, xterm. | |
563 | * CDE terminal (tested under Solaris). This one boldfaces light colors. |
|
564 | * CDE terminal (tested under Solaris). This one boldfaces light colors. | |
564 | * (X)Emacs buffers. See sec.3.4 <#sec:emacs> for more details on |
|
565 | * (X)Emacs buffers. See sec.3.4 <#sec:emacs> for more details on | |
565 | using IPython with (X)Emacs. |
|
566 | using IPython with (X)Emacs. | |
566 | * A Windows (XP/2k) command prompt with Gary Bishop's support |
|
567 | * A Windows (XP/2k) command prompt with Gary Bishop's support | |
567 | extensions. Gary's extensions are discussed in Sec. 2.3 |
|
568 | extensions. Gary's extensions are discussed in Sec. 2.3 | |
568 | <node2.html#sub:Under-Windows>. |
|
569 | <node2.html#sub:Under-Windows>. | |
569 | * A Windows (XP/2k) CygWin shell. Although some users have reported |
|
570 | * A Windows (XP/2k) CygWin shell. Although some users have reported | |
570 | problems; it is not clear whether there is an issue for everyone |
|
571 | problems; it is not clear whether there is an issue for everyone | |
571 | or only under specific configurations. If you have full color |
|
572 | or only under specific configurations. If you have full color | |
572 | support under cygwin, please post to the IPython mailing list so |
|
573 | support under cygwin, please post to the IPython mailing list so | |
573 | this issue can be resolved for all users. |
|
574 | this issue can be resolved for all users. | |
574 |
|
575 | |||
575 | These have shown problems: |
|
576 | These have shown problems: | |
576 |
|
577 | |||
577 | * Windows command prompt in WinXP/2k logged into a Linux machine via |
|
578 | * Windows command prompt in WinXP/2k logged into a Linux machine via | |
578 | telnet or ssh. |
|
579 | telnet or ssh. | |
579 | * Windows native command prompt in WinXP/2k, without Gary Bishop's |
|
580 | * Windows native command prompt in WinXP/2k, without Gary Bishop's | |
580 | extensions. Once Gary's readline library is installed, the normal |
|
581 | extensions. Once Gary's readline library is installed, the normal | |
581 | WinXP/2k command prompt works perfectly. |
|
582 | WinXP/2k command prompt works perfectly. | |
582 |
|
583 | |||
583 | Currently the following color schemes are available: |
|
584 | Currently the following color schemes are available: | |
584 |
|
585 | |||
585 | * NoColor: uses no color escapes at all (all escapes are empty '' '' |
|
586 | * NoColor: uses no color escapes at all (all escapes are empty '' '' | |
586 | strings). This 'scheme' is thus fully safe to use in any terminal. |
|
587 | strings). This 'scheme' is thus fully safe to use in any terminal. | |
587 | * Linux: works well in Linux console type environments: dark |
|
588 | * Linux: works well in Linux console type environments: dark | |
588 | background with light fonts. It uses bright colors for |
|
589 | background with light fonts. It uses bright colors for | |
589 | information, so it is difficult to read if you have a light |
|
590 | information, so it is difficult to read if you have a light | |
590 | colored background. |
|
591 | colored background. | |
591 | * LightBG: the basic colors are similar to those in the Linux scheme |
|
592 | * LightBG: the basic colors are similar to those in the Linux scheme | |
592 | but darker. It is easy to read in terminals with light backgrounds. |
|
593 | but darker. It is easy to read in terminals with light backgrounds. | |
593 |
|
594 | |||
594 | IPython uses colors for two main groups of things: prompts and |
|
595 | IPython uses colors for two main groups of things: prompts and | |
595 | tracebacks which are directly printed to the terminal, and the object |
|
596 | tracebacks which are directly printed to the terminal, and the object | |
596 | introspection system which passes large sets of data through a pager. |
|
597 | introspection system which passes large sets of data through a pager. | |
597 |
|
598 | |||
598 |
|
599 | |||
599 | Input/Output prompts and exception tracebacks |
|
600 | Input/Output prompts and exception tracebacks | |
600 | --------------------------------------------- |
|
601 | --------------------------------------------- | |
601 |
|
602 | |||
602 | You can test whether the colored prompts and tracebacks work on your |
|
603 | You can test whether the colored prompts and tracebacks work on your | |
603 | system interactively by typing '%colors Linux' at the prompt (use |
|
604 | system interactively by typing '%colors Linux' at the prompt (use | |
604 | '%colors LightBG' if your terminal has a light background). If the input |
|
605 | '%colors LightBG' if your terminal has a light background). If the input | |
605 | prompt shows garbage like: |
|
606 | prompt shows garbage like:: | |
|
607 | ||||
606 | [0;32mIn [[1;32m1[0;32m]: [0;00m |
|
608 | [0;32mIn [[1;32m1[0;32m]: [0;00m | |
607 | instead of (in color) something like: |
|
609 | ||
|
610 | instead of (in color) something like:: | |||
|
611 | ||||
608 | In [1]: |
|
612 | In [1]: | |
|
613 | ||||
609 | this means that your terminal doesn't properly handle color escape |
|
614 | this means that your terminal doesn't properly handle color escape | |
610 | sequences. You can go to a 'no color' mode by typing '%colors NoColor'. |
|
615 | sequences. You can go to a 'no color' mode by typing '%colors NoColor'. | |
611 |
|
616 | |||
612 | You can try using a different terminal emulator program (Emacs users, |
|
617 | You can try using a different terminal emulator program (Emacs users, | |
613 | see below). To permanently set your color preferences, edit the file |
|
618 | see below). To permanently set your color preferences, edit the file | |
614 | $HOME/.ipython/ipythonrc and set the colors option to the desired value. |
|
619 | $HOME/.ipython/ipythonrc and set the colors option to the desired value. | |
615 |
|
620 | |||
616 |
|
621 | |||
617 | Object details (types, docstrings, source code, etc.) |
|
622 | Object details (types, docstrings, source code, etc.) | |
618 | ----------------------------------------------------- |
|
623 | ----------------------------------------------------- | |
619 |
|
624 | |||
620 | IPython has a set of special functions for studying the objects you are |
|
625 | IPython has a set of special functions for studying the objects you are | |
621 | working with, discussed in detail in Sec. 6.4 |
|
626 | working with, discussed in detail in Sec. 6.4 | |
622 | <node6.html#sec:dyn-object-info>. But this system relies on passing |
|
627 | <node6.html#sec:dyn-object-info>. But this system relies on passing | |
623 | information which is longer than your screen through a data pager, such |
|
628 | information which is longer than your screen through a data pager, such | |
624 | as the common Unix less and more programs. In order to be able to see |
|
629 | as the common Unix less and more programs. In order to be able to see | |
625 | this information in color, your pager needs to be properly configured. I |
|
630 | this information in color, your pager needs to be properly configured. I | |
626 | strongly recommend using less instead of more, as it seems that more |
|
631 | strongly recommend using less instead of more, as it seems that more | |
627 | simply can not understand colored text correctly. |
|
632 | simply can not understand colored text correctly. | |
628 |
|
633 | |||
629 | In order to configure less as your default pager, do the following: |
|
634 | In order to configure less as your default pager, do the following: | |
630 |
|
635 | |||
631 | 1. Set the environment PAGER variable to less. |
|
636 | 1. Set the environment PAGER variable to less. | |
632 | 2. Set the environment LESS variable to -r (plus any other options |
|
637 | 2. Set the environment LESS variable to -r (plus any other options | |
633 | you always want to pass to less by default). This tells less to |
|
638 | you always want to pass to less by default). This tells less to | |
634 | properly interpret control sequences, which is how color |
|
639 | properly interpret control sequences, which is how color | |
635 | information is given to your terminal. |
|
640 | information is given to your terminal. | |
636 |
|
641 | |||
637 | For the csh or tcsh shells, add to your ~/.cshrc file the lines:: |
|
642 | For the csh or tcsh shells, add to your ~/.cshrc file the lines:: | |
638 |
|
643 | |||
639 | setenv PAGER less |
|
644 | setenv PAGER less | |
640 | setenv LESS -r |
|
645 | setenv LESS -r | |
641 |
|
646 | |||
642 | There is similar syntax for other Unix shells, look at your system |
|
647 | There is similar syntax for other Unix shells, look at your system | |
643 | documentation for details. |
|
648 | documentation for details. | |
644 |
|
649 | |||
645 | If you are on a system which lacks proper data pagers (such as Windows), |
|
650 | If you are on a system which lacks proper data pagers (such as Windows), | |
646 | IPython will use a very limited builtin pager. |
|
651 | IPython will use a very limited builtin pager. | |
647 |
|
652 | |||
648 | (X)Emacs configuration |
|
653 | (X)Emacs configuration | |
649 | ---------------------- |
|
654 | ---------------------- | |
650 |
|
655 | |||
651 | Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, |
|
656 | Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, | |
652 | currently (X)Emacs and IPython get along very well. |
|
657 | currently (X)Emacs and IPython get along very well. | |
653 |
|
658 | |||
654 | Important note: You will need to use a recent enough version of |
|
659 | Important note: You will need to use a recent enough version of | |
655 | python-mode.el, along with the file ipython.el. You can check that the |
|
660 | python-mode.el, along with the file ipython.el. You can check that the | |
656 | version you have of python-mode.el is new enough by either looking at |
|
661 | version you have of python-mode.el is new enough by either looking at | |
657 | the revision number in the file itself, or asking for it in (X)Emacs via |
|
662 | the revision number in the file itself, or asking for it in (X)Emacs via | |
658 | M-x py-version. Versions 4.68 and newer contain the necessary fixes for |
|
663 | M-x py-version. Versions 4.68 and newer contain the necessary fixes for | |
659 | proper IPython support. |
|
664 | proper IPython support. | |
660 |
|
665 | |||
661 | The file ipython.el is included with the IPython distribution, in the |
|
666 | The file ipython.el is included with the IPython distribution, in the | |
662 | documentation directory (where this manual resides in PDF and HTML |
|
667 | documentation directory (where this manual resides in PDF and HTML | |
663 | formats). |
|
668 | formats). | |
664 |
|
669 | |||
665 | Once you put these files in your Emacs path, all you need in your .emacs |
|
670 | Once you put these files in your Emacs path, all you need in your .emacs | |
666 | file is:: |
|
671 | file is:: | |
667 |
|
672 | |||
668 | (require 'ipython) |
|
673 | (require 'ipython) | |
669 |
|
674 | |||
670 | This should give you full support for executing code snippets via |
|
675 | This should give you full support for executing code snippets via | |
671 | IPython, opening IPython as your Python shell via C-c !, etc. |
|
676 | IPython, opening IPython as your Python shell via C-c !, etc. | |
672 |
|
677 | |||
673 | If you happen to get garbage instead of colored prompts as described in |
|
678 | If you happen to get garbage instead of colored prompts as described in | |
674 | the previous section, you may need to set also in your .emacs file:: |
|
679 | the previous section, you may need to set also in your .emacs file:: | |
675 |
|
680 | |||
676 | (setq ansi-color-for-comint-mode t) |
|
681 | (setq ansi-color-for-comint-mode t) | |
677 |
|
682 | |||
678 |
|
683 | |||
679 | Notes: |
|
684 | Notes: | |
680 |
|
685 | |||
681 | * There is one caveat you should be aware of: you must start the |
|
686 | * There is one caveat you should be aware of: you must start the | |
682 | IPython shell before attempting to execute any code regions via |
|
687 | IPython shell before attempting to execute any code regions via | |
683 | ``C-c |``. Simply type C-c ! to start IPython before passing any code |
|
688 | ``C-c |``. Simply type C-c ! to start IPython before passing any code | |
684 | regions to the interpreter, and you shouldn't experience any |
|
689 | regions to the interpreter, and you shouldn't experience any | |
685 | problems. |
|
690 | problems. | |
686 | This is due to a bug in Python itself, which has been fixed for |
|
691 | This is due to a bug in Python itself, which has been fixed for | |
687 | Python 2.3, but exists as of Python 2.2.2 (reported as SF bug [ |
|
692 | Python 2.3, but exists as of Python 2.2.2 (reported as SF bug [ | |
688 | 737947 ]). |
|
693 | 737947 ]). | |
689 | * The (X)Emacs support is maintained by Alexander Schmolck, so all |
|
694 | * The (X)Emacs support is maintained by Alexander Schmolck, so all | |
690 | comments/requests should be directed to him through the IPython |
|
695 | comments/requests should be directed to him through the IPython | |
691 | mailing lists. |
|
696 | mailing lists. | |
692 | * This code is still somewhat experimental so it's a bit rough |
|
697 | * This code is still somewhat experimental so it's a bit rough | |
693 | around the edges (although in practice, it works quite well). |
|
698 | around the edges (although in practice, it works quite well). | |
694 | * Be aware that if you customize py-python-command previously, this |
|
699 | * Be aware that if you customize py-python-command previously, this | |
695 | value will override what ipython.el does (because loading the |
|
700 | value will override what ipython.el does (because loading the | |
696 | customization variables comes later). |
|
701 | customization variables comes later). | |
697 |
|
702 | |||
698 | Quick tips |
|
703 | Quick tips | |
699 | ========== |
|
704 | ========== | |
700 |
|
705 | |||
701 | IPython can be used as an improved replacement for the Python prompt, |
|
706 | IPython can be used as an improved replacement for the Python prompt, | |
702 | and for that you don't really need to read any more of this manual. But |
|
707 | and for that you don't really need to read any more of this manual. But | |
703 | in this section we'll try to summarize a few tips on how to make the |
|
708 | in this section we'll try to summarize a few tips on how to make the | |
704 | most effective use of it for everyday Python development, highlighting |
|
709 | most effective use of it for everyday Python development, highlighting | |
705 | things you might miss in the rest of the manual (which is getting long). |
|
710 | things you might miss in the rest of the manual (which is getting long). | |
706 | We'll give references to parts in the manual which provide more detail |
|
711 | We'll give references to parts in the manual which provide more detail | |
707 | when appropriate. |
|
712 | when appropriate. | |
708 |
|
713 | |||
709 | The following article by Jeremy Jones provides an introductory tutorial |
|
714 | The following article by Jeremy Jones provides an introductory tutorial | |
710 | about IPython: |
|
715 | about IPython: | |
711 | http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html |
|
716 | http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html | |
712 |
|
717 | |||
713 | * The TAB key. TAB-completion, especially for attributes, is a |
|
718 | * The TAB key. TAB-completion, especially for attributes, is a | |
714 | convenient way to explore the structure of any object you're |
|
719 | convenient way to explore the structure of any object you're | |
715 | dealing with. Simply type object_name.<TAB> and a list of the |
|
720 | dealing with. Simply type object_name.<TAB> and a list of the | |
716 | object's attributes will be printed (see sec. 6.5 |
|
721 | object's attributes will be printed (see sec. 6.5 | |
717 | <node6.html#sec:readline> for more). Tab completion also works on |
|
722 | <node6.html#sec:readline> for more). Tab completion also works on | |
718 | file and directory names, which combined with IPython's alias |
|
723 | file and directory names, which combined with IPython's alias | |
719 | system allows you to do from within IPython many of the things you |
|
724 | system allows you to do from within IPython many of the things you | |
720 | normally would need the system shell for. |
|
725 | normally would need the system shell for. | |
721 | * Explore your objects. Typing object_name? will print all sorts of |
|
726 | * Explore your objects. Typing object_name? will print all sorts of | |
722 | details about any object, including docstrings, function |
|
727 | details about any object, including docstrings, function | |
723 | definition lines (for call arguments) and constructor details for |
|
728 | definition lines (for call arguments) and constructor details for | |
724 | classes. The magic commands %pdoc, %pdef, %psource and %pfile will |
|
729 | classes. The magic commands %pdoc, %pdef, %psource and %pfile will | |
725 | respectively print the docstring, function definition line, full |
|
730 | respectively print the docstring, function definition line, full | |
726 | source code and the complete file for any object (when they can be |
|
731 | source code and the complete file for any object (when they can be | |
727 | found). If automagic is on (it is by default), you don't need to |
|
732 | found). If automagic is on (it is by default), you don't need to | |
728 | type the '%' explicitly. See sec. 6.4 |
|
733 | type the '%' explicitly. See sec. 6.4 | |
729 | <node6.html#sec:dyn-object-info> for more. |
|
734 | <node6.html#sec:dyn-object-info> for more. | |
730 | * The %run magic command allows you to run any python script and |
|
735 | * The %run magic command allows you to run any python script and | |
731 | load all of its data directly into the interactive namespace. |
|
736 | load all of its data directly into the interactive namespace. | |
732 | Since the file is re-read from disk each time, changes you make to |
|
737 | Since the file is re-read from disk each time, changes you make to | |
733 | it are reflected immediately (in contrast to the behavior of |
|
738 | it are reflected immediately (in contrast to the behavior of | |
734 | import). I rarely use import for code I am testing, relying on |
|
739 | import). I rarely use import for code I am testing, relying on | |
735 | %run instead. See sec. 6.2 <node6.html#sec:magic> for more on this |
|
740 | %run instead. See sec. 6.2 <node6.html#sec:magic> for more on this | |
736 | and other magic commands, or type the name of any magic command |
|
741 | and other magic commands, or type the name of any magic command | |
737 | and ? to get details on it. See also sec. 6.9 |
|
742 | and ? to get details on it. See also sec. 6.9 | |
738 | <node6.html#sec:dreload> for a recursive reload command. |
|
743 | <node6.html#sec:dreload> for a recursive reload command. | |
739 | %run also has special flags for timing the execution of your |
|
744 | %run also has special flags for timing the execution of your | |
740 | scripts (-t) and for executing them under the control of either |
|
745 | scripts (-t) and for executing them under the control of either | |
741 | Python's pdb debugger (-d) or profiler (-p). With all of these, |
|
746 | Python's pdb debugger (-d) or profiler (-p). With all of these, | |
742 | %run can be used as the main tool for efficient interactive |
|
747 | %run can be used as the main tool for efficient interactive | |
743 | development of code which you write in your editor of choice. |
|
748 | development of code which you write in your editor of choice. | |
744 | * Use the Python debugger, pdb^2 <footnode.html#foot360>. The %pdb |
|
749 | * Use the Python debugger, pdb^2 <footnode.html#foot360>. The %pdb | |
745 | command allows you to toggle on and off the automatic invocation |
|
750 | command allows you to toggle on and off the automatic invocation | |
746 | of an IPython-enhanced pdb debugger (with coloring, tab completion |
|
751 | of an IPython-enhanced pdb debugger (with coloring, tab completion | |
747 | and more) at any uncaught exception. The advantage of this is that |
|
752 | and more) at any uncaught exception. The advantage of this is that | |
748 | pdb starts inside the function where the exception occurred, with |
|
753 | pdb starts inside the function where the exception occurred, with | |
749 | all data still available. You can print variables, see code, |
|
754 | all data still available. You can print variables, see code, | |
750 | execute statements and even walk up and down the call stack to |
|
755 | execute statements and even walk up and down the call stack to | |
751 | track down the true source of the problem (which often is many |
|
756 | track down the true source of the problem (which often is many | |
752 | layers in the stack above where the exception gets triggered). |
|
757 | layers in the stack above where the exception gets triggered). | |
753 | Running programs with %run and pdb active can be an efficient to |
|
758 | Running programs with %run and pdb active can be an efficient to | |
754 | develop and debug code, in many cases eliminating the need for |
|
759 | develop and debug code, in many cases eliminating the need for | |
755 | print statements or external debugging tools. I often simply put a |
|
760 | print statements or external debugging tools. I often simply put a | |
756 | 1/0 in a place where I want to take a look so that pdb gets |
|
761 | 1/0 in a place where I want to take a look so that pdb gets | |
757 | called, quickly view whatever variables I need to or test various |
|
762 | called, quickly view whatever variables I need to or test various | |
758 | pieces of code and then remove the 1/0. |
|
763 | pieces of code and then remove the 1/0. | |
759 | Note also that '%run -d' activates pdb and automatically sets |
|
764 | Note also that '%run -d' activates pdb and automatically sets | |
760 | initial breakpoints for you to step through your code, watch |
|
765 | initial breakpoints for you to step through your code, watch | |
761 | variables, etc. See Sec. 6.12 <node6.html#sec:cache_output> for |
|
766 | variables, etc. See Sec. 6.12 <node6.html#sec:cache_output> for | |
762 | details. |
|
767 | details. | |
763 | * Use the output cache. All output results are automatically stored |
|
768 | * Use the output cache. All output results are automatically stored | |
764 | in a global dictionary named Out and variables named _1, _2, etc. |
|
769 | in a global dictionary named Out and variables named _1, _2, etc. | |
765 | alias them. For example, the result of input line 4 is available |
|
770 | alias them. For example, the result of input line 4 is available | |
766 | either as Out[4] or as _4. Additionally, three variables named _, |
|
771 | either as Out[4] or as _4. Additionally, three variables named _, | |
767 | __ and ___ are always kept updated with the for the last three |
|
772 | __ and ___ are always kept updated with the for the last three | |
768 | results. This allows you to recall any previous result and further |
|
773 | results. This allows you to recall any previous result and further | |
769 | use it for new calculations. See Sec. 6.12 |
|
774 | use it for new calculations. See Sec. 6.12 | |
770 | <node6.html#sec:cache_output> for more. |
|
775 | <node6.html#sec:cache_output> for more. | |
771 | * Put a ';' at the end of a line to supress the printing of output. |
|
776 | * Put a ';' at the end of a line to supress the printing of output. | |
772 | This is useful when doing calculations which generate long output |
|
777 | This is useful when doing calculations which generate long output | |
773 | you are not interested in seeing. The _* variables and the Out[] |
|
778 | you are not interested in seeing. The _* variables and the Out[] | |
774 | list do get updated with the contents of the output, even if it is |
|
779 | list do get updated with the contents of the output, even if it is | |
775 | not printed. You can thus still access the generated results this |
|
780 | not printed. You can thus still access the generated results this | |
776 | way for further processing. |
|
781 | way for further processing. | |
777 | * A similar system exists for caching input. All input is stored in |
|
782 | * A similar system exists for caching input. All input is stored in | |
778 | a global list called In , so you can re-execute lines 22 through |
|
783 | a global list called In , so you can re-execute lines 22 through | |
779 | 28 plus line 34 by typing 'exec In[22:29]+In[34]' (using Python |
|
784 | 28 plus line 34 by typing 'exec In[22:29]+In[34]' (using Python | |
780 | slicing notation). If you need to execute the same set of lines |
|
785 | slicing notation). If you need to execute the same set of lines | |
781 | often, you can assign them to a macro with the %macro function. |
|
786 | often, you can assign them to a macro with the %macro function. | |
782 | See sec. 6.11 <node6.html#sec:cache_input> for more. |
|
787 | See sec. 6.11 <node6.html#sec:cache_input> for more. | |
783 | * Use your input history. The %hist command can show you all |
|
788 | * Use your input history. The %hist command can show you all | |
784 | previous input, without line numbers if desired (option -n) so you |
|
789 | previous input, without line numbers if desired (option -n) so you | |
785 | can directly copy and paste code either back in IPython or in a |
|
790 | can directly copy and paste code either back in IPython or in a | |
786 | text editor. You can also save all your history by turning on |
|
791 | text editor. You can also save all your history by turning on | |
787 | logging via %logstart; these logs can later be either reloaded as |
|
792 | logging via %logstart; these logs can later be either reloaded as | |
788 | IPython sessions or used as code for your programs. |
|
793 | IPython sessions or used as code for your programs. | |
789 | * Define your own system aliases. Even though IPython gives you |
|
794 | * Define your own system aliases. Even though IPython gives you | |
790 | access to your system shell via the ! prefix, it is convenient to |
|
795 | access to your system shell via the ! prefix, it is convenient to | |
791 | have aliases to the system commands you use most often. This |
|
796 | have aliases to the system commands you use most often. This | |
792 | allows you to work seamlessly from inside IPython with the same |
|
797 | allows you to work seamlessly from inside IPython with the same | |
793 | commands you are used to in your system shell. |
|
798 | commands you are used to in your system shell. | |
794 | IPython comes with some pre-defined aliases and a complete system |
|
799 | IPython comes with some pre-defined aliases and a complete system | |
795 | for changing directories, both via a stack (see %pushd, %popd and |
|
800 | for changing directories, both via a stack (see %pushd, %popd and | |
796 | %dhist) and via direct %cd. The latter keeps a history of visited |
|
801 | %dhist) and via direct %cd. The latter keeps a history of visited | |
797 | directories and allows you to go to any previously visited one. |
|
802 | directories and allows you to go to any previously visited one. | |
798 | * Use Python to manipulate the results of system commands. The '!!' |
|
803 | * Use Python to manipulate the results of system commands. The '!!' | |
799 | special syntax, and the %sc and %sx magic commands allow you to |
|
804 | special syntax, and the %sc and %sx magic commands allow you to | |
800 | capture system output into Python variables. |
|
805 | capture system output into Python variables. | |
801 | * Expand python variables when calling the shell (either via '!' and |
|
806 | * Expand python variables when calling the shell (either via '!' and | |
802 | '!!' or via aliases) by prepending a $ in front of them. You can |
|
807 | '!!' or via aliases) by prepending a $ in front of them. You can | |
803 | also expand complete python expressions. See sec. 6.7 |
|
808 | also expand complete python expressions. See sec. 6.7 | |
804 | <node6.html#sub:System-shell-access> for more. |
|
809 | <node6.html#sub:System-shell-access> for more. | |
805 | * Use profiles to maintain different configurations (modules to |
|
810 | * Use profiles to maintain different configurations (modules to | |
806 | load, function definitions, option settings) for particular tasks. |
|
811 | load, function definitions, option settings) for particular tasks. | |
807 | You can then have customized versions of IPython for specific |
|
812 | You can then have customized versions of IPython for specific | |
808 | purposes. See sec. 7.3 <node7.html#sec:profiles> for more. |
|
813 | purposes. See sec. 7.3 <node7.html#sec:profiles> for more. | |
809 | * Embed IPython in your programs. A few lines of code are enough to |
|
814 | * Embed IPython in your programs. A few lines of code are enough to | |
810 | load a complete IPython inside your own programs, giving you the |
|
815 | load a complete IPython inside your own programs, giving you the | |
811 | ability to work with your data interactively after automatic |
|
816 | ability to work with your data interactively after automatic | |
812 | processing has been completed. See sec. 9 <node9.html#sec:embed> |
|
817 | processing has been completed. See sec. 9 <node9.html#sec:embed> | |
813 | for more. |
|
818 | for more. | |
814 | * Use the Python profiler. When dealing with performance issues, the |
|
819 | * Use the Python profiler. When dealing with performance issues, the | |
815 | %run command with a -p option allows you to run complete programs |
|
820 | %run command with a -p option allows you to run complete programs | |
816 | under the control of the Python profiler. The %prun command does a |
|
821 | under the control of the Python profiler. The %prun command does a | |
817 | similar job for single Python expressions (like function calls). |
|
822 | similar job for single Python expressions (like function calls). | |
818 | * Use the IPython.demo.Demo class to load any Python script as an |
|
823 | * Use the IPython.demo.Demo class to load any Python script as an | |
819 | interactive demo. With a minimal amount of simple markup, you can |
|
824 | interactive demo. With a minimal amount of simple markup, you can | |
820 | control the execution of the script, stopping as needed. See |
|
825 | control the execution of the script, stopping as needed. See | |
821 | sec. 14 <node14.html#sec:interactive-demos> for more. |
|
826 | sec. 14 <node14.html#sec:interactive-demos> for more. | |
822 | * Run your doctests from within IPython for development and |
|
827 | * Run your doctests from within IPython for development and | |
823 | debugging. The special %doctest_mode command toggles a mode where |
|
828 | debugging. The special %doctest_mode command toggles a mode where | |
824 | the prompt, output and exceptions display matches as closely as |
|
829 | the prompt, output and exceptions display matches as closely as | |
825 | possible that of the default Python interpreter. In addition, this |
|
830 | possible that of the default Python interpreter. In addition, this | |
826 | mode allows you to directly paste in code that contains leading |
|
831 | mode allows you to directly paste in code that contains leading | |
827 | '>>>' prompts, even if they have extra leading whitespace (as is |
|
832 | '>>>' prompts, even if they have extra leading whitespace (as is | |
828 | common in doctest files). This combined with the '%history -tn' |
|
833 | common in doctest files). This combined with the '%history -tn' | |
829 | call to see your translated history (with these extra prompts |
|
834 | call to see your translated history (with these extra prompts | |
830 | removed and no line numbers) allows for an easy doctest workflow, |
|
835 | removed and no line numbers) allows for an easy doctest workflow, | |
831 | where you can go from doctest to interactive execution to pasting |
|
836 | where you can go from doctest to interactive execution to pasting | |
832 | into valid Python code as needed. |
|
837 | into valid Python code as needed. | |
833 |
|
838 | |||
834 |
|
839 | |||
835 | Source code handling tips |
|
840 | Source code handling tips | |
836 | ------------------------- |
|
841 | ------------------------- | |
837 |
|
842 | |||
838 | IPython is a line-oriented program, without full control of the |
|
843 | IPython is a line-oriented program, without full control of the | |
839 | terminal. Therefore, it doesn't support true multiline editing. However, |
|
844 | terminal. Therefore, it doesn't support true multiline editing. However, | |
840 | it has a number of useful tools to help you in dealing effectively with |
|
845 | it has a number of useful tools to help you in dealing effectively with | |
841 | more complex editing. |
|
846 | more complex editing. | |
842 |
|
847 | |||
843 | The %edit command gives a reasonable approximation of multiline editing, |
|
848 | The %edit command gives a reasonable approximation of multiline editing, | |
844 | by invoking your favorite editor on the spot. IPython will execute the |
|
849 | by invoking your favorite editor on the spot. IPython will execute the | |
845 | code you type in there as if it were typed interactively. Type %edit? |
|
850 | code you type in there as if it were typed interactively. Type %edit? | |
846 | for the full details on the edit command. |
|
851 | for the full details on the edit command. | |
847 |
|
852 | |||
848 | If you have typed various commands during a session, which you'd like to |
|
853 | If you have typed various commands during a session, which you'd like to | |
849 | reuse, IPython provides you with a number of tools. Start by using %hist |
|
854 | reuse, IPython provides you with a number of tools. Start by using %hist | |
850 | to see your input history, so you can see the line numbers of all input. |
|
855 | to see your input history, so you can see the line numbers of all input. | |
851 | Let us say that you'd like to reuse lines 10 through 20, plus lines 24 |
|
856 | Let us say that you'd like to reuse lines 10 through 20, plus lines 24 | |
852 | and 28. All the commands below can operate on these with the syntax:: |
|
857 | and 28. All the commands below can operate on these with the syntax:: | |
853 |
|
858 | |||
854 | %command 10-20 24 28 |
|
859 | %command 10-20 24 28 | |
855 |
|
860 | |||
856 | where the command given can be: |
|
861 | where the command given can be: | |
857 |
|
862 | |||
858 | * %macro <macroname>: this stores the lines into a variable which, |
|
863 | * %macro <macroname>: this stores the lines into a variable which, | |
859 | when called at the prompt, re-executes the input. Macros can be |
|
864 | when called at the prompt, re-executes the input. Macros can be | |
860 | edited later using '%edit macroname', and they can be stored |
|
865 | edited later using '%edit macroname', and they can be stored | |
861 | persistently across sessions with '%store macroname' (the storage |
|
866 | persistently across sessions with '%store macroname' (the storage | |
862 | system is per-profile). The combination of quick macros, |
|
867 | system is per-profile). The combination of quick macros, | |
863 | persistent storage and editing, allows you to easily refine |
|
868 | persistent storage and editing, allows you to easily refine | |
864 | quick-and-dirty interactive input into permanent utilities, always |
|
869 | quick-and-dirty interactive input into permanent utilities, always | |
865 | available both in IPython and as files for general reuse. |
|
870 | available both in IPython and as files for general reuse. | |
866 | * %edit: this will open a text editor with those lines pre-loaded |
|
871 | * %edit: this will open a text editor with those lines pre-loaded | |
867 | for further modification. It will then execute the resulting |
|
872 | for further modification. It will then execute the resulting | |
868 | file's contents as if you had typed it at the prompt. |
|
873 | file's contents as if you had typed it at the prompt. | |
869 | * %save <filename>: this saves the lines directly to a named file on |
|
874 | * %save <filename>: this saves the lines directly to a named file on | |
870 | disk. |
|
875 | disk. | |
871 |
|
876 | |||
872 | While %macro saves input lines into memory for interactive re-execution, |
|
877 | While %macro saves input lines into memory for interactive re-execution, | |
873 | sometimes you'd like to save your input directly to a file. The %save |
|
878 | sometimes you'd like to save your input directly to a file. The %save | |
874 | magic does this: its input sytnax is the same as %macro, but it saves |
|
879 | magic does this: its input sytnax is the same as %macro, but it saves | |
875 | your input directly to a Python file. Note that the %logstart command |
|
880 | your input directly to a Python file. Note that the %logstart command | |
876 | also saves input, but it logs all input to disk (though you can |
|
881 | also saves input, but it logs all input to disk (though you can | |
877 | temporarily suspend it and reactivate it with %logoff/%logon); %save |
|
882 | temporarily suspend it and reactivate it with %logoff/%logon); %save | |
878 | allows you to select which lines of input you need to save. |
|
883 | allows you to select which lines of input you need to save. | |
879 |
|
884 | |||
880 |
|
885 | |||
881 | Lightweight 'version control' |
|
886 | Lightweight 'version control' | |
882 | ----------------------------- |
|
887 | ----------------------------- | |
883 |
|
888 | |||
884 | When you call %edit with no arguments, IPython opens an empty editor |
|
889 | When you call %edit with no arguments, IPython opens an empty editor | |
885 | with a temporary file, and it returns the contents of your editing |
|
890 | with a temporary file, and it returns the contents of your editing | |
886 | session as a string variable. Thanks to IPython's output caching |
|
891 | session as a string variable. Thanks to IPython's output caching | |
887 | mechanism, this is automatically stored:: |
|
892 | mechanism, this is automatically stored:: | |
888 |
|
893 | |||
889 | In [1]: %edit |
|
894 | In [1]: %edit | |
890 |
|
895 | |||
891 | IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py |
|
896 | IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py | |
892 |
|
897 | |||
893 | Editing... done. Executing edited code... |
|
898 | Editing... done. Executing edited code... | |
894 |
|
899 | |||
895 | hello - this is a temporary file |
|
900 | hello - this is a temporary file | |
896 |
|
901 | |||
897 | Out[1]: "print 'hello - this is a temporary file'\n" |
|
902 | Out[1]: "print 'hello - this is a temporary file'\n" | |
898 |
|
903 | |||
899 | Now, if you call '%edit -p', IPython tries to open an editor with the |
|
904 | Now, if you call '%edit -p', IPython tries to open an editor with the | |
900 | same data as the last time you used %edit. So if you haven't used %edit |
|
905 | same data as the last time you used %edit. So if you haven't used %edit | |
901 | in the meantime, this same contents will reopen; however, it will be |
|
906 | in the meantime, this same contents will reopen; however, it will be | |
902 | done in a new file. This means that if you make changes and you later |
|
907 | done in a new file. This means that if you make changes and you later | |
903 | want to find an old version, you can always retrieve it by using its |
|
908 | want to find an old version, you can always retrieve it by using its | |
904 | output number, via '%edit _NN', where NN is the number of the output |
|
909 | output number, via '%edit _NN', where NN is the number of the output | |
905 | prompt. |
|
910 | prompt. | |
906 |
|
911 | |||
907 | Continuing with the example above, this should illustrate this idea:: |
|
912 | Continuing with the example above, this should illustrate this idea:: | |
908 |
|
913 | |||
909 | In [2]: edit -p |
|
914 | In [2]: edit -p | |
910 |
|
915 | |||
911 | IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py |
|
916 | IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py | |
912 |
|
917 | |||
913 | Editing... done. Executing edited code... |
|
918 | Editing... done. Executing edited code... | |
914 |
|
919 | |||
915 | hello - now I made some changes |
|
920 | hello - now I made some changes | |
916 |
|
921 | |||
917 | Out[2]: "print 'hello - now I made some changes'\n" |
|
922 | Out[2]: "print 'hello - now I made some changes'\n" | |
918 |
|
923 | |||
919 | In [3]: edit _1 |
|
924 | In [3]: edit _1 | |
920 |
|
925 | |||
921 | IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py |
|
926 | IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py | |
922 |
|
927 | |||
923 | Editing... done. Executing edited code... |
|
928 | Editing... done. Executing edited code... | |
924 |
|
929 | |||
925 | hello - this is a temporary file |
|
930 | hello - this is a temporary file | |
926 |
|
931 | |||
927 | IPython version control at work :) |
|
932 | IPython version control at work :) | |
928 |
|
933 | |||
929 | Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n" |
|
934 | Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n" | |
930 |
|
935 | |||
931 |
|
936 | |||
932 | This section was written after a contribution by Alexander Belchenko on |
|
937 | This section was written after a contribution by Alexander Belchenko on | |
933 | the IPython user list. |
|
938 | the IPython user list. | |
934 |
|
939 | |||
935 |
|
940 | |||
936 | Effective logging |
|
941 | Effective logging | |
937 | ----------------- |
|
942 | ----------------- | |
938 |
|
943 | |||
939 | A very useful suggestion sent in by Robert Kern follows: |
|
944 | A very useful suggestion sent in by Robert Kern follows: | |
940 |
|
945 | |||
941 | I recently happened on a nifty way to keep tidy per-project log files. I |
|
946 | I recently happened on a nifty way to keep tidy per-project log files. I | |
942 | made a profile for my project (which is called "parkfield"). |
|
947 | made a profile for my project (which is called "parkfield"). | |
943 |
|
948 | |||
944 | include ipythonrc |
|
949 | include ipythonrc | |
945 |
|
950 | |||
946 | # cancel earlier logfile invocation: |
|
951 | # cancel earlier logfile invocation: | |
947 |
|
952 | |||
948 | logfile '' |
|
953 | logfile '' | |
949 |
|
954 | |||
950 | execute import time |
|
955 | execute import time | |
951 |
|
956 | |||
952 | execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate' |
|
957 | execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate' | |
953 |
|
958 | |||
954 | execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d')) |
|
959 | execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d')) | |
955 |
|
960 | |||
956 | I also added a shell alias for convenience: |
|
961 | I also added a shell alias for convenience: | |
957 |
|
962 | |||
958 | alias parkfield="ipython -pylab -profile parkfield" |
|
963 | alias parkfield="ipython -pylab -profile parkfield" | |
959 |
|
964 | |||
960 | Now I have a nice little directory with everything I ever type in, |
|
965 | Now I have a nice little directory with everything I ever type in, | |
961 | organized by project and date. |
|
966 | organized by project and date. | |
962 |
|
967 | |||
963 | Contribute your own: If you have your own favorite tip on using IPython |
|
968 | Contribute your own: If you have your own favorite tip on using IPython | |
964 | efficiently for a certain task (especially things which can't be done in |
|
969 | efficiently for a certain task (especially things which can't be done in | |
965 | the normal Python interpreter), don't hesitate to send it! |
|
970 | the normal Python interpreter), don't hesitate to send it! | |
966 |
|
971 | |||
967 | Command-line use |
|
972 | Command-line use | |
968 | ================ |
|
973 | ================ | |
969 |
|
974 | |||
970 | You start IPython with the command:: |
|
975 | You start IPython with the command:: | |
971 |
|
976 | |||
972 | $ ipython [options] files |
|
977 | $ ipython [options] files | |
973 |
|
978 | |||
974 | If invoked with no options, it executes all the files listed in sequence |
|
979 | 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 |
|
980 | 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 |
|
981 | 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 |
|
982 | standard Python, which when called as python -i will only execute one | |
978 | file and ignore your configuration setup. |
|
983 | file and ignore your configuration setup. | |
979 |
|
984 | |||
980 | Please note that some of the configuration options are not available at |
|
985 | 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 |
|
986 | the command line, simply because they are not practical here. Look into | |
982 | your ipythonrc configuration file for details on those. This file |
|
987 | your ipythonrc configuration file for details on those. This file | |
983 | typically installed in the $HOME/.ipython directory. For Windows users, |
|
988 | typically installed in the $HOME/.ipython directory. For Windows users, | |
984 | $HOME resolves to C:\\Documents and Settings\\YourUserName in most |
|
989 | $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 |
|
990 | instances. In the rest of this text, we will refer to this directory as | |
986 | IPYTHONDIR. |
|
991 | IPYTHONDIR. | |
987 |
|
992 | |||
988 |
|
993 | |||
989 | Special Threading Options |
|
994 | Special Threading Options | |
990 |
|
995 | |||
991 | The following special options are ONLY valid at the beginning of the |
|
996 | The following special options are ONLY valid at the beginning of the | |
992 | command line, and not later. This is because they control the initial- |
|
997 | command line, and not later. This is because they control the initial- | |
993 | ization of ipython itself, before the normal option-handling mechanism |
|
998 | ization of ipython itself, before the normal option-handling mechanism | |
994 | is active. |
|
999 | is active. | |
995 |
|
1000 | |||
996 | * [-gthread, -qthread, -q4thread, -wthread, -pylab:] Only one of |
|
1001 | * [-gthread, -qthread, -q4thread, -wthread, -pylab:] Only one of | |
997 | these can be given, and it can only be given as the first option |
|
1002 | these can be given, and it can only be given as the first option | |
998 | passed to IPython (it will have no effect in any other position). |
|
1003 | passed to IPython (it will have no effect in any other position). | |
999 | They provide threading support for the GTK, Qt (versions 3 and 4) |
|
1004 | They provide threading support for the GTK, Qt (versions 3 and 4) | |
1000 | and WXPython toolkits, and for the matplotlib library. |
|
1005 | and WXPython toolkits, and for the matplotlib library. | |
1001 | * [ ] With any of the first four options, IPython starts running a |
|
1006 | * [ ] With any of the first four options, IPython starts running a | |
1002 | separate thread for the graphical toolkit's operation, so that you |
|
1007 | separate thread for the graphical toolkit's operation, so that you | |
1003 | can open and control graphical elements from within an IPython |
|
1008 | can open and control graphical elements from within an IPython | |
1004 | command line, without blocking. All four provide essentially the |
|
1009 | command line, without blocking. All four provide essentially the | |
1005 | same functionality, respectively for GTK, Qt3, Qt4 and WXWidgets |
|
1010 | same functionality, respectively for GTK, Qt3, Qt4 and WXWidgets | |
1006 | (via their Python interfaces). |
|
1011 | (via their Python interfaces). | |
1007 | * [ ] Note that with -wthread, you can additionally use the |
|
1012 | * [ ] Note that with -wthread, you can additionally use the | |
1008 | -wxversion option to request a specific version of wx to be used. |
|
1013 | -wxversion option to request a specific version of wx to be used. | |
1009 | This requires that you have the wxversion Python module installed, |
|
1014 | This requires that you have the wxversion Python module installed, | |
1010 | which is part of recent wxPython distributions. |
|
1015 | which is part of recent wxPython distributions. | |
1011 | * [ ] If -pylab is given, IPython loads special support for the mat |
|
1016 | * [ ] If -pylab is given, IPython loads special support for the mat | |
1012 | plotlib library (http://matplotlib.sourceforge.net), allowing |
|
1017 | plotlib library (http://matplotlib.sourceforge.net), allowing | |
1013 | interactive usage of any of its backends as defined in the user's |
|
1018 | interactive usage of any of its backends as defined in the user's | |
1014 | ~/.matplotlib/matplotlibrc file. It automatically activates GTK, |
|
1019 | ~/.matplotlib/matplotlibrc file. It automatically activates GTK, | |
1015 | Qt or WX threading for IPyhton if the choice of matplotlib backend |
|
1020 | Qt or WX threading for IPyhton if the choice of matplotlib backend | |
1016 | requires it. It also modifies the %run command to correctly |
|
1021 | requires it. It also modifies the %run command to correctly | |
1017 | execute (without blocking) any matplotlib-based script which calls |
|
1022 | execute (without blocking) any matplotlib-based script which calls | |
1018 | show() at the end. |
|
1023 | show() at the end. | |
1019 | * [-tk] The -g/q/q4/wthread options, and -pylab (if matplotlib is |
|
1024 | * [-tk] The -g/q/q4/wthread options, and -pylab (if matplotlib is | |
1020 | configured to use GTK, Qt3, Qt4 or WX), will normally block Tk |
|
1025 | configured to use GTK, Qt3, Qt4 or WX), will normally block Tk | |
1021 | graphical interfaces. This means that when either GTK, Qt or WX |
|
1026 | graphical interfaces. This means that when either GTK, Qt or WX | |
1022 | threading is active, any attempt to open a Tk GUI will result in a |
|
1027 | threading is active, any attempt to open a Tk GUI will result in a | |
1023 | dead window, and possibly cause the Python interpreter to crash. |
|
1028 | dead window, and possibly cause the Python interpreter to crash. | |
1024 | An extra option, -tk, is available to address this issue. It can |
|
1029 | An extra option, -tk, is available to address this issue. It can | |
1025 | only be given as a second option after any of the above (-gthread, |
|
1030 | only be given as a second option after any of the above (-gthread, | |
1026 | -wthread or -pylab). |
|
1031 | -wthread or -pylab). | |
1027 | * [ ] If -tk is given, IPython will try to coordinate Tk threading |
|
1032 | * [ ] If -tk is given, IPython will try to coordinate Tk threading | |
1028 | with GTK, Qt or WX. This is however potentially unreliable, and |
|
1033 | with GTK, Qt or WX. This is however potentially unreliable, and | |
1029 | you will have to test on your platform and Python configuration to |
|
1034 | you will have to test on your platform and Python configuration to | |
1030 | determine whether it works for you. Debian users have reported |
|
1035 | determine whether it works for you. Debian users have reported | |
1031 | success, apparently due to the fact that Debian builds all of Tcl, |
|
1036 | success, apparently due to the fact that Debian builds all of Tcl, | |
1032 | Tk, Tkinter and Python with pthreads support. Under other Linux |
|
1037 | Tk, Tkinter and Python with pthreads support. Under other Linux | |
1033 | environments (such as Fedora Core 2/3), this option has caused |
|
1038 | environments (such as Fedora Core 2/3), this option has caused | |
1034 | random crashes and lockups of the Python interpreter. Under other |
|
1039 | random crashes and lockups of the Python interpreter. Under other | |
1035 | operating systems (Mac OSX and Windows), you'll need to try it to |
|
1040 | operating systems (Mac OSX and Windows), you'll need to try it to | |
1036 | find out, since currently no user reports are available. |
|
1041 | find out, since currently no user reports are available. | |
1037 | * [ ] There is unfortunately no way for IPython to determine at run |
|
1042 | * [ ] There is unfortunately no way for IPython to determine at run | |
1038 | time whether -tk will work reliably or not, so you will need to do |
|
1043 | time whether -tk will work reliably or not, so you will need to do | |
1039 | some experiments before relying on it for regular work. |
|
1044 | some experiments before relying on it for regular work. | |
1040 |
|
1045 | |||
1041 |
|
1046 | |||
1042 |
|
1047 | |||
1043 | Regular Options |
|
1048 | Regular Options | |
1044 | --------------- |
|
1049 | --------------- | |
1045 |
|
1050 | |||
1046 | After the above threading options have been given, regular options can |
|
1051 | After the above threading options have been given, regular options can | |
1047 | follow in any order. All options can be abbreviated to their shortest |
|
1052 | follow in any order. All options can be abbreviated to their shortest | |
1048 | non-ambiguous form and are case-sensitive. One or two dashes can be |
|
1053 | non-ambiguous form and are case-sensitive. One or two dashes can be | |
1049 | used. Some options have an alternate short form, indicated after a ``|``. |
|
1054 | used. Some options have an alternate short form, indicated after a ``|``. | |
1050 |
|
1055 | |||
1051 | Most options can also be set from your ipythonrc configuration file. See |
|
1056 | Most options can also be set from your ipythonrc configuration file. See | |
1052 | the provided example for more details on what the options do. Options |
|
1057 | the provided example for more details on what the options do. Options | |
1053 | given at the command line override the values set in the ipythonrc file. |
|
1058 | given at the command line override the values set in the ipythonrc file. | |
1054 |
|
1059 | |||
1055 | All options with a [no] prepended can be specified in negated form |
|
1060 | All options with a [no] prepended can be specified in negated form | |
1056 | (-nooption instead of -option) to turn the feature off. |
|
1061 | (-nooption instead of -option) to turn the feature off. | |
1057 |
|
1062 | |||
1058 | * [-help:] print a help message and exit. |
|
1063 | * [-help:] print a help message and exit. | |
1059 | * [-pylab:] this can only be given as the first option passed to |
|
1064 | * [-pylab:] this can only be given as the first option passed to | |
1060 | IPython (it will have no effect in any other position). It adds |
|
1065 | IPython (it will have no effect in any other position). It adds | |
1061 | special support for the matplotlib library |
|
1066 | special support for the matplotlib library | |
1062 | (http://matplotlib.sourceforge.net |
|
1067 | (http://matplotlib.sourceforge.net | |
1063 | http://matplotlib.sourceforge.net), allowing interactive usage of |
|
1068 | http://matplotlib.sourceforge.net), allowing interactive usage of | |
1064 | any of its backends as defined in the user's .matplotlibrc file. |
|
1069 | any of its backends as defined in the user's .matplotlibrc file. | |
1065 | It automatically activates GTK or WX threading for IPyhton if the |
|
1070 | It automatically activates GTK or WX threading for IPyhton if the | |
1066 | choice of matplotlib backend requires it. It also modifies the |
|
1071 | choice of matplotlib backend requires it. It also modifies the | |
1067 | %run command to correctly execute (without blocking) any |
|
1072 | %run command to correctly execute (without blocking) any | |
1068 | matplotlib-based script which calls show() at the end. See Sec. 15 |
|
1073 | matplotlib-based script which calls show() at the end. See Sec. 15 | |
1069 | <node15.html#sec:matplotlib-support> for more details. |
|
1074 | <node15.html#sec:matplotlib-support> for more details. | |
1070 | * [-autocall] <val>: Make IPython automatically call any callable |
|
1075 | * [-autocall] <val>: Make IPython automatically call any callable | |
1071 | object even if you didn't type explicit parentheses. For example, |
|
1076 | object even if you didn't type explicit parentheses. For example, | |
1072 | 'str 43' becomes 'str(43)' automatically. The value can be '0' to |
|
1077 | 'str 43' becomes 'str(43)' automatically. The value can be '0' to | |
1073 | disable the feature, '1' for smart autocall, where it is not |
|
1078 | disable the feature, '1' for smart autocall, where it is not | |
1074 | applied if there are no more arguments on the line, and '2' for |
|
1079 | applied if there are no more arguments on the line, and '2' for | |
1075 | full autocall, where all callable objects are automatically called |
|
1080 | full autocall, where all callable objects are automatically called | |
1076 | (even if no arguments are present). The default is '1'. |
|
1081 | (even if no arguments are present). The default is '1'. | |
1077 | * [-[no]autoindent:] Turn automatic indentation on/off. |
|
1082 | * [-[no]autoindent:] Turn automatic indentation on/off. | |
1078 | * [-[no]automagic:] make magic commands automatic (without needing |
|
1083 | * [-[no]automagic:] make magic commands automatic (without needing | |
1079 | their first character to be %). Type %magic at the IPython prompt |
|
1084 | their first character to be %). Type %magic at the IPython prompt | |
1080 | for more information. |
|
1085 | for more information. | |
1081 | * [-[no]autoedit_syntax:] When a syntax error occurs after editing a |
|
1086 | * [-[no]autoedit_syntax:] When a syntax error occurs after editing a | |
1082 | file, automatically open the file to the trouble causing line for |
|
1087 | file, automatically open the file to the trouble causing line for | |
1083 | convenient fixing. |
|
1088 | convenient fixing. | |
1084 | * [-[no]banner:] Print the initial information banner (default on). |
|
1089 | * [-[no]banner:] Print the initial information banner (default on). | |
1085 | * [-c <command>:] execute the given command string, and set sys.argv |
|
1090 | * [-c <command>:] execute the given command string, and set sys.argv | |
1086 | to ['c']. This is similar to the -c option in the normal Python |
|
1091 | to ['c']. This is similar to the -c option in the normal Python | |
1087 | interpreter. |
|
1092 | interpreter. | |
1088 | * [-cache_size|cs <n>:] size of the output cache (maximum number of |
|
1093 | * [-cache_size|cs <n>:] size of the output cache (maximum number of | |
1089 | entries to hold in memory). The default is 1000, you can change it |
|
1094 | entries to hold in memory). The default is 1000, you can change it | |
1090 | permanently in your config file. Setting it to 0 completely |
|
1095 | permanently in your config file. Setting it to 0 completely | |
1091 | disables the caching system, and the minimum value accepted is 20 |
|
1096 | disables the caching system, and the minimum value accepted is 20 | |
1092 | (if you provide a value less than 20, it is reset to 0 and a |
|
1097 | (if you provide a value less than 20, it is reset to 0 and a | |
1093 | warning is issued) This limit is defined because otherwise you'll |
|
1098 | warning is issued) This limit is defined because otherwise you'll | |
1094 | spend more time re-flushing a too small cache than working. |
|
1099 | spend more time re-flushing a too small cache than working. | |
1095 | * [-classic|cl:] Gives IPython a similar feel to the classic Python |
|
1100 | * [-classic|cl:] Gives IPython a similar feel to the classic Python | |
1096 | prompt. |
|
1101 | prompt. | |
1097 | * [-colors <scheme>:] Color scheme for prompts and exception |
|
1102 | * [-colors <scheme>:] Color scheme for prompts and exception | |
1098 | reporting. Currently implemented: NoColor, Linux and LightBG. |
|
1103 | reporting. Currently implemented: NoColor, Linux and LightBG. | |
1099 | * [-[no]color_info:] IPython can display information about objects |
|
1104 | * [-[no]color_info:] IPython can display information about objects | |
1100 | via a set of functions, and optionally can use colors for this, |
|
1105 | via a set of functions, and optionally can use colors for this, | |
1101 | syntax highlighting source code and various other elements. |
|
1106 | syntax highlighting source code and various other elements. | |
1102 | However, because this information is passed through a pager (like |
|
1107 | However, because this information is passed through a pager (like | |
1103 | 'less') and many pagers get confused with color codes, this option |
|
1108 | 'less') and many pagers get confused with color codes, this option | |
1104 | is off by default. You can test it and turn it on permanently in |
|
1109 | is off by default. You can test it and turn it on permanently in | |
1105 | your ipythonrc file if it works for you. As a reference, the |
|
1110 | your ipythonrc file if it works for you. As a reference, the | |
1106 | 'less' pager supplied with Mandrake 8.2 works ok, but that in |
|
1111 | 'less' pager supplied with Mandrake 8.2 works ok, but that in | |
1107 | RedHat 7.2 doesn't. |
|
1112 | RedHat 7.2 doesn't. | |
1108 | * [ ] Test it and turn it on permanently if it works with your |
|
1113 | * [ ] Test it and turn it on permanently if it works with your | |
1109 | system. The magic function %color_info allows you to toggle this |
|
1114 | system. The magic function %color_info allows you to toggle this | |
1110 | interactively for testing. |
|
1115 | interactively for testing. | |
1111 | * [-[no]debug:] Show information about the loading process. Very |
|
1116 | * [-[no]debug:] Show information about the loading process. Very | |
1112 | useful to pin down problems with your configuration files or to |
|
1117 | useful to pin down problems with your configuration files or to | |
1113 | get details about session restores. |
|
1118 | get details about session restores. | |
1114 | * [-[no]deep_reload:] IPython can use the deep_reload module which |
|
1119 | * [-[no]deep_reload:] IPython can use the deep_reload module which | |
1115 | reloads changes in modules recursively (it replaces the reload() |
|
1120 | reloads changes in modules recursively (it replaces the reload() | |
1116 | function, so you don't need to change anything to use it). |
|
1121 | function, so you don't need to change anything to use it). | |
1117 | deep_reload() forces a full reload of modules whose code may have |
|
1122 | deep_reload() forces a full reload of modules whose code may have | |
1118 | changed, which the default reload() function does not. |
|
1123 | changed, which the default reload() function does not. | |
1119 | * [ ] When deep_reload is off, IPython will use the normal reload(), |
|
1124 | * [ ] When deep_reload is off, IPython will use the normal reload(), | |
1120 | but deep_reload will still be available as dreload(). This feature |
|
1125 | but deep_reload will still be available as dreload(). This feature | |
1121 | is off by default [which means that you have both normal reload() |
|
1126 | is off by default [which means that you have both normal reload() | |
1122 | and dreload()]. |
|
1127 | and dreload()]. | |
1123 | * [-editor <name>:] Which editor to use with the %edit command. By |
|
1128 | * [-editor <name>:] Which editor to use with the %edit command. By | |
1124 | default, IPython will honor your EDITOR environment variable (if |
|
1129 | default, IPython will honor your EDITOR environment variable (if | |
1125 | not set, vi is the Unix default and notepad the Windows one). |
|
1130 | not set, vi is the Unix default and notepad the Windows one). | |
1126 | Since this editor is invoked on the fly by IPython and is meant |
|
1131 | Since this editor is invoked on the fly by IPython and is meant | |
1127 | for editing small code snippets, you may want to use a small, |
|
1132 | for editing small code snippets, you may want to use a small, | |
1128 | lightweight editor here (in case your default EDITOR is something |
|
1133 | lightweight editor here (in case your default EDITOR is something | |
1129 | like Emacs). |
|
1134 | like Emacs). | |
1130 | * [-ipythondir <name>:] name of your IPython configuration directory |
|
1135 | * [-ipythondir <name>:] name of your IPython configuration directory | |
1131 | IPYTHONDIR. This can also be specified through the environment |
|
1136 | IPYTHONDIR. This can also be specified through the environment | |
1132 | variable IPYTHONDIR. |
|
1137 | variable IPYTHONDIR. | |
1133 | * [-log|l:] generate a log file of all input. The file is named |
|
1138 | * [-log|l:] generate a log file of all input. The file is named | |
1134 | ipython_log.py in your current directory (which prevents logs from |
|
1139 | ipython_log.py in your current directory (which prevents logs from | |
1135 | multiple IPython sessions from trampling each other). You can use |
|
1140 | multiple IPython sessions from trampling each other). You can use | |
1136 | this to later restore a session by loading your logfile as a file |
|
1141 | this to later restore a session by loading your logfile as a file | |
1137 | to be executed with option -logplay (see below). |
|
1142 | to be executed with option -logplay (see below). | |
1138 | * [-logfile|lf <name>:] specify the name of your logfile. |
|
1143 | * [-logfile|lf <name>:] specify the name of your logfile. | |
1139 | * [-logplay|lp <name>:] you can replay a previous log. For restoring |
|
1144 | * [-logplay|lp <name>:] you can replay a previous log. For restoring | |
1140 | a session as close as possible to the state you left it in, use |
|
1145 | a session as close as possible to the state you left it in, use | |
1141 | this option (don't just run the logfile). With -logplay, IPython |
|
1146 | this option (don't just run the logfile). With -logplay, IPython | |
1142 | will try to reconstruct the previous working environment in full, |
|
1147 | will try to reconstruct the previous working environment in full, | |
1143 | not just execute the commands in the logfile. |
|
1148 | not just execute the commands in the logfile. | |
1144 | * [ ] When a session is restored, logging is automatically turned on |
|
1149 | * [ ] When a session is restored, logging is automatically turned on | |
1145 | again with the name of the logfile it was invoked with (it is read |
|
1150 | again with the name of the logfile it was invoked with (it is read | |
1146 | from the log header). So once you've turned logging on for a |
|
1151 | from the log header). So once you've turned logging on for a | |
1147 | session, you can quit IPython and reload it as many times as you |
|
1152 | session, you can quit IPython and reload it as many times as you | |
1148 | want and it will continue to log its history and restore from the |
|
1153 | want and it will continue to log its history and restore from the | |
1149 | beginning every time. |
|
1154 | beginning every time. | |
1150 | * [ ] Caveats: there are limitations in this option. The history |
|
1155 | * [ ] Caveats: there are limitations in this option. The history | |
1151 | variables _i*,_* and _dh don't get restored properly. In the |
|
1156 | variables _i*,_* and _dh don't get restored properly. In the | |
1152 | future we will try to implement full session saving by writing and |
|
1157 | future we will try to implement full session saving by writing and | |
1153 | retrieving a 'snapshot' of the memory state of IPython. But our |
|
1158 | retrieving a 'snapshot' of the memory state of IPython. But our | |
1154 | first attempts failed because of inherent limitations of Python's |
|
1159 | first attempts failed because of inherent limitations of Python's | |
1155 | Pickle module, so this may have to wait. |
|
1160 | Pickle module, so this may have to wait. | |
1156 | * [-[no]messages:] Print messages which IPython collects about its |
|
1161 | * [-[no]messages:] Print messages which IPython collects about its | |
1157 | startup process (default on). |
|
1162 | startup process (default on). | |
1158 | * [-[no]pdb:] Automatically call the pdb debugger after every |
|
1163 | * [-[no]pdb:] Automatically call the pdb debugger after every | |
1159 | uncaught exception. If you are used to debugging using pdb, this |
|
1164 | uncaught exception. If you are used to debugging using pdb, this | |
1160 | puts you automatically inside of it after any call (either in |
|
1165 | puts you automatically inside of it after any call (either in | |
1161 | IPython or in code called by it) which triggers an exception which |
|
1166 | IPython or in code called by it) which triggers an exception which | |
1162 | goes uncaught. |
|
1167 | goes uncaught. | |
1163 | * [-[no]pprint:] ipython can optionally use the pprint (pretty |
|
1168 | * [-[no]pprint:] ipython can optionally use the pprint (pretty | |
1164 | printer) module for displaying results. pprint tends to give a |
|
1169 | printer) module for displaying results. pprint tends to give a | |
1165 | nicer display of nested data structures. If you like it, you can |
|
1170 | nicer display of nested data structures. If you like it, you can | |
1166 | turn it on permanently in your config file (default off). |
|
1171 | turn it on permanently in your config file (default off). | |
1167 | * [-profile|p] <name>: assume that your config file is |
|
1172 | * [-profile|p] <name>: assume that your config file is | |
1168 | ipythonrc-<name> (looks in current dir first, then in IPYTHONDIR). |
|
1173 | ipythonrc-<name> (looks in current dir first, then in IPYTHONDIR). | |
1169 | This is a quick way to keep and load multiple config files for |
|
1174 | This is a quick way to keep and load multiple config files for | |
1170 | different tasks, especially if you use the include option of |
|
1175 | different tasks, especially if you use the include option of | |
1171 | config files. You can keep a basic IPYTHONDIR/ipythonrc file and |
|
1176 | config files. You can keep a basic IPYTHONDIR/ipythonrc file and | |
1172 | then have other 'profiles' which include this one and load extra |
|
1177 | then have other 'profiles' which include this one and load extra | |
1173 | things for particular tasks. For example: |
|
1178 | things for particular tasks. For example: | |
1174 | * [ ] 1. $HOME/.ipython/ipythonrc : load basic things you always want. |
|
1179 | * [ ] 1. $HOME/.ipython/ipythonrc : load basic things you always want. | |
1175 | * [ ] 2. $HOME/.ipython/ipythonrc-math : load (1) and basic |
|
1180 | * [ ] 2. $HOME/.ipython/ipythonrc-math : load (1) and basic | |
1176 | math-related modules. |
|
1181 | math-related modules. | |
1177 | * [ ] 3. $HOME/.ipython/ipythonrc-numeric : load (1) and Numeric and |
|
1182 | * [ ] 3. $HOME/.ipython/ipythonrc-numeric : load (1) and Numeric and | |
1178 | plotting modules. |
|
1183 | plotting modules. | |
1179 | * [ ] Since it is possible to create an endless loop by having |
|
1184 | * [ ] Since it is possible to create an endless loop by having | |
1180 | circular file inclusions, IPython will stop if it reaches 15 |
|
1185 | circular file inclusions, IPython will stop if it reaches 15 | |
1181 | recursive inclusions. |
|
1186 | recursive inclusions. | |
1182 | * [-prompt_in1|pi1 <string>:] Specify the string used for input |
|
1187 | * [-prompt_in1|pi1 <string>:] Specify the string used for input | |
1183 | prompts. Note that if you are using numbered prompts, the number |
|
1188 | prompts. Note that if you are using numbered prompts, the number | |
1184 | is represented with a '\#' in the string. Don't forget to quote |
|
1189 | is represented with a '\#' in the string. Don't forget to quote | |
1185 | strings with spaces embedded in them. Default: 'In [\#]:'. |
|
1190 | strings with spaces embedded in them. Default: 'In [\#]:'. | |
1186 | Sec. 7.2 <node7.html#sec:prompts> discusses in detail all the |
|
1191 | Sec. 7.2 <node7.html#sec:prompts> discusses in detail all the | |
1187 | available escapes to customize your prompts. |
|
1192 | available escapes to customize your prompts. | |
1188 | * [-prompt_in2|pi2 <string>:] Similar to the previous option, but |
|
1193 | * [-prompt_in2|pi2 <string>:] Similar to the previous option, but | |
1189 | used for the continuation prompts. The special sequence '\D' is |
|
1194 | used for the continuation prompts. The special sequence '\D' is | |
1190 | similar to '\#', but with all digits replaced dots (so you can |
|
1195 | similar to '\#', but with all digits replaced dots (so you can | |
1191 | have your continuation prompt aligned with your input prompt). |
|
1196 | have your continuation prompt aligned with your input prompt). | |
1192 | Default: ' .\D.:' (note three spaces at the start for alignment |
|
1197 | Default: ' .\D.:' (note three spaces at the start for alignment | |
1193 | with 'In [\#]'). |
|
1198 | with 'In [\#]'). | |
1194 | * [-prompt_out|po <string>:] String used for output prompts, also |
|
1199 | * [-prompt_out|po <string>:] String used for output prompts, also | |
1195 | uses numbers like prompt_in1. Default: 'Out[\#]:' |
|
1200 | uses numbers like prompt_in1. Default: 'Out[\#]:' | |
1196 | * [-quick:] start in bare bones mode (no config file loaded). |
|
1201 | * [-quick:] start in bare bones mode (no config file loaded). | |
1197 | * [-rcfile <name>:] name of your IPython resource configuration |
|
1202 | * [-rcfile <name>:] name of your IPython resource configuration | |
1198 | file. Normally IPython loads ipythonrc (from current directory) or |
|
1203 | file. Normally IPython loads ipythonrc (from current directory) or | |
1199 | IPYTHONDIR/ipythonrc. |
|
1204 | IPYTHONDIR/ipythonrc. | |
1200 | * [ ] If the loading of your config file fails, IPython starts with |
|
1205 | * [ ] If the loading of your config file fails, IPython starts with | |
1201 | a bare bones configuration (no modules loaded at all). |
|
1206 | a bare bones configuration (no modules loaded at all). | |
1202 | * [-[no]readline:] use the readline library, which is needed to |
|
1207 | * [-[no]readline:] use the readline library, which is needed to | |
1203 | support name completion and command history, among other things. |
|
1208 | support name completion and command history, among other things. | |
1204 | It is enabled by default, but may cause problems for users of |
|
1209 | It is enabled by default, but may cause problems for users of | |
1205 | X/Emacs in Python comint or shell buffers. |
|
1210 | X/Emacs in Python comint or shell buffers. | |
1206 | * [ ] Note that X/Emacs 'eterm' buffers (opened with M-x term) |
|
1211 | * [ ] Note that X/Emacs 'eterm' buffers (opened with M-x term) | |
1207 | support IPython's readline and syntax coloring fine, only 'emacs' |
|
1212 | support IPython's readline and syntax coloring fine, only 'emacs' | |
1208 | (M-x shell and C-c !) buffers do not. |
|
1213 | (M-x shell and C-c !) buffers do not. | |
1209 | * [-screen_length|sl <n>:] number of lines of your screen. This is |
|
1214 | * [-screen_length|sl <n>:] number of lines of your screen. This is | |
1210 | used to control printing of very long strings. Strings longer than |
|
1215 | used to control printing of very long strings. Strings longer than | |
1211 | this number of lines will be sent through a pager instead of |
|
1216 | this number of lines will be sent through a pager instead of | |
1212 | directly printed. |
|
1217 | directly printed. | |
1213 | * [ ] The default value for this is 0, which means IPython will |
|
1218 | * [ ] The default value for this is 0, which means IPython will | |
1214 | auto-detect your screen size every time it needs to print certain |
|
1219 | auto-detect your screen size every time it needs to print certain | |
1215 | potentially long strings (this doesn't change the behavior of the |
|
1220 | potentially long strings (this doesn't change the behavior of the | |
1216 | 'print' keyword, it's only triggered internally). If for some |
|
1221 | 'print' keyword, it's only triggered internally). If for some | |
1217 | reason this isn't working well (it needs curses support), specify |
|
1222 | reason this isn't working well (it needs curses support), specify | |
1218 | it yourself. Otherwise don't change the default. |
|
1223 | it yourself. Otherwise don't change the default. | |
1219 | * [-separate_in|si <string>:] separator before input prompts. |
|
1224 | * [-separate_in|si <string>:] separator before input prompts. | |
1220 | Default: '\n' |
|
1225 | Default: '\n' | |
1221 | * [-separate_out|so <string>:] separator before output prompts. |
|
1226 | * [-separate_out|so <string>:] separator before output prompts. | |
1222 | Default: nothing. |
|
1227 | Default: nothing. | |
1223 | * [-separate_out2|so2 <string>:] separator after output prompts. |
|
1228 | * [-separate_out2|so2 <string>:] separator after output prompts. | |
1224 | Default: nothing. |
|
1229 | Default: nothing. | |
1225 | * [ ] For these three options, use the value 0 to specify no separator. |
|
1230 | * [ ] For these three options, use the value 0 to specify no separator. | |
1226 | * [-nosep:] shorthand for '-SeparateIn 0 -SeparateOut 0 |
|
1231 | * [-nosep:] shorthand for '-SeparateIn 0 -SeparateOut 0 | |
1227 | -SeparateOut2 0'. Simply removes all input/output separators. |
|
1232 | -SeparateOut2 0'. Simply removes all input/output separators. | |
1228 | * [-upgrade:] allows you to upgrade your IPYTHONDIR configuration |
|
1233 | * [-upgrade:] allows you to upgrade your IPYTHONDIR configuration | |
1229 | when you install a new version of IPython. Since new versions may |
|
1234 | when you install a new version of IPython. Since new versions may | |
1230 | include new command line options or example files, this copies |
|
1235 | include new command line options or example files, this copies | |
1231 | updated ipythonrc-type files. However, it backs up (with a .old |
|
1236 | updated ipythonrc-type files. However, it backs up (with a .old | |
1232 | extension) all files which it overwrites so that you can merge |
|
1237 | extension) all files which it overwrites so that you can merge | |
1233 | back any customizations you might have in your personal files. |
|
1238 | back any customizations you might have in your personal files. | |
1234 | * [-Version:] print version information and exit. |
|
1239 | * [-Version:] print version information and exit. | |
1235 | * [-wxversion <string>:] Select a specific version of wxPython (used |
|
1240 | * [-wxversion <string>:] Select a specific version of wxPython (used | |
1236 | in conjunction with -wthread). Requires the wxversion module, part |
|
1241 | in conjunction with -wthread). Requires the wxversion module, part | |
1237 | of recent wxPython distributions |
|
1242 | of recent wxPython distributions | |
1238 | * [-xmode <modename>:] Mode for exception reporting. |
|
1243 | * [-xmode <modename>:] Mode for exception reporting. | |
1239 | * [ ] Valid modes: Plain, Context and Verbose. |
|
1244 | * [ ] Valid modes: Plain, Context and Verbose. | |
1240 | * [ ] Plain: similar to python's normal traceback printing. |
|
1245 | * [ ] Plain: similar to python's normal traceback printing. | |
1241 | * [ ] Context: prints 5 lines of context source code around each |
|
1246 | * [ ] Context: prints 5 lines of context source code around each | |
1242 | line in the traceback. |
|
1247 | line in the traceback. | |
1243 | * [ ] Verbose: similar to Context, but additionally prints the |
|
1248 | * [ ] Verbose: similar to Context, but additionally prints the | |
1244 | variables currently visible where the exception happened |
|
1249 | variables currently visible where the exception happened | |
1245 | (shortening their strings if too long). This can potentially be |
|
1250 | (shortening their strings if too long). This can potentially be | |
1246 | very slow, if you happen to have a huge data structure whose |
|
1251 | very slow, if you happen to have a huge data structure whose | |
1247 | string representation is complex to compute. Your computer may |
|
1252 | string representation is complex to compute. Your computer may | |
1248 | appear to freeze for a while with cpu usage at 100%. If this |
|
1253 | appear to freeze for a while with cpu usage at 100%. If this | |
1249 | occurs, you can cancel the traceback with Ctrl-C (maybe hitting it |
|
1254 | occurs, you can cancel the traceback with Ctrl-C (maybe hitting it | |
1250 | more than once). |
|
1255 | more than once). | |
1251 |
|
1256 | |||
1252 | Interactive use |
|
1257 | Interactive use | |
1253 | =============== |
|
1258 | =============== | |
1254 |
|
1259 | |||
1255 | Warning: IPython relies on the existence of a global variable called |
|
1260 | Warning: IPython relies on the existence of a global variable called | |
1256 | __IP which controls the shell itself. If you redefine __IP to anything, |
|
1261 | __IP which controls the shell itself. If you redefine __IP to anything, | |
1257 | bizarre behavior will quickly occur. |
|
1262 | bizarre behavior will quickly occur. | |
1258 |
|
1263 | |||
1259 | Other than the above warning, IPython is meant to work as a drop-in |
|
1264 | Other than the above warning, IPython is meant to work as a drop-in | |
1260 | replacement for the standard interactive interpreter. As such, any code |
|
1265 | replacement for the standard interactive interpreter. As such, any code | |
1261 | which is valid python should execute normally under IPython (cases where |
|
1266 | which is valid python should execute normally under IPython (cases where | |
1262 | this is not true should be reported as bugs). It does, however, offer |
|
1267 | this is not true should be reported as bugs). It does, however, offer | |
1263 | many features which are not available at a standard python prompt. What |
|
1268 | many features which are not available at a standard python prompt. What | |
1264 | follows is a list of these. |
|
1269 | follows is a list of these. | |
1265 |
|
1270 | |||
1266 |
|
1271 | |||
1267 | Caution for Windows users |
|
1272 | Caution for Windows users | |
1268 | ------------------------- |
|
1273 | ------------------------- | |
1269 |
|
1274 | |||
1270 | Windows, unfortunately, uses the '\' character as a path separator. This |
|
1275 | Windows, unfortunately, uses the '\' character as a path separator. This | |
1271 | is a terrible choice, because '\' also represents the escape character |
|
1276 | is a terrible choice, because '\' also represents the escape character | |
1272 | in most modern programming languages, including Python. For this reason, |
|
1277 | in most modern programming languages, including Python. For this reason, | |
1273 | issuing many of the commands discussed below (especially magics which |
|
1278 | issuing many of the commands discussed below (especially magics which | |
1274 | affect the filesystem) with '\' in them will cause strange errors. |
|
1279 | affect the filesystem) with '\' in them will cause strange errors. | |
1275 |
|
1280 | |||
1276 | A partial solution is to use instead the '/' character as a path |
|
1281 | A partial solution is to use instead the '/' character as a path | |
1277 | separator, which Windows recognizes in most situations. However, in |
|
1282 | separator, which Windows recognizes in most situations. However, in | |
1278 | Windows commands '/' flags options, so you can not use it for the root |
|
1283 | Windows commands '/' flags options, so you can not use it for the root | |
1279 | directory. This means that paths beginning at the root must be typed in |
|
1284 | directory. This means that paths beginning at the root must be typed in | |
1280 | a contrived manner like: |
|
1285 | a contrived manner like: | |
1281 | %copy \opt/foo/bar.txt \tmp |
|
1286 | %copy \opt/foo/bar.txt \tmp | |
1282 |
|
1287 | |||
1283 | There is no sensible thing IPython can do to truly work around this flaw |
|
1288 | There is no sensible thing IPython can do to truly work around this flaw | |
1284 | in Windows^3 <footnode.html#foot878>. |
|
1289 | in Windows^3 <footnode.html#foot878>. | |
1285 |
|
1290 | |||
1286 |
|
1291 | |||
1287 |
|
1292 | |||
1288 | Magic command system |
|
1293 | Magic command system | |
1289 | -------------------- |
|
1294 | -------------------- | |
1290 |
|
1295 | |||
1291 | IPython will treat any line whose first character is a % as a special |
|
1296 | IPython will treat any line whose first character is a % as a special | |
1292 | call to a 'magic' function. These allow you to control the behavior of |
|
1297 | call to a 'magic' function. These allow you to control the behavior of | |
1293 | IPython itself, plus a lot of system-type features. They are all |
|
1298 | IPython itself, plus a lot of system-type features. They are all | |
1294 | prefixed with a % character, but parameters are given without |
|
1299 | prefixed with a % character, but parameters are given without | |
1295 | parentheses or quotes. |
|
1300 | parentheses or quotes. | |
1296 |
|
1301 | |||
1297 | Example: typing '%cd mydir' (without the quotes) changes you working |
|
1302 | Example: typing '%cd mydir' (without the quotes) changes you working | |
1298 | directory to 'mydir', if it exists. |
|
1303 | directory to 'mydir', if it exists. | |
1299 |
|
1304 | |||
1300 | If you have 'automagic' enabled (in your ipythonrc file, via the command |
|
1305 | If you have 'automagic' enabled (in your ipythonrc file, via the command | |
1301 | line option -automagic or with the %automagic function), you don't need |
|
1306 | line option -automagic or with the %automagic function), you don't need | |
1302 | to type in the % explicitly. IPython will scan its internal list of |
|
1307 | to type in the % explicitly. IPython will scan its internal list of | |
1303 | magic functions and call one if it exists. With automagic on you can |
|
1308 | magic functions and call one if it exists. With automagic on you can | |
1304 | then just type 'cd mydir' to go to directory 'mydir'. The automagic |
|
1309 | then just type 'cd mydir' to go to directory 'mydir'. The automagic | |
1305 | system has the lowest possible precedence in name searches, so defining |
|
1310 | system has the lowest possible precedence in name searches, so defining | |
1306 | an identifier with the same name as an existing magic function will |
|
1311 | an identifier with the same name as an existing magic function will | |
1307 | shadow it for automagic use. You can still access the shadowed magic |
|
1312 | shadow it for automagic use. You can still access the shadowed magic | |
1308 | function by explicitly using the % character at the beginning of the line. |
|
1313 | function by explicitly using the % character at the beginning of the line. | |
1309 |
|
1314 | |||
1310 | An example (with automagic on) should clarify all this:: |
|
1315 | An example (with automagic on) should clarify all this:: | |
1311 |
|
1316 | |||
1312 | In [1]: cd ipython # %cd is called by automagic |
|
1317 | In [1]: cd ipython # %cd is called by automagic | |
1313 |
|
1318 | |||
1314 | /home/fperez/ipython |
|
1319 | /home/fperez/ipython | |
1315 |
|
1320 | |||
1316 | In [2]: cd=1 # now cd is just a variable |
|
1321 | In [2]: cd=1 # now cd is just a variable | |
1317 |
|
1322 | |||
1318 | In [3]: cd .. # and doesn't work as a function anymore |
|
1323 | In [3]: cd .. # and doesn't work as a function anymore | |
1319 |
|
1324 | |||
1320 | ------------------------------ |
|
1325 | ------------------------------ | |
1321 |
|
1326 | |||
1322 | File "<console>", line 1 |
|
1327 | File "<console>", line 1 | |
1323 |
|
1328 | |||
1324 | cd .. |
|
1329 | cd .. | |
1325 |
|
1330 | |||
1326 | ^ |
|
1331 | ^ | |
1327 |
|
1332 | |||
1328 | SyntaxError: invalid syntax |
|
1333 | SyntaxError: invalid syntax | |
1329 |
|
1334 | |||
1330 | In [4]: %cd .. # but %cd always works |
|
1335 | In [4]: %cd .. # but %cd always works | |
1331 |
|
1336 | |||
1332 | /home/fperez |
|
1337 | /home/fperez | |
1333 |
|
1338 | |||
1334 | In [5]: del cd # if you remove the cd variable |
|
1339 | In [5]: del cd # if you remove the cd variable | |
1335 |
|
1340 | |||
1336 | In [6]: cd ipython # automagic can work again |
|
1341 | In [6]: cd ipython # automagic can work again | |
1337 |
|
1342 | |||
1338 | /home/fperez/ipython |
|
1343 | /home/fperez/ipython | |
1339 |
|
1344 | |||
1340 | You can define your own magic functions to extend the system. The |
|
1345 | You can define your own magic functions to extend the system. The | |
1341 | following example defines a new magic command, %impall:: |
|
1346 | following example defines a new magic command, %impall:: | |
1342 |
|
1347 | |||
1343 | import IPython.ipapi |
|
1348 | import IPython.ipapi | |
1344 |
|
1349 | |||
1345 | ip = IPython.ipapi.get() |
|
1350 | ip = IPython.ipapi.get() | |
1346 |
|
1351 | |||
1347 | def doimp(self, arg): |
|
1352 | def doimp(self, arg): | |
1348 |
|
1353 | |||
1349 | ip = self.api |
|
1354 | ip = self.api | |
1350 |
|
1355 | |||
1351 | ip.ex("import %s; reload(%s); from %s import *" % ( |
|
1356 | ip.ex("import %s; reload(%s); from %s import *" % ( | |
1352 |
|
1357 | |||
1353 | arg,arg,arg) |
|
1358 | arg,arg,arg) | |
1354 |
|
1359 | |||
1355 | ) |
|
1360 | ) | |
1356 |
|
1361 | |||
1357 | ip.expose_magic('impall', doimp) |
|
1362 | ip.expose_magic('impall', doimp) | |
1358 |
|
1363 | |||
1359 | You can also define your own aliased names for magic functions. In your |
|
1364 | You can also define your own aliased names for magic functions. In your | |
1360 | ipythonrc file, placing a line like: |
|
1365 | ipythonrc file, placing a line like: | |
1361 |
|
1366 | |||
1362 | execute __IP.magic_cl = __IP.magic_clear |
|
1367 | execute __IP.magic_cl = __IP.magic_clear | |
1363 |
|
1368 | |||
1364 | will define %cl as a new name for %clear. |
|
1369 | will define %cl as a new name for %clear. | |
1365 |
|
1370 | |||
1366 | Type %magic for more information, including a list of all available |
|
1371 | Type %magic for more information, including a list of all available | |
1367 | magic functions at any time and their docstrings. You can also type |
|
1372 | magic functions at any time and their docstrings. You can also type | |
1368 | %magic_function_name? (see sec. 6.4 <#sec:dyn-object-info> for |
|
1373 | %magic_function_name? (see sec. 6.4 <#sec:dyn-object-info> for | |
1369 | information on the '?' system) to get information about any particular |
|
1374 | information on the '?' system) to get information about any particular | |
1370 | magic function you are interested in. |
|
1375 | magic function you are interested in. | |
1371 |
|
1376 | |||
1372 |
|
1377 | |||
1373 | Magic commands |
|
1378 | Magic commands | |
1374 | -------------- |
|
1379 | -------------- | |
1375 |
|
1380 | |||
1376 | The rest of this section is automatically generated for each release |
|
1381 | The rest of this section is automatically generated for each release | |
1377 | from the docstrings in the IPython code. Therefore the formatting is |
|
1382 | from the docstrings in the IPython code. Therefore the formatting is | |
1378 | somewhat minimal, but this method has the advantage of having |
|
1383 | somewhat minimal, but this method has the advantage of having | |
1379 | information always in sync with the code. |
|
1384 | information always in sync with the code. | |
1380 |
|
1385 | |||
1381 | A list of all the magic commands available in IPython's default |
|
1386 | A list of all the magic commands available in IPython's default | |
1382 | installation follows. This is similar to what you'll see by simply |
|
1387 | installation follows. This is similar to what you'll see by simply | |
1383 | typing %magic at the prompt, but that will also give you information |
|
1388 | typing %magic at the prompt, but that will also give you information | |
1384 | about magic commands you may have added as part of your personal |
|
1389 | about magic commands you may have added as part of your personal | |
1385 | customizations. |
|
1390 | customizations. | |
1386 |
|
1391 | |||
1387 | :: |
|
1392 | :: | |
1388 |
|
1393 | |||
1389 | %Exit: Exit IPython without confirmation. |
|
1394 | %Exit: Exit IPython without confirmation. | |
1390 |
|
1395 | |||
1391 |
|
1396 | |||
1392 | %Pprint: Toggle pretty printing on/off. |
|
1397 | %Pprint: Toggle pretty printing on/off. | |
1393 |
|
1398 | |||
1394 |
|
1399 | |||
1395 | %alias: Define an alias for a system command. |
|
1400 | %alias: Define an alias for a system command. | |
1396 |
|
1401 | |||
1397 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' |
|
1402 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' | |
1398 |
|
1403 | |||
1399 | Then, typing 'alias_name params' will execute the system command 'cmd |
|
1404 | Then, typing 'alias_name params' will execute the system command 'cmd | |
1400 | params' (from your underlying operating system). |
|
1405 | params' (from your underlying operating system). | |
1401 |
|
1406 | |||
1402 | Aliases have lower precedence than magic functions and Python normal |
|
1407 | Aliases have lower precedence than magic functions and Python normal | |
1403 | variables, so if 'foo' is both a Python variable and an alias, the alias |
|
1408 | variables, so if 'foo' is both a Python variable and an alias, the alias | |
1404 | can not be executed until 'del foo' removes the Python variable. |
|
1409 | can not be executed until 'del foo' removes the Python variable. | |
1405 |
|
1410 | |||
1406 | You can use the %l specifier in an alias definition to represent the |
|
1411 | You can use the %l specifier in an alias definition to represent the | |
1407 | whole line when the alias is called. For example: |
|
1412 | whole line when the alias is called. For example: | |
1408 |
|
1413 | |||
1409 | In [2]: alias all echo "Input in brackets: <%l>" |
|
1414 | In [2]: alias all echo "Input in brackets: <%l>" | |
1410 | In [3]: all hello world |
|
1415 | In [3]: all hello world | |
1411 | Input in brackets: <hello world> |
|
1416 | Input in brackets: <hello world> | |
1412 |
|
1417 | |||
1413 | You can also define aliases with parameters using %s specifiers (one per |
|
1418 | You can also define aliases with parameters using %s specifiers (one per | |
1414 | parameter): |
|
1419 | parameter): | |
1415 |
|
1420 | |||
1416 | In [1]: alias parts echo first %s second %s |
|
1421 | In [1]: alias parts echo first %s second %s | |
1417 | In [2]: %parts A B |
|
1422 | In [2]: %parts A B | |
1418 | first A second B |
|
1423 | first A second B | |
1419 | In [3]: %parts A |
|
1424 | In [3]: %parts A | |
1420 | Incorrect number of arguments: 2 expected. |
|
1425 | Incorrect number of arguments: 2 expected. | |
1421 | parts is an alias to: 'echo first %s second %s' |
|
1426 | parts is an alias to: 'echo first %s second %s' | |
1422 |
|
1427 | |||
1423 | Note that %l and %s are mutually exclusive. You can only use one or the |
|
1428 | Note that %l and %s are mutually exclusive. You can only use one or the | |
1424 | other in your aliases. |
|
1429 | other in your aliases. | |
1425 |
|
1430 | |||
1426 | Aliases expand Python variables just like system calls using ! or !! do: |
|
1431 | Aliases expand Python variables just like system calls using ! or !! do: | |
1427 | all expressions prefixed with '$' get expanded. For details of the |
|
1432 | all expressions prefixed with '$' get expanded. For details of the | |
1428 | semantic rules, see PEP-215: http://www.python.org/peps/pep-0215.html. |
|
1433 | semantic rules, see PEP-215: http://www.python.org/peps/pep-0215.html. | |
1429 | This is the library used by IPython for variable expansion. If you want |
|
1434 | This is the library used by IPython for variable expansion. If you want | |
1430 | to access a true shell variable, an extra $ is necessary to prevent its |
|
1435 | to access a true shell variable, an extra $ is necessary to prevent its | |
1431 | expansion by IPython: |
|
1436 | expansion by IPython: | |
1432 |
|
1437 | |||
1433 | In [6]: alias show echo |
|
1438 | In [6]: alias show echo | |
1434 | In [7]: PATH='A Python string' |
|
1439 | In [7]: PATH='A Python string' | |
1435 | In [8]: show $PATH |
|
1440 | In [8]: show $PATH | |
1436 | A Python string |
|
1441 | A Python string | |
1437 | In [9]: show $$PATH |
|
1442 | In [9]: show $$PATH | |
1438 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
|
1443 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... | |
1439 |
|
1444 | |||
1440 | You can use the alias facility to acess all of $PATH. See the %rehash |
|
1445 | You can use the alias facility to acess all of $PATH. See the %rehash | |
1441 | and %rehashx functions, which automatically create aliases for the |
|
1446 | and %rehashx functions, which automatically create aliases for the | |
1442 | contents of your $PATH. |
|
1447 | contents of your $PATH. | |
1443 |
|
1448 | |||
1444 | If called with no parameters, %alias prints the current alias table. |
|
1449 | If called with no parameters, %alias prints the current alias table. | |
1445 |
|
1450 | |||
1446 |
|
1451 | |||
1447 | %autocall: Make functions callable without having to type parentheses. |
|
1452 | %autocall: Make functions callable without having to type parentheses. | |
1448 |
|
1453 | |||
1449 | Usage: |
|
1454 | Usage: | |
1450 |
|
1455 | |||
1451 | %autocall [mode] |
|
1456 | %autocall [mode] | |
1452 |
|
1457 | |||
1453 | The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the |
|
1458 | The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the | |
1454 | value is toggled on and off (remembering the previous state). |
|
1459 | value is toggled on and off (remembering the previous state). | |
1455 |
|
1460 | |||
1456 | In more detail, these values mean: |
|
1461 | In more detail, these values mean: | |
1457 |
|
1462 | |||
1458 | 0 -> fully disabled |
|
1463 | 0 -> fully disabled | |
1459 |
|
1464 | |||
1460 | 1 -> active, but do not apply if there are no arguments on the line. |
|
1465 | 1 -> active, but do not apply if there are no arguments on the line. | |
1461 |
|
1466 | |||
1462 | In this mode, you get: |
|
1467 | In this mode, you get: | |
1463 |
|
1468 | |||
1464 | In [1]: callable Out[1]: <built-in function callable> |
|
1469 | In [1]: callable Out[1]: <built-in function callable> | |
1465 |
|
1470 | |||
1466 | In [2]: callable 'hello' ---> callable('hello') Out[2]: False |
|
1471 | In [2]: callable 'hello' ---> callable('hello') Out[2]: False | |
1467 |
|
1472 | |||
1468 | 2 -> Active always. Even if no arguments are present, the callable |
|
1473 | 2 -> Active always. Even if no arguments are present, the callable | |
1469 | object is called: |
|
1474 | object is called: | |
1470 |
|
1475 | |||
1471 | In [4]: callable ---> callable() |
|
1476 | In [4]: callable ---> callable() | |
1472 |
|
1477 | |||
1473 | Note that even with autocall off, you can still use '/' at the start of |
|
1478 | Note that even with autocall off, you can still use '/' at the start of | |
1474 | a line to treat the first argument on the command line as a function and |
|
1479 | a line to treat the first argument on the command line as a function and | |
1475 | add parentheses to it: |
|
1480 | add parentheses to it: | |
1476 |
|
1481 | |||
1477 | In [8]: /str 43 ---> str(43) Out[8]: '43' |
|
1482 | In [8]: /str 43 ---> str(43) Out[8]: '43' | |
1478 |
|
1483 | |||
1479 |
|
1484 | |||
1480 | %autoindent: Toggle autoindent on/off (if available). |
|
1485 | %autoindent: Toggle autoindent on/off (if available). | |
1481 |
|
1486 | |||
1482 |
|
1487 | |||
1483 | %automagic: Make magic functions callable without having to type the |
|
1488 | %automagic: Make magic functions callable without having to type the | |
1484 | initial %. |
|
1489 | initial %. | |
1485 |
|
1490 | |||
1486 | Without argumentsl toggles on/off (when off, you must call it as |
|
1491 | Without argumentsl toggles on/off (when off, you must call it as | |
1487 | %automagic, of course). With arguments it sets the value, and you can |
|
1492 | %automagic, of course). With arguments it sets the value, and you can | |
1488 | use any of (case insensitive): |
|
1493 | use any of (case insensitive): | |
1489 |
|
1494 | |||
1490 | - on,1,True: to activate |
|
1495 | - on,1,True: to activate | |
1491 |
|
1496 | |||
1492 | - off,0,False: to deactivate. |
|
1497 | - off,0,False: to deactivate. | |
1493 |
|
1498 | |||
1494 | Note that magic functions have lowest priority, so if there's a variable |
|
1499 | Note that magic functions have lowest priority, so if there's a variable | |
1495 | whose name collides with that of a magic fn, automagic won't work for |
|
1500 | whose name collides with that of a magic fn, automagic won't work for | |
1496 | that function (you get the variable instead). However, if you delete the |
|
1501 | that function (you get the variable instead). However, if you delete the | |
1497 | variable (del var), the previously shadowed magic function becomes |
|
1502 | variable (del var), the previously shadowed magic function becomes | |
1498 | visible to automagic again. |
|
1503 | visible to automagic again. | |
1499 |
|
1504 | |||
1500 |
|
1505 | |||
1501 | %bg: Run a job in the background, in a separate thread. |
|
1506 | %bg: Run a job in the background, in a separate thread. | |
1502 |
|
1507 | |||
1503 | For example, |
|
1508 | For example, | |
1504 |
|
1509 | |||
1505 | %bg myfunc(x,y,z=1) |
|
1510 | %bg myfunc(x,y,z=1) | |
1506 |
|
1511 | |||
1507 | will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the |
|
1512 | will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the | |
1508 | execution starts, a message will be printed indicating the job number. |
|
1513 | execution starts, a message will be printed indicating the job number. | |
1509 | If your job number is 5, you can use |
|
1514 | If your job number is 5, you can use | |
1510 |
|
1515 | |||
1511 | myvar = jobs.result(5) or myvar = jobs[5].result |
|
1516 | myvar = jobs.result(5) or myvar = jobs[5].result | |
1512 |
|
1517 | |||
1513 | to assign this result to variable 'myvar'. |
|
1518 | to assign this result to variable 'myvar'. | |
1514 |
|
1519 | |||
1515 | IPython has a job manager, accessible via the 'jobs' object. You can |
|
1520 | IPython has a job manager, accessible via the 'jobs' object. You can | |
1516 | type jobs? to get more information about it, and use jobs.<TAB> to see |
|
1521 | type jobs? to get more information about it, and use jobs.<TAB> to see | |
1517 | its attributes. All attributes not starting with an underscore are meant |
|
1522 | its attributes. All attributes not starting with an underscore are meant | |
1518 | for public use. |
|
1523 | for public use. | |
1519 |
|
1524 | |||
1520 | In particular, look at the jobs.new() method, which is used to create |
|
1525 | In particular, look at the jobs.new() method, which is used to create | |
1521 | new jobs. This magic %bg function is just a convenience wrapper around |
|
1526 | new jobs. This magic %bg function is just a convenience wrapper around | |
1522 | jobs.new(), for expression-based jobs. If you want to create a new job |
|
1527 | jobs.new(), for expression-based jobs. If you want to create a new job | |
1523 | with an explicit function object and arguments, you must call jobs.new() |
|
1528 | with an explicit function object and arguments, you must call jobs.new() | |
1524 | directly. |
|
1529 | directly. | |
1525 |
|
1530 | |||
1526 | The jobs.new docstring also describes in detail several important |
|
1531 | The jobs.new docstring also describes in detail several important | |
1527 | caveats associated with a thread-based model for background job |
|
1532 | caveats associated with a thread-based model for background job | |
1528 | execution. Type jobs.new? for details. |
|
1533 | execution. Type jobs.new? for details. | |
1529 |
|
1534 | |||
1530 | You can check the status of all jobs with jobs.status(). |
|
1535 | You can check the status of all jobs with jobs.status(). | |
1531 |
|
1536 | |||
1532 | The jobs variable is set by IPython into the Python builtin namespace. |
|
1537 | The jobs variable is set by IPython into the Python builtin namespace. | |
1533 | If you ever declare a variable named 'jobs', you will shadow this name. |
|
1538 | If you ever declare a variable named 'jobs', you will shadow this name. | |
1534 | You can either delete your global jobs variable to regain access to the |
|
1539 | You can either delete your global jobs variable to regain access to the | |
1535 | job manager, or make a new name and assign it manually to the manager |
|
1540 | job manager, or make a new name and assign it manually to the manager | |
1536 | (stored in IPython's namespace). For example, to assign the job manager |
|
1541 | (stored in IPython's namespace). For example, to assign the job manager | |
1537 | to the Jobs name, use: |
|
1542 | to the Jobs name, use: | |
1538 |
|
1543 | |||
1539 | Jobs = __builtins__.jobs |
|
1544 | Jobs = __builtins__.jobs | |
1540 |
|
1545 | |||
1541 |
|
1546 | |||
1542 | %bookmark: Manage IPython's bookmark system. |
|
1547 | %bookmark: Manage IPython's bookmark system. | |
1543 |
|
1548 | |||
1544 | %bookmark <name> - set bookmark to current dir %bookmark <name> <dir> - |
|
1549 | %bookmark <name> - set bookmark to current dir %bookmark <name> <dir> - | |
1545 | set bookmark to <dir> %bookmark -l - list all bookmarks %bookmark -d |
|
1550 | set bookmark to <dir> %bookmark -l - list all bookmarks %bookmark -d | |
1546 | <name> - remove bookmark %bookmark -r - remove all bookmarks |
|
1551 | <name> - remove bookmark %bookmark -r - remove all bookmarks | |
1547 |
|
1552 | |||
1548 | You can later on access a bookmarked folder with: %cd -b <name> or |
|
1553 | You can later on access a bookmarked folder with: %cd -b <name> or | |
1549 | simply '%cd <name>' if there is no directory called <name> AND there is |
|
1554 | simply '%cd <name>' if there is no directory called <name> AND there is | |
1550 | such a bookmark defined. |
|
1555 | such a bookmark defined. | |
1551 |
|
1556 | |||
1552 | Your bookmarks persist through IPython sessions, but they are associated |
|
1557 | Your bookmarks persist through IPython sessions, but they are associated | |
1553 | with each profile. |
|
1558 | with each profile. | |
1554 |
|
1559 | |||
1555 |
|
1560 | |||
1556 | %cd: Change the current working directory. |
|
1561 | %cd: Change the current working directory. | |
1557 |
|
1562 | |||
1558 | This command automatically maintains an internal list of directories you |
|
1563 | This command automatically maintains an internal list of directories you | |
1559 | visit during your IPython session, in the variable _dh. The command |
|
1564 | visit during your IPython session, in the variable _dh. The command | |
1560 | %dhist shows this history nicely formatted. You can also do 'cd -<tab>' |
|
1565 | %dhist shows this history nicely formatted. You can also do 'cd -<tab>' | |
1561 | to see directory history conveniently. |
|
1566 | to see directory history conveniently. | |
1562 |
|
1567 | |||
1563 | Usage: |
|
1568 | Usage: | |
1564 |
|
1569 | |||
1565 | cd 'dir': changes to directory 'dir'. |
|
1570 | cd 'dir': changes to directory 'dir'. | |
1566 |
|
1571 | |||
1567 | cd -: changes to the last visited directory. |
|
1572 | cd -: changes to the last visited directory. | |
1568 |
|
1573 | |||
1569 | cd -<n>: changes to the n-th directory in the directory history. |
|
1574 | cd -<n>: changes to the n-th directory in the directory history. | |
1570 |
|
1575 | |||
1571 | cd -b <bookmark_name>: jump to a bookmark set by %bookmark (note: cd |
|
1576 | cd -b <bookmark_name>: jump to a bookmark set by %bookmark (note: cd | |
1572 | <bookmark_name> is enough if there is no directory <bookmark_name>, but |
|
1577 | <bookmark_name> is enough if there is no directory <bookmark_name>, but | |
1573 | a bookmark with the name exists.) 'cd -b <tab>' allows you to |
|
1578 | a bookmark with the name exists.) 'cd -b <tab>' allows you to | |
1574 | tab-complete bookmark names. |
|
1579 | tab-complete bookmark names. | |
1575 |
|
1580 | |||
1576 | Options: |
|
1581 | Options: | |
1577 |
|
1582 | |||
1578 | -q: quiet. Do not print the working directory after the cd command is |
|
1583 | -q: quiet. Do not print the working directory after the cd command is | |
1579 | executed. By default IPython's cd command does print this directory, |
|
1584 | executed. By default IPython's cd command does print this directory, | |
1580 | since the default prompts do not display path information. |
|
1585 | since the default prompts do not display path information. | |
1581 |
|
1586 | |||
1582 | Note that !cd doesn't work for this purpose because the shell where |
|
1587 | Note that !cd doesn't work for this purpose because the shell where | |
1583 | !command runs is immediately discarded after executing 'command'. |
|
1588 | !command runs is immediately discarded after executing 'command'. | |
1584 |
|
1589 | |||
1585 |
|
1590 | |||
1586 | %color_info: Toggle color_info. |
|
1591 | %color_info: Toggle color_info. | |
1587 |
|
1592 | |||
1588 | The color_info configuration parameter controls whether colors are used |
|
1593 | The color_info configuration parameter controls whether colors are used | |
1589 | for displaying object details (by things like %psource, %pfile or the |
|
1594 | for displaying object details (by things like %psource, %pfile or the | |
1590 | '?' system). This function toggles this value with each call. |
|
1595 | '?' system). This function toggles this value with each call. | |
1591 |
|
1596 | |||
1592 | Note that unless you have a fairly recent pager (less works better than |
|
1597 | Note that unless you have a fairly recent pager (less works better than | |
1593 | more) in your system, using colored object information displays will not |
|
1598 | more) in your system, using colored object information displays will not | |
1594 | work properly. Test it and see. |
|
1599 | work properly. Test it and see. | |
1595 |
|
1600 | |||
1596 |
|
1601 | |||
1597 | %colors: Switch color scheme for prompts, info system and exception |
|
1602 | %colors: Switch color scheme for prompts, info system and exception | |
1598 | handlers. |
|
1603 | handlers. | |
1599 |
|
1604 | |||
1600 | Currently implemented schemes: NoColor, Linux, LightBG. |
|
1605 | Currently implemented schemes: NoColor, Linux, LightBG. | |
1601 |
|
1606 | |||
1602 | Color scheme names are not case-sensitive. |
|
1607 | Color scheme names are not case-sensitive. | |
1603 |
|
1608 | |||
1604 |
|
1609 | |||
1605 | %cpaste: Allows you to paste & execute a pre-formatted code block from |
|
1610 | %cpaste: Allows you to paste & execute a pre-formatted code block from | |
1606 | clipboard |
|
1611 | clipboard | |
1607 |
|
1612 | |||
1608 | You must terminate the block with '-' (two minus-signs) alone on the |
|
1613 | You must terminate the block with '-' (two minus-signs) alone on the | |
1609 | line. You can also provide your own sentinel with '%paste -s %%' ('%%' |
|
1614 | line. You can also provide your own sentinel with '%paste -s %%' ('%%' | |
1610 | is the new sentinel for this operation) |
|
1615 | is the new sentinel for this operation) | |
1611 |
|
1616 | |||
1612 | The block is dedented prior to execution to enable execution of method |
|
1617 | The block is dedented prior to execution to enable execution of method | |
1613 | definitions. '>' and '+' characters at the beginning of a line are |
|
1618 | definitions. '>' and '+' characters at the beginning of a line are | |
1614 | ignored, to allow pasting directly from e-mails or diff files. The |
|
1619 | ignored, to allow pasting directly from e-mails or diff files. The | |
1615 | executed block is also assigned to variable named 'pasted_block' for |
|
1620 | executed block is also assigned to variable named 'pasted_block' for | |
1616 | later editing with '%edit pasted_block'. |
|
1621 | later editing with '%edit pasted_block'. | |
1617 |
|
1622 | |||
1618 | You can also pass a variable name as an argument, e.g. '%cpaste foo'. |
|
1623 | You can also pass a variable name as an argument, e.g. '%cpaste foo'. | |
1619 | This assigns the pasted block to variable 'foo' as string, without |
|
1624 | This assigns the pasted block to variable 'foo' as string, without | |
1620 | dedenting or executing it. |
|
1625 | dedenting or executing it. | |
1621 |
|
1626 | |||
1622 | Do not be alarmed by garbled output on Windows (it's a readline bug). |
|
1627 | Do not be alarmed by garbled output on Windows (it's a readline bug). | |
1623 | Just press enter and type - (and press enter again) and the block will |
|
1628 | Just press enter and type - (and press enter again) and the block will | |
1624 | be what was just pasted. |
|
1629 | be what was just pasted. | |
1625 |
|
1630 | |||
1626 | IPython statements (magics, shell escapes) are not supported (yet). |
|
1631 | IPython statements (magics, shell escapes) are not supported (yet). | |
1627 |
|
1632 | |||
1628 |
|
1633 | |||
1629 | %debug: Activate the interactive debugger in post-mortem mode. |
|
1634 | %debug: Activate the interactive debugger in post-mortem mode. | |
1630 |
|
1635 | |||
1631 | If an exception has just occurred, this lets you inspect its stack |
|
1636 | If an exception has just occurred, this lets you inspect its stack | |
1632 | frames interactively. Note that this will always work only on the last |
|
1637 | frames interactively. Note that this will always work only on the last | |
1633 | traceback that occurred, so you must call this quickly after an |
|
1638 | traceback that occurred, so you must call this quickly after an | |
1634 | exception that you wish to inspect has fired, because if another one |
|
1639 | exception that you wish to inspect has fired, because if another one | |
1635 | occurs, it clobbers the previous one. |
|
1640 | occurs, it clobbers the previous one. | |
1636 |
|
1641 | |||
1637 | If you want IPython to automatically do this on every exception, see the |
|
1642 | If you want IPython to automatically do this on every exception, see the | |
1638 | %pdb magic for more details. |
|
1643 | %pdb magic for more details. | |
1639 |
|
1644 | |||
1640 |
|
1645 | |||
1641 | %dhist: Print your history of visited directories. |
|
1646 | %dhist: Print your history of visited directories. | |
1642 |
|
1647 | |||
1643 | %dhist -> print full history |
|
1648 | %dhist -> print full history | |
1644 | %dhist n -> print last n entries only |
|
1649 | %dhist n -> print last n entries only | |
1645 | %dhist n1 n2 -> print entries between n1 and n2 (n1 not included) |
|
1650 | %dhist n1 n2 -> print entries between n1 and n2 (n1 not included) | |
1646 |
|
1651 | |||
1647 | This history is automatically maintained by the %cd command, and always |
|
1652 | This history is automatically maintained by the %cd command, and always | |
1648 | available as the global list variable _dh. You can use %cd -<n> to go to |
|
1653 | available as the global list variable _dh. You can use %cd -<n> to go to | |
1649 | directory number <n>. |
|
1654 | directory number <n>. | |
1650 |
|
1655 | |||
1651 | Note that most of time, you should view directory history by entering cd |
|
1656 | Note that most of time, you should view directory history by entering cd | |
1652 | -<TAB>. |
|
1657 | -<TAB>. | |
1653 |
|
1658 | |||
1654 |
|
1659 | |||
1655 | %dirs: Return the current directory stack. |
|
1660 | %dirs: Return the current directory stack. | |
1656 |
|
1661 | |||
1657 |
|
1662 | |||
1658 | %doctest_mode: Toggle doctest mode on and off. |
|
1663 | %doctest_mode: Toggle doctest mode on and off. | |
1659 |
|
1664 | |||
1660 | This mode allows you to toggle the prompt behavior between normal |
|
1665 | This mode allows you to toggle the prompt behavior between normal | |
1661 | IPython prompts and ones that are as similar to the default IPython |
|
1666 | IPython prompts and ones that are as similar to the default IPython | |
1662 | interpreter as possible. |
|
1667 | interpreter as possible. | |
1663 |
|
1668 | |||
1664 | It also supports the pasting of code snippets that have leading '»>' and |
|
1669 | It also supports the pasting of code snippets that have leading '»>' and | |
1665 | '...' prompts in them. This means that you can paste doctests from files |
|
1670 | '...' prompts in them. This means that you can paste doctests from files | |
1666 | or docstrings (even if they have leading whitespace), and the code will |
|
1671 | or docstrings (even if they have leading whitespace), and the code will | |
1667 | execute correctly. You can then use '%history -tn' to see the translated |
|
1672 | execute correctly. You can then use '%history -tn' to see the translated | |
1668 | history without line numbers; this will give you the input after removal |
|
1673 | history without line numbers; this will give you the input after removal | |
1669 | of all the leading prompts and whitespace, which can be pasted back into |
|
1674 | of all the leading prompts and whitespace, which can be pasted back into | |
1670 | an editor. |
|
1675 | an editor. | |
1671 |
|
1676 | |||
1672 | With these features, you can switch into this mode easily whenever you |
|
1677 | With these features, you can switch into this mode easily whenever you | |
1673 | need to do testing and changes to doctests, without having to leave your |
|
1678 | need to do testing and changes to doctests, without having to leave your | |
1674 | existing IPython session. |
|
1679 | existing IPython session. | |
1675 |
|
1680 | |||
1676 |
|
1681 | |||
1677 | %ed: Alias to %edit. |
|
1682 | %ed: Alias to %edit. | |
1678 |
|
1683 | |||
1679 |
|
1684 | |||
1680 | %edit: Bring up an editor and execute the resulting code. |
|
1685 | %edit: Bring up an editor and execute the resulting code. | |
1681 |
|
1686 | |||
1682 | Usage: %edit [options] [args] |
|
1687 | Usage: %edit [options] [args] | |
1683 |
|
1688 | |||
1684 | %edit runs IPython's editor hook. The default version of this hook is |
|
1689 | %edit runs IPython's editor hook. The default version of this hook is | |
1685 | set to call the __IPYTHON__.rc.editor command. This is read from your |
|
1690 | set to call the __IPYTHON__.rc.editor command. This is read from your | |
1686 | environment variable $EDITOR. If this isn't found, it will default to vi |
|
1691 | environment variable $EDITOR. If this isn't found, it will default to vi | |
1687 | under Linux/Unix and to notepad under Windows. See the end of this |
|
1692 | under Linux/Unix and to notepad under Windows. See the end of this | |
1688 | docstring for how to change the editor hook. |
|
1693 | docstring for how to change the editor hook. | |
1689 |
|
1694 | |||
1690 | You can also set the value of this editor via the command line option |
|
1695 | You can also set the value of this editor via the command line option | |
1691 | '-editor' or in your ipythonrc file. This is useful if you wish to use |
|
1696 | '-editor' or in your ipythonrc file. This is useful if you wish to use | |
1692 | specifically for IPython an editor different from your typical default |
|
1697 | specifically for IPython an editor different from your typical default | |
1693 | (and for Windows users who typically don't set environment variables). |
|
1698 | (and for Windows users who typically don't set environment variables). | |
1694 |
|
1699 | |||
1695 | This command allows you to conveniently edit multi-line code right in |
|
1700 | This command allows you to conveniently edit multi-line code right in | |
1696 | your IPython session. |
|
1701 | your IPython session. | |
1697 |
|
1702 | |||
1698 | If called without arguments, %edit opens up an empty editor with a |
|
1703 | If called without arguments, %edit opens up an empty editor with a | |
1699 | temporary file and will execute the contents of this file when you close |
|
1704 | temporary file and will execute the contents of this file when you close | |
1700 | it (don't forget to save it!). |
|
1705 | it (don't forget to save it!). | |
1701 |
|
1706 | |||
1702 | Options: |
|
1707 | Options: | |
1703 |
|
1708 | |||
1704 | -n <number>: open the editor at a specified line number. By default, the |
|
1709 | -n <number>: open the editor at a specified line number. By default, the | |
1705 | IPython editor hook uses the unix syntax 'editor +N filename', but you |
|
1710 | IPython editor hook uses the unix syntax 'editor +N filename', but you | |
1706 | can configure this by providing your own modified hook if your favorite |
|
1711 | can configure this by providing your own modified hook if your favorite | |
1707 | editor supports line-number specifications with a different syntax. |
|
1712 | editor supports line-number specifications with a different syntax. | |
1708 |
|
1713 | |||
1709 | -p: this will call the editor with the same data as the previous time it |
|
1714 | -p: this will call the editor with the same data as the previous time it | |
1710 | was used, regardless of how long ago (in your current session) it was. |
|
1715 | was used, regardless of how long ago (in your current session) it was. | |
1711 |
|
1716 | |||
1712 | -r: use 'raw' input. This option only applies to input taken from the |
|
1717 | -r: use 'raw' input. This option only applies to input taken from the | |
1713 | user's history. By default, the 'processed' history is used, so that |
|
1718 | user's history. By default, the 'processed' history is used, so that | |
1714 | magics are loaded in their transformed version to valid Python. If this |
|
1719 | magics are loaded in their transformed version to valid Python. If this | |
1715 | option is given, the raw input as typed as the command line is used |
|
1720 | option is given, the raw input as typed as the command line is used | |
1716 | instead. When you exit the editor, it will be executed by IPython's own |
|
1721 | instead. When you exit the editor, it will be executed by IPython's own | |
1717 | processor. |
|
1722 | processor. | |
1718 |
|
1723 | |||
1719 | -x: do not execute the edited code immediately upon exit. This is mainly |
|
1724 | -x: do not execute the edited code immediately upon exit. This is mainly | |
1720 | useful if you are editing programs which need to be called with command |
|
1725 | useful if you are editing programs which need to be called with command | |
1721 | line arguments, which you can then do using %run. |
|
1726 | line arguments, which you can then do using %run. | |
1722 |
|
1727 | |||
1723 | Arguments: |
|
1728 | Arguments: | |
1724 |
|
1729 | |||
1725 | If arguments are given, the following possibilites exist: |
|
1730 | If arguments are given, the following possibilites exist: | |
1726 |
|
1731 | |||
1727 | - The arguments are numbers or pairs of dash-separated numbers (like 1 |
|
1732 | - The arguments are numbers or pairs of dash-separated numbers (like 1 | |
1728 | 4-8 9). These are interpreted as lines of previous input to be loaded |
|
1733 | 4-8 9). These are interpreted as lines of previous input to be loaded | |
1729 | into the editor. The syntax is the same of the %macro command. |
|
1734 | into the editor. The syntax is the same of the %macro command. | |
1730 |
|
1735 | |||
1731 | - If the argument doesn't start with a number, it is evaluated as a |
|
1736 | - If the argument doesn't start with a number, it is evaluated as a | |
1732 | variable and its contents loaded into the editor. You can thus edit any |
|
1737 | variable and its contents loaded into the editor. You can thus edit any | |
1733 | string which contains python code (including the result of previous edits). |
|
1738 | string which contains python code (including the result of previous edits). | |
1734 |
|
1739 | |||
1735 | - If the argument is the name of an object (other than a string), |
|
1740 | - If the argument is the name of an object (other than a string), | |
1736 | IPython will try to locate the file where it was defined and open the |
|
1741 | IPython will try to locate the file where it was defined and open the | |
1737 | editor at the point where it is defined. You can use '%edit function' to |
|
1742 | editor at the point where it is defined. You can use '%edit function' to | |
1738 | load an editor exactly at the point where 'function' is defined, edit it |
|
1743 | load an editor exactly at the point where 'function' is defined, edit it | |
1739 | and have the file be executed automatically. |
|
1744 | and have the file be executed automatically. | |
1740 |
|
1745 | |||
1741 | If the object is a macro (see %macro for details), this opens up your |
|
1746 | If the object is a macro (see %macro for details), this opens up your | |
1742 | specified editor with a temporary file containing the macro's data. Upon |
|
1747 | specified editor with a temporary file containing the macro's data. Upon | |
1743 | exit, the macro is reloaded with the contents of the file. |
|
1748 | exit, the macro is reloaded with the contents of the file. | |
1744 |
|
1749 | |||
1745 | Note: opening at an exact line is only supported under Unix, and some |
|
1750 | Note: opening at an exact line is only supported under Unix, and some | |
1746 | editors (like kedit and gedit up to Gnome 2.8) do not understand the |
|
1751 | editors (like kedit and gedit up to Gnome 2.8) do not understand the | |
1747 | '+NUMBER' parameter necessary for this feature. Good editors like |
|
1752 | '+NUMBER' parameter necessary for this feature. Good editors like | |
1748 | (X)Emacs, vi, jed, pico and joe all do. |
|
1753 | (X)Emacs, vi, jed, pico and joe all do. | |
1749 |
|
1754 | |||
1750 | If the argument is not found as a variable, IPython will look for a |
|
1755 | If the argument is not found as a variable, IPython will look for a | |
1751 | file with that name (adding .py if necessary) and load it into the |
|
1756 | file with that name (adding .py if necessary) and load it into the | |
1752 | editor. It will execute its contents with execfile() when you exit, |
|
1757 | editor. It will execute its contents with execfile() when you exit, | |
1753 | loading any code in the file into your interactive namespace. |
|
1758 | loading any code in the file into your interactive namespace. | |
1754 |
|
1759 | |||
1755 | After executing your code, %edit will return as output the code you |
|
1760 | After executing your code, %edit will return as output the code you | |
1756 | typed in the editor (except when it was an existing file). This way you |
|
1761 | typed in the editor (except when it was an existing file). This way you | |
1757 | can reload the code in further invocations of %edit as a variable, via |
|
1762 | can reload the code in further invocations of %edit as a variable, via | |
1758 | _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of the |
|
1763 | _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of the | |
1759 | output. |
|
1764 | output. | |
1760 |
|
1765 | |||
1761 | Note that %edit is also available through the alias %ed. |
|
1766 | Note that %edit is also available through the alias %ed. | |
1762 |
|
1767 | |||
1763 | This is an example of creating a simple function inside the editor and |
|
1768 | This is an example of creating a simple function inside the editor and | |
1764 | then modifying it. First, start up the editor:: |
|
1769 | then modifying it. First, start up the editor:: | |
1765 |
|
1770 | |||
1766 | In [1]: ed |
|
1771 | In [1]: ed | |
1767 | Editing... done. Executing edited code... |
|
1772 | Editing... done. Executing edited code... | |
1768 | Out[1]: 'def foo():\n print "foo() was defined in an editing session"\n' |
|
1773 | Out[1]: 'def foo():\n print "foo() was defined in an editing session"\n' | |
1769 |
|
1774 | |||
1770 | We can then call the function foo(): |
|
1775 | We can then call the function foo(): | |
1771 |
|
1776 | |||
1772 | In [2]: foo() |
|
1777 | In [2]: foo() | |
1773 | foo() was defined in an editing session |
|
1778 | foo() was defined in an editing session | |
1774 |
|
1779 | |||
1775 | Now we edit foo. IPython automatically loads the editor with the |
|
1780 | Now we edit foo. IPython automatically loads the editor with the | |
1776 | (temporary) file where foo() was previously defined: |
|
1781 | (temporary) file where foo() was previously defined: | |
1777 |
|
1782 | |||
1778 | In [3]: ed foo |
|
1783 | In [3]: ed foo | |
1779 | Editing... done. Executing edited code... |
|
1784 | Editing... done. Executing edited code... | |
1780 |
|
1785 | |||
1781 | And if we call foo() again we get the modified version: |
|
1786 | And if we call foo() again we get the modified version: | |
1782 |
|
1787 | |||
1783 | In [4]: foo() |
|
1788 | In [4]: foo() | |
1784 | foo() has now been changed! |
|
1789 | foo() has now been changed! | |
1785 |
|
1790 | |||
1786 | Here is an example of how to edit a code snippet successive times. First |
|
1791 | Here is an example of how to edit a code snippet successive times. First | |
1787 | we call the editor: |
|
1792 | we call the editor: | |
1788 |
|
1793 | |||
1789 | In [8]: ed |
|
1794 | In [8]: ed | |
1790 | Editing... done. Executing edited code... |
|
1795 | Editing... done. Executing edited code... | |
1791 | hello |
|
1796 | hello | |
1792 | Out[8]: "print 'hello'\n" |
|
1797 | Out[8]: "print 'hello'\n" | |
1793 |
|
1798 | |||
1794 | Now we call it again with the previous output (stored in _): |
|
1799 | Now we call it again with the previous output (stored in _): | |
1795 |
|
1800 | |||
1796 | In [9]: ed _ |
|
1801 | In [9]: ed _ | |
1797 | Editing... done. Executing edited code... |
|
1802 | Editing... done. Executing edited code... | |
1798 | hello world |
|
1803 | hello world | |
1799 | Out[9]: "print 'hello world'\n" |
|
1804 | Out[9]: "print 'hello world'\n" | |
1800 |
|
1805 | |||
1801 | Now we call it with the output #8 (stored in _8, also as Out[8]): |
|
1806 | Now we call it with the output #8 (stored in _8, also as Out[8]): | |
1802 |
|
1807 | |||
1803 | In [10]: ed _8 |
|
1808 | In [10]: ed _8 | |
1804 | Editing... done. Executing edited code... |
|
1809 | Editing... done. Executing edited code... | |
1805 | hello again |
|
1810 | hello again | |
1806 | Out[10]: "print 'hello again'\n" |
|
1811 | Out[10]: "print 'hello again'\n" | |
1807 |
|
1812 | |||
1808 | Changing the default editor hook: |
|
1813 | Changing the default editor hook: | |
1809 |
|
1814 | |||
1810 | If you wish to write your own editor hook, you can put it in a |
|
1815 | If you wish to write your own editor hook, you can put it in a | |
1811 | configuration file which you load at startup time. The default hook is |
|
1816 | configuration file which you load at startup time. The default hook is | |
1812 | defined in the IPython.hooks module, and you can use that as a starting |
|
1817 | defined in the IPython.hooks module, and you can use that as a starting | |
1813 | example for further modifications. That file also has general |
|
1818 | example for further modifications. That file also has general | |
1814 | instructions on how to set a new hook for use once you've defined it. |
|
1819 | instructions on how to set a new hook for use once you've defined it. | |
1815 |
|
1820 | |||
1816 |
|
1821 | |||
1817 | %env: List environment variables. |
|
1822 | %env: List environment variables. | |
1818 |
|
1823 | |||
1819 |
|
1824 | |||
1820 | %exit: Exit IPython, confirming if configured to do so. |
|
1825 | %exit: Exit IPython, confirming if configured to do so. | |
1821 |
|
1826 | |||
1822 | You can configure whether IPython asks for confirmation upon exit by |
|
1827 | You can configure whether IPython asks for confirmation upon exit by | |
1823 | setting the confirm_exit flag in the ipythonrc file. |
|
1828 | setting the confirm_exit flag in the ipythonrc file. | |
1824 |
|
1829 | |||
1825 |
|
1830 | |||
1826 | %logoff: Temporarily stop logging. |
|
1831 | %logoff: Temporarily stop logging. | |
1827 |
|
1832 | |||
1828 | You must have previously started logging. |
|
1833 | You must have previously started logging. | |
1829 |
|
1834 | |||
1830 |
|
1835 | |||
1831 | %logon: Restart logging. |
|
1836 | %logon: Restart logging. | |
1832 |
|
1837 | |||
1833 | This function is for restarting logging which you've temporarily stopped |
|
1838 | This function is for restarting logging which you've temporarily stopped | |
1834 | with %logoff. For starting logging for the first time, you must use the |
|
1839 | with %logoff. For starting logging for the first time, you must use the | |
1835 | %logstart function, which allows you to specify an optional log filename. |
|
1840 | %logstart function, which allows you to specify an optional log filename. | |
1836 |
|
1841 | |||
1837 |
|
1842 | |||
1838 | %logstart: Start logging anywhere in a session. |
|
1843 | %logstart: Start logging anywhere in a session. | |
1839 |
|
1844 | |||
1840 | %logstart [-o|-r|-t] [log_name [log_mode]] |
|
1845 | %logstart [-o|-r|-t] [log_name [log_mode]] | |
1841 |
|
1846 | |||
1842 | If no name is given, it defaults to a file named 'ipython_log.py' in |
|
1847 | If no name is given, it defaults to a file named 'ipython_log.py' in | |
1843 | your current directory, in 'rotate' mode (see below). |
|
1848 | your current directory, in 'rotate' mode (see below). | |
1844 |
|
1849 | |||
1845 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your |
|
1850 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your | |
1846 | history up to that point and then continues logging. |
|
1851 | history up to that point and then continues logging. | |
1847 |
|
1852 | |||
1848 | %logstart takes a second optional parameter: logging mode. This can be |
|
1853 | %logstart takes a second optional parameter: logging mode. This can be | |
1849 | one of (note that the modes are given unquoted): |
|
1854 | one of (note that the modes are given unquoted): | |
1850 | append: well, that says it. |
|
1855 | append: well, that says it. | |
1851 | backup: rename (if exists) to name and start name. |
|
1856 | backup: rename (if exists) to name and start name. | |
1852 | global: single logfile in your home dir, appended to. |
|
1857 | global: single logfile in your home dir, appended to. | |
1853 | over : overwrite existing log. |
|
1858 | over : overwrite existing log. | |
1854 | rotate: create rotating logs name.1 , name.2 , etc. |
|
1859 | rotate: create rotating logs name.1 , name.2 , etc. | |
1855 |
|
1860 | |||
1856 | Options: |
|
1861 | Options: | |
1857 |
|
1862 | |||
1858 | -o: log also IPython's output. In this mode, all commands which generate |
|
1863 | -o: log also IPython's output. In this mode, all commands which generate | |
1859 | an Out[NN] prompt are recorded to the logfile, right after their |
|
1864 | an Out[NN] prompt are recorded to the logfile, right after their | |
1860 | corresponding input line. The output lines are always prepended with a |
|
1865 | corresponding input line. The output lines are always prepended with a | |
1861 | '#[Out]# ' marker, so that the log remains valid Python code. |
|
1866 | '#[Out]# ' marker, so that the log remains valid Python code. | |
1862 |
|
1867 | |||
1863 | Since this marker is always the same, filtering only the output from a |
|
1868 | Since this marker is always the same, filtering only the output from a | |
1864 | log is very easy, using for example a simple awk call: |
|
1869 | log is very easy, using for example a simple awk call: | |
1865 |
|
1870 | |||
1866 | awk -F'# |
|
1871 | awk -F'# | |
1867 |
|
1872 | |||
1868 | \begin{displaymath}Out\end{displaymath} |
|
1873 | \begin{displaymath}Out\end{displaymath} | |
1869 |
|
1874 | |||
1870 | # ' 'if($2) print $2' ipython_log.py |
|
1875 | # ' 'if($2) print $2' ipython_log.py | |
1871 |
|
1876 | |||
1872 | -r: log 'raw' input. Normally, IPython's logs contain the processed |
|
1877 | -r: log 'raw' input. Normally, IPython's logs contain the processed | |
1873 | input, so that user lines are logged in their final form, converted into |
|
1878 | input, so that user lines are logged in their final form, converted into | |
1874 | valid Python. For example, %Exit is logged as '_ip.magic("Exit"). If the |
|
1879 | valid Python. For example, %Exit is logged as '_ip.magic("Exit"). If the | |
1875 | -r flag is given, all input is logged exactly as typed, with no |
|
1880 | -r flag is given, all input is logged exactly as typed, with no | |
1876 | transformations applied. |
|
1881 | transformations applied. | |
1877 |
|
1882 | |||
1878 | -t: put timestamps before each input line logged (these are put in |
|
1883 | -t: put timestamps before each input line logged (these are put in | |
1879 | comments). |
|
1884 | comments). | |
1880 |
|
1885 | |||
1881 |
|
1886 | |||
1882 | %logstate: Print the status of the logging system. |
|
1887 | %logstate: Print the status of the logging system. | |
1883 |
|
1888 | |||
1884 |
|
1889 | |||
1885 | %logstop: Fully stop logging and close log file. |
|
1890 | %logstop: Fully stop logging and close log file. | |
1886 |
|
1891 | |||
1887 | In order to start logging again, a new %logstart call needs to be made, |
|
1892 | In order to start logging again, a new %logstart call needs to be made, | |
1888 | possibly (though not necessarily) with a new filename, mode and other |
|
1893 | possibly (though not necessarily) with a new filename, mode and other | |
1889 | options. |
|
1894 | options. | |
1890 |
|
1895 | |||
1891 |
|
1896 | |||
1892 | %lsmagic: List currently available magic functions. |
|
1897 | %lsmagic: List currently available magic functions. | |
1893 |
|
1898 | |||
1894 |
|
1899 | |||
1895 | %macro: Define a set of input lines as a macro for future re-execution. |
|
1900 | %macro: Define a set of input lines as a macro for future re-execution. | |
1896 |
|
1901 | |||
1897 | Usage: |
|
1902 | Usage: | |
1898 | %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ... |
|
1903 | %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ... | |
1899 |
|
1904 | |||
1900 | Options: |
|
1905 | Options: | |
1901 |
|
1906 | |||
1902 | -r: use 'raw' input. By default, the 'processed' history is used, so |
|
1907 | -r: use 'raw' input. By default, the 'processed' history is used, so | |
1903 | that magics are loaded in their transformed version to valid Python. If |
|
1908 | that magics are loaded in their transformed version to valid Python. If | |
1904 | this option is given, the raw input as typed as the command line is used |
|
1909 | this option is given, the raw input as typed as the command line is used | |
1905 | instead. |
|
1910 | instead. | |
1906 |
|
1911 | |||
1907 | This will define a global variable called 'name' which is a string made |
|
1912 | This will define a global variable called 'name' which is a string made | |
1908 | of joining the slices and lines you specify (n1,n2,... numbers above) |
|
1913 | of joining the slices and lines you specify (n1,n2,... numbers above) | |
1909 | from your input history into a single string. This variable acts like an |
|
1914 | from your input history into a single string. This variable acts like an | |
1910 | automatic function which re-executes those lines as if you had typed |
|
1915 | automatic function which re-executes those lines as if you had typed | |
1911 | them. You just type 'name' at the prompt and the code executes. |
|
1916 | them. You just type 'name' at the prompt and the code executes. | |
1912 |
|
1917 | |||
1913 | The notation for indicating number ranges is: n1-n2 means 'use line |
|
1918 | The notation for indicating number ranges is: n1-n2 means 'use line | |
1914 | numbers n1,...n2' (the endpoint is included). That is, '5-7' means using |
|
1919 | numbers n1,...n2' (the endpoint is included). That is, '5-7' means using | |
1915 | the lines numbered 5,6 and 7. |
|
1920 | the lines numbered 5,6 and 7. | |
1916 |
|
1921 | |||
1917 | Note: as a 'hidden' feature, you can also use traditional python slice |
|
1922 | Note: as a 'hidden' feature, you can also use traditional python slice | |
1918 | notation, where N:M means numbers N through M-1. |
|
1923 | notation, where N:M means numbers N through M-1. | |
1919 |
|
1924 | |||
1920 | For example, if your history contains (%hist prints it): |
|
1925 | For example, if your history contains (%hist prints it): | |
1921 |
|
1926 | |||
1922 | 44: x=1 |
|
1927 | 44: x=1 | |
1923 | 45: y=3 |
|
1928 | 45: y=3 | |
1924 | 46: z=x+y |
|
1929 | 46: z=x+y | |
1925 | 47: print x |
|
1930 | 47: print x | |
1926 | 48: a=5 |
|
1931 | 48: a=5 | |
1927 | 49: print 'x',x,'y',y |
|
1932 | 49: print 'x',x,'y',y | |
1928 |
|
1933 | |||
1929 | you can create a macro with lines 44 through 47 (included) and line 49 |
|
1934 | you can create a macro with lines 44 through 47 (included) and line 49 | |
1930 | called my_macro with: |
|
1935 | called my_macro with: | |
1931 |
|
1936 | |||
1932 | In [51]: %macro my_macro 44-47 49 |
|
1937 | In [51]: %macro my_macro 44-47 49 | |
1933 |
|
1938 | |||
1934 | Now, typing 'my_macro' (without quotes) will re-execute all this code in |
|
1939 | Now, typing 'my_macro' (without quotes) will re-execute all this code in | |
1935 | one pass. |
|
1940 | one pass. | |
1936 |
|
1941 | |||
1937 | You don't need to give the line-numbers in order, and any given line |
|
1942 | You don't need to give the line-numbers in order, and any given line | |
1938 | number can appear multiple times. You can assemble macros with any lines |
|
1943 | number can appear multiple times. You can assemble macros with any lines | |
1939 | from your input history in any order. |
|
1944 | from your input history in any order. | |
1940 |
|
1945 | |||
1941 | The macro is a simple object which holds its value in an attribute, but |
|
1946 | The macro is a simple object which holds its value in an attribute, but | |
1942 | IPython's display system checks for macros and executes them as code |
|
1947 | IPython's display system checks for macros and executes them as code | |
1943 | instead of printing them when you type their name. |
|
1948 | instead of printing them when you type their name. | |
1944 |
|
1949 | |||
1945 | You can view a macro's contents by explicitly printing it with: |
|
1950 | You can view a macro's contents by explicitly printing it with: | |
1946 |
|
1951 | |||
1947 | 'print macro_name'. |
|
1952 | 'print macro_name'. | |
1948 |
|
1953 | |||
1949 | For one-off cases which DON'T contain magic function calls in them you |
|
1954 | For one-off cases which DON'T contain magic function calls in them you | |
1950 | can obtain similar results by explicitly executing slices from your |
|
1955 | can obtain similar results by explicitly executing slices from your | |
1951 | input history with: |
|
1956 | input history with: | |
1952 |
|
1957 | |||
1953 | In [60]: exec In[44:48]+In[49] |
|
1958 | In [60]: exec In[44:48]+In[49] | |
1954 |
|
1959 | |||
1955 |
|
1960 | |||
1956 | %magic: Print information about the magic function system. |
|
1961 | %magic: Print information about the magic function system. | |
1957 |
|
1962 | |||
1958 |
|
1963 | |||
1959 | %page: Pretty print the object and display it through a pager. |
|
1964 | %page: Pretty print the object and display it through a pager. | |
1960 |
|
1965 | |||
1961 | %page [options] OBJECT |
|
1966 | %page [options] OBJECT | |
1962 |
|
1967 | |||
1963 | If no object is given, use _ (last output). |
|
1968 | If no object is given, use _ (last output). | |
1964 |
|
1969 | |||
1965 | Options: |
|
1970 | Options: | |
1966 |
|
1971 | |||
1967 | -r: page str(object), don't pretty-print it. |
|
1972 | -r: page str(object), don't pretty-print it. | |
1968 |
|
1973 | |||
1969 |
|
1974 | |||
1970 | %pdb: Control the automatic calling of the pdb interactive debugger. |
|
1975 | %pdb: Control the automatic calling of the pdb interactive debugger. | |
1971 |
|
1976 | |||
1972 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without |
|
1977 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without | |
1973 | argument it works as a toggle. |
|
1978 | argument it works as a toggle. | |
1974 |
|
1979 | |||
1975 | When an exception is triggered, IPython can optionally call the |
|
1980 | When an exception is triggered, IPython can optionally call the | |
1976 | interactive pdb debugger after the traceback printout. %pdb toggles this |
|
1981 | interactive pdb debugger after the traceback printout. %pdb toggles this | |
1977 | feature on and off. |
|
1982 | feature on and off. | |
1978 |
|
1983 | |||
1979 | The initial state of this feature is set in your ipythonrc configuration |
|
1984 | The initial state of this feature is set in your ipythonrc configuration | |
1980 | file (the variable is called 'pdb'). |
|
1985 | file (the variable is called 'pdb'). | |
1981 |
|
1986 | |||
1982 | If you want to just activate the debugger AFTER an exception has fired, |
|
1987 | If you want to just activate the debugger AFTER an exception has fired, | |
1983 | without having to type '%pdb on' and rerunning your code, you can use |
|
1988 | without having to type '%pdb on' and rerunning your code, you can use | |
1984 | the %debug magic. |
|
1989 | the %debug magic. | |
1985 |
|
1990 | |||
1986 |
|
1991 | |||
1987 | %pdef: Print the definition header for any callable object. |
|
1992 | %pdef: Print the definition header for any callable object. | |
1988 |
|
1993 | |||
1989 | If the object is a class, print the constructor information. |
|
1994 | If the object is a class, print the constructor information. | |
1990 |
|
1995 | |||
1991 |
|
1996 | |||
1992 | %pdoc: Print the docstring for an object. |
|
1997 | %pdoc: Print the docstring for an object. | |
1993 |
|
1998 | |||
1994 | If the given object is a class, it will print both the class and the |
|
1999 | If the given object is a class, it will print both the class and the | |
1995 | constructor docstrings. |
|
2000 | constructor docstrings. | |
1996 |
|
2001 | |||
1997 |
|
2002 | |||
1998 | %pfile: Print (or run through pager) the file where an object is defined. |
|
2003 | %pfile: Print (or run through pager) the file where an object is defined. | |
1999 |
|
2004 | |||
2000 | The file opens at the line where the object definition begins. IPython |
|
2005 | The file opens at the line where the object definition begins. IPython | |
2001 | will honor the environment variable PAGER if set, and otherwise will do |
|
2006 | will honor the environment variable PAGER if set, and otherwise will do | |
2002 | its best to print the file in a convenient form. |
|
2007 | its best to print the file in a convenient form. | |
2003 |
|
2008 | |||
2004 | If the given argument is not an object currently defined, IPython will |
|
2009 | If the given argument is not an object currently defined, IPython will | |
2005 | try to interpret it as a filename (automatically adding a .py extension |
|
2010 | try to interpret it as a filename (automatically adding a .py extension | |
2006 | if needed). You can thus use %pfile as a syntax highlighting code viewer. |
|
2011 | if needed). You can thus use %pfile as a syntax highlighting code viewer. | |
2007 |
|
2012 | |||
2008 |
|
2013 | |||
2009 | %pinfo: Provide detailed information about an object. |
|
2014 | %pinfo: Provide detailed information about an object. | |
2010 |
|
2015 | |||
2011 | '%pinfo object' is just a synonym for object? or ?object. |
|
2016 | '%pinfo object' is just a synonym for object? or ?object. | |
2012 |
|
2017 | |||
2013 |
|
2018 | |||
2014 | %popd: Change to directory popped off the top of the stack. |
|
2019 | %popd: Change to directory popped off the top of the stack. | |
2015 |
|
2020 | |||
2016 |
|
2021 | |||
2017 | %profile: Print your currently active IPyhton profile. |
|
2022 | %profile: Print your currently active IPyhton profile. | |
2018 |
|
2023 | |||
2019 |
|
2024 | |||
2020 | %prun: Run a statement through the python code profiler. |
|
2025 | %prun: Run a statement through the python code profiler. | |
2021 |
|
2026 | |||
2022 | Usage: |
|
2027 | Usage: | |
2023 | %prun [options] statement |
|
2028 | %prun [options] statement | |
2024 |
|
2029 | |||
2025 | The given statement (which doesn't require quote marks) is run via the |
|
2030 | The given statement (which doesn't require quote marks) is run via the | |
2026 | python profiler in a manner similar to the profile.run() function. |
|
2031 | python profiler in a manner similar to the profile.run() function. | |
2027 | Namespaces are internally managed to work correctly; profile.run cannot |
|
2032 | Namespaces are internally managed to work correctly; profile.run cannot | |
2028 | be used in IPython because it makes certain assumptions about namespaces |
|
2033 | be used in IPython because it makes certain assumptions about namespaces | |
2029 | which do not hold under IPython. |
|
2034 | which do not hold under IPython. | |
2030 |
|
2035 | |||
2031 | Options: |
|
2036 | Options: | |
2032 |
|
2037 | |||
2033 | -l <limit>: you can place restrictions on what or how much of the |
|
2038 | -l <limit>: you can place restrictions on what or how much of the | |
2034 | profile gets printed. The limit value can be: |
|
2039 | profile gets printed. The limit value can be: | |
2035 |
|
2040 | |||
2036 | * A string: only information for function names containing this string |
|
2041 | * A string: only information for function names containing this string | |
2037 | is printed. |
|
2042 | is printed. | |
2038 |
|
2043 | |||
2039 | * An integer: only these many lines are printed. |
|
2044 | * An integer: only these many lines are printed. | |
2040 |
|
2045 | |||
2041 | * A float (between 0 and 1): this fraction of the report is printed (for |
|
2046 | * A float (between 0 and 1): this fraction of the report is printed (for | |
2042 | example, use a limit of 0.4 to see the topmost 40% only). |
|
2047 | example, use a limit of 0.4 to see the topmost 40% only). | |
2043 |
|
2048 | |||
2044 | You can combine several limits with repeated use of the option. For |
|
2049 | You can combine several limits with repeated use of the option. For | |
2045 | example, '-l __init__ -l 5' will print only the topmost 5 lines of |
|
2050 | example, '-l __init__ -l 5' will print only the topmost 5 lines of | |
2046 | information about class constructors. |
|
2051 | information about class constructors. | |
2047 |
|
2052 | |||
2048 | -r: return the pstats.Stats object generated by the profiling. This |
|
2053 | -r: return the pstats.Stats object generated by the profiling. This | |
2049 | object has all the information about the profile in it, and you can |
|
2054 | object has all the information about the profile in it, and you can | |
2050 | later use it for further analysis or in other functions. |
|
2055 | later use it for further analysis or in other functions. | |
2051 |
|
2056 | |||
2052 | -s <key>: sort profile by given key. You can provide more than one key |
|
2057 | -s <key>: sort profile by given key. You can provide more than one key | |
2053 | by using the option several times: '-s key1 -s key2 -s key3...'. The |
|
2058 | by using the option several times: '-s key1 -s key2 -s key3...'. The | |
2054 | default sorting key is 'time'. |
|
2059 | default sorting key is 'time'. | |
2055 |
|
2060 | |||
2056 | The following is copied verbatim from the profile documentation |
|
2061 | The following is copied verbatim from the profile documentation | |
2057 | referenced below: |
|
2062 | referenced below: | |
2058 |
|
2063 | |||
2059 | When more than one key is provided, additional keys are used as |
|
2064 | When more than one key is provided, additional keys are used as | |
2060 | secondary criteria when the there is equality in all keys selected |
|
2065 | secondary criteria when the there is equality in all keys selected | |
2061 | before them. |
|
2066 | before them. | |
2062 |
|
2067 | |||
2063 | Abbreviations can be used for any key names, as long as the abbreviation |
|
2068 | Abbreviations can be used for any key names, as long as the abbreviation | |
2064 | is unambiguous. The following are the keys currently defined: |
|
2069 | is unambiguous. The following are the keys currently defined: | |
2065 |
|
2070 | |||
2066 | Valid Arg Meaning |
|
2071 | Valid Arg Meaning | |
2067 | "calls" call count |
|
2072 | "calls" call count | |
2068 | "cumulative" cumulative time |
|
2073 | "cumulative" cumulative time | |
2069 | "file" file name |
|
2074 | "file" file name | |
2070 | "module" file name |
|
2075 | "module" file name | |
2071 | "pcalls" primitive call count |
|
2076 | "pcalls" primitive call count | |
2072 | "line" line number |
|
2077 | "line" line number | |
2073 | "name" function name |
|
2078 | "name" function name | |
2074 | "nfl" name/file/line |
|
2079 | "nfl" name/file/line | |
2075 | "stdname" standard name |
|
2080 | "stdname" standard name | |
2076 | "time" internal time |
|
2081 | "time" internal time | |
2077 |
|
2082 | |||
2078 | Note that all sorts on statistics are in descending order (placing most |
|
2083 | Note that all sorts on statistics are in descending order (placing most | |
2079 | time consuming items first), where as name, file, and line number |
|
2084 | time consuming items first), where as name, file, and line number | |
2080 | searches are in ascending order (i.e., alphabetical). The subtle |
|
2085 | searches are in ascending order (i.e., alphabetical). The subtle | |
2081 | distinction between "nfl" and "stdname" is that the standard name is a |
|
2086 | distinction between "nfl" and "stdname" is that the standard name is a | |
2082 | sort of the name as printed, which means that the embedded line numbers |
|
2087 | sort of the name as printed, which means that the embedded line numbers | |
2083 | get compared in an odd way. For example, lines 3, 20, and 40 would (if |
|
2088 | get compared in an odd way. For example, lines 3, 20, and 40 would (if | |
2084 | the file names were the same) appear in the string order "20" "3" and |
|
2089 | the file names were the same) appear in the string order "20" "3" and | |
2085 | "40". In contrast, "nfl" does a numeric compare of the line numbers. In |
|
2090 | "40". In contrast, "nfl" does a numeric compare of the line numbers. In | |
2086 | fact, sort_stats("nfl") is the same as sort_stats("name", "file", "line"). |
|
2091 | fact, sort_stats("nfl") is the same as sort_stats("name", "file", "line"). | |
2087 |
|
2092 | |||
2088 | -T <filename>: save profile results as shown on screen to a text file. |
|
2093 | -T <filename>: save profile results as shown on screen to a text file. | |
2089 | The profile is still shown on screen. |
|
2094 | The profile is still shown on screen. | |
2090 |
|
2095 | |||
2091 | -D <filename>: save (via dump_stats) profile statistics to given |
|
2096 | -D <filename>: save (via dump_stats) profile statistics to given | |
2092 | filename. This data is in a format understod by the pstats module, and |
|
2097 | filename. This data is in a format understod by the pstats module, and | |
2093 | is generated by a call to the dump_stats() method of profile objects. |
|
2098 | is generated by a call to the dump_stats() method of profile objects. | |
2094 | The profile is still shown on screen. |
|
2099 | The profile is still shown on screen. | |
2095 |
|
2100 | |||
2096 | If you want to run complete programs under the profiler's control, use |
|
2101 | If you want to run complete programs under the profiler's control, use | |
2097 | '%run -p [prof_opts] filename.py [args to program]' where prof_opts |
|
2102 | '%run -p [prof_opts] filename.py [args to program]' where prof_opts | |
2098 | contains profiler specific options as described here. |
|
2103 | contains profiler specific options as described here. | |
2099 |
|
2104 | |||
2100 | You can read the complete documentation for the profile module with: |
|
2105 | You can read the complete documentation for the profile module with: | |
2101 | In [1]: import profile; profile.help() |
|
2106 | In [1]: import profile; profile.help() | |
2102 |
|
2107 | |||
2103 |
|
2108 | |||
2104 | %psearch: Search for object in namespaces by wildcard. |
|
2109 | %psearch: Search for object in namespaces by wildcard. | |
2105 |
|
2110 | |||
2106 | %psearch [options] PATTERN [OBJECT TYPE] |
|
2111 | %psearch [options] PATTERN [OBJECT TYPE] | |
2107 |
|
2112 | |||
2108 | Note: ? can be used as a synonym for %psearch, at the beginning or at |
|
2113 | Note: ? can be used as a synonym for %psearch, at the beginning or at | |
2109 | the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the |
|
2114 | the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the | |
2110 | rest of the command line must be unchanged (options come first), so for |
|
2115 | rest of the command line must be unchanged (options come first), so for | |
2111 | example the following forms are equivalent |
|
2116 | example the following forms are equivalent | |
2112 |
|
2117 | |||
2113 | %psearch -i a* function -i a* function? ?-i a* function |
|
2118 | %psearch -i a* function -i a* function? ?-i a* function | |
2114 |
|
2119 | |||
2115 | Arguments: |
|
2120 | Arguments: | |
2116 |
|
2121 | |||
2117 | PATTERN |
|
2122 | PATTERN | |
2118 |
|
2123 | |||
2119 | where PATTERN is a string containing * as a wildcard similar to its use |
|
2124 | where PATTERN is a string containing * as a wildcard similar to its use | |
2120 | in a shell. The pattern is matched in all namespaces on the search path. |
|
2125 | in a shell. The pattern is matched in all namespaces on the search path. | |
2121 | By default objects starting with a single _ are not matched, many |
|
2126 | By default objects starting with a single _ are not matched, many | |
2122 | IPython generated objects have a single underscore. The default is case |
|
2127 | IPython generated objects have a single underscore. The default is case | |
2123 | insensitive matching. Matching is also done on the attributes of objects |
|
2128 | insensitive matching. Matching is also done on the attributes of objects | |
2124 | and not only on the objects in a module. |
|
2129 | and not only on the objects in a module. | |
2125 |
|
2130 | |||
2126 | [OBJECT TYPE] |
|
2131 | [OBJECT TYPE] | |
2127 |
|
2132 | |||
2128 | Is the name of a python type from the types module. The name is given in |
|
2133 | Is the name of a python type from the types module. The name is given in | |
2129 | lowercase without the ending type, ex. StringType is written string. By |
|
2134 | lowercase without the ending type, ex. StringType is written string. By | |
2130 | adding a type here only objects matching the given type are matched. |
|
2135 | adding a type here only objects matching the given type are matched. | |
2131 | Using all here makes the pattern match all types (this is the default). |
|
2136 | Using all here makes the pattern match all types (this is the default). | |
2132 |
|
2137 | |||
2133 | Options: |
|
2138 | Options: | |
2134 |
|
2139 | |||
2135 | -a: makes the pattern match even objects whose names start with a single |
|
2140 | -a: makes the pattern match even objects whose names start with a single | |
2136 | underscore. These names are normally ommitted from the search. |
|
2141 | underscore. These names are normally ommitted from the search. | |
2137 |
|
2142 | |||
2138 | -i/-c: make the pattern case insensitive/sensitive. If neither of these |
|
2143 | -i/-c: make the pattern case insensitive/sensitive. If neither of these | |
2139 | options is given, the default is read from your ipythonrc file. The |
|
2144 | options is given, the default is read from your ipythonrc file. The | |
2140 | option name which sets this value is 'wildcards_case_sensitive'. If this |
|
2145 | option name which sets this value is 'wildcards_case_sensitive'. If this | |
2141 | option is not specified in your ipythonrc file, IPython's internal |
|
2146 | option is not specified in your ipythonrc file, IPython's internal | |
2142 | default is to do a case sensitive search. |
|
2147 | default is to do a case sensitive search. | |
2143 |
|
2148 | |||
2144 | -e/-s NAMESPACE: exclude/search a given namespace. The pattern you |
|
2149 | -e/-s NAMESPACE: exclude/search a given namespace. The pattern you | |
2145 | specifiy can be searched in any of the following namespaces: 'builtin', |
|
2150 | specifiy can be searched in any of the following namespaces: 'builtin', | |
2146 | 'user', 'user_global','internal', 'alias', where 'builtin' and 'user' |
|
2151 | 'user', 'user_global','internal', 'alias', where 'builtin' and 'user' | |
2147 | are the search defaults. Note that you should not use quotes when |
|
2152 | are the search defaults. Note that you should not use quotes when | |
2148 | specifying namespaces. |
|
2153 | specifying namespaces. | |
2149 |
|
2154 | |||
2150 | 'Builtin' contains the python module builtin, 'user' contains all user |
|
2155 | 'Builtin' contains the python module builtin, 'user' contains all user | |
2151 | data, 'alias' only contain the shell aliases and no python objects, |
|
2156 | data, 'alias' only contain the shell aliases and no python objects, | |
2152 | 'internal' contains objects used by IPython. The 'user_global' namespace |
|
2157 | 'internal' contains objects used by IPython. The 'user_global' namespace | |
2153 | is only used by embedded IPython instances, and it contains module-level |
|
2158 | is only used by embedded IPython instances, and it contains module-level | |
2154 | globals. You can add namespaces to the search with -s or exclude them |
|
2159 | globals. You can add namespaces to the search with -s or exclude them | |
2155 | with -e (these options can be given more than once). |
|
2160 | with -e (these options can be given more than once). | |
2156 |
|
2161 | |||
2157 | Examples: |
|
2162 | Examples: | |
2158 |
|
2163 | |||
2159 | %psearch a* -> objects beginning with an a %psearch -e builtin a* -> |
|
2164 | %psearch a* -> objects beginning with an a %psearch -e builtin a* -> | |
2160 | objects NOT in the builtin space starting in a %psearch a* function -> |
|
2165 | objects NOT in the builtin space starting in a %psearch a* function -> | |
2161 | all functions beginning with an a %psearch re.e* -> objects beginning |
|
2166 | all functions beginning with an a %psearch re.e* -> objects beginning | |
2162 | with an e in module re %psearch r*.e* -> objects that start with e in |
|
2167 | with an e in module re %psearch r*.e* -> objects that start with e in | |
2163 | modules starting in r %psearch r*.* string -> all strings in modules |
|
2168 | modules starting in r %psearch r*.* string -> all strings in modules | |
2164 | beginning with r |
|
2169 | beginning with r | |
2165 |
|
2170 | |||
2166 | Case sensitve search: |
|
2171 | Case sensitve search: | |
2167 |
|
2172 | |||
2168 | %psearch -c a* list all object beginning with lower case a |
|
2173 | %psearch -c a* list all object beginning with lower case a | |
2169 |
|
2174 | |||
2170 | Show objects beginning with a single _: |
|
2175 | Show objects beginning with a single _: | |
2171 |
|
2176 | |||
2172 | %psearch -a _* list objects beginning with a single underscore |
|
2177 | %psearch -a _* list objects beginning with a single underscore | |
2173 |
|
2178 | |||
2174 |
|
2179 | |||
2175 | %psource: Print (or run through pager) the source code for an object. |
|
2180 | %psource: Print (or run through pager) the source code for an object. | |
2176 |
|
2181 | |||
2177 |
|
2182 | |||
2178 | %pushd: Place the current dir on stack and change directory. |
|
2183 | %pushd: Place the current dir on stack and change directory. | |
2179 |
|
2184 | |||
2180 | Usage: |
|
2185 | Usage: | |
2181 | %pushd ['dirname'] |
|
2186 | %pushd ['dirname'] | |
2182 |
|
2187 | |||
2183 |
|
2188 | |||
2184 | %pwd: Return the current working directory path. |
|
2189 | %pwd: Return the current working directory path. | |
2185 |
|
2190 | |||
2186 |
|
2191 | |||
2187 | %pycat: Show a syntax-highlighted file through a pager. |
|
2192 | %pycat: Show a syntax-highlighted file through a pager. | |
2188 |
|
2193 | |||
2189 | This magic is similar to the cat utility, but it will assume the file to |
|
2194 | This magic is similar to the cat utility, but it will assume the file to | |
2190 | be Python source and will show it with syntax highlighting. |
|
2195 | be Python source and will show it with syntax highlighting. | |
2191 |
|
2196 | |||
2192 |
|
2197 | |||
2193 | %quickref: Show a quick reference sheet |
|
2198 | %quickref: Show a quick reference sheet | |
2194 |
|
2199 | |||
2195 |
|
2200 | |||
2196 | %quit: Exit IPython, confirming if configured to do so (like %exit) |
|
2201 | %quit: Exit IPython, confirming if configured to do so (like %exit) | |
2197 |
|
2202 | |||
2198 |
|
2203 | |||
2199 | %r: Repeat previous input. |
|
2204 | %r: Repeat previous input. | |
2200 |
|
2205 | |||
2201 | Note: Consider using the more powerfull %rep instead! |
|
2206 | Note: Consider using the more powerfull %rep instead! | |
2202 |
|
2207 | |||
2203 | If given an argument, repeats the previous command which starts with the |
|
2208 | If given an argument, repeats the previous command which starts with the | |
2204 | same string, otherwise it just repeats the previous input. |
|
2209 | same string, otherwise it just repeats the previous input. | |
2205 |
|
2210 | |||
2206 | Shell escaped commands (with ! as first character) are not recognized by |
|
2211 | Shell escaped commands (with ! as first character) are not recognized by | |
2207 | this system, only pure python code and magic commands. |
|
2212 | this system, only pure python code and magic commands. | |
2208 |
|
2213 | |||
2209 |
|
2214 | |||
2210 | %rehashx: Update the alias table with all executable files in $PATH. |
|
2215 | %rehashx: Update the alias table with all executable files in $PATH. | |
2211 |
|
2216 | |||
2212 | This version explicitly checks that every entry in $PATH is a file with |
|
2217 | This version explicitly checks that every entry in $PATH is a file with | |
2213 | execute access (os.X_OK), so it is much slower than %rehash. |
|
2218 | execute access (os.X_OK), so it is much slower than %rehash. | |
2214 |
|
2219 | |||
2215 | Under Windows, it checks executability as a match agains a ``|``-separated |
|
2220 | Under Windows, it checks executability as a match agains a ``|``-separated | |
2216 | string of extensions, stored in the IPython config variable |
|
2221 | string of extensions, stored in the IPython config variable | |
2217 | win_exec_ext. This defaults to ``exe|com|bat``. |
|
2222 | win_exec_ext. This defaults to ``exe|com|bat``. | |
2218 |
|
2223 | |||
2219 | This function also resets the root module cache of module completer, |
|
2224 | This function also resets the root module cache of module completer, | |
2220 | used on slow filesystems. |
|
2225 | used on slow filesystems. | |
2221 |
|
2226 | |||
2222 |
|
2227 | |||
2223 | %reset: Resets the namespace by removing all names defined by the user. |
|
2228 | %reset: Resets the namespace by removing all names defined by the user. | |
2224 |
|
2229 | |||
2225 | Input/Output history are left around in case you need them. |
|
2230 | Input/Output history are left around in case you need them. | |
2226 |
|
2231 | |||
2227 |
|
2232 | |||
2228 | %run: Run the named file inside IPython as a program. |
|
2233 | %run: Run the named file inside IPython as a program. | |
2229 |
|
2234 | |||
2230 | Usage: |
|
2235 | Usage: | |
2231 | %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args] |
|
2236 | %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args] | |
2232 |
|
2237 | |||
2233 | Parameters after the filename are passed as command-line arguments to |
|
2238 | Parameters after the filename are passed as command-line arguments to | |
2234 | the program (put in sys.argv). Then, control returns to IPython's prompt. |
|
2239 | the program (put in sys.argv). Then, control returns to IPython's prompt. | |
2235 |
|
2240 | |||
2236 | This is similar to running at a system prompt: |
|
2241 | This is similar to running at a system prompt: | |
2237 | $ python file args |
|
2242 | $ python file args | |
2238 | but with the advantage of giving you IPython's tracebacks, and of |
|
2243 | but with the advantage of giving you IPython's tracebacks, and of | |
2239 | loading all variables into your interactive namespace for further use |
|
2244 | loading all variables into your interactive namespace for further use | |
2240 | (unless -p is used, see below). |
|
2245 | (unless -p is used, see below). | |
2241 |
|
2246 | |||
2242 | The file is executed in a namespace initially consisting only of |
|
2247 | The file is executed in a namespace initially consisting only of | |
2243 | __name__=='__main__' and sys.argv constructed as indicated. It thus sees |
|
2248 | __name__=='__main__' and sys.argv constructed as indicated. It thus sees | |
2244 | its environment as if it were being run as a stand-alone program (except |
|
2249 | its environment as if it were being run as a stand-alone program (except | |
2245 | for sharing global objects such as previously imported modules). But |
|
2250 | for sharing global objects such as previously imported modules). But | |
2246 | after execution, the IPython interactive namespace gets updated with all |
|
2251 | after execution, the IPython interactive namespace gets updated with all | |
2247 | variables defined in the program (except for __name__ and sys.argv). |
|
2252 | variables defined in the program (except for __name__ and sys.argv). | |
2248 | This allows for very convenient loading of code for interactive work, |
|
2253 | This allows for very convenient loading of code for interactive work, | |
2249 | while giving each program a 'clean sheet' to run in. |
|
2254 | while giving each program a 'clean sheet' to run in. | |
2250 |
|
2255 | |||
2251 | Options: |
|
2256 | Options: | |
2252 |
|
2257 | |||
2253 | -n: __name__ is NOT set to '__main__', but to the running file's name |
|
2258 | -n: __name__ is NOT set to '__main__', but to the running file's name | |
2254 | without extension (as python does under import). This allows running |
|
2259 | without extension (as python does under import). This allows running | |
2255 | scripts and reloading the definitions in them without calling code |
|
2260 | scripts and reloading the definitions in them without calling code | |
2256 | protected by an ' if __name__ == "__main__" ' clause. |
|
2261 | protected by an ' if __name__ == "__main__" ' clause. | |
2257 |
|
2262 | |||
2258 | -i: run the file in IPython's namespace instead of an empty one. This is |
|
2263 | -i: run the file in IPython's namespace instead of an empty one. This is | |
2259 | useful if you are experimenting with code written in a text editor which |
|
2264 | useful if you are experimenting with code written in a text editor which | |
2260 | depends on variables defined interactively. |
|
2265 | depends on variables defined interactively. | |
2261 |
|
2266 | |||
2262 | -e: ignore sys.exit() calls or SystemExit exceptions in the script being |
|
2267 | -e: ignore sys.exit() calls or SystemExit exceptions in the script being | |
2263 | run. This is particularly useful if IPython is being used to run |
|
2268 | run. This is particularly useful if IPython is being used to run | |
2264 | unittests, which always exit with a sys.exit() call. In such cases you |
|
2269 | unittests, which always exit with a sys.exit() call. In such cases you | |
2265 | are interested in the output of the test results, not in seeing a |
|
2270 | are interested in the output of the test results, not in seeing a | |
2266 | traceback of the unittest module. |
|
2271 | traceback of the unittest module. | |
2267 |
|
2272 | |||
2268 | -t: print timing information at the end of the run. IPython will give |
|
2273 | -t: print timing information at the end of the run. IPython will give | |
2269 | you an estimated CPU time consumption for your script, which under Unix |
|
2274 | you an estimated CPU time consumption for your script, which under Unix | |
2270 | uses the resource module to avoid the wraparound problems of |
|
2275 | uses the resource module to avoid the wraparound problems of | |
2271 | time.clock(). Under Unix, an estimate of time spent on system tasks is |
|
2276 | time.clock(). Under Unix, an estimate of time spent on system tasks is | |
2272 | also given (for Windows platforms this is reported as 0.0). |
|
2277 | also given (for Windows platforms this is reported as 0.0). | |
2273 |
|
2278 | |||
2274 | If -t is given, an additional -N<N> option can be given, where <N> must |
|
2279 | If -t is given, an additional -N<N> option can be given, where <N> must | |
2275 | be an integer indicating how many times you want the script to run. The |
|
2280 | be an integer indicating how many times you want the script to run. The | |
2276 | final timing report will include total and per run results. |
|
2281 | final timing report will include total and per run results. | |
2277 |
|
2282 | |||
2278 | For example (testing the script uniq_stable.py): |
|
2283 | For example (testing the script uniq_stable.py): | |
2279 |
|
2284 | |||
2280 | In [1]: run -t uniq_stable |
|
2285 | In [1]: run -t uniq_stable | |
2281 |
|
2286 | |||
2282 | IPython CPU timings (estimated): |
|
2287 | IPython CPU timings (estimated): | |
2283 | User : 0.19597 s. |
|
2288 | User : 0.19597 s. | |
2284 | System: 0.0 s. |
|
2289 | System: 0.0 s. | |
2285 |
|
2290 | |||
2286 | In [2]: run -t -N5 uniq_stable |
|
2291 | In [2]: run -t -N5 uniq_stable | |
2287 |
|
2292 | |||
2288 | IPython CPU timings (estimated): |
|
2293 | IPython CPU timings (estimated): | |
2289 | Total runs performed: 5 |
|
2294 | Total runs performed: 5 | |
2290 | Times : Total Per run |
|
2295 | Times : Total Per run | |
2291 | User : 0.910862 s, 0.1821724 s. |
|
2296 | User : 0.910862 s, 0.1821724 s. | |
2292 | System: 0.0 s, 0.0 s. |
|
2297 | System: 0.0 s, 0.0 s. | |
2293 |
|
2298 | |||
2294 | -d: run your program under the control of pdb, the Python debugger. This |
|
2299 | -d: run your program under the control of pdb, the Python debugger. This | |
2295 | allows you to execute your program step by step, watch variables, etc. |
|
2300 | allows you to execute your program step by step, watch variables, etc. | |
2296 | Internally, what IPython does is similar to calling: |
|
2301 | Internally, what IPython does is similar to calling: | |
2297 |
|
2302 | |||
2298 | pdb.run('execfile("YOURFILENAME")') |
|
2303 | pdb.run('execfile("YOURFILENAME")') | |
2299 |
|
2304 | |||
2300 | with a breakpoint set on line 1 of your file. You can change the line |
|
2305 | with a breakpoint set on line 1 of your file. You can change the line | |
2301 | number for this automatic breakpoint to be <N> by using the -bN option |
|
2306 | number for this automatic breakpoint to be <N> by using the -bN option | |
2302 | (where N must be an integer). For example: |
|
2307 | (where N must be an integer). For example: | |
2303 |
|
2308 | |||
2304 | %run -d -b40 myscript |
|
2309 | %run -d -b40 myscript | |
2305 |
|
2310 | |||
2306 | will set the first breakpoint at line 40 in myscript.py. Note that the |
|
2311 | will set the first breakpoint at line 40 in myscript.py. Note that the | |
2307 | first breakpoint must be set on a line which actually does something |
|
2312 | first breakpoint must be set on a line which actually does something | |
2308 | (not a comment or docstring) for it to stop execution. |
|
2313 | (not a comment or docstring) for it to stop execution. | |
2309 |
|
2314 | |||
2310 | When the pdb debugger starts, you will see a (Pdb) prompt. You must |
|
2315 | When the pdb debugger starts, you will see a (Pdb) prompt. You must | |
2311 | first enter 'c' (without qoutes) to start execution up to the first |
|
2316 | first enter 'c' (without qoutes) to start execution up to the first | |
2312 | breakpoint. |
|
2317 | breakpoint. | |
2313 |
|
2318 | |||
2314 | Entering 'help' gives information about the use of the debugger. You can |
|
2319 | Entering 'help' gives information about the use of the debugger. You can | |
2315 | easily see pdb's full documentation with "import pdb;pdb.help()" at a |
|
2320 | easily see pdb's full documentation with "import pdb;pdb.help()" at a | |
2316 | prompt. |
|
2321 | prompt. | |
2317 |
|
2322 | |||
2318 | -p: run program under the control of the Python profiler module (which |
|
2323 | -p: run program under the control of the Python profiler module (which | |
2319 | prints a detailed report of execution times, function calls, etc). |
|
2324 | prints a detailed report of execution times, function calls, etc). | |
2320 |
|
2325 | |||
2321 | You can pass other options after -p which affect the behavior of the |
|
2326 | You can pass other options after -p which affect the behavior of the | |
2322 | profiler itself. See the docs for %prun for details. |
|
2327 | profiler itself. See the docs for %prun for details. | |
2323 |
|
2328 | |||
2324 | In this mode, the program's variables do NOT propagate back to the |
|
2329 | In this mode, the program's variables do NOT propagate back to the | |
2325 | IPython interactive namespace (because they remain in the namespace |
|
2330 | IPython interactive namespace (because they remain in the namespace | |
2326 | where the profiler executes them). |
|
2331 | where the profiler executes them). | |
2327 |
|
2332 | |||
2328 | Internally this triggers a call to %prun, see its documentation for |
|
2333 | Internally this triggers a call to %prun, see its documentation for | |
2329 | details on the options available specifically for profiling. |
|
2334 | details on the options available specifically for profiling. | |
2330 |
|
2335 | |||
2331 | There is one special usage for which the text above doesn't apply: if |
|
2336 | There is one special usage for which the text above doesn't apply: if | |
2332 | the filename ends with .ipy, the file is run as ipython script, just as |
|
2337 | the filename ends with .ipy, the file is run as ipython script, just as | |
2333 | if the commands were written on IPython prompt. |
|
2338 | if the commands were written on IPython prompt. | |
2334 |
|
2339 | |||
2335 |
|
2340 | |||
2336 | %runlog: Run files as logs. |
|
2341 | %runlog: Run files as logs. | |
2337 |
|
2342 | |||
2338 | Usage: |
|
2343 | Usage: | |
2339 | %runlog file1 file2 ... |
|
2344 | %runlog file1 file2 ... | |
2340 |
|
2345 | |||
2341 | Run the named files (treating them as log files) in sequence inside the |
|
2346 | Run the named files (treating them as log files) in sequence inside the | |
2342 | interpreter, and return to the prompt. This is much slower than %run |
|
2347 | interpreter, and return to the prompt. This is much slower than %run | |
2343 | because each line is executed in a try/except block, but it allows |
|
2348 | because each line is executed in a try/except block, but it allows | |
2344 | running files with syntax errors in them. |
|
2349 | running files with syntax errors in them. | |
2345 |
|
2350 | |||
2346 | Normally IPython will guess when a file is one of its own logfiles, so |
|
2351 | Normally IPython will guess when a file is one of its own logfiles, so | |
2347 | you can typically use %run even for logs. This shorthand allows you to |
|
2352 | you can typically use %run even for logs. This shorthand allows you to | |
2348 | force any file to be treated as a log file. |
|
2353 | force any file to be treated as a log file. | |
2349 |
|
2354 | |||
2350 |
|
2355 | |||
2351 | %save: Save a set of lines to a given filename. |
|
2356 | %save: Save a set of lines to a given filename. | |
2352 |
|
2357 | |||
2353 | Usage: |
|
2358 | Usage: | |
2354 | %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ... |
|
2359 | %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ... | |
2355 |
|
2360 | |||
2356 | Options: |
|
2361 | Options: | |
2357 |
|
2362 | |||
2358 | -r: use 'raw' input. By default, the 'processed' history is used, so |
|
2363 | -r: use 'raw' input. By default, the 'processed' history is used, so | |
2359 | that magics are loaded in their transformed version to valid Python. If |
|
2364 | that magics are loaded in their transformed version to valid Python. If | |
2360 | this option is given, the raw input as typed as the command line is used |
|
2365 | this option is given, the raw input as typed as the command line is used | |
2361 | instead. |
|
2366 | instead. | |
2362 |
|
2367 | |||
2363 | This function uses the same syntax as %macro for line extraction, but |
|
2368 | This function uses the same syntax as %macro for line extraction, but | |
2364 | instead of creating a macro it saves the resulting string to the |
|
2369 | instead of creating a macro it saves the resulting string to the | |
2365 | filename you specify. |
|
2370 | filename you specify. | |
2366 |
|
2371 | |||
2367 | It adds a '.py' extension to the file if you don't do so yourself, and |
|
2372 | It adds a '.py' extension to the file if you don't do so yourself, and | |
2368 | it asks for confirmation before overwriting existing files. |
|
2373 | it asks for confirmation before overwriting existing files. | |
2369 |
|
2374 | |||
2370 |
|
2375 | |||
2371 | %sc: Shell capture - execute a shell command and capture its output. |
|
2376 | %sc: Shell capture - execute a shell command and capture its output. | |
2372 |
|
2377 | |||
2373 | DEPRECATED. Suboptimal, retained for backwards compatibility. |
|
2378 | DEPRECATED. Suboptimal, retained for backwards compatibility. | |
2374 |
|
2379 | |||
2375 | You should use the form 'var = !command' instead. Example: |
|
2380 | You should use the form 'var = !command' instead. Example: | |
2376 |
|
2381 | |||
2377 | "%sc -l myfiles = ls " should now be written as |
|
2382 | "%sc -l myfiles = ls " should now be written as | |
2378 |
|
2383 | |||
2379 | "myfiles = !ls " |
|
2384 | "myfiles = !ls " | |
2380 |
|
2385 | |||
2381 | myfiles.s, myfiles.l and myfiles.n still apply as documented below. |
|
2386 | myfiles.s, myfiles.l and myfiles.n still apply as documented below. | |
2382 |
|
2387 | |||
2383 | - %sc [options] varname=command |
|
2388 | - %sc [options] varname=command | |
2384 |
|
2389 | |||
2385 | IPython will run the given command using commands.getoutput(), and will |
|
2390 | IPython will run the given command using commands.getoutput(), and will | |
2386 | then update the user's interactive namespace with a variable called |
|
2391 | then update the user's interactive namespace with a variable called | |
2387 | varname, containing the value of the call. Your command can contain |
|
2392 | varname, containing the value of the call. Your command can contain | |
2388 | shell wildcards, pipes, etc. |
|
2393 | shell wildcards, pipes, etc. | |
2389 |
|
2394 | |||
2390 | The '=' sign in the syntax is mandatory, and the variable name you |
|
2395 | The '=' sign in the syntax is mandatory, and the variable name you | |
2391 | supply must follow Python's standard conventions for valid names. |
|
2396 | supply must follow Python's standard conventions for valid names. | |
2392 |
|
2397 | |||
2393 | (A special format without variable name exists for internal use) |
|
2398 | (A special format without variable name exists for internal use) | |
2394 |
|
2399 | |||
2395 | Options: |
|
2400 | Options: | |
2396 |
|
2401 | |||
2397 | -l: list output. Split the output on newlines into a list before |
|
2402 | -l: list output. Split the output on newlines into a list before | |
2398 | assigning it to the given variable. By default the output is stored as a |
|
2403 | assigning it to the given variable. By default the output is stored as a | |
2399 | single string. |
|
2404 | single string. | |
2400 |
|
2405 | |||
2401 | -v: verbose. Print the contents of the variable. |
|
2406 | -v: verbose. Print the contents of the variable. | |
2402 |
|
2407 | |||
2403 | In most cases you should not need to split as a list, because the |
|
2408 | In most cases you should not need to split as a list, because the | |
2404 | returned value is a special type of string which can automatically |
|
2409 | returned value is a special type of string which can automatically | |
2405 | provide its contents either as a list (split on newlines) or as a |
|
2410 | provide its contents either as a list (split on newlines) or as a | |
2406 | space-separated string. These are convenient, respectively, either for |
|
2411 | space-separated string. These are convenient, respectively, either for | |
2407 | sequential processing or to be passed to a shell command. |
|
2412 | sequential processing or to be passed to a shell command. | |
2408 |
|
2413 | |||
2409 | For example: |
|
2414 | For example: | |
2410 |
|
2415 | |||
2411 | # Capture into variable a In [9]: sc a=ls *py |
|
2416 | # Capture into variable a In [9]: sc a=ls *py | |
2412 |
|
2417 | |||
2413 | # a is a string with embedded newlines In [10]: a Out[10]: 'setup.py |
|
2418 | # a is a string with embedded newlines In [10]: a Out[10]: 'setup.py | |
2414 | win32_manual_post_install.py' |
|
2419 | win32_manual_post_install.py' | |
2415 |
|
2420 | |||
2416 | # which can be seen as a list: In [11]: a.l Out[11]: ['setup.py', |
|
2421 | # which can be seen as a list: In [11]: a.l Out[11]: ['setup.py', | |
2417 | 'win32_manual_post_install.py'] |
|
2422 | 'win32_manual_post_install.py'] | |
2418 |
|
2423 | |||
2419 | # or as a whitespace-separated string: In [12]: a.s Out[12]: 'setup.py |
|
2424 | # or as a whitespace-separated string: In [12]: a.s Out[12]: 'setup.py | |
2420 | win32_manual_post_install.py' |
|
2425 | win32_manual_post_install.py' | |
2421 |
|
2426 | |||
2422 | # a.s is useful to pass as a single command line: In [13]: !wc -l $a.s |
|
2427 | # a.s is useful to pass as a single command line: In [13]: !wc -l $a.s | |
2423 | 146 setup.py 130 win32_manual_post_install.py 276 total |
|
2428 | 146 setup.py 130 win32_manual_post_install.py 276 total | |
2424 |
|
2429 | |||
2425 | # while the list form is useful to loop over: In [14]: for f in a.l: |
|
2430 | # while the list form is useful to loop over: In [14]: for f in a.l: | |
2426 | ....: !wc -l $f ....: 146 setup.py 130 win32_manual_post_install.py |
|
2431 | ....: !wc -l $f ....: 146 setup.py 130 win32_manual_post_install.py | |
2427 |
|
2432 | |||
2428 | Similiarly, the lists returned by the -l option are also special, in the |
|
2433 | Similiarly, the lists returned by the -l option are also special, in the | |
2429 | sense that you can equally invoke the .s attribute on them to |
|
2434 | sense that you can equally invoke the .s attribute on them to | |
2430 | automatically get a whitespace-separated string from their contents: |
|
2435 | automatically get a whitespace-separated string from their contents: | |
2431 |
|
2436 | |||
2432 | In [1]: sc -l b=ls *py |
|
2437 | In [1]: sc -l b=ls *py | |
2433 |
|
2438 | |||
2434 | In [2]: b Out[2]: ['setup.py', 'win32_manual_post_install.py'] |
|
2439 | In [2]: b Out[2]: ['setup.py', 'win32_manual_post_install.py'] | |
2435 |
|
2440 | |||
2436 | In [3]: b.s Out[3]: 'setup.py win32_manual_post_install.py' |
|
2441 | In [3]: b.s Out[3]: 'setup.py win32_manual_post_install.py' | |
2437 |
|
2442 | |||
2438 | In summary, both the lists and strings used for ouptut capture have the |
|
2443 | In summary, both the lists and strings used for ouptut capture have the | |
2439 | following special attributes: |
|
2444 | following special attributes: | |
2440 |
|
2445 | |||
2441 | .l (or .list) : value as list. .n (or .nlstr): value as |
|
2446 | .l (or .list) : value as list. .n (or .nlstr): value as | |
2442 | newline-separated string. .s (or .spstr): value as space-separated string. |
|
2447 | newline-separated string. .s (or .spstr): value as space-separated string. | |
2443 |
|
2448 | |||
2444 |
|
2449 | |||
2445 | %sx: Shell execute - run a shell command and capture its output. |
|
2450 | %sx: Shell execute - run a shell command and capture its output. | |
2446 |
|
2451 | |||
2447 | %sx command |
|
2452 | %sx command | |
2448 |
|
2453 | |||
2449 | IPython will run the given command using commands.getoutput(), and |
|
2454 | IPython will run the given command using commands.getoutput(), and | |
2450 | return the result formatted as a list (split on '\n'). Since the output |
|
2455 | return the result formatted as a list (split on '\n'). Since the output | |
2451 | is _returned_, it will be stored in ipython's regular output cache |
|
2456 | is _returned_, it will be stored in ipython's regular output cache | |
2452 | Out[N] and in the '_N' automatic variables. |
|
2457 | Out[N] and in the '_N' automatic variables. | |
2453 |
|
2458 | |||
2454 | Notes: |
|
2459 | Notes: | |
2455 |
|
2460 | |||
2456 | 1) If an input line begins with '!!', then %sx is automatically invoked. |
|
2461 | 1) If an input line begins with '!!', then %sx is automatically invoked. | |
2457 | That is, while: !ls causes ipython to simply issue system('ls'), typing |
|
2462 | That is, while: !ls causes ipython to simply issue system('ls'), typing | |
2458 | !!ls is a shorthand equivalent to: %sx ls |
|
2463 | !!ls is a shorthand equivalent to: %sx ls | |
2459 |
|
2464 | |||
2460 | 2) %sx differs from %sc in that %sx automatically splits into a list, |
|
2465 | 2) %sx differs from %sc in that %sx automatically splits into a list, | |
2461 | like '%sc -l'. The reason for this is to make it as easy as possible to |
|
2466 | like '%sc -l'. The reason for this is to make it as easy as possible to | |
2462 | process line-oriented shell output via further python commands. %sc is |
|
2467 | process line-oriented shell output via further python commands. %sc is | |
2463 | meant to provide much finer control, but requires more typing. |
|
2468 | meant to provide much finer control, but requires more typing. | |
2464 |
|
2469 | |||
2465 | 3) Just like %sc -l, this is a list with special attributes: |
|
2470 | 3) Just like %sc -l, this is a list with special attributes: | |
2466 |
|
2471 | |||
2467 | .l (or .list) : value as list. .n (or .nlstr): value as |
|
2472 | .l (or .list) : value as list. .n (or .nlstr): value as | |
2468 | newline-separated string. .s (or .spstr): value as whitespace-separated |
|
2473 | newline-separated string. .s (or .spstr): value as whitespace-separated | |
2469 | string. |
|
2474 | string. | |
2470 |
|
2475 | |||
2471 | This is very useful when trying to use such lists as arguments to system |
|
2476 | This is very useful when trying to use such lists as arguments to system | |
2472 | commands. |
|
2477 | commands. | |
2473 |
|
2478 | |||
2474 |
|
2479 | |||
2475 | %system_verbose: Set verbose printing of system calls. |
|
2480 | %system_verbose: Set verbose printing of system calls. | |
2476 |
|
2481 | |||
2477 | If called without an argument, act as a toggle |
|
2482 | If called without an argument, act as a toggle | |
2478 |
|
2483 | |||
2479 |
|
2484 | |||
2480 | %time: Time execution of a Python statement or expression. |
|
2485 | %time: Time execution of a Python statement or expression. | |
2481 |
|
2486 | |||
2482 | The CPU and wall clock times are printed, and the value of the |
|
2487 | The CPU and wall clock times are printed, and the value of the | |
2483 | expression (if any) is returned. Note that under Win32, system time is |
|
2488 | expression (if any) is returned. Note that under Win32, system time is | |
2484 | always reported as 0, since it can not be measured. |
|
2489 | always reported as 0, since it can not be measured. | |
2485 |
|
2490 | |||
2486 | This function provides very basic timing functionality. In Python 2.3, |
|
2491 | This function provides very basic timing functionality. In Python 2.3, | |
2487 | the timeit module offers more control and sophistication, so this could |
|
2492 | the timeit module offers more control and sophistication, so this could | |
2488 | be rewritten to use it (patches welcome). |
|
2493 | be rewritten to use it (patches welcome). | |
2489 |
|
2494 | |||
2490 | Some examples: |
|
2495 | Some examples: | |
2491 |
|
2496 | |||
2492 | In [1]: time 2**128 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
2497 | In [1]: time 2**128 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s | |
2493 | Wall time: 0.00 Out[1]: 340282366920938463463374607431768211456L |
|
2498 | Wall time: 0.00 Out[1]: 340282366920938463463374607431768211456L | |
2494 |
|
2499 | |||
2495 | In [2]: n = 1000000 |
|
2500 | In [2]: n = 1000000 | |
2496 |
|
2501 | |||
2497 | In [3]: time sum(range(n)) CPU times: user 1.20 s, sys: 0.05 s, total: |
|
2502 | In [3]: time sum(range(n)) CPU times: user 1.20 s, sys: 0.05 s, total: | |
2498 | 1.25 s Wall time: 1.37 Out[3]: 499999500000L |
|
2503 | 1.25 s Wall time: 1.37 Out[3]: 499999500000L | |
2499 |
|
2504 | |||
2500 | In [4]: time print 'hello world' hello world CPU times: user 0.00 s, |
|
2505 | In [4]: time print 'hello world' hello world CPU times: user 0.00 s, | |
2501 | sys: 0.00 s, total: 0.00 s Wall time: 0.00 |
|
2506 | sys: 0.00 s, total: 0.00 s Wall time: 0.00 | |
2502 |
|
2507 | |||
2503 | Note that the time needed by Python to compile the given expression will |
|
2508 | Note that the time needed by Python to compile the given expression will | |
2504 | be reported if it is more than 0.1s. In this example, the actual |
|
2509 | be reported if it is more than 0.1s. In this example, the actual | |
2505 | exponentiation is done by Python at compilation time, so while the |
|
2510 | exponentiation is done by Python at compilation time, so while the | |
2506 | expression can take a noticeable amount of time to compute, that time is |
|
2511 | expression can take a noticeable amount of time to compute, that time is | |
2507 | purely due to the compilation: |
|
2512 | purely due to the compilation: | |
2508 |
|
2513 | |||
2509 | In [5]: time 3**9999; CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
2514 | In [5]: time 3**9999; CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s | |
2510 | Wall time: 0.00 s |
|
2515 | Wall time: 0.00 s | |
2511 |
|
2516 | |||
2512 | In [6]: time 3**999999; CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 |
|
2517 | In [6]: time 3**999999; CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 | |
2513 | s Wall time: 0.00 s Compiler : 0.78 s |
|
2518 | s Wall time: 0.00 s Compiler : 0.78 s | |
2514 |
|
2519 | |||
2515 |
|
2520 | |||
2516 | %timeit: Time execution of a Python statement or expression |
|
2521 | %timeit: Time execution of a Python statement or expression | |
2517 |
|
2522 | |||
2518 | Usage: |
|
2523 | Usage: | |
2519 | %timeit [-n<N> -r<R> [-t|-c]] statement |
|
2524 | %timeit [-n<N> -r<R> [-t|-c]] statement | |
2520 |
|
2525 | |||
2521 | Time execution of a Python statement or expression using the timeit module. |
|
2526 | Time execution of a Python statement or expression using the timeit module. | |
2522 |
|
2527 | |||
2523 | Options: -n<N>: execute the given statement <N> times in a loop. If this |
|
2528 | Options: -n<N>: execute the given statement <N> times in a loop. If this | |
2524 | value is not given, a fitting value is chosen. |
|
2529 | value is not given, a fitting value is chosen. | |
2525 |
|
2530 | |||
2526 | -r<R>: repeat the loop iteration <R> times and take the best result. |
|
2531 | -r<R>: repeat the loop iteration <R> times and take the best result. | |
2527 | Default: 3 |
|
2532 | Default: 3 | |
2528 |
|
2533 | |||
2529 | -t: use time.time to measure the time, which is the default on Unix. |
|
2534 | -t: use time.time to measure the time, which is the default on Unix. | |
2530 | This function measures wall time. |
|
2535 | This function measures wall time. | |
2531 |
|
2536 | |||
2532 | -c: use time.clock to measure the time, which is the default on Windows |
|
2537 | -c: use time.clock to measure the time, which is the default on Windows | |
2533 | and measures wall time. On Unix, resource.getrusage is used instead and |
|
2538 | and measures wall time. On Unix, resource.getrusage is used instead and | |
2534 | returns the CPU user time. |
|
2539 | returns the CPU user time. | |
2535 |
|
2540 | |||
2536 | -p<P>: use a precision of <P> digits to display the timing result. |
|
2541 | -p<P>: use a precision of <P> digits to display the timing result. | |
2537 | Default: 3 |
|
2542 | Default: 3 | |
2538 |
|
2543 | |||
2539 | Examples: |
|
2544 | Examples: | |
2540 | In [1]: %timeit pass 10000000 loops, best of 3: 53.3 ns per loop |
|
2545 | In [1]: %timeit pass 10000000 loops, best of 3: 53.3 ns per loop | |
2541 |
|
2546 | |||
2542 | In [2]: u = None |
|
2547 | In [2]: u = None | |
2543 |
|
2548 | |||
2544 | In [3]: %timeit u is None 10000000 loops, best of 3: 184 ns per loop |
|
2549 | In [3]: %timeit u is None 10000000 loops, best of 3: 184 ns per loop | |
2545 |
|
2550 | |||
2546 | In [4]: %timeit -r 4 u == None 1000000 loops, best of 4: 242 ns per loop |
|
2551 | In [4]: %timeit -r 4 u == None 1000000 loops, best of 4: 242 ns per loop | |
2547 |
|
2552 | |||
2548 | In [5]: import time |
|
2553 | In [5]: import time | |
2549 |
|
2554 | |||
2550 | In [6]: %timeit -n1 time.sleep(2) 1 loops, best of 3: 2 s per loop |
|
2555 | In [6]: %timeit -n1 time.sleep(2) 1 loops, best of 3: 2 s per loop | |
2551 |
|
2556 | |||
2552 | The times reported by %timeit will be slightly higher than those |
|
2557 | The times reported by %timeit will be slightly higher than those | |
2553 | reported by the timeit.py script when variables are accessed. This is |
|
2558 | reported by the timeit.py script when variables are accessed. This is | |
2554 | due to the fact that %timeit executes the statement in the namespace of |
|
2559 | due to the fact that %timeit executes the statement in the namespace of | |
2555 | the shell, compared with timeit.py, which uses a single setup statement |
|
2560 | the shell, compared with timeit.py, which uses a single setup statement | |
2556 | to import function or create variables. Generally, the bias does not |
|
2561 | to import function or create variables. Generally, the bias does not | |
2557 | matter as long as results from timeit.py are not mixed with those from |
|
2562 | matter as long as results from timeit.py are not mixed with those from | |
2558 | %timeit. |
|
2563 | %timeit. | |
2559 |
|
2564 | |||
2560 |
|
2565 | |||
2561 | %unalias: Remove an alias |
|
2566 | %unalias: Remove an alias | |
2562 |
|
2567 | |||
2563 |
|
2568 | |||
2564 | %upgrade: Upgrade your IPython installation |
|
2569 | %upgrade: Upgrade your IPython installation | |
2565 |
|
2570 | |||
2566 | This will copy the config files that don't yet exist in your ipython dir |
|
2571 | This will copy the config files that don't yet exist in your ipython dir | |
2567 | from the system config dir. Use this after upgrading IPython if you |
|
2572 | from the system config dir. Use this after upgrading IPython if you | |
2568 | don't wish to delete your .ipython dir. |
|
2573 | don't wish to delete your .ipython dir. | |
2569 |
|
2574 | |||
2570 | Call with -nolegacy to get rid of ipythonrc* files (recommended for new |
|
2575 | Call with -nolegacy to get rid of ipythonrc* files (recommended for new | |
2571 | users) |
|
2576 | users) | |
2572 |
|
2577 | |||
2573 |
|
2578 | |||
2574 | %who: Print all interactive variables, with some minimal formatting. |
|
2579 | %who: Print all interactive variables, with some minimal formatting. | |
2575 |
|
2580 | |||
2576 | If any arguments are given, only variables whose type matches one of |
|
2581 | If any arguments are given, only variables whose type matches one of | |
2577 | these are printed. For example: |
|
2582 | these are printed. For example: | |
2578 |
|
2583 | |||
2579 | %who function str |
|
2584 | %who function str | |
2580 |
|
2585 | |||
2581 | will only list functions and strings, excluding all other types of |
|
2586 | will only list functions and strings, excluding all other types of | |
2582 | variables. To find the proper type names, simply use type(var) at a |
|
2587 | variables. To find the proper type names, simply use type(var) at a | |
2583 | command line to see how python prints type names. For example: |
|
2588 | command line to see how python prints type names. For example: | |
2584 |
|
2589 | |||
2585 | In [1]: type('hello') |
|
2590 | In [1]: type('hello') | |
2586 | Out[1]: <type 'str'> |
|
2591 | Out[1]: <type 'str'> | |
2587 |
|
2592 | |||
2588 | indicates that the type name for strings is 'str'. |
|
2593 | indicates that the type name for strings is 'str'. | |
2589 |
|
2594 | |||
2590 | %who always excludes executed names loaded through your configuration |
|
2595 | %who always excludes executed names loaded through your configuration | |
2591 | file and things which are internal to IPython. |
|
2596 | file and things which are internal to IPython. | |
2592 |
|
2597 | |||
2593 | This is deliberate, as typically you may load many modules and the |
|
2598 | This is deliberate, as typically you may load many modules and the | |
2594 | purpose of %who is to show you only what you've manually defined. |
|
2599 | purpose of %who is to show you only what you've manually defined. | |
2595 |
|
2600 | |||
2596 |
|
2601 | |||
2597 | %who_ls: Return a sorted list of all interactive variables. |
|
2602 | %who_ls: Return a sorted list of all interactive variables. | |
2598 |
|
2603 | |||
2599 | If arguments are given, only variables of types matching these arguments |
|
2604 | If arguments are given, only variables of types matching these arguments | |
2600 | are returned. |
|
2605 | are returned. | |
2601 |
|
2606 | |||
2602 |
|
2607 | |||
2603 | %whos: Like %who, but gives some extra information about each variable. |
|
2608 | %whos: Like %who, but gives some extra information about each variable. | |
2604 |
|
2609 | |||
2605 | The same type filtering of %who can be applied here. |
|
2610 | The same type filtering of %who can be applied here. | |
2606 |
|
2611 | |||
2607 | For all variables, the type is printed. Additionally it prints: |
|
2612 | For all variables, the type is printed. Additionally it prints: | |
2608 |
|
2613 | |||
2609 | - For ,[],(): their length. |
|
2614 | - For ,[],(): their length. | |
2610 |
|
2615 | |||
2611 | - For numpy and Numeric arrays, a summary with shape, number of |
|
2616 | - For numpy and Numeric arrays, a summary with shape, number of | |
2612 | elements, typecode and size in memory. |
|
2617 | elements, typecode and size in memory. | |
2613 |
|
2618 | |||
2614 | - Everything else: a string representation, snipping their middle if too |
|
2619 | - Everything else: a string representation, snipping their middle if too | |
2615 | long. |
|
2620 | long. | |
2616 |
|
2621 | |||
2617 |
|
2622 | |||
2618 | %xmode: Switch modes for the exception handlers. |
|
2623 | %xmode: Switch modes for the exception handlers. | |
2619 |
|
2624 | |||
2620 | Valid modes: Plain, Context and Verbose. |
|
2625 | Valid modes: Plain, Context and Verbose. | |
2621 |
|
2626 | |||
2622 | If called without arguments, acts as a toggle. |
|
2627 | If called without arguments, acts as a toggle. | |
2623 |
|
2628 | |||
2624 |
|
2629 | |||
2625 | Access to the standard Python help |
|
2630 | Access to the standard Python help | |
2626 | ---------------------------------- |
|
2631 | ---------------------------------- | |
2627 |
|
2632 | |||
2628 | As of Python 2.1, a help system is available with access to object |
|
2633 | As of Python 2.1, a help system is available with access to object | |
2629 | docstrings and the Python manuals. Simply type 'help' (no quotes) to |
|
2634 | docstrings and the Python manuals. Simply type 'help' (no quotes) to | |
2630 | access it. You can also type help(object) to obtain information about a |
|
2635 | access it. You can also type help(object) to obtain information about a | |
2631 | given object, and help('keyword') for information on a keyword. As noted |
|
2636 | given object, and help('keyword') for information on a keyword. As noted | |
2632 | in sec. 3.1 <node3.html#sec:help-access>, you need to properly configure |
|
2637 | in sec. 3.1 <node3.html#sec:help-access>, you need to properly configure | |
2633 | your environment variable PYTHONDOCS for this feature to work correctly. |
|
2638 | your environment variable PYTHONDOCS for this feature to work correctly. | |
2634 |
|
2639 | |||
2635 |
|
2640 | |||
2636 |
|
2641 | |||
2637 | Dynamic object information |
|
2642 | Dynamic object information | |
2638 | -------------------------- |
|
2643 | -------------------------- | |
2639 |
|
2644 | |||
2640 | Typing ?word or word? prints detailed information about an object. If |
|
2645 | Typing ?word or word? prints detailed information about an object. If | |
2641 | certain strings in the object are too long (docstrings, code, etc.) they |
|
2646 | certain strings in the object are too long (docstrings, code, etc.) they | |
2642 | get snipped in the center for brevity. This system gives access variable |
|
2647 | get snipped in the center for brevity. This system gives access variable | |
2643 | types and values, full source code for any object (if available), |
|
2648 | types and values, full source code for any object (if available), | |
2644 | function prototypes and other useful information. |
|
2649 | function prototypes and other useful information. | |
2645 |
|
2650 | |||
2646 | Typing ??word or word?? gives access to the full information without |
|
2651 | Typing ??word or word?? gives access to the full information without | |
2647 | snipping long strings. Long strings are sent to the screen through the |
|
2652 | snipping long strings. Long strings are sent to the screen through the | |
2648 | less pager if longer than the screen and printed otherwise. On systems |
|
2653 | less pager if longer than the screen and printed otherwise. On systems | |
2649 | lacking the less command, IPython uses a very basic internal pager. |
|
2654 | lacking the less command, IPython uses a very basic internal pager. | |
2650 |
|
2655 | |||
2651 | The following magic functions are particularly useful for gathering |
|
2656 | The following magic functions are particularly useful for gathering | |
2652 | information about your working environment. You can get more details by |
|
2657 | information about your working environment. You can get more details by | |
2653 | typing %magic or querying them individually (use %function_name? with or |
|
2658 | typing %magic or querying them individually (use %function_name? with or | |
2654 | without the %), this is just a summary: |
|
2659 | without the %), this is just a summary: | |
2655 |
|
2660 | |||
2656 | * [%pdoc <object>:] Print (or run through a pager if too long) the |
|
2661 | * [%pdoc <object>:] Print (or run through a pager if too long) the | |
2657 | docstring for an object. If the given object is a class, it will |
|
2662 | docstring for an object. If the given object is a class, it will | |
2658 | print both the class and the constructor docstrings. |
|
2663 | print both the class and the constructor docstrings. | |
2659 | * [%pdef <object>:] Print the definition header for any callable |
|
2664 | * [%pdef <object>:] Print the definition header for any callable | |
2660 | object. If the object is a class, print the constructor information. |
|
2665 | object. If the object is a class, print the constructor information. | |
2661 | * [%psource <object>:] Print (or run through a pager if too long) |
|
2666 | * [%psource <object>:] Print (or run through a pager if too long) | |
2662 | the source code for an object. |
|
2667 | the source code for an object. | |
2663 | * [%pfile <object>:] Show the entire source file where an object was |
|
2668 | * [%pfile <object>:] Show the entire source file where an object was | |
2664 | defined via a pager, opening it at the line where the object |
|
2669 | defined via a pager, opening it at the line where the object | |
2665 | definition begins. |
|
2670 | definition begins. | |
2666 | * [%who/%whos:] These functions give information about identifiers |
|
2671 | * [%who/%whos:] These functions give information about identifiers | |
2667 | you have defined interactively (not things you loaded or defined |
|
2672 | you have defined interactively (not things you loaded or defined | |
2668 | in your configuration files). %who just prints a list of |
|
2673 | in your configuration files). %who just prints a list of | |
2669 | identifiers and %whos prints a table with some basic details about |
|
2674 | identifiers and %whos prints a table with some basic details about | |
2670 | each identifier. |
|
2675 | each identifier. | |
2671 |
|
2676 | |||
2672 | Note that the dynamic object information functions (?/??, %pdoc, %pfile, |
|
2677 | Note that the dynamic object information functions (?/??, %pdoc, %pfile, | |
2673 | %pdef, %psource) give you access to documentation even on things which |
|
2678 | %pdef, %psource) give you access to documentation even on things which | |
2674 | are not really defined as separate identifiers. Try for example typing |
|
2679 | are not really defined as separate identifiers. Try for example typing | |
2675 | {}.get? or after doing import os, type os.path.abspath??. |
|
2680 | {}.get? or after doing import os, type os.path.abspath??. | |
2676 |
|
2681 | |||
2677 |
|
2682 | |||
2678 |
|
2683 | |||
2679 | Readline-based features |
|
2684 | Readline-based features | |
2680 | ----------------------- |
|
2685 | ----------------------- | |
2681 |
|
2686 | |||
2682 | These features require the GNU readline library, so they won't work if |
|
2687 | These features require the GNU readline library, so they won't work if | |
2683 | your Python installation lacks readline support. We will first describe |
|
2688 | your Python installation lacks readline support. We will first describe | |
2684 | the default behavior IPython uses, and then how to change it to suit |
|
2689 | the default behavior IPython uses, and then how to change it to suit | |
2685 | your preferences. |
|
2690 | your preferences. | |
2686 |
|
2691 | |||
2687 |
|
2692 | |||
2688 | Command line completion |
|
2693 | Command line completion | |
2689 | ----------------------- |
|
2694 | ----------------------- | |
2690 |
|
2695 | |||
2691 | At any time, hitting TAB will complete any available python commands or |
|
2696 | At any time, hitting TAB will complete any available python commands or | |
2692 | variable names, and show you a list of the possible completions if |
|
2697 | variable names, and show you a list of the possible completions if | |
2693 | there's no unambiguous one. It will also complete filenames in the |
|
2698 | there's no unambiguous one. It will also complete filenames in the | |
2694 | current directory if no python names match what you've typed so far. |
|
2699 | current directory if no python names match what you've typed so far. | |
2695 |
|
2700 | |||
2696 |
|
2701 | |||
2697 | Search command history |
|
2702 | Search command history | |
2698 | ---------------------- |
|
2703 | ---------------------- | |
2699 |
|
2704 | |||
2700 | IPython provides two ways for searching through previous input and thus |
|
2705 | IPython provides two ways for searching through previous input and thus | |
2701 | reduce the need for repetitive typing: |
|
2706 | reduce the need for repetitive typing: | |
2702 |
|
2707 | |||
2703 | 1. Start typing, and then use Ctrl-p (previous,up) and Ctrl-n |
|
2708 | 1. Start typing, and then use Ctrl-p (previous,up) and Ctrl-n | |
2704 | (next,down) to search through only the history items that match |
|
2709 | (next,down) to search through only the history items that match | |
2705 | what you've typed so far. If you use Ctrl-p/Ctrl-n at a blank |
|
2710 | what you've typed so far. If you use Ctrl-p/Ctrl-n at a blank | |
2706 | prompt, they just behave like normal arrow keys. |
|
2711 | prompt, they just behave like normal arrow keys. | |
2707 | 2. Hit Ctrl-r: opens a search prompt. Begin typing and the system |
|
2712 | 2. Hit Ctrl-r: opens a search prompt. Begin typing and the system | |
2708 | searches your history for lines that contain what you've typed so |
|
2713 | searches your history for lines that contain what you've typed so | |
2709 | far, completing as much as it can. |
|
2714 | far, completing as much as it can. | |
2710 |
|
2715 | |||
2711 |
|
2716 | |||
2712 | Persistent command history across sessions |
|
2717 | Persistent command history across sessions | |
2713 | ------------------------------------------ |
|
2718 | ------------------------------------------ | |
2714 |
|
2719 | |||
2715 | IPython will save your input history when it leaves and reload it next |
|
2720 | IPython will save your input history when it leaves and reload it next | |
2716 | time you restart it. By default, the history file is named |
|
2721 | time you restart it. By default, the history file is named | |
2717 | $IPYTHONDIR/history, but if you've loaded a named profile, |
|
2722 | $IPYTHONDIR/history, but if you've loaded a named profile, | |
2718 | '-PROFILE_NAME' is appended to the name. This allows you to keep |
|
2723 | '-PROFILE_NAME' is appended to the name. This allows you to keep | |
2719 | separate histories related to various tasks: commands related to |
|
2724 | separate histories related to various tasks: commands related to | |
2720 | numerical work will not be clobbered by a system shell history, for |
|
2725 | numerical work will not be clobbered by a system shell history, for | |
2721 | example. |
|
2726 | example. | |
2722 |
|
2727 | |||
2723 |
|
2728 | |||
2724 | Autoindent |
|
2729 | Autoindent | |
2725 | ---------- |
|
2730 | ---------- | |
2726 |
|
2731 | |||
2727 | IPython can recognize lines ending in ':' and indent the next line, |
|
2732 | IPython can recognize lines ending in ':' and indent the next line, | |
2728 | while also un-indenting automatically after 'raise' or 'return'. |
|
2733 | while also un-indenting automatically after 'raise' or 'return'. | |
2729 |
|
2734 | |||
2730 | This feature uses the readline library, so it will honor your ~/.inputrc |
|
2735 | This feature uses the readline library, so it will honor your ~/.inputrc | |
2731 | configuration (or whatever file your INPUTRC variable points to). Adding |
|
2736 | configuration (or whatever file your INPUTRC variable points to). Adding | |
2732 | the following lines to your .inputrc file can make indenting/unindenting |
|
2737 | the following lines to your .inputrc file can make indenting/unindenting | |
2733 | more convenient (M-i indents, M-u unindents):: |
|
2738 | more convenient (M-i indents, M-u unindents):: | |
2734 |
|
2739 | |||
2735 | $if Python |
|
2740 | $if Python | |
2736 | "\M-i": " " |
|
2741 | "\M-i": " " | |
2737 | "\M-u": "\d\d\d\d" |
|
2742 | "\M-u": "\d\d\d\d" | |
2738 | $endif |
|
2743 | $endif | |
2739 |
|
2744 | |||
2740 | Note that there are 4 spaces between the quote marks after "M-i" above. |
|
2745 | Note that there are 4 spaces between the quote marks after "M-i" above. | |
2741 |
|
2746 | |||
2742 | Warning: this feature is ON by default, but it can cause problems with |
|
2747 | Warning: this feature is ON by default, but it can cause problems with | |
2743 | the pasting of multi-line indented code (the pasted code gets |
|
2748 | the pasting of multi-line indented code (the pasted code gets | |
2744 | re-indented on each line). A magic function %autoindent allows you to |
|
2749 | re-indented on each line). A magic function %autoindent allows you to | |
2745 | toggle it on/off at runtime. You can also disable it permanently on in |
|
2750 | toggle it on/off at runtime. You can also disable it permanently on in | |
2746 | your ipythonrc file (set autoindent 0). |
|
2751 | your ipythonrc file (set autoindent 0). | |
2747 |
|
2752 | |||
2748 |
|
2753 | |||
2749 | Customizing readline behavior |
|
2754 | Customizing readline behavior | |
2750 | ----------------------------- |
|
2755 | ----------------------------- | |
2751 |
|
2756 | |||
2752 | All these features are based on the GNU readline library, which has an |
|
2757 | All these features are based on the GNU readline library, which has an | |
2753 | extremely customizable interface. Normally, readline is configured via a |
|
2758 | extremely customizable interface. Normally, readline is configured via a | |
2754 | file which defines the behavior of the library; the details of the |
|
2759 | file which defines the behavior of the library; the details of the | |
2755 | syntax for this can be found in the readline documentation available |
|
2760 | syntax for this can be found in the readline documentation available | |
2756 | with your system or on the Internet. IPython doesn't read this file (if |
|
2761 | with your system or on the Internet. IPython doesn't read this file (if | |
2757 | it exists) directly, but it does support passing to readline valid |
|
2762 | it exists) directly, but it does support passing to readline valid | |
2758 | options via a simple interface. In brief, you can customize readline by |
|
2763 | options via a simple interface. In brief, you can customize readline by | |
2759 | setting the following options in your ipythonrc configuration file (note |
|
2764 | setting the following options in your ipythonrc configuration file (note | |
2760 | that these options can not be specified at the command line): |
|
2765 | that these options can not be specified at the command line): | |
2761 |
|
2766 | |||
2762 | * [readline_parse_and_bind:] this option can appear as many times as |
|
2767 | * [readline_parse_and_bind:] this option can appear as many times as | |
2763 | you want, each time defining a string to be executed via a |
|
2768 | you want, each time defining a string to be executed via a | |
2764 | readline.parse_and_bind() command. The syntax for valid commands |
|
2769 | readline.parse_and_bind() command. The syntax for valid commands | |
2765 | of this kind can be found by reading the documentation for the GNU |
|
2770 | of this kind can be found by reading the documentation for the GNU | |
2766 | readline library, as these commands are of the kind which readline |
|
2771 | readline library, as these commands are of the kind which readline | |
2767 | accepts in its configuration file. |
|
2772 | accepts in its configuration file. | |
2768 | * [readline_remove_delims:] a string of characters to be removed |
|
2773 | * [readline_remove_delims:] a string of characters to be removed | |
2769 | from the default word-delimiters list used by readline, so that |
|
2774 | from the default word-delimiters list used by readline, so that | |
2770 | completions may be performed on strings which contain them. Do not |
|
2775 | completions may be performed on strings which contain them. Do not | |
2771 | change the default value unless you know what you're doing. |
|
2776 | change the default value unless you know what you're doing. | |
2772 | * [readline_omit__names:] when tab-completion is enabled, hitting |
|
2777 | * [readline_omit__names:] when tab-completion is enabled, hitting | |
2773 | <tab> after a '.' in a name will complete all attributes of an |
|
2778 | <tab> after a '.' in a name will complete all attributes of an | |
2774 | object, including all the special methods whose names include |
|
2779 | object, including all the special methods whose names include | |
2775 | double underscores (like __getitem__ or __class__). If you'd |
|
2780 | double underscores (like __getitem__ or __class__). If you'd | |
2776 | rather not see these names by default, you can set this option to |
|
2781 | rather not see these names by default, you can set this option to | |
2777 | 1. Note that even when this option is set, you can still see those |
|
2782 | 1. Note that even when this option is set, you can still see those | |
2778 | names by explicitly typing a _ after the period and hitting <tab>: |
|
2783 | names by explicitly typing a _ after the period and hitting <tab>: | |
2779 | 'name._<tab>' will always complete attribute names starting with '_'. |
|
2784 | 'name._<tab>' will always complete attribute names starting with '_'. | |
2780 | * [ ] This option is off by default so that new users see all |
|
2785 | * [ ] This option is off by default so that new users see all | |
2781 | attributes of any objects they are dealing with. |
|
2786 | attributes of any objects they are dealing with. | |
2782 |
|
2787 | |||
2783 | You will find the default values along with a corresponding detailed |
|
2788 | You will find the default values along with a corresponding detailed | |
2784 | explanation in your ipythonrc file. |
|
2789 | explanation in your ipythonrc file. | |
2785 |
|
2790 | |||
2786 |
|
2791 | |||
2787 | Session logging and restoring |
|
2792 | Session logging and restoring | |
2788 | ----------------------------- |
|
2793 | ----------------------------- | |
2789 |
|
2794 | |||
2790 | You can log all input from a session either by starting IPython with the |
|
2795 | You can log all input from a session either by starting IPython with the | |
2791 | command line switches -log or -logfile (see sec. 5.2 |
|
2796 | command line switches -log or -logfile (see sec. 5.2 | |
2792 | <node5.html#sec:cmd-line-opts>)or by activating the logging at any |
|
2797 | <node5.html#sec:cmd-line-opts>)or by activating the logging at any | |
2793 | moment with the magic function %logstart. |
|
2798 | moment with the magic function %logstart. | |
2794 |
|
2799 | |||
2795 | Log files can later be reloaded with the -logplay option and IPython |
|
2800 | Log files can later be reloaded with the -logplay option and IPython | |
2796 | will attempt to 'replay' the log by executing all the lines in it, thus |
|
2801 | will attempt to 'replay' the log by executing all the lines in it, thus | |
2797 | restoring the state of a previous session. This feature is not quite |
|
2802 | restoring the state of a previous session. This feature is not quite | |
2798 | perfect, but can still be useful in many cases. |
|
2803 | perfect, but can still be useful in many cases. | |
2799 |
|
2804 | |||
2800 | The log files can also be used as a way to have a permanent record of |
|
2805 | The log files can also be used as a way to have a permanent record of | |
2801 | any code you wrote while experimenting. Log files are regular text files |
|
2806 | any code you wrote while experimenting. Log files are regular text files | |
2802 | which you can later open in your favorite text editor to extract code or |
|
2807 | which you can later open in your favorite text editor to extract code or | |
2803 | to 'clean them up' before using them to replay a session. |
|
2808 | to 'clean them up' before using them to replay a session. | |
2804 |
|
2809 | |||
2805 | The %logstart function for activating logging in mid-session is used as |
|
2810 | The %logstart function for activating logging in mid-session is used as | |
2806 | follows: |
|
2811 | follows: | |
2807 |
|
2812 | |||
2808 | %logstart [log_name [log_mode]] |
|
2813 | %logstart [log_name [log_mode]] | |
2809 |
|
2814 | |||
2810 | If no name is given, it defaults to a file named 'log' in your |
|
2815 | If no name is given, it defaults to a file named 'log' in your | |
2811 | IPYTHONDIR directory, in 'rotate' mode (see below). |
|
2816 | IPYTHONDIR directory, in 'rotate' mode (see below). | |
2812 |
|
2817 | |||
2813 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your |
|
2818 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your | |
2814 | history up to that point and then continues logging. |
|
2819 | history up to that point and then continues logging. | |
2815 |
|
2820 | |||
2816 | %logstart takes a second optional parameter: logging mode. This can be |
|
2821 | %logstart takes a second optional parameter: logging mode. This can be | |
2817 | one of (note that the modes are given unquoted): |
|
2822 | one of (note that the modes are given unquoted): | |
2818 |
|
2823 | |||
2819 | * [over:] overwrite existing log_name. |
|
2824 | * [over:] overwrite existing log_name. | |
2820 | * [backup:] rename (if exists) to log_name~ and start log_name. |
|
2825 | * [backup:] rename (if exists) to log_name~ and start log_name. | |
2821 | * [append:] well, that says it. |
|
2826 | * [append:] well, that says it. | |
2822 | * [rotate:] create rotating logs log_name.1~, log_name.2~, etc. |
|
2827 | * [rotate:] create rotating logs log_name.1~, log_name.2~, etc. | |
2823 |
|
2828 | |||
2824 | The %logoff and %logon functions allow you to temporarily stop and |
|
2829 | The %logoff and %logon functions allow you to temporarily stop and | |
2825 | resume logging to a file which had previously been started with |
|
2830 | resume logging to a file which had previously been started with | |
2826 | %logstart. They will fail (with an explanation) if you try to use them |
|
2831 | %logstart. They will fail (with an explanation) if you try to use them | |
2827 | before logging has been started. |
|
2832 | before logging has been started. | |
2828 |
|
2833 | |||
2829 |
|
2834 | |||
2830 |
|
2835 | |||
2831 | System shell access |
|
2836 | System shell access | |
2832 | ------------------- |
|
2837 | ------------------- | |
2833 |
|
2838 | |||
2834 | Any input line beginning with a ! character is passed verbatim (minus |
|
2839 | Any input line beginning with a ! character is passed verbatim (minus | |
2835 | the !, of course) to the underlying operating system. For example, |
|
2840 | the !, of course) to the underlying operating system. For example, | |
2836 | typing !ls will run 'ls' in the current directory. |
|
2841 | typing !ls will run 'ls' in the current directory. | |
2837 |
|
2842 | |||
2838 | Manual capture of command output |
|
2843 | Manual capture of command output | |
2839 | -------------------------------- |
|
2844 | -------------------------------- | |
2840 |
|
2845 | |||
2841 | If the input line begins with two exclamation marks, !!, the command is |
|
2846 | If the input line begins with two exclamation marks, !!, the command is | |
2842 | executed but its output is captured and returned as a python list, split |
|
2847 | executed but its output is captured and returned as a python list, split | |
2843 | on newlines. Any output sent by the subprocess to standard error is |
|
2848 | on newlines. Any output sent by the subprocess to standard error is | |
2844 | printed separately, so that the resulting list only captures standard |
|
2849 | printed separately, so that the resulting list only captures standard | |
2845 | output. The !! syntax is a shorthand for the %sx magic command. |
|
2850 | output. The !! syntax is a shorthand for the %sx magic command. | |
2846 |
|
2851 | |||
2847 | Finally, the %sc magic (short for 'shell capture') is similar to %sx, |
|
2852 | Finally, the %sc magic (short for 'shell capture') is similar to %sx, | |
2848 | but allowing more fine-grained control of the capture details, and |
|
2853 | but allowing more fine-grained control of the capture details, and | |
2849 | storing the result directly into a named variable. The direct use of |
|
2854 | storing the result directly into a named variable. The direct use of | |
2850 | %sc is now deprecated, and you should ise the ``var = !cmd`` syntax |
|
2855 | %sc is now deprecated, and you should ise the ``var = !cmd`` syntax | |
2851 | instead. |
|
2856 | instead. | |
2852 |
|
2857 | |||
2853 | IPython also allows you to expand the value of python variables when |
|
2858 | IPython also allows you to expand the value of python variables when | |
2854 | making system calls. Any python variable or expression which you prepend |
|
2859 | making system calls. Any python variable or expression which you prepend | |
2855 | with $ will get expanded before the system call is made:: |
|
2860 | with $ will get expanded before the system call is made:: | |
2856 |
|
2861 | |||
2857 | In [1]: pyvar='Hello world' |
|
2862 | In [1]: pyvar='Hello world' | |
2858 | In [2]: !echo "A python variable: $pyvar" |
|
2863 | In [2]: !echo "A python variable: $pyvar" | |
2859 | A python variable: Hello world |
|
2864 | A python variable: Hello world | |
2860 |
|
2865 | |||
2861 | If you want the shell to actually see a literal $, you need to type it |
|
2866 | If you want the shell to actually see a literal $, you need to type it | |
2862 | twice:: |
|
2867 | twice:: | |
2863 |
|
2868 | |||
2864 | In [3]: !echo "A system variable: $$HOME" |
|
2869 | In [3]: !echo "A system variable: $$HOME" | |
2865 | A system variable: /home/fperez |
|
2870 | A system variable: /home/fperez | |
2866 |
|
2871 | |||
2867 | You can pass arbitrary expressions, though you'll need to delimit them |
|
2872 | You can pass arbitrary expressions, though you'll need to delimit them | |
2868 | with {} if there is ambiguity as to the extent of the expression:: |
|
2873 | with {} if there is ambiguity as to the extent of the expression:: | |
2869 |
|
2874 | |||
2870 | In [5]: x=10 |
|
2875 | In [5]: x=10 | |
2871 | In [6]: y=20 |
|
2876 | In [6]: y=20 | |
2872 | In [13]: !echo $x+y |
|
2877 | In [13]: !echo $x+y | |
2873 | 10+y |
|
2878 | 10+y | |
2874 | In [7]: !echo ${x+y} |
|
2879 | In [7]: !echo ${x+y} | |
2875 | 30 |
|
2880 | 30 | |
2876 |
|
2881 | |||
2877 | Even object attributes can be expanded:: |
|
2882 | Even object attributes can be expanded:: | |
2878 |
|
2883 | |||
2879 | In [12]: !echo $sys.argv |
|
2884 | In [12]: !echo $sys.argv | |
2880 | [/home/fperez/usr/bin/ipython] |
|
2885 | [/home/fperez/usr/bin/ipython] | |
2881 |
|
2886 | |||
2882 |
|
2887 | |||
2883 | System command aliases |
|
2888 | System command aliases | |
2884 | ---------------------- |
|
2889 | ---------------------- | |
2885 |
|
2890 | |||
2886 | The %alias magic function and the alias option in the ipythonrc |
|
2891 | The %alias magic function and the alias option in the ipythonrc | |
2887 | configuration file allow you to define magic functions which are in fact |
|
2892 | configuration file allow you to define magic functions which are in fact | |
2888 | system shell commands. These aliases can have parameters. |
|
2893 | system shell commands. These aliases can have parameters. | |
2889 |
|
2894 | |||
2890 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' |
|
2895 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' | |
2891 |
|
2896 | |||
2892 | Then, typing '%alias_name params' will execute the system command 'cmd |
|
2897 | Then, typing '%alias_name params' will execute the system command 'cmd | |
2893 | params' (from your underlying operating system). |
|
2898 | params' (from your underlying operating system). | |
2894 |
|
2899 | |||
2895 | You can also define aliases with parameters using %s specifiers (one per |
|
2900 | You can also define aliases with parameters using %s specifiers (one per | |
2896 | parameter). The following example defines the %parts function as an |
|
2901 | parameter). The following example defines the %parts function as an | |
2897 | alias to the command 'echo first %s second %s' where each %s will be |
|
2902 | alias to the command 'echo first %s second %s' where each %s will be | |
2898 | replaced by a positional parameter to the call to %parts:: |
|
2903 | replaced by a positional parameter to the call to %parts:: | |
2899 |
|
2904 | |||
2900 | In [1]: alias parts echo first %s second %s |
|
2905 | In [1]: alias parts echo first %s second %s | |
2901 | In [2]: %parts A B |
|
2906 | In [2]: %parts A B | |
2902 | first A second B |
|
2907 | first A second B | |
2903 | In [3]: %parts A |
|
2908 | In [3]: %parts A | |
2904 | Incorrect number of arguments: 2 expected. |
|
2909 | Incorrect number of arguments: 2 expected. | |
2905 | parts is an alias to: 'echo first %s second %s' |
|
2910 | parts is an alias to: 'echo first %s second %s' | |
2906 |
|
2911 | |||
2907 | If called with no parameters, %alias prints the table of currently |
|
2912 | If called with no parameters, %alias prints the table of currently | |
2908 | defined aliases. |
|
2913 | defined aliases. | |
2909 |
|
2914 | |||
2910 | The %rehash/rehashx magics allow you to load your entire $PATH as |
|
2915 | The %rehash/rehashx magics allow you to load your entire $PATH as | |
2911 | ipython aliases. See their respective docstrings (or sec. 6.2 |
|
2916 | ipython aliases. See their respective docstrings (or sec. 6.2 | |
2912 | <#sec:magic> for further details). |
|
2917 | <#sec:magic> for further details). | |
2913 |
|
2918 | |||
2914 |
|
2919 | |||
2915 |
|
2920 | |||
2916 | Recursive reload |
|
2921 | Recursive reload | |
2917 | ---------------- |
|
2922 | ---------------- | |
2918 |
|
2923 | |||
2919 | The dreload function does a recursive reload of a module: changes made |
|
2924 | The dreload function does a recursive reload of a module: changes made | |
2920 | to the module since you imported will actually be available without |
|
2925 | to the module since you imported will actually be available without | |
2921 | having to exit. |
|
2926 | having to exit. | |
2922 |
|
2927 | |||
2923 |
|
2928 | |||
2924 | Verbose and colored exception traceback printouts |
|
2929 | Verbose and colored exception traceback printouts | |
2925 | ------------------------------------------------- |
|
2930 | ------------------------------------------------- | |
2926 |
|
2931 | |||
2927 | IPython provides the option to see very detailed exception tracebacks, |
|
2932 | IPython provides the option to see very detailed exception tracebacks, | |
2928 | which can be especially useful when debugging large programs. You can |
|
2933 | which can be especially useful when debugging large programs. You can | |
2929 | run any Python file with the %run function to benefit from these |
|
2934 | run any Python file with the %run function to benefit from these | |
2930 | detailed tracebacks. Furthermore, both normal and verbose tracebacks can |
|
2935 | detailed tracebacks. Furthermore, both normal and verbose tracebacks can | |
2931 | be colored (if your terminal supports it) which makes them much easier |
|
2936 | be colored (if your terminal supports it) which makes them much easier | |
2932 | to parse visually. |
|
2937 | to parse visually. | |
2933 |
|
2938 | |||
2934 | See the magic xmode and colors functions for details (just type %magic). |
|
2939 | See the magic xmode and colors functions for details (just type %magic). | |
2935 |
|
2940 | |||
2936 | These features are basically a terminal version of Ka-Ping Yee's cgitb |
|
2941 | These features are basically a terminal version of Ka-Ping Yee's cgitb | |
2937 | module, now part of the standard Python library. |
|
2942 | module, now part of the standard Python library. | |
2938 |
|
2943 | |||
2939 |
|
2944 | |||
2940 |
|
2945 | |||
2941 | Input caching system |
|
2946 | Input caching system | |
2942 | -------------------- |
|
2947 | -------------------- | |
2943 |
|
2948 | |||
2944 | IPython offers numbered prompts (In/Out) with input and output caching. |
|
2949 | IPython offers numbered prompts (In/Out) with input and output caching. | |
2945 | All input is saved and can be retrieved as variables (besides the usual |
|
2950 | All input is saved and can be retrieved as variables (besides the usual | |
2946 | arrow key recall). |
|
2951 | arrow key recall). | |
2947 |
|
2952 | |||
2948 | The following GLOBAL variables always exist (so don't overwrite them!): |
|
2953 | The following GLOBAL variables always exist (so don't overwrite them!): | |
2949 | _i: stores previous input. _ii: next previous. _iii: next-next previous. |
|
2954 | _i: stores previous input. _ii: next previous. _iii: next-next previous. | |
2950 | _ih : a list of all input _ih[n] is the input from line n and this list |
|
2955 | _ih : a list of all input _ih[n] is the input from line n and this list | |
2951 | is aliased to the global variable In. If you overwrite In with a |
|
2956 | is aliased to the global variable In. If you overwrite In with a | |
2952 | variable of your own, you can remake the assignment to the internal list |
|
2957 | variable of your own, you can remake the assignment to the internal list | |
2953 | with a simple 'In=_ih'. |
|
2958 | with a simple 'In=_ih'. | |
2954 |
|
2959 | |||
2955 | Additionally, global variables named _i<n> are dynamically created (<n> |
|
2960 | Additionally, global variables named _i<n> are dynamically created (<n> | |
2956 | being the prompt counter), such that |
|
2961 | being the prompt counter), such that | |
2957 | _i<n> == _ih[<n>] == In[<n>]. |
|
2962 | _i<n> == _ih[<n>] == In[<n>]. | |
2958 |
|
2963 | |||
2959 | For example, what you typed at prompt 14 is available as _i14, _ih[14] |
|
2964 | For example, what you typed at prompt 14 is available as _i14, _ih[14] | |
2960 | and In[14]. |
|
2965 | and In[14]. | |
2961 |
|
2966 | |||
2962 | This allows you to easily cut and paste multi line interactive prompts |
|
2967 | This allows you to easily cut and paste multi line interactive prompts | |
2963 | by printing them out: they print like a clean string, without prompt |
|
2968 | by printing them out: they print like a clean string, without prompt | |
2964 | characters. You can also manipulate them like regular variables (they |
|
2969 | characters. You can also manipulate them like regular variables (they | |
2965 | are strings), modify or exec them (typing 'exec _i9' will re-execute the |
|
2970 | are strings), modify or exec them (typing 'exec _i9' will re-execute the | |
2966 | contents of input prompt 9, 'exec In[9:14]+In[18]' will re-execute lines |
|
2971 | contents of input prompt 9, 'exec In[9:14]+In[18]' will re-execute lines | |
2967 | 9 through 13 and line 18). |
|
2972 | 9 through 13 and line 18). | |
2968 |
|
2973 | |||
2969 | You can also re-execute multiple lines of input easily by using the |
|
2974 | You can also re-execute multiple lines of input easily by using the | |
2970 | magic %macro function (which automates the process and allows |
|
2975 | magic %macro function (which automates the process and allows | |
2971 | re-execution without having to type 'exec' every time). The macro system |
|
2976 | re-execution without having to type 'exec' every time). The macro system | |
2972 | also allows you to re-execute previous lines which include magic |
|
2977 | also allows you to re-execute previous lines which include magic | |
2973 | function calls (which require special processing). Type %macro? or see |
|
2978 | function calls (which require special processing). Type %macro? or see | |
2974 | sec. 6.2 <#sec:magic> for more details on the macro system. |
|
2979 | sec. 6.2 <#sec:magic> for more details on the macro system. | |
2975 |
|
2980 | |||
2976 | A history function %hist allows you to see any part of your input |
|
2981 | A history function %hist allows you to see any part of your input | |
2977 | history by printing a range of the _i variables. |
|
2982 | history by printing a range of the _i variables. | |
2978 |
|
2983 | |||
2979 | Output caching system |
|
2984 | Output caching system | |
2980 | --------------------- |
|
2985 | --------------------- | |
2981 |
|
2986 | |||
2982 | For output that is returned from actions, a system similar to the input |
|
2987 | For output that is returned from actions, a system similar to the input | |
2983 | cache exists but using _ instead of _i. Only actions that produce a |
|
2988 | cache exists but using _ instead of _i. Only actions that produce a | |
2984 | result (NOT assignments, for example) are cached. If you are familiar |
|
2989 | result (NOT assignments, for example) are cached. If you are familiar | |
2985 | with Mathematica, IPython's _ variables behave exactly like |
|
2990 | with Mathematica, IPython's _ variables behave exactly like | |
2986 | Mathematica's % variables. |
|
2991 | Mathematica's % variables. | |
2987 |
|
2992 | |||
2988 | The following GLOBAL variables always exist (so don't overwrite them!): |
|
2993 | The following GLOBAL variables always exist (so don't overwrite them!): | |
2989 |
|
2994 | |||
2990 | * [_] (a single underscore) : stores previous output, like Python's |
|
2995 | * [_] (a single underscore) : stores previous output, like Python's | |
2991 | default interpreter. |
|
2996 | default interpreter. | |
2992 | * [__] (two underscores): next previous. |
|
2997 | * [__] (two underscores): next previous. | |
2993 | * [___] (three underscores): next-next previous. |
|
2998 | * [___] (three underscores): next-next previous. | |
2994 |
|
2999 | |||
2995 | Additionally, global variables named _<n> are dynamically created (<n> |
|
3000 | Additionally, global variables named _<n> are dynamically created (<n> | |
2996 | being the prompt counter), such that the result of output <n> is always |
|
3001 | being the prompt counter), such that the result of output <n> is always | |
2997 | available as _<n> (don't use the angle brackets, just the number, e.g. |
|
3002 | available as _<n> (don't use the angle brackets, just the number, e.g. | |
2998 | _21). |
|
3003 | _21). | |
2999 |
|
3004 | |||
3000 | These global variables are all stored in a global dictionary (not a |
|
3005 | These global variables are all stored in a global dictionary (not a | |
3001 | list, since it only has entries for lines which returned a result) |
|
3006 | list, since it only has entries for lines which returned a result) | |
3002 | available under the names _oh and Out (similar to _ih and In). So the |
|
3007 | available under the names _oh and Out (similar to _ih and In). So the | |
3003 | output from line 12 can be obtained as _12, Out[12] or _oh[12]. If you |
|
3008 | output from line 12 can be obtained as _12, Out[12] or _oh[12]. If you | |
3004 | accidentally overwrite the Out variable you can recover it by typing |
|
3009 | accidentally overwrite the Out variable you can recover it by typing | |
3005 | 'Out=_oh' at the prompt. |
|
3010 | 'Out=_oh' at the prompt. | |
3006 |
|
3011 | |||
3007 | This system obviously can potentially put heavy memory demands on your |
|
3012 | This system obviously can potentially put heavy memory demands on your | |
3008 | system, since it prevents Python's garbage collector from removing any |
|
3013 | system, since it prevents Python's garbage collector from removing any | |
3009 | previously computed results. You can control how many results are kept |
|
3014 | previously computed results. You can control how many results are kept | |
3010 | in memory with the option (at the command line or in your ipythonrc |
|
3015 | in memory with the option (at the command line or in your ipythonrc | |
3011 | file) cache_size. If you set it to 0, the whole system is completely |
|
3016 | file) cache_size. If you set it to 0, the whole system is completely | |
3012 | disabled and the prompts revert to the classic '>>>' of normal Python. |
|
3017 | disabled and the prompts revert to the classic '>>>' of normal Python. | |
3013 |
|
3018 | |||
3014 |
|
3019 | |||
3015 | Directory history |
|
3020 | Directory history | |
3016 | ----------------- |
|
3021 | ----------------- | |
3017 |
|
3022 | |||
3018 | Your history of visited directories is kept in the global list _dh, and |
|
3023 | Your history of visited directories is kept in the global list _dh, and | |
3019 | the magic %cd command can be used to go to any entry in that list. The |
|
3024 | the magic %cd command can be used to go to any entry in that list. The | |
3020 | %dhist command allows you to view this history. do ``cd -<TAB`` to |
|
3025 | %dhist command allows you to view this history. do ``cd -<TAB`` to | |
3021 | conventiently view the directory history. |
|
3026 | conventiently view the directory history. | |
3022 |
|
3027 | |||
3023 |
|
3028 | |||
3024 | Automatic parentheses and quotes |
|
3029 | Automatic parentheses and quotes | |
3025 | -------------------------------- |
|
3030 | -------------------------------- | |
3026 |
|
3031 | |||
3027 | These features were adapted from Nathan Gray's LazyPython. They are |
|
3032 | These features were adapted from Nathan Gray's LazyPython. They are | |
3028 | meant to allow less typing for common situations. |
|
3033 | meant to allow less typing for common situations. | |
3029 |
|
3034 | |||
3030 |
|
3035 | |||
3031 | Automatic parentheses |
|
3036 | Automatic parentheses | |
3032 | --------------------- |
|
3037 | --------------------- | |
3033 |
|
3038 | |||
3034 | Callable objects (i.e. functions, methods, etc) can be invoked like this |
|
3039 | Callable objects (i.e. functions, methods, etc) can be invoked like this | |
3035 | (notice the commas between the arguments):: |
|
3040 | (notice the commas between the arguments):: | |
3036 |
|
3041 | |||
3037 | >>> callable_ob arg1, arg2, arg3 |
|
3042 | >>> callable_ob arg1, arg2, arg3 | |
3038 |
|
3043 | |||
3039 | and the input will be translated to this:: |
|
3044 | and the input will be translated to this:: | |
3040 |
|
3045 | |||
3041 | -> callable_ob(arg1, arg2, arg3) |
|
3046 | -> callable_ob(arg1, arg2, arg3) | |
3042 |
|
3047 | |||
3043 | You can force automatic parentheses by using '/' as the first character |
|
3048 | You can force automatic parentheses by using '/' as the first character | |
3044 | of a line. For example:: |
|
3049 | of a line. For example:: | |
3045 |
|
3050 | |||
3046 | >>> /globals # becomes 'globals()' |
|
3051 | >>> /globals # becomes 'globals()' | |
3047 |
|
3052 | |||
3048 | Note that the '/' MUST be the first character on the line! This won't work:: |
|
3053 | Note that the '/' MUST be the first character on the line! This won't work:: | |
3049 |
|
3054 | |||
3050 | >>> print /globals # syntax error |
|
3055 | >>> print /globals # syntax error | |
3051 |
|
3056 | |||
3052 | In most cases the automatic algorithm should work, so you should rarely |
|
3057 | In most cases the automatic algorithm should work, so you should rarely | |
3053 | need to explicitly invoke /. One notable exception is if you are trying |
|
3058 | need to explicitly invoke /. One notable exception is if you are trying | |
3054 | to call a function with a list of tuples as arguments (the parenthesis |
|
3059 | to call a function with a list of tuples as arguments (the parenthesis | |
3055 | will confuse IPython):: |
|
3060 | will confuse IPython):: | |
3056 |
|
3061 | |||
3057 | In [1]: zip (1,2,3),(4,5,6) # won't work |
|
3062 | In [1]: zip (1,2,3),(4,5,6) # won't work | |
3058 |
|
3063 | |||
3059 | but this will work:: |
|
3064 | but this will work:: | |
3060 |
|
3065 | |||
3061 | In [2]: /zip (1,2,3),(4,5,6) |
|
3066 | In [2]: /zip (1,2,3),(4,5,6) | |
3062 | ---> zip ((1,2,3),(4,5,6)) |
|
3067 | ---> zip ((1,2,3),(4,5,6)) | |
3063 | Out[2]= [(1, 4), (2, 5), (3, 6)] |
|
3068 | Out[2]= [(1, 4), (2, 5), (3, 6)] | |
3064 |
|
3069 | |||
3065 | IPython tells you that it has altered your command line by displaying |
|
3070 | IPython tells you that it has altered your command line by displaying | |
3066 | the new command line preceded by ->. e.g.:: |
|
3071 | the new command line preceded by ->. e.g.:: | |
3067 |
|
3072 | |||
3068 | In [18]: callable list |
|
3073 | In [18]: callable list | |
3069 | ----> callable (list) |
|
3074 | ----> callable (list) | |
3070 |
|
3075 | |||
3071 |
|
3076 | |||
3072 | Automatic quoting |
|
3077 | Automatic quoting | |
3073 | ----------------- |
|
3078 | ----------------- | |
3074 |
|
3079 | |||
3075 | You can force automatic quoting of a function's arguments by using ',' |
|
3080 | You can force automatic quoting of a function's arguments by using ',' | |
3076 | or ';' as the first character of a line. For example:: |
|
3081 | or ';' as the first character of a line. For example:: | |
3077 |
|
3082 | |||
3078 | >>> ,my_function /home/me # becomes my_function("/home/me") |
|
3083 | >>> ,my_function /home/me # becomes my_function("/home/me") | |
3079 |
|
3084 | |||
3080 | If you use ';' instead, the whole argument is quoted as a single string |
|
3085 | If you use ';' instead, the whole argument is quoted as a single string | |
3081 | (while ',' splits on whitespace):: |
|
3086 | (while ',' splits on whitespace):: | |
3082 |
|
3087 | |||
3083 | >>> ,my_function a b c # becomes my_function("a","b","c") |
|
3088 | >>> ,my_function a b c # becomes my_function("a","b","c") | |
3084 |
|
3089 | |||
3085 | >>> ;my_function a b c # becomes my_function("a b c") |
|
3090 | >>> ;my_function a b c # becomes my_function("a b c") | |
3086 |
|
3091 | |||
3087 | Note that the ',' or ';' MUST be the first character on the line! This |
|
3092 | Note that the ',' or ';' MUST be the first character on the line! This | |
3088 | won't work:: |
|
3093 | won't work:: | |
3089 |
|
3094 | |||
3090 | >>> x = ,my_function /home/me # syntax error |
|
3095 | >>> x = ,my_function /home/me # syntax error | |
3091 |
|
3096 | |||
3092 | Customization |
|
3097 | Customization | |
3093 | ============= |
|
3098 | ============= | |
3094 |
|
3099 | |||
|
3100 | There are 2 ways to configure IPython - the old way of using ipythonrc | |||
|
3101 | files (an INI-file like format), and the new way that involves editing | |||
|
3102 | your ipy_user_conf.py. Both configuration systems work at the same | |||
|
3103 | time, so you can set your options in both, but if you are hesitating | |||
|
3104 | about which alternative to choose, we recommend the ipy_user_conf.py | |||
|
3105 | approach, as it will give you more power and control in the long | |||
|
3106 | run. However, there are few options such as pylab_import_all that can | |||
|
3107 | only be specified in ipythonrc file or command line - the reason for | |||
|
3108 | this is that they are needed before IPython has been started up, and | |||
|
3109 | the IPApi object used in ipy_user_conf.py is not yet available at that | |||
|
3110 | time. A hybrid approach of specifying a few options in ipythonrc and | |||
|
3111 | doing the more advanced configuration in ipy_user_conf.py is also | |||
|
3112 | possible. | |||
|
3113 | ||||
|
3114 | The ipythonrc approach | |||
|
3115 | ---------------------- | |||
|
3116 | ||||
3095 | As we've already mentioned, IPython reads a configuration file which can |
|
3117 | As we've already mentioned, IPython reads a configuration file which can | |
3096 | be specified at the command line (-rcfile) or which by default is |
|
3118 | be specified at the command line (-rcfile) or which by default is | |
3097 | assumed to be called ipythonrc. Such a file is looked for in the current |
|
3119 | assumed to be called ipythonrc. Such a file is looked for in the current | |
3098 | directory where IPython is started and then in your IPYTHONDIR, which |
|
3120 | directory where IPython is started and then in your IPYTHONDIR, which | |
3099 | allows you to have local configuration files for specific projects. In |
|
3121 | allows you to have local configuration files for specific projects. In | |
3100 | this section we will call these types of configuration files simply |
|
3122 | this section we will call these types of configuration files simply | |
3101 | rcfiles (short for resource configuration file). |
|
3123 | rcfiles (short for resource configuration file). | |
3102 |
|
3124 | |||
3103 | The syntax of an rcfile is one of key-value pairs separated by |
|
3125 | The syntax of an rcfile is one of key-value pairs separated by | |
3104 | whitespace, one per line. Lines beginning with a # are ignored as |
|
3126 | whitespace, one per line. Lines beginning with a # are ignored as | |
3105 | comments, but comments can not be put on lines with data (the parser is |
|
3127 | comments, but comments can not be put on lines with data (the parser is | |
3106 | fairly primitive). Note that these are not python files, and this is |
|
3128 | fairly primitive). Note that these are not python files, and this is | |
3107 | deliberate, because it allows us to do some things which would be quite |
|
3129 | deliberate, because it allows us to do some things which would be quite | |
3108 | tricky to implement if they were normal python files. |
|
3130 | tricky to implement if they were normal python files. | |
3109 |
|
3131 | |||
3110 | First, an rcfile can contain permanent default values for almost all |
|
3132 | First, an rcfile can contain permanent default values for almost all | |
3111 | command line options (except things like -help or -Version). Sec 5.2 |
|
3133 | command line options (except things like -help or -Version). Sec 5.2 | |
3112 | <node5.html#sec:cmd-line-opts> contains a description of all |
|
3134 | <node5.html#sec:cmd-line-opts> contains a description of all | |
3113 | command-line options. However, values you explicitly specify at the |
|
3135 | command-line options. However, values you explicitly specify at the | |
3114 | command line override the values defined in the rcfile. |
|
3136 | command line override the values defined in the rcfile. | |
3115 |
|
3137 | |||
3116 | Besides command line option values, the rcfile can specify values for |
|
3138 | Besides command line option values, the rcfile can specify values for | |
3117 | certain extra special options which are not available at the command |
|
3139 | certain extra special options which are not available at the command | |
3118 | line. These options are briefly described below. |
|
3140 | line. These options are briefly described below. | |
3119 |
|
3141 | |||
3120 | Each of these options may appear as many times as you need it in the file. |
|
3142 | Each of these options may appear as many times as you need it in the file. | |
3121 |
|
3143 | |||
3122 | * [include <file1> <file2> ...:] you can name other rcfiles you want |
|
3144 | * [include <file1> <file2> ...:] you can name other rcfiles you want | |
3123 | to recursively load up to 15 levels (don't use the <> brackets in |
|
3145 | to recursively load up to 15 levels (don't use the <> brackets in | |
3124 | your names!). This feature allows you to define a 'base' rcfile |
|
3146 | your names!). This feature allows you to define a 'base' rcfile | |
3125 | with general options and special-purpose files which can be loaded |
|
3147 | with general options and special-purpose files which can be loaded | |
3126 | only when needed with particular configuration options. To make |
|
3148 | only when needed with particular configuration options. To make | |
3127 | this more convenient, IPython accepts the -profile <name> option |
|
3149 | this more convenient, IPython accepts the -profile <name> option | |
3128 | (abbreviates to -p <name>) which tells it to look for an rcfile |
|
3150 | (abbreviates to -p <name>) which tells it to look for an rcfile | |
3129 | named ipythonrc-<name>. |
|
3151 | named ipythonrc-<name>. | |
3130 | * [import_mod <mod1> <mod2> ...:] import modules with 'import |
|
3152 | * [import_mod <mod1> <mod2> ...:] import modules with 'import | |
3131 | <mod1>,<mod2>,...' |
|
3153 | <mod1>,<mod2>,...' | |
3132 | * [import_some <mod> <f1> <f2> ...:] import functions with 'from |
|
3154 | * [import_some <mod> <f1> <f2> ...:] import functions with 'from | |
3133 | <mod> import <f1>,<f2>,...' |
|
3155 | <mod> import <f1>,<f2>,...' | |
3134 | * [import_all <mod1> <mod2> ...:] for each module listed import |
|
3156 | * [import_all <mod1> <mod2> ...:] for each module listed import | |
3135 | functions with ``from <mod> import *``. |
|
3157 | functions with ``from <mod> import *``. | |
3136 | * [execute <python code>:] give any single-line python code to be |
|
3158 | * [execute <python code>:] give any single-line python code to be | |
3137 | executed. |
|
3159 | executed. | |
3138 | * [execfile <filename>:] execute the python file given with an |
|
3160 | * [execfile <filename>:] execute the python file given with an | |
3139 | 'execfile(filename)' command. Username expansion is performed on |
|
3161 | 'execfile(filename)' command. Username expansion is performed on | |
3140 | the given names. So if you need any amount of extra fancy |
|
3162 | the given names. So if you need any amount of extra fancy | |
3141 | customization that won't fit in any of the above 'canned' options, |
|
3163 | customization that won't fit in any of the above 'canned' options, | |
3142 | you can just put it in a separate python file and execute it. |
|
3164 | you can just put it in a separate python file and execute it. | |
3143 | * [alias <alias_def>:] this is equivalent to calling |
|
3165 | * [alias <alias_def>:] this is equivalent to calling | |
3144 | '%alias <alias_def>' at the IPython command line. This way, from |
|
3166 | '%alias <alias_def>' at the IPython command line. This way, from | |
3145 | within IPython you can do common system tasks without having to |
|
3167 | within IPython you can do common system tasks without having to | |
3146 | exit it or use the ! escape. IPython isn't meant to be a shell |
|
3168 | exit it or use the ! escape. IPython isn't meant to be a shell | |
3147 | replacement, but it is often very useful to be able to do things |
|
3169 | replacement, but it is often very useful to be able to do things | |
3148 | with files while testing code. This gives you the flexibility to |
|
3170 | with files while testing code. This gives you the flexibility to | |
3149 | have within IPython any aliases you may be used to under your |
|
3171 | have within IPython any aliases you may be used to under your | |
3150 | normal system shell. |
|
3172 | normal system shell. | |
3151 |
|
3173 | |||
3152 |
|
3174 | |||
3153 |
|
||||
3154 | Sample ipythonrc file |
|
3175 | Sample ipythonrc file | |
3155 | --------------------- |
|
3176 | --------------------- | |
3156 |
|
3177 | |||
3157 | The default rcfile, called ipythonrc and supplied in your IPYTHONDIR |
|
3178 | The default rcfile, called ipythonrc and supplied in your IPYTHONDIR | |
3158 | directory contains lots of comments on all of these options. We |
|
3179 | directory contains lots of comments on all of these options. We | |
3159 | reproduce it here for reference:: |
|
3180 | reproduce it here for reference:: | |
3160 |
|
3181 | |||
3161 |
|
3182 | |||
3162 | # -*- Mode: Shell-Script -*- Not really, but shows comments correctly |
|
3183 | # -*- Mode: Shell-Script -*- Not really, but shows comments correctly | |
3163 | # $Id: ipythonrc 2156 2007-03-19 02:32:19Z fperez $ |
|
3184 | # $Id: ipythonrc 2156 2007-03-19 02:32:19Z fperez $ | |
3164 |
|
3185 | |||
3165 | #*************************************************************************** |
|
3186 | #*************************************************************************** | |
3166 | # |
|
3187 | # | |
3167 | # Configuration file for IPython -- ipythonrc format |
|
3188 | # Configuration file for IPython -- ipythonrc format | |
3168 | # |
|
3189 | # | |
3169 | # =========================================================== |
|
3190 | # =========================================================== | |
3170 | # Deprecation note: you should look into modifying ipy_user_conf.py (located |
|
3191 | # Deprecation note: you should look into modifying ipy_user_conf.py (located | |
3171 | # in ~/.ipython or ~/_ipython, depending on your platform) instead, it's a |
|
3192 | # in ~/.ipython or ~/_ipython, depending on your platform) instead, it's a | |
3172 | # more flexible and robust (and better supported!) configuration |
|
3193 | # more flexible and robust (and better supported!) configuration | |
3173 | # method. |
|
3194 | # method. | |
3174 | # =========================================================== |
|
3195 | # =========================================================== | |
3175 | # |
|
3196 | # | |
3176 | # The format of this file is simply one of 'key value' lines. |
|
3197 | # The format of this file is simply one of 'key value' lines. | |
3177 | # Lines containing only whitespace at the beginning and then a # are ignored |
|
3198 | # Lines containing only whitespace at the beginning and then a # are ignored | |
3178 | # as comments. But comments can NOT be put on lines with data. |
|
3199 | # as comments. But comments can NOT be put on lines with data. | |
3179 |
|
3200 | |||
3180 | # The meaning and use of each key are explained below. |
|
3201 | # The meaning and use of each key are explained below. | |
3181 |
|
3202 | |||
3182 | #--------------------------------------------------------------------------- |
|
3203 | #--------------------------------------------------------------------------- | |
3183 | # Section: included files |
|
3204 | # Section: included files | |
3184 |
|
3205 | |||
3185 | # Put one or more *config* files (with the syntax of this file) you want to |
|
3206 | # Put one or more *config* files (with the syntax of this file) you want to | |
3186 | # include. For keys with a unique value the outermost file has precedence. For |
|
3207 | # include. For keys with a unique value the outermost file has precedence. For | |
3187 | # keys with multiple values, they all get assembled into a list which then |
|
3208 | # keys with multiple values, they all get assembled into a list which then | |
3188 | # gets loaded by IPython. |
|
3209 | # gets loaded by IPython. | |
3189 |
|
3210 | |||
3190 | # In this file, all lists of things should simply be space-separated. |
|
3211 | # In this file, all lists of things should simply be space-separated. | |
3191 |
|
3212 | |||
3192 | # This allows you to build hierarchies of files which recursively load |
|
3213 | # This allows you to build hierarchies of files which recursively load | |
3193 | # lower-level services. If this is your main ~/.ipython/ipythonrc file, you |
|
3214 | # lower-level services. If this is your main ~/.ipython/ipythonrc file, you | |
3194 | # should only keep here basic things you always want available. Then you can |
|
3215 | # should only keep here basic things you always want available. Then you can | |
3195 | # include it in every other special-purpose config file you create. |
|
3216 | # include it in every other special-purpose config file you create. | |
3196 | include |
|
3217 | include | |
3197 |
|
3218 | |||
3198 | #--------------------------------------------------------------------------- |
|
3219 | #--------------------------------------------------------------------------- | |
3199 | # Section: startup setup |
|
3220 | # Section: startup setup | |
3200 |
|
3221 | |||
3201 | # These are mostly things which parallel a command line option of the same |
|
3222 | # These are mostly things which parallel a command line option of the same | |
3202 | # name. |
|
3223 | # name. | |
3203 |
|
3224 | |||
3204 | # Keys in this section should only appear once. If any key from this section |
|
3225 | # Keys in this section should only appear once. If any key from this section | |
3205 | # is encountered more than once, the last value remains, all earlier ones get |
|
3226 | # is encountered more than once, the last value remains, all earlier ones get | |
3206 | # discarded. |
|
3227 | # discarded. | |
3207 |
|
3228 | |||
3208 |
|
3229 | |||
3209 | # Automatic calling of callable objects. If set to 1 or 2, callable objects |
|
3230 | # Automatic calling of callable objects. If set to 1 or 2, callable objects | |
3210 | # are automatically called when invoked at the command line, even if you don't |
|
3231 | # are automatically called when invoked at the command line, even if you don't | |
3211 | # type parentheses. IPython adds the parentheses for you. For example: |
|
3232 | # type parentheses. IPython adds the parentheses for you. For example: | |
3212 |
|
3233 | |||
3213 | #In [1]: str 45 |
|
3234 | #In [1]: str 45 | |
3214 | #------> str(45) |
|
3235 | #------> str(45) | |
3215 | #Out[1]: '45' |
|
3236 | #Out[1]: '45' | |
3216 |
|
3237 | |||
3217 | # IPython reprints your line with '---->' indicating that it added |
|
3238 | # IPython reprints your line with '---->' indicating that it added | |
3218 | # parentheses. While this option is very convenient for interactive use, it |
|
3239 | # parentheses. While this option is very convenient for interactive use, it | |
3219 | # may occasionally cause problems with objects which have side-effects if |
|
3240 | # may occasionally cause problems with objects which have side-effects if | |
3220 | # called unexpectedly. |
|
3241 | # called unexpectedly. | |
3221 |
|
3242 | |||
3222 | # The valid values for autocall are: |
|
3243 | # The valid values for autocall are: | |
3223 |
|
3244 | |||
3224 | # autocall 0 -> disabled (you can toggle it at runtime with the %autocall magic) |
|
3245 | # autocall 0 -> disabled (you can toggle it at runtime with the %autocall magic) | |
3225 |
|
3246 | |||
3226 | # autocall 1 -> active, but do not apply if there are no arguments on the line. |
|
3247 | # autocall 1 -> active, but do not apply if there are no arguments on the line. | |
3227 |
|
3248 | |||
3228 | # In this mode, you get: |
|
3249 | # In this mode, you get: | |
3229 |
|
3250 | |||
3230 | #In [1]: callable |
|
3251 | #In [1]: callable | |
3231 | #Out[1]: <built-in function callable> |
|
3252 | #Out[1]: <built-in function callable> | |
3232 |
|
3253 | |||
3233 | #In [2]: callable 'hello' |
|
3254 | #In [2]: callable 'hello' | |
3234 | #------> callable('hello') |
|
3255 | #------> callable('hello') | |
3235 | #Out[2]: False |
|
3256 | #Out[2]: False | |
3236 |
|
3257 | |||
3237 | # 2 -> Active always. Even if no arguments are present, the callable object |
|
3258 | # 2 -> Active always. Even if no arguments are present, the callable object | |
3238 | # is called: |
|
3259 | # is called: | |
3239 |
|
3260 | |||
3240 | #In [4]: callable |
|
3261 | #In [4]: callable | |
3241 | #------> callable() |
|
3262 | #------> callable() | |
3242 |
|
3263 | |||
3243 | # Note that even with autocall off, you can still use '/' at the start of a |
|
3264 | # Note that even with autocall off, you can still use '/' at the start of a | |
3244 | # line to treat the first argument on the command line as a function and add |
|
3265 | # line to treat the first argument on the command line as a function and add | |
3245 | # parentheses to it: |
|
3266 | # parentheses to it: | |
3246 |
|
3267 | |||
3247 | #In [8]: /str 43 |
|
3268 | #In [8]: /str 43 | |
3248 | #------> str(43) |
|
3269 | #------> str(43) | |
3249 | #Out[8]: '43' |
|
3270 | #Out[8]: '43' | |
3250 |
|
3271 | |||
3251 | autocall 1 |
|
3272 | autocall 1 | |
3252 |
|
3273 | |||
3253 | # Auto-edit syntax errors. When you use the %edit magic in ipython to edit |
|
3274 | # Auto-edit syntax errors. When you use the %edit magic in ipython to edit | |
3254 | # source code (see the 'editor' variable below), it is possible that you save |
|
3275 | # source code (see the 'editor' variable below), it is possible that you save | |
3255 | # a file with syntax errors in it. If this variable is true, IPython will ask |
|
3276 | # a file with syntax errors in it. If this variable is true, IPython will ask | |
3256 | # you whether to re-open the editor immediately to correct such an error. |
|
3277 | # you whether to re-open the editor immediately to correct such an error. | |
3257 |
|
3278 | |||
3258 | autoedit_syntax 0 |
|
3279 | autoedit_syntax 0 | |
3259 |
|
3280 | |||
3260 | # Auto-indent. IPython can recognize lines ending in ':' and indent the next |
|
3281 | # Auto-indent. IPython can recognize lines ending in ':' and indent the next | |
3261 | # line, while also un-indenting automatically after 'raise' or 'return'. |
|
3282 | # line, while also un-indenting automatically after 'raise' or 'return'. | |
3262 |
|
3283 | |||
3263 | # This feature uses the readline library, so it will honor your ~/.inputrc |
|
3284 | # This feature uses the readline library, so it will honor your ~/.inputrc | |
3264 | # configuration (or whatever file your INPUTRC variable points to). Adding |
|
3285 | # configuration (or whatever file your INPUTRC variable points to). Adding | |
3265 | # the following lines to your .inputrc file can make indent/unindenting more |
|
3286 | # the following lines to your .inputrc file can make indent/unindenting more | |
3266 | # convenient (M-i indents, M-u unindents): |
|
3287 | # convenient (M-i indents, M-u unindents): | |
3267 |
|
3288 | |||
3268 | # $if Python |
|
3289 | # $if Python | |
3269 | # "\M-i": " " |
|
3290 | # "\M-i": " " | |
3270 | # "\M-u": "\d\d\d\d" |
|
3291 | # "\M-u": "\d\d\d\d" | |
3271 | # $endif |
|
3292 | # $endif | |
3272 |
|
3293 | |||
3273 | # The feature is potentially a bit dangerous, because it can cause problems |
|
3294 | # The feature is potentially a bit dangerous, because it can cause problems | |
3274 | # with pasting of indented code (the pasted code gets re-indented on each |
|
3295 | # with pasting of indented code (the pasted code gets re-indented on each | |
3275 | # line). But it's a huge time-saver when working interactively. The magic |
|
3296 | # line). But it's a huge time-saver when working interactively. The magic | |
3276 | # function %autoindent allows you to toggle it on/off at runtime. |
|
3297 | # function %autoindent allows you to toggle it on/off at runtime. | |
3277 |
|
3298 | |||
3278 | autoindent 1 |
|
3299 | autoindent 1 | |
3279 |
|
3300 | |||
3280 | # Auto-magic. This gives you access to all the magic functions without having |
|
3301 | # Auto-magic. This gives you access to all the magic functions without having | |
3281 | # to prepend them with an % sign. If you define a variable with the same name |
|
3302 | # to prepend them with an % sign. If you define a variable with the same name | |
3282 | # as a magic function (say who=1), you will need to access the magic function |
|
3303 | # as a magic function (say who=1), you will need to access the magic function | |
3283 | # with % (%who in this example). However, if later you delete your variable |
|
3304 | # with % (%who in this example). However, if later you delete your variable | |
3284 | # (del who), you'll recover the automagic calling form. |
|
3305 | # (del who), you'll recover the automagic calling form. | |
3285 |
|
3306 | |||
3286 | # Considering that many magic functions provide a lot of shell-like |
|
3307 | # Considering that many magic functions provide a lot of shell-like | |
3287 | # functionality, automagic gives you something close to a full Python+system |
|
3308 | # functionality, automagic gives you something close to a full Python+system | |
3288 | # shell environment (and you can extend it further if you want). |
|
3309 | # shell environment (and you can extend it further if you want). | |
3289 |
|
3310 | |||
3290 | automagic 1 |
|
3311 | automagic 1 | |
3291 |
|
3312 | |||
3292 | # Size of the output cache. After this many entries are stored, the cache will |
|
3313 | # Size of the output cache. After this many entries are stored, the cache will | |
3293 | # get flushed. Depending on the size of your intermediate calculations, you |
|
3314 | # get flushed. Depending on the size of your intermediate calculations, you | |
3294 | # may have memory problems if you make it too big, since keeping things in the |
|
3315 | # may have memory problems if you make it too big, since keeping things in the | |
3295 | # cache prevents Python from reclaiming the memory for old results. Experiment |
|
3316 | # cache prevents Python from reclaiming the memory for old results. Experiment | |
3296 | # with a value that works well for you. |
|
3317 | # with a value that works well for you. | |
3297 |
|
3318 | |||
3298 | # If you choose cache_size 0 IPython will revert to python's regular >>> |
|
3319 | # If you choose cache_size 0 IPython will revert to python's regular >>> | |
3299 | # unnumbered prompt. You will still have _, __ and ___ for your last three |
|
3320 | # unnumbered prompt. You will still have _, __ and ___ for your last three | |
3300 | # results, but that will be it. No dynamic _1, _2, etc. will be created. If |
|
3321 | # results, but that will be it. No dynamic _1, _2, etc. will be created. If | |
3301 | # you are running on a slow machine or with very limited memory, this may |
|
3322 | # you are running on a slow machine or with very limited memory, this may | |
3302 | # help. |
|
3323 | # help. | |
3303 |
|
3324 | |||
3304 | cache_size 1000 |
|
3325 | cache_size 1000 | |
3305 |
|
3326 | |||
3306 | # Classic mode: Setting 'classic 1' you lose many of IPython niceties, |
|
3327 | # Classic mode: Setting 'classic 1' you lose many of IPython niceties, | |
3307 | # but that's your choice! Classic 1 -> same as IPython -classic. |
|
3328 | # but that's your choice! Classic 1 -> same as IPython -classic. | |
3308 | # Note that this is _not_ the normal python interpreter, it's simply |
|
3329 | # Note that this is _not_ the normal python interpreter, it's simply | |
3309 | # IPython emulating most of the classic interpreter's behavior. |
|
3330 | # IPython emulating most of the classic interpreter's behavior. | |
3310 | classic 0 |
|
3331 | classic 0 | |
3311 |
|
3332 | |||
3312 | # colors - Coloring option for prompts and traceback printouts. |
|
3333 | # colors - Coloring option for prompts and traceback printouts. | |
3313 |
|
3334 | |||
3314 | # Currently available schemes: NoColor, Linux, LightBG. |
|
3335 | # Currently available schemes: NoColor, Linux, LightBG. | |
3315 |
|
3336 | |||
3316 | # This option allows coloring the prompts and traceback printouts. This |
|
3337 | # This option allows coloring the prompts and traceback printouts. This | |
3317 | # requires a terminal which can properly handle color escape sequences. If you |
|
3338 | # requires a terminal which can properly handle color escape sequences. If you | |
3318 | # are having problems with this, use the NoColor scheme (uses no color escapes |
|
3339 | # are having problems with this, use the NoColor scheme (uses no color escapes | |
3319 | # at all). |
|
3340 | # at all). | |
3320 |
|
3341 | |||
3321 | # The Linux option works well in linux console type environments: dark |
|
3342 | # The Linux option works well in linux console type environments: dark | |
3322 | # background with light fonts. |
|
3343 | # background with light fonts. | |
3323 |
|
3344 | |||
3324 | # LightBG is similar to Linux but swaps dark/light colors to be more readable |
|
3345 | # LightBG is similar to Linux but swaps dark/light colors to be more readable | |
3325 | # in light background terminals. |
|
3346 | # in light background terminals. | |
3326 |
|
3347 | |||
3327 | # keep uncommented only the one you want: |
|
3348 | # keep uncommented only the one you want: | |
3328 | colors Linux |
|
3349 | colors Linux | |
3329 | #colors LightBG |
|
3350 | #colors LightBG | |
3330 | #colors NoColor |
|
3351 | #colors NoColor | |
3331 |
|
3352 | |||
3332 | ######################## |
|
3353 | ######################## | |
3333 | # Note to Windows users |
|
3354 | # Note to Windows users | |
3334 | # |
|
3355 | # | |
3335 | # Color and readline support is avaialble to Windows users via Gary Bishop's |
|
3356 | # Color and readline support is avaialble to Windows users via Gary Bishop's | |
3336 | # readline library. You can find Gary's tools at |
|
3357 | # readline library. You can find Gary's tools at | |
3337 | # http://sourceforge.net/projects/uncpythontools. |
|
3358 | # http://sourceforge.net/projects/uncpythontools. | |
3338 | # Note that his readline module requires in turn the ctypes library, available |
|
3359 | # Note that his readline module requires in turn the ctypes library, available | |
3339 | # at http://starship.python.net/crew/theller/ctypes. |
|
3360 | # at http://starship.python.net/crew/theller/ctypes. | |
3340 | ######################## |
|
3361 | ######################## | |
3341 |
|
3362 | |||
3342 | # color_info: IPython can display information about objects via a set of |
|
3363 | # color_info: IPython can display information about objects via a set of | |
3343 | # functions, and optionally can use colors for this, syntax highlighting |
|
3364 | # functions, and optionally can use colors for this, syntax highlighting | |
3344 | # source code and various other elements. This information is passed through a |
|
3365 | # source code and various other elements. This information is passed through a | |
3345 | # pager (it defaults to 'less' if $PAGER is not set). |
|
3366 | # pager (it defaults to 'less' if $PAGER is not set). | |
3346 |
|
3367 | |||
3347 | # If your pager has problems, try to setting it to properly handle escapes |
|
3368 | # If your pager has problems, try to setting it to properly handle escapes | |
3348 | # (see the less manpage for detail), or disable this option. The magic |
|
3369 | # (see the less manpage for detail), or disable this option. The magic | |
3349 | # function %color_info allows you to toggle this interactively for testing. |
|
3370 | # function %color_info allows you to toggle this interactively for testing. | |
3350 |
|
3371 | |||
3351 | color_info 1 |
|
3372 | color_info 1 | |
3352 |
|
3373 | |||
3353 | # confirm_exit: set to 1 if you want IPython to confirm when you try to exit |
|
3374 | # confirm_exit: set to 1 if you want IPython to confirm when you try to exit | |
3354 | # with an EOF (Control-d in Unix, Control-Z/Enter in Windows). Note that using |
|
3375 | # with an EOF (Control-d in Unix, Control-Z/Enter in Windows). Note that using | |
3355 | # the magic functions %Exit or %Quit you can force a direct exit, bypassing |
|
3376 | # the magic functions %Exit or %Quit you can force a direct exit, bypassing | |
3356 | # any confirmation. |
|
3377 | # any confirmation. | |
3357 |
|
3378 | |||
3358 | confirm_exit 1 |
|
3379 | confirm_exit 1 | |
3359 |
|
3380 | |||
3360 | # Use deep_reload() as a substitute for reload() by default. deep_reload() is |
|
3381 | # Use deep_reload() as a substitute for reload() by default. deep_reload() is | |
3361 | # still available as dreload() and appears as a builtin. |
|
3382 | # still available as dreload() and appears as a builtin. | |
3362 |
|
3383 | |||
3363 | deep_reload 0 |
|
3384 | deep_reload 0 | |
3364 |
|
3385 | |||
3365 | # Which editor to use with the %edit command. If you leave this at 0, IPython |
|
3386 | # Which editor to use with the %edit command. If you leave this at 0, IPython | |
3366 | # will honor your EDITOR environment variable. Since this editor is invoked on |
|
3387 | # will honor your EDITOR environment variable. Since this editor is invoked on | |
3367 | # the fly by ipython and is meant for editing small code snippets, you may |
|
3388 | # the fly by ipython and is meant for editing small code snippets, you may | |
3368 | # want to use a small, lightweight editor here. |
|
3389 | # want to use a small, lightweight editor here. | |
3369 |
|
3390 | |||
3370 | # For Emacs users, setting up your Emacs server properly as described in the |
|
3391 | # For Emacs users, setting up your Emacs server properly as described in the | |
3371 | # manual is a good idea. An alternative is to use jed, a very light editor |
|
3392 | # manual is a good idea. An alternative is to use jed, a very light editor | |
3372 | # with much of the feel of Emacs (though not as powerful for heavy-duty work). |
|
3393 | # with much of the feel of Emacs (though not as powerful for heavy-duty work). | |
3373 |
|
3394 | |||
3374 | editor 0 |
|
3395 | editor 0 | |
3375 |
|
3396 | |||
3376 | # log 1 -> same as ipython -log. This automatically logs to ./ipython.log |
|
3397 | # log 1 -> same as ipython -log. This automatically logs to ./ipython.log | |
3377 | log 0 |
|
3398 | log 0 | |
3378 |
|
3399 | |||
3379 | # Same as ipython -Logfile YourLogfileName. |
|
3400 | # Same as ipython -Logfile YourLogfileName. | |
3380 | # Don't use with log 1 (use one or the other) |
|
3401 | # Don't use with log 1 (use one or the other) | |
3381 | logfile '' |
|
3402 | logfile '' | |
3382 |
|
3403 | |||
3383 | # banner 0 -> same as ipython -nobanner |
|
3404 | # banner 0 -> same as ipython -nobanner | |
3384 | banner 1 |
|
3405 | banner 1 | |
3385 |
|
3406 | |||
3386 | # messages 0 -> same as ipython -nomessages |
|
3407 | # messages 0 -> same as ipython -nomessages | |
3387 | messages 1 |
|
3408 | messages 1 | |
3388 |
|
3409 | |||
3389 | # Automatically call the pdb debugger after every uncaught exception. If you |
|
3410 | # Automatically call the pdb debugger after every uncaught exception. If you | |
3390 | # are used to debugging using pdb, this puts you automatically inside of it |
|
3411 | # are used to debugging using pdb, this puts you automatically inside of it | |
3391 | # after any call (either in IPython or in code called by it) which triggers an |
|
3412 | # after any call (either in IPython or in code called by it) which triggers an | |
3392 | # exception which goes uncaught. |
|
3413 | # exception which goes uncaught. | |
3393 | pdb 0 |
|
3414 | pdb 0 | |
3394 |
|
3415 | |||
3395 | # Enable the pprint module for printing. pprint tends to give a more readable |
|
3416 | # Enable the pprint module for printing. pprint tends to give a more readable | |
3396 | # display (than print) for complex nested data structures. |
|
3417 | # display (than print) for complex nested data structures. | |
3397 | pprint 1 |
|
3418 | pprint 1 | |
3398 |
|
3419 | |||
3399 | # Prompt strings |
|
3420 | # Prompt strings | |
3400 |
|
3421 | |||
3401 | # Most bash-like escapes can be used to customize IPython's prompts, as well as |
|
3422 | # Most bash-like escapes can be used to customize IPython's prompts, as well as | |
3402 | # a few additional ones which are IPython-specific. All valid prompt escapes |
|
3423 | # a few additional ones which are IPython-specific. All valid prompt escapes | |
3403 | # are described in detail in the Customization section of the IPython HTML/PDF |
|
3424 | # are described in detail in the Customization section of the IPython HTML/PDF | |
3404 | # manual. |
|
3425 | # manual. | |
3405 |
|
3426 | |||
3406 | # Use \# to represent the current prompt number, and quote them to protect |
|
3427 | # Use \# to represent the current prompt number, and quote them to protect | |
3407 | # spaces. |
|
3428 | # spaces. | |
3408 | prompt_in1 'In [\#]: ' |
|
3429 | prompt_in1 'In [\#]: ' | |
3409 |
|
3430 | |||
3410 | # \D is replaced by as many dots as there are digits in the |
|
3431 | # \D is replaced by as many dots as there are digits in the | |
3411 | # current value of \#. |
|
3432 | # current value of \#. | |
3412 | prompt_in2 ' .\D.: ' |
|
3433 | prompt_in2 ' .\D.: ' | |
3413 |
|
3434 | |||
3414 | prompt_out 'Out[\#]: ' |
|
3435 | prompt_out 'Out[\#]: ' | |
3415 |
|
3436 | |||
3416 | # Select whether to left-pad the output prompts to match the length of the |
|
3437 | # Select whether to left-pad the output prompts to match the length of the | |
3417 | # input ones. This allows you for example to use a simple '>' as an output |
|
3438 | # input ones. This allows you for example to use a simple '>' as an output | |
3418 | # prompt, and yet have the output line up with the input. If set to false, |
|
3439 | # prompt, and yet have the output line up with the input. If set to false, | |
3419 | # the output prompts will be unpadded (flush left). |
|
3440 | # the output prompts will be unpadded (flush left). | |
3420 | prompts_pad_left 1 |
|
3441 | prompts_pad_left 1 | |
3421 |
|
3442 | |||
3422 | # Pylab support: when ipython is started with the -pylab switch, by default it |
|
3443 | # Pylab support: when ipython is started with the -pylab switch, by default it | |
3423 | # executes 'from matplotlib.pylab import *'. Set this variable to false if you |
|
3444 | # executes 'from matplotlib.pylab import *'. Set this variable to false if you | |
3424 | # want to disable this behavior. |
|
3445 | # want to disable this behavior. | |
3425 |
|
3446 | |||
3426 | # For details on pylab, see the matplotlib website: |
|
3447 | # For details on pylab, see the matplotlib website: | |
3427 | # http://matplotlib.sf.net |
|
3448 | # http://matplotlib.sf.net | |
3428 | pylab_import_all 1 |
|
3449 | pylab_import_all 1 | |
3429 |
|
3450 | |||
3430 |
|
3451 | |||
3431 | # quick 1 -> same as ipython -quick |
|
3452 | # quick 1 -> same as ipython -quick | |
3432 | quick 0 |
|
3453 | quick 0 | |
3433 |
|
3454 | |||
3434 | # Use the readline library (1) or not (0). Most users will want this on, but |
|
3455 | # Use the readline library (1) or not (0). Most users will want this on, but | |
3435 | # if you experience strange problems with line management (mainly when using |
|
3456 | # if you experience strange problems with line management (mainly when using | |
3436 | # IPython inside Emacs buffers) you may try disabling it. Not having it on |
|
3457 | # IPython inside Emacs buffers) you may try disabling it. Not having it on | |
3437 | # prevents you from getting command history with the arrow keys, searching and |
|
3458 | # prevents you from getting command history with the arrow keys, searching and | |
3438 | # name completion using TAB. |
|
3459 | # name completion using TAB. | |
3439 |
|
3460 | |||
3440 | readline 1 |
|
3461 | readline 1 | |
3441 |
|
3462 | |||
3442 | # Screen Length: number of lines of your screen. This is used to control |
|
3463 | # Screen Length: number of lines of your screen. This is used to control | |
3443 | # printing of very long strings. Strings longer than this number of lines will |
|
3464 | # printing of very long strings. Strings longer than this number of lines will | |
3444 | # be paged with the less command instead of directly printed. |
|
3465 | # be paged with the less command instead of directly printed. | |
3445 |
|
3466 | |||
3446 | # The default value for this is 0, which means IPython will auto-detect your |
|
3467 | # The default value for this is 0, which means IPython will auto-detect your | |
3447 | # screen size every time it needs to print. If for some reason this isn't |
|
3468 | # screen size every time it needs to print. If for some reason this isn't | |
3448 | # working well (it needs curses support), specify it yourself. Otherwise don't |
|
3469 | # working well (it needs curses support), specify it yourself. Otherwise don't | |
3449 | # change the default. |
|
3470 | # change the default. | |
3450 |
|
3471 | |||
3451 | screen_length 0 |
|
3472 | screen_length 0 | |
3452 |
|
3473 | |||
3453 | # Prompt separators for input and output. |
|
3474 | # Prompt separators for input and output. | |
3454 | # Use \n for newline explicitly, without quotes. |
|
3475 | # Use \n for newline explicitly, without quotes. | |
3455 | # Use 0 (like at the cmd line) to turn off a given separator. |
|
3476 | # Use 0 (like at the cmd line) to turn off a given separator. | |
3456 |
|
3477 | |||
3457 | # The structure of prompt printing is: |
|
3478 | # The structure of prompt printing is: | |
3458 | # (SeparateIn)Input.... |
|
3479 | # (SeparateIn)Input.... | |
3459 | # (SeparateOut)Output... |
|
3480 | # (SeparateOut)Output... | |
3460 | # (SeparateOut2), # that is, no newline is printed after Out2 |
|
3481 | # (SeparateOut2), # that is, no newline is printed after Out2 | |
3461 | # By choosing these you can organize your output any way you want. |
|
3482 | # By choosing these you can organize your output any way you want. | |
3462 |
|
3483 | |||
3463 | separate_in \n |
|
3484 | separate_in \n | |
3464 | separate_out 0 |
|
3485 | separate_out 0 | |
3465 | separate_out2 0 |
|
3486 | separate_out2 0 | |
3466 |
|
3487 | |||
3467 | # 'nosep 1' is a shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'. |
|
3488 | # 'nosep 1' is a shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'. | |
3468 | # Simply removes all input/output separators, overriding the choices above. |
|
3489 | # Simply removes all input/output separators, overriding the choices above. | |
3469 | nosep 0 |
|
3490 | nosep 0 | |
3470 |
|
3491 | |||
3471 | # Wildcard searches - IPython has a system for searching names using |
|
3492 | # Wildcard searches - IPython has a system for searching names using | |
3472 | # shell-like wildcards; type %psearch? for details. This variables sets |
|
3493 | # shell-like wildcards; type %psearch? for details. This variables sets | |
3473 | # whether by default such searches should be case sensitive or not. You can |
|
3494 | # whether by default such searches should be case sensitive or not. You can | |
3474 | # always override the default at the system command line or the IPython |
|
3495 | # always override the default at the system command line or the IPython | |
3475 | # prompt. |
|
3496 | # prompt. | |
3476 |
|
3497 | |||
3477 | wildcards_case_sensitive 1 |
|
3498 | wildcards_case_sensitive 1 | |
3478 |
|
3499 | |||
3479 | # Object information: at what level of detail to display the string form of an |
|
3500 | # Object information: at what level of detail to display the string form of an | |
3480 | # object. If set to 0, ipython will compute the string form of any object X, |
|
3501 | # object. If set to 0, ipython will compute the string form of any object X, | |
3481 | # by calling str(X), when X? is typed. If set to 1, str(X) will only be |
|
3502 | # by calling str(X), when X? is typed. If set to 1, str(X) will only be | |
3482 | # computed when X?? is given, and if set to 2 or higher, it will never be |
|
3503 | # computed when X?? is given, and if set to 2 or higher, it will never be | |
3483 | # computed (there is no X??? level of detail). This is mostly of use to |
|
3504 | # computed (there is no X??? level of detail). This is mostly of use to | |
3484 | # people who frequently manipulate objects whose string representation is |
|
3505 | # people who frequently manipulate objects whose string representation is | |
3485 | # extremely expensive to compute. |
|
3506 | # extremely expensive to compute. | |
3486 |
|
3507 | |||
3487 | object_info_string_level 0 |
|
3508 | object_info_string_level 0 | |
3488 |
|
3509 | |||
3489 | # xmode - Exception reporting mode. |
|
3510 | # xmode - Exception reporting mode. | |
3490 |
|
3511 | |||
3491 | # Valid modes: Plain, Context and Verbose. |
|
3512 | # Valid modes: Plain, Context and Verbose. | |
3492 |
|
3513 | |||
3493 | # Plain: similar to python's normal traceback printing. |
|
3514 | # Plain: similar to python's normal traceback printing. | |
3494 |
|
3515 | |||
3495 | # Context: prints 5 lines of context source code around each line in the |
|
3516 | # Context: prints 5 lines of context source code around each line in the | |
3496 | # traceback. |
|
3517 | # traceback. | |
3497 |
|
3518 | |||
3498 | # Verbose: similar to Context, but additionally prints the variables currently |
|
3519 | # Verbose: similar to Context, but additionally prints the variables currently | |
3499 | # visible where the exception happened (shortening their strings if too |
|
3520 | # visible where the exception happened (shortening their strings if too | |
3500 | # long). This can potentially be very slow, if you happen to have a huge data |
|
3521 | # long). This can potentially be very slow, if you happen to have a huge data | |
3501 | # structure whose string representation is complex to compute. Your computer |
|
3522 | # structure whose string representation is complex to compute. Your computer | |
3502 | # may appear to freeze for a while with cpu usage at 100%. If this occurs, you |
|
3523 | # may appear to freeze for a while with cpu usage at 100%. If this occurs, you | |
3503 | # can cancel the traceback with Ctrl-C (maybe hitting it more than once). |
|
3524 | # can cancel the traceback with Ctrl-C (maybe hitting it more than once). | |
3504 |
|
3525 | |||
3505 | #xmode Plain |
|
3526 | #xmode Plain | |
3506 | xmode Context |
|
3527 | xmode Context | |
3507 | #xmode Verbose |
|
3528 | #xmode Verbose | |
3508 |
|
3529 | |||
3509 | # multi_line_specials: if true, allow magics, aliases and shell escapes (via |
|
3530 | # multi_line_specials: if true, allow magics, aliases and shell escapes (via | |
3510 | # !cmd) to be used in multi-line input (like for loops). For example, if you |
|
3531 | # !cmd) to be used in multi-line input (like for loops). For example, if you | |
3511 | # have this active, the following is valid in IPython: |
|
3532 | # have this active, the following is valid in IPython: | |
3512 | # |
|
3533 | # | |
3513 | #In [17]: for i in range(3): |
|
3534 | #In [17]: for i in range(3): | |
3514 | # ....: mkdir $i |
|
3535 | # ....: mkdir $i | |
3515 | # ....: !touch $i/hello |
|
3536 | # ....: !touch $i/hello | |
3516 | # ....: ls -l $i |
|
3537 | # ....: ls -l $i | |
3517 |
|
3538 | |||
3518 | multi_line_specials 1 |
|
3539 | multi_line_specials 1 | |
3519 |
|
3540 | |||
3520 |
|
3541 | |||
3521 | # System calls: When IPython makes system calls (e.g. via special syntax like |
|
3542 | # System calls: When IPython makes system calls (e.g. via special syntax like | |
3522 | # !cmd or !!cmd, or magics like %sc or %sx), it can print the command it is |
|
3543 | # !cmd or !!cmd, or magics like %sc or %sx), it can print the command it is | |
3523 | # executing to standard output, prefixed by a header string. |
|
3544 | # executing to standard output, prefixed by a header string. | |
3524 |
|
3545 | |||
3525 | system_header "IPython system call: " |
|
3546 | system_header "IPython system call: " | |
3526 |
|
3547 | |||
3527 | system_verbose 1 |
|
3548 | system_verbose 1 | |
3528 |
|
3549 | |||
3529 | # wxversion: request a specific wxPython version (used for -wthread) |
|
3550 | # wxversion: request a specific wxPython version (used for -wthread) | |
3530 |
|
3551 | |||
3531 | # Set this to the value of wxPython you want to use, but note that this |
|
3552 | # Set this to the value of wxPython you want to use, but note that this | |
3532 | # feature requires you to have the wxversion Python module to work. If you |
|
3553 | # feature requires you to have the wxversion Python module to work. If you | |
3533 | # don't have the wxversion module (try 'import wxversion' at the prompt to |
|
3554 | # don't have the wxversion module (try 'import wxversion' at the prompt to | |
3534 | # check) or simply want to leave the system to pick up the default, leave this |
|
3555 | # check) or simply want to leave the system to pick up the default, leave this | |
3535 | # variable at 0. |
|
3556 | # variable at 0. | |
3536 |
|
3557 | |||
3537 | wxversion 0 |
|
3558 | wxversion 0 | |
3538 |
|
3559 | |||
3539 | #--------------------------------------------------------------------------- |
|
3560 | #--------------------------------------------------------------------------- | |
3540 | # Section: Readline configuration (readline is not available for MS-Windows) |
|
3561 | # Section: Readline configuration (readline is not available for MS-Windows) | |
3541 |
|
3562 | |||
3542 | # This is done via the following options: |
|
3563 | # This is done via the following options: | |
3543 |
|
3564 | |||
3544 | # (i) readline_parse_and_bind: this option can appear as many times as you |
|
3565 | # (i) readline_parse_and_bind: this option can appear as many times as you | |
3545 | # want, each time defining a string to be executed via a |
|
3566 | # want, each time defining a string to be executed via a | |
3546 | # readline.parse_and_bind() command. The syntax for valid commands of this |
|
3567 | # readline.parse_and_bind() command. The syntax for valid commands of this | |
3547 | # kind can be found by reading the documentation for the GNU readline library, |
|
3568 | # kind can be found by reading the documentation for the GNU readline library, | |
3548 | # as these commands are of the kind which readline accepts in its |
|
3569 | # as these commands are of the kind which readline accepts in its | |
3549 | # configuration file. |
|
3570 | # configuration file. | |
3550 |
|
3571 | |||
3551 | # The TAB key can be used to complete names at the command line in one of two |
|
3572 | # The TAB key can be used to complete names at the command line in one of two | |
3552 | # ways: 'complete' and 'menu-complete'. The difference is that 'complete' only |
|
3573 | # ways: 'complete' and 'menu-complete'. The difference is that 'complete' only | |
3553 | # completes as much as possible while 'menu-complete' cycles through all |
|
3574 | # completes as much as possible while 'menu-complete' cycles through all | |
3554 | # possible completions. Leave the one you prefer uncommented. |
|
3575 | # possible completions. Leave the one you prefer uncommented. | |
3555 |
|
3576 | |||
3556 | readline_parse_and_bind tab: complete |
|
3577 | readline_parse_and_bind tab: complete | |
3557 | #readline_parse_and_bind tab: menu-complete |
|
3578 | #readline_parse_and_bind tab: menu-complete | |
3558 |
|
3579 | |||
3559 | # This binds Control-l to printing the list of all possible completions when |
|
3580 | # This binds Control-l to printing the list of all possible completions when | |
3560 | # there is more than one (what 'complete' does when hitting TAB twice, or at |
|
3581 | # there is more than one (what 'complete' does when hitting TAB twice, or at | |
3561 | # the first TAB if show-all-if-ambiguous is on) |
|
3582 | # the first TAB if show-all-if-ambiguous is on) | |
3562 | readline_parse_and_bind "\C-l": possible-completions |
|
3583 | readline_parse_and_bind "\C-l": possible-completions | |
3563 |
|
3584 | |||
3564 | # This forces readline to automatically print the above list when tab |
|
3585 | # This forces readline to automatically print the above list when tab | |
3565 | # completion is set to 'complete'. You can still get this list manually by |
|
3586 | # completion is set to 'complete'. You can still get this list manually by | |
3566 | # using the key bound to 'possible-completions' (Control-l by default) or by |
|
3587 | # using the key bound to 'possible-completions' (Control-l by default) or by | |
3567 | # hitting TAB twice. Turning this on makes the printing happen at the first |
|
3588 | # hitting TAB twice. Turning this on makes the printing happen at the first | |
3568 | # TAB. |
|
3589 | # TAB. | |
3569 | readline_parse_and_bind set show-all-if-ambiguous on |
|
3590 | readline_parse_and_bind set show-all-if-ambiguous on | |
3570 |
|
3591 | |||
3571 | # If you have TAB set to complete names, you can rebind any key (Control-o by |
|
3592 | # If you have TAB set to complete names, you can rebind any key (Control-o by | |
3572 | # default) to insert a true TAB character. |
|
3593 | # default) to insert a true TAB character. | |
3573 | readline_parse_and_bind "\C-o": tab-insert |
|
3594 | readline_parse_and_bind "\C-o": tab-insert | |
3574 |
|
3595 | |||
3575 | # These commands allow you to indent/unindent easily, with the 4-space |
|
3596 | # These commands allow you to indent/unindent easily, with the 4-space | |
3576 | # convention of the Python coding standards. Since IPython's internal |
|
3597 | # convention of the Python coding standards. Since IPython's internal | |
3577 | # auto-indent system also uses 4 spaces, you should not change the number of |
|
3598 | # auto-indent system also uses 4 spaces, you should not change the number of | |
3578 | # spaces in the code below. |
|
3599 | # spaces in the code below. | |
3579 | readline_parse_and_bind "\M-i": " " |
|
3600 | readline_parse_and_bind "\M-i": " " | |
3580 | readline_parse_and_bind "\M-o": "\d\d\d\d" |
|
3601 | readline_parse_and_bind "\M-o": "\d\d\d\d" | |
3581 | readline_parse_and_bind "\M-I": "\d\d\d\d" |
|
3602 | readline_parse_and_bind "\M-I": "\d\d\d\d" | |
3582 |
|
3603 | |||
3583 | # Bindings for incremental searches in the history. These searches use the |
|
3604 | # Bindings for incremental searches in the history. These searches use the | |
3584 | # string typed so far on the command line and search anything in the previous |
|
3605 | # string typed so far on the command line and search anything in the previous | |
3585 | # input history containing them. |
|
3606 | # input history containing them. | |
3586 | readline_parse_and_bind "\C-r": reverse-search-history |
|
3607 | readline_parse_and_bind "\C-r": reverse-search-history | |
3587 | readline_parse_and_bind "\C-s": forward-search-history |
|
3608 | readline_parse_and_bind "\C-s": forward-search-history | |
3588 |
|
3609 | |||
3589 | # Bindings for completing the current line in the history of previous |
|
3610 | # Bindings for completing the current line in the history of previous | |
3590 | # commands. This allows you to recall any previous command by typing its first |
|
3611 | # commands. This allows you to recall any previous command by typing its first | |
3591 | # few letters and hitting Control-p, bypassing all intermediate commands which |
|
3612 | # few letters and hitting Control-p, bypassing all intermediate commands which | |
3592 | # may be in the history (much faster than hitting up-arrow 50 times!) |
|
3613 | # may be in the history (much faster than hitting up-arrow 50 times!) | |
3593 | readline_parse_and_bind "\C-p": history-search-backward |
|
3614 | readline_parse_and_bind "\C-p": history-search-backward | |
3594 | readline_parse_and_bind "\C-n": history-search-forward |
|
3615 | readline_parse_and_bind "\C-n": history-search-forward | |
3595 |
|
3616 | |||
3596 | # I also like to have the same functionality on the plain arrow keys. If you'd |
|
3617 | # I also like to have the same functionality on the plain arrow keys. If you'd | |
3597 | # rather have the arrows use all the history (and not just match what you've |
|
3618 | # rather have the arrows use all the history (and not just match what you've | |
3598 | # typed so far), comment out or delete the next two lines. |
|
3619 | # typed so far), comment out or delete the next two lines. | |
3599 | readline_parse_and_bind "\e[A": history-search-backward |
|
3620 | readline_parse_and_bind "\e[A": history-search-backward | |
3600 | readline_parse_and_bind "\e[B": history-search-forward |
|
3621 | readline_parse_and_bind "\e[B": history-search-forward | |
3601 |
|
3622 | |||
3602 | # These are typically on by default under *nix, but not win32. |
|
3623 | # These are typically on by default under *nix, but not win32. | |
3603 | readline_parse_and_bind "\C-k": kill-line |
|
3624 | readline_parse_and_bind "\C-k": kill-line | |
3604 | readline_parse_and_bind "\C-u": unix-line-discard |
|
3625 | readline_parse_and_bind "\C-u": unix-line-discard | |
3605 |
|
3626 | |||
3606 | # (ii) readline_remove_delims: a string of characters to be removed from the |
|
3627 | # (ii) readline_remove_delims: a string of characters to be removed from the | |
3607 | # default word-delimiters list used by readline, so that completions may be |
|
3628 | # default word-delimiters list used by readline, so that completions may be | |
3608 | # performed on strings which contain them. |
|
3629 | # performed on strings which contain them. | |
3609 |
|
3630 | |||
3610 | readline_remove_delims -/~ |
|
3631 | readline_remove_delims -/~ | |
3611 |
|
3632 | |||
3612 | # (iii) readline_merge_completions: whether to merge the result of all |
|
3633 | # (iii) readline_merge_completions: whether to merge the result of all | |
3613 | # possible completions or not. If true, IPython will complete filenames, |
|
3634 | # possible completions or not. If true, IPython will complete filenames, | |
3614 | # python names and aliases and return all possible completions. If you set it |
|
3635 | # python names and aliases and return all possible completions. If you set it | |
3615 | # to false, each completer is used at a time, and only if it doesn't return |
|
3636 | # to false, each completer is used at a time, and only if it doesn't return | |
3616 | # any completions is the next one used. |
|
3637 | # any completions is the next one used. | |
3617 |
|
3638 | |||
3618 | # The default order is: [python_matches, file_matches, alias_matches] |
|
3639 | # The default order is: [python_matches, file_matches, alias_matches] | |
3619 |
|
3640 | |||
3620 | readline_merge_completions 1 |
|
3641 | readline_merge_completions 1 | |
3621 |
|
3642 | |||
3622 | # (iv) readline_omit__names: normally hitting <tab> after a '.' in a name |
|
3643 | # (iv) readline_omit__names: normally hitting <tab> after a '.' in a name | |
3623 | # will complete all attributes of an object, including all the special methods |
|
3644 | # will complete all attributes of an object, including all the special methods | |
3624 | # whose names start with single or double underscores (like __getitem__ or |
|
3645 | # whose names start with single or double underscores (like __getitem__ or | |
3625 | # __class__). |
|
3646 | # __class__). | |
3626 |
|
3647 | |||
3627 | # This variable allows you to control this completion behavior: |
|
3648 | # This variable allows you to control this completion behavior: | |
3628 |
|
3649 | |||
3629 | # readline_omit__names 1 -> completion will omit showing any names starting |
|
3650 | # readline_omit__names 1 -> completion will omit showing any names starting | |
3630 | # with two __, but it will still show names starting with one _. |
|
3651 | # with two __, but it will still show names starting with one _. | |
3631 |
|
3652 | |||
3632 | # readline_omit__names 2 -> completion will omit all names beginning with one |
|
3653 | # readline_omit__names 2 -> completion will omit all names beginning with one | |
3633 | # _ (which obviously means filtering out the double __ ones). |
|
3654 | # _ (which obviously means filtering out the double __ ones). | |
3634 |
|
3655 | |||
3635 | # Even when this option is set, you can still see those names by explicitly |
|
3656 | # Even when this option is set, you can still see those names by explicitly | |
3636 | # typing a _ after the period and hitting <tab>: 'name._<tab>' will always |
|
3657 | # typing a _ after the period and hitting <tab>: 'name._<tab>' will always | |
3637 | # complete attribute names starting with '_'. |
|
3658 | # complete attribute names starting with '_'. | |
3638 |
|
3659 | |||
3639 | # This option is off by default so that new users see all attributes of any |
|
3660 | # This option is off by default so that new users see all attributes of any | |
3640 | # objects they are dealing with. |
|
3661 | # objects they are dealing with. | |
3641 |
|
3662 | |||
3642 | readline_omit__names 0 |
|
3663 | readline_omit__names 0 | |
3643 |
|
3664 | |||
3644 | #--------------------------------------------------------------------------- |
|
3665 | #--------------------------------------------------------------------------- | |
3645 | # Section: modules to be loaded with 'import ...' |
|
3666 | # Section: modules to be loaded with 'import ...' | |
3646 |
|
3667 | |||
3647 | # List, separated by spaces, the names of the modules you want to import |
|
3668 | # List, separated by spaces, the names of the modules you want to import | |
3648 |
|
3669 | |||
3649 | # Example: |
|
3670 | # Example: | |
3650 | # import_mod sys os |
|
3671 | # import_mod sys os | |
3651 | # will produce internally the statements |
|
3672 | # will produce internally the statements | |
3652 | # import sys |
|
3673 | # import sys | |
3653 | # import os |
|
3674 | # import os | |
3654 |
|
3675 | |||
3655 | # Each import is executed in its own try/except block, so if one module |
|
3676 | # Each import is executed in its own try/except block, so if one module | |
3656 | # fails to load the others will still be ok. |
|
3677 | # fails to load the others will still be ok. | |
3657 |
|
3678 | |||
3658 | import_mod |
|
3679 | import_mod | |
3659 |
|
3680 | |||
3660 | #--------------------------------------------------------------------------- |
|
3681 | #--------------------------------------------------------------------------- | |
3661 | # Section: modules to import some functions from: 'from ... import ...' |
|
3682 | # Section: modules to import some functions from: 'from ... import ...' | |
3662 |
|
3683 | |||
3663 | # List, one per line, the modules for which you want only to import some |
|
3684 | # List, one per line, the modules for which you want only to import some | |
3664 | # functions. Give the module name first and then the name of functions to be |
|
3685 | # functions. Give the module name first and then the name of functions to be | |
3665 | # imported from that module. |
|
3686 | # imported from that module. | |
3666 |
|
3687 | |||
3667 | # Example: |
|
3688 | # Example: | |
3668 |
|
3689 | |||
3669 | # import_some IPython.genutils timing timings |
|
3690 | # import_some IPython.genutils timing timings | |
3670 | # will produce internally the statement |
|
3691 | # will produce internally the statement | |
3671 | # from IPython.genutils import timing, timings |
|
3692 | # from IPython.genutils import timing, timings | |
3672 |
|
3693 | |||
3673 | # timing() and timings() are two IPython utilities for timing the execution of |
|
3694 | # timing() and timings() are two IPython utilities for timing the execution of | |
3674 | # your own functions, which you may find useful. Just commment out the above |
|
3695 | # your own functions, which you may find useful. Just commment out the above | |
3675 | # line if you want to test them. |
|
3696 | # line if you want to test them. | |
3676 |
|
3697 | |||
3677 | # If you have more than one modules_some line, each gets its own try/except |
|
3698 | # If you have more than one modules_some line, each gets its own try/except | |
3678 | # block (like modules, see above). |
|
3699 | # block (like modules, see above). | |
3679 |
|
3700 | |||
3680 | import_some |
|
3701 | import_some | |
3681 |
|
3702 | |||
3682 | #--------------------------------------------------------------------------- |
|
3703 | #--------------------------------------------------------------------------- | |
3683 | # Section: modules to import all from : 'from ... import *' |
|
3704 | # Section: modules to import all from : 'from ... import *' | |
3684 |
|
3705 | |||
3685 | # List (same syntax as import_mod above) those modules for which you want to |
|
3706 | # List (same syntax as import_mod above) those modules for which you want to | |
3686 | # import all functions. Remember, this is a potentially dangerous thing to do, |
|
3707 | # import all functions. Remember, this is a potentially dangerous thing to do, | |
3687 | # since it is very easy to overwrite names of things you need. Use with |
|
3708 | # since it is very easy to overwrite names of things you need. Use with | |
3688 | # caution. |
|
3709 | # caution. | |
3689 |
|
3710 | |||
3690 | # Example: |
|
3711 | # Example: | |
3691 | # import_all sys os |
|
3712 | # import_all sys os | |
3692 | # will produce internally the statements |
|
3713 | # will produce internally the statements | |
3693 | # from sys import * |
|
3714 | # from sys import * | |
3694 | # from os import * |
|
3715 | # from os import * | |
3695 |
|
3716 | |||
3696 | # As before, each will be called in a separate try/except block. |
|
3717 | # As before, each will be called in a separate try/except block. | |
3697 |
|
3718 | |||
3698 | import_all |
|
3719 | import_all | |
3699 |
|
3720 | |||
3700 | #--------------------------------------------------------------------------- |
|
3721 | #--------------------------------------------------------------------------- | |
3701 | # Section: Python code to execute. |
|
3722 | # Section: Python code to execute. | |
3702 |
|
3723 | |||
3703 | # Put here code to be explicitly executed (keep it simple!) |
|
3724 | # Put here code to be explicitly executed (keep it simple!) | |
3704 | # Put one line of python code per line. All whitespace is removed (this is a |
|
3725 | # Put one line of python code per line. All whitespace is removed (this is a | |
3705 | # feature, not a bug), so don't get fancy building loops here. |
|
3726 | # feature, not a bug), so don't get fancy building loops here. | |
3706 | # This is just for quick convenient creation of things you want available. |
|
3727 | # This is just for quick convenient creation of things you want available. | |
3707 |
|
3728 | |||
3708 | # Example: |
|
3729 | # Example: | |
3709 | # execute x = 1 |
|
3730 | # execute x = 1 | |
3710 | # execute print 'hello world'; y = z = 'a' |
|
3731 | # execute print 'hello world'; y = z = 'a' | |
3711 | # will produce internally |
|
3732 | # will produce internally | |
3712 | # x = 1 |
|
3733 | # x = 1 | |
3713 | # print 'hello world'; y = z = 'a' |
|
3734 | # print 'hello world'; y = z = 'a' | |
3714 | # and each *line* (not each statement, we don't do python syntax parsing) is |
|
3735 | # and each *line* (not each statement, we don't do python syntax parsing) is | |
3715 | # executed in its own try/except block. |
|
3736 | # executed in its own try/except block. | |
3716 |
|
3737 | |||
3717 | execute |
|
3738 | execute | |
3718 |
|
3739 | |||
3719 | # Note for the adventurous: you can use this to define your own names for the |
|
3740 | # Note for the adventurous: you can use this to define your own names for the | |
3720 | # magic functions, by playing some namespace tricks: |
|
3741 | # magic functions, by playing some namespace tricks: | |
3721 |
|
3742 | |||
3722 | # execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile |
|
3743 | # execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile | |
3723 |
|
3744 | |||
3724 | # defines %pf as a new name for %profile. |
|
3745 | # defines %pf as a new name for %profile. | |
3725 |
|
3746 | |||
3726 | #--------------------------------------------------------------------------- |
|
3747 | #--------------------------------------------------------------------------- | |
3727 | # Section: Pyhton files to load and execute. |
|
3748 | # Section: Pyhton files to load and execute. | |
3728 |
|
3749 | |||
3729 | # Put here the full names of files you want executed with execfile(file). If |
|
3750 | # Put here the full names of files you want executed with execfile(file). If | |
3730 | # you want complicated initialization, just write whatever you want in a |
|
3751 | # you want complicated initialization, just write whatever you want in a | |
3731 | # regular python file and load it from here. |
|
3752 | # regular python file and load it from here. | |
3732 |
|
3753 | |||
3733 | # Filenames defined here (which *must* include the extension) are searched for |
|
3754 | # Filenames defined here (which *must* include the extension) are searched for | |
3734 | # through all of sys.path. Since IPython adds your .ipython directory to |
|
3755 | # through all of sys.path. Since IPython adds your .ipython directory to | |
3735 | # sys.path, they can also be placed in your .ipython dir and will be |
|
3756 | # sys.path, they can also be placed in your .ipython dir and will be | |
3736 | # found. Otherwise (if you want to execute things not in .ipyton nor in |
|
3757 | # found. Otherwise (if you want to execute things not in .ipyton nor in | |
3737 | # sys.path) give a full path (you can use ~, it gets expanded) |
|
3758 | # sys.path) give a full path (you can use ~, it gets expanded) | |
3738 |
|
3759 | |||
3739 | # Example: |
|
3760 | # Example: | |
3740 | # execfile file1.py ~/file2.py |
|
3761 | # execfile file1.py ~/file2.py | |
3741 | # will generate |
|
3762 | # will generate | |
3742 | # execfile('file1.py') |
|
3763 | # execfile('file1.py') | |
3743 | # execfile('_path_to_your_home/file2.py') |
|
3764 | # execfile('_path_to_your_home/file2.py') | |
3744 |
|
3765 | |||
3745 | # As before, each file gets its own try/except block. |
|
3766 | # As before, each file gets its own try/except block. | |
3746 |
|
3767 | |||
3747 | execfile |
|
3768 | execfile | |
3748 |
|
3769 | |||
3749 | # If you are feeling adventurous, you can even add functionality to IPython |
|
3770 | # If you are feeling adventurous, you can even add functionality to IPython | |
3750 | # through here. IPython works through a global variable called __ip which |
|
3771 | # through here. IPython works through a global variable called __ip which | |
3751 | # exists at the time when these files are read. If you know what you are doing |
|
3772 | # exists at the time when these files are read. If you know what you are doing | |
3752 | # (read the source) you can add functions to __ip in files loaded here. |
|
3773 | # (read the source) you can add functions to __ip in files loaded here. | |
3753 |
|
3774 | |||
3754 | # The file example-magic.py contains a simple but correct example. Try it: |
|
3775 | # The file example-magic.py contains a simple but correct example. Try it: | |
3755 |
|
3776 | |||
3756 | # execfile example-magic.py |
|
3777 | # execfile example-magic.py | |
3757 |
|
3778 | |||
3758 | # Look at the examples in IPython/iplib.py for more details on how these magic |
|
3779 | # Look at the examples in IPython/iplib.py for more details on how these magic | |
3759 | # functions need to process their arguments. |
|
3780 | # functions need to process their arguments. | |
3760 |
|
3781 | |||
3761 | #--------------------------------------------------------------------------- |
|
3782 | #--------------------------------------------------------------------------- | |
3762 | # Section: aliases for system shell commands |
|
3783 | # Section: aliases for system shell commands | |
3763 |
|
3784 | |||
3764 | # Here you can define your own names for system commands. The syntax is |
|
3785 | # Here you can define your own names for system commands. The syntax is | |
3765 | # similar to that of the builtin %alias function: |
|
3786 | # similar to that of the builtin %alias function: | |
3766 |
|
3787 | |||
3767 | # alias alias_name command_string |
|
3788 | # alias alias_name command_string | |
3768 |
|
3789 | |||
3769 | # The resulting aliases are auto-generated magic functions (hence usable as |
|
3790 | # The resulting aliases are auto-generated magic functions (hence usable as | |
3770 | # %alias_name) |
|
3791 | # %alias_name) | |
3771 |
|
3792 | |||
3772 | # For example: |
|
3793 | # For example: | |
3773 |
|
3794 | |||
3774 | # alias myls ls -la |
|
3795 | # alias myls ls -la | |
3775 |
|
3796 | |||
3776 | # will define 'myls' as an alias for executing the system command 'ls -la'. |
|
3797 | # will define 'myls' as an alias for executing the system command 'ls -la'. | |
3777 | # This allows you to customize IPython's environment to have the same aliases |
|
3798 | # This allows you to customize IPython's environment to have the same aliases | |
3778 | # you are accustomed to from your own shell. |
|
3799 | # you are accustomed to from your own shell. | |
3779 |
|
3800 | |||
3780 | # You can also define aliases with parameters using %s specifiers (one per |
|
3801 | # You can also define aliases with parameters using %s specifiers (one per | |
3781 | # parameter): |
|
3802 | # parameter): | |
3782 |
|
3803 | |||
3783 | # alias parts echo first %s second %s |
|
3804 | # alias parts echo first %s second %s | |
3784 |
|
3805 | |||
3785 | # will give you in IPython: |
|
3806 | # will give you in IPython: | |
3786 | # >>> %parts A B |
|
3807 | # >>> %parts A B | |
3787 | # first A second B |
|
3808 | # first A second B | |
3788 |
|
3809 | |||
3789 | # Use one 'alias' statement per alias you wish to define. |
|
3810 | # Use one 'alias' statement per alias you wish to define. | |
3790 |
|
3811 | |||
3791 | # alias |
|
3812 | # alias | |
3792 |
|
3813 | |||
3793 | #************************* end of file <ipythonrc> ************************ |
|
3814 | #************************* end of file <ipythonrc> ************************ | |
3794 |
|
3815 | |||
3795 |
|
3816 | |||
|
3817 | ipy_user_conf.py | |||
|
3818 | ---------------- | |||
|
3819 | ||||
|
3820 | There should be a simple template ipy_user_conf.py file in your | |||
|
3821 | ~/.ipython directory. It is a plain python module that is imported | |||
|
3822 | during IPython startup, so you can do pretty much what you want there | |||
|
3823 | - import modules, configure extensions, change options, define magic | |||
|
3824 | commands, put variables and functions in the IPython namespace, | |||
|
3825 | etc. You use the IPython extension api object, acquired by | |||
|
3826 | IPython.ipapi.get() and documented in the "IPython extension API" | |||
|
3827 | chapter, to interact with IPython. A sample ipy_user_conf.py is listed | |||
|
3828 | below for reference:: | |||
|
3829 | ||||
|
3830 | # Most of your config files and extensions will probably start | |||
|
3831 | # with this import | |||
|
3832 | ||||
|
3833 | import IPython.ipapi | |||
|
3834 | ip = IPython.ipapi.get() | |||
|
3835 | ||||
|
3836 | # You probably want to uncomment this if you did %upgrade -nolegacy | |||
|
3837 | # import ipy_defaults | |||
|
3838 | ||||
|
3839 | import os | |||
|
3840 | ||||
|
3841 | def main(): | |||
|
3842 | ||||
|
3843 | #ip.dbg.debugmode = True | |||
|
3844 | ip.dbg.debug_stack() | |||
|
3845 | ||||
|
3846 | # uncomment if you want to get ipython -p sh behaviour | |||
|
3847 | # without having to use command line switches | |||
|
3848 | import ipy_profile_sh | |||
|
3849 | import jobctrl | |||
|
3850 | ||||
|
3851 | # Configure your favourite editor? | |||
|
3852 | # Good idea e.g. for %edit os.path.isfile | |||
|
3853 | ||||
|
3854 | #import ipy_editors | |||
|
3855 | ||||
|
3856 | # Choose one of these: | |||
|
3857 | ||||
|
3858 | #ipy_editors.scite() | |||
|
3859 | #ipy_editors.scite('c:/opt/scite/scite.exe') | |||
|
3860 | #ipy_editors.komodo() | |||
|
3861 | #ipy_editors.idle() | |||
|
3862 | # ... or many others, try 'ipy_editors??' after import to see them | |||
|
3863 | ||||
|
3864 | # Or roll your own: | |||
|
3865 | #ipy_editors.install_editor("c:/opt/jed +$line $file") | |||
|
3866 | ||||
|
3867 | ||||
|
3868 | o = ip.options | |||
|
3869 | # An example on how to set options | |||
|
3870 | #o.autocall = 1 | |||
|
3871 | o.system_verbose = 0 | |||
|
3872 | ||||
|
3873 | #import_all("os sys") | |||
|
3874 | #execf('~/_ipython/ns.py') | |||
|
3875 | ||||
|
3876 | ||||
|
3877 | # -- prompt | |||
|
3878 | # A different, more compact set of prompts from the default ones, that | |||
|
3879 | # always show your current location in the filesystem: | |||
|
3880 | ||||
|
3881 | #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>' | |||
|
3882 | #o.prompt_in2 = r'.\D: ' | |||
|
3883 | #o.prompt_out = r'[\#] ' | |||
|
3884 | ||||
|
3885 | # Try one of these color settings if you can't read the text easily | |||
|
3886 | # autoexec is a list of IPython commands to execute on startup | |||
|
3887 | #o.autoexec.append('%colors LightBG') | |||
|
3888 | #o.autoexec.append('%colors NoColor') | |||
|
3889 | o.autoexec.append('%colors Linux') | |||
|
3890 | ||||
|
3891 | ||||
|
3892 | # some config helper functions you can use | |||
|
3893 | def import_all(modules): | |||
|
3894 | """ Usage: import_all("os sys") """ | |||
|
3895 | for m in modules.split(): | |||
|
3896 | ip.ex("from %s import *" % m) | |||
|
3897 | ||||
|
3898 | def execf(fname): | |||
|
3899 | """ Execute a file in user namespace """ | |||
|
3900 | ip.ex('execfile("%s")' % os.path.expanduser(fname)) | |||
|
3901 | ||||
|
3902 | main() | |||
|
3903 | ||||
|
3904 | ||||
3796 |
|
3905 | |||
3797 | Fine-tuning your prompt |
|
3906 | Fine-tuning your prompt | |
3798 | ----------------------- |
|
3907 | ----------------------- | |
3799 |
|
3908 | |||
3800 | IPython's prompts can be customized using a syntax similar to that of |
|
3909 | IPython's prompts can be customized using a syntax similar to that of | |
3801 | the bash shell. Many of bash's escapes are supported, as well as a few |
|
3910 | the bash shell. Many of bash's escapes are supported, as well as a few | |
3802 | additional ones. We list them below: |
|
3911 | additional ones. We list them below:: | |
3803 |
|
3912 | |||
3804 | *\#* |
|
3913 | \# | |
3805 | the prompt/history count number. This escape is automatically |
|
3914 | the prompt/history count number. This escape is automatically | |
3806 | wrapped in the coloring codes for the currently active color scheme. |
|
3915 | wrapped in the coloring codes for the currently active color scheme. | |
3807 | *\N* |
|
3916 | \N | |
3808 | the 'naked' prompt/history count number: this is just the number |
|
3917 | the 'naked' prompt/history count number: this is just the number | |
3809 | itself, without any coloring applied to it. This lets you produce |
|
3918 | itself, without any coloring applied to it. This lets you produce | |
3810 | numbered prompts with your own colors. |
|
3919 | numbered prompts with your own colors. | |
3811 | *\D* |
|
3920 | \D | |
3812 | the prompt/history count, with the actual digits replaced by dots. |
|
3921 | the prompt/history count, with the actual digits replaced by dots. | |
3813 | Used mainly in continuation prompts (prompt_in2) |
|
3922 | Used mainly in continuation prompts (prompt_in2) | |
3814 | *\w* |
|
3923 | \w | |
3815 | the current working directory |
|
3924 | the current working directory | |
3816 | *\W* |
|
3925 | \W | |
3817 | the basename of current working directory |
|
3926 | the basename of current working directory | |
3818 | *\Xn* |
|
3927 | \Xn | |
3819 | where $n=0\ldots5.$ The current working directory, with $HOME |
|
3928 | where $n=0\ldots5.$ The current working directory, with $HOME | |
3820 | replaced by ~, and filtered out to contain only $n$ path elements |
|
3929 | replaced by ~, and filtered out to contain only $n$ path elements | |
3821 | *\Yn* |
|
3930 | \Yn | |
3822 | Similar to \Xn, but with the $n+1$ element included if it is ~ (this |
|
3931 | Similar to \Xn, but with the $n+1$ element included if it is ~ (this | |
3823 | is similar to the behavior of the %cn escapes in tcsh) |
|
3932 | is similar to the behavior of the %cn escapes in tcsh) | |
3824 | *\u* |
|
3933 | \u | |
3825 | the username of the current user |
|
3934 | the username of the current user | |
3826 | *\$* |
|
3935 | \$ | |
3827 | if the effective UID is 0, a #, otherwise a $ |
|
3936 | if the effective UID is 0, a #, otherwise a $ | |
3828 | *\h* |
|
3937 | \h | |
3829 | the hostname up to the first '.' |
|
3938 | the hostname up to the first '.' | |
3830 | *\H* |
|
3939 | \H | |
3831 | the hostname |
|
3940 | the hostname | |
3832 | *\n* |
|
3941 | \n | |
3833 | a newline |
|
3942 | a newline | |
3834 | *\r* |
|
3943 | \r | |
3835 | a carriage return |
|
3944 | a carriage return | |
3836 | *\v* |
|
3945 | \v | |
3837 | IPython version string |
|
3946 | IPython version string | |
3838 |
|
3947 | |||
3839 | In addition to these, ANSI color escapes can be insterted into the |
|
3948 | In addition to these, ANSI color escapes can be insterted into the | |
3840 | prompts, as \C_ColorName. The list of valid color names is: Black, Blue, |
|
3949 | prompts, as \C_ColorName. The list of valid color names is: Black, Blue, | |
3841 | Brown, Cyan, DarkGray, Green, LightBlue, LightCyan, LightGray, |
|
3950 | Brown, Cyan, DarkGray, Green, LightBlue, LightCyan, LightGray, | |
3842 | LightGreen, LightPurple, LightRed, NoColor, Normal, Purple, Red, White, |
|
3951 | LightGreen, LightPurple, LightRed, NoColor, Normal, Purple, Red, White, | |
3843 | Yellow. |
|
3952 | Yellow. | |
3844 |
|
3953 | |||
3845 | Finally, IPython supports the evaluation of arbitrary expressions in |
|
3954 | Finally, IPython supports the evaluation of arbitrary expressions in | |
3846 | your prompt string. The prompt strings are evaluated through the syntax |
|
3955 | your prompt string. The prompt strings are evaluated through the syntax | |
3847 | of PEP 215, but basically you can use $x.y to expand the value of x.y, |
|
3956 | of PEP 215, but basically you can use $x.y to expand the value of x.y, | |
3848 | and for more complicated expressions you can use braces: ${foo()+x} will |
|
3957 | and for more complicated expressions you can use braces: ${foo()+x} will | |
3849 | call function foo and add to it the value of x, before putting the |
|
3958 | call function foo and add to it the value of x, before putting the | |
3850 | result into your prompt. For example, using |
|
3959 | result into your prompt. For example, using | |
3851 | prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: ' |
|
3960 | prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: ' | |
3852 | will print the result of the uptime command on each prompt (assuming the |
|
3961 | will print the result of the uptime command on each prompt (assuming the | |
3853 | commands module has been imported in your ipythonrc file). |
|
3962 | commands module has been imported in your ipythonrc file). | |
3854 |
|
3963 | |||
3855 |
|
3964 | |||
3856 | Prompt examples |
|
3965 | Prompt examples | |
3857 |
|
3966 | |||
3858 | The following options in an ipythonrc file will give you IPython's |
|
3967 | The following options in an ipythonrc file will give you IPython's | |
3859 | default prompts:: |
|
3968 | default prompts:: | |
3860 |
|
3969 | |||
3861 | prompt_in1 'In [\#]:' |
|
3970 | prompt_in1 'In [\#]:' | |
3862 | prompt_in2 ' .\D.:' |
|
3971 | prompt_in2 ' .\D.:' | |
3863 | prompt_out 'Out[\#]:' |
|
3972 | prompt_out 'Out[\#]:' | |
3864 |
|
3973 | |||
3865 | which look like this:: |
|
3974 | which look like this:: | |
3866 |
|
3975 | |||
3867 | In [1]: 1+2 |
|
3976 | In [1]: 1+2 | |
3868 | Out[1]: 3 |
|
3977 | Out[1]: 3 | |
3869 |
|
3978 | |||
3870 | In [2]: for i in (1,2,3): |
|
3979 | In [2]: for i in (1,2,3): | |
3871 | ...: print i, |
|
3980 | ...: print i, | |
3872 | ...: |
|
3981 | ...: | |
3873 | 1 2 3 |
|
3982 | 1 2 3 | |
3874 |
|
3983 | |||
3875 | These will give you a very colorful prompt with path information:: |
|
3984 | These will give you a very colorful prompt with path information:: | |
3876 |
|
3985 | |||
3877 | #prompt_in1 '\C_Red\u\C_Blue[\C_Cyan\Y1\C_Blue]\C_LightGreen\#>' |
|
3986 | #prompt_in1 '\C_Red\u\C_Blue[\C_Cyan\Y1\C_Blue]\C_LightGreen\#>' | |
3878 | prompt_in2 ' ..\D>' |
|
3987 | prompt_in2 ' ..\D>' | |
3879 | prompt_out '<\#>' |
|
3988 | prompt_out '<\#>' | |
3880 |
|
3989 | |||
3881 | which look like this:: |
|
3990 | which look like this:: | |
3882 |
|
3991 | |||
3883 | fperez[~/ipython]1> 1+2 |
|
3992 | fperez[~/ipython]1> 1+2 | |
3884 | <1> 3 |
|
3993 | <1> 3 | |
3885 | fperez[~/ipython]2> for i in (1,2,3): |
|
3994 | fperez[~/ipython]2> for i in (1,2,3): | |
3886 | ...> print i, |
|
3995 | ...> print i, | |
3887 | ...> |
|
3996 | ...> | |
3888 | 1 2 3 |
|
3997 | 1 2 3 | |
3889 |
|
3998 | |||
3890 |
|
3999 | |||
3891 |
|
4000 | |||
3892 | IPython profiles |
|
4001 | IPython profiles | |
3893 | ---------------- |
|
4002 | ---------------- | |
3894 |
|
4003 | |||
3895 | As we already mentioned, IPython supports the -profile command-line |
|
4004 | As we already mentioned, IPython supports the -profile command-line | |
3896 | option (see sec. 5.2 <node5.html#sec:cmd-line-opts>). A profile is |
|
4005 | option (see sec. 5.2 <node5.html#sec:cmd-line-opts>). A profile is | |
3897 | nothing more than a particular configuration file like your basic |
|
4006 | nothing more than a particular configuration file like your basic | |
3898 | ipythonrc one, but with particular customizations for a specific |
|
4007 | ipythonrc one, but with particular customizations for a specific | |
3899 | purpose. When you start IPython with 'ipython -profile <name>', it |
|
4008 | purpose. When you start IPython with 'ipython -profile <name>', it | |
3900 | assumes that in your IPYTHONDIR there is a file called ipythonrc-<name>, |
|
4009 | assumes that in your IPYTHONDIR there is a file called ipythonrc-<name>, | |
3901 | and loads it instead of the normal ipythonrc. |
|
4010 | and loads it instead of the normal ipythonrc. | |
3902 |
|
4011 | |||
3903 | This system allows you to maintain multiple configurations which load |
|
4012 | This system allows you to maintain multiple configurations which load | |
3904 | modules, set options, define functions, etc. suitable for different |
|
4013 | modules, set options, define functions, etc. suitable for different | |
3905 | tasks and activate them in a very simple manner. In order to avoid |
|
4014 | tasks and activate them in a very simple manner. In order to avoid | |
3906 | having to repeat all of your basic options (common things that don't |
|
4015 | having to repeat all of your basic options (common things that don't | |
3907 | change such as your color preferences, for example), any profile can |
|
4016 | change such as your color preferences, for example), any profile can | |
3908 | include another configuration file. The most common way to use profiles |
|
4017 | include another configuration file. The most common way to use profiles | |
3909 | is then to have each one include your basic ipythonrc file as a starting |
|
4018 | is then to have each one include your basic ipythonrc file as a starting | |
3910 | point, and then add further customizations. |
|
4019 | point, and then add further customizations. | |
3911 |
|
4020 | |||
3912 | In sections 11 <node11.html#sec:syntax-extensions> and 16 |
|
4021 | In sections 11 <node11.html#sec:syntax-extensions> and 16 | |
3913 | <node16.html#sec:Gnuplot> we discuss some particular profiles which come |
|
4022 | <node16.html#sec:Gnuplot> we discuss some particular profiles which come | |
3914 | as part of the standard IPython distribution. You may also look in your |
|
4023 | as part of the standard IPython distribution. You may also look in your | |
3915 | IPYTHONDIR directory, any file whose name begins with ipythonrc- is a |
|
4024 | IPYTHONDIR directory, any file whose name begins with ipythonrc- is a | |
3916 | profile. You can use those as examples for further customizations to |
|
4025 | profile. You can use those as examples for further customizations to | |
3917 | suit your own needs. |
|
4026 | suit your own needs. | |
3918 |
|
4027 | |||
3919 | IPython as your default Python environment |
|
4028 | IPython as your default Python environment | |
3920 | ========================================== |
|
4029 | ========================================== | |
3921 |
|
4030 | |||
3922 | Python honors the environment variable PYTHONSTARTUP and will execute at |
|
4031 | Python honors the environment variable PYTHONSTARTUP and will execute at | |
3923 | startup the file referenced by this variable. If you put at the end of |
|
4032 | startup the file referenced by this variable. If you put at the end of | |
3924 | this file the following two lines of code:: |
|
4033 | this file the following two lines of code:: | |
3925 |
|
4034 | |||
3926 | import IPython |
|
4035 | import IPython | |
3927 | IPython.Shell.IPShell().mainloop(sys_exit=1) |
|
4036 | IPython.Shell.IPShell().mainloop(sys_exit=1) | |
3928 |
|
4037 | |||
3929 | then IPython will be your working environment anytime you start Python. |
|
4038 | then IPython will be your working environment anytime you start Python. | |
3930 | The sys_exit=1 is needed to have IPython issue a call to sys.exit() when |
|
4039 | The sys_exit=1 is needed to have IPython issue a call to sys.exit() when | |
3931 | it finishes, otherwise you'll be back at the normal Python '>>>' |
|
4040 | it finishes, otherwise you'll be back at the normal Python '>>>' | |
3932 | prompt^4 <footnode.html#foot2368>. |
|
4041 | prompt^4 <footnode.html#foot2368>. | |
3933 |
|
4042 | |||
3934 | This is probably useful to developers who manage multiple Python |
|
4043 | This is probably useful to developers who manage multiple Python | |
3935 | versions and don't want to have correspondingly multiple IPython |
|
4044 | versions and don't want to have correspondingly multiple IPython | |
3936 | versions. Note that in this mode, there is no way to pass IPython any |
|
4045 | versions. Note that in this mode, there is no way to pass IPython any | |
3937 | command-line options, as those are trapped first by Python itself. |
|
4046 | command-line options, as those are trapped first by Python itself. | |
3938 |
|
4047 | |||
3939 | Embedding IPython |
|
4048 | Embedding IPython | |
3940 | ================= |
|
4049 | ================= | |
3941 |
|
4050 | |||
3942 | It is possible to start an IPython instance inside your own Python |
|
4051 | It is possible to start an IPython instance inside your own Python | |
3943 | programs. This allows you to evaluate dynamically the state of your |
|
4052 | programs. This allows you to evaluate dynamically the state of your | |
3944 | code, operate with your variables, analyze them, etc. Note however that |
|
4053 | code, operate with your variables, analyze them, etc. Note however that | |
3945 | any changes you make to values while in the shell do not propagate back |
|
4054 | any changes you make to values while in the shell do not propagate back | |
3946 | to the running code, so it is safe to modify your values because you |
|
4055 | to the running code, so it is safe to modify your values because you | |
3947 | won't break your code in bizarre ways by doing so. |
|
4056 | won't break your code in bizarre ways by doing so. | |
3948 |
|
4057 | |||
3949 | This feature allows you to easily have a fully functional python |
|
4058 | This feature allows you to easily have a fully functional python | |
3950 | environment for doing object introspection anywhere in your code with a |
|
4059 | environment for doing object introspection anywhere in your code with a | |
3951 | simple function call. In some cases a simple print statement is enough, |
|
4060 | simple function call. In some cases a simple print statement is enough, | |
3952 | but if you need to do more detailed analysis of a code fragment this |
|
4061 | but if you need to do more detailed analysis of a code fragment this | |
3953 | feature can be very valuable. |
|
4062 | feature can be very valuable. | |
3954 |
|
4063 | |||
3955 | It can also be useful in scientific computing situations where it is |
|
4064 | It can also be useful in scientific computing situations where it is | |
3956 | common to need to do some automatic, computationally intensive part and |
|
4065 | common to need to do some automatic, computationally intensive part and | |
3957 | then stop to look at data, plots, etc^5 <footnode.html#foot3206>. |
|
4066 | then stop to look at data, plots, etc^5 <footnode.html#foot3206>. | |
3958 | Opening an IPython instance will give you full access to your data and |
|
4067 | Opening an IPython instance will give you full access to your data and | |
3959 | functions, and you can resume program execution once you are done with |
|
4068 | functions, and you can resume program execution once you are done with | |
3960 | the interactive part (perhaps to stop again later, as many times as |
|
4069 | the interactive part (perhaps to stop again later, as many times as | |
3961 | needed). |
|
4070 | needed). | |
3962 |
|
4071 | |||
3963 | The following code snippet is the bare minimum you need to include in |
|
4072 | The following code snippet is the bare minimum you need to include in | |
3964 | your Python programs for this to work (detailed examples follow later):: |
|
4073 | your Python programs for this to work (detailed examples follow later):: | |
3965 |
|
4074 | |||
3966 | from IPython.Shell import IPShellEmbed |
|
4075 | from IPython.Shell import IPShellEmbed | |
3967 |
|
4076 | |||
3968 | ipshell = IPShellEmbed() |
|
4077 | ipshell = IPShellEmbed() | |
3969 |
|
4078 | |||
3970 | ipshell() # this call anywhere in your program will start IPython |
|
4079 | ipshell() # this call anywhere in your program will start IPython | |
3971 |
|
4080 | |||
3972 | You can run embedded instances even in code which is itself being run at |
|
4081 | You can run embedded instances even in code which is itself being run at | |
3973 | the IPython interactive prompt with '%run <filename>'. Since it's easy |
|
4082 | the IPython interactive prompt with '%run <filename>'. Since it's easy | |
3974 | to get lost as to where you are (in your top-level IPython or in your |
|
4083 | to get lost as to where you are (in your top-level IPython or in your | |
3975 | embedded one), it's a good idea in such cases to set the in/out prompts |
|
4084 | embedded one), it's a good idea in such cases to set the in/out prompts | |
3976 | to something different for the embedded instances. The code examples |
|
4085 | to something different for the embedded instances. The code examples | |
3977 | below illustrate this. |
|
4086 | below illustrate this. | |
3978 |
|
4087 | |||
3979 | You can also have multiple IPython instances in your program and open |
|
4088 | You can also have multiple IPython instances in your program and open | |
3980 | them separately, for example with different options for data |
|
4089 | them separately, for example with different options for data | |
3981 | presentation. If you close and open the same instance multiple times, |
|
4090 | presentation. If you close and open the same instance multiple times, | |
3982 | its prompt counters simply continue from each execution to the next. |
|
4091 | its prompt counters simply continue from each execution to the next. | |
3983 |
|
4092 | |||
3984 | Please look at the docstrings in the Shell.py module for more details on |
|
4093 | Please look at the docstrings in the Shell.py module for more details on | |
3985 | the use of this system. |
|
4094 | the use of this system. | |
3986 |
|
4095 | |||
3987 | The following sample file illustrating how to use the embedding |
|
4096 | The following sample file illustrating how to use the embedding | |
3988 | functionality is provided in the examples directory as example-embed.py. |
|
4097 | functionality is provided in the examples directory as example-embed.py. | |
3989 | It should be fairly self-explanatory:: |
|
4098 | It should be fairly self-explanatory:: | |
3990 |
|
4099 | |||
3991 |
|
4100 | |||
3992 | #!/usr/bin/env python |
|
4101 | #!/usr/bin/env python | |
3993 |
|
4102 | |||
3994 | """An example of how to embed an IPython shell into a running program. |
|
4103 | """An example of how to embed an IPython shell into a running program. | |
3995 |
|
4104 | |||
3996 | Please see the documentation in the IPython.Shell module for more details. |
|
4105 | Please see the documentation in the IPython.Shell module for more details. | |
3997 |
|
4106 | |||
3998 | The accompanying file example-embed-short.py has quick code fragments for |
|
4107 | The accompanying file example-embed-short.py has quick code fragments for | |
3999 | embedding which you can cut and paste in your code once you understand how |
|
4108 | embedding which you can cut and paste in your code once you understand how | |
4000 | things work. |
|
4109 | things work. | |
4001 |
|
4110 | |||
4002 | The code in this file is deliberately extra-verbose, meant for learning.""" |
|
4111 | The code in this file is deliberately extra-verbose, meant for learning.""" | |
4003 |
|
4112 | |||
4004 | # The basics to get you going: |
|
4113 | # The basics to get you going: | |
4005 |
|
4114 | |||
4006 | # IPython sets the __IPYTHON__ variable so you can know if you have nested |
|
4115 | # IPython sets the __IPYTHON__ variable so you can know if you have nested | |
4007 | # copies running. |
|
4116 | # copies running. | |
4008 |
|
4117 | |||
4009 | # Try running this code both at the command line and from inside IPython (with |
|
4118 | # Try running this code both at the command line and from inside IPython (with | |
4010 | # %run example-embed.py) |
|
4119 | # %run example-embed.py) | |
4011 | try: |
|
4120 | try: | |
4012 | __IPYTHON__ |
|
4121 | __IPYTHON__ | |
4013 | except NameError: |
|
4122 | except NameError: | |
4014 | nested = 0 |
|
4123 | nested = 0 | |
4015 | args = [''] |
|
4124 | args = [''] | |
4016 | else: |
|
4125 | else: | |
4017 | print "Running nested copies of IPython." |
|
4126 | print "Running nested copies of IPython." | |
4018 | print "The prompts for the nested copy have been modified" |
|
4127 | print "The prompts for the nested copy have been modified" | |
4019 | nested = 1 |
|
4128 | nested = 1 | |
4020 | # what the embedded instance will see as sys.argv: |
|
4129 | # what the embedded instance will see as sys.argv: | |
4021 | args = ['-pi1','In <\\#>: ','-pi2',' .\\D.: ', |
|
4130 | args = ['-pi1','In <\\#>: ','-pi2',' .\\D.: ', | |
4022 | '-po','Out<\\#>: ','-nosep'] |
|
4131 | '-po','Out<\\#>: ','-nosep'] | |
4023 |
|
4132 | |||
4024 | # First import the embeddable shell class |
|
4133 | # First import the embeddable shell class | |
4025 | from IPython.Shell import IPShellEmbed |
|
4134 | from IPython.Shell import IPShellEmbed | |
4026 |
|
4135 | |||
4027 | # Now create an instance of the embeddable shell. The first argument is a |
|
4136 | # Now create an instance of the embeddable shell. The first argument is a | |
4028 | # string with options exactly as you would type them if you were starting |
|
4137 | # string with options exactly as you would type them if you were starting | |
4029 | # IPython at the system command line. Any parameters you want to define for |
|
4138 | # IPython at the system command line. Any parameters you want to define for | |
4030 | # configuration can thus be specified here. |
|
4139 | # configuration can thus be specified here. | |
4031 | ipshell = IPShellEmbed(args, |
|
4140 | ipshell = IPShellEmbed(args, | |
4032 | banner = 'Dropping into IPython', |
|
4141 | banner = 'Dropping into IPython', | |
4033 | exit_msg = 'Leaving Interpreter, back to program.') |
|
4142 | exit_msg = 'Leaving Interpreter, back to program.') | |
4034 |
|
4143 | |||
4035 | # Make a second instance, you can have as many as you want. |
|
4144 | # Make a second instance, you can have as many as you want. | |
4036 | if nested: |
|
4145 | if nested: | |
4037 | args[1] = 'In2<\\#>' |
|
4146 | args[1] = 'In2<\\#>' | |
4038 | else: |
|
4147 | else: | |
4039 | args = ['-pi1','In2<\\#>: ','-pi2',' .\\D.: ', |
|
4148 | args = ['-pi1','In2<\\#>: ','-pi2',' .\\D.: ', | |
4040 | '-po','Out<\\#>: ','-nosep'] |
|
4149 | '-po','Out<\\#>: ','-nosep'] | |
4041 | ipshell2 = IPShellEmbed(args,banner = 'Second IPython instance.') |
|
4150 | ipshell2 = IPShellEmbed(args,banner = 'Second IPython instance.') | |
4042 |
|
4151 | |||
4043 | print '\nHello. This is printed from the main controller program.\n' |
|
4152 | print '\nHello. This is printed from the main controller program.\n' | |
4044 |
|
4153 | |||
4045 | # You can then call ipshell() anywhere you need it (with an optional |
|
4154 | # You can then call ipshell() anywhere you need it (with an optional | |
4046 | # message): |
|
4155 | # message): | |
4047 | ipshell('***Called from top level. ' |
|
4156 | ipshell('***Called from top level. ' | |
4048 | 'Hit Ctrl-D to exit interpreter and continue program.\n' |
|
4157 | 'Hit Ctrl-D to exit interpreter and continue program.\n' | |
4049 | 'Note that if you use %kill_embedded, you can fully deactivate\n' |
|
4158 | 'Note that if you use %kill_embedded, you can fully deactivate\n' | |
4050 | 'This embedded instance so it will never turn on again') |
|
4159 | 'This embedded instance so it will never turn on again') | |
4051 |
|
4160 | |||
4052 | print '\nBack in caller program, moving along...\n' |
|
4161 | print '\nBack in caller program, moving along...\n' | |
4053 |
|
4162 | |||
4054 | #--------------------------------------------------------------------------- |
|
4163 | #--------------------------------------------------------------------------- | |
4055 | # More details: |
|
4164 | # More details: | |
4056 |
|
4165 | |||
4057 | # IPShellEmbed instances don't print the standard system banner and |
|
4166 | # IPShellEmbed instances don't print the standard system banner and | |
4058 | # messages. The IPython banner (which actually may contain initialization |
|
4167 | # messages. The IPython banner (which actually may contain initialization | |
4059 | # messages) is available as <instance>.IP.BANNER in case you want it. |
|
4168 | # messages) is available as <instance>.IP.BANNER in case you want it. | |
4060 |
|
4169 | |||
4061 | # IPShellEmbed instances print the following information everytime they |
|
4170 | # IPShellEmbed instances print the following information everytime they | |
4062 | # start: |
|
4171 | # start: | |
4063 |
|
4172 | |||
4064 | # - A global startup banner. |
|
4173 | # - A global startup banner. | |
4065 |
|
4174 | |||
4066 | # - A call-specific header string, which you can use to indicate where in the |
|
4175 | # - A call-specific header string, which you can use to indicate where in the | |
4067 | # execution flow the shell is starting. |
|
4176 | # execution flow the shell is starting. | |
4068 |
|
4177 | |||
4069 | # They also print an exit message every time they exit. |
|
4178 | # They also print an exit message every time they exit. | |
4070 |
|
4179 | |||
4071 | # Both the startup banner and the exit message default to None, and can be set |
|
4180 | # Both the startup banner and the exit message default to None, and can be set | |
4072 | # either at the instance constructor or at any other time with the |
|
4181 | # either at the instance constructor or at any other time with the | |
4073 | # set_banner() and set_exit_msg() methods. |
|
4182 | # set_banner() and set_exit_msg() methods. | |
4074 |
|
4183 | |||
4075 | # The shell instance can be also put in 'dummy' mode globally or on a per-call |
|
4184 | # The shell instance can be also put in 'dummy' mode globally or on a per-call | |
4076 | # basis. This gives you fine control for debugging without having to change |
|
4185 | # basis. This gives you fine control for debugging without having to change | |
4077 | # code all over the place. |
|
4186 | # code all over the place. | |
4078 |
|
4187 | |||
4079 | # The code below illustrates all this. |
|
4188 | # The code below illustrates all this. | |
4080 |
|
4189 | |||
4081 |
|
4190 | |||
4082 | # This is how the global banner and exit_msg can be reset at any point |
|
4191 | # This is how the global banner and exit_msg can be reset at any point | |
4083 | ipshell.set_banner('Entering interpreter - New Banner') |
|
4192 | ipshell.set_banner('Entering interpreter - New Banner') | |
4084 | ipshell.set_exit_msg('Leaving interpreter - New exit_msg') |
|
4193 | ipshell.set_exit_msg('Leaving interpreter - New exit_msg') | |
4085 |
|
4194 | |||
4086 | def foo(m): |
|
4195 | def foo(m): | |
4087 | s = 'spam' |
|
4196 | s = 'spam' | |
4088 | ipshell('***In foo(). Try @whos, or print s or m:') |
|
4197 | ipshell('***In foo(). Try @whos, or print s or m:') | |
4089 | print 'foo says m = ',m |
|
4198 | print 'foo says m = ',m | |
4090 |
|
4199 | |||
4091 | def bar(n): |
|
4200 | def bar(n): | |
4092 | s = 'eggs' |
|
4201 | s = 'eggs' | |
4093 | ipshell('***In bar(). Try @whos, or print s or n:') |
|
4202 | ipshell('***In bar(). Try @whos, or print s or n:') | |
4094 | print 'bar says n = ',n |
|
4203 | print 'bar says n = ',n | |
4095 |
|
4204 | |||
4096 | # Some calls to the above functions which will trigger IPython: |
|
4205 | # Some calls to the above functions which will trigger IPython: | |
4097 | print 'Main program calling foo("eggs")\n' |
|
4206 | print 'Main program calling foo("eggs")\n' | |
4098 | foo('eggs') |
|
4207 | foo('eggs') | |
4099 |
|
4208 | |||
4100 | # The shell can be put in 'dummy' mode where calls to it silently return. This |
|
4209 | # The shell can be put in 'dummy' mode where calls to it silently return. This | |
4101 | # allows you, for example, to globally turn off debugging for a program with a |
|
4210 | # allows you, for example, to globally turn off debugging for a program with a | |
4102 | # single call. |
|
4211 | # single call. | |
4103 | ipshell.set_dummy_mode(1) |
|
4212 | ipshell.set_dummy_mode(1) | |
4104 | print '\nTrying to call IPython which is now "dummy":' |
|
4213 | print '\nTrying to call IPython which is now "dummy":' | |
4105 | ipshell() |
|
4214 | ipshell() | |
4106 | print 'Nothing happened...' |
|
4215 | print 'Nothing happened...' | |
4107 | # The global 'dummy' mode can still be overridden for a single call |
|
4216 | # The global 'dummy' mode can still be overridden for a single call | |
4108 | print '\nOverriding dummy mode manually:' |
|
4217 | print '\nOverriding dummy mode manually:' | |
4109 | ipshell(dummy=0) |
|
4218 | ipshell(dummy=0) | |
4110 |
|
4219 | |||
4111 | # Reactivate the IPython shell |
|
4220 | # Reactivate the IPython shell | |
4112 | ipshell.set_dummy_mode(0) |
|
4221 | ipshell.set_dummy_mode(0) | |
4113 |
|
4222 | |||
4114 | print 'You can even have multiple embedded instances:' |
|
4223 | print 'You can even have multiple embedded instances:' | |
4115 | ipshell2() |
|
4224 | ipshell2() | |
4116 |
|
4225 | |||
4117 | print '\nMain program calling bar("spam")\n' |
|
4226 | print '\nMain program calling bar("spam")\n' | |
4118 | bar('spam') |
|
4227 | bar('spam') | |
4119 |
|
4228 | |||
4120 | print 'Main program finished. Bye!' |
|
4229 | print 'Main program finished. Bye!' | |
4121 |
|
4230 | |||
4122 | #********************** End of file <example-embed.py> *********************** |
|
4231 | #********************** End of file <example-embed.py> *********************** | |
4123 |
|
4232 | |||
4124 | Once you understand how the system functions, you can use the following |
|
4233 | Once you understand how the system functions, you can use the following | |
4125 | code fragments in your programs which are ready for cut and paste:: |
|
4234 | code fragments in your programs which are ready for cut and paste:: | |
4126 |
|
4235 | |||
4127 |
|
4236 | |||
4128 | """Quick code snippets for embedding IPython into other programs. |
|
4237 | """Quick code snippets for embedding IPython into other programs. | |
4129 |
|
4238 | |||
4130 | See example-embed.py for full details, this file has the bare minimum code for |
|
4239 | See example-embed.py for full details, this file has the bare minimum code for | |
4131 | cut and paste use once you understand how to use the system.""" |
|
4240 | cut and paste use once you understand how to use the system.""" | |
4132 |
|
4241 | |||
4133 | #--------------------------------------------------------------------------- |
|
4242 | #--------------------------------------------------------------------------- | |
4134 | # This code loads IPython but modifies a few things if it detects it's running |
|
4243 | # This code loads IPython but modifies a few things if it detects it's running | |
4135 | # embedded in another IPython session (helps avoid confusion) |
|
4244 | # embedded in another IPython session (helps avoid confusion) | |
4136 |
|
4245 | |||
4137 | try: |
|
4246 | try: | |
4138 | __IPYTHON__ |
|
4247 | __IPYTHON__ | |
4139 | except NameError: |
|
4248 | except NameError: | |
4140 | argv = [''] |
|
4249 | argv = [''] | |
4141 | banner = exit_msg = '' |
|
4250 | banner = exit_msg = '' | |
4142 | else: |
|
4251 | else: | |
4143 | # Command-line options for IPython (a list like sys.argv) |
|
4252 | # Command-line options for IPython (a list like sys.argv) | |
4144 | argv = ['-pi1','In <\\#>:','-pi2',' .\\D.:','-po','Out<\\#>:'] |
|
4253 | argv = ['-pi1','In <\\#>:','-pi2',' .\\D.:','-po','Out<\\#>:'] | |
4145 | banner = '*** Nested interpreter ***' |
|
4254 | banner = '*** Nested interpreter ***' | |
4146 | exit_msg = '*** Back in main IPython ***' |
|
4255 | exit_msg = '*** Back in main IPython ***' | |
4147 |
|
4256 | |||
4148 | # First import the embeddable shell class |
|
4257 | # First import the embeddable shell class | |
4149 | from IPython.Shell import IPShellEmbed |
|
4258 | from IPython.Shell import IPShellEmbed | |
4150 | # Now create the IPython shell instance. Put ipshell() anywhere in your code |
|
4259 | # Now create the IPython shell instance. Put ipshell() anywhere in your code | |
4151 | # where you want it to open. |
|
4260 | # where you want it to open. | |
4152 | ipshell = IPShellEmbed(argv,banner=banner,exit_msg=exit_msg) |
|
4261 | ipshell = IPShellEmbed(argv,banner=banner,exit_msg=exit_msg) | |
4153 |
|
4262 | |||
4154 | #--------------------------------------------------------------------------- |
|
4263 | #--------------------------------------------------------------------------- | |
4155 | # This code will load an embeddable IPython shell always with no changes for |
|
4264 | # This code will load an embeddable IPython shell always with no changes for | |
4156 | # nested embededings. |
|
4265 | # nested embededings. | |
4157 |
|
4266 | |||
4158 | from IPython.Shell import IPShellEmbed |
|
4267 | from IPython.Shell import IPShellEmbed | |
4159 | ipshell = IPShellEmbed() |
|
4268 | ipshell = IPShellEmbed() | |
4160 | # Now ipshell() will open IPython anywhere in the code. |
|
4269 | # Now ipshell() will open IPython anywhere in the code. | |
4161 |
|
4270 | |||
4162 | #--------------------------------------------------------------------------- |
|
4271 | #--------------------------------------------------------------------------- | |
4163 | # This code loads an embeddable shell only if NOT running inside |
|
4272 | # This code loads an embeddable shell only if NOT running inside | |
4164 | # IPython. Inside IPython, the embeddable shell variable ipshell is just a |
|
4273 | # IPython. Inside IPython, the embeddable shell variable ipshell is just a | |
4165 | # dummy function. |
|
4274 | # dummy function. | |
4166 |
|
4275 | |||
4167 | try: |
|
4276 | try: | |
4168 | __IPYTHON__ |
|
4277 | __IPYTHON__ | |
4169 | except NameError: |
|
4278 | except NameError: | |
4170 | from IPython.Shell import IPShellEmbed |
|
4279 | from IPython.Shell import IPShellEmbed | |
4171 | ipshell = IPShellEmbed() |
|
4280 | ipshell = IPShellEmbed() | |
4172 | # Now ipshell() will open IPython anywhere in the code |
|
4281 | # Now ipshell() will open IPython anywhere in the code | |
4173 | else: |
|
4282 | else: | |
4174 | # Define a dummy ipshell() so the same code doesn't crash inside an |
|
4283 | # Define a dummy ipshell() so the same code doesn't crash inside an | |
4175 | # interactive IPython |
|
4284 | # interactive IPython | |
4176 | def ipshell(): pass |
|
4285 | def ipshell(): pass | |
4177 |
|
4286 | |||
4178 | #******************* End of file <example-embed-short.py> ******************** |
|
4287 | #******************* End of file <example-embed-short.py> ******************** | |
4179 |
|
4288 | |||
4180 | Using the Python debugger (pdb) |
|
4289 | Using the Python debugger (pdb) | |
4181 | =============================== |
|
4290 | =============================== | |
4182 |
|
4291 | |||
4183 | Running entire programs via pdb |
|
4292 | Running entire programs via pdb | |
4184 | ------------------------------- |
|
4293 | ------------------------------- | |
4185 |
|
4294 | |||
4186 | pdb, the Python debugger, is a powerful interactive debugger which |
|
4295 | pdb, the Python debugger, is a powerful interactive debugger which | |
4187 | allows you to step through code, set breakpoints, watch variables, etc. |
|
4296 | allows you to step through code, set breakpoints, watch variables, etc. | |
4188 | IPython makes it very easy to start any script under the control of pdb, |
|
4297 | IPython makes it very easy to start any script under the control of pdb, | |
4189 | regardless of whether you have wrapped it into a 'main()' function or |
|
4298 | regardless of whether you have wrapped it into a 'main()' function or | |
4190 | not. For this, simply type '%run -d myscript' at an IPython prompt. See |
|
4299 | not. For this, simply type '%run -d myscript' at an IPython prompt. See | |
4191 | the %run command's documentation (via '%run?' or in Sec. 6.2 |
|
4300 | the %run command's documentation (via '%run?' or in Sec. 6.2 | |
4192 | <node6.html#sec:magic>) for more details, including how to control where |
|
4301 | <node6.html#sec:magic>) for more details, including how to control where | |
4193 | pdb will stop execution first. |
|
4302 | pdb will stop execution first. | |
4194 |
|
4303 | |||
4195 | For more information on the use of the pdb debugger, read the included |
|
4304 | For more information on the use of the pdb debugger, read the included | |
4196 | pdb.doc file (part of the standard Python distribution). On a stock |
|
4305 | pdb.doc file (part of the standard Python distribution). On a stock | |
4197 | Linux system it is located at /usr/lib/python2.3/pdb.doc, but the |
|
4306 | Linux system it is located at /usr/lib/python2.3/pdb.doc, but the | |
4198 | easiest way to read it is by using the help() function of the pdb module |
|
4307 | easiest way to read it is by using the help() function of the pdb module | |
4199 | as follows (in an IPython prompt): |
|
4308 | as follows (in an IPython prompt): | |
4200 |
|
4309 | |||
4201 | In [1]: import pdb |
|
4310 | In [1]: import pdb | |
4202 | In [2]: pdb.help() |
|
4311 | In [2]: pdb.help() | |
4203 |
|
4312 | |||
4204 | This will load the pdb.doc document in a file viewer for you automatically. |
|
4313 | This will load the pdb.doc document in a file viewer for you automatically. | |
4205 |
|
4314 | |||
4206 |
|
4315 | |||
4207 | Automatic invocation of pdb on exceptions |
|
4316 | Automatic invocation of pdb on exceptions | |
4208 | ----------------------------------------- |
|
4317 | ----------------------------------------- | |
4209 |
|
4318 | |||
4210 | IPython, if started with the -pdb option (or if the option is set in |
|
4319 | IPython, if started with the -pdb option (or if the option is set in | |
4211 | your rc file) can call the Python pdb debugger every time your code |
|
4320 | your rc file) can call the Python pdb debugger every time your code | |
4212 | triggers an uncaught exception^6 <footnode.html#foot2403>. This feature |
|
4321 | triggers an uncaught exception^6 <footnode.html#foot2403>. This feature | |
4213 | can also be toggled at any time with the %pdb magic command. This can be |
|
4322 | can also be toggled at any time with the %pdb magic command. This can be | |
4214 | extremely useful in order to find the origin of subtle bugs, because pdb |
|
4323 | extremely useful in order to find the origin of subtle bugs, because pdb | |
4215 | opens up at the point in your code which triggered the exception, and |
|
4324 | opens up at the point in your code which triggered the exception, and | |
4216 | while your program is at this point 'dead', all the data is still |
|
4325 | while your program is at this point 'dead', all the data is still | |
4217 | available and you can walk up and down the stack frame and understand |
|
4326 | available and you can walk up and down the stack frame and understand | |
4218 | the origin of the problem. |
|
4327 | the origin of the problem. | |
4219 |
|
4328 | |||
4220 | Furthermore, you can use these debugging facilities both with the |
|
4329 | Furthermore, you can use these debugging facilities both with the | |
4221 | embedded IPython mode and without IPython at all. For an embedded shell |
|
4330 | embedded IPython mode and without IPython at all. For an embedded shell | |
4222 | (see sec. 9 <node9.html#sec:embed>), simply call the constructor with |
|
4331 | (see sec. 9 <node9.html#sec:embed>), simply call the constructor with | |
4223 | '-pdb' in the argument string and automatically pdb will be called if an |
|
4332 | '-pdb' in the argument string and automatically pdb will be called if an | |
4224 | uncaught exception is triggered by your code. |
|
4333 | uncaught exception is triggered by your code. | |
4225 |
|
4334 | |||
4226 | For stand-alone use of the feature in your programs which do not use |
|
4335 | For stand-alone use of the feature in your programs which do not use | |
4227 | IPython at all, put the following lines toward the top of your 'main' |
|
4336 | IPython at all, put the following lines toward the top of your 'main' | |
4228 | routine: |
|
4337 | routine:: | |
4229 |
|
4338 | |||
4230 | import sys,IPython.ultraTB |
|
4339 | import sys,IPython.ultraTB | |
4231 | sys.excepthook = IPython.ultraTB.FormattedTB(mode='Verbose', |
|
4340 | sys.excepthook = IPython.ultraTB.FormattedTB(mode='Verbose', | |
4232 | color_scheme='Linux', call_pdb=1) |
|
4341 | color_scheme='Linux', call_pdb=1) | |
4233 |
|
4342 | |||
4234 | The mode keyword can be either 'Verbose' or 'Plain', giving either very |
|
4343 | The mode keyword can be either 'Verbose' or 'Plain', giving either very | |
4235 | detailed or normal tracebacks respectively. The color_scheme keyword can |
|
4344 | detailed or normal tracebacks respectively. The color_scheme keyword can | |
4236 | be one of 'NoColor', 'Linux' (default) or 'LightBG'. These are the same |
|
4345 | be one of 'NoColor', 'Linux' (default) or 'LightBG'. These are the same | |
4237 | options which can be set in IPython with -colors and -xmode. |
|
4346 | options which can be set in IPython with -colors and -xmode. | |
4238 |
|
4347 | |||
4239 | This will give any of your programs detailed, colored tracebacks with |
|
4348 | This will give any of your programs detailed, colored tracebacks with | |
4240 | automatic invocation of pdb. |
|
4349 | automatic invocation of pdb. | |
4241 |
|
4350 | |||
4242 |
|
4351 | |||
4243 | Extensions for syntax processing |
|
4352 | Extensions for syntax processing | |
4244 | ================================ |
|
4353 | ================================ | |
4245 |
|
4354 | |||
4246 | This isn't for the faint of heart, because the potential for breaking |
|
4355 | This isn't for the faint of heart, because the potential for breaking | |
4247 | things is quite high. But it can be a very powerful and useful feature. |
|
4356 | things is quite high. But it can be a very powerful and useful feature. | |
4248 | In a nutshell, you can redefine the way IPython processes the user input |
|
4357 | In a nutshell, you can redefine the way IPython processes the user input | |
4249 | line to accept new, special extensions to the syntax without needing to |
|
4358 | line to accept new, special extensions to the syntax without needing to | |
4250 | change any of IPython's own code. |
|
4359 | change any of IPython's own code. | |
4251 |
|
4360 | |||
4252 | In the IPython/Extensions directory you will find some examples |
|
4361 | In the IPython/Extensions directory you will find some examples | |
4253 | supplied, which we will briefly describe now. These can be used 'as is' |
|
4362 | supplied, which we will briefly describe now. These can be used 'as is' | |
4254 | (and both provide very useful functionality), or you can use them as a |
|
4363 | (and both provide very useful functionality), or you can use them as a | |
4255 | starting point for writing your own extensions. |
|
4364 | starting point for writing your own extensions. | |
4256 |
|
4365 | |||
4257 |
|
4366 | |||
4258 |
Pasting of code starting with ' |
|
4367 | Pasting of code starting with '>>> ' or '... ' | |
4259 | ---------------------------------------------- |
|
4368 | ---------------------------------------------- | |
4260 |
|
4369 | |||
4261 | In the python tutorial it is common to find code examples which have |
|
4370 | In the python tutorial it is common to find code examples which have | |
4262 | been taken from real python sessions. The problem with those is that all |
|
4371 | been taken from real python sessions. The problem with those is that all | |
4263 | the lines begin with either '>>> ' or '... ', which makes it impossible |
|
4372 | the lines begin with either '>>> ' or '... ', which makes it impossible | |
4264 | to paste them all at once. One must instead do a line by line manual |
|
4373 | to paste them all at once. One must instead do a line by line manual | |
4265 | copying, carefully removing the leading extraneous characters. |
|
4374 | copying, carefully removing the leading extraneous characters. | |
4266 |
|
4375 | |||
4267 | This extension identifies those starting characters and removes them |
|
4376 | This extension identifies those starting characters and removes them | |
4268 | from the input automatically, so that one can paste multi-line examples |
|
4377 | from the input automatically, so that one can paste multi-line examples | |
4269 | directly into IPython, saving a lot of time. Please look at the file |
|
4378 | directly into IPython, saving a lot of time. Please look at the file | |
4270 | InterpreterPasteInput.py in the IPython/Extensions directory for details |
|
4379 | InterpreterPasteInput.py in the IPython/Extensions directory for details | |
4271 | on how this is done. |
|
4380 | on how this is done. | |
4272 |
|
4381 | |||
4273 | IPython comes with a special profile enabling this feature, called |
|
4382 | IPython comes with a special profile enabling this feature, called | |
4274 | tutorial. Simply start IPython via 'ipython -p tutorial' and the feature |
|
4383 | tutorial. Simply start IPython via 'ipython -p tutorial' and the feature | |
4275 | will be available. In a normal IPython session you can activate the |
|
4384 | will be available. In a normal IPython session you can activate the | |
4276 | feature by importing the corresponding module with: |
|
4385 | feature by importing the corresponding module with: | |
4277 | In [1]: import IPython.Extensions.InterpreterPasteInput |
|
4386 | In [1]: import IPython.Extensions.InterpreterPasteInput | |
4278 |
|
4387 | |||
4279 | The following is a 'screenshot' of how things work when this extension |
|
4388 | The following is a 'screenshot' of how things work when this extension | |
4280 | is on, copying an example from the standard tutorial:: |
|
4389 | is on, copying an example from the standard tutorial:: | |
4281 |
|
4390 | |||
4282 | IPython profile: tutorial |
|
4391 | IPython profile: tutorial | |
4283 |
|
4392 | |||
4284 | *** Pasting of code with ">>>" or "..." has been enabled. |
|
4393 | *** Pasting of code with ">>>" or "..." has been enabled. | |
4285 |
|
4394 | |||
4286 | In [1]: >>> def fib2(n): # return Fibonacci series up to n |
|
4395 | In [1]: >>> def fib2(n): # return Fibonacci series up to n | |
4287 | ...: ... """Return a list containing the Fibonacci series up to |
|
4396 | ...: ... """Return a list containing the Fibonacci series up to | |
4288 | n.""" |
|
4397 | n.""" | |
4289 | ...: ... result = [] |
|
4398 | ...: ... result = [] | |
4290 | ...: ... a, b = 0, 1 |
|
4399 | ...: ... a, b = 0, 1 | |
4291 | ...: ... while b < n: |
|
4400 | ...: ... while b < n: | |
4292 | ...: ... result.append(b) # see below |
|
4401 | ...: ... result.append(b) # see below | |
4293 | ...: ... a, b = b, a+b |
|
4402 | ...: ... a, b = b, a+b | |
4294 | ...: ... return result |
|
4403 | ...: ... return result | |
4295 | ...: |
|
4404 | ...: | |
4296 |
|
4405 | |||
4297 | In [2]: fib2(10) |
|
4406 | In [2]: fib2(10) | |
4298 | Out[2]: [1, 1, 2, 3, 5, 8] |
|
4407 | Out[2]: [1, 1, 2, 3, 5, 8] | |
4299 |
|
4408 | |||
4300 | Note that as currently written, this extension does not recognize |
|
4409 | Note that as currently written, this extension does not recognize | |
4301 | IPython's prompts for pasting. Those are more complicated, since the |
|
4410 | IPython's prompts for pasting. Those are more complicated, since the | |
4302 | user can change them very easily, they involve numbers and can vary in |
|
4411 | user can change them very easily, they involve numbers and can vary in | |
4303 | length. One could however extract all the relevant information from the |
|
4412 | length. One could however extract all the relevant information from the | |
4304 | IPython instance and build an appropriate regular expression. This is |
|
4413 | IPython instance and build an appropriate regular expression. This is | |
4305 | left as an exercise for the reader. |
|
4414 | left as an exercise for the reader. | |
4306 |
|
4415 | |||
4307 |
|
4416 | |||
4308 | Input of physical quantities with units |
|
4417 | Input of physical quantities with units | |
4309 | --------------------------------------- |
|
4418 | --------------------------------------- | |
4310 |
|
4419 | |||
4311 | The module PhysicalQInput allows a simplified form of input for physical |
|
4420 | The module PhysicalQInput allows a simplified form of input for physical | |
4312 | quantities with units. This file is meant to be used in conjunction with |
|
4421 | quantities with units. This file is meant to be used in conjunction with | |
4313 | the PhysicalQInteractive module (in the same directory) and |
|
4422 | the PhysicalQInteractive module (in the same directory) and | |
4314 | Physics.PhysicalQuantities from Konrad Hinsen's ScientificPython |
|
4423 | Physics.PhysicalQuantities from Konrad Hinsen's ScientificPython | |
4315 | (http://dirac.cnrs-orleans.fr/ScientificPython/). |
|
4424 | (http://dirac.cnrs-orleans.fr/ScientificPython/). | |
4316 |
|
4425 | |||
4317 | The Physics.PhysicalQuantities module defines PhysicalQuantity objects, |
|
4426 | The Physics.PhysicalQuantities module defines PhysicalQuantity objects, | |
4318 | but these must be declared as instances of a class. For example, to |
|
4427 | but these must be declared as instances of a class. For example, to | |
4319 | define v as a velocity of 3 m/s, normally you would write:: |
|
4428 | define v as a velocity of 3 m/s, normally you would write:: | |
4320 |
|
4429 | |||
4321 | In [1]: v = PhysicalQuantity(3,'m/s') |
|
4430 | In [1]: v = PhysicalQuantity(3,'m/s') | |
4322 |
|
4431 | |||
4323 | Using the PhysicalQ_Input extension this can be input instead as: |
|
4432 | Using the PhysicalQ_Input extension this can be input instead as: | |
4324 | In [1]: v = 3 m/s |
|
4433 | In [1]: v = 3 m/s | |
4325 | which is much more convenient for interactive use (even though it is |
|
4434 | which is much more convenient for interactive use (even though it is | |
4326 | blatantly invalid Python syntax). |
|
4435 | blatantly invalid Python syntax). | |
4327 |
|
4436 | |||
4328 | The physics profile supplied with IPython (enabled via 'ipython -p |
|
4437 | The physics profile supplied with IPython (enabled via 'ipython -p | |
4329 | physics') uses these extensions, which you can also activate with: |
|
4438 | physics') uses these extensions, which you can also activate with: | |
4330 |
|
4439 | |||
4331 | from math import * # math MUST be imported BEFORE PhysicalQInteractive |
|
4440 | from math import * # math MUST be imported BEFORE PhysicalQInteractive | |
4332 | from IPython.Extensions.PhysicalQInteractive import * |
|
4441 | from IPython.Extensions.PhysicalQInteractive import * | |
4333 | import IPython.Extensions.PhysicalQInput |
|
4442 | import IPython.Extensions.PhysicalQInput | |
4334 |
|
4443 | |||
4335 |
|
4444 | |||
4336 | IPython as a system shell - the 'Sh' profile |
|
4445 | IPython as a system shell - the 'Sh' profile | |
4337 | ============================================ |
|
4446 | ============================================ | |
4338 |
|
4447 | |||
4339 | The 'sh' profile optimizes IPython for system shell usage. Apart from |
|
4448 | The 'sh' profile optimizes IPython for system shell usage. Apart from | |
4340 | certain job control functionality that is present in unix (ctrl+z does |
|
4449 | certain job control functionality that is present in unix (ctrl+z does | |
4341 | "suspend"), the sh profile should provide you with most of the |
|
4450 | "suspend"), the sh profile should provide you with most of the | |
4342 | functionality you use daily in system shell, and more. Invoke IPython |
|
4451 | functionality you use daily in system shell, and more. Invoke IPython | |
4343 | in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching |
|
4452 | in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching | |
4344 | the "pysh" shortcut in start menu. |
|
4453 | the "pysh" shortcut in start menu. | |
4345 |
|
4454 | |||
4346 | If you want to use the features of sh profile as your defaults (which |
|
4455 | If you want to use the features of sh profile as your defaults (which | |
4347 | might be a good idea if you use other profiles a lot of the time but |
|
4456 | might be a good idea if you use other profiles a lot of the time but | |
4348 |
still want the convenience of sh profile), add |
|
4457 | still want the convenience of sh profile), add ``import ipy_profile_sh`` | |
4349 | to your ~/.ipython/ipy_user_conf.py. |
|
4458 | to your ~/.ipython/ipy_user_conf.py. | |
4350 |
|
4459 | |||
4351 | The 'sh' profile is different from the default profile in that: |
|
4460 | The 'sh' profile is different from the default profile in that: | |
4352 |
|
4461 | |||
4353 | * Prompt shows the current directory |
|
4462 | * Prompt shows the current directory | |
4354 | * Spacing between prompts and input is more compact (no padding with |
|
4463 | * Spacing between prompts and input is more compact (no padding with | |
4355 | empty lines). The startup banner is more compact as well. |
|
4464 | empty lines). The startup banner is more compact as well. | |
4356 | * System commands are directly available (in alias table) without |
|
4465 | * System commands are directly available (in alias table) without | |
4357 | requesting %rehashx - however, if you install new programs along |
|
4466 | requesting %rehashx - however, if you install new programs along | |
4358 | your PATH, you might want to run %rehashx to update the persistent |
|
4467 | your PATH, you might want to run %rehashx to update the persistent | |
4359 | alias table |
|
4468 | alias table | |
4360 | * Macros are stored in raw format by default. That is, instead of |
|
4469 | * Macros are stored in raw format by default. That is, instead of | |
4361 | '_ip.system("cat foo"), the macro will contain text 'cat foo') |
|
4470 | '_ip.system("cat foo"), the macro will contain text 'cat foo') | |
4362 | * Autocall is in full mode |
|
4471 | * Autocall is in full mode | |
4363 | * Calling "up" does "cd .." |
|
4472 | * Calling "up" does "cd .." | |
4364 |
|
4473 | |||
4365 | The 'sh' profile is different from the now-obsolete (and unavailable) |
|
4474 | The 'sh' profile is different from the now-obsolete (and unavailable) | |
4366 | 'pysh' profile in that: |
|
4475 | 'pysh' profile in that: | |
4367 |
|
4476 | |||
4368 | * '$$var = command' and '$var = command' syntax is not supported |
|
4477 | * '$$var = command' and '$var = command' syntax is not supported | |
4369 | * anymore. Use 'var = !command' instead (incidentally, this is |
|
4478 | * anymore. Use 'var = !command' instead (incidentally, this is | |
4370 | * available in all IPython profiles). Note that !!command *will* |
|
4479 | * available in all IPython profiles). Note that !!command *will* | |
4371 | * work. |
|
4480 | * work. | |
4372 |
|
4481 | |||
4373 | Aliases |
|
4482 | Aliases | |
4374 | ------- |
|
4483 | ------- | |
4375 |
|
4484 | |||
4376 | All of your $PATH has been loaded as IPython aliases, so you should be |
|
4485 | All of your $PATH has been loaded as IPython aliases, so you should be | |
4377 | able to type any normal system command and have it executed. See |
|
4486 | able to type any normal system command and have it executed. See | |
4378 | %alias? and %unalias? for details on the alias facilities. See also |
|
4487 | %alias? and %unalias? for details on the alias facilities. See also | |
4379 | %rehashx? for details on the mechanism used to load $PATH. |
|
4488 | %rehashx? for details on the mechanism used to load $PATH. | |
4380 |
|
4489 | |||
4381 |
|
4490 | |||
4382 | Directory management |
|
4491 | Directory management | |
4383 | -------------------- |
|
4492 | -------------------- | |
4384 |
|
4493 | |||
4385 | Since each command passed by ipython to the underlying system is executed |
|
4494 | Since each command passed by ipython to the underlying system is executed | |
4386 | in a subshell which exits immediately, you can NOT use !cd to navigate |
|
4495 | in a subshell which exits immediately, you can NOT use !cd to navigate | |
4387 | the filesystem. |
|
4496 | the filesystem. | |
4388 |
|
4497 | |||
4389 | IPython provides its own builtin '%cd' magic command to move in the |
|
4498 | IPython provides its own builtin '%cd' magic command to move in the | |
4390 | filesystem (the % is not required with automagic on). It also maintains |
|
4499 | filesystem (the % is not required with automagic on). It also maintains | |
4391 | a list of visited directories (use %dhist to see it) and allows direct |
|
4500 | a list of visited directories (use %dhist to see it) and allows direct | |
4392 | switching to any of them. Type 'cd?' for more details. |
|
4501 | switching to any of them. Type 'cd?' for more details. | |
4393 |
|
4502 | |||
4394 | %pushd, %popd and %dirs are provided for directory stack handling. |
|
4503 | %pushd, %popd and %dirs are provided for directory stack handling. | |
4395 |
|
4504 | |||
4396 |
|
4505 | |||
4397 | Enabled extensions |
|
4506 | Enabled extensions | |
4398 | ------------------ |
|
4507 | ------------------ | |
4399 |
|
4508 | |||
4400 | Some extensions, listed below, are enabled as default in this profile. |
|
4509 | Some extensions, listed below, are enabled as default in this profile. | |
4401 |
|
4510 | |||
4402 | envpersist |
|
4511 | envpersist | |
4403 | ++++++++++ |
|
4512 | ++++++++++ | |
4404 |
|
4513 | |||
4405 | %env can be used to "remember" environment variable manipulations. Examples:: |
|
4514 | %env can be used to "remember" environment variable manipulations. Examples:: | |
4406 |
|
4515 | |||
4407 | %env - Show all environment variables |
|
4516 | %env - Show all environment variables | |
4408 | %env VISUAL=jed - set VISUAL to jed |
|
4517 | %env VISUAL=jed - set VISUAL to jed | |
4409 | %env PATH+=;/foo - append ;foo to PATH |
|
4518 | %env PATH+=;/foo - append ;foo to PATH | |
4410 | %env PATH+=;/bar - also append ;bar to PATH |
|
4519 | %env PATH+=;/bar - also append ;bar to PATH | |
4411 | %env PATH-=/wbin; - prepend /wbin; to PATH |
|
4520 | %env PATH-=/wbin; - prepend /wbin; to PATH | |
4412 | %env -d VISUAL - forget VISUAL persistent val |
|
4521 | %env -d VISUAL - forget VISUAL persistent val | |
4413 | %env -p - print all persistent env modifications |
|
4522 | %env -p - print all persistent env modifications | |
4414 |
|
4523 | |||
4415 | ipy_which |
|
4524 | ipy_which | |
4416 | +++++++++ |
|
4525 | +++++++++ | |
4417 |
|
4526 | |||
4418 | %which magic command. Like 'which' in unix, but knows about ipython aliases. |
|
4527 | %which magic command. Like 'which' in unix, but knows about ipython aliases. | |
4419 |
|
4528 | |||
4420 | Example:: |
|
4529 | Example:: | |
4421 |
|
4530 | |||
4422 | [C:/ipython]|14> %which st |
|
4531 | [C:/ipython]|14> %which st | |
4423 | st -> start . |
|
4532 | st -> start . | |
4424 | [C:/ipython]|15> %which d |
|
4533 | [C:/ipython]|15> %which d | |
4425 | d -> dir /w /og /on |
|
4534 | d -> dir /w /og /on | |
4426 | [C:/ipython]|16> %which cp |
|
4535 | [C:/ipython]|16> %which cp | |
4427 | cp -> cp |
|
4536 | cp -> cp | |
4428 | == c:\bin\cp.exe |
|
4537 | == c:\bin\cp.exe | |
4429 | c:\bin\cp.exe |
|
4538 | c:\bin\cp.exe | |
4430 |
|
4539 | |||
4431 | ipy_app_completers |
|
4540 | ipy_app_completers | |
4432 | ++++++++++++++++++ |
|
4541 | ++++++++++++++++++ | |
4433 |
|
4542 | |||
4434 | Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu. |
|
4543 | Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu. | |
4435 |
|
4544 | |||
4436 | ipy_rehashdir |
|
4545 | ipy_rehashdir | |
4437 | +++++++++++++ |
|
4546 | +++++++++++++ | |
4438 |
|
4547 | |||
4439 | 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:: |
|
4548 | 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:: | |
4440 |
|
4549 | |||
4441 | [~]|22> cd c:/opt/PuTTY/ |
|
4550 | [~]|22> cd c:/opt/PuTTY/ | |
4442 | [c:opt/PuTTY]|23> rehashdir . |
|
4551 | [c:opt/PuTTY]|23> rehashdir . | |
4443 | <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000'] |
|
4552 | <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000'] | |
4444 |
|
4553 | |||
4445 | Now, you can execute any of those commams directly:: |
|
4554 | Now, you can execute any of those commams directly:: | |
4446 |
|
4555 | |||
4447 | [c:opt/PuTTY]|24> cd |
|
4556 | [c:opt/PuTTY]|24> cd | |
4448 | [~]|25> putty |
|
4557 | [~]|25> putty | |
4449 |
|
4558 | |||
4450 | (the putty window opens). |
|
4559 | (the putty window opens). | |
4451 |
|
4560 | |||
4452 | 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:: |
|
4561 | 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:: | |
4453 |
|
4562 | |||
4454 | [~]|27> for a in _23: |
|
4563 | [~]|27> for a in _23: | |
4455 | |..> %store $a |
|
4564 | |..> %store $a | |
4456 | |..> |
|
4565 | |..> | |
4457 | |..> |
|
4566 | |..> | |
4458 | Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe') |
|
4567 | Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe') | |
4459 | Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe') |
|
4568 | Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe') | |
4460 | Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe') |
|
4569 | Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe') | |
4461 | Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe') |
|
4570 | Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe') | |
4462 | ... |
|
4571 | ... | |
4463 |
|
4572 | |||
4464 | mglob |
|
4573 | mglob | |
4465 | +++++ |
|
4574 | +++++ | |
4466 |
|
4575 | |||
4467 | Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples:: |
|
4576 | Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples:: | |
4468 |
|
4577 | |||
4469 | [c:/ipython]|9> mglob *.py |
|
4578 | [c:/ipython]|9> mglob *.py | |
4470 | [c:/ipython]|10> mglob *.py rec:*.txt |
|
4579 | [c:/ipython]|10> mglob *.py rec:*.txt | |
4471 | [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:. |
|
4580 | [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:. | |
4472 |
|
4581 | |||
4473 | 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'. |
|
4582 | 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'. | |
4474 |
|
4583 | |||
4475 |
|
4584 | |||
|
4585 | Prompt customization | |||
|
4586 | -------------------- | |||
4476 |
|
4587 | |||
|
4588 | The sh profile uses the following prompt configurations:: | |||
4477 |
|
4589 | |||
|
4590 | o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>' | |||
|
4591 | o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>' | |||
4478 |
|
4592 | |||
4479 | Prompt customization |
|
4593 | You can change the prompt configuration to your liking by editing | |
4480 | -------------------- |
|
4594 | ipy_user_conf.py. | |
4481 |
|
4595 | |||
4482 | The supplied ipy_profile_sh.py profile comes with an example of a very |
|
4596 | String lists | |
4483 | colored and detailed prompt, mainly to serve as an illustration. The |
|
4597 | ============ | |
4484 | valid escape sequences, besides color names, are:: |
|
4598 | ||
|
4599 | String lists (IPython.genutils.SList) are handy way to process output | |||
|
4600 | from system commands. They are produced by ``var = !cmd`` syntax. | |||
|
4601 | ||||
|
4602 | First, we acquire the output of 'ls -l':: | |||
|
4603 | ||||
|
4604 | [Q:doc/examples]|2> lines = !ls -l | |||
|
4605 | == | |||
|
4606 | ['total 23', | |||
|
4607 | '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py', | |||
|
4608 | '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py', | |||
|
4609 | '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py', | |||
|
4610 | '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py', | |||
|
4611 | '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py', | |||
|
4612 | '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py', | |||
|
4613 | '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc'] | |||
|
4614 | ||||
|
4615 | Now, let's take a look at the contents of 'lines' (the first number is | |||
|
4616 | the list element number):: | |||
|
4617 | ||||
|
4618 | [Q:doc/examples]|3> lines | |||
|
4619 | <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value: | |||
|
4620 | ||||
|
4621 | 0: total 23 | |||
|
4622 | 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py | |||
|
4623 | 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py | |||
|
4624 | 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py | |||
|
4625 | 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py | |||
|
4626 | 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py | |||
|
4627 | 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py | |||
|
4628 | 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc | |||
|
4629 | ||||
|
4630 | Now, let's filter out the 'embed' lines:: | |||
|
4631 | ||||
|
4632 | [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1) | |||
|
4633 | [Q:doc/examples]|5> l2 | |||
|
4634 | <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value: | |||
|
4635 | ||||
|
4636 | 0: total 23 | |||
|
4637 | 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py | |||
|
4638 | 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py | |||
|
4639 | 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py | |||
|
4640 | 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py | |||
|
4641 | 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc | |||
|
4642 | ||||
|
4643 | Now, we want strings having just file names and permissions:: | |||
|
4644 | ||||
|
4645 | [Q:doc/examples]|6> l2.fields(8,0) | |||
|
4646 | <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value: | |||
|
4647 | ||||
|
4648 | 0: total | |||
|
4649 | 1: example-demo.py -rw-rw-rw- | |||
|
4650 | 2: example-gnuplot.py -rwxrwxrwx | |||
|
4651 | 3: extension.py -rwxrwxrwx | |||
|
4652 | 4: seteditor.py -rwxrwxrwx | |||
|
4653 | 5: seteditor.pyc -rwxrwxrwx | |||
|
4654 | ||||
|
4655 | Note how the line with 'total' does not raise IndexError. | |||
|
4656 | ||||
|
4657 | If you want to split these (yielding lists), call fields() without | |||
|
4658 | arguments:: | |||
|
4659 | ||||
|
4660 | [Q:doc/examples]|7> _.fields() | |||
|
4661 | <7> | |||
|
4662 | [['total'], | |||
|
4663 | ['example-demo.py', '-rw-rw-rw-'], | |||
|
4664 | ['example-gnuplot.py', '-rwxrwxrwx'], | |||
|
4665 | ['extension.py', '-rwxrwxrwx'], | |||
|
4666 | ['seteditor.py', '-rwxrwxrwx'], | |||
|
4667 | ['seteditor.pyc', '-rwxrwxrwx']] | |||
|
4668 | ||||
|
4669 | If you want to pass these separated with spaces to a command (typical | |||
|
4670 | for lists if files), use the .s property:: | |||
|
4671 | ||||
|
4672 | ||||
|
4673 | [Q:doc/examples]|13> files = l2.fields(8).s | |||
|
4674 | [Q:doc/examples]|14> files | |||
|
4675 | <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc' | |||
|
4676 | [Q:doc/examples]|15> ls $files | |||
|
4677 | example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc | |||
|
4678 | ||||
|
4679 | SLists are inherited from normal python lists, so every list method is | |||
|
4680 | available:: | |||
|
4681 | ||||
|
4682 | [Q:doc/examples]|21> lines.append('hey') | |||
|
4683 | ||||
|
4684 | ||||
|
4685 | Real world example: remove all files outside version control | |||
|
4686 | ------------------------------------------------------------ | |||
|
4687 | ||||
|
4688 | First, capture output of "hg status":: | |||
|
4689 | ||||
|
4690 | [Q:/ipython]|28> out = !hg status | |||
|
4691 | == | |||
|
4692 | ['M IPython\\Extensions\\ipy_kitcfg.py', | |||
|
4693 | 'M IPython\\Extensions\\ipy_rehashdir.py', | |||
|
4694 | ... | |||
|
4695 | '? build\\lib\\IPython\\Debugger.py', | |||
|
4696 | '? build\\lib\\IPython\\Extensions\\InterpreterExec.py', | |||
|
4697 | '? build\\lib\\IPython\\Extensions\\InterpreterPasteInput.py', | |||
|
4698 | ... | |||
|
4699 | ||||
|
4700 | (lines starting with ? are not under version control). | |||
|
4701 | ||||
|
4702 | :: | |||
|
4703 | ||||
|
4704 | [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1) | |||
|
4705 | [Q:/ipython]|36> junk | |||
|
4706 | <36> SList (.p, .n, .l, .s, .grep(), .fields() availab | |||
|
4707 | ... | |||
|
4708 | 10: build\bdist.win32\winexe\temp\_ctypes.py | |||
|
4709 | 11: build\bdist.win32\winexe\temp\_hashlib.py | |||
|
4710 | 12: build\bdist.win32\winexe\temp\_socket.py | |||
|
4711 | ||||
|
4712 | Now we can just remove these files by doing 'rm $junk.s'. | |||
|
4713 | ||||
|
4714 | The .s, .n, .p properties | |||
|
4715 | ------------------------- | |||
|
4716 | ||||
|
4717 | The '.s' property returns one string where lines are separated by | |||
|
4718 | single space (for convenient passing to system commands). The '.n' | |||
|
4719 | property return one string where the lines are separated by '\n' | |||
|
4720 | (i.e. the original output of the function). If the items in string | |||
|
4721 | list are file names, '.p' can be used to get a list of "path" objects | |||
|
4722 | for convenient file manipulation. | |||
4485 |
|
4723 | |||
4486 | \# |
|
|||
4487 | - Prompt number, wrapped in the color escapes for the input prompt |
|
|||
4488 | (determined by the current color scheme). |
|
|||
4489 | \N |
|
|||
4490 | - Just the prompt counter number, without any coloring wrappers. You |
|
|||
4491 | can thus customize the actual prompt colors manually. |
|
|||
4492 | \D |
|
|||
4493 | - Dots, as many as there are digits in \# (so they align). |
|
|||
4494 | \w |
|
|||
4495 | - Current working directory (cwd). |
|
|||
4496 | \W |
|
|||
4497 | - Basename of current working directory. |
|
|||
4498 | \XN |
|
|||
4499 | - Where N=0..5. N terms of the cwd, with $HOME written as ~. |
|
|||
4500 | \YN |
|
|||
4501 | - Where N=0..5. Like XN, but if ~ is term N+1 it's also shown. |
|
|||
4502 | \u |
|
|||
4503 | - Username. |
|
|||
4504 | \H |
|
|||
4505 | - Full hostname. |
|
|||
4506 | \h |
|
|||
4507 | - Hostname up to first '.' |
|
|||
4508 | \$ |
|
|||
4509 | - Root symbol ($ or #). |
|
|||
4510 | \t |
|
|||
4511 | - Current time, in H:M:S format. |
|
|||
4512 | \v |
|
|||
4513 | - IPython release version. |
|
|||
4514 | \n |
|
|||
4515 | - Newline. |
|
|||
4516 | \r |
|
|||
4517 | - Carriage return. |
|
|||
4518 | \\ |
|
|||
4519 | - An explicitly escaped '\'. |
|
|||
4520 |
|
||||
4521 | You can configure your prompt colors using any ANSI color escape. Each |
|
|||
4522 | color escape sets the color for any subsequent text, until another |
|
|||
4523 | escape comes in and changes things. The valid color escapes are:: |
|
|||
4524 |
|
||||
4525 | \C_Black |
|
|||
4526 | \C_Blue |
|
|||
4527 | \C_Brown |
|
|||
4528 | \C_Cyan |
|
|||
4529 | \C_DarkGray |
|
|||
4530 | \C_Green |
|
|||
4531 | \C_LightBlue |
|
|||
4532 | \C_LightCyan |
|
|||
4533 | \C_LightGray |
|
|||
4534 | \C_LightGreen |
|
|||
4535 | \C_LightPurple |
|
|||
4536 | \C_LightRed |
|
|||
4537 | \C_Purple |
|
|||
4538 | \C_Red |
|
|||
4539 | \C_White |
|
|||
4540 | \C_Yellow |
|
|||
4541 | \C_Normal |
|
|||
4542 | Stop coloring, defaults to your terminal settings. |
|
|||
4543 |
|
4724 | |||
4544 | Threading support |
|
4725 | Threading support | |
4545 | ================= |
|
4726 | ================= | |
4546 |
|
4727 | |||
4547 | WARNING: The threading support is still somewhat experimental, and it |
|
4728 | WARNING: The threading support is still somewhat experimental, and it | |
4548 | has only seen reasonable testing under Linux. Threaded code is |
|
4729 | has only seen reasonable testing under Linux. Threaded code is | |
4549 | particularly tricky to debug, and it tends to show extremely |
|
4730 | particularly tricky to debug, and it tends to show extremely | |
4550 | platform-dependent behavior. Since I only have access to Linux machines, |
|
4731 | platform-dependent behavior. Since I only have access to Linux machines, | |
4551 | I will have to rely on user's experiences and assistance for this area |
|
4732 | I will have to rely on user's experiences and assistance for this area | |
4552 | of IPython to improve under other platforms. |
|
4733 | of IPython to improve under other platforms. | |
4553 |
|
4734 | |||
4554 | IPython, via the -gthread , -qthread, -q4thread and -wthread options |
|
4735 | IPython, via the -gthread , -qthread, -q4thread and -wthread options | |
4555 | (described in Sec. 5.1 <node5.html#sec:threading-opts>), can run in |
|
4736 | (described in Sec. 5.1 <node5.html#sec:threading-opts>), can run in | |
4556 | multithreaded mode to support pyGTK, Qt3, Qt4 and WXPython applications |
|
4737 | multithreaded mode to support pyGTK, Qt3, Qt4 and WXPython applications | |
4557 | respectively. These GUI toolkits need to control the python main loop of |
|
4738 | respectively. These GUI toolkits need to control the python main loop of | |
4558 | execution, so under a normal Python interpreter, starting a pyGTK, Qt3, |
|
4739 | execution, so under a normal Python interpreter, starting a pyGTK, Qt3, | |
4559 | Qt4 or WXPython application will immediately freeze the shell. |
|
4740 | Qt4 or WXPython application will immediately freeze the shell. | |
4560 |
|
4741 | |||
4561 | IPython, with one of these options (you can only use one at a time), |
|
4742 | IPython, with one of these options (you can only use one at a time), | |
4562 | separates the graphical loop and IPython's code execution run into |
|
4743 | separates the graphical loop and IPython's code execution run into | |
4563 | different threads. This allows you to test interactively (with %run, for |
|
4744 | different threads. This allows you to test interactively (with %run, for | |
4564 | example) your GUI code without blocking. |
|
4745 | example) your GUI code without blocking. | |
4565 |
|
4746 | |||
4566 | A nice mini-tutorial on using IPython along with the Qt Designer |
|
4747 | A nice mini-tutorial on using IPython along with the Qt Designer | |
4567 | application is available at the SciPy wiki: |
|
4748 | application is available at the SciPy wiki: | |
4568 | http://www.scipy.org/Cookbook/Matplotlib/Qt_with_IPython_and_Designer. |
|
4749 | http://www.scipy.org/Cookbook/Matplotlib/Qt_with_IPython_and_Designer. | |
4569 |
|
4750 | |||
4570 |
|
4751 | |||
4571 | Tk issues |
|
4752 | Tk issues | |
4572 | --------- |
|
4753 | --------- | |
4573 |
|
4754 | |||
4574 | As indicated in Sec. 5.1 <node5.html#sec:threading-opts>, a special -tk |
|
4755 | As indicated in Sec. 5.1 <node5.html#sec:threading-opts>, a special -tk | |
4575 | option is provided to try and allow Tk graphical applications to coexist |
|
4756 | option is provided to try and allow Tk graphical applications to coexist | |
4576 | interactively with WX, Qt or GTK ones. Whether this works at all, |
|
4757 | interactively with WX, Qt or GTK ones. Whether this works at all, | |
4577 | however, is very platform and configuration dependent. Please experiment |
|
4758 | however, is very platform and configuration dependent. Please experiment | |
4578 | with simple test cases before committing to using this combination of Tk |
|
4759 | with simple test cases before committing to using this combination of Tk | |
4579 | and GTK/Qt/WX threading in a production environment. |
|
4760 | and GTK/Qt/WX threading in a production environment. | |
4580 |
|
4761 | |||
4581 |
|
4762 | |||
4582 | I/O pitfalls |
|
4763 | I/O pitfalls | |
4583 | ------------ |
|
4764 | ------------ | |
4584 |
|
4765 | |||
4585 | Be mindful that the Python interpreter switches between threads every |
|
4766 | Be mindful that the Python interpreter switches between threads every | |
4586 | $N$ bytecodes, where the default value as of Python 2.3 is $N=100.$ This |
|
4767 | $N$ bytecodes, where the default value as of Python 2.3 is $N=100.$ This | |
4587 | value can be read by using the sys.getcheckinterval() function, and it |
|
4768 | value can be read by using the sys.getcheckinterval() function, and it | |
4588 | can be reset via sys.setcheckinterval(N). This switching of threads can |
|
4769 | can be reset via sys.setcheckinterval(N). This switching of threads can | |
4589 | cause subtly confusing effects if one of your threads is doing file I/O. |
|
4770 | cause subtly confusing effects if one of your threads is doing file I/O. | |
4590 | In text mode, most systems only flush file buffers when they encounter a |
|
4771 | In text mode, most systems only flush file buffers when they encounter a | |
4591 | '\n'. An instruction as simple as:: |
|
4772 | '\n'. An instruction as simple as:: | |
4592 |
|
4773 | |||
4593 | print >> filehandle, ''hello world'' |
|
4774 | print >> filehandle, ''hello world'' | |
4594 |
|
4775 | |||
4595 | actually consists of several bytecodes, so it is possible that the |
|
4776 | actually consists of several bytecodes, so it is possible that the | |
4596 | newline does not reach your file before the next thread switch. |
|
4777 | newline does not reach your file before the next thread switch. | |
4597 | Similarly, if you are writing to a file in binary mode, the file won't |
|
4778 | Similarly, if you are writing to a file in binary mode, the file won't | |
4598 | be flushed until the buffer fills, and your other thread may see |
|
4779 | be flushed until the buffer fills, and your other thread may see | |
4599 | apparently truncated files. |
|
4780 | apparently truncated files. | |
4600 |
|
4781 | |||
4601 | For this reason, if you are using IPython's thread support and have (for |
|
4782 | For this reason, if you are using IPython's thread support and have (for | |
4602 | example) a GUI application which will read data generated by files |
|
4783 | example) a GUI application which will read data generated by files | |
4603 | written to from the IPython thread, the safest approach is to open all |
|
4784 | written to from the IPython thread, the safest approach is to open all | |
4604 | of your files in unbuffered mode (the third argument to the file/open |
|
4785 | of your files in unbuffered mode (the third argument to the file/open | |
4605 | function is the buffering value):: |
|
4786 | function is the buffering value):: | |
4606 |
|
4787 | |||
4607 | filehandle = open(filename,mode,0) |
|
4788 | filehandle = open(filename,mode,0) | |
4608 |
|
4789 | |||
4609 | This is obviously a brute force way of avoiding race conditions with the |
|
4790 | This is obviously a brute force way of avoiding race conditions with the | |
4610 | file buffering. If you want to do it cleanly, and you have a resource |
|
4791 | file buffering. If you want to do it cleanly, and you have a resource | |
4611 | which is being shared by the interactive IPython loop and your GUI |
|
4792 | which is being shared by the interactive IPython loop and your GUI | |
4612 | thread, you should really handle it with thread locking and |
|
4793 | thread, you should really handle it with thread locking and | |
4613 | syncrhonization properties. The Python documentation discusses these. |
|
4794 | syncrhonization properties. The Python documentation discusses these. | |
4614 |
|
4795 | |||
4615 | Interactive demos with IPython |
|
4796 | Interactive demos with IPython | |
4616 | ============================== |
|
4797 | ============================== | |
4617 |
|
4798 | |||
4618 | IPython ships with a basic system for running scripts interactively in |
|
4799 | IPython ships with a basic system for running scripts interactively in | |
4619 | sections, useful when presenting code to audiences. A few tags embedded |
|
4800 | sections, useful when presenting code to audiences. A few tags embedded | |
4620 | in comments (so that the script remains valid Python code) divide a file |
|
4801 | in comments (so that the script remains valid Python code) divide a file | |
4621 | into separate blocks, and the demo can be run one block at a time, with |
|
4802 | into separate blocks, and the demo can be run one block at a time, with | |
4622 | IPython printing (with syntax highlighting) the block before executing |
|
4803 | IPython printing (with syntax highlighting) the block before executing | |
4623 | it, and returning to the interactive prompt after each block. The |
|
4804 | it, and returning to the interactive prompt after each block. The | |
4624 | interactive namespace is updated after each block is run with the |
|
4805 | interactive namespace is updated after each block is run with the | |
4625 | contents of the demo's namespace. |
|
4806 | contents of the demo's namespace. | |
4626 |
|
4807 | |||
4627 | This allows you to show a piece of code, run it and then execute |
|
4808 | This allows you to show a piece of code, run it and then execute | |
4628 | interactively commands based on the variables just created. Once you |
|
4809 | interactively commands based on the variables just created. Once you | |
4629 | want to continue, you simply execute the next block of the demo. The |
|
4810 | want to continue, you simply execute the next block of the demo. The | |
4630 | following listing shows the markup necessary for dividing a script into |
|
4811 | following listing shows the markup necessary for dividing a script into | |
4631 | sections for execution as a demo:: |
|
4812 | sections for execution as a demo:: | |
4632 |
|
4813 | |||
4633 |
|
4814 | |||
4634 | """A simple interactive demo to illustrate the use of IPython's Demo class. |
|
4815 | """A simple interactive demo to illustrate the use of IPython's Demo class. | |
4635 |
|
4816 | |||
4636 | Any python script can be run as a demo, but that does little more than showing |
|
4817 | Any python script can be run as a demo, but that does little more than showing | |
4637 | it on-screen, syntax-highlighted in one shot. If you add a little simple |
|
4818 | it on-screen, syntax-highlighted in one shot. If you add a little simple | |
4638 | markup, you can stop at specified intervals and return to the ipython prompt, |
|
4819 | markup, you can stop at specified intervals and return to the ipython prompt, | |
4639 | resuming execution later. |
|
4820 | resuming execution later. | |
4640 | """ |
|
4821 | """ | |
4641 |
|
4822 | |||
4642 | print 'Hello, welcome to an interactive IPython demo.' |
|
4823 | print 'Hello, welcome to an interactive IPython demo.' | |
4643 | print 'Executing this block should require confirmation before proceeding,' |
|
4824 | print 'Executing this block should require confirmation before proceeding,' | |
4644 | print 'unless auto_all has been set to true in the demo object' |
|
4825 | print 'unless auto_all has been set to true in the demo object' | |
4645 |
|
4826 | |||
4646 | # The mark below defines a block boundary, which is a point where IPython will |
|
4827 | # The mark below defines a block boundary, which is a point where IPython will | |
4647 | # stop execution and return to the interactive prompt. |
|
4828 | # stop execution and return to the interactive prompt. | |
4648 | # Note that in actual interactive execution, |
|
4829 | # Note that in actual interactive execution, | |
4649 | # <demo> --- stop --- |
|
4830 | # <demo> --- stop --- | |
4650 |
|
4831 | |||
4651 | x = 1 |
|
4832 | x = 1 | |
4652 | y = 2 |
|
4833 | y = 2 | |
4653 |
|
4834 | |||
4654 | # <demo> --- stop --- |
|
4835 | # <demo> --- stop --- | |
4655 |
|
4836 | |||
4656 | # the mark below makes this block as silent |
|
4837 | # the mark below makes this block as silent | |
4657 | # <demo> silent |
|
4838 | # <demo> silent | |
4658 |
|
4839 | |||
4659 | print 'This is a silent block, which gets executed but not printed.' |
|
4840 | print 'This is a silent block, which gets executed but not printed.' | |
4660 |
|
4841 | |||
4661 | # <demo> --- stop --- |
|
4842 | # <demo> --- stop --- | |
4662 | # <demo> auto |
|
4843 | # <demo> auto | |
4663 | print 'This is an automatic block.' |
|
4844 | print 'This is an automatic block.' | |
4664 | print 'It is executed without asking for confirmation, but printed.' |
|
4845 | print 'It is executed without asking for confirmation, but printed.' | |
4665 | z = x+y |
|
4846 | z = x+y | |
4666 |
|
4847 | |||
4667 | print 'z=',x |
|
4848 | print 'z=',x | |
4668 |
|
4849 | |||
4669 | # <demo> --- stop --- |
|
4850 | # <demo> --- stop --- | |
4670 | # This is just another normal block. |
|
4851 | # This is just another normal block. | |
4671 | print 'z is now:', z |
|
4852 | print 'z is now:', z | |
4672 |
|
4853 | |||
4673 | print 'bye!' |
|
4854 | print 'bye!' | |
4674 |
|
4855 | |||
4675 | In order to run a file as a demo, you must first make a Demo object out |
|
4856 | In order to run a file as a demo, you must first make a Demo object out | |
4676 | of it. If the file is named myscript.py, the following code will make a |
|
4857 | of it. If the file is named myscript.py, the following code will make a | |
4677 | demo:: |
|
4858 | demo:: | |
4678 |
|
4859 | |||
4679 | from IPython.demo import Demo |
|
4860 | from IPython.demo import Demo | |
4680 |
|
4861 | |||
4681 | mydemo = Demo('myscript.py') |
|
4862 | mydemo = Demo('myscript.py') | |
4682 |
|
4863 | |||
4683 | This creates the mydemo object, whose blocks you run one at a time by |
|
4864 | This creates the mydemo object, whose blocks you run one at a time by | |
4684 | simply calling the object with no arguments. If you have autocall active |
|
4865 | simply calling the object with no arguments. If you have autocall active | |
4685 | in IPython (the default), all you need to do is type:: |
|
4866 | in IPython (the default), all you need to do is type:: | |
4686 |
|
4867 | |||
4687 | mydemo |
|
4868 | mydemo | |
4688 |
|
4869 | |||
4689 | and IPython will call it, executing each block. Demo objects can be |
|
4870 | and IPython will call it, executing each block. Demo objects can be | |
4690 | restarted, you can move forward or back skipping blocks, re-execute the |
|
4871 | restarted, you can move forward or back skipping blocks, re-execute the | |
4691 | last block, etc. Simply use the Tab key on a demo object to see its |
|
4872 | last block, etc. Simply use the Tab key on a demo object to see its | |
4692 | methods, and call '?' on them to see their docstrings for more usage |
|
4873 | methods, and call '?' on them to see their docstrings for more usage | |
4693 | details. In addition, the demo module itself contains a comprehensive |
|
4874 | details. In addition, the demo module itself contains a comprehensive | |
4694 | docstring, which you can access via:: |
|
4875 | docstring, which you can access via:: | |
4695 |
|
4876 | |||
4696 | from IPython import demo |
|
4877 | from IPython import demo | |
4697 |
|
4878 | |||
4698 | demo? |
|
4879 | demo? | |
4699 |
|
4880 | |||
4700 | Limitations: It is important to note that these demos are limited to |
|
4881 | Limitations: It is important to note that these demos are limited to | |
4701 | fairly simple uses. In particular, you can not put division marks in |
|
4882 | fairly simple uses. In particular, you can not put division marks in | |
4702 | indented code (loops, if statements, function definitions, etc.) |
|
4883 | indented code (loops, if statements, function definitions, etc.) | |
4703 | Supporting something like this would basically require tracking the |
|
4884 | Supporting something like this would basically require tracking the | |
4704 | internal execution state of the Python interpreter, so only top-level |
|
4885 | internal execution state of the Python interpreter, so only top-level | |
4705 | divisions are allowed. If you want to be able to open an IPython |
|
4886 | divisions are allowed. If you want to be able to open an IPython | |
4706 | instance at an arbitrary point in a program, you can use IPython's |
|
4887 | instance at an arbitrary point in a program, you can use IPython's | |
4707 | embedding facilities, described in detail in Sec. 9 |
|
4888 | embedding facilities, described in detail in Sec. 9 | |
4708 |
|
4889 | |||
4709 |
|
4890 | |||
4710 | Plotting with matplotlib |
|
4891 | Plotting with matplotlib | |
4711 | ======================== |
|
4892 | ======================== | |
4712 |
|
4893 | |||
4713 | The matplotlib library (http://matplotlib.sourceforge.net |
|
4894 | The matplotlib library (http://matplotlib.sourceforge.net | |
4714 | http://matplotlib.sourceforge.net) provides high quality 2D plotting for |
|
4895 | http://matplotlib.sourceforge.net) provides high quality 2D plotting for | |
4715 | Python. Matplotlib can produce plots on screen using a variety of GUI |
|
4896 | Python. Matplotlib can produce plots on screen using a variety of GUI | |
4716 | toolkits, including Tk, GTK and WXPython. It also provides a number of |
|
4897 | toolkits, including Tk, GTK and WXPython. It also provides a number of | |
4717 | commands useful for scientific computing, all with a syntax compatible |
|
4898 | commands useful for scientific computing, all with a syntax compatible | |
4718 | with that of the popular Matlab program. |
|
4899 | with that of the popular Matlab program. | |
4719 |
|
4900 | |||
4720 | IPython accepts the special option -pylab (Sec. 5.2 |
|
4901 | IPython accepts the special option -pylab (Sec. 5.2 | |
4721 | <node5.html#sec:cmd-line-opts>). This configures it to support |
|
4902 | <node5.html#sec:cmd-line-opts>). This configures it to support | |
4722 | matplotlib, honoring the settings in the .matplotlibrc file. IPython |
|
4903 | matplotlib, honoring the settings in the .matplotlibrc file. IPython | |
4723 | will detect the user's choice of matplotlib GUI backend, and |
|
4904 | will detect the user's choice of matplotlib GUI backend, and | |
4724 | automatically select the proper threading model to prevent blocking. It |
|
4905 | automatically select the proper threading model to prevent blocking. It | |
4725 | also sets matplotlib in interactive mode and modifies %run slightly, so |
|
4906 | also sets matplotlib in interactive mode and modifies %run slightly, so | |
4726 | that any matplotlib-based script can be executed using %run and the |
|
4907 | that any matplotlib-based script can be executed using %run and the | |
4727 | final show() command does not block the interactive shell. |
|
4908 | final show() command does not block the interactive shell. | |
4728 |
|
4909 | |||
4729 | The -pylab option must be given first in order for IPython to configure |
|
4910 | The -pylab option must be given first in order for IPython to configure | |
4730 | its threading mode. However, you can still issue other options |
|
4911 | its threading mode. However, you can still issue other options | |
4731 | afterwards. This allows you to have a matplotlib-based environment |
|
4912 | afterwards. This allows you to have a matplotlib-based environment | |
4732 | customized with additional modules using the standard IPython profile |
|
4913 | customized with additional modules using the standard IPython profile | |
4733 | mechanism (Sec. 7.3 <node7.html#sec:profiles>): ''ipython -pylab -p |
|
4914 | mechanism (Sec. 7.3 <node7.html#sec:profiles>): ''ipython -pylab -p | |
4734 | myprofile'' will load the profile defined in ipythonrc-myprofile after |
|
4915 | myprofile'' will load the profile defined in ipythonrc-myprofile after | |
4735 | configuring matplotlib. |
|
4916 | configuring matplotlib. | |
4736 |
|
4917 | |||
|
4918 | IPython Extension Api | |||
|
4919 | ===================== | |||
|
4920 | ||||
|
4921 | IPython api (defined in IPython/ipapi.py) is the public api that | |||
|
4922 | should be used for | |||
|
4923 | ||||
|
4924 | * Configuration of user preferences (.ipython/ipy_user_conf.py) | |||
|
4925 | * Creating new profiles (.ipython/ipy_profile_PROFILENAME.py) | |||
|
4926 | * Writing extensions | |||
|
4927 | ||||
|
4928 | Note that by using the extension api for configuration (editing | |||
|
4929 | ipy_user_conf.py instead of ipythonrc), you get better validity checks | |||
|
4930 | and get richer functionality - for example, you can import an | |||
|
4931 | extension and call functions in it to configure it for your purposes. | |||
|
4932 | ||||
|
4933 | For an example extension (the 'sh' profile), see | |||
|
4934 | IPython/Extensions/ipy_profile_sh.py. | |||
|
4935 | ||||
|
4936 | For the last word on what's available, see the source code of | |||
|
4937 | IPython/ipapi.py. | |||
|
4938 | ||||
|
4939 | ||||
|
4940 | Getting started | |||
|
4941 | --------------- | |||
|
4942 | ||||
|
4943 | If you want to define an extension, create a normal python module that | |||
|
4944 | can be imported. The module will access IPython functionality through | |||
|
4945 | the 'ip' object defined below. | |||
|
4946 | ||||
|
4947 | If you are creating a new profile (e.g. foobar), name the module as | |||
|
4948 | 'ipy_profile_foobar.py' and put it in your ~/.ipython directory. Then, | |||
|
4949 | when you start ipython with the '-p foobar' argument, the module is | |||
|
4950 | automatically imported on ipython startup. | |||
|
4951 | ||||
|
4952 | If you are just doing some per-user configuration, you can either | |||
|
4953 | ||||
|
4954 | * Put the commands directly into ipy_user_conf.py. | |||
|
4955 | ||||
|
4956 | * Create a new module with your customization code and import *that* | |||
|
4957 | module in ipy_user_conf.py. This is preferable to the first approach, | |||
|
4958 | because now you can reuse and distribute your customization code. | |||
|
4959 | ||||
|
4960 | Getting a handle to the api | |||
|
4961 | --------------------------- | |||
|
4962 | ||||
|
4963 | Put this in the start of your module:: | |||
|
4964 | ||||
|
4965 | #!python | |||
|
4966 | import IPython.ipapi | |||
|
4967 | ip = IPython.ipapi.get() | |||
|
4968 | ||||
|
4969 | The 'ip' object will then be used for accessing IPython | |||
|
4970 | functionality. 'ip' will mean this api object in all the following | |||
|
4971 | code snippets. The same 'ip' that we just acquired is always | |||
|
4972 | accessible in interactive IPython sessions by the name _ip - play with | |||
|
4973 | it like this:: | |||
|
4974 | ||||
|
4975 | [~\_ipython]|81> a = 10 | |||
|
4976 | [~\_ipython]|82> _ip.e | |||
|
4977 | _ip.ev _ip.ex _ip.expose_magic | |||
|
4978 | [~\_ipython]|82> _ip.ev('a+13') | |||
|
4979 | <82> 23 | |||
|
4980 | ||||
|
4981 | The _ip object is also used in some examples in this document - it can | |||
|
4982 | be substituted by 'ip' in non-interactive use. | |||
|
4983 | ||||
|
4984 | Changing options | |||
|
4985 | ---------------- | |||
|
4986 | ||||
|
4987 | The ip object has 'options' attribute that can be used te get/set | |||
|
4988 | configuration options (just as in the ipythonrc file):: | |||
|
4989 | ||||
|
4990 | o = ip.options | |||
|
4991 | o.autocall = 2 | |||
|
4992 | o.automagic = 1 | |||
|
4993 | ||||
|
4994 | Executing statements in IPython namespace with 'ex' and 'ev' | |||
|
4995 | ------------------------------------------------------------ | |||
|
4996 | ||||
|
4997 | Often, you want to e.g. import some module or define something that | |||
|
4998 | should be visible in IPython namespace. Use ``ip.ev`` to | |||
|
4999 | *evaluate* (calculate the value of) expression and ``ip.ex`` to | |||
|
5000 | '''execute''' a statement:: | |||
|
5001 | ||||
|
5002 | # path module will be visible to the interactive session | |||
|
5003 | ip.ex("from path import path" ) | |||
|
5004 | ||||
|
5005 | # define a handy function 'up' that changes the working directory | |||
|
5006 | ||||
|
5007 | ip.ex('import os') | |||
|
5008 | ip.ex("def up(): os.chdir('..')") | |||
|
5009 | ||||
|
5010 | ||||
|
5011 | # _i2 has the input history entry #2, print its value in uppercase. | |||
|
5012 | print ip.ev('_i2.upper()') | |||
|
5013 | ||||
|
5014 | Accessing the IPython namespace | |||
|
5015 | ------------------------------- | |||
|
5016 | ||||
|
5017 | ip.user_ns attribute has a dictionary containing the IPython global | |||
|
5018 | namespace (the namespace visible in the interactive session). | |||
|
5019 | ||||
|
5020 | :: | |||
|
5021 | ||||
|
5022 | [~\_ipython]|84> tauno = 555 | |||
|
5023 | [~\_ipython]|85> _ip.user_ns['tauno'] | |||
|
5024 | <85> 555 | |||
|
5025 | ||||
|
5026 | Defining new magic commands | |||
|
5027 | --------------------------- | |||
|
5028 | ||||
|
5029 | The following example defines a new magic command, %impall. What the | |||
|
5030 | command does should be obvious:: | |||
|
5031 | ||||
|
5032 | def doimp(self, arg): | |||
|
5033 | ip = self.api | |||
|
5034 | ip.ex("import %s; reload(%s); from %s import *" % ( | |||
|
5035 | arg,arg,arg) | |||
|
5036 | ) | |||
|
5037 | ||||
|
5038 | ip.expose_magic('impall', doimp) | |||
|
5039 | ||||
|
5040 | Things to observe in this example: | |||
|
5041 | ||||
|
5042 | * Define a function that implements the magic command using the | |||
|
5043 | ipapi methods defined in this document | |||
|
5044 | * The first argument of the function is 'self', i.e. the | |||
|
5045 | interpreter object. It shouldn't be used directly. however. | |||
|
5046 | The interpreter object is probably *not* going to remain stable | |||
|
5047 | through IPython versions. | |||
|
5048 | * Access the ipapi through 'self.api' instead of the global 'ip' object. | |||
|
5049 | * All the text following the magic command on the command line is | |||
|
5050 | contained in the second argument | |||
|
5051 | * Expose the magic by ip.expose_magic() | |||
|
5052 | ||||
|
5053 | ||||
|
5054 | Calling magic functions and system commands | |||
|
5055 | ------------------------------------------- | |||
|
5056 | ||||
|
5057 | Use ip.magic() to execute a magic function, and ip.system() to execute | |||
|
5058 | a system command:: | |||
|
5059 | ||||
|
5060 | # go to a bookmark | |||
|
5061 | ip.magic('%cd -b relfiles') | |||
|
5062 | ||||
|
5063 | # execute 'ls -F' system command. Interchangeable with os.system('ls'), really. | |||
|
5064 | ip.system('ls -F') | |||
|
5065 | ||||
|
5066 | Launching IPython instance from normal python code | |||
|
5067 | -------------------------------------------------- | |||
|
5068 | ||||
|
5069 | Use ipapi.launch_new_instance() with an argument that specifies the | |||
|
5070 | namespace to use. This can be useful for trivially embedding IPython | |||
|
5071 | into your program. Here's an example of normal python program test.py | |||
|
5072 | ('''without''' an existing IPython session) that launches an IPython | |||
|
5073 | interpreter and regains control when the interpreter is exited:: | |||
|
5074 | ||||
|
5075 | [ipython]|1> cat test.py | |||
|
5076 | my_ns = dict( | |||
|
5077 | kissa = 15, | |||
|
5078 | koira = 16) | |||
|
5079 | import IPython.ipapi | |||
|
5080 | print "launching IPython instance" | |||
|
5081 | IPython.ipapi.launch_new_instance(my_ns) | |||
|
5082 | print "Exited IPython instance!" | |||
|
5083 | print "New vals:",my_ns['kissa'], my_ns['koira'] | |||
|
5084 | ||||
|
5085 | And here's what it looks like when run (note how we don't start it | |||
|
5086 | from an ipython session):: | |||
|
5087 | ||||
|
5088 | Q:\ipython>python test.py | |||
|
5089 | launching IPython instance | |||
|
5090 | Py 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] IPy 0.7.3b3.r1975 | |||
|
5091 | [ipython]|1> kissa = 444 | |||
|
5092 | [ipython]|2> koira = 555 | |||
|
5093 | [ipython]|3> Exit | |||
|
5094 | Exited IPython instance! | |||
|
5095 | New vals: 444 555 | |||
|
5096 | ||||
|
5097 | Accessing unexposed functionality | |||
|
5098 | --------------------------------- | |||
|
5099 | ||||
|
5100 | There are still many features that are not exposed via the ipapi. If | |||
|
5101 | you can't avoid using them, you can use the functionality in | |||
|
5102 | InteractiveShell object (central IPython session class, defined in | |||
|
5103 | iplib.py) through ip.IP. | |||
|
5104 | ||||
|
5105 | For example:: | |||
|
5106 | ||||
|
5107 | [~]|7> _ip.IP.expand_aliases('np','myfile.py') | |||
|
5108 | <7> 'c:/opt/Notepad++/notepad++.exe myfile.py' | |||
|
5109 | [~]|8> | |||
|
5110 | ||||
|
5111 | Still, it's preferable that if you encounter such a feature, contact | |||
|
5112 | the IPython team and request that the functionality be exposed in a | |||
|
5113 | future version of IPython. Things not in ipapi are more likely to | |||
|
5114 | change over time. | |||
|
5115 | ||||
4737 | Reporting bugs |
|
5116 | Reporting bugs | |
4738 | ============== |
|
5117 | ============== | |
4739 |
|
5118 | |||
4740 | Automatic crash reports |
|
5119 | Automatic crash reports | |
4741 | ----------------------- |
|
5120 | ----------------------- | |
4742 |
|
5121 | |||
4743 | Ideally, IPython itself shouldn't crash. It will catch exceptions |
|
5122 | Ideally, IPython itself shouldn't crash. It will catch exceptions | |
4744 | produced by you, but bugs in its internals will still crash it. |
|
5123 | produced by you, but bugs in its internals will still crash it. | |
4745 |
|
5124 | |||
4746 | In such a situation, IPython will leave a file named |
|
5125 | In such a situation, IPython will leave a file named | |
4747 | IPython_crash_report.txt in your IPYTHONDIR directory (that way if |
|
5126 | IPython_crash_report.txt in your IPYTHONDIR directory (that way if | |
4748 | crashes happen several times it won't litter many directories, the |
|
5127 | crashes happen several times it won't litter many directories, the | |
4749 | post-mortem file is always located in the same place and new occurrences |
|
5128 | post-mortem file is always located in the same place and new occurrences | |
4750 | just overwrite the previous one). If you can mail this file to the |
|
5129 | just overwrite the previous one). If you can mail this file to the | |
4751 | developers (see sec. 20 <node20.html#sec:credits> for names and |
|
5130 | developers (see sec. 20 <node20.html#sec:credits> for names and | |
4752 | addresses), it will help us a lot in understanding the cause of the |
|
5131 | addresses), it will help us a lot in understanding the cause of the | |
4753 | problem and fixing it sooner. |
|
5132 | problem and fixing it sooner. | |
4754 |
|
5133 | |||
4755 |
|
5134 | |||
4756 | The bug tracker |
|
5135 | The bug tracker | |
4757 | --------------- |
|
5136 | --------------- | |
4758 |
|
5137 | |||
4759 | IPython also has an online bug-tracker, located at |
|
5138 | IPython also has an online bug-tracker, located at | |
4760 | http://projects.scipy.org/ipython/ipython/report/1. In addition to |
|
5139 | http://projects.scipy.org/ipython/ipython/report/1. In addition to | |
4761 | mailing the developers, it would be a good idea to file a bug report |
|
5140 | mailing the developers, it would be a good idea to file a bug report | |
4762 | here. This will ensure that the issue is properly followed to |
|
5141 | here. This will ensure that the issue is properly followed to | |
4763 | conclusion. To report new bugs you will have to register first. |
|
5142 | conclusion. To report new bugs you will have to register first. | |
4764 |
|
5143 | |||
4765 | You can also use this bug tracker to file feature requests. |
|
5144 | You can also use this bug tracker to file feature requests. | |
4766 |
|
5145 | |||
4767 | Brief history |
|
5146 | Brief history | |
4768 | ============= |
|
5147 | ============= | |
4769 |
|
5148 | |||
4770 |
|
5149 | |||
4771 | Origins |
|
5150 | Origins | |
|
5151 | ------- | |||
4772 |
|
5152 | |||
4773 | The current IPython system grew out of the following three projects: |
|
5153 | The current IPython system grew out of the following three projects: | |
4774 |
|
5154 | |||
4775 | * [ipython] by Fernando Pérez. I was working on adding |
|
5155 | * [ipython] by Fernando Pérez. I was working on adding | |
4776 | Mathematica-type prompts and a flexible configuration system |
|
5156 | Mathematica-type prompts and a flexible configuration system | |
4777 | (something better than $PYTHONSTARTUP) to the standard Python |
|
5157 | (something better than $PYTHONSTARTUP) to the standard Python | |
4778 | interactive interpreter. |
|
5158 | interactive interpreter. | |
4779 | * [IPP] by Janko Hauser. Very well organized, great usability. Had |
|
5159 | * [IPP] by Janko Hauser. Very well organized, great usability. Had | |
4780 | an old help system. IPP was used as the 'container' code into |
|
5160 | an old help system. IPP was used as the 'container' code into | |
4781 | which I added the functionality from ipython and LazyPython. |
|
5161 | which I added the functionality from ipython and LazyPython. | |
4782 | * [LazyPython] by Nathan Gray. Simple but very powerful. The quick |
|
5162 | * [LazyPython] by Nathan Gray. Simple but very powerful. The quick | |
4783 | syntax (auto parens, auto quotes) and verbose/colored tracebacks |
|
5163 | syntax (auto parens, auto quotes) and verbose/colored tracebacks | |
4784 | were all taken from here. |
|
5164 | were all taken from here. | |
4785 |
|
5165 | |||
4786 | When I found out (see sec. 20 <node20.html#figgins>) about IPP and |
|
5166 | When I found out (see sec. 20 <node20.html#figgins>) about IPP and | |
4787 | LazyPython I tried to join all three into a unified system. I thought |
|
5167 | LazyPython I tried to join all three into a unified system. I thought | |
4788 | this could provide a very nice working environment, both for regular |
|
5168 | this could provide a very nice working environment, both for regular | |
4789 | programming and scientific computing: shell-like features, IDL/Matlab |
|
5169 | programming and scientific computing: shell-like features, IDL/Matlab | |
4790 | numerics, Mathematica-type prompt history and great object introspection |
|
5170 | numerics, Mathematica-type prompt history and great object introspection | |
4791 | and help facilities. I think it worked reasonably well, though it was a |
|
5171 | and help facilities. I think it worked reasonably well, though it was a | |
4792 | lot more work than I had initially planned. |
|
5172 | lot more work than I had initially planned. | |
4793 |
|
5173 | |||
4794 |
|
5174 | |||
4795 | Current status |
|
5175 | Current status | |
4796 | -------------- |
|
5176 | -------------- | |
4797 |
|
5177 | |||
4798 | The above listed features work, and quite well for the most part. But |
|
5178 | The above listed features work, and quite well for the most part. But | |
4799 | until a major internal restructuring is done (see below), only bug |
|
5179 | until a major internal restructuring is done (see below), only bug | |
4800 | fixing will be done, no other features will be added (unless very minor |
|
5180 | fixing will be done, no other features will be added (unless very minor | |
4801 | and well localized in the cleaner parts of the code). |
|
5181 | and well localized in the cleaner parts of the code). | |
4802 |
|
5182 | |||
4803 | IPython consists of some 18000 lines of pure python code, of which |
|
5183 | IPython consists of some 18000 lines of pure python code, of which | |
4804 | roughly two thirds is reasonably clean. The rest is, messy code which |
|
5184 | roughly two thirds is reasonably clean. The rest is, messy code which | |
4805 | needs a massive restructuring before any further major work is done. |
|
5185 | needs a massive restructuring before any further major work is done. | |
4806 | Even the messy code is fairly well documented though, and most of the |
|
5186 | Even the messy code is fairly well documented though, and most of the | |
4807 | problems in the (non-existent) class design are well pointed to by a |
|
5187 | problems in the (non-existent) class design are well pointed to by a | |
4808 | PyChecker run. So the rewriting work isn't that bad, it will just be |
|
5188 | PyChecker run. So the rewriting work isn't that bad, it will just be | |
4809 | time-consuming. |
|
5189 | time-consuming. | |
4810 |
|
5190 | |||
4811 |
|
5191 | |||
4812 | Future |
|
5192 | Future | |
4813 | ------ |
|
5193 | ------ | |
4814 |
|
5194 | |||
4815 | See the separate new_design document for details. Ultimately, I would |
|
5195 | See the separate new_design document for details. Ultimately, I would | |
4816 | like to see IPython become part of the standard Python distribution as a |
|
5196 | like to see IPython become part of the standard Python distribution as a | |
4817 | 'big brother with batteries' to the standard Python interactive |
|
5197 | 'big brother with batteries' to the standard Python interactive | |
4818 | interpreter. But that will never happen with the current state of the |
|
5198 | interpreter. But that will never happen with the current state of the | |
4819 | code, so all contributions are welcome. |
|
5199 | code, so all contributions are welcome. | |
4820 |
|
5200 | |||
4821 | License |
|
5201 | License | |
4822 | ======= |
|
5202 | ======= | |
4823 |
|
5203 | |||
4824 | IPython is released under the terms of the BSD license, whose general |
|
5204 | IPython is released under the terms of the BSD license, whose general | |
4825 | form can be found at: |
|
5205 | form can be found at: | |
4826 | http://www.opensource.org/licenses/bsd-license.php. The full text of the |
|
5206 | http://www.opensource.org/licenses/bsd-license.php. The full text of the | |
4827 | IPython license is reproduced below:: |
|
5207 | IPython license is reproduced below:: | |
4828 |
|
5208 | |||
4829 | IPython is released under a BSD-type license. |
|
5209 | IPython is released under a BSD-type license. | |
4830 |
|
5210 | |||
4831 | Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez |
|
5211 | Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez | |
4832 | <fperez@colorado.edu>. |
|
5212 | <fperez@colorado.edu>. | |
4833 |
|
5213 | |||
4834 | Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and |
|
5214 | Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and | |
4835 | Nathaniel Gray <n8gray@caltech.edu>. |
|
5215 | Nathaniel Gray <n8gray@caltech.edu>. | |
4836 |
|
5216 | |||
4837 | All rights reserved. |
|
5217 | All rights reserved. | |
4838 |
|
5218 | |||
4839 | Redistribution and use in source and binary forms, with or without |
|
5219 | Redistribution and use in source and binary forms, with or without | |
4840 | modification, are permitted provided that the following conditions |
|
5220 | modification, are permitted provided that the following conditions | |
4841 | are met: |
|
5221 | are met: | |
4842 |
|
5222 | |||
4843 | a. Redistributions of source code must retain the above copyright |
|
5223 | a. Redistributions of source code must retain the above copyright | |
4844 | notice, this list of conditions and the following disclaimer. |
|
5224 | notice, this list of conditions and the following disclaimer. | |
4845 |
|
5225 | |||
4846 | b. Redistributions in binary form must reproduce the above copyright |
|
5226 | b. Redistributions in binary form must reproduce the above copyright | |
4847 | notice, this list of conditions and the following disclaimer in the |
|
5227 | notice, this list of conditions and the following disclaimer in the | |
4848 | documentation and/or other materials provided with the distribution. |
|
5228 | documentation and/or other materials provided with the distribution. | |
4849 |
|
5229 | |||
4850 | c. Neither the name of the copyright holders nor the names of any |
|
5230 | c. Neither the name of the copyright holders nor the names of any | |
4851 | contributors to this software may be used to endorse or promote |
|
5231 | contributors to this software may be used to endorse or promote | |
4852 | products derived from this software without specific prior written |
|
5232 | products derived from this software without specific prior written | |
4853 | permission. |
|
5233 | permission. | |
4854 |
|
5234 | |||
4855 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5235 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
4856 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5236 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
4857 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
5237 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
4858 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
5238 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
4859 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
5239 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
4860 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
5240 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
4861 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
5241 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
4862 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
5242 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
4863 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
5243 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
4864 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
5244 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
4865 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
5245 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
4866 | POSSIBILITY OF SUCH DAMAGE. |
|
5246 | POSSIBILITY OF SUCH DAMAGE. | |
4867 |
|
5247 | |||
4868 | Individual authors are the holders of the copyright for their code and |
|
5248 | Individual authors are the holders of the copyright for their code and | |
4869 | are listed in each file. |
|
5249 | are listed in each file. | |
4870 |
|
5250 | |||
4871 | Some files (DPyGetOpt.py, for example) may be licensed under different |
|
5251 | Some files (DPyGetOpt.py, for example) may be licensed under different | |
4872 | conditions. Ultimately each file indicates clearly the conditions under |
|
5252 | conditions. Ultimately each file indicates clearly the conditions under | |
4873 | which its author/authors have decided to publish the code. |
|
5253 | which its author/authors have decided to publish the code. | |
4874 |
|
5254 | |||
4875 | Versions of IPython up to and including 0.6.3 were released under the |
|
5255 | Versions of IPython up to and including 0.6.3 were released under the | |
4876 | GNU Lesser General Public License (LGPL), available at |
|
5256 | GNU Lesser General Public License (LGPL), available at | |
4877 | http://www.gnu.org/copyleft/lesser.html. |
|
5257 | http://www.gnu.org/copyleft/lesser.html. | |
4878 |
|
5258 | |||
4879 | Credits |
|
5259 | Credits | |
4880 | ======= |
|
5260 | ======= | |
4881 |
|
5261 | |||
4882 | IPython is mainly developed by Fernando Pérez |
|
5262 | IPython is mainly developed by Fernando Pérez | |
4883 | <Fernando.Perez@colorado.edu>, but the project was born from mixing in |
|
5263 | <Fernando.Perez@colorado.edu>, but the project was born from mixing in | |
4884 | Fernando's code with the IPP project by Janko Hauser |
|
5264 | Fernando's code with the IPP project by Janko Hauser | |
4885 | <jhauser-AT-zscout.de> and LazyPython by Nathan Gray |
|
5265 | <jhauser-AT-zscout.de> and LazyPython by Nathan Gray | |
4886 | <n8gray-AT-caltech.edu>. For all IPython-related requests, please |
|
5266 | <n8gray-AT-caltech.edu>. For all IPython-related requests, please | |
4887 | contact Fernando. |
|
5267 | contact Fernando. | |
4888 |
|
5268 | |||
4889 | As of early 2006, the following developers have joined the core team: |
|
5269 | As of early 2006, the following developers have joined the core team: | |
4890 |
|
5270 | |||
4891 | * [Robert Kern] <rkern-AT-enthought.com>: co-mentored the 2005 |
|
5271 | * [Robert Kern] <rkern-AT-enthought.com>: co-mentored the 2005 | |
4892 | Google Summer of Code project to develop python interactive |
|
5272 | Google Summer of Code project to develop python interactive | |
4893 | notebooks (XML documents) and graphical interface. This project |
|
5273 | notebooks (XML documents) and graphical interface. This project | |
4894 | was awarded to the students Tzanko Matev <tsanko-AT-gmail.com> and |
|
5274 | was awarded to the students Tzanko Matev <tsanko-AT-gmail.com> and | |
4895 | Toni Alatalo <antont-AT-an.org> |
|
5275 | Toni Alatalo <antont-AT-an.org> | |
4896 | * [Brian Granger] <bgranger-AT-scu.edu>: extending IPython to allow |
|
5276 | * [Brian Granger] <bgranger-AT-scu.edu>: extending IPython to allow | |
4897 | support for interactive parallel computing. |
|
5277 | support for interactive parallel computing. | |
4898 | * [Ville Vainio] <vivainio-AT-gmail.com>: Ville is the new |
|
5278 | * [Ville Vainio] <vivainio-AT-gmail.com>: Ville is the new | |
4899 | maintainer for the main trunk of IPython after version 0.7.1. |
|
5279 | maintainer for the main trunk of IPython after version 0.7.1. | |
4900 |
|
5280 | |||
4901 | User or development help should be requested via the IPython mailing lists: |
|
5281 | User or development help should be requested via the IPython mailing lists: | |
4902 |
|
5282 | |||
4903 | *User list:* |
|
5283 | *User list:* | |
4904 | http://scipy.net/mailman/listinfo/ipython-user |
|
5284 | http://scipy.net/mailman/listinfo/ipython-user | |
4905 | *Developer's list:* |
|
5285 | *Developer's list:* | |
4906 | http://scipy.net/mailman/listinfo/ipython-dev |
|
5286 | http://scipy.net/mailman/listinfo/ipython-dev | |
4907 |
|
5287 | |||
4908 | The IPython project is also very grateful to^7 <footnode.html#foot2913>: |
|
5288 | The IPython project is also very grateful to^7 <footnode.html#foot2913>: | |
4909 |
|
5289 | |||
4910 | Bill Bumgarner <bbum-AT-friday.com>: for providing the DPyGetOpt module |
|
5290 | Bill Bumgarner <bbum-AT-friday.com>: for providing the DPyGetOpt module | |
4911 | which gives very powerful and convenient handling of command-line |
|
5291 | which gives very powerful and convenient handling of command-line | |
4912 | options (light years ahead of what Python 2.1.1's getopt module does). |
|
5292 | options (light years ahead of what Python 2.1.1's getopt module does). | |
4913 |
|
5293 | |||
4914 | Ka-Ping Yee <ping-AT-lfw.org>: for providing the Itpl module for |
|
5294 | Ka-Ping Yee <ping-AT-lfw.org>: for providing the Itpl module for | |
4915 | convenient and powerful string interpolation with a much nicer syntax |
|
5295 | convenient and powerful string interpolation with a much nicer syntax | |
4916 | than formatting through the '%' operator. |
|
5296 | than formatting through the '%' operator. | |
4917 |
|
5297 | |||
4918 | Arnd Baecker <baecker-AT-physik.tu-dresden.de>: for his many very useful |
|
5298 | Arnd Baecker <baecker-AT-physik.tu-dresden.de>: for his many very useful | |
4919 | suggestions and comments, and lots of help with testing and |
|
5299 | suggestions and comments, and lots of help with testing and | |
4920 | documentation checking. Many of IPython's newer features are a result of |
|
5300 | documentation checking. Many of IPython's newer features are a result of | |
4921 | discussions with him (bugs are still my fault, not his). |
|
5301 | discussions with him (bugs are still my fault, not his). | |
4922 |
|
5302 | |||
4923 | Obviously Guido van Rossum and the whole Python development team, that |
|
5303 | Obviously Guido van Rossum and the whole Python development team, that | |
4924 | goes without saying. |
|
5304 | goes without saying. | |
4925 |
|
5305 | |||
4926 | IPython's website is generously hosted at http://ipython.scipy.orgby |
|
5306 | IPython's website is generously hosted at http://ipython.scipy.orgby | |
4927 | Enthought (http://www.enthought.com). I am very grateful to them and all |
|
5307 | Enthought (http://www.enthought.com). I am very grateful to them and all | |
4928 | of the SciPy team for their contribution. |
|
5308 | of the SciPy team for their contribution. | |
4929 |
|
5309 | |||
4930 | Fernando would also like to thank Stephen Figgins <fig-AT-monitor.net>, |
|
5310 | Fernando would also like to thank Stephen Figgins <fig-AT-monitor.net>, | |
4931 | an O'Reilly Python editor. His Oct/11/2001 article about IPP and |
|
5311 | an O'Reilly Python editor. His Oct/11/2001 article about IPP and | |
4932 | LazyPython, was what got this project started. You can read it at: |
|
5312 | LazyPython, was what got this project started. You can read it at: | |
4933 | http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html. |
|
5313 | http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html. | |
4934 |
|
5314 | |||
4935 | And last but not least, all the kind IPython users who have emailed new |
|
5315 | And last but not least, all the kind IPython users who have emailed new | |
4936 | code, bug reports, fixes, comments and ideas. A brief list follows, |
|
5316 | code, bug reports, fixes, comments and ideas. A brief list follows, | |
4937 | please let me know if I have ommitted your name by accident: |
|
5317 | please let me know if I have ommitted your name by accident: | |
4938 |
|
5318 | |||
4939 | * [Jack Moffit] <jack-AT-xiph.org> Bug fixes, including the infamous |
|
5319 | * [Jack Moffit] <jack-AT-xiph.org> Bug fixes, including the infamous | |
4940 | color problem. This bug alone caused many lost hours and |
|
5320 | color problem. This bug alone caused many lost hours and | |
4941 | frustration, many thanks to him for the fix. I've always been a |
|
5321 | frustration, many thanks to him for the fix. I've always been a | |
4942 | fan of Ogg & friends, now I have one more reason to like these folks. |
|
5322 | fan of Ogg & friends, now I have one more reason to like these folks. | |
4943 | Jack is also contributing with Debian packaging and many other |
|
5323 | Jack is also contributing with Debian packaging and many other | |
4944 | things. |
|
5324 | things. | |
4945 | * [Alexander Schmolck] <a.schmolck-AT-gmx.net> Emacs work, bug |
|
5325 | * [Alexander Schmolck] <a.schmolck-AT-gmx.net> Emacs work, bug | |
4946 | reports, bug fixes, ideas, lots more. The ipython.el mode for |
|
5326 | reports, bug fixes, ideas, lots more. The ipython.el mode for | |
4947 | (X)Emacs is Alex's code, providing full support for IPython under |
|
5327 | (X)Emacs is Alex's code, providing full support for IPython under | |
4948 | (X)Emacs. |
|
5328 | (X)Emacs. | |
4949 | * [Andrea Riciputi] <andrea.riciputi-AT-libero.it> Mac OSX |
|
5329 | * [Andrea Riciputi] <andrea.riciputi-AT-libero.it> Mac OSX | |
4950 | information, Fink package management. |
|
5330 | information, Fink package management. | |
4951 | * [Gary Bishop] <gb-AT-cs.unc.edu> Bug reports, and patches to work |
|
5331 | * [Gary Bishop] <gb-AT-cs.unc.edu> Bug reports, and patches to work | |
4952 | around the exception handling idiosyncracies of WxPython. Readline |
|
5332 | around the exception handling idiosyncracies of WxPython. Readline | |
4953 | and color support for Windows. |
|
5333 | and color support for Windows. | |
4954 | * [Jeffrey Collins] <Jeff.Collins-AT-vexcel.com> Bug reports. Much |
|
5334 | * [Jeffrey Collins] <Jeff.Collins-AT-vexcel.com> Bug reports. Much | |
4955 | improved readline support, including fixes for Python 2.3. |
|
5335 | improved readline support, including fixes for Python 2.3. | |
4956 | * [Dryice Liu] <dryice-AT-liu.com.cn> FreeBSD port. |
|
5336 | * [Dryice Liu] <dryice-AT-liu.com.cn> FreeBSD port. | |
4957 | * [Mike Heeter] <korora-AT-SDF.LONESTAR.ORG> |
|
5337 | * [Mike Heeter] <korora-AT-SDF.LONESTAR.ORG> | |
4958 | * [Christopher Hart] <hart-AT-caltech.edu> PDB integration. |
|
5338 | * [Christopher Hart] <hart-AT-caltech.edu> PDB integration. | |
4959 | * [Milan Zamazal] <pdm-AT-zamazal.org> Emacs info. |
|
5339 | * [Milan Zamazal] <pdm-AT-zamazal.org> Emacs info. | |
4960 | * [Philip Hisley] <compsys-AT-starpower.net> |
|
5340 | * [Philip Hisley] <compsys-AT-starpower.net> | |
4961 | * [Holger Krekel] <pyth-AT-devel.trillke.net> Tab completion, lots |
|
5341 | * [Holger Krekel] <pyth-AT-devel.trillke.net> Tab completion, lots | |
4962 | more. |
|
5342 | more. | |
4963 | * [Robin Siebler] <robinsiebler-AT-starband.net> |
|
5343 | * [Robin Siebler] <robinsiebler-AT-starband.net> | |
4964 | * [Ralf Ahlbrink] <ralf_ahlbrink-AT-web.de> |
|
5344 | * [Ralf Ahlbrink] <ralf_ahlbrink-AT-web.de> | |
4965 | * [Thorsten Kampe] <thorsten-AT-thorstenkampe.de> |
|
5345 | * [Thorsten Kampe] <thorsten-AT-thorstenkampe.de> | |
4966 | * [Fredrik Kant] <fredrik.kant-AT-front.com> Windows setup. |
|
5346 | * [Fredrik Kant] <fredrik.kant-AT-front.com> Windows setup. | |
4967 | * [Syver Enstad] <syver-en-AT-online.no> Windows setup. |
|
5347 | * [Syver Enstad] <syver-en-AT-online.no> Windows setup. | |
4968 | * [Richard] <rxe-AT-renre-europe.com> Global embedding. |
|
5348 | * [Richard] <rxe-AT-renre-europe.com> Global embedding. | |
4969 | * [Hayden Callow] <h.callow-AT-elec.canterbury.ac.nz> Gnuplot.py 1.6 |
|
5349 | * [Hayden Callow] <h.callow-AT-elec.canterbury.ac.nz> Gnuplot.py 1.6 | |
4970 | compatibility. |
|
5350 | compatibility. | |
4971 | * [Leonardo Santagada] <retype-AT-terra.com.br> Fixes for Windows |
|
5351 | * [Leonardo Santagada] <retype-AT-terra.com.br> Fixes for Windows | |
4972 | installation. |
|
5352 | installation. | |
4973 | * [Christopher Armstrong] <radix-AT-twistedmatrix.com> Bugfixes. |
|
5353 | * [Christopher Armstrong] <radix-AT-twistedmatrix.com> Bugfixes. | |
4974 | * [Francois Pinard] <pinard-AT-iro.umontreal.ca> Code and |
|
5354 | * [Francois Pinard] <pinard-AT-iro.umontreal.ca> Code and | |
4975 | documentation fixes. |
|
5355 | documentation fixes. | |
4976 | * [Cory Dodt] <cdodt-AT-fcoe.k12.ca.us> Bug reports and Windows |
|
5356 | * [Cory Dodt] <cdodt-AT-fcoe.k12.ca.us> Bug reports and Windows | |
4977 | ideas. Patches for Windows installer. |
|
5357 | ideas. Patches for Windows installer. | |
4978 | * [Olivier Aubert] <oaubert-AT-bat710.univ-lyon1.fr> New magics. |
|
5358 | * [Olivier Aubert] <oaubert-AT-bat710.univ-lyon1.fr> New magics. | |
4979 | * [King C. Shu] <kingshu-AT-myrealbox.com> Autoindent patch. |
|
5359 | * [King C. Shu] <kingshu-AT-myrealbox.com> Autoindent patch. | |
4980 | * [Chris Drexler] <chris-AT-ac-drexler.de> Readline packages for |
|
5360 | * [Chris Drexler] <chris-AT-ac-drexler.de> Readline packages for | |
4981 | Win32/CygWin. |
|
5361 | Win32/CygWin. | |
4982 | * [Gustavo Cordova Avila] <gcordova-AT-sismex.com> EvalDict code for |
|
5362 | * [Gustavo Cordova Avila] <gcordova-AT-sismex.com> EvalDict code for | |
4983 | nice, lightweight string interpolation. |
|
5363 | nice, lightweight string interpolation. | |
4984 | * [Kasper Souren] <Kasper.Souren-AT-ircam.fr> Bug reports, ideas. |
|
5364 | * [Kasper Souren] <Kasper.Souren-AT-ircam.fr> Bug reports, ideas. | |
4985 | * [Gever Tulley] <gever-AT-helium.com> Code contributions. |
|
5365 | * [Gever Tulley] <gever-AT-helium.com> Code contributions. | |
4986 | * [Ralf Schmitt] <ralf-AT-brainbot.com> Bug reports & fixes. |
|
5366 | * [Ralf Schmitt] <ralf-AT-brainbot.com> Bug reports & fixes. | |
4987 | * [Oliver Sander] <osander-AT-gmx.de> Bug reports. |
|
5367 | * [Oliver Sander] <osander-AT-gmx.de> Bug reports. | |
4988 | * [Rod Holland] <rhh-AT-structurelabs.com> Bug reports and fixes to |
|
5368 | * [Rod Holland] <rhh-AT-structurelabs.com> Bug reports and fixes to | |
4989 | logging module. |
|
5369 | logging module. | |
4990 | * [Daniel 'Dang' Griffith] <pythondev-dang-AT-lazytwinacres.net> |
|
5370 | * [Daniel 'Dang' Griffith] <pythondev-dang-AT-lazytwinacres.net> | |
4991 | Fixes, enhancement suggestions for system shell use. |
|
5371 | Fixes, enhancement suggestions for system shell use. | |
4992 | * [Viktor Ransmayr] <viktor.ransmayr-AT-t-online.de> Tests and |
|
5372 | * [Viktor Ransmayr] <viktor.ransmayr-AT-t-online.de> Tests and | |
4993 | reports on Windows installation issues. Contributed a true Windows |
|
5373 | reports on Windows installation issues. Contributed a true Windows | |
4994 | binary installer. |
|
5374 | binary installer. | |
4995 | * [Mike Salib] <msalib-AT-mit.edu> Help fixing a subtle bug related |
|
5375 | * [Mike Salib] <msalib-AT-mit.edu> Help fixing a subtle bug related | |
4996 | to traceback printing. |
|
5376 | to traceback printing. | |
4997 | * [W.J. van der Laan] <gnufnork-AT-hetdigitalegat.nl> Bash-like |
|
5377 | * [W.J. van der Laan] <gnufnork-AT-hetdigitalegat.nl> Bash-like | |
4998 | prompt specials. |
|
5378 | prompt specials. | |
4999 | * [Antoon Pardon] <Antoon.Pardon-AT-rece.vub.ac.be> Critical fix for |
|
5379 | * [Antoon Pardon] <Antoon.Pardon-AT-rece.vub.ac.be> Critical fix for | |
5000 | the multithreaded IPython. |
|
5380 | the multithreaded IPython. | |
5001 | * [John Hunter] <jdhunter-AT-nitace.bsd.uchicago.edu> Matplotlib |
|
5381 | * [John Hunter] <jdhunter-AT-nitace.bsd.uchicago.edu> Matplotlib | |
5002 | author, helped with all the development of support for matplotlib |
|
5382 | author, helped with all the development of support for matplotlib | |
5003 | in IPyhton, including making necessary changes to matplotlib itself. |
|
5383 | in IPyhton, including making necessary changes to matplotlib itself. | |
5004 | * [Matthew Arnison] <maffew-AT-cat.org.au> Bug reports, '%run -d' idea. |
|
5384 | * [Matthew Arnison] <maffew-AT-cat.org.au> Bug reports, '%run -d' idea. | |
5005 | * [Prabhu Ramachandran] <prabhu_r-AT-users.sourceforge.net> Help |
|
5385 | * [Prabhu Ramachandran] <prabhu_r-AT-users.sourceforge.net> Help | |
5006 | with (X)Emacs support, threading patches, ideas... |
|
5386 | with (X)Emacs support, threading patches, ideas... | |
5007 | * [Norbert Tretkowski] <tretkowski-AT-inittab.de> help with Debian |
|
5387 | * [Norbert Tretkowski] <tretkowski-AT-inittab.de> help with Debian | |
5008 | packaging and distribution. |
|
5388 | packaging and distribution. | |
5009 | * [George Sakkis] <gsakkis-AT-eden.rutgers.edu> New matcher for |
|
5389 | * [George Sakkis] <gsakkis-AT-eden.rutgers.edu> New matcher for | |
5010 | tab-completing named arguments of user-defined functions. |
|
5390 | tab-completing named arguments of user-defined functions. | |
5011 | * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu> Wildcard |
|
5391 | * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu> Wildcard | |
5012 | support implementation for searching namespaces. |
|
5392 | support implementation for searching namespaces. | |
5013 | * [Vivian De Smedt] <vivian-AT-vdesmedt.com> Debugger enhancements, |
|
5393 | * [Vivian De Smedt] <vivian-AT-vdesmedt.com> Debugger enhancements, | |
5014 | so that when pdb is activated from within IPython, coloring, tab |
|
5394 | so that when pdb is activated from within IPython, coloring, tab | |
5015 | completion and other features continue to work seamlessly. |
|
5395 | completion and other features continue to work seamlessly. | |
5016 | * [Scott Tsai] <scottt958-AT-yahoo.com.tw> Support for automatic |
|
5396 | * [Scott Tsai] <scottt958-AT-yahoo.com.tw> Support for automatic | |
5017 | editor invocation on syntax errors (see |
|
5397 | editor invocation on syntax errors (see | |
5018 | http://www.scipy.net/roundup/ipython/issue36). |
|
5398 | http://www.scipy.net/roundup/ipython/issue36). | |
5019 | * [Alexander Belchenko] <bialix-AT-ukr.net> Improvements for win32 |
|
5399 | * [Alexander Belchenko] <bialix-AT-ukr.net> Improvements for win32 | |
5020 | paging system. |
|
5400 | paging system. | |
5021 | * [Will Maier] <willmaier-AT-ml1.net> Official OpenBSD port. |
|
5401 | * [Will Maier] <willmaier-AT-ml1.net> Official OpenBSD port. | |
5022 |
|
5402 |
General Comments 0
You need to be logged in to leave comments.
Login now