##// END OF EJS Templates
Merged Ville files
ldufrechou -
r1131:51ac6e12 merge
parent child Browse files
Show More
@@ -0,0 +1,4 b''
1 import os
2 def oscmd(c):
3 os.system(c)
4 oscmd('sphinx-build -d build/doctrees source build/html') No newline at end of file
@@ -0,0 +1,132 b''
1 # -*- coding: utf-8 -*-
2 #
3 # IPython documentation build configuration file, created by
4 # sphinx-quickstart.py on Sat Mar 29 15:36:13 2008.
5 #
6 # This file is execfile()d with the current directory set to its containing dir.
7 #
8 # The contents of this file are pickled, so don't put values in the namespace
9 # that aren't pickleable (module imports are okay, they're removed automatically).
10 #
11 # All configuration values have a default value; values that are commented out
12 # serve to show the default value.
13
14 import sys
15
16 # If your extensions are in another directory, add it here.
17 #sys.path.append('some/directory')
18
19 # General configuration
20 # ---------------------
21
22 # Add any Sphinx extension module names here, as strings. They can be extensions
23 # coming with Sphinx (named 'sphinx.addons.*') or your custom ones.
24 #extensions = []
25
26 # Add any paths that contain templates here, relative to this directory.
27 templates_path = ['_templates']
28
29 # The suffix of source filenames.
30 source_suffix = '.rst'
31
32 # The master toctree document.
33 master_doc = 'ipython'
34
35 # General substitutions.
36 project = 'IPython'
37 copyright = '2008, IPython team'
38
39 # The default replacements for |version| and |release|, also used in various
40 # other places throughout the built documents.
41 #
42 # The short X.Y version.
43 version = '0.8.3'
44 # The full version, including alpha/beta/rc tags.
45 release = '0.8.3'
46
47 # There are two options for replacing |today|: either, you set today to some
48 # non-false value, then it is used:
49 #today = ''
50 # Else, today_fmt is used as the format for a strftime call.
51 today_fmt = '%B %d, %Y'
52
53 # List of documents that shouldn't be included in the build.
54 #unused_docs = []
55
56 # If true, '()' will be appended to :func: etc. cross-reference text.
57 #add_function_parentheses = True
58
59 # If true, the current module name will be prepended to all description
60 # unit titles (such as .. function::).
61 #add_module_names = True
62
63 # If true, sectionauthor and moduleauthor directives will be shown in the
64 # output. They are ignored by default.
65 #show_authors = False
66
67 # The name of the Pygments (syntax highlighting) style to use.
68 pygments_style = 'sphinx'
69
70
71 # Options for HTML output
72 # -----------------------
73
74 # The style sheet to use for HTML and HTML Help pages. A file of that name
75 # must exist either in Sphinx' static/ path, or in one of the custom paths
76 # given in html_static_path.
77 html_style = 'default.css'
78
79 # Add any paths that contain custom static files (such as style sheets) here,
80 # relative to this directory. They are copied after the builtin static files,
81 # so a file named "default.css" will overwrite the builtin "default.css".
82 html_static_path = ['_static']
83
84 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
85 # using the given strftime format.
86 html_last_updated_fmt = '%b %d, %Y'
87
88 # If true, SmartyPants will be used to convert quotes and dashes to
89 # typographically correct entities.
90 #html_use_smartypants = True
91
92 # Content template for the index page.
93 #html_index = ''
94
95 # Custom sidebar templates, maps document names to template names.
96 #html_sidebars = {}
97
98 # Additional templates that should be rendered to pages, maps page names to
99 # template names.
100 #html_additional_pages = {}
101
102 # If false, no module index is generated.
103 #html_use_modindex = True
104
105 # If true, the reST sources are included in the HTML build as _sources/<name>.
106 #html_copy_source = True
107
108 # Output file base name for HTML help builder.
109 htmlhelp_basename = 'IPythondoc'
110
111
112 # Options for LaTeX output
113 # ------------------------
114
115 # The paper size ('letter' or 'a4').
116 #latex_paper_size = 'letter'
117
118 # The font size ('10pt', '11pt' or '12pt').
119 #latex_font_size = '10pt'
120
121 # Grouping the document tree into LaTeX files. List of tuples
122 # (source start file, target name, title, author, document class [howto/manual]).
123 #latex_documents = []
124
125 # Additional stuff for the LaTeX preamble.
126 #latex_preamble = ''
127
128 # Documents to append as an appendix to all manuals.
129 #latex_appendices = []
130
131 # If false, no module index is generated.
132 #latex_use_modindex = True
@@ -374,7 +374,6 b' def push_ipython_script(node):'
374 hstart = len(ip.IP.input_hist)
374 hstart = len(ip.IP.input_hist)
375 script = node.script()
375 script = node.script()
376
376
377 script = g.splitLines(script + '\n')
378 ip.user_ns['_p'] = node
377 ip.user_ns['_p'] = node
379 ip.runlines(script)
378 ip.runlines(script)
380 ip.user_ns.pop('_p',None)
379 ip.user_ns.pop('_p',None)
@@ -273,6 +273,7 b' class IPApi:'
273 """
273 """
274 res = []
274 res = []
275 lines = script.splitlines()
275 lines = script.splitlines()
276
276 level = 0
277 level = 0
277 for l in lines:
278 for l in lines:
278 lstripped = l.lstrip()
279 lstripped = l.lstrip()
@@ -280,9 +281,19 b' class IPApi:'
280 if not stripped:
281 if not stripped:
281 continue
282 continue
282 newlevel = len(l) - len(lstripped)
283 newlevel = len(l) - len(lstripped)
283 if level > 0 and newlevel == 0 and not stripped.endswith(':'):
284 def is_secondary_block_start(s):
285 if not s.endswith(':'):
286 return False
287 if (s.startswith('elif') or
288 s.startswith('else') or
289 s.startswith('except') or
290 s.startswith('finally')):
291 return True
292
293 if level > 0 and newlevel == 0 and not is_secondary_block_start(stripped):
284 # add empty line
294 # add empty line
285 res.append('')
295 res.append('')
296
286 res.append(l)
297 res.append(l)
287 level = newlevel
298 level = newlevel
288 return '\n'.join(res) + '\n'
299 return '\n'.join(res) + '\n'
@@ -292,7 +303,7 b' class IPApi:'
292 else:
303 else:
293 script = '\n'.join(lines)
304 script = '\n'.join(lines)
294 clean=cleanup_ipy_script(script)
305 clean=cleanup_ipy_script(script)
295
306 # print "_ip.runlines() script:\n",clean #dbg
296 self.IP.runlines(clean)
307 self.IP.runlines(clean)
297 def to_user_ns(self,vars, interactive = True):
308 def to_user_ns(self,vars, interactive = True):
298 """Inject a group of variables into the IPython user namespace.
309 """Inject a group of variables into the IPython user namespace.
@@ -210,7 +210,7 b" object? -> Details about 'object'. ?object also works, ?? prints more."
210 editor = '0',
210 editor = '0',
211 gthread = 0,
211 gthread = 0,
212 help = 0,
212 help = 0,
213 interact = 1,
213 interact = 0,
214 ipythondir = ipythondir_def,
214 ipythondir = ipythondir_def,
215 log = 0,
215 log = 0,
216 logfile = '',
216 logfile = '',
@@ -3,7 +3,7 b''
3 <leo_file>
3 <leo_file>
4 <leo_header file_format="2" tnodes="0" max_tnode_index="0" clone_windows="0"/>
4 <leo_header file_format="2" tnodes="0" max_tnode_index="0" clone_windows="0"/>
5 <globals body_outline_ratio="0.307814992026">
5 <globals body_outline_ratio="0.307814992026">
6 <global_window_position top="180" left="223" height="627" width="1280"/>
6 <global_window_position top="257" left="131" height="627" width="1280"/>
7 <global_log_window_position top="0" left="0" height="0" width="0"/>
7 <global_log_window_position top="0" left="0" height="0" width="0"/>
8 </globals>
8 </globals>
9 <preferences/>
9 <preferences/>
@@ -38,18 +38,18 b''
38 <v t="vivainio.20080219230342"><vh>slist to leo</vh></v>
38 <v t="vivainio.20080219230342"><vh>slist to leo</vh></v>
39 </v>
39 </v>
40 </v>
40 </v>
41 <v t="vivainio.20080218195413"><vh>Class tests</vh>
41 <v t="vivainio.20080218195413" a="E"><vh>Class tests</vh>
42 <v t="vivainio.20080218200509"><vh>csvr</vh></v>
42 <v t="vivainio.20080218200509"><vh>csvr</vh></v>
43 <v t="vivainio.20080218191007"><vh>tempfile</vh></v>
43 <v t="vivainio.20080218191007"><vh>tempfile</vh></v>
44 <v t="vivainio.20080218195413.1"><vh>rfile</vh></v>
44 <v t="vivainio.20080218195413.1"><vh>rfile</vh></v>
45 <v t="vivainio.20080219225804"><vh>strlist</vh></v>
45 <v t="vivainio.20080219225804"><vh>strlist</vh></v>
46 </v>
46 </v>
47 <v t="vivainio.20080222201226" a="V"><vh>IPython script push tests</vh></v>
47 <v t="vivainio.20080218201219" a="E"><vh>Direct variables</vh>
48 <v t="vivainio.20080218201219" a="E"><vh>Direct variables</vh>
48 <v t="vivainio.20080222201226"><vh>NewHeadline</vh></v>
49 <v t="vivainio.20080218201219.2"><vh>bar</vh></v>
49 <v t="vivainio.20080218201219.2"><vh>bar</vh></v>
50 </v>
50 </v>
51 <v t="vivainio.20080316144536" a="E"><vh>pylab tests</vh>
51 <v t="vivainio.20080316144536" a="E"><vh>pylab tests</vh>
52 <v t="vivainio.20080316145539.2" a="TV"><vh>Generate testarr</vh></v>
52 <v t="vivainio.20080316145539.2"><vh>Generate testarr</vh></v>
53 <v t="vivainio.20080316085925"><vh>testarr</vh></v>
53 <v t="vivainio.20080316085925"><vh>testarr</vh></v>
54 <v t="vivainio.20080316085950"><vh>Call plotter on testarr</vh></v>
54 <v t="vivainio.20080316085950"><vh>Call plotter on testarr</vh></v>
55 </v>
55 </v>
@@ -128,21 +128,45 b' def format_slist(obj):'
128 <t tx="vivainio.20080222193236">?</t>
128 <t tx="vivainio.20080222193236">?</t>
129 <t tx="vivainio.20080222193236.1">@wrap
129 <t tx="vivainio.20080222193236.1">@wrap
130 @nocolor</t>
130 @nocolor</t>
131 <t tx="vivainio.20080222201226">1+2
131 <t tx="vivainio.20080222201226"># test ipython script 'cleanup' with complex blocks
132 1+2
132 print "hello"
133 print "hello"
133 3+4
134 3+4
134
135
135 def f(x):
136 def f(x):
136 return x.upper()
137 return x.upper()
137
138
138 f('hello world')
139
139
140 if 0:
140 if 0:
141 print "foo"
141 print "foo"
142 else:
142 else:
143 print "bar"
143 print "bar"
144
144
145 </t>
145 def g():
146 pass
147
148 g()
149
150 if 1:
151 if 1:
152 print "hello"
153
154 print "world"
155
156 if 1:
157 print "hello"
158
159 print "word"
160 else:
161 print "foo"
162
163 print "bar"
164 print "baz"
165
166 try:
167 raise Exception
168 except:
169 print "exc ok"</t>
146 <t tx="vivainio.20080222202211"></t>
170 <t tx="vivainio.20080222202211"></t>
147 <t tx="vivainio.20080222202211.1" ipython="7d71005506636f6f7264737101284b0c4bde747102732e">@cl rfile
171 <t tx="vivainio.20080222202211.1" ipython="7d71005506636f6f7264737101284b0c4bde747102732e">@cl rfile
148 hello
172 hello
This diff has been collapsed as it changes many lines, (856 lines changed) Show them Hide them
@@ -53,6 +53,7 b' which tries to:'
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
@@ -228,24 +229,31 b' manner. If you download the tar archive, the process is:'
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 $)::
233
232 $ python setup.py install
234 $ python setup.py install
235
233 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
234 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
235 default python directories, you'll need to use the |--home| option
238 default python directories, you'll need to use the ``--home`` option
236 (or |--prefix|). For example:
239 (or ``--prefix``). For example::
237 |$ python setup.py install --home $HOME/local|
240
241 $ python setup.py install --home $HOME/local
242
238 will install IPython into $HOME/local and its subdirectories
243 will install IPython into $HOME/local and its subdirectories
239 (creating them if necessary).
244 (creating them if necessary).
240 You can type
245 You can type::
241 |$ python setup.py --help|
246
247 $ python setup.py --help
248
242 for more details.
249 for more details.
243 Note that if you change the default location for |--home| at
250
251 Note that if you change the default location for ``--home`` at
244 installation, IPython may end up installed at a location which is
252 installation, IPython may end up installed at a location which is
245 not part of your $PYTHONPATH environment variable. In this case,
253 not part of your $PYTHONPATH environment variable. In this case,
246 you'll need to configure this variable to include the actual
254 you'll need to configure this variable to include the actual
247 directory where the IPython/ directory ended (typically the value
255 directory where the IPython/ directory ended (typically the value
248 you give to |--home| plus /lib/python).
256 you give to ``--home`` plus /lib/python).
249
257
250
258
251 Mac OSX information
259 Mac OSX information
@@ -280,10 +288,14 b' and GTK apps. Under OSX, however, this requires that ipython is'
280 installed by calling the special pythonw script at installation time,
288 installed by calling the special pythonw script at installation time,
281 which takes care of coordinating things with Apple's graphical environment.
289 which takes care of coordinating things with Apple's graphical environment.
282
290
283 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::
284 | $ sudo pythonw setup.py install --install-scripts=/usr/local/bin|
292
293 $ sudo pythonw setup.py install --install-scripts=/usr/local/bin
294
285 or
295 or
286 | $ sudo pythonw setup.py install --install-scripts=/usr/bin|
296
297 $ sudo pythonw setup.py install --install-scripts=/usr/bin
298
287 depending on where you like to keep hand-installed executables.
299 depending on where you like to keep hand-installed executables.
288
300
289 The resulting script will have an appropriate shebang line (the first
301 The resulting script will have an appropriate shebang line (the first
@@ -294,7 +306,7 b' does not work and has a shebang line that points to, for example, just'
294 build/scripts-<python-version> directory. Delete that directory and
306 build/scripts-<python-version> directory. Delete that directory and
295 rerun the setup.py.
307 rerun the setup.py.
296
308
297 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
298 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
299 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
300 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
@@ -591,10 +603,14 b' Input/Output prompts and exception tracebacks'
591 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
592 system interactively by typing '%colors Linux' at the prompt (use
604 system interactively by typing '%colors Linux' at the prompt (use
593 '%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
594 prompt shows garbage like:
606 prompt shows garbage like::
607
595 [0;32mIn [[1;32m1[0;32m]: [0;00m
608 [0;32mIn [[1;32m1[0;32m]: [0;00m
596 instead of (in color) something like:
609
610 instead of (in color) something like::
611
597 In [1]:
612 In [1]:
613
598 this means that your terminal doesn't properly handle color escape
614 this means that your terminal doesn't properly handle color escape
599 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'.
600
616
@@ -665,11 +681,11 b' the previous section, you may need to set also in your .emacs file::'
665 (setq ansi-color-for-comint-mode t)
681 (setq ansi-color-for-comint-mode t)
666
682
667
683
668 Notes::
684 Notes:
669
685
670 * 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
671 IPython shell before attempting to execute any code regions via
687 IPython shell before attempting to execute any code regions via
672 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
673 regions to the interpreter, and you shouldn't experience any
689 regions to the interpreter, and you shouldn't experience any
674 problems.
690 problems.
675 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
@@ -1035,7 +1051,7 b' Regular Options'
1035 After the above threading options have been given, regular options can
1051 After the above threading options have been given, regular options can
1036 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
1037 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
1038 used. Some options have an alternate short form, indicated after a |.
1054 used. Some options have an alternate short form, indicated after a ``|``.
1039
1055
1040 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
1041 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
@@ -1373,6 +1389,7 b' typing %magic at the prompt, but that will also give you information'
1373 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
1374 customizations.
1390 customizations.
1375
1391
1392 ::
1376
1393
1377 %Exit: Exit IPython without confirmation.
1394 %Exit: Exit IPython without confirmation.
1378
1395
@@ -1712,8 +1729,8 b' Arguments:'
1712
1729
1713 If arguments are given, the following possibilites exist:
1730 If arguments are given, the following possibilites exist:
1714
1731
1715 - The arguments are numbers or pairs of colon-separated numbers (like 1
1732 - The arguments are numbers or pairs of dash-separated numbers (like 1
1716 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
1717 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.
1718
1735
1719 - 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
@@ -1735,7 +1752,7 b' editors (like kedit and gedit up to Gnome 2.8) do not understand the'
1735 '+NUMBER' parameter necessary for this feature. Good editors like
1752 '+NUMBER' parameter necessary for this feature. Good editors like
1736 (X)Emacs, vi, jed, pico and joe all do.
1753 (X)Emacs, vi, jed, pico and joe all do.
1737
1754
1738 - 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
1739 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
1740 editor. It will execute its contents with execfile() when you exit,
1757 editor. It will execute its contents with execfile() when you exit,
1741 loading any code in the file into your interactive namespace.
1758 loading any code in the file into your interactive namespace.
@@ -2200,9 +2217,9 b' this system, only pure python code and magic commands.'
2200 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
2201 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.
2202
2219
2203 Under Windows, it checks executability as a match agains a '|'-separated
2220 Under Windows, it checks executability as a match agains a ``|``-separated
2204 string of extensions, stored in the IPython config variable
2221 string of extensions, stored in the IPython config variable
2205 win_exec_ext. This defaults to 'exe|com|bat'.
2222 win_exec_ext. This defaults to ``exe|com|bat``.
2206
2223
2207 This function also resets the root module cache of module completer,
2224 This function also resets the root module cache of module completer,
2208 used on slow filesystems.
2225 used on slow filesystems.
@@ -2611,6 +2628,7 b' If called without arguments, acts as a toggle.'
2611
2628
2612
2629
2613 Access to the standard Python help
2630 Access to the standard Python help
2631 ----------------------------------
2614
2632
2615 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
2616 docstrings and the Python manuals. Simply type 'help' (no quotes) to
2634 docstrings and the Python manuals. Simply type 'help' (no quotes) to
@@ -2622,6 +2640,7 b' your environment variable PYTHONDOCS for this feature to work correctly.'
2622
2640
2623
2641
2624 Dynamic object information
2642 Dynamic object information
2643 --------------------------
2625
2644
2626 Typing ?word or word? prints detailed information about an object. If
2645 Typing ?word or word? prints detailed information about an object. If
2627 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
@@ -2663,6 +2682,7 b' are not really defined as separate identifiers. Try for example typing'
2663
2682
2664
2683
2665 Readline-based features
2684 Readline-based features
2685 -----------------------
2666
2686
2667 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
2668 your Python installation lacks readline support. We will first describe
2688 your Python installation lacks readline support. We will first describe
@@ -2820,7 +2840,6 b' Any input line beginning with a ! character is passed verbatim (minus'
2820 the !, of course) to the underlying operating system. For example,
2840 the !, of course) to the underlying operating system. For example,
2821 typing !ls will run 'ls' in the current directory.
2841 typing !ls will run 'ls' in the current directory.
2822
2842
2823
2824 Manual capture of command output
2843 Manual capture of command output
2825 --------------------------------
2844 --------------------------------
2826
2845
@@ -2832,10 +2851,9 b' output. The !! syntax is a shorthand for the %sx magic command.'
2832
2851
2833 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,
2834 but allowing more fine-grained control of the capture details, and
2853 but allowing more fine-grained control of the capture details, and
2835 storing the result directly into a named variable.
2854 storing the result directly into a named variable. The direct use of
2836
2855 %sc is now deprecated, and you should ise the ``var = !cmd`` syntax
2837 See Sec. 6.2 <#sec:magic> for details on the magics %sc and %sx, or use
2856 instead.
2838 IPython's own help (sc? and sx?) for further details.
2839
2857
2840 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
2841 making system calls. Any python variable or expression which you prepend
2859 making system calls. Any python variable or expression which you prepend
@@ -3004,7 +3022,8 b' Directory history'
3004
3022
3005 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
3006 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
3007 %dhist command allows you to view this history.
3025 %dhist command allows you to view this history. do ``cd -<TAB`` to
3026 conventiently view the directory history.
3008
3027
3009
3028
3010 Automatic parentheses and quotes
3029 Automatic parentheses and quotes
@@ -3078,6 +3097,23 b" won't work::"
3078 Customization
3097 Customization
3079 =============
3098 =============
3080
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
3081 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
3082 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
3083 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
@@ -3118,7 +3154,7 b' Each of these options may appear as many times as you need it in the file.'
3118 * [import_some <mod> <f1> <f2> ...:] import functions with 'from
3154 * [import_some <mod> <f1> <f2> ...:] import functions with 'from
3119 <mod> import <f1>,<f2>,...'
3155 <mod> import <f1>,<f2>,...'
3120 * [import_all <mod1> <mod2> ...:] for each module listed import
3156 * [import_all <mod1> <mod2> ...:] for each module listed import
3121 functions with 'from <mod> import *'
3157 functions with ``from <mod> import *``.
3122 * [execute <python code>:] give any single-line python code to be
3158 * [execute <python code>:] give any single-line python code to be
3123 executed.
3159 executed.
3124 * [execfile <filename>:] execute the python file given with an
3160 * [execfile <filename>:] execute the python file given with an
@@ -3136,7 +3172,6 b' Each of these options may appear as many times as you need it in the file.'
3136 normal system shell.
3172 normal system shell.
3137
3173
3138
3174
3139
3140 Sample ipythonrc file
3175 Sample ipythonrc file
3141 ---------------------
3176 ---------------------
3142
3177
@@ -3779,47 +3814,135 b' reproduce it here for reference::'
3779 #************************* end of file <ipythonrc> ************************
3814 #************************* end of file <ipythonrc> ************************
3780
3815
3781
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
3782
3905
3783 Fine-tuning your prompt
3906 Fine-tuning your prompt
3784 -----------------------
3907 -----------------------
3785
3908
3786 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
3787 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
3788 additional ones. We list them below:
3911 additional ones. We list them below::
3789
3912
3790 *\#*
3913 \#
3791 the prompt/history count number. This escape is automatically
3914 the prompt/history count number. This escape is automatically
3792 wrapped in the coloring codes for the currently active color scheme.
3915 wrapped in the coloring codes for the currently active color scheme.
3793 *\N*
3916 \N
3794 the 'naked' prompt/history count number: this is just the number
3917 the 'naked' prompt/history count number: this is just the number
3795 itself, without any coloring applied to it. This lets you produce
3918 itself, without any coloring applied to it. This lets you produce
3796 numbered prompts with your own colors.
3919 numbered prompts with your own colors.
3797 *\D*
3920 \D
3798 the prompt/history count, with the actual digits replaced by dots.
3921 the prompt/history count, with the actual digits replaced by dots.
3799 Used mainly in continuation prompts (prompt_in2)
3922 Used mainly in continuation prompts (prompt_in2)
3800 *\w*
3923 \w
3801 the current working directory
3924 the current working directory
3802 *\W*
3925 \W
3803 the basename of current working directory
3926 the basename of current working directory
3804 *\Xn*
3927 \Xn
3805 where $n=0\ldots5.$ The current working directory, with $HOME
3928 where $n=0\ldots5.$ The current working directory, with $HOME
3806 replaced by ~, and filtered out to contain only $n$ path elements
3929 replaced by ~, and filtered out to contain only $n$ path elements
3807 *\Yn*
3930 \Yn
3808 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
3809 is similar to the behavior of the %cn escapes in tcsh)
3932 is similar to the behavior of the %cn escapes in tcsh)
3810 *\u*
3933 \u
3811 the username of the current user
3934 the username of the current user
3812 *\$*
3935 \$
3813 if the effective UID is 0, a #, otherwise a $
3936 if the effective UID is 0, a #, otherwise a $
3814 *\h*
3937 \h
3815 the hostname up to the first '.'
3938 the hostname up to the first '.'
3816 *\H*
3939 \H
3817 the hostname
3940 the hostname
3818 *\n*
3941 \n
3819 a newline
3942 a newline
3820 *\r*
3943 \r
3821 a carriage return
3944 a carriage return
3822 *\v*
3945 \v
3823 IPython version string
3946 IPython version string
3824
3947
3825 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
@@ -3848,7 +3971,7 b' default prompts::'
3848 prompt_in2 ' .\D.:'
3971 prompt_in2 ' .\D.:'
3849 prompt_out 'Out[\#]:'
3972 prompt_out 'Out[\#]:'
3850
3973
3851 which look like this:
3974 which look like this::
3852
3975
3853 In [1]: 1+2
3976 In [1]: 1+2
3854 Out[1]: 3
3977 Out[1]: 3
@@ -4166,7 +4289,6 b' code fragments in your programs which are ready for cut and paste::'
4166 Using the Python debugger (pdb)
4289 Using the Python debugger (pdb)
4167 ===============================
4290 ===============================
4168
4291
4169
4170 Running entire programs via pdb
4292 Running entire programs via pdb
4171 -------------------------------
4293 -------------------------------
4172
4294
@@ -4212,7 +4334,7 b' uncaught exception is triggered by your code.'
4212
4334
4213 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
4214 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'
4215 routine:
4337 routine::
4216
4338
4217 import sys,IPython.ultraTB
4339 import sys,IPython.ultraTB
4218 sys.excepthook = IPython.ultraTB.FormattedTB(mode='Verbose',
4340 sys.excepthook = IPython.ultraTB.FormattedTB(mode='Verbose',
@@ -4242,7 +4364,7 b" supplied, which we will briefly describe now. These can be used 'as is'"
4242 starting point for writing your own extensions.
4364 starting point for writing your own extensions.
4243
4365
4244
4366
4245 Pasting of code starting with 'Β»> ' or '... '
4367 Pasting of code starting with '>>> ' or '... '
4246 ----------------------------------------------
4368 ----------------------------------------------
4247
4369
4248 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
@@ -4304,6 +4426,7 b" Physics.PhysicalQuantities from Konrad Hinsen's ScientificPython"
4304 The Physics.PhysicalQuantities module defines PhysicalQuantity objects,
4426 The Physics.PhysicalQuantities module defines PhysicalQuantity objects,
4305 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
4306 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::
4429
4307 In [1]: v = PhysicalQuantity(3,'m/s')
4430 In [1]: v = PhysicalQuantity(3,'m/s')
4308
4431
4309 Using the PhysicalQ_Input extension this can be input instead as:
4432 Using the PhysicalQ_Input extension this can be input instead as:
@@ -4318,235 +4441,286 b' from math import * # math MUST be imported BEFORE PhysicalQInteractive'
4318 from IPython.Extensions.PhysicalQInteractive import *
4441 from IPython.Extensions.PhysicalQInteractive import *
4319 import IPython.Extensions.PhysicalQInput
4442 import IPython.Extensions.PhysicalQInput
4320
4443
4321 IPython as a system shell
4322 =========================
4323
4444
4324 IPython ships with a special profile called pysh, which you can activate
4445 IPython as a system shell - the 'Sh' profile
4325 at the command line as 'ipython -p pysh'. This loads InterpreterExec,
4446 ============================================
4326 along with some additional facilities and a prompt customized for
4447
4327 filesystem navigation.
4448 The 'sh' profile optimizes IPython for system shell usage. Apart from
4449 certain job control functionality that is present in unix (ctrl+z does
4450 "suspend"), the sh profile should provide you with most of the
4451 functionality you use daily in system shell, and more. Invoke IPython
4452 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
4453 the "pysh" shortcut in start menu.
4454
4455 If you want to use the features of sh profile as your defaults (which
4456 might be a good idea if you use other profiles a lot of the time but
4457 still want the convenience of sh profile), add ``import ipy_profile_sh``
4458 to your ~/.ipython/ipy_user_conf.py.
4328
4459
4329 Note that this does not make IPython a full-fledged system shell. In
4460 The 'sh' profile is different from the default profile in that:
4330 particular, it has no job control, so if you type Ctrl-Z (under Unix),
4331 you'll suspend pysh itself, not the process you just started.
4332
4461
4333 What the shell profile allows you to do is to use the convenient and
4462 * Prompt shows the current directory
4334 powerful syntax of Python to do quick scripting at the command line.
4463 * Spacing between prompts and input is more compact (no padding with
4335 Below we describe some of its features.
4464 empty lines). The startup banner is more compact as well.
4465 * System commands are directly available (in alias table) without
4466 requesting %rehashx - however, if you install new programs along
4467 your PATH, you might want to run %rehashx to update the persistent
4468 alias table
4469 * Macros are stored in raw format by default. That is, instead of
4470 '_ip.system("cat foo"), the macro will contain text 'cat foo')
4471 * Autocall is in full mode
4472 * Calling "up" does "cd .."
4336
4473
4474 The 'sh' profile is different from the now-obsolete (and unavailable)
4475 'pysh' profile in that:
4476
4477 * '$$var = command' and '$var = command' syntax is not supported
4478 * anymore. Use 'var = !command' instead (incidentally, this is
4479 * available in all IPython profiles). Note that !!command *will*
4480 * work.
4337
4481
4338 Aliases
4482 Aliases
4339 -------
4483 -------
4340
4484
4341 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
4342 able to type any normal system command and have it executed. See %alias?
4486 able to type any normal system command and have it executed. See
4343 and %unalias? for details on the alias facilities. See also %rehash? and
4487 %alias? and %unalias? for details on the alias facilities. See also
4344 %rehashx? for details on the mechanism used to load $PATH.
4488 %rehashx? for details on the mechanism used to load $PATH.
4345
4489
4346
4490
4347 Special syntax
4491 Directory management
4348 --------------
4492 --------------------
4493
4494 Since each command passed by ipython to the underlying system is executed
4495 in a subshell which exits immediately, you can NOT use !cd to navigate
4496 the filesystem.
4349
4497
4350 Any lines which begin with '~', '/' and '.' will be executed as shell
4498 IPython provides its own builtin '%cd' magic command to move in the
4351 commands instead of as Python code. The special escapes below are also
4499 filesystem (the % is not required with automagic on). It also maintains
4352 recognized. !cmd is valid in single or multi-line input, all others are
4500 a list of visited directories (use %dhist to see it) and allows direct
4353 only valid in single-line input::
4501 switching to any of them. Type 'cd?' for more details.
4354
4502
4355 *!cmd*
4503 %pushd, %popd and %dirs are provided for directory stack handling.
4356 pass 'cmd' directly to the shell
4357 *!!cmd*
4358 execute 'cmd' and return output as a list (split on '\n')
4359 *var=!cmd
4360 capture output of cmd into var, as a string list
4361
4504
4362 The $/$$ syntaxes make Python variables from system output, which you
4363 can later use for further scripting. The converse is also possible: when
4364 executing an alias or calling to the system via !/!!, you can expand any
4365 python variable or expression by prepending it with $. Full details of
4366 the allowed syntax can be found in Python's PEP 215.
4367
4505
4368 A few brief examples will illustrate these (note that the indentation
4506 Enabled extensions
4369 below may be incorrectly displayed)::
4507 ------------------
4370
4508
4371 fperez[~/test]|3> !ls *s.py
4509 Some extensions, listed below, are enabled as default in this profile.
4372 scopes.py strings.py
4373
4510
4374 ls is an internal alias, so there's no need to use !::
4511 envpersist
4512 ++++++++++
4375
4513
4376 fperez[~/test]|4> ls *s.py
4514 %env can be used to "remember" environment variable manipulations. Examples::
4377 scopes.py* strings.py
4378
4515
4379 !!ls will return the output into a Python variable FIXME!!!::
4516 %env - Show all environment variables
4517 %env VISUAL=jed - set VISUAL to jed
4518 %env PATH+=;/foo - append ;foo to PATH
4519 %env PATH+=;/bar - also append ;bar to PATH
4520 %env PATH-=/wbin; - prepend /wbin; to PATH
4521 %env -d VISUAL - forget VISUAL persistent val
4522 %env -p - print all persistent env modifications
4380
4523
4381 fperez[~/test]|5> !!ls *s.py
4524 ipy_which
4382 <5> ['scopes.py', 'strings.py']
4525 +++++++++
4383 fperez[~/test]|6> print _5
4384 ['scopes.py', 'strings.py']
4385
4526
4386 $ and $$ allow direct capture to named variables:
4527 %which magic command. Like 'which' in unix, but knows about ipython aliases.
4387
4528
4388 fperez[~/test]|7> $astr = ls *s.py
4529 Example::
4389 fperez[~/test]|8> astr
4390 <8> 'scopes.py\nstrings.py'
4391
4530
4392 fperez[~/test]|9> $$alist = ls *s.py
4531 [C:/ipython]|14> %which st
4393 fperez[~/test]|10> alist
4532 st -> start .
4394 <10> ['scopes.py', 'strings.py']
4533 [C:/ipython]|15> %which d
4534 d -> dir /w /og /on
4535 [C:/ipython]|16> %which cp
4536 cp -> cp
4537 == c:\bin\cp.exe
4538 c:\bin\cp.exe
4395
4539
4396 alist is now a normal python list you can loop over. Using $ will expand
4540 ipy_app_completers
4397 back the python values when alias calls are made:
4541 ++++++++++++++++++
4398
4542
4399 fperez[~/test]|11> for f in alist:
4543 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
4400 |..> print 'file',f,
4401 |..> wc -l $f
4402 |..>
4403 file scopes.py 13 scopes.py
4404 file strings.py 4 strings.py
4405
4544
4406 Note that you may need to protect your variables with braces if you want
4545 ipy_rehashdir
4407 to append strings to their names. To copy all files in alist to .bak
4546 +++++++++++++
4408 extensions, you must use::
4409
4547
4410 fperez[~/test]|12> for f in alist:
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::
4411 |..> cp $f ${f}.bak
4412
4549
4413 If you try using $f.bak, you'll get an AttributeError exception saying
4550 [~]|22> cd c:/opt/PuTTY/
4414 that your string object doesn't have a .bak attribute. This is because
4551 [c:opt/PuTTY]|23> rehashdir .
4415 the $ expansion mechanism allows you to expand full Python expressions::
4552 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
4416
4553
4417 fperez[~/test]|13> echo "sys.platform is: $sys.platform"
4554 Now, you can execute any of those commams directly::
4418 sys.platform is: linux2
4419
4555
4420 IPython's input history handling is still active, which allows you to
4556 [c:opt/PuTTY]|24> cd
4421 rerun a single block of multi-line input by simply using exec::
4557 [~]|25> putty
4422
4558
4423 fperez[~/test]|14> $$alist = ls *.eps
4559 (the putty window opens).
4424 fperez[~/test]|15> exec _i11
4425 file image2.eps 921 image2.eps
4426 file image.eps 921 image.eps
4427
4560
4428 While these are new special-case syntaxes, they are designed to allow
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::
4429 very efficient use of the shell with minimal typing. At an interactive
4430 shell prompt, conciseness of expression wins over readability.
4431
4562
4563 [~]|27> for a in _23:
4564 |..> %store $a
4565 |..>
4566 |..>
4567 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
4568 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
4569 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
4570 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
4571 ...
4432
4572
4433 Useful functions and modules
4573 mglob
4434 ----------------------------
4574 +++++
4435
4575
4436 The os, sys and shutil modules from the Python standard library are
4576 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
4437 automatically loaded. Some additional functions, useful for shell usage,
4438 are listed below. You can request more help about them with '?'.
4439
4577
4440 *shell*
4578 [c:/ipython]|9> mglob *.py
4441 - execute a command in the underlying system shell
4579 [c:/ipython]|10> mglob *.py rec:*.txt
4442 *system*
4580 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
4443 - like shell(), but return the exit status of the command
4444 *sout*
4445 - capture the output of a command as a string
4446 *lout*
4447 - capture the output of a command as a list (split on '\n')
4448 *getoutputerror*
4449 - capture (output,error) of a shell commandss
4450
4581
4451 sout/lout are the functional equivalents of $/$$. They are provided to
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'.
4452 allow you to capture system output in the middle of true python code,
4453 function definitions, etc (where $ and $$ are invalid).
4454
4583
4455
4584
4456 Directory management
4585 Prompt customization
4457 --------------------
4586 --------------------
4458
4587
4459 Since each command passed by pysh to the underlying system is executed
4588 The sh profile uses the following prompt configurations::
4460 in a subshell which exits immediately, you can NOT use !cd to navigate
4461 the filesystem.
4462
4589
4463 Pysh provides its own builtin '%cd' magic command to move in the
4590 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
4464 filesystem (the % is not required with automagic on). It also maintains
4591 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
4465 a list of visited directories (use %dhist to see it) and allows direct
4466 switching to any of them. Type 'cd?' for more details.
4467
4592
4468 %pushd, %popd and %dirs are provided for directory stack handling.
4593 You can change the prompt configuration to your liking by editing
4594 ipy_user_conf.py.
4595
4596 String lists
4597 ============
4469
4598
4599 String lists (IPython.genutils.SList) are handy way to process output
4600 from system commands. They are produced by ``var = !cmd`` syntax.
4470
4601
4471 Prompt customization
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:
4472
4620
4473 The supplied ipythonrc-pysh profile comes with an example of a very
4621 0: total 23
4474 colored and detailed prompt, mainly to serve as an illustration. The
4622 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
4475 valid escape sequences, besides color names, are:
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
4476
4629
4477 *\#*
4630 Now, let's filter out the 'embed' lines::
4478 - Prompt number, wrapped in the color escapes for the input prompt
4479 (determined by the current color scheme).
4480 *\N*
4481 - Just the prompt counter number, without any coloring wrappers. You
4482 can thus customize the actual prompt colors manually.
4483 *\D*
4484 - Dots, as many as there are digits in \# (so they align).
4485 *\w*
4486 - Current working directory (cwd).
4487 *\W*
4488 - Basename of current working directory.
4489 *\XN*
4490 - Where N=0..5. N terms of the cwd, with $HOME written as ~.
4491 *\YN*
4492 - Where N=0..5. Like XN, but if ~ is term N+1 it's also shown.
4493 *\u*
4494 - Username.
4495 *\H*
4496 - Full hostname.
4497 *\h*
4498 - Hostname up to first '.'
4499 *\$*
4500 - Root symbol ($ or #).
4501 *\t*
4502 - Current time, in H:M:S format.
4503 *\v*
4504 - IPython release version.
4505 *\n*
4506 - Newline.
4507 *\r*
4508 - Carriage return.
4509 *\\*
4510 - An explicitly escaped '\'.
4511
4631
4512 You can configure your prompt colors using any ANSI color escape. Each
4632 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
4513 color escape sets the color for any subsequent text, until another
4633 [Q:doc/examples]|5> l2
4514 escape comes in and changes things. The valid color escapes are:
4634 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
4515
4635
4516 *\C_Black*
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
4517
4642
4518 *\C_Blue*
4643 Now, we want strings having just file names and permissions::
4519
4644
4520 *\C_Brown*
4645 [Q:doc/examples]|6> l2.fields(8,0)
4646 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
4521
4647
4522 *\C_Cyan*
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
4523
4654
4524 *\C_DarkGray*
4655 Note how the line with 'total' does not raise IndexError.
4525
4656
4526 *\C_Green*
4657 If you want to split these (yielding lists), call fields() without
4658 arguments::
4527
4659
4528 *\C_LightBlue*
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']]
4529
4668
4530 *\C_LightCyan*
4669 If you want to pass these separated with spaces to a command (typical
4670 for lists if files), use the .s property::
4531
4671
4532 *\C_LightGray*
4533
4672
4534 *\C_LightGreen*
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
4535
4678
4536 *\C_LightPurple*
4679 SLists are inherited from normal python lists, so every list method is
4680 available::
4537
4681
4538 *\C_LightRed*
4682 [Q:doc/examples]|21> lines.append('hey')
4539
4683
4540 *\C_Purple*
4541
4684
4542 *\C_Red*
4685 Real world example: remove all files outside version control
4686 ------------------------------------------------------------
4543
4687
4544 *\C_White*
4688 First, capture output of "hg status"::
4545
4689
4546 *\C_Yellow*
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.
4547
4723
4548 *\C_Normal*
4549 Stop coloring, defaults to your terminal settings.
4550
4724
4551 Threading support
4725 Threading support
4552 =================
4726 =================
@@ -4595,8 +4769,10 b' value can be read by using the sys.getcheckinterval() function, and it'
4595 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
4596 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.
4597 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
4598 '\n'. An instruction as simple as
4772 '\n'. An instruction as simple as::
4773
4599 print >> filehandle, ''hello world''
4774 print >> filehandle, ''hello world''
4775
4600 actually consists of several bytecodes, so it is possible that the
4776 actually consists of several bytecodes, so it is possible that the
4601 newline does not reach your file before the next thread switch.
4777 newline does not reach your file before the next thread switch.
4602 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
@@ -4608,6 +4784,7 b' example) a GUI application which will read data generated by files'
4608 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
4609 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
4610 function is the buffering value)::
4786 function is the buffering value)::
4787
4611 filehandle = open(filename,mode,0)
4788 filehandle = open(filename,mode,0)
4612
4789
4613 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
@@ -4738,6 +4915,258 b" mechanism (Sec. 7.3 <node7.html#sec:profiles>): ''ipython -pylab -p"
4738 myprofile'' will load the profile defined in ipythonrc-myprofile after
4915 myprofile'' will load the profile defined in ipythonrc-myprofile after
4739 configuring matplotlib.
4916 configuring matplotlib.
4740
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
5116 Provided extensions
5117 ===================
5118
5119 You can see the list of available extensions (and profiles) by doing
5120 ``import ipy_<TAB>``. Some extensions don't have the ``ipy_`` prefix in
5121 module name, so you may need to see the contents of IPython/Extensions
5122 folder to see what's available.
5123
5124 You can see a brief documentation of an extension by looking at the
5125 module docstring::
5126
5127 [c:p/ipython_main]|190> import ipy_fsops
5128 [c:p/ipython_main]|191> ipy_fsops?
5129
5130 ...
5131
5132 Docstring:
5133 File system operations
5134
5135 Contains: Simple variants of normal unix shell commands (icp, imv, irm,
5136 imkdir, igrep).
5137
5138 You can also install your own extensions - the recommended way is to
5139 just copy the module to ~/.ipython. Extensions are typically enabled
5140 by just importing them (e.g. in ipy_user_conf.py), but some extensions
5141 require additional steps, for example::
5142
5143 [c:p]|192> import ipy_traits_completer
5144 [c:p]|193> ipy_traits_completer.activate()
5145
5146 Note that extensions, even if provided in the stock IPython
5147 installation, are not guaranteed to have the same requirements as the
5148 rest of IPython - an extension may require external libraries or a
5149 newer version of Python than what IPython officially requires. An
5150 extension may also be under a more restrictive license than IPython
5151 (e.g. ipy_bzr is under GPL).
5152
5153 Just for reference, the list of bundled extensions at the time of
5154 writing is below:
5155
5156 astyle.py clearcmd.py envpersist.py ext_rescapture.py ibrowse.py
5157 igrid.py InterpreterExec.py InterpreterPasteInput.py ipipe.py
5158 ipy_app_completers.py ipy_autoreload.py ipy_bzr.py ipy_completers.py
5159 ipy_constants.py ipy_defaults.py ipy_editors.py ipy_exportdb.py
5160 ipy_extutil.py ipy_fsops.py ipy_gnuglobal.py ipy_kitcfg.py
5161 ipy_legacy.py ipy_leo.py ipy_p4.py ipy_profile_doctest.py
5162 ipy_profile_none.py ipy_profile_scipy.py ipy_profile_sh.py
5163 ipy_profile_zope.py ipy_pydb.py ipy_rehashdir.py ipy_render.py
5164 ipy_server.py ipy_signals.py ipy_stock_completers.py
5165 ipy_system_conf.py ipy_traits_completer.py ipy_vimserver.py
5166 ipy_which.py ipy_workdir.py jobctrl.py ledit.py numeric_formats.py
5167 PhysicalQInput.py PhysicalQInteractive.py pickleshare.py
5168 pspersistence.py win32clip.py __init__.py
5169
4741 Reporting bugs
5170 Reporting bugs
4742 ==============
5171 ==============
4743
5172
@@ -4773,6 +5202,7 b' Brief history'
4773
5202
4774
5203
4775 Origins
5204 Origins
5205 -------
4776
5206
4777 The current IPython system grew out of the following three projects:
5207 The current IPython system grew out of the following three projects:
4778
5208
General Comments 0
You need to be logged in to leave comments. Login now