##// END OF EJS Templates
oops, revert failed application of patch 2/9
vivainio -
Show More
@@ -1,3072 +1,3067 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 1921 2006-11-21 20:49:55Z vivainio $"""
4 $Id: Magic.py 1922 2006-11-21 20:56:48Z vivainio $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 #
9 #
10 # Distributed under the terms of the BSD License. The full license is in
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
11 # the file COPYING, distributed as part of this software.
12 #*****************************************************************************
12 #*****************************************************************************
13
13
14 #****************************************************************************
14 #****************************************************************************
15 # Modules and globals
15 # Modules and globals
16
16
17 from IPython import Release
17 from IPython import Release
18 __author__ = '%s <%s>\n%s <%s>' % \
18 __author__ = '%s <%s>\n%s <%s>' % \
19 ( Release.authors['Janko'] + Release.authors['Fernando'] )
19 ( Release.authors['Janko'] + Release.authors['Fernando'] )
20 __license__ = Release.license
20 __license__ = Release.license
21
21
22 # Python standard modules
22 # Python standard modules
23 import __builtin__
23 import __builtin__
24 import bdb
24 import bdb
25 import inspect
25 import inspect
26 import os
26 import os
27 import pdb
27 import pdb
28 import pydoc
28 import pydoc
29 import sys
29 import sys
30 import re
30 import re
31 import tempfile
31 import tempfile
32 import time
32 import time
33 import cPickle as pickle
33 import cPickle as pickle
34 import textwrap
34 import textwrap
35 from cStringIO import StringIO
35 from cStringIO import StringIO
36 from getopt import getopt,GetoptError
36 from getopt import getopt,GetoptError
37 from pprint import pprint, pformat
37 from pprint import pprint, pformat
38
38
39 # cProfile was added in Python2.5
39 # profile isn't bundled by default in Debian for license reasons
40 try:
40 try:
41 import cProfile as profile
41 import profile,pstats
42 import pstats
43 except ImportError:
42 except ImportError:
44 # profile isn't bundled by default in Debian for license reasons
43 profile = pstats = None
45 try:
46 import profile,pstats
47 except ImportError:
48 profile = pstats = None
49
44
50 # Homebrewed
45 # Homebrewed
51 import IPython
46 import IPython
52 from IPython import Debugger, OInspect, wildcard
47 from IPython import Debugger, OInspect, wildcard
53 from IPython.FakeModule import FakeModule
48 from IPython.FakeModule import FakeModule
54 from IPython.Itpl import Itpl, itpl, printpl,itplns
49 from IPython.Itpl import Itpl, itpl, printpl,itplns
55 from IPython.PyColorize import Parser
50 from IPython.PyColorize import Parser
56 from IPython.ipstruct import Struct
51 from IPython.ipstruct import Struct
57 from IPython.macro import Macro
52 from IPython.macro import Macro
58 from IPython.genutils import *
53 from IPython.genutils import *
59 from IPython import platutils
54 from IPython import platutils
60
55
61 #***************************************************************************
56 #***************************************************************************
62 # Utility functions
57 # Utility functions
63 def on_off(tag):
58 def on_off(tag):
64 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
59 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
65 return ['OFF','ON'][tag]
60 return ['OFF','ON'][tag]
66
61
67 class Bunch: pass
62 class Bunch: pass
68
63
69 #***************************************************************************
64 #***************************************************************************
70 # Main class implementing Magic functionality
65 # Main class implementing Magic functionality
71 class Magic:
66 class Magic:
72 """Magic functions for InteractiveShell.
67 """Magic functions for InteractiveShell.
73
68
74 Shell functions which can be reached as %function_name. All magic
69 Shell functions which can be reached as %function_name. All magic
75 functions should accept a string, which they can parse for their own
70 functions should accept a string, which they can parse for their own
76 needs. This can make some functions easier to type, eg `%cd ../`
71 needs. This can make some functions easier to type, eg `%cd ../`
77 vs. `%cd("../")`
72 vs. `%cd("../")`
78
73
79 ALL definitions MUST begin with the prefix magic_. The user won't need it
74 ALL definitions MUST begin with the prefix magic_. The user won't need it
80 at the command line, but it is is needed in the definition. """
75 at the command line, but it is is needed in the definition. """
81
76
82 # class globals
77 # class globals
83 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
78 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
84 'Automagic is ON, % prefix NOT needed for magic functions.']
79 'Automagic is ON, % prefix NOT needed for magic functions.']
85
80
86 #......................................................................
81 #......................................................................
87 # some utility functions
82 # some utility functions
88
83
89 def __init__(self,shell):
84 def __init__(self,shell):
90
85
91 self.options_table = {}
86 self.options_table = {}
92 if profile is None:
87 if profile is None:
93 self.magic_prun = self.profile_missing_notice
88 self.magic_prun = self.profile_missing_notice
94 self.shell = shell
89 self.shell = shell
95
90
96 # namespace for holding state we may need
91 # namespace for holding state we may need
97 self._magic_state = Bunch()
92 self._magic_state = Bunch()
98
93
99 def profile_missing_notice(self, *args, **kwargs):
94 def profile_missing_notice(self, *args, **kwargs):
100 error("""\
95 error("""\
101 The profile module could not be found. If you are a Debian user,
96 The profile module could not be found. If you are a Debian user,
102 it has been removed from the standard Debian package because of its non-free
97 it has been removed from the standard Debian package because of its non-free
103 license. To use profiling, please install"python2.3-profiler" from non-free.""")
98 license. To use profiling, please install"python2.3-profiler" from non-free.""")
104
99
105 def default_option(self,fn,optstr):
100 def default_option(self,fn,optstr):
106 """Make an entry in the options_table for fn, with value optstr"""
101 """Make an entry in the options_table for fn, with value optstr"""
107
102
108 if fn not in self.lsmagic():
103 if fn not in self.lsmagic():
109 error("%s is not a magic function" % fn)
104 error("%s is not a magic function" % fn)
110 self.options_table[fn] = optstr
105 self.options_table[fn] = optstr
111
106
112 def lsmagic(self):
107 def lsmagic(self):
113 """Return a list of currently available magic functions.
108 """Return a list of currently available magic functions.
114
109
115 Gives a list of the bare names after mangling (['ls','cd', ...], not
110 Gives a list of the bare names after mangling (['ls','cd', ...], not
116 ['magic_ls','magic_cd',...]"""
111 ['magic_ls','magic_cd',...]"""
117
112
118 # FIXME. This needs a cleanup, in the way the magics list is built.
113 # FIXME. This needs a cleanup, in the way the magics list is built.
119
114
120 # magics in class definition
115 # magics in class definition
121 class_magic = lambda fn: fn.startswith('magic_') and \
116 class_magic = lambda fn: fn.startswith('magic_') and \
122 callable(Magic.__dict__[fn])
117 callable(Magic.__dict__[fn])
123 # in instance namespace (run-time user additions)
118 # in instance namespace (run-time user additions)
124 inst_magic = lambda fn: fn.startswith('magic_') and \
119 inst_magic = lambda fn: fn.startswith('magic_') and \
125 callable(self.__dict__[fn])
120 callable(self.__dict__[fn])
126 # and bound magics by user (so they can access self):
121 # and bound magics by user (so they can access self):
127 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
122 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
128 callable(self.__class__.__dict__[fn])
123 callable(self.__class__.__dict__[fn])
129 magics = filter(class_magic,Magic.__dict__.keys()) + \
124 magics = filter(class_magic,Magic.__dict__.keys()) + \
130 filter(inst_magic,self.__dict__.keys()) + \
125 filter(inst_magic,self.__dict__.keys()) + \
131 filter(inst_bound_magic,self.__class__.__dict__.keys())
126 filter(inst_bound_magic,self.__class__.__dict__.keys())
132 out = []
127 out = []
133 for fn in magics:
128 for fn in magics:
134 out.append(fn.replace('magic_','',1))
129 out.append(fn.replace('magic_','',1))
135 out.sort()
130 out.sort()
136 return out
131 return out
137
132
138 def extract_input_slices(self,slices,raw=False):
133 def extract_input_slices(self,slices,raw=False):
139 """Return as a string a set of input history slices.
134 """Return as a string a set of input history slices.
140
135
141 Inputs:
136 Inputs:
142
137
143 - slices: the set of slices is given as a list of strings (like
138 - slices: the set of slices is given as a list of strings (like
144 ['1','4:8','9'], since this function is for use by magic functions
139 ['1','4:8','9'], since this function is for use by magic functions
145 which get their arguments as strings.
140 which get their arguments as strings.
146
141
147 Optional inputs:
142 Optional inputs:
148
143
149 - raw(False): by default, the processed input is used. If this is
144 - raw(False): by default, the processed input is used. If this is
150 true, the raw input history is used instead.
145 true, the raw input history is used instead.
151
146
152 Note that slices can be called with two notations:
147 Note that slices can be called with two notations:
153
148
154 N:M -> standard python form, means including items N...(M-1).
149 N:M -> standard python form, means including items N...(M-1).
155
150
156 N-M -> include items N..M (closed endpoint)."""
151 N-M -> include items N..M (closed endpoint)."""
157
152
158 if raw:
153 if raw:
159 hist = self.shell.input_hist_raw
154 hist = self.shell.input_hist_raw
160 else:
155 else:
161 hist = self.shell.input_hist
156 hist = self.shell.input_hist
162
157
163 cmds = []
158 cmds = []
164 for chunk in slices:
159 for chunk in slices:
165 if ':' in chunk:
160 if ':' in chunk:
166 ini,fin = map(int,chunk.split(':'))
161 ini,fin = map(int,chunk.split(':'))
167 elif '-' in chunk:
162 elif '-' in chunk:
168 ini,fin = map(int,chunk.split('-'))
163 ini,fin = map(int,chunk.split('-'))
169 fin += 1
164 fin += 1
170 else:
165 else:
171 ini = int(chunk)
166 ini = int(chunk)
172 fin = ini+1
167 fin = ini+1
173 cmds.append(hist[ini:fin])
168 cmds.append(hist[ini:fin])
174 return cmds
169 return cmds
175
170
176 def _ofind(self, oname, namespaces=None):
171 def _ofind(self, oname, namespaces=None):
177 """Find an object in the available namespaces.
172 """Find an object in the available namespaces.
178
173
179 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
174 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
180
175
181 Has special code to detect magic functions.
176 Has special code to detect magic functions.
182 """
177 """
183
178
184 oname = oname.strip()
179 oname = oname.strip()
185
180
186 alias_ns = None
181 alias_ns = None
187 if namespaces is None:
182 if namespaces is None:
188 # Namespaces to search in:
183 # Namespaces to search in:
189 # Put them in a list. The order is important so that we
184 # Put them in a list. The order is important so that we
190 # find things in the same order that Python finds them.
185 # find things in the same order that Python finds them.
191 namespaces = [ ('Interactive', self.shell.user_ns),
186 namespaces = [ ('Interactive', self.shell.user_ns),
192 ('IPython internal', self.shell.internal_ns),
187 ('IPython internal', self.shell.internal_ns),
193 ('Python builtin', __builtin__.__dict__),
188 ('Python builtin', __builtin__.__dict__),
194 ('Alias', self.shell.alias_table),
189 ('Alias', self.shell.alias_table),
195 ]
190 ]
196 alias_ns = self.shell.alias_table
191 alias_ns = self.shell.alias_table
197
192
198 # initialize results to 'null'
193 # initialize results to 'null'
199 found = 0; obj = None; ospace = None; ds = None;
194 found = 0; obj = None; ospace = None; ds = None;
200 ismagic = 0; isalias = 0; parent = None
195 ismagic = 0; isalias = 0; parent = None
201
196
202 # Look for the given name by splitting it in parts. If the head is
197 # Look for the given name by splitting it in parts. If the head is
203 # found, then we look for all the remaining parts as members, and only
198 # found, then we look for all the remaining parts as members, and only
204 # declare success if we can find them all.
199 # declare success if we can find them all.
205 oname_parts = oname.split('.')
200 oname_parts = oname.split('.')
206 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
201 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
207 for nsname,ns in namespaces:
202 for nsname,ns in namespaces:
208 try:
203 try:
209 obj = ns[oname_head]
204 obj = ns[oname_head]
210 except KeyError:
205 except KeyError:
211 continue
206 continue
212 else:
207 else:
213 for part in oname_rest:
208 for part in oname_rest:
214 try:
209 try:
215 parent = obj
210 parent = obj
216 obj = getattr(obj,part)
211 obj = getattr(obj,part)
217 except:
212 except:
218 # Blanket except b/c some badly implemented objects
213 # Blanket except b/c some badly implemented objects
219 # allow __getattr__ to raise exceptions other than
214 # allow __getattr__ to raise exceptions other than
220 # AttributeError, which then crashes IPython.
215 # AttributeError, which then crashes IPython.
221 break
216 break
222 else:
217 else:
223 # If we finish the for loop (no break), we got all members
218 # If we finish the for loop (no break), we got all members
224 found = 1
219 found = 1
225 ospace = nsname
220 ospace = nsname
226 if ns == alias_ns:
221 if ns == alias_ns:
227 isalias = 1
222 isalias = 1
228 break # namespace loop
223 break # namespace loop
229
224
230 # Try to see if it's magic
225 # Try to see if it's magic
231 if not found:
226 if not found:
232 if oname.startswith(self.shell.ESC_MAGIC):
227 if oname.startswith(self.shell.ESC_MAGIC):
233 oname = oname[1:]
228 oname = oname[1:]
234 obj = getattr(self,'magic_'+oname,None)
229 obj = getattr(self,'magic_'+oname,None)
235 if obj is not None:
230 if obj is not None:
236 found = 1
231 found = 1
237 ospace = 'IPython internal'
232 ospace = 'IPython internal'
238 ismagic = 1
233 ismagic = 1
239
234
240 # Last try: special-case some literals like '', [], {}, etc:
235 # Last try: special-case some literals like '', [], {}, etc:
241 if not found and oname_head in ["''",'""','[]','{}','()']:
236 if not found and oname_head in ["''",'""','[]','{}','()']:
242 obj = eval(oname_head)
237 obj = eval(oname_head)
243 found = 1
238 found = 1
244 ospace = 'Interactive'
239 ospace = 'Interactive'
245
240
246 return {'found':found, 'obj':obj, 'namespace':ospace,
241 return {'found':found, 'obj':obj, 'namespace':ospace,
247 'ismagic':ismagic, 'isalias':isalias, 'parent':parent}
242 'ismagic':ismagic, 'isalias':isalias, 'parent':parent}
248
243
249 def arg_err(self,func):
244 def arg_err(self,func):
250 """Print docstring if incorrect arguments were passed"""
245 """Print docstring if incorrect arguments were passed"""
251 print 'Error in arguments:'
246 print 'Error in arguments:'
252 print OInspect.getdoc(func)
247 print OInspect.getdoc(func)
253
248
254 def format_latex(self,strng):
249 def format_latex(self,strng):
255 """Format a string for latex inclusion."""
250 """Format a string for latex inclusion."""
256
251
257 # Characters that need to be escaped for latex:
252 # Characters that need to be escaped for latex:
258 escape_re = re.compile(r'(%|_|\$|#|&)',re.MULTILINE)
253 escape_re = re.compile(r'(%|_|\$|#|&)',re.MULTILINE)
259 # Magic command names as headers:
254 # Magic command names as headers:
260 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
255 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
261 re.MULTILINE)
256 re.MULTILINE)
262 # Magic commands
257 # Magic commands
263 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
258 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
264 re.MULTILINE)
259 re.MULTILINE)
265 # Paragraph continue
260 # Paragraph continue
266 par_re = re.compile(r'\\$',re.MULTILINE)
261 par_re = re.compile(r'\\$',re.MULTILINE)
267
262
268 # The "\n" symbol
263 # The "\n" symbol
269 newline_re = re.compile(r'\\n')
264 newline_re = re.compile(r'\\n')
270
265
271 # Now build the string for output:
266 # Now build the string for output:
272 #strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
267 #strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
273 strng = cmd_name_re.sub(r'\n\\bigskip\n\\texttt{\\textbf{ \1}}:',
268 strng = cmd_name_re.sub(r'\n\\bigskip\n\\texttt{\\textbf{ \1}}:',
274 strng)
269 strng)
275 strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng)
270 strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng)
276 strng = par_re.sub(r'\\\\',strng)
271 strng = par_re.sub(r'\\\\',strng)
277 strng = escape_re.sub(r'\\\1',strng)
272 strng = escape_re.sub(r'\\\1',strng)
278 strng = newline_re.sub(r'\\textbackslash{}n',strng)
273 strng = newline_re.sub(r'\\textbackslash{}n',strng)
279 return strng
274 return strng
280
275
281 def format_screen(self,strng):
276 def format_screen(self,strng):
282 """Format a string for screen printing.
277 """Format a string for screen printing.
283
278
284 This removes some latex-type format codes."""
279 This removes some latex-type format codes."""
285 # Paragraph continue
280 # Paragraph continue
286 par_re = re.compile(r'\\$',re.MULTILINE)
281 par_re = re.compile(r'\\$',re.MULTILINE)
287 strng = par_re.sub('',strng)
282 strng = par_re.sub('',strng)
288 return strng
283 return strng
289
284
290 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
285 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
291 """Parse options passed to an argument string.
286 """Parse options passed to an argument string.
292
287
293 The interface is similar to that of getopt(), but it returns back a
288 The interface is similar to that of getopt(), but it returns back a
294 Struct with the options as keys and the stripped argument string still
289 Struct with the options as keys and the stripped argument string still
295 as a string.
290 as a string.
296
291
297 arg_str is quoted as a true sys.argv vector by using shlex.split.
292 arg_str is quoted as a true sys.argv vector by using shlex.split.
298 This allows us to easily expand variables, glob files, quote
293 This allows us to easily expand variables, glob files, quote
299 arguments, etc.
294 arguments, etc.
300
295
301 Options:
296 Options:
302 -mode: default 'string'. If given as 'list', the argument string is
297 -mode: default 'string'. If given as 'list', the argument string is
303 returned as a list (split on whitespace) instead of a string.
298 returned as a list (split on whitespace) instead of a string.
304
299
305 -list_all: put all option values in lists. Normally only options
300 -list_all: put all option values in lists. Normally only options
306 appearing more than once are put in a list.
301 appearing more than once are put in a list.
307
302
308 -posix (True): whether to split the input line in POSIX mode or not,
303 -posix (True): whether to split the input line in POSIX mode or not,
309 as per the conventions outlined in the shlex module from the
304 as per the conventions outlined in the shlex module from the
310 standard library."""
305 standard library."""
311
306
312 # inject default options at the beginning of the input line
307 # inject default options at the beginning of the input line
313 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
308 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
314 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
309 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
315
310
316 mode = kw.get('mode','string')
311 mode = kw.get('mode','string')
317 if mode not in ['string','list']:
312 if mode not in ['string','list']:
318 raise ValueError,'incorrect mode given: %s' % mode
313 raise ValueError,'incorrect mode given: %s' % mode
319 # Get options
314 # Get options
320 list_all = kw.get('list_all',0)
315 list_all = kw.get('list_all',0)
321 posix = kw.get('posix',True)
316 posix = kw.get('posix',True)
322
317
323 # Check if we have more than one argument to warrant extra processing:
318 # Check if we have more than one argument to warrant extra processing:
324 odict = {} # Dictionary with options
319 odict = {} # Dictionary with options
325 args = arg_str.split()
320 args = arg_str.split()
326 if len(args) >= 1:
321 if len(args) >= 1:
327 # If the list of inputs only has 0 or 1 thing in it, there's no
322 # If the list of inputs only has 0 or 1 thing in it, there's no
328 # need to look for options
323 # need to look for options
329 argv = arg_split(arg_str,posix)
324 argv = arg_split(arg_str,posix)
330 # Do regular option processing
325 # Do regular option processing
331 try:
326 try:
332 opts,args = getopt(argv,opt_str,*long_opts)
327 opts,args = getopt(argv,opt_str,*long_opts)
333 except GetoptError,e:
328 except GetoptError,e:
334 raise GetoptError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
329 raise GetoptError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
335 " ".join(long_opts)))
330 " ".join(long_opts)))
336 for o,a in opts:
331 for o,a in opts:
337 if o.startswith('--'):
332 if o.startswith('--'):
338 o = o[2:]
333 o = o[2:]
339 else:
334 else:
340 o = o[1:]
335 o = o[1:]
341 try:
336 try:
342 odict[o].append(a)
337 odict[o].append(a)
343 except AttributeError:
338 except AttributeError:
344 odict[o] = [odict[o],a]
339 odict[o] = [odict[o],a]
345 except KeyError:
340 except KeyError:
346 if list_all:
341 if list_all:
347 odict[o] = [a]
342 odict[o] = [a]
348 else:
343 else:
349 odict[o] = a
344 odict[o] = a
350
345
351 # Prepare opts,args for return
346 # Prepare opts,args for return
352 opts = Struct(odict)
347 opts = Struct(odict)
353 if mode == 'string':
348 if mode == 'string':
354 args = ' '.join(args)
349 args = ' '.join(args)
355
350
356 return opts,args
351 return opts,args
357
352
358 #......................................................................
353 #......................................................................
359 # And now the actual magic functions
354 # And now the actual magic functions
360
355
361 # Functions for IPython shell work (vars,funcs, config, etc)
356 # Functions for IPython shell work (vars,funcs, config, etc)
362 def magic_lsmagic(self, parameter_s = ''):
357 def magic_lsmagic(self, parameter_s = ''):
363 """List currently available magic functions."""
358 """List currently available magic functions."""
364 mesc = self.shell.ESC_MAGIC
359 mesc = self.shell.ESC_MAGIC
365 print 'Available magic functions:\n'+mesc+\
360 print 'Available magic functions:\n'+mesc+\
366 (' '+mesc).join(self.lsmagic())
361 (' '+mesc).join(self.lsmagic())
367 print '\n' + Magic.auto_status[self.shell.rc.automagic]
362 print '\n' + Magic.auto_status[self.shell.rc.automagic]
368 return None
363 return None
369
364
370 def magic_magic(self, parameter_s = ''):
365 def magic_magic(self, parameter_s = ''):
371 """Print information about the magic function system."""
366 """Print information about the magic function system."""
372
367
373 mode = ''
368 mode = ''
374 try:
369 try:
375 if parameter_s.split()[0] == '-latex':
370 if parameter_s.split()[0] == '-latex':
376 mode = 'latex'
371 mode = 'latex'
377 if parameter_s.split()[0] == '-brief':
372 if parameter_s.split()[0] == '-brief':
378 mode = 'brief'
373 mode = 'brief'
379 except:
374 except:
380 pass
375 pass
381
376
382 magic_docs = []
377 magic_docs = []
383 for fname in self.lsmagic():
378 for fname in self.lsmagic():
384 mname = 'magic_' + fname
379 mname = 'magic_' + fname
385 for space in (Magic,self,self.__class__):
380 for space in (Magic,self,self.__class__):
386 try:
381 try:
387 fn = space.__dict__[mname]
382 fn = space.__dict__[mname]
388 except KeyError:
383 except KeyError:
389 pass
384 pass
390 else:
385 else:
391 break
386 break
392 if mode == 'brief':
387 if mode == 'brief':
393 # only first line
388 # only first line
394 fndoc = fn.__doc__.split('\n',1)[0]
389 fndoc = fn.__doc__.split('\n',1)[0]
395 else:
390 else:
396 fndoc = fn.__doc__
391 fndoc = fn.__doc__
397
392
398 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
393 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
399 fname,fndoc))
394 fname,fndoc))
400 magic_docs = ''.join(magic_docs)
395 magic_docs = ''.join(magic_docs)
401
396
402 if mode == 'latex':
397 if mode == 'latex':
403 print self.format_latex(magic_docs)
398 print self.format_latex(magic_docs)
404 return
399 return
405 else:
400 else:
406 magic_docs = self.format_screen(magic_docs)
401 magic_docs = self.format_screen(magic_docs)
407 if mode == 'brief':
402 if mode == 'brief':
408 return magic_docs
403 return magic_docs
409
404
410 outmsg = """
405 outmsg = """
411 IPython's 'magic' functions
406 IPython's 'magic' functions
412 ===========================
407 ===========================
413
408
414 The magic function system provides a series of functions which allow you to
409 The magic function system provides a series of functions which allow you to
415 control the behavior of IPython itself, plus a lot of system-type
410 control the behavior of IPython itself, plus a lot of system-type
416 features. All these functions are prefixed with a % character, but parameters
411 features. All these functions are prefixed with a % character, but parameters
417 are given without parentheses or quotes.
412 are given without parentheses or quotes.
418
413
419 NOTE: If you have 'automagic' enabled (via the command line option or with the
414 NOTE: If you have 'automagic' enabled (via the command line option or with the
420 %automagic function), you don't need to type in the % explicitly. By default,
415 %automagic function), you don't need to type in the % explicitly. By default,
421 IPython ships with automagic on, so you should only rarely need the % escape.
416 IPython ships with automagic on, so you should only rarely need the % escape.
422
417
423 Example: typing '%cd mydir' (without the quotes) changes you working directory
418 Example: typing '%cd mydir' (without the quotes) changes you working directory
424 to 'mydir', if it exists.
419 to 'mydir', if it exists.
425
420
426 You can define your own magic functions to extend the system. See the supplied
421 You can define your own magic functions to extend the system. See the supplied
427 ipythonrc and example-magic.py files for details (in your ipython
422 ipythonrc and example-magic.py files for details (in your ipython
428 configuration directory, typically $HOME/.ipython/).
423 configuration directory, typically $HOME/.ipython/).
429
424
430 You can also define your own aliased names for magic functions. In your
425 You can also define your own aliased names for magic functions. In your
431 ipythonrc file, placing a line like:
426 ipythonrc file, placing a line like:
432
427
433 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
428 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
434
429
435 will define %pf as a new name for %profile.
430 will define %pf as a new name for %profile.
436
431
437 You can also call magics in code using the ipmagic() function, which IPython
432 You can also call magics in code using the ipmagic() function, which IPython
438 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
433 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
439
434
440 For a list of the available magic functions, use %lsmagic. For a description
435 For a list of the available magic functions, use %lsmagic. For a description
441 of any of them, type %magic_name?, e.g. '%cd?'.
436 of any of them, type %magic_name?, e.g. '%cd?'.
442
437
443 Currently the magic system has the following functions:\n"""
438 Currently the magic system has the following functions:\n"""
444
439
445 mesc = self.shell.ESC_MAGIC
440 mesc = self.shell.ESC_MAGIC
446 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
441 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
447 "\n\n%s%s\n\n%s" % (outmsg,
442 "\n\n%s%s\n\n%s" % (outmsg,
448 magic_docs,mesc,mesc,
443 magic_docs,mesc,mesc,
449 (' '+mesc).join(self.lsmagic()),
444 (' '+mesc).join(self.lsmagic()),
450 Magic.auto_status[self.shell.rc.automagic] ) )
445 Magic.auto_status[self.shell.rc.automagic] ) )
451
446
452 page(outmsg,screen_lines=self.shell.rc.screen_length)
447 page(outmsg,screen_lines=self.shell.rc.screen_length)
453
448
454 def magic_automagic(self, parameter_s = ''):
449 def magic_automagic(self, parameter_s = ''):
455 """Make magic functions callable without having to type the initial %.
450 """Make magic functions callable without having to type the initial %.
456
451
457 Toggles on/off (when off, you must call it as %automagic, of
452 Toggles on/off (when off, you must call it as %automagic, of
458 course). Note that magic functions have lowest priority, so if there's
453 course). Note that magic functions have lowest priority, so if there's
459 a variable whose name collides with that of a magic fn, automagic
454 a variable whose name collides with that of a magic fn, automagic
460 won't work for that function (you get the variable instead). However,
455 won't work for that function (you get the variable instead). However,
461 if you delete the variable (del var), the previously shadowed magic
456 if you delete the variable (del var), the previously shadowed magic
462 function becomes visible to automagic again."""
457 function becomes visible to automagic again."""
463
458
464 rc = self.shell.rc
459 rc = self.shell.rc
465 rc.automagic = not rc.automagic
460 rc.automagic = not rc.automagic
466 print '\n' + Magic.auto_status[rc.automagic]
461 print '\n' + Magic.auto_status[rc.automagic]
467
462
468 def magic_autocall(self, parameter_s = ''):
463 def magic_autocall(self, parameter_s = ''):
469 """Make functions callable without having to type parentheses.
464 """Make functions callable without having to type parentheses.
470
465
471 Usage:
466 Usage:
472
467
473 %autocall [mode]
468 %autocall [mode]
474
469
475 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
470 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
476 value is toggled on and off (remembering the previous state)."""
471 value is toggled on and off (remembering the previous state)."""
477
472
478 rc = self.shell.rc
473 rc = self.shell.rc
479
474
480 if parameter_s:
475 if parameter_s:
481 arg = int(parameter_s)
476 arg = int(parameter_s)
482 else:
477 else:
483 arg = 'toggle'
478 arg = 'toggle'
484
479
485 if not arg in (0,1,2,'toggle'):
480 if not arg in (0,1,2,'toggle'):
486 error('Valid modes: (0->Off, 1->Smart, 2->Full')
481 error('Valid modes: (0->Off, 1->Smart, 2->Full')
487 return
482 return
488
483
489 if arg in (0,1,2):
484 if arg in (0,1,2):
490 rc.autocall = arg
485 rc.autocall = arg
491 else: # toggle
486 else: # toggle
492 if rc.autocall:
487 if rc.autocall:
493 self._magic_state.autocall_save = rc.autocall
488 self._magic_state.autocall_save = rc.autocall
494 rc.autocall = 0
489 rc.autocall = 0
495 else:
490 else:
496 try:
491 try:
497 rc.autocall = self._magic_state.autocall_save
492 rc.autocall = self._magic_state.autocall_save
498 except AttributeError:
493 except AttributeError:
499 rc.autocall = self._magic_state.autocall_save = 1
494 rc.autocall = self._magic_state.autocall_save = 1
500
495
501 print "Automatic calling is:",['OFF','Smart','Full'][rc.autocall]
496 print "Automatic calling is:",['OFF','Smart','Full'][rc.autocall]
502
497
503 def magic_autoindent(self, parameter_s = ''):
498 def magic_autoindent(self, parameter_s = ''):
504 """Toggle autoindent on/off (if available)."""
499 """Toggle autoindent on/off (if available)."""
505
500
506 self.shell.set_autoindent()
501 self.shell.set_autoindent()
507 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
502 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
508
503
509 def magic_system_verbose(self, parameter_s = ''):
504 def magic_system_verbose(self, parameter_s = ''):
510 """Set verbose printing of system calls.
505 """Set verbose printing of system calls.
511
506
512 If called without an argument, act as a toggle"""
507 If called without an argument, act as a toggle"""
513
508
514 if parameter_s:
509 if parameter_s:
515 val = bool(eval(parameter_s))
510 val = bool(eval(parameter_s))
516 else:
511 else:
517 val = None
512 val = None
518
513
519 self.shell.rc_set_toggle('system_verbose',val)
514 self.shell.rc_set_toggle('system_verbose',val)
520 print "System verbose printing is:",\
515 print "System verbose printing is:",\
521 ['OFF','ON'][self.shell.rc.system_verbose]
516 ['OFF','ON'][self.shell.rc.system_verbose]
522
517
523 def magic_history(self, parameter_s = ''):
518 def magic_history(self, parameter_s = ''):
524 """Print input history (_i<n> variables), with most recent last.
519 """Print input history (_i<n> variables), with most recent last.
525
520
526 %history -> print at most 40 inputs (some may be multi-line)\\
521 %history -> print at most 40 inputs (some may be multi-line)\\
527 %history n -> print at most n inputs\\
522 %history n -> print at most n inputs\\
528 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
523 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
529
524
530 Each input's number <n> is shown, and is accessible as the
525 Each input's number <n> is shown, and is accessible as the
531 automatically generated variable _i<n>. Multi-line statements are
526 automatically generated variable _i<n>. Multi-line statements are
532 printed starting at a new line for easy copy/paste.
527 printed starting at a new line for easy copy/paste.
533
528
534
529
535 Options:
530 Options:
536
531
537 -n: do NOT print line numbers. This is useful if you want to get a
532 -n: do NOT print line numbers. This is useful if you want to get a
538 printout of many lines which can be directly pasted into a text
533 printout of many lines which can be directly pasted into a text
539 editor.
534 editor.
540
535
541 This feature is only available if numbered prompts are in use.
536 This feature is only available if numbered prompts are in use.
542
537
543 -r: print the 'raw' history. IPython filters your input and
538 -r: print the 'raw' history. IPython filters your input and
544 converts it all into valid Python source before executing it (things
539 converts it all into valid Python source before executing it (things
545 like magics or aliases are turned into function calls, for
540 like magics or aliases are turned into function calls, for
546 example). With this option, you'll see the unfiltered history
541 example). With this option, you'll see the unfiltered history
547 instead of the filtered version: '%cd /' will be seen as '%cd /'
542 instead of the filtered version: '%cd /' will be seen as '%cd /'
548 instead of '_ip.magic("%cd /")'.
543 instead of '_ip.magic("%cd /")'.
549 """
544 """
550
545
551 shell = self.shell
546 shell = self.shell
552 if not shell.outputcache.do_full_cache:
547 if not shell.outputcache.do_full_cache:
553 print 'This feature is only available if numbered prompts are in use.'
548 print 'This feature is only available if numbered prompts are in use.'
554 return
549 return
555 opts,args = self.parse_options(parameter_s,'nr',mode='list')
550 opts,args = self.parse_options(parameter_s,'nr',mode='list')
556
551
557 if opts.has_key('r'):
552 if opts.has_key('r'):
558 input_hist = shell.input_hist_raw
553 input_hist = shell.input_hist_raw
559 else:
554 else:
560 input_hist = shell.input_hist
555 input_hist = shell.input_hist
561
556
562 default_length = 40
557 default_length = 40
563 if len(args) == 0:
558 if len(args) == 0:
564 final = len(input_hist)
559 final = len(input_hist)
565 init = max(1,final-default_length)
560 init = max(1,final-default_length)
566 elif len(args) == 1:
561 elif len(args) == 1:
567 final = len(input_hist)
562 final = len(input_hist)
568 init = max(1,final-int(args[0]))
563 init = max(1,final-int(args[0]))
569 elif len(args) == 2:
564 elif len(args) == 2:
570 init,final = map(int,args)
565 init,final = map(int,args)
571 else:
566 else:
572 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
567 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
573 print self.magic_hist.__doc__
568 print self.magic_hist.__doc__
574 return
569 return
575 width = len(str(final))
570 width = len(str(final))
576 line_sep = ['','\n']
571 line_sep = ['','\n']
577 print_nums = not opts.has_key('n')
572 print_nums = not opts.has_key('n')
578 for in_num in range(init,final):
573 for in_num in range(init,final):
579 inline = input_hist[in_num]
574 inline = input_hist[in_num]
580 multiline = int(inline.count('\n') > 1)
575 multiline = int(inline.count('\n') > 1)
581 if print_nums:
576 if print_nums:
582 print '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]),
577 print '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]),
583 print inline,
578 print inline,
584
579
585 def magic_hist(self, parameter_s=''):
580 def magic_hist(self, parameter_s=''):
586 """Alternate name for %history."""
581 """Alternate name for %history."""
587 return self.magic_history(parameter_s)
582 return self.magic_history(parameter_s)
588
583
589 def magic_p(self, parameter_s=''):
584 def magic_p(self, parameter_s=''):
590 """Just a short alias for Python's 'print'."""
585 """Just a short alias for Python's 'print'."""
591 exec 'print ' + parameter_s in self.shell.user_ns
586 exec 'print ' + parameter_s in self.shell.user_ns
592
587
593 def magic_r(self, parameter_s=''):
588 def magic_r(self, parameter_s=''):
594 """Repeat previous input.
589 """Repeat previous input.
595
590
596 If given an argument, repeats the previous command which starts with
591 If given an argument, repeats the previous command which starts with
597 the same string, otherwise it just repeats the previous input.
592 the same string, otherwise it just repeats the previous input.
598
593
599 Shell escaped commands (with ! as first character) are not recognized
594 Shell escaped commands (with ! as first character) are not recognized
600 by this system, only pure python code and magic commands.
595 by this system, only pure python code and magic commands.
601 """
596 """
602
597
603 start = parameter_s.strip()
598 start = parameter_s.strip()
604 esc_magic = self.shell.ESC_MAGIC
599 esc_magic = self.shell.ESC_MAGIC
605 # Identify magic commands even if automagic is on (which means
600 # Identify magic commands even if automagic is on (which means
606 # the in-memory version is different from that typed by the user).
601 # the in-memory version is different from that typed by the user).
607 if self.shell.rc.automagic:
602 if self.shell.rc.automagic:
608 start_magic = esc_magic+start
603 start_magic = esc_magic+start
609 else:
604 else:
610 start_magic = start
605 start_magic = start
611 # Look through the input history in reverse
606 # Look through the input history in reverse
612 for n in range(len(self.shell.input_hist)-2,0,-1):
607 for n in range(len(self.shell.input_hist)-2,0,-1):
613 input = self.shell.input_hist[n]
608 input = self.shell.input_hist[n]
614 # skip plain 'r' lines so we don't recurse to infinity
609 # skip plain 'r' lines so we don't recurse to infinity
615 if input != '_ip.magic("r")\n' and \
610 if input != '_ip.magic("r")\n' and \
616 (input.startswith(start) or input.startswith(start_magic)):
611 (input.startswith(start) or input.startswith(start_magic)):
617 #print 'match',`input` # dbg
612 #print 'match',`input` # dbg
618 print 'Executing:',input,
613 print 'Executing:',input,
619 self.shell.runlines(input)
614 self.shell.runlines(input)
620 return
615 return
621 print 'No previous input matching `%s` found.' % start
616 print 'No previous input matching `%s` found.' % start
622
617
623 def magic_page(self, parameter_s=''):
618 def magic_page(self, parameter_s=''):
624 """Pretty print the object and display it through a pager.
619 """Pretty print the object and display it through a pager.
625
620
626 %page [options] OBJECT
621 %page [options] OBJECT
627
622
628 If no object is given, use _ (last output).
623 If no object is given, use _ (last output).
629
624
630 Options:
625 Options:
631
626
632 -r: page str(object), don't pretty-print it."""
627 -r: page str(object), don't pretty-print it."""
633
628
634 # After a function contributed by Olivier Aubert, slightly modified.
629 # After a function contributed by Olivier Aubert, slightly modified.
635
630
636 # Process options/args
631 # Process options/args
637 opts,args = self.parse_options(parameter_s,'r')
632 opts,args = self.parse_options(parameter_s,'r')
638 raw = 'r' in opts
633 raw = 'r' in opts
639
634
640 oname = args and args or '_'
635 oname = args and args or '_'
641 info = self._ofind(oname)
636 info = self._ofind(oname)
642 if info['found']:
637 if info['found']:
643 txt = (raw and str or pformat)( info['obj'] )
638 txt = (raw and str or pformat)( info['obj'] )
644 page(txt)
639 page(txt)
645 else:
640 else:
646 print 'Object `%s` not found' % oname
641 print 'Object `%s` not found' % oname
647
642
648 def magic_profile(self, parameter_s=''):
643 def magic_profile(self, parameter_s=''):
649 """Print your currently active IPyhton profile."""
644 """Print your currently active IPyhton profile."""
650 if self.shell.rc.profile:
645 if self.shell.rc.profile:
651 printpl('Current IPython profile: $self.shell.rc.profile.')
646 printpl('Current IPython profile: $self.shell.rc.profile.')
652 else:
647 else:
653 print 'No profile active.'
648 print 'No profile active.'
654
649
655 def _inspect(self,meth,oname,namespaces=None,**kw):
650 def _inspect(self,meth,oname,namespaces=None,**kw):
656 """Generic interface to the inspector system.
651 """Generic interface to the inspector system.
657
652
658 This function is meant to be called by pdef, pdoc & friends."""
653 This function is meant to be called by pdef, pdoc & friends."""
659
654
660 oname = oname.strip()
655 oname = oname.strip()
661 info = Struct(self._ofind(oname, namespaces))
656 info = Struct(self._ofind(oname, namespaces))
662
657
663 if info.found:
658 if info.found:
664 # Get the docstring of the class property if it exists.
659 # Get the docstring of the class property if it exists.
665 path = oname.split('.')
660 path = oname.split('.')
666 root = '.'.join(path[:-1])
661 root = '.'.join(path[:-1])
667 if info.parent is not None:
662 if info.parent is not None:
668 try:
663 try:
669 target = getattr(info.parent, '__class__')
664 target = getattr(info.parent, '__class__')
670 # The object belongs to a class instance.
665 # The object belongs to a class instance.
671 try:
666 try:
672 target = getattr(target, path[-1])
667 target = getattr(target, path[-1])
673 # The class defines the object.
668 # The class defines the object.
674 if isinstance(target, property):
669 if isinstance(target, property):
675 oname = root + '.__class__.' + path[-1]
670 oname = root + '.__class__.' + path[-1]
676 info = Struct(self._ofind(oname))
671 info = Struct(self._ofind(oname))
677 except AttributeError: pass
672 except AttributeError: pass
678 except AttributeError: pass
673 except AttributeError: pass
679
674
680 pmethod = getattr(self.shell.inspector,meth)
675 pmethod = getattr(self.shell.inspector,meth)
681 formatter = info.ismagic and self.format_screen or None
676 formatter = info.ismagic and self.format_screen or None
682 if meth == 'pdoc':
677 if meth == 'pdoc':
683 pmethod(info.obj,oname,formatter)
678 pmethod(info.obj,oname,formatter)
684 elif meth == 'pinfo':
679 elif meth == 'pinfo':
685 pmethod(info.obj,oname,formatter,info,**kw)
680 pmethod(info.obj,oname,formatter,info,**kw)
686 else:
681 else:
687 pmethod(info.obj,oname)
682 pmethod(info.obj,oname)
688 else:
683 else:
689 print 'Object `%s` not found.' % oname
684 print 'Object `%s` not found.' % oname
690 return 'not found' # so callers can take other action
685 return 'not found' # so callers can take other action
691
686
692 def magic_pdef(self, parameter_s='', namespaces=None):
687 def magic_pdef(self, parameter_s='', namespaces=None):
693 """Print the definition header for any callable object.
688 """Print the definition header for any callable object.
694
689
695 If the object is a class, print the constructor information."""
690 If the object is a class, print the constructor information."""
696 print "+++"
691 print "+++"
697 self._inspect('pdef',parameter_s, namespaces)
692 self._inspect('pdef',parameter_s, namespaces)
698
693
699 def magic_pdoc(self, parameter_s='', namespaces=None):
694 def magic_pdoc(self, parameter_s='', namespaces=None):
700 """Print the docstring for an object.
695 """Print the docstring for an object.
701
696
702 If the given object is a class, it will print both the class and the
697 If the given object is a class, it will print both the class and the
703 constructor docstrings."""
698 constructor docstrings."""
704 self._inspect('pdoc',parameter_s, namespaces)
699 self._inspect('pdoc',parameter_s, namespaces)
705
700
706 def magic_psource(self, parameter_s='', namespaces=None):
701 def magic_psource(self, parameter_s='', namespaces=None):
707 """Print (or run through pager) the source code for an object."""
702 """Print (or run through pager) the source code for an object."""
708 self._inspect('psource',parameter_s, namespaces)
703 self._inspect('psource',parameter_s, namespaces)
709
704
710 def magic_pfile(self, parameter_s=''):
705 def magic_pfile(self, parameter_s=''):
711 """Print (or run through pager) the file where an object is defined.
706 """Print (or run through pager) the file where an object is defined.
712
707
713 The file opens at the line where the object definition begins. IPython
708 The file opens at the line where the object definition begins. IPython
714 will honor the environment variable PAGER if set, and otherwise will
709 will honor the environment variable PAGER if set, and otherwise will
715 do its best to print the file in a convenient form.
710 do its best to print the file in a convenient form.
716
711
717 If the given argument is not an object currently defined, IPython will
712 If the given argument is not an object currently defined, IPython will
718 try to interpret it as a filename (automatically adding a .py extension
713 try to interpret it as a filename (automatically adding a .py extension
719 if needed). You can thus use %pfile as a syntax highlighting code
714 if needed). You can thus use %pfile as a syntax highlighting code
720 viewer."""
715 viewer."""
721
716
722 # first interpret argument as an object name
717 # first interpret argument as an object name
723 out = self._inspect('pfile',parameter_s)
718 out = self._inspect('pfile',parameter_s)
724 # if not, try the input as a filename
719 # if not, try the input as a filename
725 if out == 'not found':
720 if out == 'not found':
726 try:
721 try:
727 filename = get_py_filename(parameter_s)
722 filename = get_py_filename(parameter_s)
728 except IOError,msg:
723 except IOError,msg:
729 print msg
724 print msg
730 return
725 return
731 page(self.shell.inspector.format(file(filename).read()))
726 page(self.shell.inspector.format(file(filename).read()))
732
727
733 def magic_pinfo(self, parameter_s='', namespaces=None):
728 def magic_pinfo(self, parameter_s='', namespaces=None):
734 """Provide detailed information about an object.
729 """Provide detailed information about an object.
735
730
736 '%pinfo object' is just a synonym for object? or ?object."""
731 '%pinfo object' is just a synonym for object? or ?object."""
737
732
738 #print 'pinfo par: <%s>' % parameter_s # dbg
733 #print 'pinfo par: <%s>' % parameter_s # dbg
739
734
740 # detail_level: 0 -> obj? , 1 -> obj??
735 # detail_level: 0 -> obj? , 1 -> obj??
741 detail_level = 0
736 detail_level = 0
742 # We need to detect if we got called as 'pinfo pinfo foo', which can
737 # We need to detect if we got called as 'pinfo pinfo foo', which can
743 # happen if the user types 'pinfo foo?' at the cmd line.
738 # happen if the user types 'pinfo foo?' at the cmd line.
744 pinfo,qmark1,oname,qmark2 = \
739 pinfo,qmark1,oname,qmark2 = \
745 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
740 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
746 if pinfo or qmark1 or qmark2:
741 if pinfo or qmark1 or qmark2:
747 detail_level = 1
742 detail_level = 1
748 if "*" in oname:
743 if "*" in oname:
749 self.magic_psearch(oname)
744 self.magic_psearch(oname)
750 else:
745 else:
751 self._inspect('pinfo', oname, detail_level=detail_level,
746 self._inspect('pinfo', oname, detail_level=detail_level,
752 namespaces=namespaces)
747 namespaces=namespaces)
753
748
754 def magic_psearch(self, parameter_s=''):
749 def magic_psearch(self, parameter_s=''):
755 """Search for object in namespaces by wildcard.
750 """Search for object in namespaces by wildcard.
756
751
757 %psearch [options] PATTERN [OBJECT TYPE]
752 %psearch [options] PATTERN [OBJECT TYPE]
758
753
759 Note: ? can be used as a synonym for %psearch, at the beginning or at
754 Note: ? can be used as a synonym for %psearch, at the beginning or at
760 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
755 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
761 rest of the command line must be unchanged (options come first), so
756 rest of the command line must be unchanged (options come first), so
762 for example the following forms are equivalent
757 for example the following forms are equivalent
763
758
764 %psearch -i a* function
759 %psearch -i a* function
765 -i a* function?
760 -i a* function?
766 ?-i a* function
761 ?-i a* function
767
762
768 Arguments:
763 Arguments:
769
764
770 PATTERN
765 PATTERN
771
766
772 where PATTERN is a string containing * as a wildcard similar to its
767 where PATTERN is a string containing * as a wildcard similar to its
773 use in a shell. The pattern is matched in all namespaces on the
768 use in a shell. The pattern is matched in all namespaces on the
774 search path. By default objects starting with a single _ are not
769 search path. By default objects starting with a single _ are not
775 matched, many IPython generated objects have a single
770 matched, many IPython generated objects have a single
776 underscore. The default is case insensitive matching. Matching is
771 underscore. The default is case insensitive matching. Matching is
777 also done on the attributes of objects and not only on the objects
772 also done on the attributes of objects and not only on the objects
778 in a module.
773 in a module.
779
774
780 [OBJECT TYPE]
775 [OBJECT TYPE]
781
776
782 Is the name of a python type from the types module. The name is
777 Is the name of a python type from the types module. The name is
783 given in lowercase without the ending type, ex. StringType is
778 given in lowercase without the ending type, ex. StringType is
784 written string. By adding a type here only objects matching the
779 written string. By adding a type here only objects matching the
785 given type are matched. Using all here makes the pattern match all
780 given type are matched. Using all here makes the pattern match all
786 types (this is the default).
781 types (this is the default).
787
782
788 Options:
783 Options:
789
784
790 -a: makes the pattern match even objects whose names start with a
785 -a: makes the pattern match even objects whose names start with a
791 single underscore. These names are normally ommitted from the
786 single underscore. These names are normally ommitted from the
792 search.
787 search.
793
788
794 -i/-c: make the pattern case insensitive/sensitive. If neither of
789 -i/-c: make the pattern case insensitive/sensitive. If neither of
795 these options is given, the default is read from your ipythonrc
790 these options is given, the default is read from your ipythonrc
796 file. The option name which sets this value is
791 file. The option name which sets this value is
797 'wildcards_case_sensitive'. If this option is not specified in your
792 'wildcards_case_sensitive'. If this option is not specified in your
798 ipythonrc file, IPython's internal default is to do a case sensitive
793 ipythonrc file, IPython's internal default is to do a case sensitive
799 search.
794 search.
800
795
801 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
796 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
802 specifiy can be searched in any of the following namespaces:
797 specifiy can be searched in any of the following namespaces:
803 'builtin', 'user', 'user_global','internal', 'alias', where
798 'builtin', 'user', 'user_global','internal', 'alias', where
804 'builtin' and 'user' are the search defaults. Note that you should
799 'builtin' and 'user' are the search defaults. Note that you should
805 not use quotes when specifying namespaces.
800 not use quotes when specifying namespaces.
806
801
807 'Builtin' contains the python module builtin, 'user' contains all
802 'Builtin' contains the python module builtin, 'user' contains all
808 user data, 'alias' only contain the shell aliases and no python
803 user data, 'alias' only contain the shell aliases and no python
809 objects, 'internal' contains objects used by IPython. The
804 objects, 'internal' contains objects used by IPython. The
810 'user_global' namespace is only used by embedded IPython instances,
805 'user_global' namespace is only used by embedded IPython instances,
811 and it contains module-level globals. You can add namespaces to the
806 and it contains module-level globals. You can add namespaces to the
812 search with -s or exclude them with -e (these options can be given
807 search with -s or exclude them with -e (these options can be given
813 more than once).
808 more than once).
814
809
815 Examples:
810 Examples:
816
811
817 %psearch a* -> objects beginning with an a
812 %psearch a* -> objects beginning with an a
818 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
813 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
819 %psearch a* function -> all functions beginning with an a
814 %psearch a* function -> all functions beginning with an a
820 %psearch re.e* -> objects beginning with an e in module re
815 %psearch re.e* -> objects beginning with an e in module re
821 %psearch r*.e* -> objects that start with e in modules starting in r
816 %psearch r*.e* -> objects that start with e in modules starting in r
822 %psearch r*.* string -> all strings in modules beginning with r
817 %psearch r*.* string -> all strings in modules beginning with r
823
818
824 Case sensitve search:
819 Case sensitve search:
825
820
826 %psearch -c a* list all object beginning with lower case a
821 %psearch -c a* list all object beginning with lower case a
827
822
828 Show objects beginning with a single _:
823 Show objects beginning with a single _:
829
824
830 %psearch -a _* list objects beginning with a single underscore"""
825 %psearch -a _* list objects beginning with a single underscore"""
831
826
832 # default namespaces to be searched
827 # default namespaces to be searched
833 def_search = ['user','builtin']
828 def_search = ['user','builtin']
834
829
835 # Process options/args
830 # Process options/args
836 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
831 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
837 opt = opts.get
832 opt = opts.get
838 shell = self.shell
833 shell = self.shell
839 psearch = shell.inspector.psearch
834 psearch = shell.inspector.psearch
840
835
841 # select case options
836 # select case options
842 if opts.has_key('i'):
837 if opts.has_key('i'):
843 ignore_case = True
838 ignore_case = True
844 elif opts.has_key('c'):
839 elif opts.has_key('c'):
845 ignore_case = False
840 ignore_case = False
846 else:
841 else:
847 ignore_case = not shell.rc.wildcards_case_sensitive
842 ignore_case = not shell.rc.wildcards_case_sensitive
848
843
849 # Build list of namespaces to search from user options
844 # Build list of namespaces to search from user options
850 def_search.extend(opt('s',[]))
845 def_search.extend(opt('s',[]))
851 ns_exclude = ns_exclude=opt('e',[])
846 ns_exclude = ns_exclude=opt('e',[])
852 ns_search = [nm for nm in def_search if nm not in ns_exclude]
847 ns_search = [nm for nm in def_search if nm not in ns_exclude]
853
848
854 # Call the actual search
849 # Call the actual search
855 try:
850 try:
856 psearch(args,shell.ns_table,ns_search,
851 psearch(args,shell.ns_table,ns_search,
857 show_all=opt('a'),ignore_case=ignore_case)
852 show_all=opt('a'),ignore_case=ignore_case)
858 except:
853 except:
859 shell.showtraceback()
854 shell.showtraceback()
860
855
861 def magic_who_ls(self, parameter_s=''):
856 def magic_who_ls(self, parameter_s=''):
862 """Return a sorted list of all interactive variables.
857 """Return a sorted list of all interactive variables.
863
858
864 If arguments are given, only variables of types matching these
859 If arguments are given, only variables of types matching these
865 arguments are returned."""
860 arguments are returned."""
866
861
867 user_ns = self.shell.user_ns
862 user_ns = self.shell.user_ns
868 internal_ns = self.shell.internal_ns
863 internal_ns = self.shell.internal_ns
869 user_config_ns = self.shell.user_config_ns
864 user_config_ns = self.shell.user_config_ns
870 out = []
865 out = []
871 typelist = parameter_s.split()
866 typelist = parameter_s.split()
872
867
873 for i in user_ns:
868 for i in user_ns:
874 if not (i.startswith('_') or i.startswith('_i')) \
869 if not (i.startswith('_') or i.startswith('_i')) \
875 and not (i in internal_ns or i in user_config_ns):
870 and not (i in internal_ns or i in user_config_ns):
876 if typelist:
871 if typelist:
877 if type(user_ns[i]).__name__ in typelist:
872 if type(user_ns[i]).__name__ in typelist:
878 out.append(i)
873 out.append(i)
879 else:
874 else:
880 out.append(i)
875 out.append(i)
881 out.sort()
876 out.sort()
882 return out
877 return out
883
878
884 def magic_who(self, parameter_s=''):
879 def magic_who(self, parameter_s=''):
885 """Print all interactive variables, with some minimal formatting.
880 """Print all interactive variables, with some minimal formatting.
886
881
887 If any arguments are given, only variables whose type matches one of
882 If any arguments are given, only variables whose type matches one of
888 these are printed. For example:
883 these are printed. For example:
889
884
890 %who function str
885 %who function str
891
886
892 will only list functions and strings, excluding all other types of
887 will only list functions and strings, excluding all other types of
893 variables. To find the proper type names, simply use type(var) at a
888 variables. To find the proper type names, simply use type(var) at a
894 command line to see how python prints type names. For example:
889 command line to see how python prints type names. For example:
895
890
896 In [1]: type('hello')\\
891 In [1]: type('hello')\\
897 Out[1]: <type 'str'>
892 Out[1]: <type 'str'>
898
893
899 indicates that the type name for strings is 'str'.
894 indicates that the type name for strings is 'str'.
900
895
901 %who always excludes executed names loaded through your configuration
896 %who always excludes executed names loaded through your configuration
902 file and things which are internal to IPython.
897 file and things which are internal to IPython.
903
898
904 This is deliberate, as typically you may load many modules and the
899 This is deliberate, as typically you may load many modules and the
905 purpose of %who is to show you only what you've manually defined."""
900 purpose of %who is to show you only what you've manually defined."""
906
901
907 varlist = self.magic_who_ls(parameter_s)
902 varlist = self.magic_who_ls(parameter_s)
908 if not varlist:
903 if not varlist:
909 print 'Interactive namespace is empty.'
904 print 'Interactive namespace is empty.'
910 return
905 return
911
906
912 # if we have variables, move on...
907 # if we have variables, move on...
913
908
914 # stupid flushing problem: when prompts have no separators, stdout is
909 # stupid flushing problem: when prompts have no separators, stdout is
915 # getting lost. I'm starting to think this is a python bug. I'm having
910 # getting lost. I'm starting to think this is a python bug. I'm having
916 # to force a flush with a print because even a sys.stdout.flush
911 # to force a flush with a print because even a sys.stdout.flush
917 # doesn't seem to do anything!
912 # doesn't seem to do anything!
918
913
919 count = 0
914 count = 0
920 for i in varlist:
915 for i in varlist:
921 print i+'\t',
916 print i+'\t',
922 count += 1
917 count += 1
923 if count > 8:
918 if count > 8:
924 count = 0
919 count = 0
925 print
920 print
926 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
921 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
927
922
928 print # well, this does force a flush at the expense of an extra \n
923 print # well, this does force a flush at the expense of an extra \n
929
924
930 def magic_whos(self, parameter_s=''):
925 def magic_whos(self, parameter_s=''):
931 """Like %who, but gives some extra information about each variable.
926 """Like %who, but gives some extra information about each variable.
932
927
933 The same type filtering of %who can be applied here.
928 The same type filtering of %who can be applied here.
934
929
935 For all variables, the type is printed. Additionally it prints:
930 For all variables, the type is printed. Additionally it prints:
936
931
937 - For {},[],(): their length.
932 - For {},[],(): their length.
938
933
939 - For Numeric arrays, a summary with shape, number of elements,
934 - For Numeric arrays, a summary with shape, number of elements,
940 typecode and size in memory.
935 typecode and size in memory.
941
936
942 - Everything else: a string representation, snipping their middle if
937 - Everything else: a string representation, snipping their middle if
943 too long."""
938 too long."""
944
939
945 varnames = self.magic_who_ls(parameter_s)
940 varnames = self.magic_who_ls(parameter_s)
946 if not varnames:
941 if not varnames:
947 print 'Interactive namespace is empty.'
942 print 'Interactive namespace is empty.'
948 return
943 return
949
944
950 # if we have variables, move on...
945 # if we have variables, move on...
951
946
952 # for these types, show len() instead of data:
947 # for these types, show len() instead of data:
953 seq_types = [types.DictType,types.ListType,types.TupleType]
948 seq_types = [types.DictType,types.ListType,types.TupleType]
954
949
955 # for Numeric arrays, display summary info
950 # for Numeric arrays, display summary info
956 try:
951 try:
957 import Numeric
952 import Numeric
958 except ImportError:
953 except ImportError:
959 array_type = None
954 array_type = None
960 else:
955 else:
961 array_type = Numeric.ArrayType.__name__
956 array_type = Numeric.ArrayType.__name__
962
957
963 # Find all variable names and types so we can figure out column sizes
958 # Find all variable names and types so we can figure out column sizes
964 get_vars = lambda i: self.shell.user_ns[i]
959 get_vars = lambda i: self.shell.user_ns[i]
965 type_name = lambda v: type(v).__name__
960 type_name = lambda v: type(v).__name__
966 varlist = map(get_vars,varnames)
961 varlist = map(get_vars,varnames)
967
962
968 typelist = []
963 typelist = []
969 for vv in varlist:
964 for vv in varlist:
970 tt = type_name(vv)
965 tt = type_name(vv)
971 if tt=='instance':
966 if tt=='instance':
972 typelist.append(str(vv.__class__))
967 typelist.append(str(vv.__class__))
973 else:
968 else:
974 typelist.append(tt)
969 typelist.append(tt)
975
970
976 # column labels and # of spaces as separator
971 # column labels and # of spaces as separator
977 varlabel = 'Variable'
972 varlabel = 'Variable'
978 typelabel = 'Type'
973 typelabel = 'Type'
979 datalabel = 'Data/Info'
974 datalabel = 'Data/Info'
980 colsep = 3
975 colsep = 3
981 # variable format strings
976 # variable format strings
982 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
977 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
983 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
978 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
984 aformat = "%s: %s elems, type `%s`, %s bytes"
979 aformat = "%s: %s elems, type `%s`, %s bytes"
985 # find the size of the columns to format the output nicely
980 # find the size of the columns to format the output nicely
986 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
981 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
987 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
982 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
988 # table header
983 # table header
989 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
984 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
990 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
985 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
991 # and the table itself
986 # and the table itself
992 kb = 1024
987 kb = 1024
993 Mb = 1048576 # kb**2
988 Mb = 1048576 # kb**2
994 for vname,var,vtype in zip(varnames,varlist,typelist):
989 for vname,var,vtype in zip(varnames,varlist,typelist):
995 print itpl(vformat),
990 print itpl(vformat),
996 if vtype in seq_types:
991 if vtype in seq_types:
997 print len(var)
992 print len(var)
998 elif vtype==array_type:
993 elif vtype==array_type:
999 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
994 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
1000 vsize = Numeric.size(var)
995 vsize = Numeric.size(var)
1001 vbytes = vsize*var.itemsize()
996 vbytes = vsize*var.itemsize()
1002 if vbytes < 100000:
997 if vbytes < 100000:
1003 print aformat % (vshape,vsize,var.typecode(),vbytes)
998 print aformat % (vshape,vsize,var.typecode(),vbytes)
1004 else:
999 else:
1005 print aformat % (vshape,vsize,var.typecode(),vbytes),
1000 print aformat % (vshape,vsize,var.typecode(),vbytes),
1006 if vbytes < Mb:
1001 if vbytes < Mb:
1007 print '(%s kb)' % (vbytes/kb,)
1002 print '(%s kb)' % (vbytes/kb,)
1008 else:
1003 else:
1009 print '(%s Mb)' % (vbytes/Mb,)
1004 print '(%s Mb)' % (vbytes/Mb,)
1010 else:
1005 else:
1011 vstr = str(var).replace('\n','\\n')
1006 vstr = str(var).replace('\n','\\n')
1012 if len(vstr) < 50:
1007 if len(vstr) < 50:
1013 print vstr
1008 print vstr
1014 else:
1009 else:
1015 printpl(vfmt_short)
1010 printpl(vfmt_short)
1016
1011
1017 def magic_reset(self, parameter_s=''):
1012 def magic_reset(self, parameter_s=''):
1018 """Resets the namespace by removing all names defined by the user.
1013 """Resets the namespace by removing all names defined by the user.
1019
1014
1020 Input/Output history are left around in case you need them."""
1015 Input/Output history are left around in case you need them."""
1021
1016
1022 ans = self.shell.ask_yes_no(
1017 ans = self.shell.ask_yes_no(
1023 "Once deleted, variables cannot be recovered. Proceed (y/[n])? ")
1018 "Once deleted, variables cannot be recovered. Proceed (y/[n])? ")
1024 if not ans:
1019 if not ans:
1025 print 'Nothing done.'
1020 print 'Nothing done.'
1026 return
1021 return
1027 user_ns = self.shell.user_ns
1022 user_ns = self.shell.user_ns
1028 for i in self.magic_who_ls():
1023 for i in self.magic_who_ls():
1029 del(user_ns[i])
1024 del(user_ns[i])
1030
1025
1031 def magic_config(self,parameter_s=''):
1026 def magic_config(self,parameter_s=''):
1032 """Handle IPython's internal configuration.
1027 """Handle IPython's internal configuration.
1033
1028
1034 If called without arguments, it will print IPython's complete internal
1029 If called without arguments, it will print IPython's complete internal
1035 configuration.
1030 configuration.
1036
1031
1037 If called with one argument, it will print the value of that key in
1032 If called with one argument, it will print the value of that key in
1038 the configuration.
1033 the configuration.
1039
1034
1040 If called with more than one argument, the first is interpreted as a
1035 If called with more than one argument, the first is interpreted as a
1041 key and the rest as a Python expression which gets eval()'d.
1036 key and the rest as a Python expression which gets eval()'d.
1042
1037
1043 Examples:
1038 Examples:
1044
1039
1045 In [1]: s='A Python string'
1040 In [1]: s='A Python string'
1046
1041
1047 In [2]: !echo $s
1042 In [2]: !echo $s
1048 A Python string
1043 A Python string
1049
1044
1050 In [3]: config system_verbose True
1045 In [3]: config system_verbose True
1051
1046
1052 In [4]: !echo $s
1047 In [4]: !echo $s
1053 IPython system call: echo A Python string
1048 IPython system call: echo A Python string
1054 A Python string
1049 A Python string
1055
1050
1056 In [5]: %config system_header 'sys> '
1051 In [5]: %config system_header 'sys> '
1057
1052
1058 In [6]: !echo $s
1053 In [6]: !echo $s
1059 sys> echo A Python string
1054 sys> echo A Python string
1060 A Python string
1055 A Python string
1061
1056
1062 # Notice the extra quotes to protect the string after interpolation:
1057 # Notice the extra quotes to protect the string after interpolation:
1063 In [7]: header = "'sys2> '"
1058 In [7]: header = "'sys2> '"
1064
1059
1065 In [8]: %config system_header $header
1060 In [8]: %config system_header $header
1066
1061
1067 In [9]: !echo $s
1062 In [9]: !echo $s
1068 sys2> echo A Python string
1063 sys2> echo A Python string
1069 A Python string
1064 A Python string
1070 """
1065 """
1071
1066
1072 args = parameter_s.split(None,1)
1067 args = parameter_s.split(None,1)
1073 key = args[0]
1068 key = args[0]
1074 if len(args)==1:
1069 if len(args)==1:
1075 self.shell.ipconfig(key)
1070 self.shell.ipconfig(key)
1076 else:
1071 else:
1077 self.shell.ipconfig(key,eval(args[1]))
1072 self.shell.ipconfig(key,eval(args[1]))
1078
1073
1079 def magic_logstart(self,parameter_s=''):
1074 def magic_logstart(self,parameter_s=''):
1080 """Start logging anywhere in a session.
1075 """Start logging anywhere in a session.
1081
1076
1082 %logstart [-o|-r|-t] [log_name [log_mode]]
1077 %logstart [-o|-r|-t] [log_name [log_mode]]
1083
1078
1084 If no name is given, it defaults to a file named 'ipython_log.py' in your
1079 If no name is given, it defaults to a file named 'ipython_log.py' in your
1085 current directory, in 'rotate' mode (see below).
1080 current directory, in 'rotate' mode (see below).
1086
1081
1087 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
1082 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
1088 history up to that point and then continues logging.
1083 history up to that point and then continues logging.
1089
1084
1090 %logstart takes a second optional parameter: logging mode. This can be one
1085 %logstart takes a second optional parameter: logging mode. This can be one
1091 of (note that the modes are given unquoted):\\
1086 of (note that the modes are given unquoted):\\
1092 append: well, that says it.\\
1087 append: well, that says it.\\
1093 backup: rename (if exists) to name~ and start name.\\
1088 backup: rename (if exists) to name~ and start name.\\
1094 global: single logfile in your home dir, appended to.\\
1089 global: single logfile in your home dir, appended to.\\
1095 over : overwrite existing log.\\
1090 over : overwrite existing log.\\
1096 rotate: create rotating logs name.1~, name.2~, etc.
1091 rotate: create rotating logs name.1~, name.2~, etc.
1097
1092
1098 Options:
1093 Options:
1099
1094
1100 -o: log also IPython's output. In this mode, all commands which
1095 -o: log also IPython's output. In this mode, all commands which
1101 generate an Out[NN] prompt are recorded to the logfile, right after
1096 generate an Out[NN] prompt are recorded to the logfile, right after
1102 their corresponding input line. The output lines are always
1097 their corresponding input line. The output lines are always
1103 prepended with a '#[Out]# ' marker, so that the log remains valid
1098 prepended with a '#[Out]# ' marker, so that the log remains valid
1104 Python code.
1099 Python code.
1105
1100
1106 Since this marker is always the same, filtering only the output from
1101 Since this marker is always the same, filtering only the output from
1107 a log is very easy, using for example a simple awk call:
1102 a log is very easy, using for example a simple awk call:
1108
1103
1109 awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py
1104 awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py
1110
1105
1111 -r: log 'raw' input. Normally, IPython's logs contain the processed
1106 -r: log 'raw' input. Normally, IPython's logs contain the processed
1112 input, so that user lines are logged in their final form, converted
1107 input, so that user lines are logged in their final form, converted
1113 into valid Python. For example, %Exit is logged as
1108 into valid Python. For example, %Exit is logged as
1114 '_ip.magic("Exit"). If the -r flag is given, all input is logged
1109 '_ip.magic("Exit"). If the -r flag is given, all input is logged
1115 exactly as typed, with no transformations applied.
1110 exactly as typed, with no transformations applied.
1116
1111
1117 -t: put timestamps before each input line logged (these are put in
1112 -t: put timestamps before each input line logged (these are put in
1118 comments)."""
1113 comments)."""
1119
1114
1120 opts,par = self.parse_options(parameter_s,'ort')
1115 opts,par = self.parse_options(parameter_s,'ort')
1121 log_output = 'o' in opts
1116 log_output = 'o' in opts
1122 log_raw_input = 'r' in opts
1117 log_raw_input = 'r' in opts
1123 timestamp = 't' in opts
1118 timestamp = 't' in opts
1124
1119
1125 rc = self.shell.rc
1120 rc = self.shell.rc
1126 logger = self.shell.logger
1121 logger = self.shell.logger
1127
1122
1128 # if no args are given, the defaults set in the logger constructor by
1123 # if no args are given, the defaults set in the logger constructor by
1129 # ipytohn remain valid
1124 # ipytohn remain valid
1130 if par:
1125 if par:
1131 try:
1126 try:
1132 logfname,logmode = par.split()
1127 logfname,logmode = par.split()
1133 except:
1128 except:
1134 logfname = par
1129 logfname = par
1135 logmode = 'backup'
1130 logmode = 'backup'
1136 else:
1131 else:
1137 logfname = logger.logfname
1132 logfname = logger.logfname
1138 logmode = logger.logmode
1133 logmode = logger.logmode
1139 # put logfname into rc struct as if it had been called on the command
1134 # put logfname into rc struct as if it had been called on the command
1140 # line, so it ends up saved in the log header Save it in case we need
1135 # line, so it ends up saved in the log header Save it in case we need
1141 # to restore it...
1136 # to restore it...
1142 old_logfile = rc.opts.get('logfile','')
1137 old_logfile = rc.opts.get('logfile','')
1143 if logfname:
1138 if logfname:
1144 logfname = os.path.expanduser(logfname)
1139 logfname = os.path.expanduser(logfname)
1145 rc.opts.logfile = logfname
1140 rc.opts.logfile = logfname
1146 loghead = self.shell.loghead_tpl % (rc.opts,rc.args)
1141 loghead = self.shell.loghead_tpl % (rc.opts,rc.args)
1147 try:
1142 try:
1148 started = logger.logstart(logfname,loghead,logmode,
1143 started = logger.logstart(logfname,loghead,logmode,
1149 log_output,timestamp,log_raw_input)
1144 log_output,timestamp,log_raw_input)
1150 except:
1145 except:
1151 rc.opts.logfile = old_logfile
1146 rc.opts.logfile = old_logfile
1152 warn("Couldn't start log: %s" % sys.exc_info()[1])
1147 warn("Couldn't start log: %s" % sys.exc_info()[1])
1153 else:
1148 else:
1154 # log input history up to this point, optionally interleaving
1149 # log input history up to this point, optionally interleaving
1155 # output if requested
1150 # output if requested
1156
1151
1157 if timestamp:
1152 if timestamp:
1158 # disable timestamping for the previous history, since we've
1153 # disable timestamping for the previous history, since we've
1159 # lost those already (no time machine here).
1154 # lost those already (no time machine here).
1160 logger.timestamp = False
1155 logger.timestamp = False
1161
1156
1162 if log_raw_input:
1157 if log_raw_input:
1163 input_hist = self.shell.input_hist_raw
1158 input_hist = self.shell.input_hist_raw
1164 else:
1159 else:
1165 input_hist = self.shell.input_hist
1160 input_hist = self.shell.input_hist
1166
1161
1167 if log_output:
1162 if log_output:
1168 log_write = logger.log_write
1163 log_write = logger.log_write
1169 output_hist = self.shell.output_hist
1164 output_hist = self.shell.output_hist
1170 for n in range(1,len(input_hist)-1):
1165 for n in range(1,len(input_hist)-1):
1171 log_write(input_hist[n].rstrip())
1166 log_write(input_hist[n].rstrip())
1172 if n in output_hist:
1167 if n in output_hist:
1173 log_write(repr(output_hist[n]),'output')
1168 log_write(repr(output_hist[n]),'output')
1174 else:
1169 else:
1175 logger.log_write(input_hist[1:])
1170 logger.log_write(input_hist[1:])
1176 if timestamp:
1171 if timestamp:
1177 # re-enable timestamping
1172 # re-enable timestamping
1178 logger.timestamp = True
1173 logger.timestamp = True
1179
1174
1180 print ('Activating auto-logging. '
1175 print ('Activating auto-logging. '
1181 'Current session state plus future input saved.')
1176 'Current session state plus future input saved.')
1182 logger.logstate()
1177 logger.logstate()
1183
1178
1184 def magic_logoff(self,parameter_s=''):
1179 def magic_logoff(self,parameter_s=''):
1185 """Temporarily stop logging.
1180 """Temporarily stop logging.
1186
1181
1187 You must have previously started logging."""
1182 You must have previously started logging."""
1188 self.shell.logger.switch_log(0)
1183 self.shell.logger.switch_log(0)
1189
1184
1190 def magic_logon(self,parameter_s=''):
1185 def magic_logon(self,parameter_s=''):
1191 """Restart logging.
1186 """Restart logging.
1192
1187
1193 This function is for restarting logging which you've temporarily
1188 This function is for restarting logging which you've temporarily
1194 stopped with %logoff. For starting logging for the first time, you
1189 stopped with %logoff. For starting logging for the first time, you
1195 must use the %logstart function, which allows you to specify an
1190 must use the %logstart function, which allows you to specify an
1196 optional log filename."""
1191 optional log filename."""
1197
1192
1198 self.shell.logger.switch_log(1)
1193 self.shell.logger.switch_log(1)
1199
1194
1200 def magic_logstate(self,parameter_s=''):
1195 def magic_logstate(self,parameter_s=''):
1201 """Print the status of the logging system."""
1196 """Print the status of the logging system."""
1202
1197
1203 self.shell.logger.logstate()
1198 self.shell.logger.logstate()
1204
1199
1205 def magic_pdb(self, parameter_s=''):
1200 def magic_pdb(self, parameter_s=''):
1206 """Control the calling of the pdb interactive debugger.
1201 """Control the calling of the pdb interactive debugger.
1207
1202
1208 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1203 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1209 argument it works as a toggle.
1204 argument it works as a toggle.
1210
1205
1211 When an exception is triggered, IPython can optionally call the
1206 When an exception is triggered, IPython can optionally call the
1212 interactive pdb debugger after the traceback printout. %pdb toggles
1207 interactive pdb debugger after the traceback printout. %pdb toggles
1213 this feature on and off."""
1208 this feature on and off."""
1214
1209
1215 par = parameter_s.strip().lower()
1210 par = parameter_s.strip().lower()
1216
1211
1217 if par:
1212 if par:
1218 try:
1213 try:
1219 new_pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1214 new_pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1220 except KeyError:
1215 except KeyError:
1221 print ('Incorrect argument. Use on/1, off/0, '
1216 print ('Incorrect argument. Use on/1, off/0, '
1222 'or nothing for a toggle.')
1217 'or nothing for a toggle.')
1223 return
1218 return
1224 else:
1219 else:
1225 # toggle
1220 # toggle
1226 new_pdb = not self.shell.InteractiveTB.call_pdb
1221 new_pdb = not self.shell.InteractiveTB.call_pdb
1227
1222
1228 # set on the shell
1223 # set on the shell
1229 self.shell.call_pdb = new_pdb
1224 self.shell.call_pdb = new_pdb
1230 print 'Automatic pdb calling has been turned',on_off(new_pdb)
1225 print 'Automatic pdb calling has been turned',on_off(new_pdb)
1231
1226
1232 def magic_prun(self, parameter_s ='',user_mode=1,
1227 def magic_prun(self, parameter_s ='',user_mode=1,
1233 opts=None,arg_lst=None,prog_ns=None):
1228 opts=None,arg_lst=None,prog_ns=None):
1234
1229
1235 """Run a statement through the python code profiler.
1230 """Run a statement through the python code profiler.
1236
1231
1237 Usage:\\
1232 Usage:\\
1238 %prun [options] statement
1233 %prun [options] statement
1239
1234
1240 The given statement (which doesn't require quote marks) is run via the
1235 The given statement (which doesn't require quote marks) is run via the
1241 python profiler in a manner similar to the profile.run() function.
1236 python profiler in a manner similar to the profile.run() function.
1242 Namespaces are internally managed to work correctly; profile.run
1237 Namespaces are internally managed to work correctly; profile.run
1243 cannot be used in IPython because it makes certain assumptions about
1238 cannot be used in IPython because it makes certain assumptions about
1244 namespaces which do not hold under IPython.
1239 namespaces which do not hold under IPython.
1245
1240
1246 Options:
1241 Options:
1247
1242
1248 -l <limit>: you can place restrictions on what or how much of the
1243 -l <limit>: you can place restrictions on what or how much of the
1249 profile gets printed. The limit value can be:
1244 profile gets printed. The limit value can be:
1250
1245
1251 * A string: only information for function names containing this string
1246 * A string: only information for function names containing this string
1252 is printed.
1247 is printed.
1253
1248
1254 * An integer: only these many lines are printed.
1249 * An integer: only these many lines are printed.
1255
1250
1256 * A float (between 0 and 1): this fraction of the report is printed
1251 * A float (between 0 and 1): this fraction of the report is printed
1257 (for example, use a limit of 0.4 to see the topmost 40% only).
1252 (for example, use a limit of 0.4 to see the topmost 40% only).
1258
1253
1259 You can combine several limits with repeated use of the option. For
1254 You can combine several limits with repeated use of the option. For
1260 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1255 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1261 information about class constructors.
1256 information about class constructors.
1262
1257
1263 -r: return the pstats.Stats object generated by the profiling. This
1258 -r: return the pstats.Stats object generated by the profiling. This
1264 object has all the information about the profile in it, and you can
1259 object has all the information about the profile in it, and you can
1265 later use it for further analysis or in other functions.
1260 later use it for further analysis or in other functions.
1266
1261
1267 -s <key>: sort profile by given key. You can provide more than one key
1262 -s <key>: sort profile by given key. You can provide more than one key
1268 by using the option several times: '-s key1 -s key2 -s key3...'. The
1263 by using the option several times: '-s key1 -s key2 -s key3...'. The
1269 default sorting key is 'time'.
1264 default sorting key is 'time'.
1270
1265
1271 The following is copied verbatim from the profile documentation
1266 The following is copied verbatim from the profile documentation
1272 referenced below:
1267 referenced below:
1273
1268
1274 When more than one key is provided, additional keys are used as
1269 When more than one key is provided, additional keys are used as
1275 secondary criteria when the there is equality in all keys selected
1270 secondary criteria when the there is equality in all keys selected
1276 before them.
1271 before them.
1277
1272
1278 Abbreviations can be used for any key names, as long as the
1273 Abbreviations can be used for any key names, as long as the
1279 abbreviation is unambiguous. The following are the keys currently
1274 abbreviation is unambiguous. The following are the keys currently
1280 defined:
1275 defined:
1281
1276
1282 Valid Arg Meaning\\
1277 Valid Arg Meaning\\
1283 "calls" call count\\
1278 "calls" call count\\
1284 "cumulative" cumulative time\\
1279 "cumulative" cumulative time\\
1285 "file" file name\\
1280 "file" file name\\
1286 "module" file name\\
1281 "module" file name\\
1287 "pcalls" primitive call count\\
1282 "pcalls" primitive call count\\
1288 "line" line number\\
1283 "line" line number\\
1289 "name" function name\\
1284 "name" function name\\
1290 "nfl" name/file/line\\
1285 "nfl" name/file/line\\
1291 "stdname" standard name\\
1286 "stdname" standard name\\
1292 "time" internal time
1287 "time" internal time
1293
1288
1294 Note that all sorts on statistics are in descending order (placing
1289 Note that all sorts on statistics are in descending order (placing
1295 most time consuming items first), where as name, file, and line number
1290 most time consuming items first), where as name, file, and line number
1296 searches are in ascending order (i.e., alphabetical). The subtle
1291 searches are in ascending order (i.e., alphabetical). The subtle
1297 distinction between "nfl" and "stdname" is that the standard name is a
1292 distinction between "nfl" and "stdname" is that the standard name is a
1298 sort of the name as printed, which means that the embedded line
1293 sort of the name as printed, which means that the embedded line
1299 numbers get compared in an odd way. For example, lines 3, 20, and 40
1294 numbers get compared in an odd way. For example, lines 3, 20, and 40
1300 would (if the file names were the same) appear in the string order
1295 would (if the file names were the same) appear in the string order
1301 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1296 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1302 line numbers. In fact, sort_stats("nfl") is the same as
1297 line numbers. In fact, sort_stats("nfl") is the same as
1303 sort_stats("name", "file", "line").
1298 sort_stats("name", "file", "line").
1304
1299
1305 -T <filename>: save profile results as shown on screen to a text
1300 -T <filename>: save profile results as shown on screen to a text
1306 file. The profile is still shown on screen.
1301 file. The profile is still shown on screen.
1307
1302
1308 -D <filename>: save (via dump_stats) profile statistics to given
1303 -D <filename>: save (via dump_stats) profile statistics to given
1309 filename. This data is in a format understod by the pstats module, and
1304 filename. This data is in a format understod by the pstats module, and
1310 is generated by a call to the dump_stats() method of profile
1305 is generated by a call to the dump_stats() method of profile
1311 objects. The profile is still shown on screen.
1306 objects. The profile is still shown on screen.
1312
1307
1313 If you want to run complete programs under the profiler's control, use
1308 If you want to run complete programs under the profiler's control, use
1314 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1309 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1315 contains profiler specific options as described here.
1310 contains profiler specific options as described here.
1316
1311
1317 You can read the complete documentation for the profile module with:\\
1312 You can read the complete documentation for the profile module with:\\
1318 In [1]: import profile; profile.help() """
1313 In [1]: import profile; profile.help() """
1319
1314
1320 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1315 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1321 # protect user quote marks
1316 # protect user quote marks
1322 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1317 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1323
1318
1324 if user_mode: # regular user call
1319 if user_mode: # regular user call
1325 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1320 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1326 list_all=1)
1321 list_all=1)
1327 namespace = self.shell.user_ns
1322 namespace = self.shell.user_ns
1328 else: # called to run a program by %run -p
1323 else: # called to run a program by %run -p
1329 try:
1324 try:
1330 filename = get_py_filename(arg_lst[0])
1325 filename = get_py_filename(arg_lst[0])
1331 except IOError,msg:
1326 except IOError,msg:
1332 error(msg)
1327 error(msg)
1333 return
1328 return
1334
1329
1335 arg_str = 'execfile(filename,prog_ns)'
1330 arg_str = 'execfile(filename,prog_ns)'
1336 namespace = locals()
1331 namespace = locals()
1337
1332
1338 opts.merge(opts_def)
1333 opts.merge(opts_def)
1339
1334
1340 prof = profile.Profile()
1335 prof = profile.Profile()
1341 try:
1336 try:
1342 prof = prof.runctx(arg_str,namespace,namespace)
1337 prof = prof.runctx(arg_str,namespace,namespace)
1343 sys_exit = ''
1338 sys_exit = ''
1344 except SystemExit:
1339 except SystemExit:
1345 sys_exit = """*** SystemExit exception caught in code being profiled."""
1340 sys_exit = """*** SystemExit exception caught in code being profiled."""
1346
1341
1347 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1342 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1348
1343
1349 lims = opts.l
1344 lims = opts.l
1350 if lims:
1345 if lims:
1351 lims = [] # rebuild lims with ints/floats/strings
1346 lims = [] # rebuild lims with ints/floats/strings
1352 for lim in opts.l:
1347 for lim in opts.l:
1353 try:
1348 try:
1354 lims.append(int(lim))
1349 lims.append(int(lim))
1355 except ValueError:
1350 except ValueError:
1356 try:
1351 try:
1357 lims.append(float(lim))
1352 lims.append(float(lim))
1358 except ValueError:
1353 except ValueError:
1359 lims.append(lim)
1354 lims.append(lim)
1360
1355
1361 # trap output
1356 # trap output
1362 sys_stdout = sys.stdout
1357 sys_stdout = sys.stdout
1363 stdout_trap = StringIO()
1358 stdout_trap = StringIO()
1364 try:
1359 try:
1365 sys.stdout = stdout_trap
1360 sys.stdout = stdout_trap
1366 stats.print_stats(*lims)
1361 stats.print_stats(*lims)
1367 finally:
1362 finally:
1368 sys.stdout = sys_stdout
1363 sys.stdout = sys_stdout
1369 output = stdout_trap.getvalue()
1364 output = stdout_trap.getvalue()
1370 output = output.rstrip()
1365 output = output.rstrip()
1371
1366
1372 page(output,screen_lines=self.shell.rc.screen_length)
1367 page(output,screen_lines=self.shell.rc.screen_length)
1373 print sys_exit,
1368 print sys_exit,
1374
1369
1375 dump_file = opts.D[0]
1370 dump_file = opts.D[0]
1376 text_file = opts.T[0]
1371 text_file = opts.T[0]
1377 if dump_file:
1372 if dump_file:
1378 prof.dump_stats(dump_file)
1373 prof.dump_stats(dump_file)
1379 print '\n*** Profile stats marshalled to file',\
1374 print '\n*** Profile stats marshalled to file',\
1380 `dump_file`+'.',sys_exit
1375 `dump_file`+'.',sys_exit
1381 if text_file:
1376 if text_file:
1382 file(text_file,'w').write(output)
1377 file(text_file,'w').write(output)
1383 print '\n*** Profile printout saved to text file',\
1378 print '\n*** Profile printout saved to text file',\
1384 `text_file`+'.',sys_exit
1379 `text_file`+'.',sys_exit
1385
1380
1386 if opts.has_key('r'):
1381 if opts.has_key('r'):
1387 return stats
1382 return stats
1388 else:
1383 else:
1389 return None
1384 return None
1390
1385
1391 def magic_run(self, parameter_s ='',runner=None):
1386 def magic_run(self, parameter_s ='',runner=None):
1392 """Run the named file inside IPython as a program.
1387 """Run the named file inside IPython as a program.
1393
1388
1394 Usage:\\
1389 Usage:\\
1395 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1390 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1396
1391
1397 Parameters after the filename are passed as command-line arguments to
1392 Parameters after the filename are passed as command-line arguments to
1398 the program (put in sys.argv). Then, control returns to IPython's
1393 the program (put in sys.argv). Then, control returns to IPython's
1399 prompt.
1394 prompt.
1400
1395
1401 This is similar to running at a system prompt:\\
1396 This is similar to running at a system prompt:\\
1402 $ python file args\\
1397 $ python file args\\
1403 but with the advantage of giving you IPython's tracebacks, and of
1398 but with the advantage of giving you IPython's tracebacks, and of
1404 loading all variables into your interactive namespace for further use
1399 loading all variables into your interactive namespace for further use
1405 (unless -p is used, see below).
1400 (unless -p is used, see below).
1406
1401
1407 The file is executed in a namespace initially consisting only of
1402 The file is executed in a namespace initially consisting only of
1408 __name__=='__main__' and sys.argv constructed as indicated. It thus
1403 __name__=='__main__' and sys.argv constructed as indicated. It thus
1409 sees its environment as if it were being run as a stand-alone
1404 sees its environment as if it were being run as a stand-alone
1410 program. But after execution, the IPython interactive namespace gets
1405 program. But after execution, the IPython interactive namespace gets
1411 updated with all variables defined in the program (except for __name__
1406 updated with all variables defined in the program (except for __name__
1412 and sys.argv). This allows for very convenient loading of code for
1407 and sys.argv). This allows for very convenient loading of code for
1413 interactive work, while giving each program a 'clean sheet' to run in.
1408 interactive work, while giving each program a 'clean sheet' to run in.
1414
1409
1415 Options:
1410 Options:
1416
1411
1417 -n: __name__ is NOT set to '__main__', but to the running file's name
1412 -n: __name__ is NOT set to '__main__', but to the running file's name
1418 without extension (as python does under import). This allows running
1413 without extension (as python does under import). This allows running
1419 scripts and reloading the definitions in them without calling code
1414 scripts and reloading the definitions in them without calling code
1420 protected by an ' if __name__ == "__main__" ' clause.
1415 protected by an ' if __name__ == "__main__" ' clause.
1421
1416
1422 -i: run the file in IPython's namespace instead of an empty one. This
1417 -i: run the file in IPython's namespace instead of an empty one. This
1423 is useful if you are experimenting with code written in a text editor
1418 is useful if you are experimenting with code written in a text editor
1424 which depends on variables defined interactively.
1419 which depends on variables defined interactively.
1425
1420
1426 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1421 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1427 being run. This is particularly useful if IPython is being used to
1422 being run. This is particularly useful if IPython is being used to
1428 run unittests, which always exit with a sys.exit() call. In such
1423 run unittests, which always exit with a sys.exit() call. In such
1429 cases you are interested in the output of the test results, not in
1424 cases you are interested in the output of the test results, not in
1430 seeing a traceback of the unittest module.
1425 seeing a traceback of the unittest module.
1431
1426
1432 -t: print timing information at the end of the run. IPython will give
1427 -t: print timing information at the end of the run. IPython will give
1433 you an estimated CPU time consumption for your script, which under
1428 you an estimated CPU time consumption for your script, which under
1434 Unix uses the resource module to avoid the wraparound problems of
1429 Unix uses the resource module to avoid the wraparound problems of
1435 time.clock(). Under Unix, an estimate of time spent on system tasks
1430 time.clock(). Under Unix, an estimate of time spent on system tasks
1436 is also given (for Windows platforms this is reported as 0.0).
1431 is also given (for Windows platforms this is reported as 0.0).
1437
1432
1438 If -t is given, an additional -N<N> option can be given, where <N>
1433 If -t is given, an additional -N<N> option can be given, where <N>
1439 must be an integer indicating how many times you want the script to
1434 must be an integer indicating how many times you want the script to
1440 run. The final timing report will include total and per run results.
1435 run. The final timing report will include total and per run results.
1441
1436
1442 For example (testing the script uniq_stable.py):
1437 For example (testing the script uniq_stable.py):
1443
1438
1444 In [1]: run -t uniq_stable
1439 In [1]: run -t uniq_stable
1445
1440
1446 IPython CPU timings (estimated):\\
1441 IPython CPU timings (estimated):\\
1447 User : 0.19597 s.\\
1442 User : 0.19597 s.\\
1448 System: 0.0 s.\\
1443 System: 0.0 s.\\
1449
1444
1450 In [2]: run -t -N5 uniq_stable
1445 In [2]: run -t -N5 uniq_stable
1451
1446
1452 IPython CPU timings (estimated):\\
1447 IPython CPU timings (estimated):\\
1453 Total runs performed: 5\\
1448 Total runs performed: 5\\
1454 Times : Total Per run\\
1449 Times : Total Per run\\
1455 User : 0.910862 s, 0.1821724 s.\\
1450 User : 0.910862 s, 0.1821724 s.\\
1456 System: 0.0 s, 0.0 s.
1451 System: 0.0 s, 0.0 s.
1457
1452
1458 -d: run your program under the control of pdb, the Python debugger.
1453 -d: run your program under the control of pdb, the Python debugger.
1459 This allows you to execute your program step by step, watch variables,
1454 This allows you to execute your program step by step, watch variables,
1460 etc. Internally, what IPython does is similar to calling:
1455 etc. Internally, what IPython does is similar to calling:
1461
1456
1462 pdb.run('execfile("YOURFILENAME")')
1457 pdb.run('execfile("YOURFILENAME")')
1463
1458
1464 with a breakpoint set on line 1 of your file. You can change the line
1459 with a breakpoint set on line 1 of your file. You can change the line
1465 number for this automatic breakpoint to be <N> by using the -bN option
1460 number for this automatic breakpoint to be <N> by using the -bN option
1466 (where N must be an integer). For example:
1461 (where N must be an integer). For example:
1467
1462
1468 %run -d -b40 myscript
1463 %run -d -b40 myscript
1469
1464
1470 will set the first breakpoint at line 40 in myscript.py. Note that
1465 will set the first breakpoint at line 40 in myscript.py. Note that
1471 the first breakpoint must be set on a line which actually does
1466 the first breakpoint must be set on a line which actually does
1472 something (not a comment or docstring) for it to stop execution.
1467 something (not a comment or docstring) for it to stop execution.
1473
1468
1474 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1469 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1475 first enter 'c' (without qoutes) to start execution up to the first
1470 first enter 'c' (without qoutes) to start execution up to the first
1476 breakpoint.
1471 breakpoint.
1477
1472
1478 Entering 'help' gives information about the use of the debugger. You
1473 Entering 'help' gives information about the use of the debugger. You
1479 can easily see pdb's full documentation with "import pdb;pdb.help()"
1474 can easily see pdb's full documentation with "import pdb;pdb.help()"
1480 at a prompt.
1475 at a prompt.
1481
1476
1482 -p: run program under the control of the Python profiler module (which
1477 -p: run program under the control of the Python profiler module (which
1483 prints a detailed report of execution times, function calls, etc).
1478 prints a detailed report of execution times, function calls, etc).
1484
1479
1485 You can pass other options after -p which affect the behavior of the
1480 You can pass other options after -p which affect the behavior of the
1486 profiler itself. See the docs for %prun for details.
1481 profiler itself. See the docs for %prun for details.
1487
1482
1488 In this mode, the program's variables do NOT propagate back to the
1483 In this mode, the program's variables do NOT propagate back to the
1489 IPython interactive namespace (because they remain in the namespace
1484 IPython interactive namespace (because they remain in the namespace
1490 where the profiler executes them).
1485 where the profiler executes them).
1491
1486
1492 Internally this triggers a call to %prun, see its documentation for
1487 Internally this triggers a call to %prun, see its documentation for
1493 details on the options available specifically for profiling."""
1488 details on the options available specifically for profiling."""
1494
1489
1495 # get arguments and set sys.argv for program to be run.
1490 # get arguments and set sys.argv for program to be run.
1496 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1491 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1497 mode='list',list_all=1)
1492 mode='list',list_all=1)
1498
1493
1499 try:
1494 try:
1500 filename = get_py_filename(arg_lst[0])
1495 filename = get_py_filename(arg_lst[0])
1501 except IndexError:
1496 except IndexError:
1502 warn('you must provide at least a filename.')
1497 warn('you must provide at least a filename.')
1503 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1498 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1504 return
1499 return
1505 except IOError,msg:
1500 except IOError,msg:
1506 error(msg)
1501 error(msg)
1507 return
1502 return
1508
1503
1509 # Control the response to exit() calls made by the script being run
1504 # Control the response to exit() calls made by the script being run
1510 exit_ignore = opts.has_key('e')
1505 exit_ignore = opts.has_key('e')
1511
1506
1512 # Make sure that the running script gets a proper sys.argv as if it
1507 # Make sure that the running script gets a proper sys.argv as if it
1513 # were run from a system shell.
1508 # were run from a system shell.
1514 save_argv = sys.argv # save it for later restoring
1509 save_argv = sys.argv # save it for later restoring
1515 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1510 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1516
1511
1517 if opts.has_key('i'):
1512 if opts.has_key('i'):
1518 prog_ns = self.shell.user_ns
1513 prog_ns = self.shell.user_ns
1519 __name__save = self.shell.user_ns['__name__']
1514 __name__save = self.shell.user_ns['__name__']
1520 prog_ns['__name__'] = '__main__'
1515 prog_ns['__name__'] = '__main__'
1521 else:
1516 else:
1522 if opts.has_key('n'):
1517 if opts.has_key('n'):
1523 name = os.path.splitext(os.path.basename(filename))[0]
1518 name = os.path.splitext(os.path.basename(filename))[0]
1524 else:
1519 else:
1525 name = '__main__'
1520 name = '__main__'
1526 prog_ns = {'__name__':name}
1521 prog_ns = {'__name__':name}
1527
1522
1528 # Since '%run foo' emulates 'python foo.py' at the cmd line, we must
1523 # Since '%run foo' emulates 'python foo.py' at the cmd line, we must
1529 # set the __file__ global in the script's namespace
1524 # set the __file__ global in the script's namespace
1530 prog_ns['__file__'] = filename
1525 prog_ns['__file__'] = filename
1531
1526
1532 # pickle fix. See iplib for an explanation. But we need to make sure
1527 # pickle fix. See iplib for an explanation. But we need to make sure
1533 # that, if we overwrite __main__, we replace it at the end
1528 # that, if we overwrite __main__, we replace it at the end
1534 if prog_ns['__name__'] == '__main__':
1529 if prog_ns['__name__'] == '__main__':
1535 restore_main = sys.modules['__main__']
1530 restore_main = sys.modules['__main__']
1536 else:
1531 else:
1537 restore_main = False
1532 restore_main = False
1538
1533
1539 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1534 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1540
1535
1541 stats = None
1536 stats = None
1542 try:
1537 try:
1543 if self.shell.has_readline:
1538 if self.shell.has_readline:
1544 self.shell.savehist()
1539 self.shell.savehist()
1545
1540
1546 if opts.has_key('p'):
1541 if opts.has_key('p'):
1547 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1542 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1548 else:
1543 else:
1549 if opts.has_key('d'):
1544 if opts.has_key('d'):
1550 deb = Debugger.Pdb(self.shell.rc.colors)
1545 deb = Debugger.Pdb(self.shell.rc.colors)
1551 # reset Breakpoint state, which is moronically kept
1546 # reset Breakpoint state, which is moronically kept
1552 # in a class
1547 # in a class
1553 bdb.Breakpoint.next = 1
1548 bdb.Breakpoint.next = 1
1554 bdb.Breakpoint.bplist = {}
1549 bdb.Breakpoint.bplist = {}
1555 bdb.Breakpoint.bpbynumber = [None]
1550 bdb.Breakpoint.bpbynumber = [None]
1556 # Set an initial breakpoint to stop execution
1551 # Set an initial breakpoint to stop execution
1557 maxtries = 10
1552 maxtries = 10
1558 bp = int(opts.get('b',[1])[0])
1553 bp = int(opts.get('b',[1])[0])
1559 checkline = deb.checkline(filename,bp)
1554 checkline = deb.checkline(filename,bp)
1560 if not checkline:
1555 if not checkline:
1561 for bp in range(bp+1,bp+maxtries+1):
1556 for bp in range(bp+1,bp+maxtries+1):
1562 if deb.checkline(filename,bp):
1557 if deb.checkline(filename,bp):
1563 break
1558 break
1564 else:
1559 else:
1565 msg = ("\nI failed to find a valid line to set "
1560 msg = ("\nI failed to find a valid line to set "
1566 "a breakpoint\n"
1561 "a breakpoint\n"
1567 "after trying up to line: %s.\n"
1562 "after trying up to line: %s.\n"
1568 "Please set a valid breakpoint manually "
1563 "Please set a valid breakpoint manually "
1569 "with the -b option." % bp)
1564 "with the -b option." % bp)
1570 error(msg)
1565 error(msg)
1571 return
1566 return
1572 # if we find a good linenumber, set the breakpoint
1567 # if we find a good linenumber, set the breakpoint
1573 deb.do_break('%s:%s' % (filename,bp))
1568 deb.do_break('%s:%s' % (filename,bp))
1574 # Start file run
1569 # Start file run
1575 print "NOTE: Enter 'c' at the",
1570 print "NOTE: Enter 'c' at the",
1576 print "%s prompt to start your script." % deb.prompt
1571 print "%s prompt to start your script." % deb.prompt
1577 try:
1572 try:
1578 deb.run('execfile("%s")' % filename,prog_ns)
1573 deb.run('execfile("%s")' % filename,prog_ns)
1579
1574
1580 except:
1575 except:
1581 etype, value, tb = sys.exc_info()
1576 etype, value, tb = sys.exc_info()
1582 # Skip three frames in the traceback: the %run one,
1577 # Skip three frames in the traceback: the %run one,
1583 # one inside bdb.py, and the command-line typed by the
1578 # one inside bdb.py, and the command-line typed by the
1584 # user (run by exec in pdb itself).
1579 # user (run by exec in pdb itself).
1585 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1580 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1586 else:
1581 else:
1587 if runner is None:
1582 if runner is None:
1588 runner = self.shell.safe_execfile
1583 runner = self.shell.safe_execfile
1589 if opts.has_key('t'):
1584 if opts.has_key('t'):
1590 try:
1585 try:
1591 nruns = int(opts['N'][0])
1586 nruns = int(opts['N'][0])
1592 if nruns < 1:
1587 if nruns < 1:
1593 error('Number of runs must be >=1')
1588 error('Number of runs must be >=1')
1594 return
1589 return
1595 except (KeyError):
1590 except (KeyError):
1596 nruns = 1
1591 nruns = 1
1597 if nruns == 1:
1592 if nruns == 1:
1598 t0 = clock2()
1593 t0 = clock2()
1599 runner(filename,prog_ns,prog_ns,
1594 runner(filename,prog_ns,prog_ns,
1600 exit_ignore=exit_ignore)
1595 exit_ignore=exit_ignore)
1601 t1 = clock2()
1596 t1 = clock2()
1602 t_usr = t1[0]-t0[0]
1597 t_usr = t1[0]-t0[0]
1603 t_sys = t1[1]-t1[1]
1598 t_sys = t1[1]-t1[1]
1604 print "\nIPython CPU timings (estimated):"
1599 print "\nIPython CPU timings (estimated):"
1605 print " User : %10s s." % t_usr
1600 print " User : %10s s." % t_usr
1606 print " System: %10s s." % t_sys
1601 print " System: %10s s." % t_sys
1607 else:
1602 else:
1608 runs = range(nruns)
1603 runs = range(nruns)
1609 t0 = clock2()
1604 t0 = clock2()
1610 for nr in runs:
1605 for nr in runs:
1611 runner(filename,prog_ns,prog_ns,
1606 runner(filename,prog_ns,prog_ns,
1612 exit_ignore=exit_ignore)
1607 exit_ignore=exit_ignore)
1613 t1 = clock2()
1608 t1 = clock2()
1614 t_usr = t1[0]-t0[0]
1609 t_usr = t1[0]-t0[0]
1615 t_sys = t1[1]-t1[1]
1610 t_sys = t1[1]-t1[1]
1616 print "\nIPython CPU timings (estimated):"
1611 print "\nIPython CPU timings (estimated):"
1617 print "Total runs performed:",nruns
1612 print "Total runs performed:",nruns
1618 print " Times : %10s %10s" % ('Total','Per run')
1613 print " Times : %10s %10s" % ('Total','Per run')
1619 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1614 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1620 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1615 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1621
1616
1622 else:
1617 else:
1623 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1618 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1624 if opts.has_key('i'):
1619 if opts.has_key('i'):
1625 self.shell.user_ns['__name__'] = __name__save
1620 self.shell.user_ns['__name__'] = __name__save
1626 else:
1621 else:
1627 # update IPython interactive namespace
1622 # update IPython interactive namespace
1628 del prog_ns['__name__']
1623 del prog_ns['__name__']
1629 self.shell.user_ns.update(prog_ns)
1624 self.shell.user_ns.update(prog_ns)
1630 finally:
1625 finally:
1631 sys.argv = save_argv
1626 sys.argv = save_argv
1632 if restore_main:
1627 if restore_main:
1633 sys.modules['__main__'] = restore_main
1628 sys.modules['__main__'] = restore_main
1634 if self.shell.has_readline:
1629 if self.shell.has_readline:
1635 self.shell.readline.read_history_file(self.shell.histfile)
1630 self.shell.readline.read_history_file(self.shell.histfile)
1636
1631
1637 return stats
1632 return stats
1638
1633
1639 def magic_runlog(self, parameter_s =''):
1634 def magic_runlog(self, parameter_s =''):
1640 """Run files as logs.
1635 """Run files as logs.
1641
1636
1642 Usage:\\
1637 Usage:\\
1643 %runlog file1 file2 ...
1638 %runlog file1 file2 ...
1644
1639
1645 Run the named files (treating them as log files) in sequence inside
1640 Run the named files (treating them as log files) in sequence inside
1646 the interpreter, and return to the prompt. This is much slower than
1641 the interpreter, and return to the prompt. This is much slower than
1647 %run because each line is executed in a try/except block, but it
1642 %run because each line is executed in a try/except block, but it
1648 allows running files with syntax errors in them.
1643 allows running files with syntax errors in them.
1649
1644
1650 Normally IPython will guess when a file is one of its own logfiles, so
1645 Normally IPython will guess when a file is one of its own logfiles, so
1651 you can typically use %run even for logs. This shorthand allows you to
1646 you can typically use %run even for logs. This shorthand allows you to
1652 force any file to be treated as a log file."""
1647 force any file to be treated as a log file."""
1653
1648
1654 for f in parameter_s.split():
1649 for f in parameter_s.split():
1655 self.shell.safe_execfile(f,self.shell.user_ns,
1650 self.shell.safe_execfile(f,self.shell.user_ns,
1656 self.shell.user_ns,islog=1)
1651 self.shell.user_ns,islog=1)
1657
1652
1658 def magic_timeit(self, parameter_s =''):
1653 def magic_timeit(self, parameter_s =''):
1659 """Time execution of a Python statement or expression
1654 """Time execution of a Python statement or expression
1660
1655
1661 Usage:\\
1656 Usage:\\
1662 %timeit [-n<N> -r<R> [-t|-c]] statement
1657 %timeit [-n<N> -r<R> [-t|-c]] statement
1663
1658
1664 Time execution of a Python statement or expression using the timeit
1659 Time execution of a Python statement or expression using the timeit
1665 module.
1660 module.
1666
1661
1667 Options:
1662 Options:
1668 -n<N>: execute the given statement <N> times in a loop. If this value
1663 -n<N>: execute the given statement <N> times in a loop. If this value
1669 is not given, a fitting value is chosen.
1664 is not given, a fitting value is chosen.
1670
1665
1671 -r<R>: repeat the loop iteration <R> times and take the best result.
1666 -r<R>: repeat the loop iteration <R> times and take the best result.
1672 Default: 3
1667 Default: 3
1673
1668
1674 -t: use time.time to measure the time, which is the default on Unix.
1669 -t: use time.time to measure the time, which is the default on Unix.
1675 This function measures wall time.
1670 This function measures wall time.
1676
1671
1677 -c: use time.clock to measure the time, which is the default on
1672 -c: use time.clock to measure the time, which is the default on
1678 Windows and measures wall time. On Unix, resource.getrusage is used
1673 Windows and measures wall time. On Unix, resource.getrusage is used
1679 instead and returns the CPU user time.
1674 instead and returns the CPU user time.
1680
1675
1681 -p<P>: use a precision of <P> digits to display the timing result.
1676 -p<P>: use a precision of <P> digits to display the timing result.
1682 Default: 3
1677 Default: 3
1683
1678
1684
1679
1685 Examples:\\
1680 Examples:\\
1686 In [1]: %timeit pass
1681 In [1]: %timeit pass
1687 10000000 loops, best of 3: 53.3 ns per loop
1682 10000000 loops, best of 3: 53.3 ns per loop
1688
1683
1689 In [2]: u = None
1684 In [2]: u = None
1690
1685
1691 In [3]: %timeit u is None
1686 In [3]: %timeit u is None
1692 10000000 loops, best of 3: 184 ns per loop
1687 10000000 loops, best of 3: 184 ns per loop
1693
1688
1694 In [4]: %timeit -r 4 u == None
1689 In [4]: %timeit -r 4 u == None
1695 1000000 loops, best of 4: 242 ns per loop
1690 1000000 loops, best of 4: 242 ns per loop
1696
1691
1697 In [5]: import time
1692 In [5]: import time
1698
1693
1699 In [6]: %timeit -n1 time.sleep(2)
1694 In [6]: %timeit -n1 time.sleep(2)
1700 1 loops, best of 3: 2 s per loop
1695 1 loops, best of 3: 2 s per loop
1701
1696
1702
1697
1703 The times reported by %timeit will be slightly higher than those
1698 The times reported by %timeit will be slightly higher than those
1704 reported by the timeit.py script when variables are accessed. This is
1699 reported by the timeit.py script when variables are accessed. This is
1705 due to the fact that %timeit executes the statement in the namespace
1700 due to the fact that %timeit executes the statement in the namespace
1706 of the shell, compared with timeit.py, which uses a single setup
1701 of the shell, compared with timeit.py, which uses a single setup
1707 statement to import function or create variables. Generally, the bias
1702 statement to import function or create variables. Generally, the bias
1708 does not matter as long as results from timeit.py are not mixed with
1703 does not matter as long as results from timeit.py are not mixed with
1709 those from %timeit."""
1704 those from %timeit."""
1710
1705
1711 import timeit
1706 import timeit
1712 import math
1707 import math
1713
1708
1714 units = ["s", "ms", "\xc2\xb5s", "ns"]
1709 units = ["s", "ms", "\xc2\xb5s", "ns"]
1715 scaling = [1, 1e3, 1e6, 1e9]
1710 scaling = [1, 1e3, 1e6, 1e9]
1716
1711
1717 opts, stmt = self.parse_options(parameter_s,'n:r:tcp:',
1712 opts, stmt = self.parse_options(parameter_s,'n:r:tcp:',
1718 posix=False)
1713 posix=False)
1719 if stmt == "":
1714 if stmt == "":
1720 return
1715 return
1721 timefunc = timeit.default_timer
1716 timefunc = timeit.default_timer
1722 number = int(getattr(opts, "n", 0))
1717 number = int(getattr(opts, "n", 0))
1723 repeat = int(getattr(opts, "r", timeit.default_repeat))
1718 repeat = int(getattr(opts, "r", timeit.default_repeat))
1724 precision = int(getattr(opts, "p", 3))
1719 precision = int(getattr(opts, "p", 3))
1725 if hasattr(opts, "t"):
1720 if hasattr(opts, "t"):
1726 timefunc = time.time
1721 timefunc = time.time
1727 if hasattr(opts, "c"):
1722 if hasattr(opts, "c"):
1728 timefunc = clock
1723 timefunc = clock
1729
1724
1730 timer = timeit.Timer(timer=timefunc)
1725 timer = timeit.Timer(timer=timefunc)
1731 # this code has tight coupling to the inner workings of timeit.Timer,
1726 # this code has tight coupling to the inner workings of timeit.Timer,
1732 # but is there a better way to achieve that the code stmt has access
1727 # but is there a better way to achieve that the code stmt has access
1733 # to the shell namespace?
1728 # to the shell namespace?
1734
1729
1735 src = timeit.template % {'stmt': timeit.reindent(stmt, 8),
1730 src = timeit.template % {'stmt': timeit.reindent(stmt, 8),
1736 'setup': "pass"}
1731 'setup': "pass"}
1737 code = compile(src, "<magic-timeit>", "exec")
1732 code = compile(src, "<magic-timeit>", "exec")
1738 ns = {}
1733 ns = {}
1739 exec code in self.shell.user_ns, ns
1734 exec code in self.shell.user_ns, ns
1740 timer.inner = ns["inner"]
1735 timer.inner = ns["inner"]
1741
1736
1742 if number == 0:
1737 if number == 0:
1743 # determine number so that 0.2 <= total time < 2.0
1738 # determine number so that 0.2 <= total time < 2.0
1744 number = 1
1739 number = 1
1745 for i in range(1, 10):
1740 for i in range(1, 10):
1746 number *= 10
1741 number *= 10
1747 if timer.timeit(number) >= 0.2:
1742 if timer.timeit(number) >= 0.2:
1748 break
1743 break
1749
1744
1750 best = min(timer.repeat(repeat, number)) / number
1745 best = min(timer.repeat(repeat, number)) / number
1751
1746
1752 if best > 0.0:
1747 if best > 0.0:
1753 order = min(-int(math.floor(math.log10(best)) // 3), 3)
1748 order = min(-int(math.floor(math.log10(best)) // 3), 3)
1754 else:
1749 else:
1755 order = 3
1750 order = 3
1756 print "%d loops, best of %d: %.*g %s per loop" % (number, repeat,
1751 print "%d loops, best of %d: %.*g %s per loop" % (number, repeat,
1757 precision,
1752 precision,
1758 best * scaling[order],
1753 best * scaling[order],
1759 units[order])
1754 units[order])
1760
1755
1761 def magic_time(self,parameter_s = ''):
1756 def magic_time(self,parameter_s = ''):
1762 """Time execution of a Python statement or expression.
1757 """Time execution of a Python statement or expression.
1763
1758
1764 The CPU and wall clock times are printed, and the value of the
1759 The CPU and wall clock times are printed, and the value of the
1765 expression (if any) is returned. Note that under Win32, system time
1760 expression (if any) is returned. Note that under Win32, system time
1766 is always reported as 0, since it can not be measured.
1761 is always reported as 0, since it can not be measured.
1767
1762
1768 This function provides very basic timing functionality. In Python
1763 This function provides very basic timing functionality. In Python
1769 2.3, the timeit module offers more control and sophistication, so this
1764 2.3, the timeit module offers more control and sophistication, so this
1770 could be rewritten to use it (patches welcome).
1765 could be rewritten to use it (patches welcome).
1771
1766
1772 Some examples:
1767 Some examples:
1773
1768
1774 In [1]: time 2**128
1769 In [1]: time 2**128
1775 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1770 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1776 Wall time: 0.00
1771 Wall time: 0.00
1777 Out[1]: 340282366920938463463374607431768211456L
1772 Out[1]: 340282366920938463463374607431768211456L
1778
1773
1779 In [2]: n = 1000000
1774 In [2]: n = 1000000
1780
1775
1781 In [3]: time sum(range(n))
1776 In [3]: time sum(range(n))
1782 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1777 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1783 Wall time: 1.37
1778 Wall time: 1.37
1784 Out[3]: 499999500000L
1779 Out[3]: 499999500000L
1785
1780
1786 In [4]: time print 'hello world'
1781 In [4]: time print 'hello world'
1787 hello world
1782 hello world
1788 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1783 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1789 Wall time: 0.00
1784 Wall time: 0.00
1790 """
1785 """
1791
1786
1792 # fail immediately if the given expression can't be compiled
1787 # fail immediately if the given expression can't be compiled
1793 try:
1788 try:
1794 mode = 'eval'
1789 mode = 'eval'
1795 code = compile(parameter_s,'<timed eval>',mode)
1790 code = compile(parameter_s,'<timed eval>',mode)
1796 except SyntaxError:
1791 except SyntaxError:
1797 mode = 'exec'
1792 mode = 'exec'
1798 code = compile(parameter_s,'<timed exec>',mode)
1793 code = compile(parameter_s,'<timed exec>',mode)
1799 # skew measurement as little as possible
1794 # skew measurement as little as possible
1800 glob = self.shell.user_ns
1795 glob = self.shell.user_ns
1801 clk = clock2
1796 clk = clock2
1802 wtime = time.time
1797 wtime = time.time
1803 # time execution
1798 # time execution
1804 wall_st = wtime()
1799 wall_st = wtime()
1805 if mode=='eval':
1800 if mode=='eval':
1806 st = clk()
1801 st = clk()
1807 out = eval(code,glob)
1802 out = eval(code,glob)
1808 end = clk()
1803 end = clk()
1809 else:
1804 else:
1810 st = clk()
1805 st = clk()
1811 exec code in glob
1806 exec code in glob
1812 end = clk()
1807 end = clk()
1813 out = None
1808 out = None
1814 wall_end = wtime()
1809 wall_end = wtime()
1815 # Compute actual times and report
1810 # Compute actual times and report
1816 wall_time = wall_end-wall_st
1811 wall_time = wall_end-wall_st
1817 cpu_user = end[0]-st[0]
1812 cpu_user = end[0]-st[0]
1818 cpu_sys = end[1]-st[1]
1813 cpu_sys = end[1]-st[1]
1819 cpu_tot = cpu_user+cpu_sys
1814 cpu_tot = cpu_user+cpu_sys
1820 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1815 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1821 (cpu_user,cpu_sys,cpu_tot)
1816 (cpu_user,cpu_sys,cpu_tot)
1822 print "Wall time: %.2f" % wall_time
1817 print "Wall time: %.2f" % wall_time
1823 return out
1818 return out
1824
1819
1825 def magic_macro(self,parameter_s = ''):
1820 def magic_macro(self,parameter_s = ''):
1826 """Define a set of input lines as a macro for future re-execution.
1821 """Define a set of input lines as a macro for future re-execution.
1827
1822
1828 Usage:\\
1823 Usage:\\
1829 %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...
1824 %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...
1830
1825
1831 Options:
1826 Options:
1832
1827
1833 -r: use 'raw' input. By default, the 'processed' history is used,
1828 -r: use 'raw' input. By default, the 'processed' history is used,
1834 so that magics are loaded in their transformed version to valid
1829 so that magics are loaded in their transformed version to valid
1835 Python. If this option is given, the raw input as typed as the
1830 Python. If this option is given, the raw input as typed as the
1836 command line is used instead.
1831 command line is used instead.
1837
1832
1838 This will define a global variable called `name` which is a string
1833 This will define a global variable called `name` which is a string
1839 made of joining the slices and lines you specify (n1,n2,... numbers
1834 made of joining the slices and lines you specify (n1,n2,... numbers
1840 above) from your input history into a single string. This variable
1835 above) from your input history into a single string. This variable
1841 acts like an automatic function which re-executes those lines as if
1836 acts like an automatic function which re-executes those lines as if
1842 you had typed them. You just type 'name' at the prompt and the code
1837 you had typed them. You just type 'name' at the prompt and the code
1843 executes.
1838 executes.
1844
1839
1845 The notation for indicating number ranges is: n1-n2 means 'use line
1840 The notation for indicating number ranges is: n1-n2 means 'use line
1846 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
1841 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
1847 using the lines numbered 5,6 and 7.
1842 using the lines numbered 5,6 and 7.
1848
1843
1849 Note: as a 'hidden' feature, you can also use traditional python slice
1844 Note: as a 'hidden' feature, you can also use traditional python slice
1850 notation, where N:M means numbers N through M-1.
1845 notation, where N:M means numbers N through M-1.
1851
1846
1852 For example, if your history contains (%hist prints it):
1847 For example, if your history contains (%hist prints it):
1853
1848
1854 44: x=1\\
1849 44: x=1\\
1855 45: y=3\\
1850 45: y=3\\
1856 46: z=x+y\\
1851 46: z=x+y\\
1857 47: print x\\
1852 47: print x\\
1858 48: a=5\\
1853 48: a=5\\
1859 49: print 'x',x,'y',y\\
1854 49: print 'x',x,'y',y\\
1860
1855
1861 you can create a macro with lines 44 through 47 (included) and line 49
1856 you can create a macro with lines 44 through 47 (included) and line 49
1862 called my_macro with:
1857 called my_macro with:
1863
1858
1864 In [51]: %macro my_macro 44-47 49
1859 In [51]: %macro my_macro 44-47 49
1865
1860
1866 Now, typing `my_macro` (without quotes) will re-execute all this code
1861 Now, typing `my_macro` (without quotes) will re-execute all this code
1867 in one pass.
1862 in one pass.
1868
1863
1869 You don't need to give the line-numbers in order, and any given line
1864 You don't need to give the line-numbers in order, and any given line
1870 number can appear multiple times. You can assemble macros with any
1865 number can appear multiple times. You can assemble macros with any
1871 lines from your input history in any order.
1866 lines from your input history in any order.
1872
1867
1873 The macro is a simple object which holds its value in an attribute,
1868 The macro is a simple object which holds its value in an attribute,
1874 but IPython's display system checks for macros and executes them as
1869 but IPython's display system checks for macros and executes them as
1875 code instead of printing them when you type their name.
1870 code instead of printing them when you type their name.
1876
1871
1877 You can view a macro's contents by explicitly printing it with:
1872 You can view a macro's contents by explicitly printing it with:
1878
1873
1879 'print macro_name'.
1874 'print macro_name'.
1880
1875
1881 For one-off cases which DON'T contain magic function calls in them you
1876 For one-off cases which DON'T contain magic function calls in them you
1882 can obtain similar results by explicitly executing slices from your
1877 can obtain similar results by explicitly executing slices from your
1883 input history with:
1878 input history with:
1884
1879
1885 In [60]: exec In[44:48]+In[49]"""
1880 In [60]: exec In[44:48]+In[49]"""
1886
1881
1887 opts,args = self.parse_options(parameter_s,'r',mode='list')
1882 opts,args = self.parse_options(parameter_s,'r',mode='list')
1888 name,ranges = args[0], args[1:]
1883 name,ranges = args[0], args[1:]
1889 #print 'rng',ranges # dbg
1884 #print 'rng',ranges # dbg
1890 lines = self.extract_input_slices(ranges,opts.has_key('r'))
1885 lines = self.extract_input_slices(ranges,opts.has_key('r'))
1891 macro = Macro(lines)
1886 macro = Macro(lines)
1892 self.shell.user_ns.update({name:macro})
1887 self.shell.user_ns.update({name:macro})
1893 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1888 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1894 print 'Macro contents:'
1889 print 'Macro contents:'
1895 print macro,
1890 print macro,
1896
1891
1897 def magic_save(self,parameter_s = ''):
1892 def magic_save(self,parameter_s = ''):
1898 """Save a set of lines to a given filename.
1893 """Save a set of lines to a given filename.
1899
1894
1900 Usage:\\
1895 Usage:\\
1901 %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
1896 %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
1902
1897
1903 Options:
1898 Options:
1904
1899
1905 -r: use 'raw' input. By default, the 'processed' history is used,
1900 -r: use 'raw' input. By default, the 'processed' history is used,
1906 so that magics are loaded in their transformed version to valid
1901 so that magics are loaded in their transformed version to valid
1907 Python. If this option is given, the raw input as typed as the
1902 Python. If this option is given, the raw input as typed as the
1908 command line is used instead.
1903 command line is used instead.
1909
1904
1910 This function uses the same syntax as %macro for line extraction, but
1905 This function uses the same syntax as %macro for line extraction, but
1911 instead of creating a macro it saves the resulting string to the
1906 instead of creating a macro it saves the resulting string to the
1912 filename you specify.
1907 filename you specify.
1913
1908
1914 It adds a '.py' extension to the file if you don't do so yourself, and
1909 It adds a '.py' extension to the file if you don't do so yourself, and
1915 it asks for confirmation before overwriting existing files."""
1910 it asks for confirmation before overwriting existing files."""
1916
1911
1917 opts,args = self.parse_options(parameter_s,'r',mode='list')
1912 opts,args = self.parse_options(parameter_s,'r',mode='list')
1918 fname,ranges = args[0], args[1:]
1913 fname,ranges = args[0], args[1:]
1919 if not fname.endswith('.py'):
1914 if not fname.endswith('.py'):
1920 fname += '.py'
1915 fname += '.py'
1921 if os.path.isfile(fname):
1916 if os.path.isfile(fname):
1922 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1917 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1923 if ans.lower() not in ['y','yes']:
1918 if ans.lower() not in ['y','yes']:
1924 print 'Operation cancelled.'
1919 print 'Operation cancelled.'
1925 return
1920 return
1926 cmds = ''.join(self.extract_input_slices(ranges,opts.has_key('r')))
1921 cmds = ''.join(self.extract_input_slices(ranges,opts.has_key('r')))
1927 f = file(fname,'w')
1922 f = file(fname,'w')
1928 f.write(cmds)
1923 f.write(cmds)
1929 f.close()
1924 f.close()
1930 print 'The following commands were written to file `%s`:' % fname
1925 print 'The following commands were written to file `%s`:' % fname
1931 print cmds
1926 print cmds
1932
1927
1933 def _edit_macro(self,mname,macro):
1928 def _edit_macro(self,mname,macro):
1934 """open an editor with the macro data in a file"""
1929 """open an editor with the macro data in a file"""
1935 filename = self.shell.mktempfile(macro.value)
1930 filename = self.shell.mktempfile(macro.value)
1936 self.shell.hooks.editor(filename)
1931 self.shell.hooks.editor(filename)
1937
1932
1938 # and make a new macro object, to replace the old one
1933 # and make a new macro object, to replace the old one
1939 mfile = open(filename)
1934 mfile = open(filename)
1940 mvalue = mfile.read()
1935 mvalue = mfile.read()
1941 mfile.close()
1936 mfile.close()
1942 self.shell.user_ns[mname] = Macro(mvalue)
1937 self.shell.user_ns[mname] = Macro(mvalue)
1943
1938
1944 def magic_ed(self,parameter_s=''):
1939 def magic_ed(self,parameter_s=''):
1945 """Alias to %edit."""
1940 """Alias to %edit."""
1946 return self.magic_edit(parameter_s)
1941 return self.magic_edit(parameter_s)
1947
1942
1948 def magic_edit(self,parameter_s='',last_call=['','']):
1943 def magic_edit(self,parameter_s='',last_call=['','']):
1949 """Bring up an editor and execute the resulting code.
1944 """Bring up an editor and execute the resulting code.
1950
1945
1951 Usage:
1946 Usage:
1952 %edit [options] [args]
1947 %edit [options] [args]
1953
1948
1954 %edit runs IPython's editor hook. The default version of this hook is
1949 %edit runs IPython's editor hook. The default version of this hook is
1955 set to call the __IPYTHON__.rc.editor command. This is read from your
1950 set to call the __IPYTHON__.rc.editor command. This is read from your
1956 environment variable $EDITOR. If this isn't found, it will default to
1951 environment variable $EDITOR. If this isn't found, it will default to
1957 vi under Linux/Unix and to notepad under Windows. See the end of this
1952 vi under Linux/Unix and to notepad under Windows. See the end of this
1958 docstring for how to change the editor hook.
1953 docstring for how to change the editor hook.
1959
1954
1960 You can also set the value of this editor via the command line option
1955 You can also set the value of this editor via the command line option
1961 '-editor' or in your ipythonrc file. This is useful if you wish to use
1956 '-editor' or in your ipythonrc file. This is useful if you wish to use
1962 specifically for IPython an editor different from your typical default
1957 specifically for IPython an editor different from your typical default
1963 (and for Windows users who typically don't set environment variables).
1958 (and for Windows users who typically don't set environment variables).
1964
1959
1965 This command allows you to conveniently edit multi-line code right in
1960 This command allows you to conveniently edit multi-line code right in
1966 your IPython session.
1961 your IPython session.
1967
1962
1968 If called without arguments, %edit opens up an empty editor with a
1963 If called without arguments, %edit opens up an empty editor with a
1969 temporary file and will execute the contents of this file when you
1964 temporary file and will execute the contents of this file when you
1970 close it (don't forget to save it!).
1965 close it (don't forget to save it!).
1971
1966
1972
1967
1973 Options:
1968 Options:
1974
1969
1975 -n <number>: open the editor at a specified line number. By default,
1970 -n <number>: open the editor at a specified line number. By default,
1976 the IPython editor hook uses the unix syntax 'editor +N filename', but
1971 the IPython editor hook uses the unix syntax 'editor +N filename', but
1977 you can configure this by providing your own modified hook if your
1972 you can configure this by providing your own modified hook if your
1978 favorite editor supports line-number specifications with a different
1973 favorite editor supports line-number specifications with a different
1979 syntax.
1974 syntax.
1980
1975
1981 -p: this will call the editor with the same data as the previous time
1976 -p: this will call the editor with the same data as the previous time
1982 it was used, regardless of how long ago (in your current session) it
1977 it was used, regardless of how long ago (in your current session) it
1983 was.
1978 was.
1984
1979
1985 -r: use 'raw' input. This option only applies to input taken from the
1980 -r: use 'raw' input. This option only applies to input taken from the
1986 user's history. By default, the 'processed' history is used, so that
1981 user's history. By default, the 'processed' history is used, so that
1987 magics are loaded in their transformed version to valid Python. If
1982 magics are loaded in their transformed version to valid Python. If
1988 this option is given, the raw input as typed as the command line is
1983 this option is given, the raw input as typed as the command line is
1989 used instead. When you exit the editor, it will be executed by
1984 used instead. When you exit the editor, it will be executed by
1990 IPython's own processor.
1985 IPython's own processor.
1991
1986
1992 -x: do not execute the edited code immediately upon exit. This is
1987 -x: do not execute the edited code immediately upon exit. This is
1993 mainly useful if you are editing programs which need to be called with
1988 mainly useful if you are editing programs which need to be called with
1994 command line arguments, which you can then do using %run.
1989 command line arguments, which you can then do using %run.
1995
1990
1996
1991
1997 Arguments:
1992 Arguments:
1998
1993
1999 If arguments are given, the following possibilites exist:
1994 If arguments are given, the following possibilites exist:
2000
1995
2001 - The arguments are numbers or pairs of colon-separated numbers (like
1996 - The arguments are numbers or pairs of colon-separated numbers (like
2002 1 4:8 9). These are interpreted as lines of previous input to be
1997 1 4:8 9). These are interpreted as lines of previous input to be
2003 loaded into the editor. The syntax is the same of the %macro command.
1998 loaded into the editor. The syntax is the same of the %macro command.
2004
1999
2005 - If the argument doesn't start with a number, it is evaluated as a
2000 - If the argument doesn't start with a number, it is evaluated as a
2006 variable and its contents loaded into the editor. You can thus edit
2001 variable and its contents loaded into the editor. You can thus edit
2007 any string which contains python code (including the result of
2002 any string which contains python code (including the result of
2008 previous edits).
2003 previous edits).
2009
2004
2010 - If the argument is the name of an object (other than a string),
2005 - If the argument is the name of an object (other than a string),
2011 IPython will try to locate the file where it was defined and open the
2006 IPython will try to locate the file where it was defined and open the
2012 editor at the point where it is defined. You can use `%edit function`
2007 editor at the point where it is defined. You can use `%edit function`
2013 to load an editor exactly at the point where 'function' is defined,
2008 to load an editor exactly at the point where 'function' is defined,
2014 edit it and have the file be executed automatically.
2009 edit it and have the file be executed automatically.
2015
2010
2016 If the object is a macro (see %macro for details), this opens up your
2011 If the object is a macro (see %macro for details), this opens up your
2017 specified editor with a temporary file containing the macro's data.
2012 specified editor with a temporary file containing the macro's data.
2018 Upon exit, the macro is reloaded with the contents of the file.
2013 Upon exit, the macro is reloaded with the contents of the file.
2019
2014
2020 Note: opening at an exact line is only supported under Unix, and some
2015 Note: opening at an exact line is only supported under Unix, and some
2021 editors (like kedit and gedit up to Gnome 2.8) do not understand the
2016 editors (like kedit and gedit up to Gnome 2.8) do not understand the
2022 '+NUMBER' parameter necessary for this feature. Good editors like
2017 '+NUMBER' parameter necessary for this feature. Good editors like
2023 (X)Emacs, vi, jed, pico and joe all do.
2018 (X)Emacs, vi, jed, pico and joe all do.
2024
2019
2025 - If the argument is not found as a variable, IPython will look for a
2020 - If the argument is not found as a variable, IPython will look for a
2026 file with that name (adding .py if necessary) and load it into the
2021 file with that name (adding .py if necessary) and load it into the
2027 editor. It will execute its contents with execfile() when you exit,
2022 editor. It will execute its contents with execfile() when you exit,
2028 loading any code in the file into your interactive namespace.
2023 loading any code in the file into your interactive namespace.
2029
2024
2030 After executing your code, %edit will return as output the code you
2025 After executing your code, %edit will return as output the code you
2031 typed in the editor (except when it was an existing file). This way
2026 typed in the editor (except when it was an existing file). This way
2032 you can reload the code in further invocations of %edit as a variable,
2027 you can reload the code in further invocations of %edit as a variable,
2033 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
2028 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
2034 the output.
2029 the output.
2035
2030
2036 Note that %edit is also available through the alias %ed.
2031 Note that %edit is also available through the alias %ed.
2037
2032
2038 This is an example of creating a simple function inside the editor and
2033 This is an example of creating a simple function inside the editor and
2039 then modifying it. First, start up the editor:
2034 then modifying it. First, start up the editor:
2040
2035
2041 In [1]: ed\\
2036 In [1]: ed\\
2042 Editing... done. Executing edited code...\\
2037 Editing... done. Executing edited code...\\
2043 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
2038 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
2044
2039
2045 We can then call the function foo():
2040 We can then call the function foo():
2046
2041
2047 In [2]: foo()\\
2042 In [2]: foo()\\
2048 foo() was defined in an editing session
2043 foo() was defined in an editing session
2049
2044
2050 Now we edit foo. IPython automatically loads the editor with the
2045 Now we edit foo. IPython automatically loads the editor with the
2051 (temporary) file where foo() was previously defined:
2046 (temporary) file where foo() was previously defined:
2052
2047
2053 In [3]: ed foo\\
2048 In [3]: ed foo\\
2054 Editing... done. Executing edited code...
2049 Editing... done. Executing edited code...
2055
2050
2056 And if we call foo() again we get the modified version:
2051 And if we call foo() again we get the modified version:
2057
2052
2058 In [4]: foo()\\
2053 In [4]: foo()\\
2059 foo() has now been changed!
2054 foo() has now been changed!
2060
2055
2061 Here is an example of how to edit a code snippet successive
2056 Here is an example of how to edit a code snippet successive
2062 times. First we call the editor:
2057 times. First we call the editor:
2063
2058
2064 In [8]: ed\\
2059 In [8]: ed\\
2065 Editing... done. Executing edited code...\\
2060 Editing... done. Executing edited code...\\
2066 hello\\
2061 hello\\
2067 Out[8]: "print 'hello'\\n"
2062 Out[8]: "print 'hello'\\n"
2068
2063
2069 Now we call it again with the previous output (stored in _):
2064 Now we call it again with the previous output (stored in _):
2070
2065
2071 In [9]: ed _\\
2066 In [9]: ed _\\
2072 Editing... done. Executing edited code...\\
2067 Editing... done. Executing edited code...\\
2073 hello world\\
2068 hello world\\
2074 Out[9]: "print 'hello world'\\n"
2069 Out[9]: "print 'hello world'\\n"
2075
2070
2076 Now we call it with the output #8 (stored in _8, also as Out[8]):
2071 Now we call it with the output #8 (stored in _8, also as Out[8]):
2077
2072
2078 In [10]: ed _8\\
2073 In [10]: ed _8\\
2079 Editing... done. Executing edited code...\\
2074 Editing... done. Executing edited code...\\
2080 hello again\\
2075 hello again\\
2081 Out[10]: "print 'hello again'\\n"
2076 Out[10]: "print 'hello again'\\n"
2082
2077
2083
2078
2084 Changing the default editor hook:
2079 Changing the default editor hook:
2085
2080
2086 If you wish to write your own editor hook, you can put it in a
2081 If you wish to write your own editor hook, you can put it in a
2087 configuration file which you load at startup time. The default hook
2082 configuration file which you load at startup time. The default hook
2088 is defined in the IPython.hooks module, and you can use that as a
2083 is defined in the IPython.hooks module, and you can use that as a
2089 starting example for further modifications. That file also has
2084 starting example for further modifications. That file also has
2090 general instructions on how to set a new hook for use once you've
2085 general instructions on how to set a new hook for use once you've
2091 defined it."""
2086 defined it."""
2092
2087
2093 # FIXME: This function has become a convoluted mess. It needs a
2088 # FIXME: This function has become a convoluted mess. It needs a
2094 # ground-up rewrite with clean, simple logic.
2089 # ground-up rewrite with clean, simple logic.
2095
2090
2096 def make_filename(arg):
2091 def make_filename(arg):
2097 "Make a filename from the given args"
2092 "Make a filename from the given args"
2098 try:
2093 try:
2099 filename = get_py_filename(arg)
2094 filename = get_py_filename(arg)
2100 except IOError:
2095 except IOError:
2101 if args.endswith('.py'):
2096 if args.endswith('.py'):
2102 filename = arg
2097 filename = arg
2103 else:
2098 else:
2104 filename = None
2099 filename = None
2105 return filename
2100 return filename
2106
2101
2107 # custom exceptions
2102 # custom exceptions
2108 class DataIsObject(Exception): pass
2103 class DataIsObject(Exception): pass
2109
2104
2110 opts,args = self.parse_options(parameter_s,'prxn:')
2105 opts,args = self.parse_options(parameter_s,'prxn:')
2111 # Set a few locals from the options for convenience:
2106 # Set a few locals from the options for convenience:
2112 opts_p = opts.has_key('p')
2107 opts_p = opts.has_key('p')
2113 opts_r = opts.has_key('r')
2108 opts_r = opts.has_key('r')
2114
2109
2115 # Default line number value
2110 # Default line number value
2116 lineno = opts.get('n',None)
2111 lineno = opts.get('n',None)
2117
2112
2118 if opts_p:
2113 if opts_p:
2119 args = '_%s' % last_call[0]
2114 args = '_%s' % last_call[0]
2120 if not self.shell.user_ns.has_key(args):
2115 if not self.shell.user_ns.has_key(args):
2121 args = last_call[1]
2116 args = last_call[1]
2122
2117
2123 # use last_call to remember the state of the previous call, but don't
2118 # use last_call to remember the state of the previous call, but don't
2124 # let it be clobbered by successive '-p' calls.
2119 # let it be clobbered by successive '-p' calls.
2125 try:
2120 try:
2126 last_call[0] = self.shell.outputcache.prompt_count
2121 last_call[0] = self.shell.outputcache.prompt_count
2127 if not opts_p:
2122 if not opts_p:
2128 last_call[1] = parameter_s
2123 last_call[1] = parameter_s
2129 except:
2124 except:
2130 pass
2125 pass
2131
2126
2132 # by default this is done with temp files, except when the given
2127 # by default this is done with temp files, except when the given
2133 # arg is a filename
2128 # arg is a filename
2134 use_temp = 1
2129 use_temp = 1
2135
2130
2136 if re.match(r'\d',args):
2131 if re.match(r'\d',args):
2137 # Mode where user specifies ranges of lines, like in %macro.
2132 # Mode where user specifies ranges of lines, like in %macro.
2138 # This means that you can't edit files whose names begin with
2133 # This means that you can't edit files whose names begin with
2139 # numbers this way. Tough.
2134 # numbers this way. Tough.
2140 ranges = args.split()
2135 ranges = args.split()
2141 data = ''.join(self.extract_input_slices(ranges,opts_r))
2136 data = ''.join(self.extract_input_slices(ranges,opts_r))
2142 elif args.endswith('.py'):
2137 elif args.endswith('.py'):
2143 filename = make_filename(args)
2138 filename = make_filename(args)
2144 data = ''
2139 data = ''
2145 use_temp = 0
2140 use_temp = 0
2146 elif args:
2141 elif args:
2147 try:
2142 try:
2148 # Load the parameter given as a variable. If not a string,
2143 # Load the parameter given as a variable. If not a string,
2149 # process it as an object instead (below)
2144 # process it as an object instead (below)
2150
2145
2151 #print '*** args',args,'type',type(args) # dbg
2146 #print '*** args',args,'type',type(args) # dbg
2152 data = eval(args,self.shell.user_ns)
2147 data = eval(args,self.shell.user_ns)
2153 if not type(data) in StringTypes:
2148 if not type(data) in StringTypes:
2154 raise DataIsObject
2149 raise DataIsObject
2155
2150
2156 except (NameError,SyntaxError):
2151 except (NameError,SyntaxError):
2157 # given argument is not a variable, try as a filename
2152 # given argument is not a variable, try as a filename
2158 filename = make_filename(args)
2153 filename = make_filename(args)
2159 if filename is None:
2154 if filename is None:
2160 warn("Argument given (%s) can't be found as a variable "
2155 warn("Argument given (%s) can't be found as a variable "
2161 "or as a filename." % args)
2156 "or as a filename." % args)
2162 return
2157 return
2163
2158
2164 data = ''
2159 data = ''
2165 use_temp = 0
2160 use_temp = 0
2166 except DataIsObject:
2161 except DataIsObject:
2167
2162
2168 # macros have a special edit function
2163 # macros have a special edit function
2169 if isinstance(data,Macro):
2164 if isinstance(data,Macro):
2170 self._edit_macro(args,data)
2165 self._edit_macro(args,data)
2171 return
2166 return
2172
2167
2173 # For objects, try to edit the file where they are defined
2168 # For objects, try to edit the file where they are defined
2174 try:
2169 try:
2175 filename = inspect.getabsfile(data)
2170 filename = inspect.getabsfile(data)
2176 datafile = 1
2171 datafile = 1
2177 except TypeError:
2172 except TypeError:
2178 filename = make_filename(args)
2173 filename = make_filename(args)
2179 datafile = 1
2174 datafile = 1
2180 warn('Could not find file where `%s` is defined.\n'
2175 warn('Could not find file where `%s` is defined.\n'
2181 'Opening a file named `%s`' % (args,filename))
2176 'Opening a file named `%s`' % (args,filename))
2182 # Now, make sure we can actually read the source (if it was in
2177 # Now, make sure we can actually read the source (if it was in
2183 # a temp file it's gone by now).
2178 # a temp file it's gone by now).
2184 if datafile:
2179 if datafile:
2185 try:
2180 try:
2186 if lineno is None:
2181 if lineno is None:
2187 lineno = inspect.getsourcelines(data)[1]
2182 lineno = inspect.getsourcelines(data)[1]
2188 except IOError:
2183 except IOError:
2189 filename = make_filename(args)
2184 filename = make_filename(args)
2190 if filename is None:
2185 if filename is None:
2191 warn('The file `%s` where `%s` was defined cannot '
2186 warn('The file `%s` where `%s` was defined cannot '
2192 'be read.' % (filename,data))
2187 'be read.' % (filename,data))
2193 return
2188 return
2194 use_temp = 0
2189 use_temp = 0
2195 else:
2190 else:
2196 data = ''
2191 data = ''
2197
2192
2198 if use_temp:
2193 if use_temp:
2199 filename = self.shell.mktempfile(data)
2194 filename = self.shell.mktempfile(data)
2200 print 'IPython will make a temporary file named:',filename
2195 print 'IPython will make a temporary file named:',filename
2201
2196
2202 # do actual editing here
2197 # do actual editing here
2203 print 'Editing...',
2198 print 'Editing...',
2204 sys.stdout.flush()
2199 sys.stdout.flush()
2205 self.shell.hooks.editor(filename,lineno)
2200 self.shell.hooks.editor(filename,lineno)
2206 if opts.has_key('x'): # -x prevents actual execution
2201 if opts.has_key('x'): # -x prevents actual execution
2207 print
2202 print
2208 else:
2203 else:
2209 print 'done. Executing edited code...'
2204 print 'done. Executing edited code...'
2210 if opts_r:
2205 if opts_r:
2211 self.shell.runlines(file_read(filename))
2206 self.shell.runlines(file_read(filename))
2212 else:
2207 else:
2213 self.shell.safe_execfile(filename,self.shell.user_ns)
2208 self.shell.safe_execfile(filename,self.shell.user_ns)
2214 if use_temp:
2209 if use_temp:
2215 try:
2210 try:
2216 return open(filename).read()
2211 return open(filename).read()
2217 except IOError,msg:
2212 except IOError,msg:
2218 if msg.filename == filename:
2213 if msg.filename == filename:
2219 warn('File not found. Did you forget to save?')
2214 warn('File not found. Did you forget to save?')
2220 return
2215 return
2221 else:
2216 else:
2222 self.shell.showtraceback()
2217 self.shell.showtraceback()
2223
2218
2224 def magic_xmode(self,parameter_s = ''):
2219 def magic_xmode(self,parameter_s = ''):
2225 """Switch modes for the exception handlers.
2220 """Switch modes for the exception handlers.
2226
2221
2227 Valid modes: Plain, Context and Verbose.
2222 Valid modes: Plain, Context and Verbose.
2228
2223
2229 If called without arguments, acts as a toggle."""
2224 If called without arguments, acts as a toggle."""
2230
2225
2231 def xmode_switch_err(name):
2226 def xmode_switch_err(name):
2232 warn('Error changing %s exception modes.\n%s' %
2227 warn('Error changing %s exception modes.\n%s' %
2233 (name,sys.exc_info()[1]))
2228 (name,sys.exc_info()[1]))
2234
2229
2235 shell = self.shell
2230 shell = self.shell
2236 new_mode = parameter_s.strip().capitalize()
2231 new_mode = parameter_s.strip().capitalize()
2237 try:
2232 try:
2238 shell.InteractiveTB.set_mode(mode=new_mode)
2233 shell.InteractiveTB.set_mode(mode=new_mode)
2239 print 'Exception reporting mode:',shell.InteractiveTB.mode
2234 print 'Exception reporting mode:',shell.InteractiveTB.mode
2240 except:
2235 except:
2241 xmode_switch_err('user')
2236 xmode_switch_err('user')
2242
2237
2243 # threaded shells use a special handler in sys.excepthook
2238 # threaded shells use a special handler in sys.excepthook
2244 if shell.isthreaded:
2239 if shell.isthreaded:
2245 try:
2240 try:
2246 shell.sys_excepthook.set_mode(mode=new_mode)
2241 shell.sys_excepthook.set_mode(mode=new_mode)
2247 except:
2242 except:
2248 xmode_switch_err('threaded')
2243 xmode_switch_err('threaded')
2249
2244
2250 def magic_colors(self,parameter_s = ''):
2245 def magic_colors(self,parameter_s = ''):
2251 """Switch color scheme for prompts, info system and exception handlers.
2246 """Switch color scheme for prompts, info system and exception handlers.
2252
2247
2253 Currently implemented schemes: NoColor, Linux, LightBG.
2248 Currently implemented schemes: NoColor, Linux, LightBG.
2254
2249
2255 Color scheme names are not case-sensitive."""
2250 Color scheme names are not case-sensitive."""
2256
2251
2257 def color_switch_err(name):
2252 def color_switch_err(name):
2258 warn('Error changing %s color schemes.\n%s' %
2253 warn('Error changing %s color schemes.\n%s' %
2259 (name,sys.exc_info()[1]))
2254 (name,sys.exc_info()[1]))
2260
2255
2261
2256
2262 new_scheme = parameter_s.strip()
2257 new_scheme = parameter_s.strip()
2263 if not new_scheme:
2258 if not new_scheme:
2264 print 'You must specify a color scheme.'
2259 print 'You must specify a color scheme.'
2265 return
2260 return
2266 import IPython.rlineimpl as readline
2261 import IPython.rlineimpl as readline
2267 if not readline.have_readline:
2262 if not readline.have_readline:
2268 msg = """\
2263 msg = """\
2269 Proper color support under MS Windows requires the pyreadline library.
2264 Proper color support under MS Windows requires the pyreadline library.
2270 You can find it at:
2265 You can find it at:
2271 http://ipython.scipy.org/moin/PyReadline/Intro
2266 http://ipython.scipy.org/moin/PyReadline/Intro
2272 Gary's readline needs the ctypes module, from:
2267 Gary's readline needs the ctypes module, from:
2273 http://starship.python.net/crew/theller/ctypes
2268 http://starship.python.net/crew/theller/ctypes
2274 (Note that ctypes is already part of Python versions 2.5 and newer).
2269 (Note that ctypes is already part of Python versions 2.5 and newer).
2275
2270
2276 Defaulting color scheme to 'NoColor'"""
2271 Defaulting color scheme to 'NoColor'"""
2277 new_scheme = 'NoColor'
2272 new_scheme = 'NoColor'
2278 warn(msg)
2273 warn(msg)
2279 # local shortcut
2274 # local shortcut
2280 shell = self.shell
2275 shell = self.shell
2281
2276
2282 # Set prompt colors
2277 # Set prompt colors
2283 try:
2278 try:
2284 shell.outputcache.set_colors(new_scheme)
2279 shell.outputcache.set_colors(new_scheme)
2285 except:
2280 except:
2286 color_switch_err('prompt')
2281 color_switch_err('prompt')
2287 else:
2282 else:
2288 shell.rc.colors = \
2283 shell.rc.colors = \
2289 shell.outputcache.color_table.active_scheme_name
2284 shell.outputcache.color_table.active_scheme_name
2290 # Set exception colors
2285 # Set exception colors
2291 try:
2286 try:
2292 shell.InteractiveTB.set_colors(scheme = new_scheme)
2287 shell.InteractiveTB.set_colors(scheme = new_scheme)
2293 shell.SyntaxTB.set_colors(scheme = new_scheme)
2288 shell.SyntaxTB.set_colors(scheme = new_scheme)
2294 except:
2289 except:
2295 color_switch_err('exception')
2290 color_switch_err('exception')
2296
2291
2297 # threaded shells use a verbose traceback in sys.excepthook
2292 # threaded shells use a verbose traceback in sys.excepthook
2298 if shell.isthreaded:
2293 if shell.isthreaded:
2299 try:
2294 try:
2300 shell.sys_excepthook.set_colors(scheme=new_scheme)
2295 shell.sys_excepthook.set_colors(scheme=new_scheme)
2301 except:
2296 except:
2302 color_switch_err('system exception handler')
2297 color_switch_err('system exception handler')
2303
2298
2304 # Set info (for 'object?') colors
2299 # Set info (for 'object?') colors
2305 if shell.rc.color_info:
2300 if shell.rc.color_info:
2306 try:
2301 try:
2307 shell.inspector.set_active_scheme(new_scheme)
2302 shell.inspector.set_active_scheme(new_scheme)
2308 except:
2303 except:
2309 color_switch_err('object inspector')
2304 color_switch_err('object inspector')
2310 else:
2305 else:
2311 shell.inspector.set_active_scheme('NoColor')
2306 shell.inspector.set_active_scheme('NoColor')
2312
2307
2313 def magic_color_info(self,parameter_s = ''):
2308 def magic_color_info(self,parameter_s = ''):
2314 """Toggle color_info.
2309 """Toggle color_info.
2315
2310
2316 The color_info configuration parameter controls whether colors are
2311 The color_info configuration parameter controls whether colors are
2317 used for displaying object details (by things like %psource, %pfile or
2312 used for displaying object details (by things like %psource, %pfile or
2318 the '?' system). This function toggles this value with each call.
2313 the '?' system). This function toggles this value with each call.
2319
2314
2320 Note that unless you have a fairly recent pager (less works better
2315 Note that unless you have a fairly recent pager (less works better
2321 than more) in your system, using colored object information displays
2316 than more) in your system, using colored object information displays
2322 will not work properly. Test it and see."""
2317 will not work properly. Test it and see."""
2323
2318
2324 self.shell.rc.color_info = 1 - self.shell.rc.color_info
2319 self.shell.rc.color_info = 1 - self.shell.rc.color_info
2325 self.magic_colors(self.shell.rc.colors)
2320 self.magic_colors(self.shell.rc.colors)
2326 print 'Object introspection functions have now coloring:',
2321 print 'Object introspection functions have now coloring:',
2327 print ['OFF','ON'][self.shell.rc.color_info]
2322 print ['OFF','ON'][self.shell.rc.color_info]
2328
2323
2329 def magic_Pprint(self, parameter_s=''):
2324 def magic_Pprint(self, parameter_s=''):
2330 """Toggle pretty printing on/off."""
2325 """Toggle pretty printing on/off."""
2331
2326
2332 self.shell.rc.pprint = 1 - self.shell.rc.pprint
2327 self.shell.rc.pprint = 1 - self.shell.rc.pprint
2333 print 'Pretty printing has been turned', \
2328 print 'Pretty printing has been turned', \
2334 ['OFF','ON'][self.shell.rc.pprint]
2329 ['OFF','ON'][self.shell.rc.pprint]
2335
2330
2336 def magic_exit(self, parameter_s=''):
2331 def magic_exit(self, parameter_s=''):
2337 """Exit IPython, confirming if configured to do so.
2332 """Exit IPython, confirming if configured to do so.
2338
2333
2339 You can configure whether IPython asks for confirmation upon exit by
2334 You can configure whether IPython asks for confirmation upon exit by
2340 setting the confirm_exit flag in the ipythonrc file."""
2335 setting the confirm_exit flag in the ipythonrc file."""
2341
2336
2342 self.shell.exit()
2337 self.shell.exit()
2343
2338
2344 def magic_quit(self, parameter_s=''):
2339 def magic_quit(self, parameter_s=''):
2345 """Exit IPython, confirming if configured to do so (like %exit)"""
2340 """Exit IPython, confirming if configured to do so (like %exit)"""
2346
2341
2347 self.shell.exit()
2342 self.shell.exit()
2348
2343
2349 def magic_Exit(self, parameter_s=''):
2344 def magic_Exit(self, parameter_s=''):
2350 """Exit IPython without confirmation."""
2345 """Exit IPython without confirmation."""
2351
2346
2352 self.shell.exit_now = True
2347 self.shell.exit_now = True
2353
2348
2354 def magic_Quit(self, parameter_s=''):
2349 def magic_Quit(self, parameter_s=''):
2355 """Exit IPython without confirmation (like %Exit)."""
2350 """Exit IPython without confirmation (like %Exit)."""
2356
2351
2357 self.shell.exit_now = True
2352 self.shell.exit_now = True
2358
2353
2359 #......................................................................
2354 #......................................................................
2360 # Functions to implement unix shell-type things
2355 # Functions to implement unix shell-type things
2361
2356
2362 def magic_alias(self, parameter_s = ''):
2357 def magic_alias(self, parameter_s = ''):
2363 """Define an alias for a system command.
2358 """Define an alias for a system command.
2364
2359
2365 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2360 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2366
2361
2367 Then, typing 'alias_name params' will execute the system command 'cmd
2362 Then, typing 'alias_name params' will execute the system command 'cmd
2368 params' (from your underlying operating system).
2363 params' (from your underlying operating system).
2369
2364
2370 Aliases have lower precedence than magic functions and Python normal
2365 Aliases have lower precedence than magic functions and Python normal
2371 variables, so if 'foo' is both a Python variable and an alias, the
2366 variables, so if 'foo' is both a Python variable and an alias, the
2372 alias can not be executed until 'del foo' removes the Python variable.
2367 alias can not be executed until 'del foo' removes the Python variable.
2373
2368
2374 You can use the %l specifier in an alias definition to represent the
2369 You can use the %l specifier in an alias definition to represent the
2375 whole line when the alias is called. For example:
2370 whole line when the alias is called. For example:
2376
2371
2377 In [2]: alias all echo "Input in brackets: <%l>"\\
2372 In [2]: alias all echo "Input in brackets: <%l>"\\
2378 In [3]: all hello world\\
2373 In [3]: all hello world\\
2379 Input in brackets: <hello world>
2374 Input in brackets: <hello world>
2380
2375
2381 You can also define aliases with parameters using %s specifiers (one
2376 You can also define aliases with parameters using %s specifiers (one
2382 per parameter):
2377 per parameter):
2383
2378
2384 In [1]: alias parts echo first %s second %s\\
2379 In [1]: alias parts echo first %s second %s\\
2385 In [2]: %parts A B\\
2380 In [2]: %parts A B\\
2386 first A second B\\
2381 first A second B\\
2387 In [3]: %parts A\\
2382 In [3]: %parts A\\
2388 Incorrect number of arguments: 2 expected.\\
2383 Incorrect number of arguments: 2 expected.\\
2389 parts is an alias to: 'echo first %s second %s'
2384 parts is an alias to: 'echo first %s second %s'
2390
2385
2391 Note that %l and %s are mutually exclusive. You can only use one or
2386 Note that %l and %s are mutually exclusive. You can only use one or
2392 the other in your aliases.
2387 the other in your aliases.
2393
2388
2394 Aliases expand Python variables just like system calls using ! or !!
2389 Aliases expand Python variables just like system calls using ! or !!
2395 do: all expressions prefixed with '$' get expanded. For details of
2390 do: all expressions prefixed with '$' get expanded. For details of
2396 the semantic rules, see PEP-215:
2391 the semantic rules, see PEP-215:
2397 http://www.python.org/peps/pep-0215.html. This is the library used by
2392 http://www.python.org/peps/pep-0215.html. This is the library used by
2398 IPython for variable expansion. If you want to access a true shell
2393 IPython for variable expansion. If you want to access a true shell
2399 variable, an extra $ is necessary to prevent its expansion by IPython:
2394 variable, an extra $ is necessary to prevent its expansion by IPython:
2400
2395
2401 In [6]: alias show echo\\
2396 In [6]: alias show echo\\
2402 In [7]: PATH='A Python string'\\
2397 In [7]: PATH='A Python string'\\
2403 In [8]: show $PATH\\
2398 In [8]: show $PATH\\
2404 A Python string\\
2399 A Python string\\
2405 In [9]: show $$PATH\\
2400 In [9]: show $$PATH\\
2406 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2401 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2407
2402
2408 You can use the alias facility to acess all of $PATH. See the %rehash
2403 You can use the alias facility to acess all of $PATH. See the %rehash
2409 and %rehashx functions, which automatically create aliases for the
2404 and %rehashx functions, which automatically create aliases for the
2410 contents of your $PATH.
2405 contents of your $PATH.
2411
2406
2412 If called with no parameters, %alias prints the current alias table."""
2407 If called with no parameters, %alias prints the current alias table."""
2413
2408
2414 par = parameter_s.strip()
2409 par = parameter_s.strip()
2415 if not par:
2410 if not par:
2416 stored = self.db.get('stored_aliases', {} )
2411 stored = self.db.get('stored_aliases', {} )
2417 atab = self.shell.alias_table
2412 atab = self.shell.alias_table
2418 aliases = atab.keys()
2413 aliases = atab.keys()
2419 aliases.sort()
2414 aliases.sort()
2420 res = []
2415 res = []
2421 showlast = []
2416 showlast = []
2422 for alias in aliases:
2417 for alias in aliases:
2423 tgt = atab[alias][1]
2418 tgt = atab[alias][1]
2424 # 'interesting' aliases
2419 # 'interesting' aliases
2425 if (alias in stored or
2420 if (alias in stored or
2426 alias != os.path.splitext(tgt)[0] or
2421 alias != os.path.splitext(tgt)[0] or
2427 ' ' in tgt):
2422 ' ' in tgt):
2428 showlast.append((alias, tgt))
2423 showlast.append((alias, tgt))
2429 else:
2424 else:
2430 res.append((alias, tgt ))
2425 res.append((alias, tgt ))
2431
2426
2432 # show most interesting aliases last
2427 # show most interesting aliases last
2433 res.extend(showlast)
2428 res.extend(showlast)
2434 print "Total number of aliases:",len(aliases)
2429 print "Total number of aliases:",len(aliases)
2435 return res
2430 return res
2436 try:
2431 try:
2437 alias,cmd = par.split(None,1)
2432 alias,cmd = par.split(None,1)
2438 except:
2433 except:
2439 print OInspect.getdoc(self.magic_alias)
2434 print OInspect.getdoc(self.magic_alias)
2440 else:
2435 else:
2441 nargs = cmd.count('%s')
2436 nargs = cmd.count('%s')
2442 if nargs>0 and cmd.find('%l')>=0:
2437 if nargs>0 and cmd.find('%l')>=0:
2443 error('The %s and %l specifiers are mutually exclusive '
2438 error('The %s and %l specifiers are mutually exclusive '
2444 'in alias definitions.')
2439 'in alias definitions.')
2445 else: # all looks OK
2440 else: # all looks OK
2446 self.shell.alias_table[alias] = (nargs,cmd)
2441 self.shell.alias_table[alias] = (nargs,cmd)
2447 self.shell.alias_table_validate(verbose=0)
2442 self.shell.alias_table_validate(verbose=0)
2448 # end magic_alias
2443 # end magic_alias
2449
2444
2450 def magic_unalias(self, parameter_s = ''):
2445 def magic_unalias(self, parameter_s = ''):
2451 """Remove an alias"""
2446 """Remove an alias"""
2452
2447
2453 aname = parameter_s.strip()
2448 aname = parameter_s.strip()
2454 if aname in self.shell.alias_table:
2449 if aname in self.shell.alias_table:
2455 del self.shell.alias_table[aname]
2450 del self.shell.alias_table[aname]
2456 stored = self.db.get('stored_aliases', {} )
2451 stored = self.db.get('stored_aliases', {} )
2457 if aname in stored:
2452 if aname in stored:
2458 print "Removing %stored alias",aname
2453 print "Removing %stored alias",aname
2459 del stored[aname]
2454 del stored[aname]
2460 self.db['stored_aliases'] = stored
2455 self.db['stored_aliases'] = stored
2461
2456
2462 def magic_rehash(self, parameter_s = ''):
2457 def magic_rehash(self, parameter_s = ''):
2463 """Update the alias table with all entries in $PATH.
2458 """Update the alias table with all entries in $PATH.
2464
2459
2465 This version does no checks on execute permissions or whether the
2460 This version does no checks on execute permissions or whether the
2466 contents of $PATH are truly files (instead of directories or something
2461 contents of $PATH are truly files (instead of directories or something
2467 else). For such a safer (but slower) version, use %rehashx."""
2462 else). For such a safer (but slower) version, use %rehashx."""
2468
2463
2469 # This function (and rehashx) manipulate the alias_table directly
2464 # This function (and rehashx) manipulate the alias_table directly
2470 # rather than calling magic_alias, for speed reasons. A rehash on a
2465 # rather than calling magic_alias, for speed reasons. A rehash on a
2471 # typical Linux box involves several thousand entries, so efficiency
2466 # typical Linux box involves several thousand entries, so efficiency
2472 # here is a top concern.
2467 # here is a top concern.
2473
2468
2474 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2469 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2475 alias_table = self.shell.alias_table
2470 alias_table = self.shell.alias_table
2476 for pdir in path:
2471 for pdir in path:
2477 for ff in os.listdir(pdir):
2472 for ff in os.listdir(pdir):
2478 # each entry in the alias table must be (N,name), where
2473 # each entry in the alias table must be (N,name), where
2479 # N is the number of positional arguments of the alias.
2474 # N is the number of positional arguments of the alias.
2480 alias_table[ff] = (0,ff)
2475 alias_table[ff] = (0,ff)
2481 # Make sure the alias table doesn't contain keywords or builtins
2476 # Make sure the alias table doesn't contain keywords or builtins
2482 self.shell.alias_table_validate()
2477 self.shell.alias_table_validate()
2483 # Call again init_auto_alias() so we get 'rm -i' and other modified
2478 # Call again init_auto_alias() so we get 'rm -i' and other modified
2484 # aliases since %rehash will probably clobber them
2479 # aliases since %rehash will probably clobber them
2485 self.shell.init_auto_alias()
2480 self.shell.init_auto_alias()
2486
2481
2487 def magic_rehashx(self, parameter_s = ''):
2482 def magic_rehashx(self, parameter_s = ''):
2488 """Update the alias table with all executable files in $PATH.
2483 """Update the alias table with all executable files in $PATH.
2489
2484
2490 This version explicitly checks that every entry in $PATH is a file
2485 This version explicitly checks that every entry in $PATH is a file
2491 with execute access (os.X_OK), so it is much slower than %rehash.
2486 with execute access (os.X_OK), so it is much slower than %rehash.
2492
2487
2493 Under Windows, it checks executability as a match agains a
2488 Under Windows, it checks executability as a match agains a
2494 '|'-separated string of extensions, stored in the IPython config
2489 '|'-separated string of extensions, stored in the IPython config
2495 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2490 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2496
2491
2497 path = [os.path.abspath(os.path.expanduser(p)) for p in
2492 path = [os.path.abspath(os.path.expanduser(p)) for p in
2498 os.environ['PATH'].split(os.pathsep)]
2493 os.environ['PATH'].split(os.pathsep)]
2499 path = filter(os.path.isdir,path)
2494 path = filter(os.path.isdir,path)
2500
2495
2501 alias_table = self.shell.alias_table
2496 alias_table = self.shell.alias_table
2502 syscmdlist = []
2497 syscmdlist = []
2503 if os.name == 'posix':
2498 if os.name == 'posix':
2504 isexec = lambda fname:os.path.isfile(fname) and \
2499 isexec = lambda fname:os.path.isfile(fname) and \
2505 os.access(fname,os.X_OK)
2500 os.access(fname,os.X_OK)
2506 else:
2501 else:
2507
2502
2508 try:
2503 try:
2509 winext = os.environ['pathext'].replace(';','|').replace('.','')
2504 winext = os.environ['pathext'].replace(';','|').replace('.','')
2510 except KeyError:
2505 except KeyError:
2511 winext = 'exe|com|bat|py'
2506 winext = 'exe|com|bat|py'
2512 if 'py' not in winext:
2507 if 'py' not in winext:
2513 winext += '|py'
2508 winext += '|py'
2514 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2509 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2515 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2510 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2516 savedir = os.getcwd()
2511 savedir = os.getcwd()
2517 try:
2512 try:
2518 # write the whole loop for posix/Windows so we don't have an if in
2513 # write the whole loop for posix/Windows so we don't have an if in
2519 # the innermost part
2514 # the innermost part
2520 if os.name == 'posix':
2515 if os.name == 'posix':
2521 for pdir in path:
2516 for pdir in path:
2522 os.chdir(pdir)
2517 os.chdir(pdir)
2523 for ff in os.listdir(pdir):
2518 for ff in os.listdir(pdir):
2524 if isexec(ff) and ff not in self.shell.no_alias:
2519 if isexec(ff) and ff not in self.shell.no_alias:
2525 # each entry in the alias table must be (N,name),
2520 # each entry in the alias table must be (N,name),
2526 # where N is the number of positional arguments of the
2521 # where N is the number of positional arguments of the
2527 # alias.
2522 # alias.
2528 alias_table[ff] = (0,ff)
2523 alias_table[ff] = (0,ff)
2529 syscmdlist.append(ff)
2524 syscmdlist.append(ff)
2530 else:
2525 else:
2531 for pdir in path:
2526 for pdir in path:
2532 os.chdir(pdir)
2527 os.chdir(pdir)
2533 for ff in os.listdir(pdir):
2528 for ff in os.listdir(pdir):
2534 if isexec(ff) and os.path.splitext(ff)[0] not in self.shell.no_alias:
2529 if isexec(ff) and os.path.splitext(ff)[0] not in self.shell.no_alias:
2535 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2530 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2536 syscmdlist.append(ff)
2531 syscmdlist.append(ff)
2537 # Make sure the alias table doesn't contain keywords or builtins
2532 # Make sure the alias table doesn't contain keywords or builtins
2538 self.shell.alias_table_validate()
2533 self.shell.alias_table_validate()
2539 # Call again init_auto_alias() so we get 'rm -i' and other
2534 # Call again init_auto_alias() so we get 'rm -i' and other
2540 # modified aliases since %rehashx will probably clobber them
2535 # modified aliases since %rehashx will probably clobber them
2541 self.shell.init_auto_alias()
2536 self.shell.init_auto_alias()
2542 db = self.getapi().db
2537 db = self.getapi().db
2543 db['syscmdlist'] = syscmdlist
2538 db['syscmdlist'] = syscmdlist
2544 finally:
2539 finally:
2545 os.chdir(savedir)
2540 os.chdir(savedir)
2546
2541
2547 def magic_pwd(self, parameter_s = ''):
2542 def magic_pwd(self, parameter_s = ''):
2548 """Return the current working directory path."""
2543 """Return the current working directory path."""
2549 return os.getcwd()
2544 return os.getcwd()
2550
2545
2551 def magic_cd(self, parameter_s=''):
2546 def magic_cd(self, parameter_s=''):
2552 """Change the current working directory.
2547 """Change the current working directory.
2553
2548
2554 This command automatically maintains an internal list of directories
2549 This command automatically maintains an internal list of directories
2555 you visit during your IPython session, in the variable _dh. The
2550 you visit during your IPython session, in the variable _dh. The
2556 command %dhist shows this history nicely formatted.
2551 command %dhist shows this history nicely formatted.
2557
2552
2558 Usage:
2553 Usage:
2559
2554
2560 cd 'dir': changes to directory 'dir'.
2555 cd 'dir': changes to directory 'dir'.
2561
2556
2562 cd -: changes to the last visited directory.
2557 cd -: changes to the last visited directory.
2563
2558
2564 cd -<n>: changes to the n-th directory in the directory history.
2559 cd -<n>: changes to the n-th directory in the directory history.
2565
2560
2566 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2561 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2567 (note: cd <bookmark_name> is enough if there is no
2562 (note: cd <bookmark_name> is enough if there is no
2568 directory <bookmark_name>, but a bookmark with the name exists.)
2563 directory <bookmark_name>, but a bookmark with the name exists.)
2569
2564
2570 Options:
2565 Options:
2571
2566
2572 -q: quiet. Do not print the working directory after the cd command is
2567 -q: quiet. Do not print the working directory after the cd command is
2573 executed. By default IPython's cd command does print this directory,
2568 executed. By default IPython's cd command does print this directory,
2574 since the default prompts do not display path information.
2569 since the default prompts do not display path information.
2575
2570
2576 Note that !cd doesn't work for this purpose because the shell where
2571 Note that !cd doesn't work for this purpose because the shell where
2577 !command runs is immediately discarded after executing 'command'."""
2572 !command runs is immediately discarded after executing 'command'."""
2578
2573
2579 parameter_s = parameter_s.strip()
2574 parameter_s = parameter_s.strip()
2580 #bkms = self.shell.persist.get("bookmarks",{})
2575 #bkms = self.shell.persist.get("bookmarks",{})
2581
2576
2582 numcd = re.match(r'(-)(\d+)$',parameter_s)
2577 numcd = re.match(r'(-)(\d+)$',parameter_s)
2583 # jump in directory history by number
2578 # jump in directory history by number
2584 if numcd:
2579 if numcd:
2585 nn = int(numcd.group(2))
2580 nn = int(numcd.group(2))
2586 try:
2581 try:
2587 ps = self.shell.user_ns['_dh'][nn]
2582 ps = self.shell.user_ns['_dh'][nn]
2588 except IndexError:
2583 except IndexError:
2589 print 'The requested directory does not exist in history.'
2584 print 'The requested directory does not exist in history.'
2590 return
2585 return
2591 else:
2586 else:
2592 opts = {}
2587 opts = {}
2593 else:
2588 else:
2594 #turn all non-space-escaping backslashes to slashes,
2589 #turn all non-space-escaping backslashes to slashes,
2595 # for c:\windows\directory\names\
2590 # for c:\windows\directory\names\
2596 parameter_s = re.sub(r'\\(?! )','/', parameter_s)
2591 parameter_s = re.sub(r'\\(?! )','/', parameter_s)
2597 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2592 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2598 # jump to previous
2593 # jump to previous
2599 if ps == '-':
2594 if ps == '-':
2600 try:
2595 try:
2601 ps = self.shell.user_ns['_dh'][-2]
2596 ps = self.shell.user_ns['_dh'][-2]
2602 except IndexError:
2597 except IndexError:
2603 print 'No previous directory to change to.'
2598 print 'No previous directory to change to.'
2604 return
2599 return
2605 # jump to bookmark if needed
2600 # jump to bookmark if needed
2606 else:
2601 else:
2607 if not os.path.isdir(ps) or opts.has_key('b'):
2602 if not os.path.isdir(ps) or opts.has_key('b'):
2608 bkms = self.db.get('bookmarks', {})
2603 bkms = self.db.get('bookmarks', {})
2609
2604
2610 if bkms.has_key(ps):
2605 if bkms.has_key(ps):
2611 target = bkms[ps]
2606 target = bkms[ps]
2612 print '(bookmark:%s) -> %s' % (ps,target)
2607 print '(bookmark:%s) -> %s' % (ps,target)
2613 ps = target
2608 ps = target
2614 else:
2609 else:
2615 if opts.has_key('b'):
2610 if opts.has_key('b'):
2616 error("Bookmark '%s' not found. "
2611 error("Bookmark '%s' not found. "
2617 "Use '%%bookmark -l' to see your bookmarks." % ps)
2612 "Use '%%bookmark -l' to see your bookmarks." % ps)
2618 return
2613 return
2619
2614
2620 # at this point ps should point to the target dir
2615 # at this point ps should point to the target dir
2621 if ps:
2616 if ps:
2622 try:
2617 try:
2623 os.chdir(os.path.expanduser(ps))
2618 os.chdir(os.path.expanduser(ps))
2624 ttitle = ("IPy:" + (
2619 ttitle = ("IPy:" + (
2625 os.getcwd() == '/' and '/' or os.path.basename(os.getcwd())))
2620 os.getcwd() == '/' and '/' or os.path.basename(os.getcwd())))
2626 platutils.set_term_title(ttitle)
2621 platutils.set_term_title(ttitle)
2627 except OSError:
2622 except OSError:
2628 print sys.exc_info()[1]
2623 print sys.exc_info()[1]
2629 else:
2624 else:
2630 self.shell.user_ns['_dh'].append(os.getcwd())
2625 self.shell.user_ns['_dh'].append(os.getcwd())
2631 else:
2626 else:
2632 os.chdir(self.shell.home_dir)
2627 os.chdir(self.shell.home_dir)
2633 platutils.set_term_title("IPy:~")
2628 platutils.set_term_title("IPy:~")
2634 self.shell.user_ns['_dh'].append(os.getcwd())
2629 self.shell.user_ns['_dh'].append(os.getcwd())
2635 if not 'q' in opts:
2630 if not 'q' in opts:
2636 print self.shell.user_ns['_dh'][-1]
2631 print self.shell.user_ns['_dh'][-1]
2637
2632
2638 def magic_dhist(self, parameter_s=''):
2633 def magic_dhist(self, parameter_s=''):
2639 """Print your history of visited directories.
2634 """Print your history of visited directories.
2640
2635
2641 %dhist -> print full history\\
2636 %dhist -> print full history\\
2642 %dhist n -> print last n entries only\\
2637 %dhist n -> print last n entries only\\
2643 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2638 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2644
2639
2645 This history is automatically maintained by the %cd command, and
2640 This history is automatically maintained by the %cd command, and
2646 always available as the global list variable _dh. You can use %cd -<n>
2641 always available as the global list variable _dh. You can use %cd -<n>
2647 to go to directory number <n>."""
2642 to go to directory number <n>."""
2648
2643
2649 dh = self.shell.user_ns['_dh']
2644 dh = self.shell.user_ns['_dh']
2650 if parameter_s:
2645 if parameter_s:
2651 try:
2646 try:
2652 args = map(int,parameter_s.split())
2647 args = map(int,parameter_s.split())
2653 except:
2648 except:
2654 self.arg_err(Magic.magic_dhist)
2649 self.arg_err(Magic.magic_dhist)
2655 return
2650 return
2656 if len(args) == 1:
2651 if len(args) == 1:
2657 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2652 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2658 elif len(args) == 2:
2653 elif len(args) == 2:
2659 ini,fin = args
2654 ini,fin = args
2660 else:
2655 else:
2661 self.arg_err(Magic.magic_dhist)
2656 self.arg_err(Magic.magic_dhist)
2662 return
2657 return
2663 else:
2658 else:
2664 ini,fin = 0,len(dh)
2659 ini,fin = 0,len(dh)
2665 nlprint(dh,
2660 nlprint(dh,
2666 header = 'Directory history (kept in _dh)',
2661 header = 'Directory history (kept in _dh)',
2667 start=ini,stop=fin)
2662 start=ini,stop=fin)
2668
2663
2669 def magic_env(self, parameter_s=''):
2664 def magic_env(self, parameter_s=''):
2670 """List environment variables."""
2665 """List environment variables."""
2671
2666
2672 return os.environ.data
2667 return os.environ.data
2673
2668
2674 def magic_pushd(self, parameter_s=''):
2669 def magic_pushd(self, parameter_s=''):
2675 """Place the current dir on stack and change directory.
2670 """Place the current dir on stack and change directory.
2676
2671
2677 Usage:\\
2672 Usage:\\
2678 %pushd ['dirname']
2673 %pushd ['dirname']
2679
2674
2680 %pushd with no arguments does a %pushd to your home directory.
2675 %pushd with no arguments does a %pushd to your home directory.
2681 """
2676 """
2682 if parameter_s == '': parameter_s = '~'
2677 if parameter_s == '': parameter_s = '~'
2683 dir_s = self.shell.dir_stack
2678 dir_s = self.shell.dir_stack
2684 if len(dir_s)>0 and os.path.expanduser(parameter_s) != \
2679 if len(dir_s)>0 and os.path.expanduser(parameter_s) != \
2685 os.path.expanduser(self.shell.dir_stack[0]):
2680 os.path.expanduser(self.shell.dir_stack[0]):
2686 try:
2681 try:
2687 self.magic_cd(parameter_s)
2682 self.magic_cd(parameter_s)
2688 dir_s.insert(0,os.getcwd().replace(self.home_dir,'~'))
2683 dir_s.insert(0,os.getcwd().replace(self.home_dir,'~'))
2689 self.magic_dirs()
2684 self.magic_dirs()
2690 except:
2685 except:
2691 print 'Invalid directory'
2686 print 'Invalid directory'
2692 else:
2687 else:
2693 print 'You are already there!'
2688 print 'You are already there!'
2694
2689
2695 def magic_popd(self, parameter_s=''):
2690 def magic_popd(self, parameter_s=''):
2696 """Change to directory popped off the top of the stack.
2691 """Change to directory popped off the top of the stack.
2697 """
2692 """
2698 if len (self.shell.dir_stack) > 1:
2693 if len (self.shell.dir_stack) > 1:
2699 self.shell.dir_stack.pop(0)
2694 self.shell.dir_stack.pop(0)
2700 self.magic_cd(self.shell.dir_stack[0])
2695 self.magic_cd(self.shell.dir_stack[0])
2701 print self.shell.dir_stack[0]
2696 print self.shell.dir_stack[0]
2702 else:
2697 else:
2703 print "You can't remove the starting directory from the stack:",\
2698 print "You can't remove the starting directory from the stack:",\
2704 self.shell.dir_stack
2699 self.shell.dir_stack
2705
2700
2706 def magic_dirs(self, parameter_s=''):
2701 def magic_dirs(self, parameter_s=''):
2707 """Return the current directory stack."""
2702 """Return the current directory stack."""
2708
2703
2709 return self.shell.dir_stack[:]
2704 return self.shell.dir_stack[:]
2710
2705
2711 def magic_sc(self, parameter_s=''):
2706 def magic_sc(self, parameter_s=''):
2712 """Shell capture - execute a shell command and capture its output.
2707 """Shell capture - execute a shell command and capture its output.
2713
2708
2714 DEPRECATED. Suboptimal, retained for backwards compatibility.
2709 DEPRECATED. Suboptimal, retained for backwards compatibility.
2715
2710
2716 You should use the form 'var = !command' instead. Example:
2711 You should use the form 'var = !command' instead. Example:
2717
2712
2718 "%sc -l myfiles = ls ~" should now be written as
2713 "%sc -l myfiles = ls ~" should now be written as
2719
2714
2720 "myfiles = !ls ~"
2715 "myfiles = !ls ~"
2721
2716
2722 myfiles.s, myfiles.l and myfiles.n still apply as documented
2717 myfiles.s, myfiles.l and myfiles.n still apply as documented
2723 below.
2718 below.
2724
2719
2725 --
2720 --
2726 %sc [options] varname=command
2721 %sc [options] varname=command
2727
2722
2728 IPython will run the given command using commands.getoutput(), and
2723 IPython will run the given command using commands.getoutput(), and
2729 will then update the user's interactive namespace with a variable
2724 will then update the user's interactive namespace with a variable
2730 called varname, containing the value of the call. Your command can
2725 called varname, containing the value of the call. Your command can
2731 contain shell wildcards, pipes, etc.
2726 contain shell wildcards, pipes, etc.
2732
2727
2733 The '=' sign in the syntax is mandatory, and the variable name you
2728 The '=' sign in the syntax is mandatory, and the variable name you
2734 supply must follow Python's standard conventions for valid names.
2729 supply must follow Python's standard conventions for valid names.
2735
2730
2736 (A special format without variable name exists for internal use)
2731 (A special format without variable name exists for internal use)
2737
2732
2738 Options:
2733 Options:
2739
2734
2740 -l: list output. Split the output on newlines into a list before
2735 -l: list output. Split the output on newlines into a list before
2741 assigning it to the given variable. By default the output is stored
2736 assigning it to the given variable. By default the output is stored
2742 as a single string.
2737 as a single string.
2743
2738
2744 -v: verbose. Print the contents of the variable.
2739 -v: verbose. Print the contents of the variable.
2745
2740
2746 In most cases you should not need to split as a list, because the
2741 In most cases you should not need to split as a list, because the
2747 returned value is a special type of string which can automatically
2742 returned value is a special type of string which can automatically
2748 provide its contents either as a list (split on newlines) or as a
2743 provide its contents either as a list (split on newlines) or as a
2749 space-separated string. These are convenient, respectively, either
2744 space-separated string. These are convenient, respectively, either
2750 for sequential processing or to be passed to a shell command.
2745 for sequential processing or to be passed to a shell command.
2751
2746
2752 For example:
2747 For example:
2753
2748
2754 # Capture into variable a
2749 # Capture into variable a
2755 In [9]: sc a=ls *py
2750 In [9]: sc a=ls *py
2756
2751
2757 # a is a string with embedded newlines
2752 # a is a string with embedded newlines
2758 In [10]: a
2753 In [10]: a
2759 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2754 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2760
2755
2761 # which can be seen as a list:
2756 # which can be seen as a list:
2762 In [11]: a.l
2757 In [11]: a.l
2763 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2758 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2764
2759
2765 # or as a whitespace-separated string:
2760 # or as a whitespace-separated string:
2766 In [12]: a.s
2761 In [12]: a.s
2767 Out[12]: 'setup.py win32_manual_post_install.py'
2762 Out[12]: 'setup.py win32_manual_post_install.py'
2768
2763
2769 # a.s is useful to pass as a single command line:
2764 # a.s is useful to pass as a single command line:
2770 In [13]: !wc -l $a.s
2765 In [13]: !wc -l $a.s
2771 146 setup.py
2766 146 setup.py
2772 130 win32_manual_post_install.py
2767 130 win32_manual_post_install.py
2773 276 total
2768 276 total
2774
2769
2775 # while the list form is useful to loop over:
2770 # while the list form is useful to loop over:
2776 In [14]: for f in a.l:
2771 In [14]: for f in a.l:
2777 ....: !wc -l $f
2772 ....: !wc -l $f
2778 ....:
2773 ....:
2779 146 setup.py
2774 146 setup.py
2780 130 win32_manual_post_install.py
2775 130 win32_manual_post_install.py
2781
2776
2782 Similiarly, the lists returned by the -l option are also special, in
2777 Similiarly, the lists returned by the -l option are also special, in
2783 the sense that you can equally invoke the .s attribute on them to
2778 the sense that you can equally invoke the .s attribute on them to
2784 automatically get a whitespace-separated string from their contents:
2779 automatically get a whitespace-separated string from their contents:
2785
2780
2786 In [1]: sc -l b=ls *py
2781 In [1]: sc -l b=ls *py
2787
2782
2788 In [2]: b
2783 In [2]: b
2789 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2784 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2790
2785
2791 In [3]: b.s
2786 In [3]: b.s
2792 Out[3]: 'setup.py win32_manual_post_install.py'
2787 Out[3]: 'setup.py win32_manual_post_install.py'
2793
2788
2794 In summary, both the lists and strings used for ouptut capture have
2789 In summary, both the lists and strings used for ouptut capture have
2795 the following special attributes:
2790 the following special attributes:
2796
2791
2797 .l (or .list) : value as list.
2792 .l (or .list) : value as list.
2798 .n (or .nlstr): value as newline-separated string.
2793 .n (or .nlstr): value as newline-separated string.
2799 .s (or .spstr): value as space-separated string.
2794 .s (or .spstr): value as space-separated string.
2800 """
2795 """
2801
2796
2802 opts,args = self.parse_options(parameter_s,'lv')
2797 opts,args = self.parse_options(parameter_s,'lv')
2803 # Try to get a variable name and command to run
2798 # Try to get a variable name and command to run
2804 try:
2799 try:
2805 # the variable name must be obtained from the parse_options
2800 # the variable name must be obtained from the parse_options
2806 # output, which uses shlex.split to strip options out.
2801 # output, which uses shlex.split to strip options out.
2807 var,_ = args.split('=',1)
2802 var,_ = args.split('=',1)
2808 var = var.strip()
2803 var = var.strip()
2809 # But the the command has to be extracted from the original input
2804 # But the the command has to be extracted from the original input
2810 # parameter_s, not on what parse_options returns, to avoid the
2805 # parameter_s, not on what parse_options returns, to avoid the
2811 # quote stripping which shlex.split performs on it.
2806 # quote stripping which shlex.split performs on it.
2812 _,cmd = parameter_s.split('=',1)
2807 _,cmd = parameter_s.split('=',1)
2813 except ValueError:
2808 except ValueError:
2814 var,cmd = '',''
2809 var,cmd = '',''
2815 # If all looks ok, proceed
2810 # If all looks ok, proceed
2816 out,err = self.shell.getoutputerror(cmd)
2811 out,err = self.shell.getoutputerror(cmd)
2817 if err:
2812 if err:
2818 print >> Term.cerr,err
2813 print >> Term.cerr,err
2819 if opts.has_key('l'):
2814 if opts.has_key('l'):
2820 out = SList(out.split('\n'))
2815 out = SList(out.split('\n'))
2821 else:
2816 else:
2822 out = LSString(out)
2817 out = LSString(out)
2823 if opts.has_key('v'):
2818 if opts.has_key('v'):
2824 print '%s ==\n%s' % (var,pformat(out))
2819 print '%s ==\n%s' % (var,pformat(out))
2825 if var:
2820 if var:
2826 self.shell.user_ns.update({var:out})
2821 self.shell.user_ns.update({var:out})
2827 else:
2822 else:
2828 return out
2823 return out
2829
2824
2830 def magic_sx(self, parameter_s=''):
2825 def magic_sx(self, parameter_s=''):
2831 """Shell execute - run a shell command and capture its output.
2826 """Shell execute - run a shell command and capture its output.
2832
2827
2833 %sx command
2828 %sx command
2834
2829
2835 IPython will run the given command using commands.getoutput(), and
2830 IPython will run the given command using commands.getoutput(), and
2836 return the result formatted as a list (split on '\\n'). Since the
2831 return the result formatted as a list (split on '\\n'). Since the
2837 output is _returned_, it will be stored in ipython's regular output
2832 output is _returned_, it will be stored in ipython's regular output
2838 cache Out[N] and in the '_N' automatic variables.
2833 cache Out[N] and in the '_N' automatic variables.
2839
2834
2840 Notes:
2835 Notes:
2841
2836
2842 1) If an input line begins with '!!', then %sx is automatically
2837 1) If an input line begins with '!!', then %sx is automatically
2843 invoked. That is, while:
2838 invoked. That is, while:
2844 !ls
2839 !ls
2845 causes ipython to simply issue system('ls'), typing
2840 causes ipython to simply issue system('ls'), typing
2846 !!ls
2841 !!ls
2847 is a shorthand equivalent to:
2842 is a shorthand equivalent to:
2848 %sx ls
2843 %sx ls
2849
2844
2850 2) %sx differs from %sc in that %sx automatically splits into a list,
2845 2) %sx differs from %sc in that %sx automatically splits into a list,
2851 like '%sc -l'. The reason for this is to make it as easy as possible
2846 like '%sc -l'. The reason for this is to make it as easy as possible
2852 to process line-oriented shell output via further python commands.
2847 to process line-oriented shell output via further python commands.
2853 %sc is meant to provide much finer control, but requires more
2848 %sc is meant to provide much finer control, but requires more
2854 typing.
2849 typing.
2855
2850
2856 3) Just like %sc -l, this is a list with special attributes:
2851 3) Just like %sc -l, this is a list with special attributes:
2857
2852
2858 .l (or .list) : value as list.
2853 .l (or .list) : value as list.
2859 .n (or .nlstr): value as newline-separated string.
2854 .n (or .nlstr): value as newline-separated string.
2860 .s (or .spstr): value as whitespace-separated string.
2855 .s (or .spstr): value as whitespace-separated string.
2861
2856
2862 This is very useful when trying to use such lists as arguments to
2857 This is very useful when trying to use such lists as arguments to
2863 system commands."""
2858 system commands."""
2864
2859
2865 if parameter_s:
2860 if parameter_s:
2866 out,err = self.shell.getoutputerror(parameter_s)
2861 out,err = self.shell.getoutputerror(parameter_s)
2867 if err:
2862 if err:
2868 print >> Term.cerr,err
2863 print >> Term.cerr,err
2869 return SList(out.split('\n'))
2864 return SList(out.split('\n'))
2870
2865
2871 def magic_bg(self, parameter_s=''):
2866 def magic_bg(self, parameter_s=''):
2872 """Run a job in the background, in a separate thread.
2867 """Run a job in the background, in a separate thread.
2873
2868
2874 For example,
2869 For example,
2875
2870
2876 %bg myfunc(x,y,z=1)
2871 %bg myfunc(x,y,z=1)
2877
2872
2878 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2873 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2879 execution starts, a message will be printed indicating the job
2874 execution starts, a message will be printed indicating the job
2880 number. If your job number is 5, you can use
2875 number. If your job number is 5, you can use
2881
2876
2882 myvar = jobs.result(5) or myvar = jobs[5].result
2877 myvar = jobs.result(5) or myvar = jobs[5].result
2883
2878
2884 to assign this result to variable 'myvar'.
2879 to assign this result to variable 'myvar'.
2885
2880
2886 IPython has a job manager, accessible via the 'jobs' object. You can
2881 IPython has a job manager, accessible via the 'jobs' object. You can
2887 type jobs? to get more information about it, and use jobs.<TAB> to see
2882 type jobs? to get more information about it, and use jobs.<TAB> to see
2888 its attributes. All attributes not starting with an underscore are
2883 its attributes. All attributes not starting with an underscore are
2889 meant for public use.
2884 meant for public use.
2890
2885
2891 In particular, look at the jobs.new() method, which is used to create
2886 In particular, look at the jobs.new() method, which is used to create
2892 new jobs. This magic %bg function is just a convenience wrapper
2887 new jobs. This magic %bg function is just a convenience wrapper
2893 around jobs.new(), for expression-based jobs. If you want to create a
2888 around jobs.new(), for expression-based jobs. If you want to create a
2894 new job with an explicit function object and arguments, you must call
2889 new job with an explicit function object and arguments, you must call
2895 jobs.new() directly.
2890 jobs.new() directly.
2896
2891
2897 The jobs.new docstring also describes in detail several important
2892 The jobs.new docstring also describes in detail several important
2898 caveats associated with a thread-based model for background job
2893 caveats associated with a thread-based model for background job
2899 execution. Type jobs.new? for details.
2894 execution. Type jobs.new? for details.
2900
2895
2901 You can check the status of all jobs with jobs.status().
2896 You can check the status of all jobs with jobs.status().
2902
2897
2903 The jobs variable is set by IPython into the Python builtin namespace.
2898 The jobs variable is set by IPython into the Python builtin namespace.
2904 If you ever declare a variable named 'jobs', you will shadow this
2899 If you ever declare a variable named 'jobs', you will shadow this
2905 name. You can either delete your global jobs variable to regain
2900 name. You can either delete your global jobs variable to regain
2906 access to the job manager, or make a new name and assign it manually
2901 access to the job manager, or make a new name and assign it manually
2907 to the manager (stored in IPython's namespace). For example, to
2902 to the manager (stored in IPython's namespace). For example, to
2908 assign the job manager to the Jobs name, use:
2903 assign the job manager to the Jobs name, use:
2909
2904
2910 Jobs = __builtins__.jobs"""
2905 Jobs = __builtins__.jobs"""
2911
2906
2912 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2907 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2913
2908
2914
2909
2915 def magic_bookmark(self, parameter_s=''):
2910 def magic_bookmark(self, parameter_s=''):
2916 """Manage IPython's bookmark system.
2911 """Manage IPython's bookmark system.
2917
2912
2918 %bookmark <name> - set bookmark to current dir
2913 %bookmark <name> - set bookmark to current dir
2919 %bookmark <name> <dir> - set bookmark to <dir>
2914 %bookmark <name> <dir> - set bookmark to <dir>
2920 %bookmark -l - list all bookmarks
2915 %bookmark -l - list all bookmarks
2921 %bookmark -d <name> - remove bookmark
2916 %bookmark -d <name> - remove bookmark
2922 %bookmark -r - remove all bookmarks
2917 %bookmark -r - remove all bookmarks
2923
2918
2924 You can later on access a bookmarked folder with:
2919 You can later on access a bookmarked folder with:
2925 %cd -b <name>
2920 %cd -b <name>
2926 or simply '%cd <name>' if there is no directory called <name> AND
2921 or simply '%cd <name>' if there is no directory called <name> AND
2927 there is such a bookmark defined.
2922 there is such a bookmark defined.
2928
2923
2929 Your bookmarks persist through IPython sessions, but they are
2924 Your bookmarks persist through IPython sessions, but they are
2930 associated with each profile."""
2925 associated with each profile."""
2931
2926
2932 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2927 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2933 if len(args) > 2:
2928 if len(args) > 2:
2934 error('You can only give at most two arguments')
2929 error('You can only give at most two arguments')
2935 return
2930 return
2936
2931
2937 bkms = self.db.get('bookmarks',{})
2932 bkms = self.db.get('bookmarks',{})
2938
2933
2939 if opts.has_key('d'):
2934 if opts.has_key('d'):
2940 try:
2935 try:
2941 todel = args[0]
2936 todel = args[0]
2942 except IndexError:
2937 except IndexError:
2943 error('You must provide a bookmark to delete')
2938 error('You must provide a bookmark to delete')
2944 else:
2939 else:
2945 try:
2940 try:
2946 del bkms[todel]
2941 del bkms[todel]
2947 except:
2942 except:
2948 error("Can't delete bookmark '%s'" % todel)
2943 error("Can't delete bookmark '%s'" % todel)
2949 elif opts.has_key('r'):
2944 elif opts.has_key('r'):
2950 bkms = {}
2945 bkms = {}
2951 elif opts.has_key('l'):
2946 elif opts.has_key('l'):
2952 bks = bkms.keys()
2947 bks = bkms.keys()
2953 bks.sort()
2948 bks.sort()
2954 if bks:
2949 if bks:
2955 size = max(map(len,bks))
2950 size = max(map(len,bks))
2956 else:
2951 else:
2957 size = 0
2952 size = 0
2958 fmt = '%-'+str(size)+'s -> %s'
2953 fmt = '%-'+str(size)+'s -> %s'
2959 print 'Current bookmarks:'
2954 print 'Current bookmarks:'
2960 for bk in bks:
2955 for bk in bks:
2961 print fmt % (bk,bkms[bk])
2956 print fmt % (bk,bkms[bk])
2962 else:
2957 else:
2963 if not args:
2958 if not args:
2964 error("You must specify the bookmark name")
2959 error("You must specify the bookmark name")
2965 elif len(args)==1:
2960 elif len(args)==1:
2966 bkms[args[0]] = os.getcwd()
2961 bkms[args[0]] = os.getcwd()
2967 elif len(args)==2:
2962 elif len(args)==2:
2968 bkms[args[0]] = args[1]
2963 bkms[args[0]] = args[1]
2969 self.db['bookmarks'] = bkms
2964 self.db['bookmarks'] = bkms
2970
2965
2971 def magic_pycat(self, parameter_s=''):
2966 def magic_pycat(self, parameter_s=''):
2972 """Show a syntax-highlighted file through a pager.
2967 """Show a syntax-highlighted file through a pager.
2973
2968
2974 This magic is similar to the cat utility, but it will assume the file
2969 This magic is similar to the cat utility, but it will assume the file
2975 to be Python source and will show it with syntax highlighting. """
2970 to be Python source and will show it with syntax highlighting. """
2976
2971
2977 try:
2972 try:
2978 filename = get_py_filename(parameter_s)
2973 filename = get_py_filename(parameter_s)
2979 cont = file_read(filename)
2974 cont = file_read(filename)
2980 except IOError:
2975 except IOError:
2981 try:
2976 try:
2982 cont = eval(parameter_s,self.user_ns)
2977 cont = eval(parameter_s,self.user_ns)
2983 except NameError:
2978 except NameError:
2984 cont = None
2979 cont = None
2985 if cont is None:
2980 if cont is None:
2986 print "Error: no such file or variable"
2981 print "Error: no such file or variable"
2987 return
2982 return
2988
2983
2989 page(self.shell.pycolorize(cont),
2984 page(self.shell.pycolorize(cont),
2990 screen_lines=self.shell.rc.screen_length)
2985 screen_lines=self.shell.rc.screen_length)
2991
2986
2992 def magic_cpaste(self, parameter_s=''):
2987 def magic_cpaste(self, parameter_s=''):
2993 """Allows you to paste & execute a pre-formatted code block from clipboard
2988 """Allows you to paste & execute a pre-formatted code block from clipboard
2994
2989
2995 You must terminate the block with '--' (two minus-signs) alone on the
2990 You must terminate the block with '--' (two minus-signs) alone on the
2996 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
2991 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
2997 is the new sentinel for this operation)
2992 is the new sentinel for this operation)
2998
2993
2999 The block is dedented prior to execution to enable execution of
2994 The block is dedented prior to execution to enable execution of
3000 method definitions. '>' characters at the beginning of a line is
2995 method definitions. '>' characters at the beginning of a line is
3001 ignored, to allow pasting directly from e-mails. The executed block
2996 ignored, to allow pasting directly from e-mails. The executed block
3002 is also assigned to variable named 'pasted_block' for later editing
2997 is also assigned to variable named 'pasted_block' for later editing
3003 with '%edit pasted_block'.
2998 with '%edit pasted_block'.
3004
2999
3005 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
3000 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
3006 This assigns the pasted block to variable 'foo' as string, without
3001 This assigns the pasted block to variable 'foo' as string, without
3007 dedenting or executing it.
3002 dedenting or executing it.
3008
3003
3009 Do not be alarmed by garbled output on Windows (it's a readline bug).
3004 Do not be alarmed by garbled output on Windows (it's a readline bug).
3010 Just press enter and type -- (and press enter again) and the block
3005 Just press enter and type -- (and press enter again) and the block
3011 will be what was just pasted.
3006 will be what was just pasted.
3012
3007
3013 IPython statements (magics, shell escapes) are not supported (yet).
3008 IPython statements (magics, shell escapes) are not supported (yet).
3014 """
3009 """
3015 opts,args = self.parse_options(parameter_s,'s:',mode='string')
3010 opts,args = self.parse_options(parameter_s,'s:',mode='string')
3016 par = args.strip()
3011 par = args.strip()
3017 sentinel = opts.get('s','--')
3012 sentinel = opts.get('s','--')
3018
3013
3019 from IPython import iplib
3014 from IPython import iplib
3020 lines = []
3015 lines = []
3021 print "Pasting code; enter '%s' alone on the line to stop." % sentinel
3016 print "Pasting code; enter '%s' alone on the line to stop." % sentinel
3022 while 1:
3017 while 1:
3023 l = iplib.raw_input_original(':')
3018 l = iplib.raw_input_original(':')
3024 if l ==sentinel:
3019 if l ==sentinel:
3025 break
3020 break
3026 lines.append(l.lstrip('>'))
3021 lines.append(l.lstrip('>'))
3027 block = "\n".join(lines) + '\n'
3022 block = "\n".join(lines) + '\n'
3028 #print "block:\n",block
3023 #print "block:\n",block
3029 if not par:
3024 if not par:
3030 b = textwrap.dedent(block)
3025 b = textwrap.dedent(block)
3031 exec b in self.user_ns
3026 exec b in self.user_ns
3032 self.user_ns['pasted_block'] = b
3027 self.user_ns['pasted_block'] = b
3033 else:
3028 else:
3034 self.user_ns[par] = block
3029 self.user_ns[par] = block
3035 print "Block assigned to '%s'" % par
3030 print "Block assigned to '%s'" % par
3036
3031
3037 def magic_quickref(self,arg):
3032 def magic_quickref(self,arg):
3038 """ Show a quick reference sheet """
3033 """ Show a quick reference sheet """
3039 import IPython.usage
3034 import IPython.usage
3040 qr = IPython.usage.quick_reference + self.magic_magic('-brief')
3035 qr = IPython.usage.quick_reference + self.magic_magic('-brief')
3041
3036
3042 page(qr)
3037 page(qr)
3043
3038
3044 def magic_upgrade(self,arg):
3039 def magic_upgrade(self,arg):
3045 """ Upgrade your IPython installation
3040 """ Upgrade your IPython installation
3046
3041
3047 This will copy the config files that don't yet exist in your
3042 This will copy the config files that don't yet exist in your
3048 ipython dir from the system config dir. Use this after upgrading
3043 ipython dir from the system config dir. Use this after upgrading
3049 IPython if you don't wish to delete your .ipython dir.
3044 IPython if you don't wish to delete your .ipython dir.
3050
3045
3051 Call with -nolegacy to get rid of ipythonrc* files (recommended for
3046 Call with -nolegacy to get rid of ipythonrc* files (recommended for
3052 new users)
3047 new users)
3053
3048
3054 """
3049 """
3055 ip = self.getapi()
3050 ip = self.getapi()
3056 ipinstallation = path(IPython.__file__).dirname()
3051 ipinstallation = path(IPython.__file__).dirname()
3057 upgrade_script = '%s "%s"' % (sys.executable,ipinstallation / 'upgrade_dir.py')
3052 upgrade_script = '%s "%s"' % (sys.executable,ipinstallation / 'upgrade_dir.py')
3058 src_config = ipinstallation / 'UserConfig'
3053 src_config = ipinstallation / 'UserConfig'
3059 userdir = path(ip.options.ipythondir)
3054 userdir = path(ip.options.ipythondir)
3060 cmd = '%s "%s" "%s"' % (upgrade_script, src_config, userdir)
3055 cmd = '%s "%s" "%s"' % (upgrade_script, src_config, userdir)
3061 print ">",cmd
3056 print ">",cmd
3062 shell(cmd)
3057 shell(cmd)
3063 if arg == '-nolegacy':
3058 if arg == '-nolegacy':
3064 legacy = userdir.files('ipythonrc*')
3059 legacy = userdir.files('ipythonrc*')
3065 print "Nuking legacy files:",legacy
3060 print "Nuking legacy files:",legacy
3066
3061
3067 [p.remove() for p in legacy]
3062 [p.remove() for p in legacy]
3068 suffix = (sys.platform == 'win32' and '.ini' or '')
3063 suffix = (sys.platform == 'win32' and '.ini' or '')
3069 (userdir / ('ipythonrc' + suffix)).write_text('# Empty, see ipy_user_conf.py\n')
3064 (userdir / ('ipythonrc' + suffix)).write_text('# Empty, see ipy_user_conf.py\n')
3070
3065
3071
3066
3072 # end Magic
3067 # end Magic
@@ -1,9549 +1,9545 b''
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
2 \lyxformat 221
3 \textclass article
3 \textclass article
4 \begin_preamble
4 \begin_preamble
5 %\usepackage{ae,aecompl}
5 %\usepackage{ae,aecompl}
6 \usepackage{color}
6 \usepackage{color}
7
7
8 % A few colors to replace the defaults for certain link types
8 % A few colors to replace the defaults for certain link types
9 \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
9 \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
10 \definecolor{darkorange}{rgb}{.71,0.21,0.01}
10 \definecolor{darkorange}{rgb}{.71,0.21,0.01}
11 \definecolor{darkred}{rgb}{.52,0.08,0.01}
11 \definecolor{darkred}{rgb}{.52,0.08,0.01}
12 \definecolor{darkgreen}{rgb}{.12,.54,.11}
12 \definecolor{darkgreen}{rgb}{.12,.54,.11}
13
13
14 % Use and configure listings package for nicely formatted code
14 % Use and configure listings package for nicely formatted code
15 \usepackage{listings}
15 \usepackage{listings}
16 \lstset{
16 \lstset{
17 language=Python,
17 language=Python,
18 basicstyle=\small\ttfamily,
18 basicstyle=\small\ttfamily,
19 commentstyle=\ttfamily\color{blue},
19 commentstyle=\ttfamily\color{blue},
20 stringstyle=\ttfamily\color{darkorange},
20 stringstyle=\ttfamily\color{darkorange},
21 showstringspaces=false,
21 showstringspaces=false,
22 breaklines=true,
22 breaklines=true,
23 postbreak = \space\dots
23 postbreak = \space\dots
24 }
24 }
25
25
26 \usepackage[%pdftex, % needed for pdflatex
26 \usepackage[%pdftex, % needed for pdflatex
27 breaklinks=true, % so long urls are correctly broken across lines
27 breaklinks=true, % so long urls are correctly broken across lines
28 colorlinks=true,
28 colorlinks=true,
29 urlcolor=blue,
29 urlcolor=blue,
30 linkcolor=darkred,
30 linkcolor=darkred,
31 citecolor=darkgreen,
31 citecolor=darkgreen,
32 ]{hyperref}
32 ]{hyperref}
33
33
34 \usepackage{html}
34 \usepackage{html}
35
35
36 % This helps prevent overly long lines that stretch beyond the margins
36 % This helps prevent overly long lines that stretch beyond the margins
37 \sloppy
37 \sloppy
38
38
39 % Define a \codelist command which either uses listings for latex, or
39 % Define a \codelist command which either uses listings for latex, or
40 % plain verbatim for html (since latex2html doesn't understand the
40 % plain verbatim for html (since latex2html doesn't understand the
41 % listings package).
41 % listings package).
42 \usepackage{verbatim}
42 \usepackage{verbatim}
43 \newcommand{\codelist}[1] {
43 \newcommand{\codelist}[1] {
44 \latex{\lstinputlisting{#1}}
44 \latex{\lstinputlisting{#1}}
45 \html{\verbatiminput{#1}}
45 \html{\verbatiminput{#1}}
46 }
46 }
47 \end_preamble
47 \end_preamble
48 \language english
48 \language english
49 \inputencoding latin1
49 \inputencoding latin1
50 \fontscheme palatino
50 \fontscheme palatino
51 \graphics default
51 \graphics default
52 \paperfontsize 11
52 \paperfontsize 11
53 \spacing single
53 \spacing single
54 \papersize Default
54 \papersize Default
55 \paperpackage a4
55 \paperpackage a4
56 \use_geometry 1
56 \use_geometry 1
57 \use_amsmath 0
57 \use_amsmath 0
58 \use_natbib 0
58 \use_natbib 0
59 \use_numerical_citations 0
59 \use_numerical_citations 0
60 \paperorientation portrait
60 \paperorientation portrait
61 \leftmargin 1in
61 \leftmargin 1in
62 \topmargin 1in
62 \topmargin 1in
63 \rightmargin 1in
63 \rightmargin 1in
64 \bottommargin 1in
64 \bottommargin 1in
65 \secnumdepth 3
65 \secnumdepth 3
66 \tocdepth 3
66 \tocdepth 3
67 \paragraph_separation skip
67 \paragraph_separation skip
68 \defskip medskip
68 \defskip medskip
69 \quotes_language english
69 \quotes_language english
70 \quotes_times 2
70 \quotes_times 2
71 \papercolumns 1
71 \papercolumns 1
72 \papersides 2
72 \papersides 2
73 \paperpagestyle fancy
73 \paperpagestyle fancy
74
74
75 \layout Title
75 \layout Title
76
76
77 IPython
77 IPython
78 \newline
78 \newline
79
79
80 \size larger
80 \size larger
81 An enhanced Interactive Python
81 An enhanced Interactive Python
82 \size large
82 \size large
83
83
84 \newline
84 \newline
85 User Manual, v.
85 User Manual, v.
86 __version__
86 __version__
87 \layout Author
87 \layout Author
88
88
89 Fernando PοΏ½rez
89 Fernando PοΏ½rez
90 \begin_inset Foot
90 \begin_inset Foot
91 collapsed true
91 collapsed true
92
92
93 \layout Standard
93 \layout Standard
94
94
95
95
96 \size scriptsize
96 \size scriptsize
97 Department of Applied Mathematics, University of Colorado at Boulder.
97 Department of Applied Mathematics, University of Colorado at Boulder.
98
98
99 \family typewriter
99 \family typewriter
100 <Fernando.Perez@colorado.edu>
100 <Fernando.Perez@colorado.edu>
101 \end_inset
101 \end_inset
102
102
103
103
104 \layout Standard
104 \layout Standard
105
105
106
106
107 \begin_inset ERT
107 \begin_inset ERT
108 status Collapsed
108 status Collapsed
109
109
110 \layout Standard
110 \layout Standard
111
111
112 \backslash
112 \backslash
113 latex{
113 latex{
114 \end_inset
114 \end_inset
115
115
116
116
117 \begin_inset LatexCommand \tableofcontents{}
117 \begin_inset LatexCommand \tableofcontents{}
118
118
119 \end_inset
119 \end_inset
120
120
121
121
122 \begin_inset ERT
122 \begin_inset ERT
123 status Collapsed
123 status Collapsed
124
124
125 \layout Standard
125 \layout Standard
126 }
126 }
127 \end_inset
127 \end_inset
128
128
129
129
130 \layout Standard
130 \layout Standard
131
131
132
132
133 \begin_inset ERT
133 \begin_inset ERT
134 status Open
134 status Open
135
135
136 \layout Standard
136 \layout Standard
137
137
138 \backslash
138 \backslash
139 html{
139 html{
140 \backslash
140 \backslash
141 bodytext{bgcolor=#ffffff}}
141 bodytext{bgcolor=#ffffff}}
142 \end_inset
142 \end_inset
143
143
144
144
145 \layout Section
145 \layout Section
146 \pagebreak_top
146 \pagebreak_top
147 Overview
147 Overview
148 \layout Standard
148 \layout Standard
149
149
150 One of Python's most useful features is its interactive interpreter.
150 One of Python's most useful features is its interactive interpreter.
151 This system allows very fast testing of ideas without the overhead of creating
151 This system allows very fast testing of ideas without the overhead of creating
152 test files as is typical in most programming languages.
152 test files as is typical in most programming languages.
153 However, the interpreter supplied with the standard Python distribution
153 However, the interpreter supplied with the standard Python distribution
154 is somewhat limited for extended interactive use.
154 is somewhat limited for extended interactive use.
155 \layout Standard
155 \layout Standard
156
156
157 IPython is a free software project (released under the BSD license) which
157 IPython is a free software project (released under the BSD license) which
158 tries to:
158 tries to:
159 \layout Enumerate
159 \layout Enumerate
160
160
161 Provide an interactive shell superior to Python's default.
161 Provide an interactive shell superior to Python's default.
162 IPython has many features for object introspection, system shell access,
162 IPython has many features for object introspection, system shell access,
163 and its own special command system for adding functionality when working
163 and its own special command system for adding functionality when working
164 interactively.
164 interactively.
165 It tries to be a very efficient environment both for Python code development
165 It tries to be a very efficient environment both for Python code development
166 and for exploration of problems using Python objects (in situations like
166 and for exploration of problems using Python objects (in situations like
167 data analysis).
167 data analysis).
168 \layout Enumerate
168 \layout Enumerate
169
169
170 Serve as an embeddable, ready to use interpreter for your own programs.
170 Serve as an embeddable, ready to use interpreter for your own programs.
171 IPython can be started with a single call from inside another program,
171 IPython can be started with a single call from inside another program,
172 providing access to the current namespace.
172 providing access to the current namespace.
173 This can be very useful both for debugging purposes and for situations
173 This can be very useful both for debugging purposes and for situations
174 where a blend of batch-processing and interactive exploration are needed.
174 where a blend of batch-processing and interactive exploration are needed.
175 \layout Enumerate
175 \layout Enumerate
176
176
177 Offer a flexible framework which can be used as the base environment for
177 Offer a flexible framework which can be used as the base environment for
178 other systems with Python as the underlying language.
178 other systems with Python as the underlying language.
179 Specifically scientific environments like Mathematica, IDL and Matlab inspired
179 Specifically scientific environments like Mathematica, IDL and Matlab inspired
180 its design, but similar ideas can be useful in many fields.
180 its design, but similar ideas can be useful in many fields.
181 \layout Enumerate
181 \layout Enumerate
182
182
183 Allow interactive testing of threaded graphical toolkits.
183 Allow interactive testing of threaded graphical toolkits.
184 IPython has support for interactive, non-blocking control of GTK, Qt and
184 IPython has support for interactive, non-blocking control of GTK, Qt and
185 WX applications via special threading flags.
185 WX applications via special threading flags.
186 The normal Python shell can only do this for Tkinter applications.
186 The normal Python shell can only do this for Tkinter applications.
187 \layout Subsection
187 \layout Subsection
188
188
189 Main features
189 Main features
190 \layout Itemize
190 \layout Itemize
191
191
192 Dynamic object introspection.
192 Dynamic object introspection.
193 One can access docstrings, function definition prototypes, source code,
193 One can access docstrings, function definition prototypes, source code,
194 source files and other details of any object accessible to the interpreter
194 source files and other details of any object accessible to the interpreter
195 with a single keystroke (`
195 with a single keystroke (`
196 \family typewriter
196 \family typewriter
197 ?
197 ?
198 \family default
198 \family default
199 ', and using `
199 ', and using `
200 \family typewriter
200 \family typewriter
201 ??
201 ??
202 \family default
202 \family default
203 ' provides additional detail).
203 ' provides additional detail).
204 \layout Itemize
204 \layout Itemize
205
205
206 Searching through modules and namespaces with `
206 Searching through modules and namespaces with `
207 \family typewriter
207 \family typewriter
208 *
208 *
209 \family default
209 \family default
210 ' wildcards, both when using the `
210 ' wildcards, both when using the `
211 \family typewriter
211 \family typewriter
212 ?
212 ?
213 \family default
213 \family default
214 ' system and via the
214 ' system and via the
215 \family typewriter
215 \family typewriter
216 %psearch
216 %psearch
217 \family default
217 \family default
218 command.
218 command.
219 \layout Itemize
219 \layout Itemize
220
220
221 Completion in the local namespace, by typing TAB at the prompt.
221 Completion in the local namespace, by typing TAB at the prompt.
222 This works for keywords, methods, variables and files in the current directory.
222 This works for keywords, methods, variables and files in the current directory.
223 This is supported via the readline library, and full access to configuring
223 This is supported via the readline library, and full access to configuring
224 readline's behavior is provided.
224 readline's behavior is provided.
225 \layout Itemize
225 \layout Itemize
226
226
227 Numbered input/output prompts with command history (persistent across sessions
227 Numbered input/output prompts with command history (persistent across sessions
228 and tied to each profile), full searching in this history and caching of
228 and tied to each profile), full searching in this history and caching of
229 all input and output.
229 all input and output.
230 \layout Itemize
230 \layout Itemize
231
231
232 User-extensible `magic' commands.
232 User-extensible `magic' commands.
233 A set of commands prefixed with
233 A set of commands prefixed with
234 \family typewriter
234 \family typewriter
235 %
235 %
236 \family default
236 \family default
237 is available for controlling IPython itself and provides directory control,
237 is available for controlling IPython itself and provides directory control,
238 namespace information and many aliases to common system shell commands.
238 namespace information and many aliases to common system shell commands.
239 \layout Itemize
239 \layout Itemize
240
240
241 Alias facility for defining your own system aliases.
241 Alias facility for defining your own system aliases.
242 \layout Itemize
242 \layout Itemize
243
243
244 Complete system shell access.
244 Complete system shell access.
245 Lines starting with ! are passed directly to the system shell, and using
245 Lines starting with ! are passed directly to the system shell, and using
246 !! captures shell output into python variables for further use.
246 !! captures shell output into python variables for further use.
247 \layout Itemize
247 \layout Itemize
248
248
249 Background execution of Python commands in a separate thread.
249 Background execution of Python commands in a separate thread.
250 IPython has an internal job manager called
250 IPython has an internal job manager called
251 \family typewriter
251 \family typewriter
252 jobs
252 jobs
253 \family default
253 \family default
254 , and a conveninence backgrounding magic function called
254 , and a conveninence backgrounding magic function called
255 \family typewriter
255 \family typewriter
256 %bg
256 %bg
257 \family default
257 \family default
258 .
258 .
259 \layout Itemize
259 \layout Itemize
260
260
261 The ability to expand python variables when calling the system shell.
261 The ability to expand python variables when calling the system shell.
262 In a shell command, any python variable prefixed with
262 In a shell command, any python variable prefixed with
263 \family typewriter
263 \family typewriter
264 $
264 $
265 \family default
265 \family default
266 is expanded.
266 is expanded.
267 A double
267 A double
268 \family typewriter
268 \family typewriter
269 $$
269 $$
270 \family default
270 \family default
271 allows passing a literal
271 allows passing a literal
272 \family typewriter
272 \family typewriter
273 $
273 $
274 \family default
274 \family default
275 to the shell (for access to shell and environment variables like
275 to the shell (for access to shell and environment variables like
276 \family typewriter
276 \family typewriter
277 $PATH
277 $PATH
278 \family default
278 \family default
279 ).
279 ).
280 \layout Itemize
280 \layout Itemize
281
281
282 Filesystem navigation, via a magic
282 Filesystem navigation, via a magic
283 \family typewriter
283 \family typewriter
284 %cd
284 %cd
285 \family default
285 \family default
286 command, along with a persistent bookmark system (using
286 command, along with a persistent bookmark system (using
287 \family typewriter
287 \family typewriter
288 %bookmark
288 %bookmark
289 \family default
289 \family default
290 ) for fast access to frequently visited directories.
290 ) for fast access to frequently visited directories.
291 \layout Itemize
291 \layout Itemize
292
292
293 A lightweight persistence framework via the
293 A lightweight persistence framework via the
294 \family typewriter
294 \family typewriter
295 %store
295 %store
296 \family default
296 \family default
297 command, which allows you to save arbitrary Python variables.
297 command, which allows you to save arbitrary Python variables.
298 These get restored automatically when your session restarts.
298 These get restored automatically when your session restarts.
299 \layout Itemize
299 \layout Itemize
300
300
301 Automatic indentation (optional) of code as you type (through the readline
301 Automatic indentation (optional) of code as you type (through the readline
302 library).
302 library).
303 \layout Itemize
303 \layout Itemize
304
304
305 Macro system for quickly re-executing multiple lines of previous input with
305 Macro system for quickly re-executing multiple lines of previous input with
306 a single name.
306 a single name.
307 Macros can be stored persistently via
307 Macros can be stored persistently via
308 \family typewriter
308 \family typewriter
309 %store
309 %store
310 \family default
310 \family default
311 and edited via
311 and edited via
312 \family typewriter
312 \family typewriter
313 %edit
313 %edit
314 \family default
314 \family default
315 .
315 .
316
316
317 \layout Itemize
317 \layout Itemize
318
318
319 Session logging (you can then later use these logs as code in your programs).
319 Session logging (you can then later use these logs as code in your programs).
320 Logs can optionally timestamp all input, and also store session output
320 Logs can optionally timestamp all input, and also store session output
321 (marked as comments, so the log remains valid Python source code).
321 (marked as comments, so the log remains valid Python source code).
322 \layout Itemize
322 \layout Itemize
323
323
324 Session restoring: logs can be replayed to restore a previous session to
324 Session restoring: logs can be replayed to restore a previous session to
325 the state where you left it.
325 the state where you left it.
326 \layout Itemize
326 \layout Itemize
327
327
328 Verbose and colored exception traceback printouts.
328 Verbose and colored exception traceback printouts.
329 Easier to parse visually, and in verbose mode they produce a lot of useful
329 Easier to parse visually, and in verbose mode they produce a lot of useful
330 debugging information (basically a terminal version of the cgitb module).
330 debugging information (basically a terminal version of the cgitb module).
331 \layout Itemize
331 \layout Itemize
332
332
333 Auto-parentheses: callable objects can be executed without parentheses:
333 Auto-parentheses: callable objects can be executed without parentheses:
334
334
335 \family typewriter
335 \family typewriter
336 `sin 3'
336 `sin 3'
337 \family default
337 \family default
338 is automatically converted to
338 is automatically converted to
339 \family typewriter
339 \family typewriter
340 `sin(3)
340 `sin(3)
341 \family default
341 \family default
342 '.
342 '.
343 \layout Itemize
343 \layout Itemize
344
344
345 Auto-quoting: using `
345 Auto-quoting: using `
346 \family typewriter
346 \family typewriter
347 ,
347 ,
348 \family default
348 \family default
349 ' or `
349 ' or `
350 \family typewriter
350 \family typewriter
351 ;
351 ;
352 \family default
352 \family default
353 ' as the first character forces auto-quoting of the rest of the line:
353 ' as the first character forces auto-quoting of the rest of the line:
354 \family typewriter
354 \family typewriter
355 `,my_function a\SpecialChar ~
355 `,my_function a\SpecialChar ~
356 b'
356 b'
357 \family default
357 \family default
358 becomes automatically
358 becomes automatically
359 \family typewriter
359 \family typewriter
360 `my_function("a","b")'
360 `my_function("a","b")'
361 \family default
361 \family default
362 , while
362 , while
363 \family typewriter
363 \family typewriter
364 `;my_function a\SpecialChar ~
364 `;my_function a\SpecialChar ~
365 b'
365 b'
366 \family default
366 \family default
367 becomes
367 becomes
368 \family typewriter
368 \family typewriter
369 `my_function("a b")'
369 `my_function("a b")'
370 \family default
370 \family default
371 .
371 .
372 \layout Itemize
372 \layout Itemize
373
373
374 Extensible input syntax.
374 Extensible input syntax.
375 You can define filters that pre-process user input to simplify input in
375 You can define filters that pre-process user input to simplify input in
376 special situations.
376 special situations.
377 This allows for example pasting multi-line code fragments which start with
377 This allows for example pasting multi-line code fragments which start with
378
378
379 \family typewriter
379 \family typewriter
380 `>>>'
380 `>>>'
381 \family default
381 \family default
382 or
382 or
383 \family typewriter
383 \family typewriter
384 `...'
384 `...'
385 \family default
385 \family default
386 such as those from other python sessions or the standard Python documentation.
386 such as those from other python sessions or the standard Python documentation.
387 \layout Itemize
387 \layout Itemize
388
388
389 Flexible configuration system.
389 Flexible configuration system.
390 It uses a configuration file which allows permanent setting of all command-line
390 It uses a configuration file which allows permanent setting of all command-line
391 options, module loading, code and file execution.
391 options, module loading, code and file execution.
392 The system allows recursive file inclusion, so you can have a base file
392 The system allows recursive file inclusion, so you can have a base file
393 with defaults and layers which load other customizations for particular
393 with defaults and layers which load other customizations for particular
394 projects.
394 projects.
395 \layout Itemize
395 \layout Itemize
396
396
397 Embeddable.
397 Embeddable.
398 You can call IPython as a python shell inside your own python programs.
398 You can call IPython as a python shell inside your own python programs.
399 This can be used both for debugging code or for providing interactive abilities
399 This can be used both for debugging code or for providing interactive abilities
400 to your programs with knowledge about the local namespaces (very useful
400 to your programs with knowledge about the local namespaces (very useful
401 in debugging and data analysis situations).
401 in debugging and data analysis situations).
402 \layout Itemize
402 \layout Itemize
403
403
404 Easy debugger access.
404 Easy debugger access.
405 You can set IPython to call up an enhanced version of the Python debugger
405 You can set IPython to call up an enhanced version of the Python debugger
406 (
406 (
407 \family typewriter
407 \family typewriter
408 pdb
408 pdb
409 \family default
409 \family default
410 ) every time there is an uncaught exception.
410 ) every time there is an uncaught exception.
411 This drops you inside the code which triggered the exception with all the
411 This drops you inside the code which triggered the exception with all the
412 data live and it is possible to navigate the stack to rapidly isolate the
412 data live and it is possible to navigate the stack to rapidly isolate the
413 source of a bug.
413 source of a bug.
414 The
414 The
415 \family typewriter
415 \family typewriter
416 %run
416 %run
417 \family default
417 \family default
418 magic command --with the
418 magic command --with the
419 \family typewriter
419 \family typewriter
420 -d
420 -d
421 \family default
421 \family default
422 option-- can run any script under
422 option-- can run any script under
423 \family typewriter
423 \family typewriter
424 pdb
424 pdb
425 \family default
425 \family default
426 's control, automatically setting initial breakpoints for you.
426 's control, automatically setting initial breakpoints for you.
427 This version of
427 This version of
428 \family typewriter
428 \family typewriter
429 pdb
429 pdb
430 \family default
430 \family default
431 has IPython-specific improvements, including tab-completion and traceback
431 has IPython-specific improvements, including tab-completion and traceback
432 coloring support.
432 coloring support.
433 \layout Itemize
433 \layout Itemize
434
434
435 Profiler support.
435 Profiler support.
436 You can run single statements (similar to
436 You can run single statements (similar to
437 \family typewriter
437 \family typewriter
438 profile.run()
438 profile.run()
439 \family default
439 \family default
440 ) or complete programs under the profiler's control.
440 ) or complete programs under the profiler's control.
441 While this is possible with standard
441 While this is possible with the standard
442 \family typewriter
443 cProfile
444 \family default
445 or
446 \family typewriter
442 \family typewriter
447 profile
443 profile
448 \family default
444 \family default
449 modules, IPython wraps this functionality with magic commands (see
445 module, IPython wraps this functionality with magic commands (see
450 \family typewriter
446 \family typewriter
451 `%prun'
447 `%prun'
452 \family default
448 \family default
453 and
449 and
454 \family typewriter
450 \family typewriter
455 `%run -p
451 `%run -p
456 \family default
452 \family default
457 ') convenient for rapid interactive work.
453 ') convenient for rapid interactive work.
458 \layout Subsection
454 \layout Subsection
459
455
460 Portability and Python requirements
456 Portability and Python requirements
461 \layout Standard
457 \layout Standard
462
458
463
459
464 \series bold
460 \series bold
465 Python requirements:
461 Python requirements:
466 \series default
462 \series default
467 IPython requires with Python version 2.3 or newer.
463 IPython requires with Python version 2.3 or newer.
468 If you are still using Python 2.2 and can not upgrade, the last version
464 If you are still using Python 2.2 and can not upgrade, the last version
469 of IPython which worked with Python 2.2 was 0.6.15, so you will have to use
465 of IPython which worked with Python 2.2 was 0.6.15, so you will have to use
470 that.
466 that.
471 \layout Standard
467 \layout Standard
472
468
473 IPython is developed under
469 IPython is developed under
474 \series bold
470 \series bold
475 Linux
471 Linux
476 \series default
472 \series default
477 , but it should work in any reasonable Unix-type system (tested OK under
473 , but it should work in any reasonable Unix-type system (tested OK under
478 Solaris and the *BSD family, for which a port exists thanks to Dryice Liu).
474 Solaris and the *BSD family, for which a port exists thanks to Dryice Liu).
479 \layout Standard
475 \layout Standard
480
476
481
477
482 \series bold
478 \series bold
483 Mac OS X
479 Mac OS X
484 \series default
480 \series default
485 : it works, apparently without any problems (thanks to Jim Boyle at Lawrence
481 : it works, apparently without any problems (thanks to Jim Boyle at Lawrence
486 Livermore for the information).
482 Livermore for the information).
487 Thanks to Andrea Riciputi, Fink support is available.
483 Thanks to Andrea Riciputi, Fink support is available.
488 \layout Standard
484 \layout Standard
489
485
490
486
491 \series bold
487 \series bold
492 CygWin
488 CygWin
493 \series default
489 \series default
494 : it works mostly OK, though some users have reported problems with prompt
490 : it works mostly OK, though some users have reported problems with prompt
495 coloring.
491 coloring.
496 No satisfactory solution to this has been found so far, you may want to
492 No satisfactory solution to this has been found so far, you may want to
497 disable colors permanently in the
493 disable colors permanently in the
498 \family typewriter
494 \family typewriter
499 ipythonrc
495 ipythonrc
500 \family default
496 \family default
501 configuration file if you experience problems.
497 configuration file if you experience problems.
502 If you have proper color support under cygwin, please post to the IPython
498 If you have proper color support under cygwin, please post to the IPython
503 mailing list so this issue can be resolved for all users.
499 mailing list so this issue can be resolved for all users.
504 \layout Standard
500 \layout Standard
505
501
506
502
507 \series bold
503 \series bold
508 Windows
504 Windows
509 \series default
505 \series default
510 : it works well under Windows XP/2k, and I suspect NT should behave similarly.
506 : it works well under Windows XP/2k, and I suspect NT should behave similarly.
511 Section\SpecialChar ~
507 Section\SpecialChar ~
512
508
513 \begin_inset LatexCommand \ref{sub:Under-Windows}
509 \begin_inset LatexCommand \ref{sub:Under-Windows}
514
510
515 \end_inset
511 \end_inset
516
512
517 describes installation details for Windows, including some additional tools
513 describes installation details for Windows, including some additional tools
518 needed on this platform.
514 needed on this platform.
519 \layout Standard
515 \layout Standard
520
516
521 Windows 9x support is present, and has been reported to work fine (at least
517 Windows 9x support is present, and has been reported to work fine (at least
522 on WinME).
518 on WinME).
523 \layout Standard
519 \layout Standard
524
520
525 Note, that I have very little access to and experience with Windows development.
521 Note, that I have very little access to and experience with Windows development.
526 However, an excellent group of Win32 users (led by Ville Vainio), consistently
522 However, an excellent group of Win32 users (led by Ville Vainio), consistently
527 contribute bugfixes and platform-specific enhancements, so they more than
523 contribute bugfixes and platform-specific enhancements, so they more than
528 make up for my deficiencies on that front.
524 make up for my deficiencies on that front.
529 In fact, Win32 users report using IPython as a system shell (see Sec.\SpecialChar ~
525 In fact, Win32 users report using IPython as a system shell (see Sec.\SpecialChar ~
530
526
531 \begin_inset LatexCommand \ref{sec:IPython-as-shell}
527 \begin_inset LatexCommand \ref{sec:IPython-as-shell}
532
528
533 \end_inset
529 \end_inset
534
530
535 for details), as it offers a level of control and features which the default
531 for details), as it offers a level of control and features which the default
536
532
537 \family typewriter
533 \family typewriter
538 cmd.exe
534 cmd.exe
539 \family default
535 \family default
540 doesn't provide.
536 doesn't provide.
541 \layout Subsection
537 \layout Subsection
542
538
543 Location
539 Location
544 \layout Standard
540 \layout Standard
545
541
546 IPython is generously hosted at
542 IPython is generously hosted at
547 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
543 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
548
544
549 \end_inset
545 \end_inset
550
546
551 by the Enthought, Inc and the SciPy project.
547 by the Enthought, Inc and the SciPy project.
552 This site offers downloads, subversion access, mailing lists and a bug
548 This site offers downloads, subversion access, mailing lists and a bug
553 tracking system.
549 tracking system.
554 I am very grateful to Enthought (
550 I am very grateful to Enthought (
555 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
551 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
556
552
557 \end_inset
553 \end_inset
558
554
559 ) and all of the SciPy team for their contribution.
555 ) and all of the SciPy team for their contribution.
560 \layout Section
556 \layout Section
561
557
562
558
563 \begin_inset LatexCommand \label{sec:install}
559 \begin_inset LatexCommand \label{sec:install}
564
560
565 \end_inset
561 \end_inset
566
562
567 Installation
563 Installation
568 \layout Subsection
564 \layout Subsection
569
565
570 Instant instructions
566 Instant instructions
571 \layout Standard
567 \layout Standard
572
568
573 If you are of the impatient kind, under Linux/Unix simply untar/unzip the
569 If you are of the impatient kind, under Linux/Unix simply untar/unzip the
574 download, then install with
570 download, then install with
575 \family typewriter
571 \family typewriter
576 `python setup.py install'
572 `python setup.py install'
577 \family default
573 \family default
578 .
574 .
579 Under Windows, double-click on the provided
575 Under Windows, double-click on the provided
580 \family typewriter
576 \family typewriter
581 .exe
577 .exe
582 \family default
578 \family default
583 binary installer.
579 binary installer.
584 \layout Standard
580 \layout Standard
585
581
586 Then, take a look at Sections
582 Then, take a look at Sections
587 \begin_inset LatexCommand \ref{sec:good_config}
583 \begin_inset LatexCommand \ref{sec:good_config}
588
584
589 \end_inset
585 \end_inset
590
586
591 for configuring things optimally and
587 for configuring things optimally and
592 \begin_inset LatexCommand \ref{sec:quick_tips}
588 \begin_inset LatexCommand \ref{sec:quick_tips}
593
589
594 \end_inset
590 \end_inset
595
591
596 for quick tips on efficient use of IPython.
592 for quick tips on efficient use of IPython.
597 You can later refer to the rest of the manual for all the gory details.
593 You can later refer to the rest of the manual for all the gory details.
598 \layout Standard
594 \layout Standard
599
595
600 See the notes in sec.
596 See the notes in sec.
601
597
602 \begin_inset LatexCommand \ref{sec:upgrade}
598 \begin_inset LatexCommand \ref{sec:upgrade}
603
599
604 \end_inset
600 \end_inset
605
601
606 for upgrading IPython versions.
602 for upgrading IPython versions.
607 \layout Subsection
603 \layout Subsection
608
604
609 Detailed Unix instructions (Linux, Mac OS X, etc.)
605 Detailed Unix instructions (Linux, Mac OS X, etc.)
610 \layout Standard
606 \layout Standard
611
607
612 For RPM based systems, simply install the supplied package in the usual
608 For RPM based systems, simply install the supplied package in the usual
613 manner.
609 manner.
614 If you download the tar archive, the process is:
610 If you download the tar archive, the process is:
615 \layout Enumerate
611 \layout Enumerate
616
612
617 Unzip/untar the
613 Unzip/untar the
618 \family typewriter
614 \family typewriter
619 ipython-XXX.tar.gz
615 ipython-XXX.tar.gz
620 \family default
616 \family default
621 file wherever you want (
617 file wherever you want (
622 \family typewriter
618 \family typewriter
623 XXX
619 XXX
624 \family default
620 \family default
625 is the version number).
621 is the version number).
626 It will make a directory called
622 It will make a directory called
627 \family typewriter
623 \family typewriter
628 ipython-XXX.
624 ipython-XXX.
629
625
630 \family default
626 \family default
631 Change into that directory where you will find the files
627 Change into that directory where you will find the files
632 \family typewriter
628 \family typewriter
633 README
629 README
634 \family default
630 \family default
635 and
631 and
636 \family typewriter
632 \family typewriter
637 setup.py
633 setup.py
638 \family default
634 \family default
639 .
635 .
640
636
641 \family typewriter
637 \family typewriter
642 O
638 O
643 \family default
639 \family default
644 nce you've completed the installation, you can safely remove this directory.
640 nce you've completed the installation, you can safely remove this directory.
645
641
646 \layout Enumerate
642 \layout Enumerate
647
643
648 If you are installing over a previous installation of version 0.2.0 or earlier,
644 If you are installing over a previous installation of version 0.2.0 or earlier,
649 first remove your
645 first remove your
650 \family typewriter
646 \family typewriter
651 $HOME/.ipython
647 $HOME/.ipython
652 \family default
648 \family default
653 directory, since the configuration file format has changed somewhat (the
649 directory, since the configuration file format has changed somewhat (the
654 '=' were removed from all option specifications).
650 '=' were removed from all option specifications).
655 Or you can call ipython with the
651 Or you can call ipython with the
656 \family typewriter
652 \family typewriter
657 -upgrade
653 -upgrade
658 \family default
654 \family default
659 option and it will do this automatically for you.
655 option and it will do this automatically for you.
660 \layout Enumerate
656 \layout Enumerate
661
657
662 IPython uses distutils, so you can install it by simply typing at the system
658 IPython uses distutils, so you can install it by simply typing at the system
663 prompt (don't type the
659 prompt (don't type the
664 \family typewriter
660 \family typewriter
665 $
661 $
666 \family default
662 \family default
667 )
663 )
668 \newline
664 \newline
669
665
670 \family typewriter
666 \family typewriter
671 $ python setup.py install
667 $ python setup.py install
672 \family default
668 \family default
673
669
674 \newline
670 \newline
675 Note that this assumes you have root access to your machine.
671 Note that this assumes you have root access to your machine.
676 If you don't have root access or don't want IPython to go in the default
672 If you don't have root access or don't want IPython to go in the default
677 python directories, you'll need to use the
673 python directories, you'll need to use the
678 \begin_inset ERT
674 \begin_inset ERT
679 status Collapsed
675 status Collapsed
680
676
681 \layout Standard
677 \layout Standard
682
678
683 \backslash
679 \backslash
684 verb|--home|
680 verb|--home|
685 \end_inset
681 \end_inset
686
682
687 option (or
683 option (or
688 \begin_inset ERT
684 \begin_inset ERT
689 status Collapsed
685 status Collapsed
690
686
691 \layout Standard
687 \layout Standard
692
688
693 \backslash
689 \backslash
694 verb|--prefix|
690 verb|--prefix|
695 \end_inset
691 \end_inset
696
692
697 ).
693 ).
698 For example:
694 For example:
699 \newline
695 \newline
700
696
701 \begin_inset ERT
697 \begin_inset ERT
702 status Collapsed
698 status Collapsed
703
699
704 \layout Standard
700 \layout Standard
705
701
706 \backslash
702 \backslash
707 verb|$ python setup.py install --home $HOME/local|
703 verb|$ python setup.py install --home $HOME/local|
708 \end_inset
704 \end_inset
709
705
710
706
711 \newline
707 \newline
712 will install IPython into
708 will install IPython into
713 \family typewriter
709 \family typewriter
714 $HOME/local
710 $HOME/local
715 \family default
711 \family default
716 and its subdirectories (creating them if necessary).
712 and its subdirectories (creating them if necessary).
717 \newline
713 \newline
718 You can type
714 You can type
719 \newline
715 \newline
720
716
721 \begin_inset ERT
717 \begin_inset ERT
722 status Collapsed
718 status Collapsed
723
719
724 \layout Standard
720 \layout Standard
725
721
726 \backslash
722 \backslash
727 verb|$ python setup.py --help|
723 verb|$ python setup.py --help|
728 \end_inset
724 \end_inset
729
725
730
726
731 \newline
727 \newline
732 for more details.
728 for more details.
733 \newline
729 \newline
734 Note that if you change the default location for
730 Note that if you change the default location for
735 \begin_inset ERT
731 \begin_inset ERT
736 status Collapsed
732 status Collapsed
737
733
738 \layout Standard
734 \layout Standard
739
735
740 \backslash
736 \backslash
741 verb|--home|
737 verb|--home|
742 \end_inset
738 \end_inset
743
739
744 at installation, IPython may end up installed at a location which is not
740 at installation, IPython may end up installed at a location which is not
745 part of your
741 part of your
746 \family typewriter
742 \family typewriter
747 $PYTHONPATH
743 $PYTHONPATH
748 \family default
744 \family default
749 environment variable.
745 environment variable.
750 In this case, you'll need to configure this variable to include the actual
746 In this case, you'll need to configure this variable to include the actual
751 directory where the
747 directory where the
752 \family typewriter
748 \family typewriter
753 IPython/
749 IPython/
754 \family default
750 \family default
755 directory ended (typically the value you give to
751 directory ended (typically the value you give to
756 \begin_inset ERT
752 \begin_inset ERT
757 status Collapsed
753 status Collapsed
758
754
759 \layout Standard
755 \layout Standard
760
756
761 \backslash
757 \backslash
762 verb|--home|
758 verb|--home|
763 \end_inset
759 \end_inset
764
760
765 plus
761 plus
766 \family typewriter
762 \family typewriter
767 /lib/python
763 /lib/python
768 \family default
764 \family default
769 ).
765 ).
770 \layout Subsubsection
766 \layout Subsubsection
771
767
772 Mac OSX information
768 Mac OSX information
773 \layout Standard
769 \layout Standard
774
770
775 Under OSX, there is a choice you need to make.
771 Under OSX, there is a choice you need to make.
776 Apple ships its own build of Python, which lives in the core OSX filesystem
772 Apple ships its own build of Python, which lives in the core OSX filesystem
777 hierarchy.
773 hierarchy.
778 You can also manually install a separate Python, either purely by hand
774 You can also manually install a separate Python, either purely by hand
779 (typically in
775 (typically in
780 \family typewriter
776 \family typewriter
781 /usr/local
777 /usr/local
782 \family default
778 \family default
783 ) or by using Fink, which puts everything under
779 ) or by using Fink, which puts everything under
784 \family typewriter
780 \family typewriter
785 /sw
781 /sw
786 \family default
782 \family default
787 .
783 .
788 Which route to follow is a matter of personal preference, as I've seen
784 Which route to follow is a matter of personal preference, as I've seen
789 users who favor each of the approaches.
785 users who favor each of the approaches.
790 Here I will simply list the known installation issues under OSX, along
786 Here I will simply list the known installation issues under OSX, along
791 with their solutions.
787 with their solutions.
792 \layout Standard
788 \layout Standard
793
789
794 This page:
790 This page:
795 \begin_inset LatexCommand \htmlurl{http://geosci.uchicago.edu/~tobis/pylab.html}
791 \begin_inset LatexCommand \htmlurl{http://geosci.uchicago.edu/~tobis/pylab.html}
796
792
797 \end_inset
793 \end_inset
798
794
799 contains information on this topic, with additional details on how to make
795 contains information on this topic, with additional details on how to make
800 IPython and matplotlib play nicely under OSX.
796 IPython and matplotlib play nicely under OSX.
801 \layout Subsubsection*
797 \layout Subsubsection*
802
798
803 GUI problems
799 GUI problems
804 \layout Standard
800 \layout Standard
805
801
806 The following instructions apply to an install of IPython under OSX from
802 The following instructions apply to an install of IPython under OSX from
807 unpacking the
803 unpacking the
808 \family typewriter
804 \family typewriter
809 .tar.gz
805 .tar.gz
810 \family default
806 \family default
811 distribution and installing it for the default Python interpreter shipped
807 distribution and installing it for the default Python interpreter shipped
812 by Apple.
808 by Apple.
813 If you are using a fink install, fink will take care of these details for
809 If you are using a fink install, fink will take care of these details for
814 you, by installing IPython against fink's Python.
810 you, by installing IPython against fink's Python.
815 \layout Standard
811 \layout Standard
816
812
817 IPython offers various forms of support for interacting with graphical applicati
813 IPython offers various forms of support for interacting with graphical applicati
818 ons from the command line, from simple Tk apps (which are in principle always
814 ons from the command line, from simple Tk apps (which are in principle always
819 supported by Python) to interactive control of WX, Qt and GTK apps.
815 supported by Python) to interactive control of WX, Qt and GTK apps.
820 Under OSX, however, this requires that ipython is installed by calling
816 Under OSX, however, this requires that ipython is installed by calling
821 the special
817 the special
822 \family typewriter
818 \family typewriter
823 pythonw
819 pythonw
824 \family default
820 \family default
825 script at installation time, which takes care of coordinating things with
821 script at installation time, which takes care of coordinating things with
826 Apple's graphical environment.
822 Apple's graphical environment.
827 \layout Standard
823 \layout Standard
828
824
829 So when installing under OSX, it is best to use the following command:
825 So when installing under OSX, it is best to use the following command:
830 \family typewriter
826 \family typewriter
831
827
832 \newline
828 \newline
833
829
834 \family default
830 \family default
835
831
836 \begin_inset ERT
832 \begin_inset ERT
837 status Collapsed
833 status Collapsed
838
834
839 \layout Standard
835 \layout Standard
840
836
841 \backslash
837 \backslash
842 verb| $ sudo pythonw setup.py install --install-scripts=/usr/local/bin|
838 verb| $ sudo pythonw setup.py install --install-scripts=/usr/local/bin|
843 \end_inset
839 \end_inset
844
840
845
841
846 \newline
842 \newline
847 or
843 or
848 \newline
844 \newline
849
845
850 \begin_inset ERT
846 \begin_inset ERT
851 status Collapsed
847 status Collapsed
852
848
853 \layout Standard
849 \layout Standard
854
850
855 \backslash
851 \backslash
856 verb| $ sudo pythonw setup.py install --install-scripts=/usr/bin|
852 verb| $ sudo pythonw setup.py install --install-scripts=/usr/bin|
857 \end_inset
853 \end_inset
858
854
859
855
860 \newline
856 \newline
861 depending on where you like to keep hand-installed executables.
857 depending on where you like to keep hand-installed executables.
862 \layout Standard
858 \layout Standard
863
859
864 The resulting script will have an appropriate shebang line (the first line
860 The resulting script will have an appropriate shebang line (the first line
865 in the script whic begins with
861 in the script whic begins with
866 \family typewriter
862 \family typewriter
867 #!...
863 #!...
868 \family default
864 \family default
869 ) such that the ipython interpreter can interact with the OS X GUI.
865 ) such that the ipython interpreter can interact with the OS X GUI.
870 If the installed version does not work and has a shebang line that points
866 If the installed version does not work and has a shebang line that points
871 to, for example, just
867 to, for example, just
872 \family typewriter
868 \family typewriter
873 /usr/bin/python
869 /usr/bin/python
874 \family default
870 \family default
875 , then you might have a stale, cached version in your
871 , then you might have a stale, cached version in your
876 \family typewriter
872 \family typewriter
877 build/scripts-<python-version>
873 build/scripts-<python-version>
878 \family default
874 \family default
879 directory.
875 directory.
880 Delete that directory and rerun the
876 Delete that directory and rerun the
881 \family typewriter
877 \family typewriter
882 setup.py
878 setup.py
883 \family default
879 \family default
884 .
880 .
885
881
886 \layout Standard
882 \layout Standard
887
883
888 It is also a good idea to use the special flag
884 It is also a good idea to use the special flag
889 \begin_inset ERT
885 \begin_inset ERT
890 status Collapsed
886 status Collapsed
891
887
892 \layout Standard
888 \layout Standard
893
889
894 \backslash
890 \backslash
895 verb|--install-scripts|
891 verb|--install-scripts|
896 \end_inset
892 \end_inset
897
893
898 as indicated above, to ensure that the ipython scripts end up in a location
894 as indicated above, to ensure that the ipython scripts end up in a location
899 which is part of your
895 which is part of your
900 \family typewriter
896 \family typewriter
901 $PATH
897 $PATH
902 \family default
898 \family default
903 .
899 .
904 Otherwise Apple's Python will put the scripts in an internal directory
900 Otherwise Apple's Python will put the scripts in an internal directory
905 not available by default at the command line (if you use
901 not available by default at the command line (if you use
906 \family typewriter
902 \family typewriter
907 /usr/local/bin
903 /usr/local/bin
908 \family default
904 \family default
909 , you need to make sure this is in your
905 , you need to make sure this is in your
910 \family typewriter
906 \family typewriter
911 $PATH
907 $PATH
912 \family default
908 \family default
913 , which may not be true by default).
909 , which may not be true by default).
914 \layout Subsubsection*
910 \layout Subsubsection*
915
911
916 Readline problems
912 Readline problems
917 \layout Standard
913 \layout Standard
918
914
919 By default, the Python version shipped by Apple does
915 By default, the Python version shipped by Apple does
920 \emph on
916 \emph on
921 not
917 not
922 \emph default
918 \emph default
923 include the readline library, so central to IPython's behavior.
919 include the readline library, so central to IPython's behavior.
924 If you install IPython against Apple's Python, you will not have arrow
920 If you install IPython against Apple's Python, you will not have arrow
925 keys, tab completion, etc.
921 keys, tab completion, etc.
926 For Mac OSX 10.3 (Panther), you can find a prebuilt readline library here:
922 For Mac OSX 10.3 (Panther), you can find a prebuilt readline library here:
927 \newline
923 \newline
928
924
929 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip}
925 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip}
930
926
931 \end_inset
927 \end_inset
932
928
933
929
934 \layout Standard
930 \layout Standard
935
931
936 If you are using OSX 10.4 (Tiger), after installing this package you need
932 If you are using OSX 10.4 (Tiger), after installing this package you need
937 to either:
933 to either:
938 \layout Enumerate
934 \layout Enumerate
939
935
940 move
936 move
941 \family typewriter
937 \family typewriter
942 readline.so
938 readline.so
943 \family default
939 \family default
944 from
940 from
945 \family typewriter
941 \family typewriter
946 /Library/Python/2.3
942 /Library/Python/2.3
947 \family default
943 \family default
948 to
944 to
949 \family typewriter
945 \family typewriter
950 /Library/Python/2.3/site-packages
946 /Library/Python/2.3/site-packages
951 \family default
947 \family default
952 , or
948 , or
953 \layout Enumerate
949 \layout Enumerate
954
950
955 install
951 install
956 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/TigerPython23Compat.pkg.zip}
952 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/TigerPython23Compat.pkg.zip}
957
953
958 \end_inset
954 \end_inset
959
955
960
956
961 \layout Standard
957 \layout Standard
962
958
963 Users installing against Fink's Python or a properly hand-built one should
959 Users installing against Fink's Python or a properly hand-built one should
964 not have this problem.
960 not have this problem.
965 \layout Subsubsection*
961 \layout Subsubsection*
966
962
967 DarwinPorts
963 DarwinPorts
968 \layout Standard
964 \layout Standard
969
965
970 I report here a message from an OSX user, who suggests an alternative means
966 I report here a message from an OSX user, who suggests an alternative means
971 of using IPython under this operating system with good results.
967 of using IPython under this operating system with good results.
972 Please let me know of any updates that may be useful for this section.
968 Please let me know of any updates that may be useful for this section.
973 His message is reproduced verbatim below:
969 His message is reproduced verbatim below:
974 \layout Quote
970 \layout Quote
975
971
976 From: Markus Banfi
972 From: Markus Banfi
977 \family typewriter
973 \family typewriter
978 <markus.banfi-AT-mospheira.net>
974 <markus.banfi-AT-mospheira.net>
979 \layout Quote
975 \layout Quote
980
976
981 As a MacOS X (10.4.2) user I prefer to install software using DawinPorts instead
977 As a MacOS X (10.4.2) user I prefer to install software using DawinPorts instead
982 of Fink.
978 of Fink.
983 I had no problems installing ipython with DarwinPorts.
979 I had no problems installing ipython with DarwinPorts.
984 It's just:
980 It's just:
985 \layout Quote
981 \layout Quote
986
982
987
983
988 \family typewriter
984 \family typewriter
989 sudo port install py-ipython
985 sudo port install py-ipython
990 \layout Quote
986 \layout Quote
991
987
992 It automatically resolved all dependencies (python24, readline, py-readline).
988 It automatically resolved all dependencies (python24, readline, py-readline).
993 So far I did not encounter any problems with the DarwinPorts port of ipython.
989 So far I did not encounter any problems with the DarwinPorts port of ipython.
994
990
995 \layout Subsection
991 \layout Subsection
996
992
997
993
998 \begin_inset LatexCommand \label{sub:Under-Windows}
994 \begin_inset LatexCommand \label{sub:Under-Windows}
999
995
1000 \end_inset
996 \end_inset
1001
997
1002 Windows instructions
998 Windows instructions
1003 \layout Standard
999 \layout Standard
1004
1000
1005 Some of IPython's very useful features are:
1001 Some of IPython's very useful features are:
1006 \layout Itemize
1002 \layout Itemize
1007
1003
1008 Integrated readline support (Tab-based file, object and attribute completion,
1004 Integrated readline support (Tab-based file, object and attribute completion,
1009 input history across sessions, editable command line, etc.)
1005 input history across sessions, editable command line, etc.)
1010 \layout Itemize
1006 \layout Itemize
1011
1007
1012 Coloring of prompts, code and tracebacks.
1008 Coloring of prompts, code and tracebacks.
1013 \layout Standard
1009 \layout Standard
1014
1010
1015 These, by default, are only available under Unix-like operating systems.
1011 These, by default, are only available under Unix-like operating systems.
1016 However, thanks to Gary Bishop's work, Windows XP/2k users can also benefit
1012 However, thanks to Gary Bishop's work, Windows XP/2k users can also benefit
1017 from them.
1013 from them.
1018 His readline library originally implemented both GNU readline functionality
1014 His readline library originally implemented both GNU readline functionality
1019 and color support, so that IPython under Windows XP/2k can be as friendly
1015 and color support, so that IPython under Windows XP/2k can be as friendly
1020 and powerful as under Unix-like environments.
1016 and powerful as under Unix-like environments.
1021
1017
1022 \layout Standard
1018 \layout Standard
1023
1019
1024 This library, now named
1020 This library, now named
1025 \family typewriter
1021 \family typewriter
1026 PyReadline
1022 PyReadline
1027 \family default
1023 \family default
1028 , has been absorbed by the IPython team (JοΏ½rgen Stenarson, in particular),
1024 , has been absorbed by the IPython team (JοΏ½rgen Stenarson, in particular),
1029 and it continues to be developed with new features, as well as being distribute
1025 and it continues to be developed with new features, as well as being distribute
1030 d directly from the IPython site.
1026 d directly from the IPython site.
1031 \layout Standard
1027 \layout Standard
1032
1028
1033 The
1029 The
1034 \family typewriter
1030 \family typewriter
1035 PyReadline
1031 PyReadline
1036 \family default
1032 \family default
1037 extension requires
1033 extension requires
1038 \family typewriter
1034 \family typewriter
1039 CTypes
1035 CTypes
1040 \family default
1036 \family default
1041 and the windows IPython installer needs
1037 and the windows IPython installer needs
1042 \family typewriter
1038 \family typewriter
1043 PyWin32
1039 PyWin32
1044 \family default
1040 \family default
1045 , so in all you need:
1041 , so in all you need:
1046 \layout Enumerate
1042 \layout Enumerate
1047
1043
1048
1044
1049 \family typewriter
1045 \family typewriter
1050 PyWin32
1046 PyWin32
1051 \family default
1047 \family default
1052 from
1048 from
1053 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
1049 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
1054
1050
1055 \end_inset
1051 \end_inset
1056
1052
1057 .
1053 .
1058 \layout Enumerate
1054 \layout Enumerate
1059
1055
1060
1056
1061 \family typewriter
1057 \family typewriter
1062 CTypes
1058 CTypes
1063 \family default
1059 \family default
1064 from
1060 from
1065 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
1061 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
1066
1062
1067 \end_inset
1063 \end_inset
1068
1064
1069 (you
1065 (you
1070 \emph on
1066 \emph on
1071 must
1067 must
1072 \emph default
1068 \emph default
1073 use version 0.9.1 or newer).
1069 use version 0.9.1 or newer).
1074 \layout Enumerate
1070 \layout Enumerate
1075
1071
1076
1072
1077 \family typewriter
1073 \family typewriter
1078 PyReadline
1074 PyReadline
1079 \family default
1075 \family default
1080 for Windows from
1076 for Windows from
1081 \begin_inset LatexCommand \htmlurl{http://projects.scipy.org/ipython/ipython/wiki/PyReadline/Intro}
1077 \begin_inset LatexCommand \htmlurl{http://projects.scipy.org/ipython/ipython/wiki/PyReadline/Intro}
1082
1078
1083 \end_inset
1079 \end_inset
1084
1080
1085 .
1081 .
1086 That page contains further details on using and configuring the system
1082 That page contains further details on using and configuring the system
1087 to your liking.
1083 to your liking.
1088 \layout Standard
1084 \layout Standard
1089
1085
1090
1086
1091 \series bold
1087 \series bold
1092 Warning about a broken readline-like library:
1088 Warning about a broken readline-like library:
1093 \series default
1089 \series default
1094 several users have reported problems stemming from using the pseudo-readline
1090 several users have reported problems stemming from using the pseudo-readline
1095 library at
1091 library at
1096 \begin_inset LatexCommand \htmlurl{http://newcenturycomputers.net/projects/readline.html}
1092 \begin_inset LatexCommand \htmlurl{http://newcenturycomputers.net/projects/readline.html}
1097
1093
1098 \end_inset
1094 \end_inset
1099
1095
1100 .
1096 .
1101 This is a broken library which, while called readline, only implements
1097 This is a broken library which, while called readline, only implements
1102 an incomplete subset of the readline API.
1098 an incomplete subset of the readline API.
1103 Since it is still called readline, it fools IPython's detection mechanisms
1099 Since it is still called readline, it fools IPython's detection mechanisms
1104 and causes unpredictable crashes later.
1100 and causes unpredictable crashes later.
1105 If you wish to use IPython under Windows, you must NOT use this library,
1101 If you wish to use IPython under Windows, you must NOT use this library,
1106 which for all purposes is (at least as of version 1.6) terminally broken.
1102 which for all purposes is (at least as of version 1.6) terminally broken.
1107 \layout Subsubsection
1103 \layout Subsubsection
1108
1104
1109 Installation procedure
1105 Installation procedure
1110 \layout Standard
1106 \layout Standard
1111
1107
1112 Once you have the above installed, from the IPython download directory grab
1108 Once you have the above installed, from the IPython download directory grab
1113 the
1109 the
1114 \family typewriter
1110 \family typewriter
1115 ipython-XXX.win32.exe
1111 ipython-XXX.win32.exe
1116 \family default
1112 \family default
1117 file, where
1113 file, where
1118 \family typewriter
1114 \family typewriter
1119 XXX
1115 XXX
1120 \family default
1116 \family default
1121 represents the version number.
1117 represents the version number.
1122 This is a regular windows executable installer, which you can simply double-cli
1118 This is a regular windows executable installer, which you can simply double-cli
1123 ck to install.
1119 ck to install.
1124 It will add an entry for IPython to your Start Menu, as well as registering
1120 It will add an entry for IPython to your Start Menu, as well as registering
1125 IPython in the Windows list of applications, so you can later uninstall
1121 IPython in the Windows list of applications, so you can later uninstall
1126 it from the Control Panel.
1122 it from the Control Panel.
1127
1123
1128 \layout Standard
1124 \layout Standard
1129
1125
1130 IPython tries to install the configuration information in a directory named
1126 IPython tries to install the configuration information in a directory named
1131
1127
1132 \family typewriter
1128 \family typewriter
1133 .ipython
1129 .ipython
1134 \family default
1130 \family default
1135 (
1131 (
1136 \family typewriter
1132 \family typewriter
1137 _ipython
1133 _ipython
1138 \family default
1134 \family default
1139 under Windows) located in your `home' directory.
1135 under Windows) located in your `home' directory.
1140 IPython sets this directory by looking for a
1136 IPython sets this directory by looking for a
1141 \family typewriter
1137 \family typewriter
1142 HOME
1138 HOME
1143 \family default
1139 \family default
1144 environment variable; if such a variable does not exist, it uses
1140 environment variable; if such a variable does not exist, it uses
1145 \family typewriter
1141 \family typewriter
1146 HOMEDRIVE
1142 HOMEDRIVE
1147 \backslash
1143 \backslash
1148 HOMEPATH
1144 HOMEPATH
1149 \family default
1145 \family default
1150 (these are always defined by Windows).
1146 (these are always defined by Windows).
1151 This typically gives something like
1147 This typically gives something like
1152 \family typewriter
1148 \family typewriter
1153 C:
1149 C:
1154 \backslash
1150 \backslash
1155 Documents and Settings
1151 Documents and Settings
1156 \backslash
1152 \backslash
1157 YourUserName
1153 YourUserName
1158 \family default
1154 \family default
1159 , but your local details may vary.
1155 , but your local details may vary.
1160 In this directory you will find all the files that configure IPython's
1156 In this directory you will find all the files that configure IPython's
1161 defaults, and you can put there your profiles and extensions.
1157 defaults, and you can put there your profiles and extensions.
1162 This directory is automatically added by IPython to
1158 This directory is automatically added by IPython to
1163 \family typewriter
1159 \family typewriter
1164 sys.path
1160 sys.path
1165 \family default
1161 \family default
1166 , so anything you place there can be found by
1162 , so anything you place there can be found by
1167 \family typewriter
1163 \family typewriter
1168 import
1164 import
1169 \family default
1165 \family default
1170 statements.
1166 statements.
1171 \layout Paragraph
1167 \layout Paragraph
1172
1168
1173 Upgrading
1169 Upgrading
1174 \layout Standard
1170 \layout Standard
1175
1171
1176 For an IPython upgrade, you should first uninstall the previous version.
1172 For an IPython upgrade, you should first uninstall the previous version.
1177 This will ensure that all files and directories (such as the documentation)
1173 This will ensure that all files and directories (such as the documentation)
1178 which carry embedded version strings in their names are properly removed.
1174 which carry embedded version strings in their names are properly removed.
1179 \layout Paragraph
1175 \layout Paragraph
1180
1176
1181 Manual installation under Win32
1177 Manual installation under Win32
1182 \layout Standard
1178 \layout Standard
1183
1179
1184 In case the automatic installer does not work for some reason, you can download
1180 In case the automatic installer does not work for some reason, you can download
1185 the
1181 the
1186 \family typewriter
1182 \family typewriter
1187 ipython-XXX.tar.gz
1183 ipython-XXX.tar.gz
1188 \family default
1184 \family default
1189 file, which contains the full IPython source distribution (the popular
1185 file, which contains the full IPython source distribution (the popular
1190 WinZip can read
1186 WinZip can read
1191 \family typewriter
1187 \family typewriter
1192 .tar.gz
1188 .tar.gz
1193 \family default
1189 \family default
1194 files).
1190 files).
1195 After uncompressing the archive, you can install it at a command terminal
1191 After uncompressing the archive, you can install it at a command terminal
1196 just like any other Python module, by using
1192 just like any other Python module, by using
1197 \family typewriter
1193 \family typewriter
1198 `python setup.py install'
1194 `python setup.py install'
1199 \family default
1195 \family default
1200 .
1196 .
1201
1197
1202 \layout Standard
1198 \layout Standard
1203
1199
1204 After the installation, run the supplied
1200 After the installation, run the supplied
1205 \family typewriter
1201 \family typewriter
1206 win32_manual_post_install.py
1202 win32_manual_post_install.py
1207 \family default
1203 \family default
1208 script, which creates the necessary Start Menu shortcuts for you.
1204 script, which creates the necessary Start Menu shortcuts for you.
1209 \layout Subsection
1205 \layout Subsection
1210
1206
1211
1207
1212 \begin_inset LatexCommand \label{sec:upgrade}
1208 \begin_inset LatexCommand \label{sec:upgrade}
1213
1209
1214 \end_inset
1210 \end_inset
1215
1211
1216 Upgrading from a previous version
1212 Upgrading from a previous version
1217 \layout Standard
1213 \layout Standard
1218
1214
1219 If you are upgrading from a previous version of IPython, after doing the
1215 If you are upgrading from a previous version of IPython, after doing the
1220 routine installation described above, you should call IPython with the
1216 routine installation described above, you should call IPython with the
1221
1217
1222 \family typewriter
1218 \family typewriter
1223 -upgrade
1219 -upgrade
1224 \family default
1220 \family default
1225 option the first time you run your new copy.
1221 option the first time you run your new copy.
1226 This will automatically update your configuration directory while preserving
1222 This will automatically update your configuration directory while preserving
1227 copies of your old files.
1223 copies of your old files.
1228 You can then later merge back any personal customizations you may have
1224 You can then later merge back any personal customizations you may have
1229 made into the new files.
1225 made into the new files.
1230 It is a good idea to do this as there may be new options available in the
1226 It is a good idea to do this as there may be new options available in the
1231 new configuration files which you will not have.
1227 new configuration files which you will not have.
1232 \layout Standard
1228 \layout Standard
1233
1229
1234 Under Windows, if you don't know how to call python scripts with arguments
1230 Under Windows, if you don't know how to call python scripts with arguments
1235 from a command line, simply delete the old config directory and IPython
1231 from a command line, simply delete the old config directory and IPython
1236 will make a new one.
1232 will make a new one.
1237 Win2k and WinXP users will find it in
1233 Win2k and WinXP users will find it in
1238 \family typewriter
1234 \family typewriter
1239 C:
1235 C:
1240 \backslash
1236 \backslash
1241 Documents and Settings
1237 Documents and Settings
1242 \backslash
1238 \backslash
1243 YourUserName
1239 YourUserName
1244 \backslash
1240 \backslash
1245 _ipython
1241 _ipython
1246 \family default
1242 \family default
1247 , and Win 9x users under
1243 , and Win 9x users under
1248 \family typewriter
1244 \family typewriter
1249 C:
1245 C:
1250 \backslash
1246 \backslash
1251 Program Files
1247 Program Files
1252 \backslash
1248 \backslash
1253 IPython
1249 IPython
1254 \backslash
1250 \backslash
1255 _ipython.
1251 _ipython.
1256 \layout Section
1252 \layout Section
1257
1253
1258
1254
1259 \begin_inset LatexCommand \label{sec:good_config}
1255 \begin_inset LatexCommand \label{sec:good_config}
1260
1256
1261 \end_inset
1257 \end_inset
1262
1258
1263
1259
1264 \begin_inset OptArg
1260 \begin_inset OptArg
1265 collapsed true
1261 collapsed true
1266
1262
1267 \layout Standard
1263 \layout Standard
1268
1264
1269 Initial configuration
1265 Initial configuration
1270 \begin_inset ERT
1266 \begin_inset ERT
1271 status Collapsed
1267 status Collapsed
1272
1268
1273 \layout Standard
1269 \layout Standard
1274
1270
1275 \backslash
1271 \backslash
1276 ldots
1272 ldots
1277 \end_inset
1273 \end_inset
1278
1274
1279
1275
1280 \end_inset
1276 \end_inset
1281
1277
1282 Initial configuration of your environment
1278 Initial configuration of your environment
1283 \layout Standard
1279 \layout Standard
1284
1280
1285 This section will help you set various things in your environment for your
1281 This section will help you set various things in your environment for your
1286 IPython sessions to be as efficient as possible.
1282 IPython sessions to be as efficient as possible.
1287 All of IPython's configuration information, along with several example
1283 All of IPython's configuration information, along with several example
1288 files, is stored in a directory named by default
1284 files, is stored in a directory named by default
1289 \family typewriter
1285 \family typewriter
1290 $HOME/.ipython
1286 $HOME/.ipython
1291 \family default
1287 \family default
1292 .
1288 .
1293 You can change this by defining the environment variable
1289 You can change this by defining the environment variable
1294 \family typewriter
1290 \family typewriter
1295 IPYTHONDIR
1291 IPYTHONDIR
1296 \family default
1292 \family default
1297 , or at runtime with the command line option
1293 , or at runtime with the command line option
1298 \family typewriter
1294 \family typewriter
1299 -ipythondir
1295 -ipythondir
1300 \family default
1296 \family default
1301 .
1297 .
1302 \layout Standard
1298 \layout Standard
1303
1299
1304 If all goes well, the first time you run IPython it should automatically
1300 If all goes well, the first time you run IPython it should automatically
1305 create a user copy of the config directory for you, based on its builtin
1301 create a user copy of the config directory for you, based on its builtin
1306 defaults.
1302 defaults.
1307 You can look at the files it creates to learn more about configuring the
1303 You can look at the files it creates to learn more about configuring the
1308 system.
1304 system.
1309 The main file you will modify to configure IPython's behavior is called
1305 The main file you will modify to configure IPython's behavior is called
1310
1306
1311 \family typewriter
1307 \family typewriter
1312 ipythonrc
1308 ipythonrc
1313 \family default
1309 \family default
1314 (with a
1310 (with a
1315 \family typewriter
1311 \family typewriter
1316 .ini
1312 .ini
1317 \family default
1313 \family default
1318 extension under Windows), included for reference in Sec.
1314 extension under Windows), included for reference in Sec.
1319
1315
1320 \begin_inset LatexCommand \ref{sec:ipytonrc-sample}
1316 \begin_inset LatexCommand \ref{sec:ipytonrc-sample}
1321
1317
1322 \end_inset
1318 \end_inset
1323
1319
1324 .
1320 .
1325 This file is very commented and has many variables you can change to suit
1321 This file is very commented and has many variables you can change to suit
1326 your taste, you can find more details in Sec.
1322 your taste, you can find more details in Sec.
1327
1323
1328 \begin_inset LatexCommand \ref{sec:customization}
1324 \begin_inset LatexCommand \ref{sec:customization}
1329
1325
1330 \end_inset
1326 \end_inset
1331
1327
1332 .
1328 .
1333 Here we discuss the basic things you will want to make sure things are
1329 Here we discuss the basic things you will want to make sure things are
1334 working properly from the beginning.
1330 working properly from the beginning.
1335 \layout Subsection
1331 \layout Subsection
1336
1332
1337
1333
1338 \begin_inset LatexCommand \label{sec:help-access}
1334 \begin_inset LatexCommand \label{sec:help-access}
1339
1335
1340 \end_inset
1336 \end_inset
1341
1337
1342 Access to the Python help system
1338 Access to the Python help system
1343 \layout Standard
1339 \layout Standard
1344
1340
1345 This is true for Python in general (not just for IPython): you should have
1341 This is true for Python in general (not just for IPython): you should have
1346 an environment variable called
1342 an environment variable called
1347 \family typewriter
1343 \family typewriter
1348 PYTHONDOCS
1344 PYTHONDOCS
1349 \family default
1345 \family default
1350 pointing to the directory where your HTML Python documentation lives.
1346 pointing to the directory where your HTML Python documentation lives.
1351 In my system it's
1347 In my system it's
1352 \family typewriter
1348 \family typewriter
1353 /usr/share/doc/python-docs-2.3.4/html
1349 /usr/share/doc/python-docs-2.3.4/html
1354 \family default
1350 \family default
1355 , check your local details or ask your systems administrator.
1351 , check your local details or ask your systems administrator.
1356
1352
1357 \layout Standard
1353 \layout Standard
1358
1354
1359 This is the directory which holds the HTML version of the Python manuals.
1355 This is the directory which holds the HTML version of the Python manuals.
1360 Unfortunately it seems that different Linux distributions package these
1356 Unfortunately it seems that different Linux distributions package these
1361 files differently, so you may have to look around a bit.
1357 files differently, so you may have to look around a bit.
1362 Below I show the contents of this directory on my system for reference:
1358 Below I show the contents of this directory on my system for reference:
1363 \layout Standard
1359 \layout Standard
1364
1360
1365
1361
1366 \family typewriter
1362 \family typewriter
1367 [html]> ls
1363 [html]> ls
1368 \newline
1364 \newline
1369 about.dat acks.html dist/ ext/ index.html lib/ modindex.html stdabout.dat tut/
1365 about.dat acks.html dist/ ext/ index.html lib/ modindex.html stdabout.dat tut/
1370 about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
1366 about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
1371 \layout Standard
1367 \layout Standard
1372
1368
1373 You should really make sure this variable is correctly set so that Python's
1369 You should really make sure this variable is correctly set so that Python's
1374 pydoc-based help system works.
1370 pydoc-based help system works.
1375 It is a powerful and convenient system with full access to the Python manuals
1371 It is a powerful and convenient system with full access to the Python manuals
1376 and all modules accessible to you.
1372 and all modules accessible to you.
1377 \layout Standard
1373 \layout Standard
1378
1374
1379 Under Windows it seems that pydoc finds the documentation automatically,
1375 Under Windows it seems that pydoc finds the documentation automatically,
1380 so no extra setup appears necessary.
1376 so no extra setup appears necessary.
1381 \layout Subsection
1377 \layout Subsection
1382
1378
1383 Editor
1379 Editor
1384 \layout Standard
1380 \layout Standard
1385
1381
1386 The
1382 The
1387 \family typewriter
1383 \family typewriter
1388 %edit
1384 %edit
1389 \family default
1385 \family default
1390 command (and its alias
1386 command (and its alias
1391 \family typewriter
1387 \family typewriter
1392 %ed
1388 %ed
1393 \family default
1389 \family default
1394 ) will invoke the editor set in your environment as
1390 ) will invoke the editor set in your environment as
1395 \family typewriter
1391 \family typewriter
1396 EDITOR
1392 EDITOR
1397 \family default
1393 \family default
1398 .
1394 .
1399 If this variable is not set, it will default to
1395 If this variable is not set, it will default to
1400 \family typewriter
1396 \family typewriter
1401 vi
1397 vi
1402 \family default
1398 \family default
1403 under Linux/Unix and to
1399 under Linux/Unix and to
1404 \family typewriter
1400 \family typewriter
1405 notepad
1401 notepad
1406 \family default
1402 \family default
1407 under Windows.
1403 under Windows.
1408 You may want to set this variable properly and to a lightweight editor
1404 You may want to set this variable properly and to a lightweight editor
1409 which doesn't take too long to start (that is, something other than a new
1405 which doesn't take too long to start (that is, something other than a new
1410 instance of
1406 instance of
1411 \family typewriter
1407 \family typewriter
1412 Emacs
1408 Emacs
1413 \family default
1409 \family default
1414 ).
1410 ).
1415 This way you can edit multi-line code quickly and with the power of a real
1411 This way you can edit multi-line code quickly and with the power of a real
1416 editor right inside IPython.
1412 editor right inside IPython.
1417
1413
1418 \layout Standard
1414 \layout Standard
1419
1415
1420 If you are a dedicated
1416 If you are a dedicated
1421 \family typewriter
1417 \family typewriter
1422 Emacs
1418 Emacs
1423 \family default
1419 \family default
1424 user, you should set up the
1420 user, you should set up the
1425 \family typewriter
1421 \family typewriter
1426 Emacs
1422 Emacs
1427 \family default
1423 \family default
1428 server so that new requests are handled by the original process.
1424 server so that new requests are handled by the original process.
1429 This means that almost no time is spent in handling the request (assuming
1425 This means that almost no time is spent in handling the request (assuming
1430 an
1426 an
1431 \family typewriter
1427 \family typewriter
1432 Emacs
1428 Emacs
1433 \family default
1429 \family default
1434 process is already running).
1430 process is already running).
1435 For this to work, you need to set your
1431 For this to work, you need to set your
1436 \family typewriter
1432 \family typewriter
1437 EDITOR
1433 EDITOR
1438 \family default
1434 \family default
1439 environment variable to
1435 environment variable to
1440 \family typewriter
1436 \family typewriter
1441 'emacsclient'
1437 'emacsclient'
1442 \family default
1438 \family default
1443 .
1439 .
1444
1440
1445 \family typewriter
1441 \family typewriter
1446
1442
1447 \family default
1443 \family default
1448 The code below, supplied by Francois Pinard, can then be used in your
1444 The code below, supplied by Francois Pinard, can then be used in your
1449 \family typewriter
1445 \family typewriter
1450 .emacs
1446 .emacs
1451 \family default
1447 \family default
1452 file to enable the server:
1448 file to enable the server:
1453 \layout Standard
1449 \layout Standard
1454
1450
1455
1451
1456 \family typewriter
1452 \family typewriter
1457 (defvar server-buffer-clients)
1453 (defvar server-buffer-clients)
1458 \newline
1454 \newline
1459 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
1455 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
1460 \newline
1456 \newline
1461
1457
1462 \begin_inset ERT
1458 \begin_inset ERT
1463 status Collapsed
1459 status Collapsed
1464
1460
1465 \layout Standard
1461 \layout Standard
1466
1462
1467 \backslash
1463 \backslash
1468 hspace*{0mm}
1464 hspace*{0mm}
1469 \end_inset
1465 \end_inset
1470
1466
1471 \SpecialChar ~
1467 \SpecialChar ~
1472 \SpecialChar ~
1468 \SpecialChar ~
1473 (server-start)
1469 (server-start)
1474 \newline
1470 \newline
1475
1471
1476 \begin_inset ERT
1472 \begin_inset ERT
1477 status Collapsed
1473 status Collapsed
1478
1474
1479 \layout Standard
1475 \layout Standard
1480
1476
1481 \backslash
1477 \backslash
1482 hspace*{0mm}
1478 hspace*{0mm}
1483 \end_inset
1479 \end_inset
1484
1480
1485 \SpecialChar ~
1481 \SpecialChar ~
1486 \SpecialChar ~
1482 \SpecialChar ~
1487 (defun fp-kill-server-with-buffer-routine ()
1483 (defun fp-kill-server-with-buffer-routine ()
1488 \newline
1484 \newline
1489
1485
1490 \begin_inset ERT
1486 \begin_inset ERT
1491 status Collapsed
1487 status Collapsed
1492
1488
1493 \layout Standard
1489 \layout Standard
1494
1490
1495 \backslash
1491 \backslash
1496 hspace*{0mm}
1492 hspace*{0mm}
1497 \end_inset
1493 \end_inset
1498
1494
1499 \SpecialChar ~
1495 \SpecialChar ~
1500 \SpecialChar ~
1496 \SpecialChar ~
1501 \SpecialChar ~
1497 \SpecialChar ~
1502 \SpecialChar ~
1498 \SpecialChar ~
1503 (and server-buffer-clients (server-done)))
1499 (and server-buffer-clients (server-done)))
1504 \newline
1500 \newline
1505
1501
1506 \begin_inset ERT
1502 \begin_inset ERT
1507 status Collapsed
1503 status Collapsed
1508
1504
1509 \layout Standard
1505 \layout Standard
1510
1506
1511 \backslash
1507 \backslash
1512 hspace*{0mm}
1508 hspace*{0mm}
1513 \end_inset
1509 \end_inset
1514
1510
1515 \SpecialChar ~
1511 \SpecialChar ~
1516 \SpecialChar ~
1512 \SpecialChar ~
1517 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
1513 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
1518 \layout Standard
1514 \layout Standard
1519
1515
1520 You can also set the value of this editor via the commmand-line option '-
1516 You can also set the value of this editor via the commmand-line option '-
1521 \family typewriter
1517 \family typewriter
1522 editor'
1518 editor'
1523 \family default
1519 \family default
1524 or in your
1520 or in your
1525 \family typewriter
1521 \family typewriter
1526 ipythonrc
1522 ipythonrc
1527 \family default
1523 \family default
1528 file.
1524 file.
1529 This is useful if you wish to use specifically for IPython an editor different
1525 This is useful if you wish to use specifically for IPython an editor different
1530 from your typical default (and for Windows users who tend to use fewer
1526 from your typical default (and for Windows users who tend to use fewer
1531 environment variables).
1527 environment variables).
1532 \layout Subsection
1528 \layout Subsection
1533
1529
1534 Color
1530 Color
1535 \layout Standard
1531 \layout Standard
1536
1532
1537 The default IPython configuration has most bells and whistles turned on
1533 The default IPython configuration has most bells and whistles turned on
1538 (they're pretty safe).
1534 (they're pretty safe).
1539 But there's one that
1535 But there's one that
1540 \emph on
1536 \emph on
1541 may
1537 may
1542 \emph default
1538 \emph default
1543 cause problems on some systems: the use of color on screen for displaying
1539 cause problems on some systems: the use of color on screen for displaying
1544 information.
1540 information.
1545 This is very useful, since IPython can show prompts and exception tracebacks
1541 This is very useful, since IPython can show prompts and exception tracebacks
1546 with various colors, display syntax-highlighted source code, and in general
1542 with various colors, display syntax-highlighted source code, and in general
1547 make it easier to visually parse information.
1543 make it easier to visually parse information.
1548 \layout Standard
1544 \layout Standard
1549
1545
1550 The following terminals seem to handle the color sequences fine:
1546 The following terminals seem to handle the color sequences fine:
1551 \layout Itemize
1547 \layout Itemize
1552
1548
1553 Linux main text console, KDE Konsole, Gnome Terminal, E-term, rxvt, xterm.
1549 Linux main text console, KDE Konsole, Gnome Terminal, E-term, rxvt, xterm.
1554 \layout Itemize
1550 \layout Itemize
1555
1551
1556 CDE terminal (tested under Solaris).
1552 CDE terminal (tested under Solaris).
1557 This one boldfaces light colors.
1553 This one boldfaces light colors.
1558 \layout Itemize
1554 \layout Itemize
1559
1555
1560 (X)Emacs buffers.
1556 (X)Emacs buffers.
1561 See sec.
1557 See sec.
1562 \begin_inset LatexCommand \ref{sec:emacs}
1558 \begin_inset LatexCommand \ref{sec:emacs}
1563
1559
1564 \end_inset
1560 \end_inset
1565
1561
1566 for more details on using IPython with (X)Emacs.
1562 for more details on using IPython with (X)Emacs.
1567 \layout Itemize
1563 \layout Itemize
1568
1564
1569 A Windows (XP/2k) command prompt
1565 A Windows (XP/2k) command prompt
1570 \emph on
1566 \emph on
1571 with Gary Bishop's support extensions
1567 with Gary Bishop's support extensions
1572 \emph default
1568 \emph default
1573 .
1569 .
1574 Gary's extensions are discussed in Sec.\SpecialChar ~
1570 Gary's extensions are discussed in Sec.\SpecialChar ~
1575
1571
1576 \begin_inset LatexCommand \ref{sub:Under-Windows}
1572 \begin_inset LatexCommand \ref{sub:Under-Windows}
1577
1573
1578 \end_inset
1574 \end_inset
1579
1575
1580 .
1576 .
1581 \layout Itemize
1577 \layout Itemize
1582
1578
1583 A Windows (XP/2k) CygWin shell.
1579 A Windows (XP/2k) CygWin shell.
1584 Although some users have reported problems; it is not clear whether there
1580 Although some users have reported problems; it is not clear whether there
1585 is an issue for everyone or only under specific configurations.
1581 is an issue for everyone or only under specific configurations.
1586 If you have full color support under cygwin, please post to the IPython
1582 If you have full color support under cygwin, please post to the IPython
1587 mailing list so this issue can be resolved for all users.
1583 mailing list so this issue can be resolved for all users.
1588 \layout Standard
1584 \layout Standard
1589
1585
1590 These have shown problems:
1586 These have shown problems:
1591 \layout Itemize
1587 \layout Itemize
1592
1588
1593 Windows command prompt in WinXP/2k logged into a Linux machine via telnet
1589 Windows command prompt in WinXP/2k logged into a Linux machine via telnet
1594 or ssh.
1590 or ssh.
1595 \layout Itemize
1591 \layout Itemize
1596
1592
1597 Windows native command prompt in WinXP/2k,
1593 Windows native command prompt in WinXP/2k,
1598 \emph on
1594 \emph on
1599 without
1595 without
1600 \emph default
1596 \emph default
1601 Gary Bishop's extensions.
1597 Gary Bishop's extensions.
1602 Once Gary's readline library is installed, the normal WinXP/2k command
1598 Once Gary's readline library is installed, the normal WinXP/2k command
1603 prompt works perfectly.
1599 prompt works perfectly.
1604 \layout Standard
1600 \layout Standard
1605
1601
1606 Currently the following color schemes are available:
1602 Currently the following color schemes are available:
1607 \layout Itemize
1603 \layout Itemize
1608
1604
1609
1605
1610 \family typewriter
1606 \family typewriter
1611 NoColor
1607 NoColor
1612 \family default
1608 \family default
1613 : uses no color escapes at all (all escapes are empty
1609 : uses no color escapes at all (all escapes are empty
1614 \begin_inset Quotes eld
1610 \begin_inset Quotes eld
1615 \end_inset
1611 \end_inset
1616
1612
1617
1613
1618 \begin_inset Quotes eld
1614 \begin_inset Quotes eld
1619 \end_inset
1615 \end_inset
1620
1616
1621 strings).
1617 strings).
1622 This 'scheme' is thus fully safe to use in any terminal.
1618 This 'scheme' is thus fully safe to use in any terminal.
1623 \layout Itemize
1619 \layout Itemize
1624
1620
1625
1621
1626 \family typewriter
1622 \family typewriter
1627 Linux
1623 Linux
1628 \family default
1624 \family default
1629 : works well in Linux console type environments: dark background with light
1625 : works well in Linux console type environments: dark background with light
1630 fonts.
1626 fonts.
1631 It uses bright colors for information, so it is difficult to read if you
1627 It uses bright colors for information, so it is difficult to read if you
1632 have a light colored background.
1628 have a light colored background.
1633 \layout Itemize
1629 \layout Itemize
1634
1630
1635
1631
1636 \family typewriter
1632 \family typewriter
1637 LightBG
1633 LightBG
1638 \family default
1634 \family default
1639 : the basic colors are similar to those in the
1635 : the basic colors are similar to those in the
1640 \family typewriter
1636 \family typewriter
1641 Linux
1637 Linux
1642 \family default
1638 \family default
1643 scheme but darker.
1639 scheme but darker.
1644 It is easy to read in terminals with light backgrounds.
1640 It is easy to read in terminals with light backgrounds.
1645 \layout Standard
1641 \layout Standard
1646
1642
1647 IPython uses colors for two main groups of things: prompts and tracebacks
1643 IPython uses colors for two main groups of things: prompts and tracebacks
1648 which are directly printed to the terminal, and the object introspection
1644 which are directly printed to the terminal, and the object introspection
1649 system which passes large sets of data through a pager.
1645 system which passes large sets of data through a pager.
1650 \layout Subsubsection
1646 \layout Subsubsection
1651
1647
1652 Input/Output prompts and exception tracebacks
1648 Input/Output prompts and exception tracebacks
1653 \layout Standard
1649 \layout Standard
1654
1650
1655 You can test whether the colored prompts and tracebacks work on your system
1651 You can test whether the colored prompts and tracebacks work on your system
1656 interactively by typing
1652 interactively by typing
1657 \family typewriter
1653 \family typewriter
1658 '%colors Linux'
1654 '%colors Linux'
1659 \family default
1655 \family default
1660 at the prompt (use '
1656 at the prompt (use '
1661 \family typewriter
1657 \family typewriter
1662 %colors LightBG'
1658 %colors LightBG'
1663 \family default
1659 \family default
1664 if your terminal has a light background).
1660 if your terminal has a light background).
1665 If the input prompt shows garbage like:
1661 If the input prompt shows garbage like:
1666 \newline
1662 \newline
1667
1663
1668 \family typewriter
1664 \family typewriter
1669 [0;32mIn [[1;32m1[0;32m]: [0;00m
1665 [0;32mIn [[1;32m1[0;32m]: [0;00m
1670 \family default
1666 \family default
1671
1667
1672 \newline
1668 \newline
1673 instead of (in color) something like:
1669 instead of (in color) something like:
1674 \newline
1670 \newline
1675
1671
1676 \family typewriter
1672 \family typewriter
1677 In [1]:
1673 In [1]:
1678 \family default
1674 \family default
1679
1675
1680 \newline
1676 \newline
1681 this means that your terminal doesn't properly handle color escape sequences.
1677 this means that your terminal doesn't properly handle color escape sequences.
1682 You can go to a 'no color' mode by typing '
1678 You can go to a 'no color' mode by typing '
1683 \family typewriter
1679 \family typewriter
1684 %colors NoColor
1680 %colors NoColor
1685 \family default
1681 \family default
1686 '.
1682 '.
1687
1683
1688 \layout Standard
1684 \layout Standard
1689
1685
1690 You can try using a different terminal emulator program (Emacs users, see
1686 You can try using a different terminal emulator program (Emacs users, see
1691 below).
1687 below).
1692 To permanently set your color preferences, edit the file
1688 To permanently set your color preferences, edit the file
1693 \family typewriter
1689 \family typewriter
1694 $HOME/.ipython/ipythonrc
1690 $HOME/.ipython/ipythonrc
1695 \family default
1691 \family default
1696 and set the
1692 and set the
1697 \family typewriter
1693 \family typewriter
1698 colors
1694 colors
1699 \family default
1695 \family default
1700 option to the desired value.
1696 option to the desired value.
1701 \layout Subsubsection
1697 \layout Subsubsection
1702
1698
1703 Object details (types, docstrings, source code, etc.)
1699 Object details (types, docstrings, source code, etc.)
1704 \layout Standard
1700 \layout Standard
1705
1701
1706 IPython has a set of special functions for studying the objects you are
1702 IPython has a set of special functions for studying the objects you are
1707 working with, discussed in detail in Sec.
1703 working with, discussed in detail in Sec.
1708
1704
1709 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1705 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1710
1706
1711 \end_inset
1707 \end_inset
1712
1708
1713 .
1709 .
1714 But this system relies on passing information which is longer than your
1710 But this system relies on passing information which is longer than your
1715 screen through a data pager, such as the common Unix
1711 screen through a data pager, such as the common Unix
1716 \family typewriter
1712 \family typewriter
1717 less
1713 less
1718 \family default
1714 \family default
1719 and
1715 and
1720 \family typewriter
1716 \family typewriter
1721 more
1717 more
1722 \family default
1718 \family default
1723 programs.
1719 programs.
1724 In order to be able to see this information in color, your pager needs
1720 In order to be able to see this information in color, your pager needs
1725 to be properly configured.
1721 to be properly configured.
1726 I strongly recommend using
1722 I strongly recommend using
1727 \family typewriter
1723 \family typewriter
1728 less
1724 less
1729 \family default
1725 \family default
1730 instead of
1726 instead of
1731 \family typewriter
1727 \family typewriter
1732 more
1728 more
1733 \family default
1729 \family default
1734 , as it seems that
1730 , as it seems that
1735 \family typewriter
1731 \family typewriter
1736 more
1732 more
1737 \family default
1733 \family default
1738 simply can not understand colored text correctly.
1734 simply can not understand colored text correctly.
1739 \layout Standard
1735 \layout Standard
1740
1736
1741 In order to configure
1737 In order to configure
1742 \family typewriter
1738 \family typewriter
1743 less
1739 less
1744 \family default
1740 \family default
1745 as your default pager, do the following:
1741 as your default pager, do the following:
1746 \layout Enumerate
1742 \layout Enumerate
1747
1743
1748 Set the environment
1744 Set the environment
1749 \family typewriter
1745 \family typewriter
1750 PAGER
1746 PAGER
1751 \family default
1747 \family default
1752 variable to
1748 variable to
1753 \family typewriter
1749 \family typewriter
1754 less
1750 less
1755 \family default
1751 \family default
1756 .
1752 .
1757 \layout Enumerate
1753 \layout Enumerate
1758
1754
1759 Set the environment
1755 Set the environment
1760 \family typewriter
1756 \family typewriter
1761 LESS
1757 LESS
1762 \family default
1758 \family default
1763 variable to
1759 variable to
1764 \family typewriter
1760 \family typewriter
1765 -r
1761 -r
1766 \family default
1762 \family default
1767 (plus any other options you always want to pass to
1763 (plus any other options you always want to pass to
1768 \family typewriter
1764 \family typewriter
1769 less
1765 less
1770 \family default
1766 \family default
1771 by default).
1767 by default).
1772 This tells
1768 This tells
1773 \family typewriter
1769 \family typewriter
1774 less
1770 less
1775 \family default
1771 \family default
1776 to properly interpret control sequences, which is how color information
1772 to properly interpret control sequences, which is how color information
1777 is given to your terminal.
1773 is given to your terminal.
1778 \layout Standard
1774 \layout Standard
1779
1775
1780 For the
1776 For the
1781 \family typewriter
1777 \family typewriter
1782 csh
1778 csh
1783 \family default
1779 \family default
1784 or
1780 or
1785 \family typewriter
1781 \family typewriter
1786 tcsh
1782 tcsh
1787 \family default
1783 \family default
1788 shells, add to your
1784 shells, add to your
1789 \family typewriter
1785 \family typewriter
1790 ~/.cshrc
1786 ~/.cshrc
1791 \family default
1787 \family default
1792 file the lines:
1788 file the lines:
1793 \layout Standard
1789 \layout Standard
1794
1790
1795
1791
1796 \family typewriter
1792 \family typewriter
1797 setenv PAGER less
1793 setenv PAGER less
1798 \newline
1794 \newline
1799 setenv LESS -r
1795 setenv LESS -r
1800 \layout Standard
1796 \layout Standard
1801
1797
1802 There is similar syntax for other Unix shells, look at your system documentation
1798 There is similar syntax for other Unix shells, look at your system documentation
1803 for details.
1799 for details.
1804 \layout Standard
1800 \layout Standard
1805
1801
1806 If you are on a system which lacks proper data pagers (such as Windows),
1802 If you are on a system which lacks proper data pagers (such as Windows),
1807 IPython will use a very limited builtin pager.
1803 IPython will use a very limited builtin pager.
1808 \layout Subsection
1804 \layout Subsection
1809
1805
1810
1806
1811 \begin_inset LatexCommand \label{sec:emacs}
1807 \begin_inset LatexCommand \label{sec:emacs}
1812
1808
1813 \end_inset
1809 \end_inset
1814
1810
1815 (X)Emacs configuration
1811 (X)Emacs configuration
1816 \layout Standard
1812 \layout Standard
1817
1813
1818 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, currently
1814 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, currently
1819 (X)Emacs and IPython get along very well.
1815 (X)Emacs and IPython get along very well.
1820
1816
1821 \layout Standard
1817 \layout Standard
1822
1818
1823
1819
1824 \series bold
1820 \series bold
1825 Important note:
1821 Important note:
1826 \series default
1822 \series default
1827 You will need to use a recent enough version of
1823 You will need to use a recent enough version of
1828 \family typewriter
1824 \family typewriter
1829 python-mode.el
1825 python-mode.el
1830 \family default
1826 \family default
1831 , along with the file
1827 , along with the file
1832 \family typewriter
1828 \family typewriter
1833 ipython.el
1829 ipython.el
1834 \family default
1830 \family default
1835 .
1831 .
1836 You can check that the version you have of
1832 You can check that the version you have of
1837 \family typewriter
1833 \family typewriter
1838 python-mode.el
1834 python-mode.el
1839 \family default
1835 \family default
1840 is new enough by either looking at the revision number in the file itself,
1836 is new enough by either looking at the revision number in the file itself,
1841 or asking for it in (X)Emacs via
1837 or asking for it in (X)Emacs via
1842 \family typewriter
1838 \family typewriter
1843 M-x py-version
1839 M-x py-version
1844 \family default
1840 \family default
1845 .
1841 .
1846 Versions 4.68 and newer contain the necessary fixes for proper IPython support.
1842 Versions 4.68 and newer contain the necessary fixes for proper IPython support.
1847 \layout Standard
1843 \layout Standard
1848
1844
1849 The file
1845 The file
1850 \family typewriter
1846 \family typewriter
1851 ipython.el
1847 ipython.el
1852 \family default
1848 \family default
1853 is included with the IPython distribution, in the documentation directory
1849 is included with the IPython distribution, in the documentation directory
1854 (where this manual resides in PDF and HTML formats).
1850 (where this manual resides in PDF and HTML formats).
1855 \layout Standard
1851 \layout Standard
1856
1852
1857 Once you put these files in your Emacs path, all you need in your
1853 Once you put these files in your Emacs path, all you need in your
1858 \family typewriter
1854 \family typewriter
1859 .emacs
1855 .emacs
1860 \family default
1856 \family default
1861 file is:
1857 file is:
1862 \layout LyX-Code
1858 \layout LyX-Code
1863
1859
1864 (require 'ipython)
1860 (require 'ipython)
1865 \layout Standard
1861 \layout Standard
1866
1862
1867 This should give you full support for executing code snippets via IPython,
1863 This should give you full support for executing code snippets via IPython,
1868 opening IPython as your Python shell via
1864 opening IPython as your Python shell via
1869 \family typewriter
1865 \family typewriter
1870 C-c\SpecialChar ~
1866 C-c\SpecialChar ~
1871 !
1867 !
1872 \family default
1868 \family default
1873 , etc.
1869 , etc.
1874
1870
1875 \layout Standard
1871 \layout Standard
1876
1872
1877 If you happen to get garbage instead of colored prompts as described in
1873 If you happen to get garbage instead of colored prompts as described in
1878 the previous section, you may need to set also in your
1874 the previous section, you may need to set also in your
1879 \family typewriter
1875 \family typewriter
1880 .emacs
1876 .emacs
1881 \family default
1877 \family default
1882 file:
1878 file:
1883 \layout LyX-Code
1879 \layout LyX-Code
1884
1880
1885 (setq ansi-color-for-comint-mode t)
1881 (setq ansi-color-for-comint-mode t)
1886 \layout Subsubsection*
1882 \layout Subsubsection*
1887
1883
1888 Notes
1884 Notes
1889 \layout Itemize
1885 \layout Itemize
1890
1886
1891 There is one caveat you should be aware of: you must start the IPython shell
1887 There is one caveat you should be aware of: you must start the IPython shell
1892
1888
1893 \emph on
1889 \emph on
1894 before
1890 before
1895 \emph default
1891 \emph default
1896 attempting to execute any code regions via
1892 attempting to execute any code regions via
1897 \family typewriter
1893 \family typewriter
1898 C-c\SpecialChar ~
1894 C-c\SpecialChar ~
1899 |
1895 |
1900 \family default
1896 \family default
1901 .
1897 .
1902 Simply type
1898 Simply type
1903 \family typewriter
1899 \family typewriter
1904 C-c\SpecialChar ~
1900 C-c\SpecialChar ~
1905 !
1901 !
1906 \family default
1902 \family default
1907 to start IPython before passing any code regions to the interpreter, and
1903 to start IPython before passing any code regions to the interpreter, and
1908 you shouldn't experience any problems.
1904 you shouldn't experience any problems.
1909 \newline
1905 \newline
1910 This is due to a bug in Python itself, which has been fixed for Python 2.3,
1906 This is due to a bug in Python itself, which has been fixed for Python 2.3,
1911 but exists as of Python 2.2.2 (reported as SF bug [ 737947 ]).
1907 but exists as of Python 2.2.2 (reported as SF bug [ 737947 ]).
1912 \layout Itemize
1908 \layout Itemize
1913
1909
1914 The (X)Emacs support is maintained by Alexander Schmolck, so all comments/reques
1910 The (X)Emacs support is maintained by Alexander Schmolck, so all comments/reques
1915 ts should be directed to him through the IPython mailing lists.
1911 ts should be directed to him through the IPython mailing lists.
1916
1912
1917 \layout Itemize
1913 \layout Itemize
1918
1914
1919 This code is still somewhat experimental so it's a bit rough around the
1915 This code is still somewhat experimental so it's a bit rough around the
1920 edges (although in practice, it works quite well).
1916 edges (although in practice, it works quite well).
1921 \layout Itemize
1917 \layout Itemize
1922
1918
1923 Be aware that if you customize
1919 Be aware that if you customize
1924 \family typewriter
1920 \family typewriter
1925 py-python-command
1921 py-python-command
1926 \family default
1922 \family default
1927 previously, this value will override what
1923 previously, this value will override what
1928 \family typewriter
1924 \family typewriter
1929 ipython.el
1925 ipython.el
1930 \family default
1926 \family default
1931 does (because loading the customization variables comes later).
1927 does (because loading the customization variables comes later).
1932 \layout Section
1928 \layout Section
1933
1929
1934
1930
1935 \begin_inset LatexCommand \label{sec:quick_tips}
1931 \begin_inset LatexCommand \label{sec:quick_tips}
1936
1932
1937 \end_inset
1933 \end_inset
1938
1934
1939 Quick tips
1935 Quick tips
1940 \layout Standard
1936 \layout Standard
1941
1937
1942 IPython can be used as an improved replacement for the Python prompt, and
1938 IPython can be used as an improved replacement for the Python prompt, and
1943 for that you don't really need to read any more of this manual.
1939 for that you don't really need to read any more of this manual.
1944 But in this section we'll try to summarize a few tips on how to make the
1940 But in this section we'll try to summarize a few tips on how to make the
1945 most effective use of it for everyday Python development, highlighting
1941 most effective use of it for everyday Python development, highlighting
1946 things you might miss in the rest of the manual (which is getting long).
1942 things you might miss in the rest of the manual (which is getting long).
1947 We'll give references to parts in the manual which provide more detail
1943 We'll give references to parts in the manual which provide more detail
1948 when appropriate.
1944 when appropriate.
1949 \layout Standard
1945 \layout Standard
1950
1946
1951 The following article by Jeremy Jones provides an introductory tutorial
1947 The following article by Jeremy Jones provides an introductory tutorial
1952 about IPython:
1948 about IPython:
1953 \newline
1949 \newline
1954
1950
1955 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html}
1951 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html}
1956
1952
1957 \end_inset
1953 \end_inset
1958
1954
1959
1955
1960 \layout Itemize
1956 \layout Itemize
1961
1957
1962 The TAB key.
1958 The TAB key.
1963 TAB-completion, especially for attributes, is a convenient way to explore
1959 TAB-completion, especially for attributes, is a convenient way to explore
1964 the structure of any object you're dealing with.
1960 the structure of any object you're dealing with.
1965 Simply type
1961 Simply type
1966 \family typewriter
1962 \family typewriter
1967 object_name.<TAB>
1963 object_name.<TAB>
1968 \family default
1964 \family default
1969 and a list of the object's attributes will be printed (see sec.
1965 and a list of the object's attributes will be printed (see sec.
1970
1966
1971 \begin_inset LatexCommand \ref{sec:readline}
1967 \begin_inset LatexCommand \ref{sec:readline}
1972
1968
1973 \end_inset
1969 \end_inset
1974
1970
1975 for more).
1971 for more).
1976 Tab completion also works on file and directory names, which combined with
1972 Tab completion also works on file and directory names, which combined with
1977 IPython's alias system allows you to do from within IPython many of the
1973 IPython's alias system allows you to do from within IPython many of the
1978 things you normally would need the system shell for.
1974 things you normally would need the system shell for.
1979
1975
1980 \layout Itemize
1976 \layout Itemize
1981
1977
1982 Explore your objects.
1978 Explore your objects.
1983 Typing
1979 Typing
1984 \family typewriter
1980 \family typewriter
1985 object_name?
1981 object_name?
1986 \family default
1982 \family default
1987 will print all sorts of details about any object, including docstrings,
1983 will print all sorts of details about any object, including docstrings,
1988 function definition lines (for call arguments) and constructor details
1984 function definition lines (for call arguments) and constructor details
1989 for classes.
1985 for classes.
1990 The magic commands
1986 The magic commands
1991 \family typewriter
1987 \family typewriter
1992 %pdoc
1988 %pdoc
1993 \family default
1989 \family default
1994 ,
1990 ,
1995 \family typewriter
1991 \family typewriter
1996 %pdef
1992 %pdef
1997 \family default
1993 \family default
1998 ,
1994 ,
1999 \family typewriter
1995 \family typewriter
2000 %psource
1996 %psource
2001 \family default
1997 \family default
2002 and
1998 and
2003 \family typewriter
1999 \family typewriter
2004 %pfile
2000 %pfile
2005 \family default
2001 \family default
2006 will respectively print the docstring, function definition line, full source
2002 will respectively print the docstring, function definition line, full source
2007 code and the complete file for any object (when they can be found).
2003 code and the complete file for any object (when they can be found).
2008 If automagic is on (it is by default), you don't need to type the '
2004 If automagic is on (it is by default), you don't need to type the '
2009 \family typewriter
2005 \family typewriter
2010 %
2006 %
2011 \family default
2007 \family default
2012 ' explicitly.
2008 ' explicitly.
2013 See sec.
2009 See sec.
2014
2010
2015 \begin_inset LatexCommand \ref{sec:dyn-object-info}
2011 \begin_inset LatexCommand \ref{sec:dyn-object-info}
2016
2012
2017 \end_inset
2013 \end_inset
2018
2014
2019 for more.
2015 for more.
2020 \layout Itemize
2016 \layout Itemize
2021
2017
2022 The
2018 The
2023 \family typewriter
2019 \family typewriter
2024 %run
2020 %run
2025 \family default
2021 \family default
2026 magic command allows you to run any python script and load all of its data
2022 magic command allows you to run any python script and load all of its data
2027 directly into the interactive namespace.
2023 directly into the interactive namespace.
2028 Since the file is re-read from disk each time, changes you make to it are
2024 Since the file is re-read from disk each time, changes you make to it are
2029 reflected immediately (in contrast to the behavior of
2025 reflected immediately (in contrast to the behavior of
2030 \family typewriter
2026 \family typewriter
2031 import
2027 import
2032 \family default
2028 \family default
2033 ).
2029 ).
2034 I rarely use
2030 I rarely use
2035 \family typewriter
2031 \family typewriter
2036 import
2032 import
2037 \family default
2033 \family default
2038 for code I am testing, relying on
2034 for code I am testing, relying on
2039 \family typewriter
2035 \family typewriter
2040 %run
2036 %run
2041 \family default
2037 \family default
2042 instead.
2038 instead.
2043 See sec.
2039 See sec.
2044
2040
2045 \begin_inset LatexCommand \ref{sec:magic}
2041 \begin_inset LatexCommand \ref{sec:magic}
2046
2042
2047 \end_inset
2043 \end_inset
2048
2044
2049 for more on this and other magic commands, or type the name of any magic
2045 for more on this and other magic commands, or type the name of any magic
2050 command and ? to get details on it.
2046 command and ? to get details on it.
2051 See also sec.
2047 See also sec.
2052
2048
2053 \begin_inset LatexCommand \ref{sec:dreload}
2049 \begin_inset LatexCommand \ref{sec:dreload}
2054
2050
2055 \end_inset
2051 \end_inset
2056
2052
2057 for a recursive reload command.
2053 for a recursive reload command.
2058 \newline
2054 \newline
2059
2055
2060 \family typewriter
2056 \family typewriter
2061 %run
2057 %run
2062 \family default
2058 \family default
2063 also has special flags for timing the execution of your scripts (
2059 also has special flags for timing the execution of your scripts (
2064 \family typewriter
2060 \family typewriter
2065 -t
2061 -t
2066 \family default
2062 \family default
2067 ) and for executing them under the control of either Python's
2063 ) and for executing them under the control of either Python's
2068 \family typewriter
2064 \family typewriter
2069 pdb
2065 pdb
2070 \family default
2066 \family default
2071 debugger (
2067 debugger (
2072 \family typewriter
2068 \family typewriter
2073 -d
2069 -d
2074 \family default
2070 \family default
2075 ) or profiler (
2071 ) or profiler (
2076 \family typewriter
2072 \family typewriter
2077 -p
2073 -p
2078 \family default
2074 \family default
2079 ).
2075 ).
2080 With all of these,
2076 With all of these,
2081 \family typewriter
2077 \family typewriter
2082 %run
2078 %run
2083 \family default
2079 \family default
2084 can be used as the main tool for efficient interactive development of code
2080 can be used as the main tool for efficient interactive development of code
2085 which you write in your editor of choice.
2081 which you write in your editor of choice.
2086 \layout Itemize
2082 \layout Itemize
2087
2083
2088 Use the Python debugger,
2084 Use the Python debugger,
2089 \family typewriter
2085 \family typewriter
2090 pdb
2086 pdb
2091 \family default
2087 \family default
2092
2088
2093 \begin_inset Foot
2089 \begin_inset Foot
2094 collapsed true
2090 collapsed true
2095
2091
2096 \layout Standard
2092 \layout Standard
2097
2093
2098 Thanks to Christian Hart and Matthew Arnison for the suggestions leading
2094 Thanks to Christian Hart and Matthew Arnison for the suggestions leading
2099 to IPython's improved debugger and profiler support.
2095 to IPython's improved debugger and profiler support.
2100 \end_inset
2096 \end_inset
2101
2097
2102 .
2098 .
2103 The
2099 The
2104 \family typewriter
2100 \family typewriter
2105 %pdb
2101 %pdb
2106 \family default
2102 \family default
2107 command allows you to toggle on and off the automatic invocation of an
2103 command allows you to toggle on and off the automatic invocation of an
2108 IPython-enhanced
2104 IPython-enhanced
2109 \family typewriter
2105 \family typewriter
2110 pdb
2106 pdb
2111 \family default
2107 \family default
2112 debugger (with coloring, tab completion and more) at any uncaught exception.
2108 debugger (with coloring, tab completion and more) at any uncaught exception.
2113 The advantage of this is that
2109 The advantage of this is that
2114 \family typewriter
2110 \family typewriter
2115 pdb
2111 pdb
2116 \family default
2112 \family default
2117 starts
2113 starts
2118 \emph on
2114 \emph on
2119 inside
2115 inside
2120 \emph default
2116 \emph default
2121 the function where the exception occurred, with all data still available.
2117 the function where the exception occurred, with all data still available.
2122 You can print variables, see code, execute statements and even walk up
2118 You can print variables, see code, execute statements and even walk up
2123 and down the call stack to track down the true source of the problem (which
2119 and down the call stack to track down the true source of the problem (which
2124 often is many layers in the stack above where the exception gets triggered).
2120 often is many layers in the stack above where the exception gets triggered).
2125 \newline
2121 \newline
2126 Running programs with
2122 Running programs with
2127 \family typewriter
2123 \family typewriter
2128 %run
2124 %run
2129 \family default
2125 \family default
2130 and pdb active can be an efficient to develop and debug code, in many cases
2126 and pdb active can be an efficient to develop and debug code, in many cases
2131 eliminating the need for
2127 eliminating the need for
2132 \family typewriter
2128 \family typewriter
2133 print
2129 print
2134 \family default
2130 \family default
2135 statements or external debugging tools.
2131 statements or external debugging tools.
2136 I often simply put a
2132 I often simply put a
2137 \family typewriter
2133 \family typewriter
2138 1/0
2134 1/0
2139 \family default
2135 \family default
2140 in a place where I want to take a look so that pdb gets called, quickly
2136 in a place where I want to take a look so that pdb gets called, quickly
2141 view whatever variables I need to or test various pieces of code and then
2137 view whatever variables I need to or test various pieces of code and then
2142 remove the
2138 remove the
2143 \family typewriter
2139 \family typewriter
2144 1/0
2140 1/0
2145 \family default
2141 \family default
2146 .
2142 .
2147 \newline
2143 \newline
2148 Note also that `
2144 Note also that `
2149 \family typewriter
2145 \family typewriter
2150 %run -d
2146 %run -d
2151 \family default
2147 \family default
2152 ' activates
2148 ' activates
2153 \family typewriter
2149 \family typewriter
2154 pdb
2150 pdb
2155 \family default
2151 \family default
2156 and automatically sets initial breakpoints for you to step through your
2152 and automatically sets initial breakpoints for you to step through your
2157 code, watch variables, etc.
2153 code, watch variables, etc.
2158 See Sec.\SpecialChar ~
2154 See Sec.\SpecialChar ~
2159
2155
2160 \begin_inset LatexCommand \ref{sec:cache_output}
2156 \begin_inset LatexCommand \ref{sec:cache_output}
2161
2157
2162 \end_inset
2158 \end_inset
2163
2159
2164 for details.
2160 for details.
2165 \layout Itemize
2161 \layout Itemize
2166
2162
2167 Use the output cache.
2163 Use the output cache.
2168 All output results are automatically stored in a global dictionary named
2164 All output results are automatically stored in a global dictionary named
2169
2165
2170 \family typewriter
2166 \family typewriter
2171 Out
2167 Out
2172 \family default
2168 \family default
2173 and variables named
2169 and variables named
2174 \family typewriter
2170 \family typewriter
2175 _1
2171 _1
2176 \family default
2172 \family default
2177 ,
2173 ,
2178 \family typewriter
2174 \family typewriter
2179 _2
2175 _2
2180 \family default
2176 \family default
2181 , etc.
2177 , etc.
2182 alias them.
2178 alias them.
2183 For example, the result of input line 4 is available either as
2179 For example, the result of input line 4 is available either as
2184 \family typewriter
2180 \family typewriter
2185 Out[4]
2181 Out[4]
2186 \family default
2182 \family default
2187 or as
2183 or as
2188 \family typewriter
2184 \family typewriter
2189 _4
2185 _4
2190 \family default
2186 \family default
2191 .
2187 .
2192 Additionally, three variables named
2188 Additionally, three variables named
2193 \family typewriter
2189 \family typewriter
2194 _
2190 _
2195 \family default
2191 \family default
2196 ,
2192 ,
2197 \family typewriter
2193 \family typewriter
2198 __
2194 __
2199 \family default
2195 \family default
2200 and
2196 and
2201 \family typewriter
2197 \family typewriter
2202 ___
2198 ___
2203 \family default
2199 \family default
2204 are always kept updated with the for the last three results.
2200 are always kept updated with the for the last three results.
2205 This allows you to recall any previous result and further use it for new
2201 This allows you to recall any previous result and further use it for new
2206 calculations.
2202 calculations.
2207 See Sec.\SpecialChar ~
2203 See Sec.\SpecialChar ~
2208
2204
2209 \begin_inset LatexCommand \ref{sec:cache_output}
2205 \begin_inset LatexCommand \ref{sec:cache_output}
2210
2206
2211 \end_inset
2207 \end_inset
2212
2208
2213 for more.
2209 for more.
2214 \layout Itemize
2210 \layout Itemize
2215
2211
2216 Put a '
2212 Put a '
2217 \family typewriter
2213 \family typewriter
2218 ;
2214 ;
2219 \family default
2215 \family default
2220 ' at the end of a line to supress the printing of output.
2216 ' at the end of a line to supress the printing of output.
2221 This is useful when doing calculations which generate long output you are
2217 This is useful when doing calculations which generate long output you are
2222 not interested in seeing.
2218 not interested in seeing.
2223 The
2219 The
2224 \family typewriter
2220 \family typewriter
2225 _*
2221 _*
2226 \family default
2222 \family default
2227 variables and the
2223 variables and the
2228 \family typewriter
2224 \family typewriter
2229 Out[]
2225 Out[]
2230 \family default
2226 \family default
2231 list do get updated with the contents of the output, even if it is not
2227 list do get updated with the contents of the output, even if it is not
2232 printed.
2228 printed.
2233 You can thus still access the generated results this way for further processing.
2229 You can thus still access the generated results this way for further processing.
2234 \layout Itemize
2230 \layout Itemize
2235
2231
2236 A similar system exists for caching input.
2232 A similar system exists for caching input.
2237 All input is stored in a global list called
2233 All input is stored in a global list called
2238 \family typewriter
2234 \family typewriter
2239 In
2235 In
2240 \family default
2236 \family default
2241 , so you can re-execute lines 22 through 28 plus line 34 by typing
2237 , so you can re-execute lines 22 through 28 plus line 34 by typing
2242 \family typewriter
2238 \family typewriter
2243 'exec In[22:29]+In[34]'
2239 'exec In[22:29]+In[34]'
2244 \family default
2240 \family default
2245 (using Python slicing notation).
2241 (using Python slicing notation).
2246 If you need to execute the same set of lines often, you can assign them
2242 If you need to execute the same set of lines often, you can assign them
2247 to a macro with the
2243 to a macro with the
2248 \family typewriter
2244 \family typewriter
2249 %macro
2245 %macro
2250 \family default
2246 \family default
2251
2247
2252 \family typewriter
2248 \family typewriter
2253 function.
2249 function.
2254
2250
2255 \family default
2251 \family default
2256 See sec.
2252 See sec.
2257
2253
2258 \begin_inset LatexCommand \ref{sec:cache_input}
2254 \begin_inset LatexCommand \ref{sec:cache_input}
2259
2255
2260 \end_inset
2256 \end_inset
2261
2257
2262 for more.
2258 for more.
2263 \layout Itemize
2259 \layout Itemize
2264
2260
2265 Use your input history.
2261 Use your input history.
2266 The
2262 The
2267 \family typewriter
2263 \family typewriter
2268 %hist
2264 %hist
2269 \family default
2265 \family default
2270 command can show you all previous input, without line numbers if desired
2266 command can show you all previous input, without line numbers if desired
2271 (option
2267 (option
2272 \family typewriter
2268 \family typewriter
2273 -n
2269 -n
2274 \family default
2270 \family default
2275 ) so you can directly copy and paste code either back in IPython or in a
2271 ) so you can directly copy and paste code either back in IPython or in a
2276 text editor.
2272 text editor.
2277 You can also save all your history by turning on logging via
2273 You can also save all your history by turning on logging via
2278 \family typewriter
2274 \family typewriter
2279 %logstart
2275 %logstart
2280 \family default
2276 \family default
2281 ; these logs can later be either reloaded as IPython sessions or used as
2277 ; these logs can later be either reloaded as IPython sessions or used as
2282 code for your programs.
2278 code for your programs.
2283 \layout Itemize
2279 \layout Itemize
2284
2280
2285 Define your own system aliases.
2281 Define your own system aliases.
2286 Even though IPython gives you access to your system shell via the
2282 Even though IPython gives you access to your system shell via the
2287 \family typewriter
2283 \family typewriter
2288 !
2284 !
2289 \family default
2285 \family default
2290 prefix, it is convenient to have aliases to the system commands you use
2286 prefix, it is convenient to have aliases to the system commands you use
2291 most often.
2287 most often.
2292 This allows you to work seamlessly from inside IPython with the same commands
2288 This allows you to work seamlessly from inside IPython with the same commands
2293 you are used to in your system shell.
2289 you are used to in your system shell.
2294 \newline
2290 \newline
2295 IPython comes with some pre-defined aliases and a complete system for changing
2291 IPython comes with some pre-defined aliases and a complete system for changing
2296 directories, both via a stack (see
2292 directories, both via a stack (see
2297 \family typewriter
2293 \family typewriter
2298 %pushd
2294 %pushd
2299 \family default
2295 \family default
2300 ,
2296 ,
2301 \family typewriter
2297 \family typewriter
2302 %popd
2298 %popd
2303 \family default
2299 \family default
2304 and
2300 and
2305 \family typewriter
2301 \family typewriter
2306 %dhist
2302 %dhist
2307 \family default
2303 \family default
2308 ) and via direct
2304 ) and via direct
2309 \family typewriter
2305 \family typewriter
2310 %cd
2306 %cd
2311 \family default
2307 \family default
2312 .
2308 .
2313 The latter keeps a history of visited directories and allows you to go
2309 The latter keeps a history of visited directories and allows you to go
2314 to any previously visited one.
2310 to any previously visited one.
2315 \layout Itemize
2311 \layout Itemize
2316
2312
2317 Use Python to manipulate the results of system commands.
2313 Use Python to manipulate the results of system commands.
2318 The `
2314 The `
2319 \family typewriter
2315 \family typewriter
2320 !!
2316 !!
2321 \family default
2317 \family default
2322 ' special syntax, and the
2318 ' special syntax, and the
2323 \family typewriter
2319 \family typewriter
2324 %sc
2320 %sc
2325 \family default
2321 \family default
2326 and
2322 and
2327 \family typewriter
2323 \family typewriter
2328 %sx
2324 %sx
2329 \family default
2325 \family default
2330 magic commands allow you to capture system output into Python variables.
2326 magic commands allow you to capture system output into Python variables.
2331 \layout Itemize
2327 \layout Itemize
2332
2328
2333 Expand python variables when calling the shell (either via
2329 Expand python variables when calling the shell (either via
2334 \family typewriter
2330 \family typewriter
2335 `!'
2331 `!'
2336 \family default
2332 \family default
2337 and
2333 and
2338 \family typewriter
2334 \family typewriter
2339 `!!'
2335 `!!'
2340 \family default
2336 \family default
2341 or via aliases) by prepending a
2337 or via aliases) by prepending a
2342 \family typewriter
2338 \family typewriter
2343 $
2339 $
2344 \family default
2340 \family default
2345 in front of them.
2341 in front of them.
2346 You can also expand complete python expressions.
2342 You can also expand complete python expressions.
2347 See sec.\SpecialChar ~
2343 See sec.\SpecialChar ~
2348
2344
2349 \begin_inset LatexCommand \ref{sub:System-shell-access}
2345 \begin_inset LatexCommand \ref{sub:System-shell-access}
2350
2346
2351 \end_inset
2347 \end_inset
2352
2348
2353 for more.
2349 for more.
2354 \layout Itemize
2350 \layout Itemize
2355
2351
2356 Use profiles to maintain different configurations (modules to load, function
2352 Use profiles to maintain different configurations (modules to load, function
2357 definitions, option settings) for particular tasks.
2353 definitions, option settings) for particular tasks.
2358 You can then have customized versions of IPython for specific purposes.
2354 You can then have customized versions of IPython for specific purposes.
2359 See sec.\SpecialChar ~
2355 See sec.\SpecialChar ~
2360
2356
2361 \begin_inset LatexCommand \ref{sec:profiles}
2357 \begin_inset LatexCommand \ref{sec:profiles}
2362
2358
2363 \end_inset
2359 \end_inset
2364
2360
2365 for more.
2361 for more.
2366 \layout Itemize
2362 \layout Itemize
2367
2363
2368 Embed IPython in your programs.
2364 Embed IPython in your programs.
2369 A few lines of code are enough to load a complete IPython inside your own
2365 A few lines of code are enough to load a complete IPython inside your own
2370 programs, giving you the ability to work with your data interactively after
2366 programs, giving you the ability to work with your data interactively after
2371 automatic processing has been completed.
2367 automatic processing has been completed.
2372 See sec.\SpecialChar ~
2368 See sec.\SpecialChar ~
2373
2369
2374 \begin_inset LatexCommand \ref{sec:embed}
2370 \begin_inset LatexCommand \ref{sec:embed}
2375
2371
2376 \end_inset
2372 \end_inset
2377
2373
2378 for more.
2374 for more.
2379 \layout Itemize
2375 \layout Itemize
2380
2376
2381 Use the Python profiler.
2377 Use the Python profiler.
2382 When dealing with performance issues, the
2378 When dealing with performance issues, the
2383 \family typewriter
2379 \family typewriter
2384 %run
2380 %run
2385 \family default
2381 \family default
2386 command with a
2382 command with a
2387 \family typewriter
2383 \family typewriter
2388 -p
2384 -p
2389 \family default
2385 \family default
2390 option allows you to run complete programs under the control of the Python
2386 option allows you to run complete programs under the control of the Python
2391 profiler.
2387 profiler.
2392 The
2388 The
2393 \family typewriter
2389 \family typewriter
2394 %prun
2390 %prun
2395 \family default
2391 \family default
2396 command does a similar job for single Python expressions (like function
2392 command does a similar job for single Python expressions (like function
2397 calls).
2393 calls).
2398 \layout Itemize
2394 \layout Itemize
2399
2395
2400 Use the IPython.demo.Demo class to load any Python script as an interactive
2396 Use the IPython.demo.Demo class to load any Python script as an interactive
2401 demo.
2397 demo.
2402 With a minimal amount of simple markup, you can control the execution of
2398 With a minimal amount of simple markup, you can control the execution of
2403 the script, stopping as needed.
2399 the script, stopping as needed.
2404 See sec.\SpecialChar ~
2400 See sec.\SpecialChar ~
2405
2401
2406 \begin_inset LatexCommand \ref{sec:interactive-demos}
2402 \begin_inset LatexCommand \ref{sec:interactive-demos}
2407
2403
2408 \end_inset
2404 \end_inset
2409
2405
2410 for more.
2406 for more.
2411 \layout Subsection
2407 \layout Subsection
2412
2408
2413 Source code handling tips
2409 Source code handling tips
2414 \layout Standard
2410 \layout Standard
2415
2411
2416 IPython is a line-oriented program, without full control of the terminal.
2412 IPython is a line-oriented program, without full control of the terminal.
2417 Therefore, it doesn't support true multiline editing.
2413 Therefore, it doesn't support true multiline editing.
2418 However, it has a number of useful tools to help you in dealing effectively
2414 However, it has a number of useful tools to help you in dealing effectively
2419 with more complex editing.
2415 with more complex editing.
2420 \layout Standard
2416 \layout Standard
2421
2417
2422 The
2418 The
2423 \family typewriter
2419 \family typewriter
2424 %edit
2420 %edit
2425 \family default
2421 \family default
2426 command gives a reasonable approximation of multiline editing, by invoking
2422 command gives a reasonable approximation of multiline editing, by invoking
2427 your favorite editor on the spot.
2423 your favorite editor on the spot.
2428 IPython will execute the code you type in there as if it were typed interactive
2424 IPython will execute the code you type in there as if it were typed interactive
2429 ly.
2425 ly.
2430 Type
2426 Type
2431 \family typewriter
2427 \family typewriter
2432 %edit?
2428 %edit?
2433 \family default
2429 \family default
2434 for the full details on the edit command.
2430 for the full details on the edit command.
2435 \layout Standard
2431 \layout Standard
2436
2432
2437 If you have typed various commands during a session, which you'd like to
2433 If you have typed various commands during a session, which you'd like to
2438 reuse, IPython provides you with a number of tools.
2434 reuse, IPython provides you with a number of tools.
2439 Start by using
2435 Start by using
2440 \family typewriter
2436 \family typewriter
2441 %hist
2437 %hist
2442 \family default
2438 \family default
2443 to see your input history, so you can see the line numbers of all input.
2439 to see your input history, so you can see the line numbers of all input.
2444 Let us say that you'd like to reuse lines 10 through 20, plus lines 24
2440 Let us say that you'd like to reuse lines 10 through 20, plus lines 24
2445 and 28.
2441 and 28.
2446 All the commands below can operate on these with the syntax
2442 All the commands below can operate on these with the syntax
2447 \layout LyX-Code
2443 \layout LyX-Code
2448
2444
2449 %command 10-20 24 28
2445 %command 10-20 24 28
2450 \layout Standard
2446 \layout Standard
2451
2447
2452 where the command given can be:
2448 where the command given can be:
2453 \layout Itemize
2449 \layout Itemize
2454
2450
2455
2451
2456 \family typewriter
2452 \family typewriter
2457 %macro <macroname>
2453 %macro <macroname>
2458 \family default
2454 \family default
2459 : this stores the lines into a variable which, when called at the prompt,
2455 : this stores the lines into a variable which, when called at the prompt,
2460 re-executes the input.
2456 re-executes the input.
2461 Macros can be edited later using
2457 Macros can be edited later using
2462 \family typewriter
2458 \family typewriter
2463 `%edit macroname
2459 `%edit macroname
2464 \family default
2460 \family default
2465 ', and they can be stored persistently across sessions with `
2461 ', and they can be stored persistently across sessions with `
2466 \family typewriter
2462 \family typewriter
2467 %store macroname
2463 %store macroname
2468 \family default
2464 \family default
2469 ' (the storage system is per-profile).
2465 ' (the storage system is per-profile).
2470 The combination of quick macros, persistent storage and editing, allows
2466 The combination of quick macros, persistent storage and editing, allows
2471 you to easily refine quick-and-dirty interactive input into permanent utilities
2467 you to easily refine quick-and-dirty interactive input into permanent utilities
2472 , always available both in IPython and as files for general reuse.
2468 , always available both in IPython and as files for general reuse.
2473 \layout Itemize
2469 \layout Itemize
2474
2470
2475
2471
2476 \family typewriter
2472 \family typewriter
2477 %edit
2473 %edit
2478 \family default
2474 \family default
2479 : this will open a text editor with those lines pre-loaded for further modificat
2475 : this will open a text editor with those lines pre-loaded for further modificat
2480 ion.
2476 ion.
2481 It will then execute the resulting file's contents as if you had typed
2477 It will then execute the resulting file's contents as if you had typed
2482 it at the prompt.
2478 it at the prompt.
2483 \layout Itemize
2479 \layout Itemize
2484
2480
2485
2481
2486 \family typewriter
2482 \family typewriter
2487 %save <filename>
2483 %save <filename>
2488 \family default
2484 \family default
2489 : this saves the lines directly to a named file on disk.
2485 : this saves the lines directly to a named file on disk.
2490 \layout Standard
2486 \layout Standard
2491
2487
2492 While
2488 While
2493 \family typewriter
2489 \family typewriter
2494 %macro
2490 %macro
2495 \family default
2491 \family default
2496 saves input lines into memory for interactive re-execution, sometimes you'd
2492 saves input lines into memory for interactive re-execution, sometimes you'd
2497 like to save your input directly to a file.
2493 like to save your input directly to a file.
2498 The
2494 The
2499 \family typewriter
2495 \family typewriter
2500 %save
2496 %save
2501 \family default
2497 \family default
2502 magic does this: its input sytnax is the same as
2498 magic does this: its input sytnax is the same as
2503 \family typewriter
2499 \family typewriter
2504 %macro
2500 %macro
2505 \family default
2501 \family default
2506 , but it saves your input directly to a Python file.
2502 , but it saves your input directly to a Python file.
2507 Note that the
2503 Note that the
2508 \family typewriter
2504 \family typewriter
2509 %logstart
2505 %logstart
2510 \family default
2506 \family default
2511 command also saves input, but it logs
2507 command also saves input, but it logs
2512 \emph on
2508 \emph on
2513 all
2509 all
2514 \emph default
2510 \emph default
2515 input to disk (though you can temporarily suspend it and reactivate it
2511 input to disk (though you can temporarily suspend it and reactivate it
2516 with
2512 with
2517 \family typewriter
2513 \family typewriter
2518 %logoff/%logon
2514 %logoff/%logon
2519 \family default
2515 \family default
2520 );
2516 );
2521 \family typewriter
2517 \family typewriter
2522 %save
2518 %save
2523 \family default
2519 \family default
2524 allows you to select which lines of input you need to save.
2520 allows you to select which lines of input you need to save.
2525 \layout Subsubsection*
2521 \layout Subsubsection*
2526
2522
2527 Lightweight 'version control'
2523 Lightweight 'version control'
2528 \layout Standard
2524 \layout Standard
2529
2525
2530 When you call
2526 When you call
2531 \family typewriter
2527 \family typewriter
2532 %edit
2528 %edit
2533 \family default
2529 \family default
2534 with no arguments, IPython opens an empty editor with a temporary file,
2530 with no arguments, IPython opens an empty editor with a temporary file,
2535 and it returns the contents of your editing session as a string variable.
2531 and it returns the contents of your editing session as a string variable.
2536 Thanks to IPython's output caching mechanism, this is automatically stored:
2532 Thanks to IPython's output caching mechanism, this is automatically stored:
2537 \layout LyX-Code
2533 \layout LyX-Code
2538
2534
2539 In [1]: %edit
2535 In [1]: %edit
2540 \layout LyX-Code
2536 \layout LyX-Code
2541
2537
2542 IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py
2538 IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py
2543 \layout LyX-Code
2539 \layout LyX-Code
2544
2540
2545 Editing...
2541 Editing...
2546 done.
2542 done.
2547 Executing edited code...
2543 Executing edited code...
2548 \layout LyX-Code
2544 \layout LyX-Code
2549
2545
2550 hello - this is a temporary file
2546 hello - this is a temporary file
2551 \layout LyX-Code
2547 \layout LyX-Code
2552
2548
2553 Out[1]: "print 'hello - this is a temporary file'
2549 Out[1]: "print 'hello - this is a temporary file'
2554 \backslash
2550 \backslash
2555 n"
2551 n"
2556 \layout Standard
2552 \layout Standard
2557
2553
2558 Now, if you call
2554 Now, if you call
2559 \family typewriter
2555 \family typewriter
2560 `%edit -p'
2556 `%edit -p'
2561 \family default
2557 \family default
2562 , IPython tries to open an editor with the same data as the last time you
2558 , IPython tries to open an editor with the same data as the last time you
2563 used
2559 used
2564 \family typewriter
2560 \family typewriter
2565 %edit
2561 %edit
2566 \family default
2562 \family default
2567 .
2563 .
2568 So if you haven't used
2564 So if you haven't used
2569 \family typewriter
2565 \family typewriter
2570 %edit
2566 %edit
2571 \family default
2567 \family default
2572 in the meantime, this same contents will reopen; however, it will be done
2568 in the meantime, this same contents will reopen; however, it will be done
2573 in a
2569 in a
2574 \emph on
2570 \emph on
2575 new file
2571 new file
2576 \emph default
2572 \emph default
2577 .
2573 .
2578 This means that if you make changes and you later want to find an old version,
2574 This means that if you make changes and you later want to find an old version,
2579 you can always retrieve it by using its output number, via
2575 you can always retrieve it by using its output number, via
2580 \family typewriter
2576 \family typewriter
2581 `%edit _NN'
2577 `%edit _NN'
2582 \family default
2578 \family default
2583 , where
2579 , where
2584 \family typewriter
2580 \family typewriter
2585 NN
2581 NN
2586 \family default
2582 \family default
2587 is the number of the output prompt.
2583 is the number of the output prompt.
2588 \layout Standard
2584 \layout Standard
2589
2585
2590 Continuing with the example above, this should illustrate this idea:
2586 Continuing with the example above, this should illustrate this idea:
2591 \layout LyX-Code
2587 \layout LyX-Code
2592
2588
2593 In [2]: edit -p
2589 In [2]: edit -p
2594 \layout LyX-Code
2590 \layout LyX-Code
2595
2591
2596 IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py
2592 IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py
2597 \layout LyX-Code
2593 \layout LyX-Code
2598
2594
2599 Editing...
2595 Editing...
2600 done.
2596 done.
2601 Executing edited code...
2597 Executing edited code...
2602 \layout LyX-Code
2598 \layout LyX-Code
2603
2599
2604 hello - now I made some changes
2600 hello - now I made some changes
2605 \layout LyX-Code
2601 \layout LyX-Code
2606
2602
2607 Out[2]: "print 'hello - now I made some changes'
2603 Out[2]: "print 'hello - now I made some changes'
2608 \backslash
2604 \backslash
2609 n"
2605 n"
2610 \layout LyX-Code
2606 \layout LyX-Code
2611
2607
2612 In [3]: edit _1
2608 In [3]: edit _1
2613 \layout LyX-Code
2609 \layout LyX-Code
2614
2610
2615 IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py
2611 IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py
2616 \layout LyX-Code
2612 \layout LyX-Code
2617
2613
2618 Editing...
2614 Editing...
2619 done.
2615 done.
2620 Executing edited code...
2616 Executing edited code...
2621 \layout LyX-Code
2617 \layout LyX-Code
2622
2618
2623 hello - this is a temporary file
2619 hello - this is a temporary file
2624 \layout LyX-Code
2620 \layout LyX-Code
2625
2621
2626 IPython version control at work :)
2622 IPython version control at work :)
2627 \layout LyX-Code
2623 \layout LyX-Code
2628
2624
2629 Out[3]: "print 'hello - this is a temporary file'
2625 Out[3]: "print 'hello - this is a temporary file'
2630 \backslash
2626 \backslash
2631 nprint 'IPython version control at work :)'
2627 nprint 'IPython version control at work :)'
2632 \backslash
2628 \backslash
2633 n"
2629 n"
2634 \layout Standard
2630 \layout Standard
2635
2631
2636 This section was written after a contribution by Alexander Belchenko on
2632 This section was written after a contribution by Alexander Belchenko on
2637 the IPython user list.
2633 the IPython user list.
2638 \layout LyX-Code
2634 \layout LyX-Code
2639
2635
2640 \layout Subsection
2636 \layout Subsection
2641
2637
2642 Effective logging
2638 Effective logging
2643 \layout Standard
2639 \layout Standard
2644
2640
2645 A very useful suggestion sent in by Robert Kern follows:
2641 A very useful suggestion sent in by Robert Kern follows:
2646 \layout Standard
2642 \layout Standard
2647
2643
2648 I recently happened on a nifty way to keep tidy per-project log files.
2644 I recently happened on a nifty way to keep tidy per-project log files.
2649 I made a profile for my project (which is called "parkfield").
2645 I made a profile for my project (which is called "parkfield").
2650 \layout LyX-Code
2646 \layout LyX-Code
2651
2647
2652 include ipythonrc
2648 include ipythonrc
2653 \layout LyX-Code
2649 \layout LyX-Code
2654
2650
2655 # cancel earlier logfile invocation:
2651 # cancel earlier logfile invocation:
2656 \layout LyX-Code
2652 \layout LyX-Code
2657
2653
2658 logfile ''
2654 logfile ''
2659 \layout LyX-Code
2655 \layout LyX-Code
2660
2656
2661 execute import time
2657 execute import time
2662 \layout LyX-Code
2658 \layout LyX-Code
2663
2659
2664 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
2660 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
2665 \layout LyX-Code
2661 \layout LyX-Code
2666
2662
2667 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
2663 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
2668 \layout Standard
2664 \layout Standard
2669
2665
2670 I also added a shell alias for convenience:
2666 I also added a shell alias for convenience:
2671 \layout LyX-Code
2667 \layout LyX-Code
2672
2668
2673 alias parkfield="ipython -pylab -profile parkfield"
2669 alias parkfield="ipython -pylab -profile parkfield"
2674 \layout Standard
2670 \layout Standard
2675
2671
2676 Now I have a nice little directory with everything I ever type in, organized
2672 Now I have a nice little directory with everything I ever type in, organized
2677 by project and date.
2673 by project and date.
2678 \layout Standard
2674 \layout Standard
2679
2675
2680
2676
2681 \series bold
2677 \series bold
2682 Contribute your own:
2678 Contribute your own:
2683 \series default
2679 \series default
2684 If you have your own favorite tip on using IPython efficiently for a certain
2680 If you have your own favorite tip on using IPython efficiently for a certain
2685 task (especially things which can't be done in the normal Python interpreter),
2681 task (especially things which can't be done in the normal Python interpreter),
2686 don't hesitate to send it!
2682 don't hesitate to send it!
2687 \layout Section
2683 \layout Section
2688
2684
2689 Command-line use
2685 Command-line use
2690 \layout Standard
2686 \layout Standard
2691
2687
2692 You start IPython with the command:
2688 You start IPython with the command:
2693 \layout Standard
2689 \layout Standard
2694
2690
2695
2691
2696 \family typewriter
2692 \family typewriter
2697 $ ipython [options] files
2693 $ ipython [options] files
2698 \layout Standard
2694 \layout Standard
2699
2695
2700 If invoked with no options, it executes all the files listed in sequence
2696 If invoked with no options, it executes all the files listed in sequence
2701 and drops you into the interpreter while still acknowledging any options
2697 and drops you into the interpreter while still acknowledging any options
2702 you may have set in your ipythonrc file.
2698 you may have set in your ipythonrc file.
2703 This behavior is different from standard Python, which when called as
2699 This behavior is different from standard Python, which when called as
2704 \family typewriter
2700 \family typewriter
2705 python -i
2701 python -i
2706 \family default
2702 \family default
2707 will only execute one file and ignore your configuration setup.
2703 will only execute one file and ignore your configuration setup.
2708 \layout Standard
2704 \layout Standard
2709
2705
2710 Please note that some of the configuration options are not available at
2706 Please note that some of the configuration options are not available at
2711 the command line, simply because they are not practical here.
2707 the command line, simply because they are not practical here.
2712 Look into your ipythonrc configuration file for details on those.
2708 Look into your ipythonrc configuration file for details on those.
2713 This file typically installed in the
2709 This file typically installed in the
2714 \family typewriter
2710 \family typewriter
2715 $HOME/.ipython
2711 $HOME/.ipython
2716 \family default
2712 \family default
2717 directory.
2713 directory.
2718 For Windows users,
2714 For Windows users,
2719 \family typewriter
2715 \family typewriter
2720 $HOME
2716 $HOME
2721 \family default
2717 \family default
2722 resolves to
2718 resolves to
2723 \family typewriter
2719 \family typewriter
2724 C:
2720 C:
2725 \backslash
2721 \backslash
2726
2722
2727 \backslash
2723 \backslash
2728 Documents and Settings
2724 Documents and Settings
2729 \backslash
2725 \backslash
2730
2726
2731 \backslash
2727 \backslash
2732 YourUserName
2728 YourUserName
2733 \family default
2729 \family default
2734 in most instances.
2730 in most instances.
2735 In the rest of this text, we will refer to this directory as
2731 In the rest of this text, we will refer to this directory as
2736 \family typewriter
2732 \family typewriter
2737 IPYTHONDIR
2733 IPYTHONDIR
2738 \family default
2734 \family default
2739 .
2735 .
2740 \layout Subsection
2736 \layout Subsection
2741
2737
2742
2738
2743 \begin_inset LatexCommand \label{sec:threading-opts}
2739 \begin_inset LatexCommand \label{sec:threading-opts}
2744
2740
2745 \end_inset
2741 \end_inset
2746
2742
2747 Special Threading Options
2743 Special Threading Options
2748 \layout Standard
2744 \layout Standard
2749
2745
2750 The following special options are ONLY valid at the beginning of the command
2746 The following special options are ONLY valid at the beginning of the command
2751 line, and not later.
2747 line, and not later.
2752 This is because they control the initial- ization of ipython itself, before
2748 This is because they control the initial- ization of ipython itself, before
2753 the normal option-handling mechanism is active.
2749 the normal option-handling mechanism is active.
2754 \layout List
2750 \layout List
2755 \labelwidthstring 00.00.0000
2751 \labelwidthstring 00.00.0000
2756
2752
2757
2753
2758 \family typewriter
2754 \family typewriter
2759 \series bold
2755 \series bold
2760 -gthread,\SpecialChar ~
2756 -gthread,\SpecialChar ~
2761 -qthread,\SpecialChar ~
2757 -qthread,\SpecialChar ~
2762 -wthread,\SpecialChar ~
2758 -wthread,\SpecialChar ~
2763 -pylab:
2759 -pylab:
2764 \family default
2760 \family default
2765 \series default
2761 \series default
2766 Only
2762 Only
2767 \emph on
2763 \emph on
2768 one
2764 one
2769 \emph default
2765 \emph default
2770 of these can be given, and it can only be given as the first option passed
2766 of these can be given, and it can only be given as the first option passed
2771 to IPython (it will have no effect in any other position).
2767 to IPython (it will have no effect in any other position).
2772 They provide threading support for the GTK Qt and WXPython toolkits, and
2768 They provide threading support for the GTK Qt and WXPython toolkits, and
2773 for the matplotlib library.
2769 for the matplotlib library.
2774 \layout List
2770 \layout List
2775 \labelwidthstring 00.00.0000
2771 \labelwidthstring 00.00.0000
2776
2772
2777 \SpecialChar ~
2773 \SpecialChar ~
2778 With any of the first three options, IPython starts running a separate
2774 With any of the first three options, IPython starts running a separate
2779 thread for the graphical toolkit's operation, so that you can open and
2775 thread for the graphical toolkit's operation, so that you can open and
2780 control graphical elements from within an IPython command line, without
2776 control graphical elements from within an IPython command line, without
2781 blocking.
2777 blocking.
2782 All three provide essentially the same functionality, respectively for
2778 All three provide essentially the same functionality, respectively for
2783 GTK, QT and WXWidgets (via their Python interfaces).
2779 GTK, QT and WXWidgets (via their Python interfaces).
2784 \layout List
2780 \layout List
2785 \labelwidthstring 00.00.0000
2781 \labelwidthstring 00.00.0000
2786
2782
2787 \SpecialChar ~
2783 \SpecialChar ~
2788 Note that with
2784 Note that with
2789 \family typewriter
2785 \family typewriter
2790 -wthread
2786 -wthread
2791 \family default
2787 \family default
2792 , you can additionally use the -wxversion option to request a specific version
2788 , you can additionally use the -wxversion option to request a specific version
2793 of wx to be used.
2789 of wx to be used.
2794 This requires that you have the
2790 This requires that you have the
2795 \family typewriter
2791 \family typewriter
2796 wxversion
2792 wxversion
2797 \family default
2793 \family default
2798 Python module installed, which is part of recent wxPython distributions.
2794 Python module installed, which is part of recent wxPython distributions.
2799 \layout List
2795 \layout List
2800 \labelwidthstring 00.00.0000
2796 \labelwidthstring 00.00.0000
2801
2797
2802 \SpecialChar ~
2798 \SpecialChar ~
2803 If
2799 If
2804 \family typewriter
2800 \family typewriter
2805 -pylab
2801 -pylab
2806 \family default
2802 \family default
2807 is given, IPython loads special support for the mat plotlib library (
2803 is given, IPython loads special support for the mat plotlib library (
2808 \begin_inset LatexCommand \htmlurl{http://matplotlib.sourceforge.net}
2804 \begin_inset LatexCommand \htmlurl{http://matplotlib.sourceforge.net}
2809
2805
2810 \end_inset
2806 \end_inset
2811
2807
2812 ), allowing interactive usage of any of its backends as defined in the user's
2808 ), allowing interactive usage of any of its backends as defined in the user's
2813
2809
2814 \family typewriter
2810 \family typewriter
2815 ~/.matplotlib/matplotlibrc
2811 ~/.matplotlib/matplotlibrc
2816 \family default
2812 \family default
2817 file.
2813 file.
2818 It automatically activates GTK, Qt or WX threading for IPyhton if the choice
2814 It automatically activates GTK, Qt or WX threading for IPyhton if the choice
2819 of matplotlib backend requires it.
2815 of matplotlib backend requires it.
2820 It also modifies the
2816 It also modifies the
2821 \family typewriter
2817 \family typewriter
2822 %run
2818 %run
2823 \family default
2819 \family default
2824 command to correctly execute (without blocking) any matplotlib-based script
2820 command to correctly execute (without blocking) any matplotlib-based script
2825 which calls
2821 which calls
2826 \family typewriter
2822 \family typewriter
2827 show()
2823 show()
2828 \family default
2824 \family default
2829 at the end.
2825 at the end.
2830
2826
2831 \layout List
2827 \layout List
2832 \labelwidthstring 00.00.0000
2828 \labelwidthstring 00.00.0000
2833
2829
2834
2830
2835 \family typewriter
2831 \family typewriter
2836 \series bold
2832 \series bold
2837 -tk
2833 -tk
2838 \family default
2834 \family default
2839 \series default
2835 \series default
2840 The
2836 The
2841 \family typewriter
2837 \family typewriter
2842 -g/q/wthread
2838 -g/q/wthread
2843 \family default
2839 \family default
2844 options, and
2840 options, and
2845 \family typewriter
2841 \family typewriter
2846 -pylab
2842 -pylab
2847 \family default
2843 \family default
2848 (if matplotlib is configured to use GTK, Qt or WX), will normally block
2844 (if matplotlib is configured to use GTK, Qt or WX), will normally block
2849 Tk graphical interfaces.
2845 Tk graphical interfaces.
2850 This means that when either GTK, Qt or WX threading is active, any attempt
2846 This means that when either GTK, Qt or WX threading is active, any attempt
2851 to open a Tk GUI will result in a dead window, and possibly cause the Python
2847 to open a Tk GUI will result in a dead window, and possibly cause the Python
2852 interpreter to crash.
2848 interpreter to crash.
2853 An extra option,
2849 An extra option,
2854 \family typewriter
2850 \family typewriter
2855 -tk
2851 -tk
2856 \family default
2852 \family default
2857 , is available to address this issue.
2853 , is available to address this issue.
2858 It can
2854 It can
2859 \emph on
2855 \emph on
2860 only
2856 only
2861 \emph default
2857 \emph default
2862 be given as a
2858 be given as a
2863 \emph on
2859 \emph on
2864 second
2860 second
2865 \emph default
2861 \emph default
2866 option after any of the above (
2862 option after any of the above (
2867 \family typewriter
2863 \family typewriter
2868 -gthread
2864 -gthread
2869 \family default
2865 \family default
2870 ,
2866 ,
2871 \family typewriter
2867 \family typewriter
2872 -wthread
2868 -wthread
2873 \family default
2869 \family default
2874 or
2870 or
2875 \family typewriter
2871 \family typewriter
2876 -pylab
2872 -pylab
2877 \family default
2873 \family default
2878 ).
2874 ).
2879 \layout List
2875 \layout List
2880 \labelwidthstring 00.00.0000
2876 \labelwidthstring 00.00.0000
2881
2877
2882 \SpecialChar ~
2878 \SpecialChar ~
2883 If
2879 If
2884 \family typewriter
2880 \family typewriter
2885 -tk
2881 -tk
2886 \family default
2882 \family default
2887 is given, IPython will try to coordinate Tk threading with GTK, Qt or WX.
2883 is given, IPython will try to coordinate Tk threading with GTK, Qt or WX.
2888 This is however potentially unreliable, and you will have to test on your
2884 This is however potentially unreliable, and you will have to test on your
2889 platform and Python configuration to determine whether it works for you.
2885 platform and Python configuration to determine whether it works for you.
2890 Debian users have reported success, apparently due to the fact that Debian
2886 Debian users have reported success, apparently due to the fact that Debian
2891 builds all of Tcl, Tk, Tkinter and Python with pthreads support.
2887 builds all of Tcl, Tk, Tkinter and Python with pthreads support.
2892 Under other Linux environments (such as Fedora Core 2/3), this option has
2888 Under other Linux environments (such as Fedora Core 2/3), this option has
2893 caused random crashes and lockups of the Python interpreter.
2889 caused random crashes and lockups of the Python interpreter.
2894 Under other operating systems (Mac OSX and Windows), you'll need to try
2890 Under other operating systems (Mac OSX and Windows), you'll need to try
2895 it to find out, since currently no user reports are available.
2891 it to find out, since currently no user reports are available.
2896 \layout List
2892 \layout List
2897 \labelwidthstring 00.00.0000
2893 \labelwidthstring 00.00.0000
2898
2894
2899 \SpecialChar ~
2895 \SpecialChar ~
2900 There is unfortunately no way for IPython to determine at run time whether
2896 There is unfortunately no way for IPython to determine at run time whether
2901
2897
2902 \family typewriter
2898 \family typewriter
2903 -tk
2899 -tk
2904 \family default
2900 \family default
2905 will work reliably or not, so you will need to do some experiments before
2901 will work reliably or not, so you will need to do some experiments before
2906 relying on it for regular work.
2902 relying on it for regular work.
2907
2903
2908 \layout Subsection
2904 \layout Subsection
2909
2905
2910
2906
2911 \begin_inset LatexCommand \label{sec:cmd-line-opts}
2907 \begin_inset LatexCommand \label{sec:cmd-line-opts}
2912
2908
2913 \end_inset
2909 \end_inset
2914
2910
2915 Regular Options
2911 Regular Options
2916 \layout Standard
2912 \layout Standard
2917
2913
2918 After the above threading options have been given, regular options can follow
2914 After the above threading options have been given, regular options can follow
2919 in any order.
2915 in any order.
2920 All options can be abbreviated to their shortest non-ambiguous form and
2916 All options can be abbreviated to their shortest non-ambiguous form and
2921 are case-sensitive.
2917 are case-sensitive.
2922 One or two dashes can be used.
2918 One or two dashes can be used.
2923 Some options have an alternate short form, indicated after a
2919 Some options have an alternate short form, indicated after a
2924 \family typewriter
2920 \family typewriter
2925 |
2921 |
2926 \family default
2922 \family default
2927 .
2923 .
2928 \layout Standard
2924 \layout Standard
2929
2925
2930 Most options can also be set from your ipythonrc configuration file.
2926 Most options can also be set from your ipythonrc configuration file.
2931 See the provided example for more details on what the options do.
2927 See the provided example for more details on what the options do.
2932 Options given at the command line override the values set in the ipythonrc
2928 Options given at the command line override the values set in the ipythonrc
2933 file.
2929 file.
2934 \layout Standard
2930 \layout Standard
2935
2931
2936 All options with a
2932 All options with a
2937 \family typewriter
2933 \family typewriter
2938 [no]
2934 [no]
2939 \family default
2935 \family default
2940 prepended can be specified in negated form (
2936 prepended can be specified in negated form (
2941 \family typewriter
2937 \family typewriter
2942 -nooption
2938 -nooption
2943 \family default
2939 \family default
2944 instead of
2940 instead of
2945 \family typewriter
2941 \family typewriter
2946 -option
2942 -option
2947 \family default
2943 \family default
2948 ) to turn the feature off.
2944 ) to turn the feature off.
2949 \layout List
2945 \layout List
2950 \labelwidthstring 00.00.0000
2946 \labelwidthstring 00.00.0000
2951
2947
2952
2948
2953 \family typewriter
2949 \family typewriter
2954 \series bold
2950 \series bold
2955 -help
2951 -help
2956 \family default
2952 \family default
2957 \series default
2953 \series default
2958 : print a help message and exit.
2954 : print a help message and exit.
2959 \layout List
2955 \layout List
2960 \labelwidthstring 00.00.0000
2956 \labelwidthstring 00.00.0000
2961
2957
2962
2958
2963 \family typewriter
2959 \family typewriter
2964 \series bold
2960 \series bold
2965 -pylab:
2961 -pylab:
2966 \family default
2962 \family default
2967 \series default
2963 \series default
2968 this can
2964 this can
2969 \emph on
2965 \emph on
2970 only
2966 only
2971 \emph default
2967 \emph default
2972 be given as the
2968 be given as the
2973 \emph on
2969 \emph on
2974 first
2970 first
2975 \emph default
2971 \emph default
2976 option passed to IPython (it will have no effect in any other position).
2972 option passed to IPython (it will have no effect in any other position).
2977 It adds special support for the matplotlib library (
2973 It adds special support for the matplotlib library (
2978 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
2974 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
2979
2975
2980 \end_inset
2976 \end_inset
2981
2977
2982 ), allowing interactive usage of any of its backends as defined in the user's
2978 ), allowing interactive usage of any of its backends as defined in the user's
2983
2979
2984 \family typewriter
2980 \family typewriter
2985 .matplotlibrc
2981 .matplotlibrc
2986 \family default
2982 \family default
2987 file.
2983 file.
2988 It automatically activates GTK or WX threading for IPyhton if the choice
2984 It automatically activates GTK or WX threading for IPyhton if the choice
2989 of matplotlib backend requires it.
2985 of matplotlib backend requires it.
2990 It also modifies the
2986 It also modifies the
2991 \family typewriter
2987 \family typewriter
2992 %run
2988 %run
2993 \family default
2989 \family default
2994 command to correctly execute (without blocking) any matplotlib-based script
2990 command to correctly execute (without blocking) any matplotlib-based script
2995 which calls
2991 which calls
2996 \family typewriter
2992 \family typewriter
2997 show()
2993 show()
2998 \family default
2994 \family default
2999 at the end.
2995 at the end.
3000 See Sec.\SpecialChar ~
2996 See Sec.\SpecialChar ~
3001
2997
3002 \begin_inset LatexCommand \ref{sec:matplotlib-support}
2998 \begin_inset LatexCommand \ref{sec:matplotlib-support}
3003
2999
3004 \end_inset
3000 \end_inset
3005
3001
3006 for more details.
3002 for more details.
3007 \layout List
3003 \layout List
3008 \labelwidthstring 00.00.0000
3004 \labelwidthstring 00.00.0000
3009
3005
3010
3006
3011 \family typewriter
3007 \family typewriter
3012 \series bold
3008 \series bold
3013 -autocall <val>:
3009 -autocall <val>:
3014 \family default
3010 \family default
3015 \series default
3011 \series default
3016 Make IPython automatically call any callable object even if you didn't
3012 Make IPython automatically call any callable object even if you didn't
3017 type explicit parentheses.
3013 type explicit parentheses.
3018 For example, `str 43' becomes `str(43)' automatically.
3014 For example, `str 43' becomes `str(43)' automatically.
3019 The value can be `0' to disable the feature, `1' for
3015 The value can be `0' to disable the feature, `1' for
3020 \emph on
3016 \emph on
3021 smart
3017 smart
3022 \emph default
3018 \emph default
3023 autocall, where it is not applied if there are no more arguments on the
3019 autocall, where it is not applied if there are no more arguments on the
3024 line, and `2' for
3020 line, and `2' for
3025 \emph on
3021 \emph on
3026 full
3022 full
3027 \emph default
3023 \emph default
3028 autocall, where all callable objects are automatically called (even if
3024 autocall, where all callable objects are automatically called (even if
3029 no arguments are present).
3025 no arguments are present).
3030 The default is `1'.
3026 The default is `1'.
3031 \layout List
3027 \layout List
3032 \labelwidthstring 00.00.0000
3028 \labelwidthstring 00.00.0000
3033
3029
3034
3030
3035 \family typewriter
3031 \family typewriter
3036 \series bold
3032 \series bold
3037 -[no]autoindent:
3033 -[no]autoindent:
3038 \family default
3034 \family default
3039 \series default
3035 \series default
3040 Turn automatic indentation on/off.
3036 Turn automatic indentation on/off.
3041 \layout List
3037 \layout List
3042 \labelwidthstring 00.00.0000
3038 \labelwidthstring 00.00.0000
3043
3039
3044
3040
3045 \family typewriter
3041 \family typewriter
3046 \series bold
3042 \series bold
3047 -[no]automagic
3043 -[no]automagic
3048 \series default
3044 \series default
3049 :
3045 :
3050 \family default
3046 \family default
3051 make magic commands automatic (without needing their first character to
3047 make magic commands automatic (without needing their first character to
3052 be
3048 be
3053 \family typewriter
3049 \family typewriter
3054 %
3050 %
3055 \family default
3051 \family default
3056 ).
3052 ).
3057 Type
3053 Type
3058 \family typewriter
3054 \family typewriter
3059 %magic
3055 %magic
3060 \family default
3056 \family default
3061 at the IPython prompt for more information.
3057 at the IPython prompt for more information.
3062 \layout List
3058 \layout List
3063 \labelwidthstring 00.00.0000
3059 \labelwidthstring 00.00.0000
3064
3060
3065
3061
3066 \family typewriter
3062 \family typewriter
3067 \series bold
3063 \series bold
3068 -[no]autoedit_syntax:
3064 -[no]autoedit_syntax:
3069 \family default
3065 \family default
3070 \series default
3066 \series default
3071 When a syntax error occurs after editing a file, automatically open the
3067 When a syntax error occurs after editing a file, automatically open the
3072 file to the trouble causing line for convenient fixing.
3068 file to the trouble causing line for convenient fixing.
3073
3069
3074 \layout List
3070 \layout List
3075 \labelwidthstring 00.00.0000
3071 \labelwidthstring 00.00.0000
3076
3072
3077
3073
3078 \family typewriter
3074 \family typewriter
3079 \series bold
3075 \series bold
3080 -[no]banner
3076 -[no]banner
3081 \series default
3077 \series default
3082 :
3078 :
3083 \family default
3079 \family default
3084 Print the initial information banner (default on).
3080 Print the initial information banner (default on).
3085 \layout List
3081 \layout List
3086 \labelwidthstring 00.00.0000
3082 \labelwidthstring 00.00.0000
3087
3083
3088
3084
3089 \family typewriter
3085 \family typewriter
3090 \series bold
3086 \series bold
3091 -c\SpecialChar ~
3087 -c\SpecialChar ~
3092 <command>:
3088 <command>:
3093 \family default
3089 \family default
3094 \series default
3090 \series default
3095 execute the given command string, and set sys.argv to
3091 execute the given command string, and set sys.argv to
3096 \family typewriter
3092 \family typewriter
3097 ['c']
3093 ['c']
3098 \family default
3094 \family default
3099 .
3095 .
3100 This is similar to the
3096 This is similar to the
3101 \family typewriter
3097 \family typewriter
3102 -c
3098 -c
3103 \family default
3099 \family default
3104 option in the normal Python interpreter.
3100 option in the normal Python interpreter.
3105
3101
3106 \layout List
3102 \layout List
3107 \labelwidthstring 00.00.0000
3103 \labelwidthstring 00.00.0000
3108
3104
3109
3105
3110 \family typewriter
3106 \family typewriter
3111 \series bold
3107 \series bold
3112 -cache_size|cs\SpecialChar ~
3108 -cache_size|cs\SpecialChar ~
3113 <n>
3109 <n>
3114 \series default
3110 \series default
3115 :
3111 :
3116 \family default
3112 \family default
3117 size of the output cache (maximum number of entries to hold in memory).
3113 size of the output cache (maximum number of entries to hold in memory).
3118 The default is 1000, you can change it permanently in your config file.
3114 The default is 1000, you can change it permanently in your config file.
3119 Setting it to 0 completely disables the caching system, and the minimum
3115 Setting it to 0 completely disables the caching system, and the minimum
3120 value accepted is 20 (if you provide a value less than 20, it is reset
3116 value accepted is 20 (if you provide a value less than 20, it is reset
3121 to 0 and a warning is issued) This limit is defined because otherwise you'll
3117 to 0 and a warning is issued) This limit is defined because otherwise you'll
3122 spend more time re-flushing a too small cache than working.
3118 spend more time re-flushing a too small cache than working.
3123 \layout List
3119 \layout List
3124 \labelwidthstring 00.00.0000
3120 \labelwidthstring 00.00.0000
3125
3121
3126
3122
3127 \family typewriter
3123 \family typewriter
3128 \series bold
3124 \series bold
3129 -classic|cl
3125 -classic|cl
3130 \series default
3126 \series default
3131 :
3127 :
3132 \family default
3128 \family default
3133 Gives IPython a similar feel to the classic Python prompt.
3129 Gives IPython a similar feel to the classic Python prompt.
3134 \layout List
3130 \layout List
3135 \labelwidthstring 00.00.0000
3131 \labelwidthstring 00.00.0000
3136
3132
3137
3133
3138 \family typewriter
3134 \family typewriter
3139 \series bold
3135 \series bold
3140 -colors\SpecialChar ~
3136 -colors\SpecialChar ~
3141 <scheme>:
3137 <scheme>:
3142 \family default
3138 \family default
3143 \series default
3139 \series default
3144 Color scheme for prompts and exception reporting.
3140 Color scheme for prompts and exception reporting.
3145 Currently implemented: NoColor, Linux and LightBG.
3141 Currently implemented: NoColor, Linux and LightBG.
3146 \layout List
3142 \layout List
3147 \labelwidthstring 00.00.0000
3143 \labelwidthstring 00.00.0000
3148
3144
3149
3145
3150 \family typewriter
3146 \family typewriter
3151 \series bold
3147 \series bold
3152 -[no]color_info:
3148 -[no]color_info:
3153 \family default
3149 \family default
3154 \series default
3150 \series default
3155 IPython can display information about objects via a set of functions, and
3151 IPython can display information about objects via a set of functions, and
3156 optionally can use colors for this, syntax highlighting source code and
3152 optionally can use colors for this, syntax highlighting source code and
3157 various other elements.
3153 various other elements.
3158 However, because this information is passed through a pager (like 'less')
3154 However, because this information is passed through a pager (like 'less')
3159 and many pagers get confused with color codes, this option is off by default.
3155 and many pagers get confused with color codes, this option is off by default.
3160 You can test it and turn it on permanently in your ipythonrc file if it
3156 You can test it and turn it on permanently in your ipythonrc file if it
3161 works for you.
3157 works for you.
3162 As a reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
3158 As a reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
3163 that in RedHat 7.2 doesn't.
3159 that in RedHat 7.2 doesn't.
3164 \layout List
3160 \layout List
3165 \labelwidthstring 00.00.0000
3161 \labelwidthstring 00.00.0000
3166
3162
3167 \SpecialChar ~
3163 \SpecialChar ~
3168 Test it and turn it on permanently if it works with your system.
3164 Test it and turn it on permanently if it works with your system.
3169 The magic function
3165 The magic function
3170 \family typewriter
3166 \family typewriter
3171 %color_info
3167 %color_info
3172 \family default
3168 \family default
3173 allows you to toggle this interactively for testing.
3169 allows you to toggle this interactively for testing.
3174 \layout List
3170 \layout List
3175 \labelwidthstring 00.00.0000
3171 \labelwidthstring 00.00.0000
3176
3172
3177
3173
3178 \family typewriter
3174 \family typewriter
3179 \series bold
3175 \series bold
3180 -[no]debug
3176 -[no]debug
3181 \family default
3177 \family default
3182 \series default
3178 \series default
3183 : Show information about the loading process.
3179 : Show information about the loading process.
3184 Very useful to pin down problems with your configuration files or to get
3180 Very useful to pin down problems with your configuration files or to get
3185 details about session restores.
3181 details about session restores.
3186 \layout List
3182 \layout List
3187 \labelwidthstring 00.00.0000
3183 \labelwidthstring 00.00.0000
3188
3184
3189
3185
3190 \family typewriter
3186 \family typewriter
3191 \series bold
3187 \series bold
3192 -[no]deep_reload
3188 -[no]deep_reload
3193 \series default
3189 \series default
3194 :
3190 :
3195 \family default
3191 \family default
3196 IPython can use the
3192 IPython can use the
3197 \family typewriter
3193 \family typewriter
3198 deep_reload
3194 deep_reload
3199 \family default
3195 \family default
3200 module which reloads changes in modules recursively (it replaces the
3196 module which reloads changes in modules recursively (it replaces the
3201 \family typewriter
3197 \family typewriter
3202 reload()
3198 reload()
3203 \family default
3199 \family default
3204 function, so you don't need to change anything to use it).
3200 function, so you don't need to change anything to use it).
3205
3201
3206 \family typewriter
3202 \family typewriter
3207 deep_reload()
3203 deep_reload()
3208 \family default
3204 \family default
3209 forces a full reload of modules whose code may have changed, which the
3205 forces a full reload of modules whose code may have changed, which the
3210 default
3206 default
3211 \family typewriter
3207 \family typewriter
3212 reload()
3208 reload()
3213 \family default
3209 \family default
3214 function does not.
3210 function does not.
3215 \layout List
3211 \layout List
3216 \labelwidthstring 00.00.0000
3212 \labelwidthstring 00.00.0000
3217
3213
3218 \SpecialChar ~
3214 \SpecialChar ~
3219 When deep_reload is off, IPython will use the normal
3215 When deep_reload is off, IPython will use the normal
3220 \family typewriter
3216 \family typewriter
3221 reload()
3217 reload()
3222 \family default
3218 \family default
3223 , but deep_reload will still be available as
3219 , but deep_reload will still be available as
3224 \family typewriter
3220 \family typewriter
3225 dreload()
3221 dreload()
3226 \family default
3222 \family default
3227 .
3223 .
3228 This feature is off by default [which means that you have both normal
3224 This feature is off by default [which means that you have both normal
3229 \family typewriter
3225 \family typewriter
3230 reload()
3226 reload()
3231 \family default
3227 \family default
3232 and
3228 and
3233 \family typewriter
3229 \family typewriter
3234 dreload()
3230 dreload()
3235 \family default
3231 \family default
3236 ].
3232 ].
3237 \layout List
3233 \layout List
3238 \labelwidthstring 00.00.0000
3234 \labelwidthstring 00.00.0000
3239
3235
3240
3236
3241 \family typewriter
3237 \family typewriter
3242 \series bold
3238 \series bold
3243 -editor\SpecialChar ~
3239 -editor\SpecialChar ~
3244 <name>
3240 <name>
3245 \family default
3241 \family default
3246 \series default
3242 \series default
3247 : Which editor to use with the
3243 : Which editor to use with the
3248 \family typewriter
3244 \family typewriter
3249 %edit
3245 %edit
3250 \family default
3246 \family default
3251 command.
3247 command.
3252 By default, IPython will honor your
3248 By default, IPython will honor your
3253 \family typewriter
3249 \family typewriter
3254 EDITOR
3250 EDITOR
3255 \family default
3251 \family default
3256 environment variable (if not set, vi is the Unix default and notepad the
3252 environment variable (if not set, vi is the Unix default and notepad the
3257 Windows one).
3253 Windows one).
3258 Since this editor is invoked on the fly by IPython and is meant for editing
3254 Since this editor is invoked on the fly by IPython and is meant for editing
3259 small code snippets, you may want to use a small, lightweight editor here
3255 small code snippets, you may want to use a small, lightweight editor here
3260 (in case your default
3256 (in case your default
3261 \family typewriter
3257 \family typewriter
3262 EDITOR
3258 EDITOR
3263 \family default
3259 \family default
3264 is something like Emacs).
3260 is something like Emacs).
3265 \layout List
3261 \layout List
3266 \labelwidthstring 00.00.0000
3262 \labelwidthstring 00.00.0000
3267
3263
3268
3264
3269 \family typewriter
3265 \family typewriter
3270 \series bold
3266 \series bold
3271 -ipythondir\SpecialChar ~
3267 -ipythondir\SpecialChar ~
3272 <name>
3268 <name>
3273 \series default
3269 \series default
3274 :
3270 :
3275 \family default
3271 \family default
3276 name of your IPython configuration directory
3272 name of your IPython configuration directory
3277 \family typewriter
3273 \family typewriter
3278 IPYTHONDIR
3274 IPYTHONDIR
3279 \family default
3275 \family default
3280 .
3276 .
3281 This can also be specified through the environment variable
3277 This can also be specified through the environment variable
3282 \family typewriter
3278 \family typewriter
3283 IPYTHONDIR
3279 IPYTHONDIR
3284 \family default
3280 \family default
3285 .
3281 .
3286 \layout List
3282 \layout List
3287 \labelwidthstring 00.00.0000
3283 \labelwidthstring 00.00.0000
3288
3284
3289
3285
3290 \family typewriter
3286 \family typewriter
3291 \series bold
3287 \series bold
3292 -log|l
3288 -log|l
3293 \family default
3289 \family default
3294 \series default
3290 \series default
3295 : generate a log file of all input.
3291 : generate a log file of all input.
3296 The file is named
3292 The file is named
3297 \family typewriter
3293 \family typewriter
3298 ipython_log.py
3294 ipython_log.py
3299 \family default
3295 \family default
3300 in your current directory (which prevents logs from multiple IPython sessions
3296 in your current directory (which prevents logs from multiple IPython sessions
3301 from trampling each other).
3297 from trampling each other).
3302 You can use this to later restore a session by loading your logfile as
3298 You can use this to later restore a session by loading your logfile as
3303 a file to be executed with option
3299 a file to be executed with option
3304 \family typewriter
3300 \family typewriter
3305 -logplay
3301 -logplay
3306 \family default
3302 \family default
3307 (see below).
3303 (see below).
3308 \layout List
3304 \layout List
3309 \labelwidthstring 00.00.0000
3305 \labelwidthstring 00.00.0000
3310
3306
3311
3307
3312 \family typewriter
3308 \family typewriter
3313 \series bold
3309 \series bold
3314 -logfile|lf\SpecialChar ~
3310 -logfile|lf\SpecialChar ~
3315 <name>
3311 <name>
3316 \series default
3312 \series default
3317 :
3313 :
3318 \family default
3314 \family default
3319 specify the name of your logfile.
3315 specify the name of your logfile.
3320 \layout List
3316 \layout List
3321 \labelwidthstring 00.00.0000
3317 \labelwidthstring 00.00.0000
3322
3318
3323
3319
3324 \family typewriter
3320 \family typewriter
3325 \series bold
3321 \series bold
3326 -logplay|lp\SpecialChar ~
3322 -logplay|lp\SpecialChar ~
3327 <name>
3323 <name>
3328 \series default
3324 \series default
3329 :
3325 :
3330 \family default
3326 \family default
3331 you can replay a previous log.
3327 you can replay a previous log.
3332 For restoring a session as close as possible to the state you left it in,
3328 For restoring a session as close as possible to the state you left it in,
3333 use this option (don't just run the logfile).
3329 use this option (don't just run the logfile).
3334 With
3330 With
3335 \family typewriter
3331 \family typewriter
3336 -logplay
3332 -logplay
3337 \family default
3333 \family default
3338 , IPython will try to reconstruct the previous working environment in full,
3334 , IPython will try to reconstruct the previous working environment in full,
3339 not just execute the commands in the logfile.
3335 not just execute the commands in the logfile.
3340 \layout List
3336 \layout List
3341 \labelwidthstring 00.00.0000
3337 \labelwidthstring 00.00.0000
3342
3338
3343 \SpecialChar ~
3339 \SpecialChar ~
3344 When a session is restored, logging is automatically turned on again with
3340 When a session is restored, logging is automatically turned on again with
3345 the name of the logfile it was invoked with (it is read from the log header).
3341 the name of the logfile it was invoked with (it is read from the log header).
3346 So once you've turned logging on for a session, you can quit IPython and
3342 So once you've turned logging on for a session, you can quit IPython and
3347 reload it as many times as you want and it will continue to log its history
3343 reload it as many times as you want and it will continue to log its history
3348 and restore from the beginning every time.
3344 and restore from the beginning every time.
3349 \layout List
3345 \layout List
3350 \labelwidthstring 00.00.0000
3346 \labelwidthstring 00.00.0000
3351
3347
3352 \SpecialChar ~
3348 \SpecialChar ~
3353 Caveats: there are limitations in this option.
3349 Caveats: there are limitations in this option.
3354 The history variables
3350 The history variables
3355 \family typewriter
3351 \family typewriter
3356 _i*
3352 _i*
3357 \family default
3353 \family default
3358 ,
3354 ,
3359 \family typewriter
3355 \family typewriter
3360 _*
3356 _*
3361 \family default
3357 \family default
3362 and
3358 and
3363 \family typewriter
3359 \family typewriter
3364 _dh
3360 _dh
3365 \family default
3361 \family default
3366 don't get restored properly.
3362 don't get restored properly.
3367 In the future we will try to implement full session saving by writing and
3363 In the future we will try to implement full session saving by writing and
3368 retrieving a 'snapshot' of the memory state of IPython.
3364 retrieving a 'snapshot' of the memory state of IPython.
3369 But our first attempts failed because of inherent limitations of Python's
3365 But our first attempts failed because of inherent limitations of Python's
3370 Pickle module, so this may have to wait.
3366 Pickle module, so this may have to wait.
3371 \layout List
3367 \layout List
3372 \labelwidthstring 00.00.0000
3368 \labelwidthstring 00.00.0000
3373
3369
3374
3370
3375 \family typewriter
3371 \family typewriter
3376 \series bold
3372 \series bold
3377 -[no]messages
3373 -[no]messages
3378 \series default
3374 \series default
3379 :
3375 :
3380 \family default
3376 \family default
3381 Print messages which IPython collects about its startup process (default
3377 Print messages which IPython collects about its startup process (default
3382 on).
3378 on).
3383 \layout List
3379 \layout List
3384 \labelwidthstring 00.00.0000
3380 \labelwidthstring 00.00.0000
3385
3381
3386
3382
3387 \family typewriter
3383 \family typewriter
3388 \series bold
3384 \series bold
3389 -[no]pdb
3385 -[no]pdb
3390 \family default
3386 \family default
3391 \series default
3387 \series default
3392 : Automatically call the pdb debugger after every uncaught exception.
3388 : Automatically call the pdb debugger after every uncaught exception.
3393 If you are used to debugging using pdb, this puts you automatically inside
3389 If you are used to debugging using pdb, this puts you automatically inside
3394 of it after any call (either in IPython or in code called by it) which
3390 of it after any call (either in IPython or in code called by it) which
3395 triggers an exception which goes uncaught.
3391 triggers an exception which goes uncaught.
3396 \layout List
3392 \layout List
3397 \labelwidthstring 00.00.0000
3393 \labelwidthstring 00.00.0000
3398
3394
3399
3395
3400 \family typewriter
3396 \family typewriter
3401 \series bold
3397 \series bold
3402 -[no]pprint
3398 -[no]pprint
3403 \series default
3399 \series default
3404 :
3400 :
3405 \family default
3401 \family default
3406 ipython can optionally use the pprint (pretty printer) module for displaying
3402 ipython can optionally use the pprint (pretty printer) module for displaying
3407 results.
3403 results.
3408 pprint tends to give a nicer display of nested data structures.
3404 pprint tends to give a nicer display of nested data structures.
3409 If you like it, you can turn it on permanently in your config file (default
3405 If you like it, you can turn it on permanently in your config file (default
3410 off).
3406 off).
3411 \layout List
3407 \layout List
3412 \labelwidthstring 00.00.0000
3408 \labelwidthstring 00.00.0000
3413
3409
3414
3410
3415 \family typewriter
3411 \family typewriter
3416 \series bold
3412 \series bold
3417 -profile|p <name>
3413 -profile|p <name>
3418 \series default
3414 \series default
3419 :
3415 :
3420 \family default
3416 \family default
3421 assume that your config file is
3417 assume that your config file is
3422 \family typewriter
3418 \family typewriter
3423 ipythonrc-<name>
3419 ipythonrc-<name>
3424 \family default
3420 \family default
3425 (looks in current dir first, then in
3421 (looks in current dir first, then in
3426 \family typewriter
3422 \family typewriter
3427 IPYTHONDIR
3423 IPYTHONDIR
3428 \family default
3424 \family default
3429 ).
3425 ).
3430 This is a quick way to keep and load multiple config files for different
3426 This is a quick way to keep and load multiple config files for different
3431 tasks, especially if you use the include option of config files.
3427 tasks, especially if you use the include option of config files.
3432 You can keep a basic
3428 You can keep a basic
3433 \family typewriter
3429 \family typewriter
3434 IPYTHONDIR/ipythonrc
3430 IPYTHONDIR/ipythonrc
3435 \family default
3431 \family default
3436 file and then have other 'profiles' which include this one and load extra
3432 file and then have other 'profiles' which include this one and load extra
3437 things for particular tasks.
3433 things for particular tasks.
3438 For example:
3434 For example:
3439 \layout List
3435 \layout List
3440 \labelwidthstring 00.00.0000
3436 \labelwidthstring 00.00.0000
3441
3437
3442
3438
3443 \family typewriter
3439 \family typewriter
3444 \SpecialChar ~
3440 \SpecialChar ~
3445
3441
3446 \family default
3442 \family default
3447 1.
3443 1.
3448
3444
3449 \family typewriter
3445 \family typewriter
3450 $HOME/.ipython/ipythonrc
3446 $HOME/.ipython/ipythonrc
3451 \family default
3447 \family default
3452 : load basic things you always want.
3448 : load basic things you always want.
3453 \layout List
3449 \layout List
3454 \labelwidthstring 00.00.0000
3450 \labelwidthstring 00.00.0000
3455
3451
3456
3452
3457 \family typewriter
3453 \family typewriter
3458 \SpecialChar ~
3454 \SpecialChar ~
3459
3455
3460 \family default
3456 \family default
3461 2.
3457 2.
3462
3458
3463 \family typewriter
3459 \family typewriter
3464 $HOME/.ipython/ipythonrc-math
3460 $HOME/.ipython/ipythonrc-math
3465 \family default
3461 \family default
3466 : load (1) and basic math-related modules.
3462 : load (1) and basic math-related modules.
3467
3463
3468 \layout List
3464 \layout List
3469 \labelwidthstring 00.00.0000
3465 \labelwidthstring 00.00.0000
3470
3466
3471
3467
3472 \family typewriter
3468 \family typewriter
3473 \SpecialChar ~
3469 \SpecialChar ~
3474
3470
3475 \family default
3471 \family default
3476 3.
3472 3.
3477
3473
3478 \family typewriter
3474 \family typewriter
3479 $HOME/.ipython/ipythonrc-numeric
3475 $HOME/.ipython/ipythonrc-numeric
3480 \family default
3476 \family default
3481 : load (1) and Numeric and plotting modules.
3477 : load (1) and Numeric and plotting modules.
3482 \layout List
3478 \layout List
3483 \labelwidthstring 00.00.0000
3479 \labelwidthstring 00.00.0000
3484
3480
3485 \SpecialChar ~
3481 \SpecialChar ~
3486 Since it is possible to create an endless loop by having circular file
3482 Since it is possible to create an endless loop by having circular file
3487 inclusions, IPython will stop if it reaches 15 recursive inclusions.
3483 inclusions, IPython will stop if it reaches 15 recursive inclusions.
3488 \layout List
3484 \layout List
3489 \labelwidthstring 00.00.0000
3485 \labelwidthstring 00.00.0000
3490
3486
3491
3487
3492 \family typewriter
3488 \family typewriter
3493 \series bold
3489 \series bold
3494 -prompt_in1|pi1\SpecialChar ~
3490 -prompt_in1|pi1\SpecialChar ~
3495 <string>:
3491 <string>:
3496 \family default
3492 \family default
3497 \series default
3493 \series default
3498 Specify the string used for input prompts.
3494 Specify the string used for input prompts.
3499 Note that if you are using numbered prompts, the number is represented
3495 Note that if you are using numbered prompts, the number is represented
3500 with a '
3496 with a '
3501 \backslash
3497 \backslash
3502 #' in the string.
3498 #' in the string.
3503 Don't forget to quote strings with spaces embedded in them.
3499 Don't forget to quote strings with spaces embedded in them.
3504 Default: '
3500 Default: '
3505 \family typewriter
3501 \family typewriter
3506 In\SpecialChar ~
3502 In\SpecialChar ~
3507 [
3503 [
3508 \backslash
3504 \backslash
3509 #]:
3505 #]:
3510 \family default
3506 \family default
3511 '.
3507 '.
3512 Sec.\SpecialChar ~
3508 Sec.\SpecialChar ~
3513
3509
3514 \begin_inset LatexCommand \ref{sec:prompts}
3510 \begin_inset LatexCommand \ref{sec:prompts}
3515
3511
3516 \end_inset
3512 \end_inset
3517
3513
3518 discusses in detail all the available escapes to customize your prompts.
3514 discusses in detail all the available escapes to customize your prompts.
3519 \layout List
3515 \layout List
3520 \labelwidthstring 00.00.0000
3516 \labelwidthstring 00.00.0000
3521
3517
3522
3518
3523 \family typewriter
3519 \family typewriter
3524 \series bold
3520 \series bold
3525 -prompt_in2|pi2\SpecialChar ~
3521 -prompt_in2|pi2\SpecialChar ~
3526 <string>:
3522 <string>:
3527 \family default
3523 \family default
3528 \series default
3524 \series default
3529 Similar to the previous option, but used for the continuation prompts.
3525 Similar to the previous option, but used for the continuation prompts.
3530 The special sequence '
3526 The special sequence '
3531 \family typewriter
3527 \family typewriter
3532
3528
3533 \backslash
3529 \backslash
3534 D
3530 D
3535 \family default
3531 \family default
3536 ' is similar to '
3532 ' is similar to '
3537 \family typewriter
3533 \family typewriter
3538
3534
3539 \backslash
3535 \backslash
3540 #
3536 #
3541 \family default
3537 \family default
3542 ', but with all digits replaced dots (so you can have your continuation
3538 ', but with all digits replaced dots (so you can have your continuation
3543 prompt aligned with your input prompt).
3539 prompt aligned with your input prompt).
3544 Default: '
3540 Default: '
3545 \family typewriter
3541 \family typewriter
3546 \SpecialChar ~
3542 \SpecialChar ~
3547 \SpecialChar ~
3543 \SpecialChar ~
3548 \SpecialChar ~
3544 \SpecialChar ~
3549 .
3545 .
3550 \backslash
3546 \backslash
3551 D.:
3547 D.:
3552 \family default
3548 \family default
3553 ' (note three spaces at the start for alignment with '
3549 ' (note three spaces at the start for alignment with '
3554 \family typewriter
3550 \family typewriter
3555 In\SpecialChar ~
3551 In\SpecialChar ~
3556 [
3552 [
3557 \backslash
3553 \backslash
3558 #]
3554 #]
3559 \family default
3555 \family default
3560 ').
3556 ').
3561 \layout List
3557 \layout List
3562 \labelwidthstring 00.00.0000
3558 \labelwidthstring 00.00.0000
3563
3559
3564
3560
3565 \family typewriter
3561 \family typewriter
3566 \series bold
3562 \series bold
3567 -prompt_out|po\SpecialChar ~
3563 -prompt_out|po\SpecialChar ~
3568 <string>:
3564 <string>:
3569 \family default
3565 \family default
3570 \series default
3566 \series default
3571 String used for output prompts, also uses numbers like
3567 String used for output prompts, also uses numbers like
3572 \family typewriter
3568 \family typewriter
3573 prompt_in1
3569 prompt_in1
3574 \family default
3570 \family default
3575 .
3571 .
3576 Default: '
3572 Default: '
3577 \family typewriter
3573 \family typewriter
3578 Out[
3574 Out[
3579 \backslash
3575 \backslash
3580 #]:
3576 #]:
3581 \family default
3577 \family default
3582 '
3578 '
3583 \layout List
3579 \layout List
3584 \labelwidthstring 00.00.0000
3580 \labelwidthstring 00.00.0000
3585
3581
3586
3582
3587 \family typewriter
3583 \family typewriter
3588 \series bold
3584 \series bold
3589 -quick
3585 -quick
3590 \family default
3586 \family default
3591 \series default
3587 \series default
3592 : start in bare bones mode (no config file loaded).
3588 : start in bare bones mode (no config file loaded).
3593 \layout List
3589 \layout List
3594 \labelwidthstring 00.00.0000
3590 \labelwidthstring 00.00.0000
3595
3591
3596
3592
3597 \family typewriter
3593 \family typewriter
3598 \series bold
3594 \series bold
3599 -rcfile\SpecialChar ~
3595 -rcfile\SpecialChar ~
3600 <name>
3596 <name>
3601 \series default
3597 \series default
3602 :
3598 :
3603 \family default
3599 \family default
3604 name of your IPython resource configuration file.
3600 name of your IPython resource configuration file.
3605 Normally IPython loads ipythonrc (from current directory) or
3601 Normally IPython loads ipythonrc (from current directory) or
3606 \family typewriter
3602 \family typewriter
3607 IPYTHONDIR/ipythonrc
3603 IPYTHONDIR/ipythonrc
3608 \family default
3604 \family default
3609 .
3605 .
3610 \layout List
3606 \layout List
3611 \labelwidthstring 00.00.0000
3607 \labelwidthstring 00.00.0000
3612
3608
3613 \SpecialChar ~
3609 \SpecialChar ~
3614 If the loading of your config file fails, IPython starts with a bare bones
3610 If the loading of your config file fails, IPython starts with a bare bones
3615 configuration (no modules loaded at all).
3611 configuration (no modules loaded at all).
3616 \layout List
3612 \layout List
3617 \labelwidthstring 00.00.0000
3613 \labelwidthstring 00.00.0000
3618
3614
3619
3615
3620 \family typewriter
3616 \family typewriter
3621 \series bold
3617 \series bold
3622 -[no]readline
3618 -[no]readline
3623 \family default
3619 \family default
3624 \series default
3620 \series default
3625 : use the readline library, which is needed to support name completion and
3621 : use the readline library, which is needed to support name completion and
3626 command history, among other things.
3622 command history, among other things.
3627 It is enabled by default, but may cause problems for users of X/Emacs in
3623 It is enabled by default, but may cause problems for users of X/Emacs in
3628 Python comint or shell buffers.
3624 Python comint or shell buffers.
3629 \layout List
3625 \layout List
3630 \labelwidthstring 00.00.0000
3626 \labelwidthstring 00.00.0000
3631
3627
3632 \SpecialChar ~
3628 \SpecialChar ~
3633 Note that X/Emacs 'eterm' buffers (opened with
3629 Note that X/Emacs 'eterm' buffers (opened with
3634 \family typewriter
3630 \family typewriter
3635 M-x\SpecialChar ~
3631 M-x\SpecialChar ~
3636 term
3632 term
3637 \family default
3633 \family default
3638 ) support IPython's readline and syntax coloring fine, only 'emacs' (
3634 ) support IPython's readline and syntax coloring fine, only 'emacs' (
3639 \family typewriter
3635 \family typewriter
3640 M-x\SpecialChar ~
3636 M-x\SpecialChar ~
3641 shell
3637 shell
3642 \family default
3638 \family default
3643 and
3639 and
3644 \family typewriter
3640 \family typewriter
3645 C-c\SpecialChar ~
3641 C-c\SpecialChar ~
3646 !
3642 !
3647 \family default
3643 \family default
3648 ) buffers do not.
3644 ) buffers do not.
3649 \layout List
3645 \layout List
3650 \labelwidthstring 00.00.0000
3646 \labelwidthstring 00.00.0000
3651
3647
3652
3648
3653 \family typewriter
3649 \family typewriter
3654 \series bold
3650 \series bold
3655 -screen_length|sl\SpecialChar ~
3651 -screen_length|sl\SpecialChar ~
3656 <n>
3652 <n>
3657 \series default
3653 \series default
3658 :
3654 :
3659 \family default
3655 \family default
3660 number of lines of your screen.
3656 number of lines of your screen.
3661 This is used to control printing of very long strings.
3657 This is used to control printing of very long strings.
3662 Strings longer than this number of lines will be sent through a pager instead
3658 Strings longer than this number of lines will be sent through a pager instead
3663 of directly printed.
3659 of directly printed.
3664 \layout List
3660 \layout List
3665 \labelwidthstring 00.00.0000
3661 \labelwidthstring 00.00.0000
3666
3662
3667 \SpecialChar ~
3663 \SpecialChar ~
3668 The default value for this is 0, which means IPython will auto-detect your
3664 The default value for this is 0, which means IPython will auto-detect your
3669 screen size every time it needs to print certain potentially long strings
3665 screen size every time it needs to print certain potentially long strings
3670 (this doesn't change the behavior of the 'print' keyword, it's only triggered
3666 (this doesn't change the behavior of the 'print' keyword, it's only triggered
3671 internally).
3667 internally).
3672 If for some reason this isn't working well (it needs curses support), specify
3668 If for some reason this isn't working well (it needs curses support), specify
3673 it yourself.
3669 it yourself.
3674 Otherwise don't change the default.
3670 Otherwise don't change the default.
3675 \layout List
3671 \layout List
3676 \labelwidthstring 00.00.0000
3672 \labelwidthstring 00.00.0000
3677
3673
3678
3674
3679 \family typewriter
3675 \family typewriter
3680 \series bold
3676 \series bold
3681 -separate_in|si\SpecialChar ~
3677 -separate_in|si\SpecialChar ~
3682 <string>
3678 <string>
3683 \series default
3679 \series default
3684 :
3680 :
3685 \family default
3681 \family default
3686 separator before input prompts.
3682 separator before input prompts.
3687 Default: '
3683 Default: '
3688 \family typewriter
3684 \family typewriter
3689
3685
3690 \backslash
3686 \backslash
3691 n
3687 n
3692 \family default
3688 \family default
3693 '
3689 '
3694 \layout List
3690 \layout List
3695 \labelwidthstring 00.00.0000
3691 \labelwidthstring 00.00.0000
3696
3692
3697
3693
3698 \family typewriter
3694 \family typewriter
3699 \series bold
3695 \series bold
3700 -separate_out|so\SpecialChar ~
3696 -separate_out|so\SpecialChar ~
3701 <string>
3697 <string>
3702 \family default
3698 \family default
3703 \series default
3699 \series default
3704 : separator before output prompts.
3700 : separator before output prompts.
3705 Default: nothing.
3701 Default: nothing.
3706 \layout List
3702 \layout List
3707 \labelwidthstring 00.00.0000
3703 \labelwidthstring 00.00.0000
3708
3704
3709
3705
3710 \family typewriter
3706 \family typewriter
3711 \series bold
3707 \series bold
3712 -separate_out2|so2\SpecialChar ~
3708 -separate_out2|so2\SpecialChar ~
3713 <string>
3709 <string>
3714 \series default
3710 \series default
3715 :
3711 :
3716 \family default
3712 \family default
3717 separator after output prompts.
3713 separator after output prompts.
3718 Default: nothing.
3714 Default: nothing.
3719 \layout List
3715 \layout List
3720 \labelwidthstring 00.00.0000
3716 \labelwidthstring 00.00.0000
3721
3717
3722 \SpecialChar ~
3718 \SpecialChar ~
3723 For these three options, use the value 0 to specify no separator.
3719 For these three options, use the value 0 to specify no separator.
3724 \layout List
3720 \layout List
3725 \labelwidthstring 00.00.0000
3721 \labelwidthstring 00.00.0000
3726
3722
3727
3723
3728 \family typewriter
3724 \family typewriter
3729 \series bold
3725 \series bold
3730 -nosep
3726 -nosep
3731 \series default
3727 \series default
3732 :
3728 :
3733 \family default
3729 \family default
3734 shorthand for
3730 shorthand for
3735 \family typewriter
3731 \family typewriter
3736 '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'
3732 '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'
3737 \family default
3733 \family default
3738 .
3734 .
3739 Simply removes all input/output separators.
3735 Simply removes all input/output separators.
3740 \layout List
3736 \layout List
3741 \labelwidthstring 00.00.0000
3737 \labelwidthstring 00.00.0000
3742
3738
3743
3739
3744 \family typewriter
3740 \family typewriter
3745 \series bold
3741 \series bold
3746 -upgrade
3742 -upgrade
3747 \family default
3743 \family default
3748 \series default
3744 \series default
3749 : allows you to upgrade your
3745 : allows you to upgrade your
3750 \family typewriter
3746 \family typewriter
3751 IPYTHONDIR
3747 IPYTHONDIR
3752 \family default
3748 \family default
3753 configuration when you install a new version of IPython.
3749 configuration when you install a new version of IPython.
3754 Since new versions may include new command line options or example files,
3750 Since new versions may include new command line options or example files,
3755 this copies updated ipythonrc-type files.
3751 this copies updated ipythonrc-type files.
3756 However, it backs up (with a
3752 However, it backs up (with a
3757 \family typewriter
3753 \family typewriter
3758 .old
3754 .old
3759 \family default
3755 \family default
3760 extension) all files which it overwrites so that you can merge back any
3756 extension) all files which it overwrites so that you can merge back any
3761 customizations you might have in your personal files.
3757 customizations you might have in your personal files.
3762 \layout List
3758 \layout List
3763 \labelwidthstring 00.00.0000
3759 \labelwidthstring 00.00.0000
3764
3760
3765
3761
3766 \family typewriter
3762 \family typewriter
3767 \series bold
3763 \series bold
3768 -Version
3764 -Version
3769 \series default
3765 \series default
3770 :
3766 :
3771 \family default
3767 \family default
3772 print version information and exit.
3768 print version information and exit.
3773 \layout List
3769 \layout List
3774 \labelwidthstring 00.00.0000
3770 \labelwidthstring 00.00.0000
3775
3771
3776
3772
3777 \family typewriter
3773 \family typewriter
3778 \series bold
3774 \series bold
3779 -wxversion\SpecialChar ~
3775 -wxversion\SpecialChar ~
3780 <string>:
3776 <string>:
3781 \family default
3777 \family default
3782 \series default
3778 \series default
3783 Select a specific version of wxPython (used in conjunction with
3779 Select a specific version of wxPython (used in conjunction with
3784 \family typewriter
3780 \family typewriter
3785 -wthread
3781 -wthread
3786 \family default
3782 \family default
3787 ).
3783 ).
3788 Requires the wxversion module, part of recent wxPython distributions
3784 Requires the wxversion module, part of recent wxPython distributions
3789 \layout List
3785 \layout List
3790 \labelwidthstring 00.00.0000
3786 \labelwidthstring 00.00.0000
3791
3787
3792
3788
3793 \family typewriter
3789 \family typewriter
3794 \series bold
3790 \series bold
3795 -xmode\SpecialChar ~
3791 -xmode\SpecialChar ~
3796 <modename>
3792 <modename>
3797 \series default
3793 \series default
3798 :
3794 :
3799 \family default
3795 \family default
3800 Mode for exception reporting.
3796 Mode for exception reporting.
3801 \layout List
3797 \layout List
3802 \labelwidthstring 00.00.0000
3798 \labelwidthstring 00.00.0000
3803
3799
3804 \SpecialChar ~
3800 \SpecialChar ~
3805 Valid modes: Plain, Context and Verbose.
3801 Valid modes: Plain, Context and Verbose.
3806 \layout List
3802 \layout List
3807 \labelwidthstring 00.00.0000
3803 \labelwidthstring 00.00.0000
3808
3804
3809 \SpecialChar ~
3805 \SpecialChar ~
3810 Plain: similar to python's normal traceback printing.
3806 Plain: similar to python's normal traceback printing.
3811 \layout List
3807 \layout List
3812 \labelwidthstring 00.00.0000
3808 \labelwidthstring 00.00.0000
3813
3809
3814 \SpecialChar ~
3810 \SpecialChar ~
3815 Context: prints 5 lines of context source code around each line in the
3811 Context: prints 5 lines of context source code around each line in the
3816 traceback.
3812 traceback.
3817 \layout List
3813 \layout List
3818 \labelwidthstring 00.00.0000
3814 \labelwidthstring 00.00.0000
3819
3815
3820 \SpecialChar ~
3816 \SpecialChar ~
3821 Verbose: similar to Context, but additionally prints the variables currently
3817 Verbose: similar to Context, but additionally prints the variables currently
3822 visible where the exception happened (shortening their strings if too long).
3818 visible where the exception happened (shortening their strings if too long).
3823 This can potentially be very slow, if you happen to have a huge data structure
3819 This can potentially be very slow, if you happen to have a huge data structure
3824 whose string representation is complex to compute.
3820 whose string representation is complex to compute.
3825 Your computer may appear to freeze for a while with cpu usage at 100%.
3821 Your computer may appear to freeze for a while with cpu usage at 100%.
3826 If this occurs, you can cancel the traceback with Ctrl-C (maybe hitting
3822 If this occurs, you can cancel the traceback with Ctrl-C (maybe hitting
3827 it more than once).
3823 it more than once).
3828 \layout Section
3824 \layout Section
3829
3825
3830 Interactive use
3826 Interactive use
3831 \layout Standard
3827 \layout Standard
3832
3828
3833
3829
3834 \series bold
3830 \series bold
3835 Warning
3831 Warning
3836 \series default
3832 \series default
3837 : IPython relies on the existence of a global variable called
3833 : IPython relies on the existence of a global variable called
3838 \family typewriter
3834 \family typewriter
3839 __IP
3835 __IP
3840 \family default
3836 \family default
3841 which controls the shell itself.
3837 which controls the shell itself.
3842 If you redefine
3838 If you redefine
3843 \family typewriter
3839 \family typewriter
3844 __IP
3840 __IP
3845 \family default
3841 \family default
3846 to anything, bizarre behavior will quickly occur.
3842 to anything, bizarre behavior will quickly occur.
3847 \layout Standard
3843 \layout Standard
3848
3844
3849 Other than the above warning, IPython is meant to work as a drop-in replacement
3845 Other than the above warning, IPython is meant to work as a drop-in replacement
3850 for the standard interactive interpreter.
3846 for the standard interactive interpreter.
3851 As such, any code which is valid python should execute normally under IPython
3847 As such, any code which is valid python should execute normally under IPython
3852 (cases where this is not true should be reported as bugs).
3848 (cases where this is not true should be reported as bugs).
3853 It does, however, offer many features which are not available at a standard
3849 It does, however, offer many features which are not available at a standard
3854 python prompt.
3850 python prompt.
3855 What follows is a list of these.
3851 What follows is a list of these.
3856 \layout Subsection
3852 \layout Subsection
3857
3853
3858 Caution for Windows users
3854 Caution for Windows users
3859 \layout Standard
3855 \layout Standard
3860
3856
3861 Windows, unfortunately, uses the `
3857 Windows, unfortunately, uses the `
3862 \family typewriter
3858 \family typewriter
3863
3859
3864 \backslash
3860 \backslash
3865
3861
3866 \family default
3862 \family default
3867 ' character as a path separator.
3863 ' character as a path separator.
3868 This is a terrible choice, because `
3864 This is a terrible choice, because `
3869 \family typewriter
3865 \family typewriter
3870
3866
3871 \backslash
3867 \backslash
3872
3868
3873 \family default
3869 \family default
3874 ' also represents the escape character in most modern programming languages,
3870 ' also represents the escape character in most modern programming languages,
3875 including Python.
3871 including Python.
3876 For this reason, issuing many of the commands discussed below (especially
3872 For this reason, issuing many of the commands discussed below (especially
3877 magics which affect the filesystem) with `
3873 magics which affect the filesystem) with `
3878 \family typewriter
3874 \family typewriter
3879
3875
3880 \backslash
3876 \backslash
3881
3877
3882 \family default
3878 \family default
3883 ' in them will cause strange errors.
3879 ' in them will cause strange errors.
3884 \layout Standard
3880 \layout Standard
3885
3881
3886 A partial solution is to use instead the `
3882 A partial solution is to use instead the `
3887 \family typewriter
3883 \family typewriter
3888 /
3884 /
3889 \family default
3885 \family default
3890 ' character as a path separator, which Windows recognizes in
3886 ' character as a path separator, which Windows recognizes in
3891 \emph on
3887 \emph on
3892 most
3888 most
3893 \emph default
3889 \emph default
3894 situations.
3890 situations.
3895 However, in Windows commands `
3891 However, in Windows commands `
3896 \family typewriter
3892 \family typewriter
3897 /
3893 /
3898 \family default
3894 \family default
3899 ' flags options, so you can not use it for the root directory.
3895 ' flags options, so you can not use it for the root directory.
3900 This means that paths beginning at the root must be typed in a contrived
3896 This means that paths beginning at the root must be typed in a contrived
3901 manner like:
3897 manner like:
3902 \newline
3898 \newline
3903
3899
3904 \family typewriter
3900 \family typewriter
3905 %copy
3901 %copy
3906 \backslash
3902 \backslash
3907 opt/foo/bar.txt
3903 opt/foo/bar.txt
3908 \backslash
3904 \backslash
3909 tmp
3905 tmp
3910 \layout Standard
3906 \layout Standard
3911
3907
3912 There is no sensible thing IPython can do to truly work around this flaw
3908 There is no sensible thing IPython can do to truly work around this flaw
3913 in Windows
3909 in Windows
3914 \begin_inset Foot
3910 \begin_inset Foot
3915 collapsed true
3911 collapsed true
3916
3912
3917 \layout Standard
3913 \layout Standard
3918
3914
3919 If anyone comes up with a
3915 If anyone comes up with a
3920 \emph on
3916 \emph on
3921 clean
3917 clean
3922 \emph default
3918 \emph default
3923 solution which works consistently and does not negatively impact other
3919 solution which works consistently and does not negatively impact other
3924 platforms at all, I'll gladly accept a patch.
3920 platforms at all, I'll gladly accept a patch.
3925 \end_inset
3921 \end_inset
3926
3922
3927 .
3923 .
3928 \layout Subsection
3924 \layout Subsection
3929
3925
3930
3926
3931 \begin_inset LatexCommand \label{sec:magic}
3927 \begin_inset LatexCommand \label{sec:magic}
3932
3928
3933 \end_inset
3929 \end_inset
3934
3930
3935 Magic command system
3931 Magic command system
3936 \layout Standard
3932 \layout Standard
3937
3933
3938 IPython will treat any line whose first character is a
3934 IPython will treat any line whose first character is a
3939 \family typewriter
3935 \family typewriter
3940 %
3936 %
3941 \family default
3937 \family default
3942 as a special call to a 'magic' function.
3938 as a special call to a 'magic' function.
3943 These allow you to control the behavior of IPython itself, plus a lot of
3939 These allow you to control the behavior of IPython itself, plus a lot of
3944 system-type features.
3940 system-type features.
3945 They are all prefixed with a
3941 They are all prefixed with a
3946 \family typewriter
3942 \family typewriter
3947 %
3943 %
3948 \family default
3944 \family default
3949 character, but parameters are given without parentheses or quotes.
3945 character, but parameters are given without parentheses or quotes.
3950 \layout Standard
3946 \layout Standard
3951
3947
3952 Example: typing
3948 Example: typing
3953 \family typewriter
3949 \family typewriter
3954 '%cd mydir'
3950 '%cd mydir'
3955 \family default
3951 \family default
3956 (without the quotes) changes you working directory to
3952 (without the quotes) changes you working directory to
3957 \family typewriter
3953 \family typewriter
3958 'mydir'
3954 'mydir'
3959 \family default
3955 \family default
3960 , if it exists.
3956 , if it exists.
3961 \layout Standard
3957 \layout Standard
3962
3958
3963 If you have 'automagic' enabled (in your
3959 If you have 'automagic' enabled (in your
3964 \family typewriter
3960 \family typewriter
3965 ipythonrc
3961 ipythonrc
3966 \family default
3962 \family default
3967 file, via the command line option
3963 file, via the command line option
3968 \family typewriter
3964 \family typewriter
3969 -automagic
3965 -automagic
3970 \family default
3966 \family default
3971 or with the
3967 or with the
3972 \family typewriter
3968 \family typewriter
3973 %automagic
3969 %automagic
3974 \family default
3970 \family default
3975 function), you don't need to type in the
3971 function), you don't need to type in the
3976 \family typewriter
3972 \family typewriter
3977 %
3973 %
3978 \family default
3974 \family default
3979 explicitly.
3975 explicitly.
3980 IPython will scan its internal list of magic functions and call one if
3976 IPython will scan its internal list of magic functions and call one if
3981 it exists.
3977 it exists.
3982 With automagic on you can then just type '
3978 With automagic on you can then just type '
3983 \family typewriter
3979 \family typewriter
3984 cd mydir
3980 cd mydir
3985 \family default
3981 \family default
3986 ' to go to directory '
3982 ' to go to directory '
3987 \family typewriter
3983 \family typewriter
3988 mydir
3984 mydir
3989 \family default
3985 \family default
3990 '.
3986 '.
3991 The automagic system has the lowest possible precedence in name searches,
3987 The automagic system has the lowest possible precedence in name searches,
3992 so defining an identifier with the same name as an existing magic function
3988 so defining an identifier with the same name as an existing magic function
3993 will shadow it for automagic use.
3989 will shadow it for automagic use.
3994 You can still access the shadowed magic function by explicitly using the
3990 You can still access the shadowed magic function by explicitly using the
3995
3991
3996 \family typewriter
3992 \family typewriter
3997 %
3993 %
3998 \family default
3994 \family default
3999 character at the beginning of the line.
3995 character at the beginning of the line.
4000 \layout Standard
3996 \layout Standard
4001
3997
4002 An example (with automagic on) should clarify all this:
3998 An example (with automagic on) should clarify all this:
4003 \layout LyX-Code
3999 \layout LyX-Code
4004
4000
4005 In [1]: cd ipython # %cd is called by automagic
4001 In [1]: cd ipython # %cd is called by automagic
4006 \layout LyX-Code
4002 \layout LyX-Code
4007
4003
4008 /home/fperez/ipython
4004 /home/fperez/ipython
4009 \layout LyX-Code
4005 \layout LyX-Code
4010
4006
4011 In [2]: cd=1 # now cd is just a variable
4007 In [2]: cd=1 # now cd is just a variable
4012 \layout LyX-Code
4008 \layout LyX-Code
4013
4009
4014 In [3]: cd ..
4010 In [3]: cd ..
4015 # and doesn't work as a function anymore
4011 # and doesn't work as a function anymore
4016 \layout LyX-Code
4012 \layout LyX-Code
4017
4013
4018 ------------------------------------------------------------
4014 ------------------------------------------------------------
4019 \layout LyX-Code
4015 \layout LyX-Code
4020
4016
4021 File "<console>", line 1
4017 File "<console>", line 1
4022 \layout LyX-Code
4018 \layout LyX-Code
4023
4019
4024 cd ..
4020 cd ..
4025 \layout LyX-Code
4021 \layout LyX-Code
4026
4022
4027 ^
4023 ^
4028 \layout LyX-Code
4024 \layout LyX-Code
4029
4025
4030 SyntaxError: invalid syntax
4026 SyntaxError: invalid syntax
4031 \layout LyX-Code
4027 \layout LyX-Code
4032
4028
4033 \layout LyX-Code
4029 \layout LyX-Code
4034
4030
4035 In [4]: %cd ..
4031 In [4]: %cd ..
4036 # but %cd always works
4032 # but %cd always works
4037 \layout LyX-Code
4033 \layout LyX-Code
4038
4034
4039 /home/fperez
4035 /home/fperez
4040 \layout LyX-Code
4036 \layout LyX-Code
4041
4037
4042 In [5]: del cd # if you remove the cd variable
4038 In [5]: del cd # if you remove the cd variable
4043 \layout LyX-Code
4039 \layout LyX-Code
4044
4040
4045 In [6]: cd ipython # automagic can work again
4041 In [6]: cd ipython # automagic can work again
4046 \layout LyX-Code
4042 \layout LyX-Code
4047
4043
4048 /home/fperez/ipython
4044 /home/fperez/ipython
4049 \layout Standard
4045 \layout Standard
4050
4046
4051 You can define your own magic functions to extend the system.
4047 You can define your own magic functions to extend the system.
4052 The following is a snippet of code which shows how to do it.
4048 The following is a snippet of code which shows how to do it.
4053 It is provided as file
4049 It is provided as file
4054 \family typewriter
4050 \family typewriter
4055 example-magic.py
4051 example-magic.py
4056 \family default
4052 \family default
4057 in the examples directory:
4053 in the examples directory:
4058 \layout Standard
4054 \layout Standard
4059
4055
4060
4056
4061 \begin_inset ERT
4057 \begin_inset ERT
4062 status Open
4058 status Open
4063
4059
4064 \layout Standard
4060 \layout Standard
4065
4061
4066 \backslash
4062 \backslash
4067 codelist{examples/example-magic.py}
4063 codelist{examples/example-magic.py}
4068 \end_inset
4064 \end_inset
4069
4065
4070
4066
4071 \layout Standard
4067 \layout Standard
4072
4068
4073 You can also define your own aliased names for magic functions.
4069 You can also define your own aliased names for magic functions.
4074 In your
4070 In your
4075 \family typewriter
4071 \family typewriter
4076 ipythonrc
4072 ipythonrc
4077 \family default
4073 \family default
4078 file, placing a line like:
4074 file, placing a line like:
4079 \layout Standard
4075 \layout Standard
4080
4076
4081
4077
4082 \family typewriter
4078 \family typewriter
4083 execute __IP.magic_cl = __IP.magic_clear
4079 execute __IP.magic_cl = __IP.magic_clear
4084 \layout Standard
4080 \layout Standard
4085
4081
4086 will define
4082 will define
4087 \family typewriter
4083 \family typewriter
4088 %cl
4084 %cl
4089 \family default
4085 \family default
4090 as a new name for
4086 as a new name for
4091 \family typewriter
4087 \family typewriter
4092 %clear
4088 %clear
4093 \family default
4089 \family default
4094 .
4090 .
4095 \layout Standard
4091 \layout Standard
4096
4092
4097 Type
4093 Type
4098 \family typewriter
4094 \family typewriter
4099 %magic
4095 %magic
4100 \family default
4096 \family default
4101 for more information, including a list of all available magic functions
4097 for more information, including a list of all available magic functions
4102 at any time and their docstrings.
4098 at any time and their docstrings.
4103 You can also type
4099 You can also type
4104 \family typewriter
4100 \family typewriter
4105 %magic_function_name?
4101 %magic_function_name?
4106 \family default
4102 \family default
4107 (see sec.
4103 (see sec.
4108
4104
4109 \begin_inset LatexCommand \ref{sec:dyn-object-info}
4105 \begin_inset LatexCommand \ref{sec:dyn-object-info}
4110
4106
4111 \end_inset
4107 \end_inset
4112
4108
4113 for information on the
4109 for information on the
4114 \family typewriter
4110 \family typewriter
4115 '?'
4111 '?'
4116 \family default
4112 \family default
4117 system) to get information about any particular magic function you are
4113 system) to get information about any particular magic function you are
4118 interested in.
4114 interested in.
4119 \layout Subsubsection
4115 \layout Subsubsection
4120
4116
4121 Magic commands
4117 Magic commands
4122 \layout Standard
4118 \layout Standard
4123
4119
4124 The rest of this section is automatically generated for each release from
4120 The rest of this section is automatically generated for each release from
4125 the docstrings in the IPython code.
4121 the docstrings in the IPython code.
4126 Therefore the formatting is somewhat minimal, but this method has the advantage
4122 Therefore the formatting is somewhat minimal, but this method has the advantage
4127 of having information always in sync with the code.
4123 of having information always in sync with the code.
4128 \layout Standard
4124 \layout Standard
4129
4125
4130 A list of all the magic commands available in IPython's
4126 A list of all the magic commands available in IPython's
4131 \emph on
4127 \emph on
4132 default
4128 default
4133 \emph default
4129 \emph default
4134 installation follows.
4130 installation follows.
4135 This is similar to what you'll see by simply typing
4131 This is similar to what you'll see by simply typing
4136 \family typewriter
4132 \family typewriter
4137 %magic
4133 %magic
4138 \family default
4134 \family default
4139 at the prompt, but that will also give you information about magic commands
4135 at the prompt, but that will also give you information about magic commands
4140 you may have added as part of your personal customizations.
4136 you may have added as part of your personal customizations.
4141 \layout Standard
4137 \layout Standard
4142
4138
4143
4139
4144 \begin_inset Include \input{magic.tex}
4140 \begin_inset Include \input{magic.tex}
4145 preview false
4141 preview false
4146
4142
4147 \end_inset
4143 \end_inset
4148
4144
4149
4145
4150 \layout Subsection
4146 \layout Subsection
4151
4147
4152 Access to the standard Python help
4148 Access to the standard Python help
4153 \layout Standard
4149 \layout Standard
4154
4150
4155 As of Python 2.1, a help system is available with access to object docstrings
4151 As of Python 2.1, a help system is available with access to object docstrings
4156 and the Python manuals.
4152 and the Python manuals.
4157 Simply type
4153 Simply type
4158 \family typewriter
4154 \family typewriter
4159 'help'
4155 'help'
4160 \family default
4156 \family default
4161 (no quotes) to access it.
4157 (no quotes) to access it.
4162 You can also type
4158 You can also type
4163 \family typewriter
4159 \family typewriter
4164 help(object)
4160 help(object)
4165 \family default
4161 \family default
4166 to obtain information about a given object, and
4162 to obtain information about a given object, and
4167 \family typewriter
4163 \family typewriter
4168 help('keyword')
4164 help('keyword')
4169 \family default
4165 \family default
4170 for information on a keyword.
4166 for information on a keyword.
4171 As noted in sec.
4167 As noted in sec.
4172
4168
4173 \begin_inset LatexCommand \ref{sec:help-access}
4169 \begin_inset LatexCommand \ref{sec:help-access}
4174
4170
4175 \end_inset
4171 \end_inset
4176
4172
4177 , you need to properly configure your environment variable
4173 , you need to properly configure your environment variable
4178 \family typewriter
4174 \family typewriter
4179 PYTHONDOCS
4175 PYTHONDOCS
4180 \family default
4176 \family default
4181 for this feature to work correctly.
4177 for this feature to work correctly.
4182 \layout Subsection
4178 \layout Subsection
4183
4179
4184
4180
4185 \begin_inset LatexCommand \label{sec:dyn-object-info}
4181 \begin_inset LatexCommand \label{sec:dyn-object-info}
4186
4182
4187 \end_inset
4183 \end_inset
4188
4184
4189 Dynamic object information
4185 Dynamic object information
4190 \layout Standard
4186 \layout Standard
4191
4187
4192 Typing
4188 Typing
4193 \family typewriter
4189 \family typewriter
4194 ?word
4190 ?word
4195 \family default
4191 \family default
4196 or
4192 or
4197 \family typewriter
4193 \family typewriter
4198 word?
4194 word?
4199 \family default
4195 \family default
4200 prints detailed information about an object.
4196 prints detailed information about an object.
4201 If certain strings in the object are too long (docstrings, code, etc.) they
4197 If certain strings in the object are too long (docstrings, code, etc.) they
4202 get snipped in the center for brevity.
4198 get snipped in the center for brevity.
4203 This system gives access variable types and values, full source code for
4199 This system gives access variable types and values, full source code for
4204 any object (if available), function prototypes and other useful information.
4200 any object (if available), function prototypes and other useful information.
4205 \layout Standard
4201 \layout Standard
4206
4202
4207 Typing
4203 Typing
4208 \family typewriter
4204 \family typewriter
4209 ??word
4205 ??word
4210 \family default
4206 \family default
4211 or
4207 or
4212 \family typewriter
4208 \family typewriter
4213 word??
4209 word??
4214 \family default
4210 \family default
4215 gives access to the full information without snipping long strings.
4211 gives access to the full information without snipping long strings.
4216 Long strings are sent to the screen through the
4212 Long strings are sent to the screen through the
4217 \family typewriter
4213 \family typewriter
4218 less
4214 less
4219 \family default
4215 \family default
4220 pager if longer than the screen and printed otherwise.
4216 pager if longer than the screen and printed otherwise.
4221 On systems lacking the
4217 On systems lacking the
4222 \family typewriter
4218 \family typewriter
4223 less
4219 less
4224 \family default
4220 \family default
4225 command, IPython uses a very basic internal pager.
4221 command, IPython uses a very basic internal pager.
4226 \layout Standard
4222 \layout Standard
4227
4223
4228 The following magic functions are particularly useful for gathering information
4224 The following magic functions are particularly useful for gathering information
4229 about your working environment.
4225 about your working environment.
4230 You can get more details by typing
4226 You can get more details by typing
4231 \family typewriter
4227 \family typewriter
4232 %magic
4228 %magic
4233 \family default
4229 \family default
4234 or querying them individually (use
4230 or querying them individually (use
4235 \family typewriter
4231 \family typewriter
4236 %function_name?
4232 %function_name?
4237 \family default
4233 \family default
4238 with or without the
4234 with or without the
4239 \family typewriter
4235 \family typewriter
4240 %
4236 %
4241 \family default
4237 \family default
4242 ), this is just a summary:
4238 ), this is just a summary:
4243 \layout List
4239 \layout List
4244 \labelwidthstring 00.00.0000
4240 \labelwidthstring 00.00.0000
4245
4241
4246
4242
4247 \family typewriter
4243 \family typewriter
4248 \series bold
4244 \series bold
4249 %pdoc\SpecialChar ~
4245 %pdoc\SpecialChar ~
4250 <object>
4246 <object>
4251 \family default
4247 \family default
4252 \series default
4248 \series default
4253 : Print (or run through a pager if too long) the docstring for an object.
4249 : Print (or run through a pager if too long) the docstring for an object.
4254 If the given object is a class, it will print both the class and the constructo
4250 If the given object is a class, it will print both the class and the constructo
4255 r docstrings.
4251 r docstrings.
4256 \layout List
4252 \layout List
4257 \labelwidthstring 00.00.0000
4253 \labelwidthstring 00.00.0000
4258
4254
4259
4255
4260 \family typewriter
4256 \family typewriter
4261 \series bold
4257 \series bold
4262 %pdef\SpecialChar ~
4258 %pdef\SpecialChar ~
4263 <object>
4259 <object>
4264 \family default
4260 \family default
4265 \series default
4261 \series default
4266 : Print the definition header for any callable object.
4262 : Print the definition header for any callable object.
4267 If the object is a class, print the constructor information.
4263 If the object is a class, print the constructor information.
4268 \layout List
4264 \layout List
4269 \labelwidthstring 00.00.0000
4265 \labelwidthstring 00.00.0000
4270
4266
4271
4267
4272 \family typewriter
4268 \family typewriter
4273 \series bold
4269 \series bold
4274 %psource\SpecialChar ~
4270 %psource\SpecialChar ~
4275 <object>
4271 <object>
4276 \family default
4272 \family default
4277 \series default
4273 \series default
4278 : Print (or run through a pager if too long) the source code for an object.
4274 : Print (or run through a pager if too long) the source code for an object.
4279 \layout List
4275 \layout List
4280 \labelwidthstring 00.00.0000
4276 \labelwidthstring 00.00.0000
4281
4277
4282
4278
4283 \family typewriter
4279 \family typewriter
4284 \series bold
4280 \series bold
4285 %pfile\SpecialChar ~
4281 %pfile\SpecialChar ~
4286 <object>
4282 <object>
4287 \family default
4283 \family default
4288 \series default
4284 \series default
4289 : Show the entire source file where an object was defined via a pager, opening
4285 : Show the entire source file where an object was defined via a pager, opening
4290 it at the line where the object definition begins.
4286 it at the line where the object definition begins.
4291 \layout List
4287 \layout List
4292 \labelwidthstring 00.00.0000
4288 \labelwidthstring 00.00.0000
4293
4289
4294
4290
4295 \family typewriter
4291 \family typewriter
4296 \series bold
4292 \series bold
4297 %who/%whos
4293 %who/%whos
4298 \family default
4294 \family default
4299 \series default
4295 \series default
4300 : These functions give information about identifiers you have defined interactiv
4296 : These functions give information about identifiers you have defined interactiv
4301 ely (not things you loaded or defined in your configuration files).
4297 ely (not things you loaded or defined in your configuration files).
4302
4298
4303 \family typewriter
4299 \family typewriter
4304 %who
4300 %who
4305 \family default
4301 \family default
4306 just prints a list of identifiers and
4302 just prints a list of identifiers and
4307 \family typewriter
4303 \family typewriter
4308 %whos
4304 %whos
4309 \family default
4305 \family default
4310 prints a table with some basic details about each identifier.
4306 prints a table with some basic details about each identifier.
4311 \layout Standard
4307 \layout Standard
4312
4308
4313 Note that the dynamic object information functions (
4309 Note that the dynamic object information functions (
4314 \family typewriter
4310 \family typewriter
4315 ?/??, %pdoc, %pfile, %pdef, %psource
4311 ?/??, %pdoc, %pfile, %pdef, %psource
4316 \family default
4312 \family default
4317 ) give you access to documentation even on things which are not really defined
4313 ) give you access to documentation even on things which are not really defined
4318 as separate identifiers.
4314 as separate identifiers.
4319 Try for example typing
4315 Try for example typing
4320 \family typewriter
4316 \family typewriter
4321 {}.get?
4317 {}.get?
4322 \family default
4318 \family default
4323 or after doing
4319 or after doing
4324 \family typewriter
4320 \family typewriter
4325 import os
4321 import os
4326 \family default
4322 \family default
4327 , type
4323 , type
4328 \family typewriter
4324 \family typewriter
4329 os.path.abspath??
4325 os.path.abspath??
4330 \family default
4326 \family default
4331 .
4327 .
4332 \layout Subsection
4328 \layout Subsection
4333
4329
4334
4330
4335 \begin_inset LatexCommand \label{sec:readline}
4331 \begin_inset LatexCommand \label{sec:readline}
4336
4332
4337 \end_inset
4333 \end_inset
4338
4334
4339 Readline-based features
4335 Readline-based features
4340 \layout Standard
4336 \layout Standard
4341
4337
4342 These features require the GNU readline library, so they won't work if your
4338 These features require the GNU readline library, so they won't work if your
4343 Python installation lacks readline support.
4339 Python installation lacks readline support.
4344 We will first describe the default behavior IPython uses, and then how
4340 We will first describe the default behavior IPython uses, and then how
4345 to change it to suit your preferences.
4341 to change it to suit your preferences.
4346 \layout Subsubsection
4342 \layout Subsubsection
4347
4343
4348 Command line completion
4344 Command line completion
4349 \layout Standard
4345 \layout Standard
4350
4346
4351 At any time, hitting TAB will complete any available python commands or
4347 At any time, hitting TAB will complete any available python commands or
4352 variable names, and show you a list of the possible completions if there's
4348 variable names, and show you a list of the possible completions if there's
4353 no unambiguous one.
4349 no unambiguous one.
4354 It will also complete filenames in the current directory if no python names
4350 It will also complete filenames in the current directory if no python names
4355 match what you've typed so far.
4351 match what you've typed so far.
4356 \layout Subsubsection
4352 \layout Subsubsection
4357
4353
4358 Search command history
4354 Search command history
4359 \layout Standard
4355 \layout Standard
4360
4356
4361 IPython provides two ways for searching through previous input and thus
4357 IPython provides two ways for searching through previous input and thus
4362 reduce the need for repetitive typing:
4358 reduce the need for repetitive typing:
4363 \layout Enumerate
4359 \layout Enumerate
4364
4360
4365 Start typing, and then use
4361 Start typing, and then use
4366 \family typewriter
4362 \family typewriter
4367 Ctrl-p
4363 Ctrl-p
4368 \family default
4364 \family default
4369 (previous,up) and
4365 (previous,up) and
4370 \family typewriter
4366 \family typewriter
4371 Ctrl-n
4367 Ctrl-n
4372 \family default
4368 \family default
4373 (next,down) to search through only the history items that match what you've
4369 (next,down) to search through only the history items that match what you've
4374 typed so far.
4370 typed so far.
4375 If you use
4371 If you use
4376 \family typewriter
4372 \family typewriter
4377 Ctrl-p/Ctrl-n
4373 Ctrl-p/Ctrl-n
4378 \family default
4374 \family default
4379 at a blank prompt, they just behave like normal arrow keys.
4375 at a blank prompt, they just behave like normal arrow keys.
4380 \layout Enumerate
4376 \layout Enumerate
4381
4377
4382 Hit
4378 Hit
4383 \family typewriter
4379 \family typewriter
4384 Ctrl-r
4380 Ctrl-r
4385 \family default
4381 \family default
4386 : opens a search prompt.
4382 : opens a search prompt.
4387 Begin typing and the system searches your history for lines that contain
4383 Begin typing and the system searches your history for lines that contain
4388 what you've typed so far, completing as much as it can.
4384 what you've typed so far, completing as much as it can.
4389 \layout Subsubsection
4385 \layout Subsubsection
4390
4386
4391 Persistent command history across sessions
4387 Persistent command history across sessions
4392 \layout Standard
4388 \layout Standard
4393
4389
4394 IPython will save your input history when it leaves and reload it next time
4390 IPython will save your input history when it leaves and reload it next time
4395 you restart it.
4391 you restart it.
4396 By default, the history file is named
4392 By default, the history file is named
4397 \family typewriter
4393 \family typewriter
4398 $IPYTHONDIR/history
4394 $IPYTHONDIR/history
4399 \family default
4395 \family default
4400 , but if you've loaded a named profile, '
4396 , but if you've loaded a named profile, '
4401 \family typewriter
4397 \family typewriter
4402 -PROFILE_NAME
4398 -PROFILE_NAME
4403 \family default
4399 \family default
4404 ' is appended to the name.
4400 ' is appended to the name.
4405 This allows you to keep separate histories related to various tasks: commands
4401 This allows you to keep separate histories related to various tasks: commands
4406 related to numerical work will not be clobbered by a system shell history,
4402 related to numerical work will not be clobbered by a system shell history,
4407 for example.
4403 for example.
4408 \layout Subsubsection
4404 \layout Subsubsection
4409
4405
4410 Autoindent
4406 Autoindent
4411 \layout Standard
4407 \layout Standard
4412
4408
4413 IPython can recognize lines ending in ':' and indent the next line, while
4409 IPython can recognize lines ending in ':' and indent the next line, while
4414 also un-indenting automatically after 'raise' or 'return'.
4410 also un-indenting automatically after 'raise' or 'return'.
4415
4411
4416 \layout Standard
4412 \layout Standard
4417
4413
4418 This feature uses the readline library, so it will honor your
4414 This feature uses the readline library, so it will honor your
4419 \family typewriter
4415 \family typewriter
4420 ~/.inputrc
4416 ~/.inputrc
4421 \family default
4417 \family default
4422 configuration (or whatever file your
4418 configuration (or whatever file your
4423 \family typewriter
4419 \family typewriter
4424 INPUTRC
4420 INPUTRC
4425 \family default
4421 \family default
4426 variable points to).
4422 variable points to).
4427 Adding the following lines to your
4423 Adding the following lines to your
4428 \family typewriter
4424 \family typewriter
4429 .inputrc
4425 .inputrc
4430 \family default
4426 \family default
4431 file can make indenting/unindenting more convenient (
4427 file can make indenting/unindenting more convenient (
4432 \family typewriter
4428 \family typewriter
4433 M-i
4429 M-i
4434 \family default
4430 \family default
4435 indents,
4431 indents,
4436 \family typewriter
4432 \family typewriter
4437 M-u
4433 M-u
4438 \family default
4434 \family default
4439 unindents):
4435 unindents):
4440 \layout Standard
4436 \layout Standard
4441
4437
4442
4438
4443 \family typewriter
4439 \family typewriter
4444 $if Python
4440 $if Python
4445 \newline
4441 \newline
4446 "
4442 "
4447 \backslash
4443 \backslash
4448 M-i": "\SpecialChar ~
4444 M-i": "\SpecialChar ~
4449 \SpecialChar ~
4445 \SpecialChar ~
4450 \SpecialChar ~
4446 \SpecialChar ~
4451 \SpecialChar ~
4447 \SpecialChar ~
4452 "
4448 "
4453 \newline
4449 \newline
4454 "
4450 "
4455 \backslash
4451 \backslash
4456 M-u": "
4452 M-u": "
4457 \backslash
4453 \backslash
4458 d
4454 d
4459 \backslash
4455 \backslash
4460 d
4456 d
4461 \backslash
4457 \backslash
4462 d
4458 d
4463 \backslash
4459 \backslash
4464 d"
4460 d"
4465 \newline
4461 \newline
4466 $endif
4462 $endif
4467 \layout Standard
4463 \layout Standard
4468
4464
4469 Note that there are 4 spaces between the quote marks after
4465 Note that there are 4 spaces between the quote marks after
4470 \family typewriter
4466 \family typewriter
4471 "M-i"
4467 "M-i"
4472 \family default
4468 \family default
4473 above.
4469 above.
4474 \layout Standard
4470 \layout Standard
4475
4471
4476
4472
4477 \series bold
4473 \series bold
4478 Warning:
4474 Warning:
4479 \series default
4475 \series default
4480 this feature is ON by default, but it can cause problems with the pasting
4476 this feature is ON by default, but it can cause problems with the pasting
4481 of multi-line indented code (the pasted code gets re-indented on each line).
4477 of multi-line indented code (the pasted code gets re-indented on each line).
4482 A magic function
4478 A magic function
4483 \family typewriter
4479 \family typewriter
4484 %autoindent
4480 %autoindent
4485 \family default
4481 \family default
4486 allows you to toggle it on/off at runtime.
4482 allows you to toggle it on/off at runtime.
4487 You can also disable it permanently on in your
4483 You can also disable it permanently on in your
4488 \family typewriter
4484 \family typewriter
4489 ipythonrc
4485 ipythonrc
4490 \family default
4486 \family default
4491 file (set
4487 file (set
4492 \family typewriter
4488 \family typewriter
4493 autoindent 0
4489 autoindent 0
4494 \family default
4490 \family default
4495 ).
4491 ).
4496 \layout Subsubsection
4492 \layout Subsubsection
4497
4493
4498 Customizing readline behavior
4494 Customizing readline behavior
4499 \layout Standard
4495 \layout Standard
4500
4496
4501 All these features are based on the GNU readline library, which has an extremely
4497 All these features are based on the GNU readline library, which has an extremely
4502 customizable interface.
4498 customizable interface.
4503 Normally, readline is configured via a file which defines the behavior
4499 Normally, readline is configured via a file which defines the behavior
4504 of the library; the details of the syntax for this can be found in the
4500 of the library; the details of the syntax for this can be found in the
4505 readline documentation available with your system or on the Internet.
4501 readline documentation available with your system or on the Internet.
4506 IPython doesn't read this file (if it exists) directly, but it does support
4502 IPython doesn't read this file (if it exists) directly, but it does support
4507 passing to readline valid options via a simple interface.
4503 passing to readline valid options via a simple interface.
4508 In brief, you can customize readline by setting the following options in
4504 In brief, you can customize readline by setting the following options in
4509 your
4505 your
4510 \family typewriter
4506 \family typewriter
4511 ipythonrc
4507 ipythonrc
4512 \family default
4508 \family default
4513 configuration file (note that these options can
4509 configuration file (note that these options can
4514 \emph on
4510 \emph on
4515 not
4511 not
4516 \emph default
4512 \emph default
4517 be specified at the command line):
4513 be specified at the command line):
4518 \layout List
4514 \layout List
4519 \labelwidthstring 00.00.0000
4515 \labelwidthstring 00.00.0000
4520
4516
4521
4517
4522 \family typewriter
4518 \family typewriter
4523 \series bold
4519 \series bold
4524 readline_parse_and_bind:
4520 readline_parse_and_bind:
4525 \family default
4521 \family default
4526 \series default
4522 \series default
4527 this option can appear as many times as you want, each time defining a
4523 this option can appear as many times as you want, each time defining a
4528 string to be executed via a
4524 string to be executed via a
4529 \family typewriter
4525 \family typewriter
4530 readline.parse_and_bind()
4526 readline.parse_and_bind()
4531 \family default
4527 \family default
4532 command.
4528 command.
4533 The syntax for valid commands of this kind can be found by reading the
4529 The syntax for valid commands of this kind can be found by reading the
4534 documentation for the GNU readline library, as these commands are of the
4530 documentation for the GNU readline library, as these commands are of the
4535 kind which readline accepts in its configuration file.
4531 kind which readline accepts in its configuration file.
4536 \layout List
4532 \layout List
4537 \labelwidthstring 00.00.0000
4533 \labelwidthstring 00.00.0000
4538
4534
4539
4535
4540 \family typewriter
4536 \family typewriter
4541 \series bold
4537 \series bold
4542 readline_remove_delims:
4538 readline_remove_delims:
4543 \family default
4539 \family default
4544 \series default
4540 \series default
4545 a string of characters to be removed from the default word-delimiters list
4541 a string of characters to be removed from the default word-delimiters list
4546 used by readline, so that completions may be performed on strings which
4542 used by readline, so that completions may be performed on strings which
4547 contain them.
4543 contain them.
4548 Do not change the default value unless you know what you're doing.
4544 Do not change the default value unless you know what you're doing.
4549 \layout List
4545 \layout List
4550 \labelwidthstring 00.00.0000
4546 \labelwidthstring 00.00.0000
4551
4547
4552
4548
4553 \family typewriter
4549 \family typewriter
4554 \series bold
4550 \series bold
4555 readline_omit__names
4551 readline_omit__names
4556 \family default
4552 \family default
4557 \series default
4553 \series default
4558 : when tab-completion is enabled, hitting
4554 : when tab-completion is enabled, hitting
4559 \family typewriter
4555 \family typewriter
4560 <tab>
4556 <tab>
4561 \family default
4557 \family default
4562 after a '
4558 after a '
4563 \family typewriter
4559 \family typewriter
4564 .
4560 .
4565 \family default
4561 \family default
4566 ' in a name will complete all attributes of an object, including all the
4562 ' in a name will complete all attributes of an object, including all the
4567 special methods whose names include double underscores (like
4563 special methods whose names include double underscores (like
4568 \family typewriter
4564 \family typewriter
4569 __getitem__
4565 __getitem__
4570 \family default
4566 \family default
4571 or
4567 or
4572 \family typewriter
4568 \family typewriter
4573 __class__
4569 __class__
4574 \family default
4570 \family default
4575 ).
4571 ).
4576 If you'd rather not see these names by default, you can set this option
4572 If you'd rather not see these names by default, you can set this option
4577 to 1.
4573 to 1.
4578 Note that even when this option is set, you can still see those names by
4574 Note that even when this option is set, you can still see those names by
4579 explicitly typing a
4575 explicitly typing a
4580 \family typewriter
4576 \family typewriter
4581 _
4577 _
4582 \family default
4578 \family default
4583 after the period and hitting
4579 after the period and hitting
4584 \family typewriter
4580 \family typewriter
4585 <tab>
4581 <tab>
4586 \family default
4582 \family default
4587 : '
4583 : '
4588 \family typewriter
4584 \family typewriter
4589 name._<tab>
4585 name._<tab>
4590 \family default
4586 \family default
4591 ' will always complete attribute names starting with '
4587 ' will always complete attribute names starting with '
4592 \family typewriter
4588 \family typewriter
4593 _
4589 _
4594 \family default
4590 \family default
4595 '.
4591 '.
4596 \layout List
4592 \layout List
4597 \labelwidthstring 00.00.0000
4593 \labelwidthstring 00.00.0000
4598
4594
4599 \SpecialChar ~
4595 \SpecialChar ~
4600 This option is off by default so that new users see all attributes of any
4596 This option is off by default so that new users see all attributes of any
4601 objects they are dealing with.
4597 objects they are dealing with.
4602 \layout Standard
4598 \layout Standard
4603
4599
4604 You will find the default values along with a corresponding detailed explanation
4600 You will find the default values along with a corresponding detailed explanation
4605 in your
4601 in your
4606 \family typewriter
4602 \family typewriter
4607 ipythonrc
4603 ipythonrc
4608 \family default
4604 \family default
4609 file.
4605 file.
4610 \layout Subsection
4606 \layout Subsection
4611
4607
4612 Session logging and restoring
4608 Session logging and restoring
4613 \layout Standard
4609 \layout Standard
4614
4610
4615 You can log all input from a session either by starting IPython with the
4611 You can log all input from a session either by starting IPython with the
4616 command line switches
4612 command line switches
4617 \family typewriter
4613 \family typewriter
4618 -log
4614 -log
4619 \family default
4615 \family default
4620 or
4616 or
4621 \family typewriter
4617 \family typewriter
4622 -logfile
4618 -logfile
4623 \family default
4619 \family default
4624 (see sec.
4620 (see sec.
4625
4621
4626 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
4622 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
4627
4623
4628 \end_inset
4624 \end_inset
4629
4625
4630 )or by activating the logging at any moment with the magic function
4626 )or by activating the logging at any moment with the magic function
4631 \family typewriter
4627 \family typewriter
4632 %logstart
4628 %logstart
4633 \family default
4629 \family default
4634 .
4630 .
4635
4631
4636 \layout Standard
4632 \layout Standard
4637
4633
4638 Log files can later be reloaded with the
4634 Log files can later be reloaded with the
4639 \family typewriter
4635 \family typewriter
4640 -logplay
4636 -logplay
4641 \family default
4637 \family default
4642 option and IPython will attempt to 'replay' the log by executing all the
4638 option and IPython will attempt to 'replay' the log by executing all the
4643 lines in it, thus restoring the state of a previous session.
4639 lines in it, thus restoring the state of a previous session.
4644 This feature is not quite perfect, but can still be useful in many cases.
4640 This feature is not quite perfect, but can still be useful in many cases.
4645 \layout Standard
4641 \layout Standard
4646
4642
4647 The log files can also be used as a way to have a permanent record of any
4643 The log files can also be used as a way to have a permanent record of any
4648 code you wrote while experimenting.
4644 code you wrote while experimenting.
4649 Log files are regular text files which you can later open in your favorite
4645 Log files are regular text files which you can later open in your favorite
4650 text editor to extract code or to 'clean them up' before using them to
4646 text editor to extract code or to 'clean them up' before using them to
4651 replay a session.
4647 replay a session.
4652 \layout Standard
4648 \layout Standard
4653
4649
4654 The
4650 The
4655 \family typewriter
4651 \family typewriter
4656 %logstart
4652 %logstart
4657 \family default
4653 \family default
4658 function for activating logging in mid-session is used as follows:
4654 function for activating logging in mid-session is used as follows:
4659 \layout Standard
4655 \layout Standard
4660
4656
4661
4657
4662 \family typewriter
4658 \family typewriter
4663 %logstart [log_name [log_mode]]
4659 %logstart [log_name [log_mode]]
4664 \layout Standard
4660 \layout Standard
4665
4661
4666 If no name is given, it defaults to a file named
4662 If no name is given, it defaults to a file named
4667 \family typewriter
4663 \family typewriter
4668 'log'
4664 'log'
4669 \family default
4665 \family default
4670 in your IPYTHONDIR directory, in
4666 in your IPYTHONDIR directory, in
4671 \family typewriter
4667 \family typewriter
4672 'rotate'
4668 'rotate'
4673 \family default
4669 \family default
4674 mode (see below).
4670 mode (see below).
4675 \layout Standard
4671 \layout Standard
4676
4672
4677 '
4673 '
4678 \family typewriter
4674 \family typewriter
4679 %logstart name
4675 %logstart name
4680 \family default
4676 \family default
4681 ' saves to file
4677 ' saves to file
4682 \family typewriter
4678 \family typewriter
4683 'name'
4679 'name'
4684 \family default
4680 \family default
4685 in
4681 in
4686 \family typewriter
4682 \family typewriter
4687 'backup'
4683 'backup'
4688 \family default
4684 \family default
4689 mode.
4685 mode.
4690 It saves your history up to that point and then continues logging.
4686 It saves your history up to that point and then continues logging.
4691 \layout Standard
4687 \layout Standard
4692
4688
4693
4689
4694 \family typewriter
4690 \family typewriter
4695 %logstart
4691 %logstart
4696 \family default
4692 \family default
4697 takes a second optional parameter: logging mode.
4693 takes a second optional parameter: logging mode.
4698 This can be one of (note that the modes are given unquoted):
4694 This can be one of (note that the modes are given unquoted):
4699 \layout List
4695 \layout List
4700 \labelwidthstring 00.00.0000
4696 \labelwidthstring 00.00.0000
4701
4697
4702
4698
4703 \family typewriter
4699 \family typewriter
4704 over
4700 over
4705 \family default
4701 \family default
4706 : overwrite existing
4702 : overwrite existing
4707 \family typewriter
4703 \family typewriter
4708 log_name
4704 log_name
4709 \family default
4705 \family default
4710 .
4706 .
4711 \layout List
4707 \layout List
4712 \labelwidthstring 00.00.0000
4708 \labelwidthstring 00.00.0000
4713
4709
4714
4710
4715 \family typewriter
4711 \family typewriter
4716 backup
4712 backup
4717 \family default
4713 \family default
4718 : rename (if exists) to
4714 : rename (if exists) to
4719 \family typewriter
4715 \family typewriter
4720 log_name~
4716 log_name~
4721 \family default
4717 \family default
4722 and start
4718 and start
4723 \family typewriter
4719 \family typewriter
4724 log_name
4720 log_name
4725 \family default
4721 \family default
4726 .
4722 .
4727 \layout List
4723 \layout List
4728 \labelwidthstring 00.00.0000
4724 \labelwidthstring 00.00.0000
4729
4725
4730
4726
4731 \family typewriter
4727 \family typewriter
4732 append
4728 append
4733 \family default
4729 \family default
4734 : well, that says it.
4730 : well, that says it.
4735 \layout List
4731 \layout List
4736 \labelwidthstring 00.00.0000
4732 \labelwidthstring 00.00.0000
4737
4733
4738
4734
4739 \family typewriter
4735 \family typewriter
4740 rotate
4736 rotate
4741 \family default
4737 \family default
4742 : create rotating logs
4738 : create rotating logs
4743 \family typewriter
4739 \family typewriter
4744 log_name
4740 log_name
4745 \family default
4741 \family default
4746 .
4742 .
4747 \family typewriter
4743 \family typewriter
4748 1~
4744 1~
4749 \family default
4745 \family default
4750 ,
4746 ,
4751 \family typewriter
4747 \family typewriter
4752 log_name.2~
4748 log_name.2~
4753 \family default
4749 \family default
4754 , etc.
4750 , etc.
4755 \layout Standard
4751 \layout Standard
4756
4752
4757 The
4753 The
4758 \family typewriter
4754 \family typewriter
4759 %logoff
4755 %logoff
4760 \family default
4756 \family default
4761 and
4757 and
4762 \family typewriter
4758 \family typewriter
4763 %logon
4759 %logon
4764 \family default
4760 \family default
4765 functions allow you to temporarily stop and resume logging to a file which
4761 functions allow you to temporarily stop and resume logging to a file which
4766 had previously been started with
4762 had previously been started with
4767 \family typewriter
4763 \family typewriter
4768 %logstart
4764 %logstart
4769 \family default
4765 \family default
4770 .
4766 .
4771 They will fail (with an explanation) if you try to use them before logging
4767 They will fail (with an explanation) if you try to use them before logging
4772 has been started.
4768 has been started.
4773 \layout Subsection
4769 \layout Subsection
4774
4770
4775
4771
4776 \begin_inset LatexCommand \label{sub:System-shell-access}
4772 \begin_inset LatexCommand \label{sub:System-shell-access}
4777
4773
4778 \end_inset
4774 \end_inset
4779
4775
4780 System shell access
4776 System shell access
4781 \layout Standard
4777 \layout Standard
4782
4778
4783 Any input line beginning with a
4779 Any input line beginning with a
4784 \family typewriter
4780 \family typewriter
4785 !
4781 !
4786 \family default
4782 \family default
4787 character is passed verbatim (minus the
4783 character is passed verbatim (minus the
4788 \family typewriter
4784 \family typewriter
4789 !
4785 !
4790 \family default
4786 \family default
4791 , of course) to the underlying operating system.
4787 , of course) to the underlying operating system.
4792 For example, typing
4788 For example, typing
4793 \family typewriter
4789 \family typewriter
4794 !ls
4790 !ls
4795 \family default
4791 \family default
4796 will run
4792 will run
4797 \family typewriter
4793 \family typewriter
4798 'ls'
4794 'ls'
4799 \family default
4795 \family default
4800 in the current directory.
4796 in the current directory.
4801 \layout Subsubsection
4797 \layout Subsubsection
4802
4798
4803 Manual capture of command output
4799 Manual capture of command output
4804 \layout Standard
4800 \layout Standard
4805
4801
4806 If the input line begins with
4802 If the input line begins with
4807 \emph on
4803 \emph on
4808 two
4804 two
4809 \emph default
4805 \emph default
4810 exclamation marks,
4806 exclamation marks,
4811 \family typewriter
4807 \family typewriter
4812 !!
4808 !!
4813 \family default
4809 \family default
4814 , the command is executed but its output is captured and returned as a python
4810 , the command is executed but its output is captured and returned as a python
4815 list, split on newlines.
4811 list, split on newlines.
4816 Any output sent by the subprocess to standard error is printed separately,
4812 Any output sent by the subprocess to standard error is printed separately,
4817 so that the resulting list only captures standard output.
4813 so that the resulting list only captures standard output.
4818 The
4814 The
4819 \family typewriter
4815 \family typewriter
4820 !!
4816 !!
4821 \family default
4817 \family default
4822 syntax is a shorthand for the
4818 syntax is a shorthand for the
4823 \family typewriter
4819 \family typewriter
4824 %sx
4820 %sx
4825 \family default
4821 \family default
4826 magic command.
4822 magic command.
4827 \layout Standard
4823 \layout Standard
4828
4824
4829 Finally, the
4825 Finally, the
4830 \family typewriter
4826 \family typewriter
4831 %sc
4827 %sc
4832 \family default
4828 \family default
4833 magic (short for `shell capture') is similar to
4829 magic (short for `shell capture') is similar to
4834 \family typewriter
4830 \family typewriter
4835 %sx
4831 %sx
4836 \family default
4832 \family default
4837 , but allowing more fine-grained control of the capture details, and storing
4833 , but allowing more fine-grained control of the capture details, and storing
4838 the result directly into a named variable.
4834 the result directly into a named variable.
4839 \layout Standard
4835 \layout Standard
4840
4836
4841 See Sec.\SpecialChar ~
4837 See Sec.\SpecialChar ~
4842
4838
4843 \begin_inset LatexCommand \ref{sec:magic}
4839 \begin_inset LatexCommand \ref{sec:magic}
4844
4840
4845 \end_inset
4841 \end_inset
4846
4842
4847 for details on the magics
4843 for details on the magics
4848 \family typewriter
4844 \family typewriter
4849 %sc
4845 %sc
4850 \family default
4846 \family default
4851 and
4847 and
4852 \family typewriter
4848 \family typewriter
4853 %sx
4849 %sx
4854 \family default
4850 \family default
4855 , or use IPython's own help (
4851 , or use IPython's own help (
4856 \family typewriter
4852 \family typewriter
4857 sc?
4853 sc?
4858 \family default
4854 \family default
4859 and
4855 and
4860 \family typewriter
4856 \family typewriter
4861 sx?
4857 sx?
4862 \family default
4858 \family default
4863 ) for further details.
4859 ) for further details.
4864 \layout Standard
4860 \layout Standard
4865
4861
4866 IPython also allows you to expand the value of python variables when making
4862 IPython also allows you to expand the value of python variables when making
4867 system calls.
4863 system calls.
4868 Any python variable or expression which you prepend with
4864 Any python variable or expression which you prepend with
4869 \family typewriter
4865 \family typewriter
4870 $
4866 $
4871 \family default
4867 \family default
4872 will get expanded before the system call is made.
4868 will get expanded before the system call is made.
4873
4869
4874 \layout Standard
4870 \layout Standard
4875
4871
4876
4872
4877 \family typewriter
4873 \family typewriter
4878 In [1]: pyvar='Hello world'
4874 In [1]: pyvar='Hello world'
4879 \newline
4875 \newline
4880 In [2]: !echo "A python variable: $pyvar"
4876 In [2]: !echo "A python variable: $pyvar"
4881 \newline
4877 \newline
4882 A python variable: Hello world
4878 A python variable: Hello world
4883 \layout Standard
4879 \layout Standard
4884
4880
4885 If you want the shell to actually see a literal
4881 If you want the shell to actually see a literal
4886 \family typewriter
4882 \family typewriter
4887 $
4883 $
4888 \family default
4884 \family default
4889 , you need to type it twice:
4885 , you need to type it twice:
4890 \layout Standard
4886 \layout Standard
4891
4887
4892
4888
4893 \family typewriter
4889 \family typewriter
4894 In [3]: !echo "A system variable: $$HOME"
4890 In [3]: !echo "A system variable: $$HOME"
4895 \newline
4891 \newline
4896 A system variable: /home/fperez
4892 A system variable: /home/fperez
4897 \layout Standard
4893 \layout Standard
4898
4894
4899 You can pass arbitrary expressions, though you'll need to delimit them with
4895 You can pass arbitrary expressions, though you'll need to delimit them with
4900
4896
4901 \family typewriter
4897 \family typewriter
4902 {}
4898 {}
4903 \family default
4899 \family default
4904 if there is ambiguity as to the extent of the expression:
4900 if there is ambiguity as to the extent of the expression:
4905 \layout Standard
4901 \layout Standard
4906
4902
4907
4903
4908 \family typewriter
4904 \family typewriter
4909 In [5]: x=10
4905 In [5]: x=10
4910 \newline
4906 \newline
4911 In [6]: y=20
4907 In [6]: y=20
4912 \newline
4908 \newline
4913 In [13]: !echo $x+y
4909 In [13]: !echo $x+y
4914 \newline
4910 \newline
4915 10+y
4911 10+y
4916 \newline
4912 \newline
4917 In [7]: !echo ${x+y}
4913 In [7]: !echo ${x+y}
4918 \newline
4914 \newline
4919 30
4915 30
4920 \layout Standard
4916 \layout Standard
4921
4917
4922 Even object attributes can be expanded:
4918 Even object attributes can be expanded:
4923 \layout Standard
4919 \layout Standard
4924
4920
4925
4921
4926 \family typewriter
4922 \family typewriter
4927 In [12]: !echo $sys.argv
4923 In [12]: !echo $sys.argv
4928 \newline
4924 \newline
4929 [/home/fperez/usr/bin/ipython]
4925 [/home/fperez/usr/bin/ipython]
4930 \layout Subsection
4926 \layout Subsection
4931
4927
4932 System command aliases
4928 System command aliases
4933 \layout Standard
4929 \layout Standard
4934
4930
4935 The
4931 The
4936 \family typewriter
4932 \family typewriter
4937 %alias
4933 %alias
4938 \family default
4934 \family default
4939 magic function and the
4935 magic function and the
4940 \family typewriter
4936 \family typewriter
4941 alias
4937 alias
4942 \family default
4938 \family default
4943 option in the
4939 option in the
4944 \family typewriter
4940 \family typewriter
4945 ipythonrc
4941 ipythonrc
4946 \family default
4942 \family default
4947 configuration file allow you to define magic functions which are in fact
4943 configuration file allow you to define magic functions which are in fact
4948 system shell commands.
4944 system shell commands.
4949 These aliases can have parameters.
4945 These aliases can have parameters.
4950
4946
4951 \layout Standard
4947 \layout Standard
4952
4948
4953 '
4949 '
4954 \family typewriter
4950 \family typewriter
4955 %alias alias_name cmd
4951 %alias alias_name cmd
4956 \family default
4952 \family default
4957 ' defines '
4953 ' defines '
4958 \family typewriter
4954 \family typewriter
4959 alias_name
4955 alias_name
4960 \family default
4956 \family default
4961 ' as an alias for '
4957 ' as an alias for '
4962 \family typewriter
4958 \family typewriter
4963 cmd
4959 cmd
4964 \family default
4960 \family default
4965 '
4961 '
4966 \layout Standard
4962 \layout Standard
4967
4963
4968 Then, typing '
4964 Then, typing '
4969 \family typewriter
4965 \family typewriter
4970 %alias_name params
4966 %alias_name params
4971 \family default
4967 \family default
4972 ' will execute the system command '
4968 ' will execute the system command '
4973 \family typewriter
4969 \family typewriter
4974 cmd params
4970 cmd params
4975 \family default
4971 \family default
4976 ' (from your underlying operating system).
4972 ' (from your underlying operating system).
4977
4973
4978 \layout Standard
4974 \layout Standard
4979
4975
4980 You can also define aliases with parameters using
4976 You can also define aliases with parameters using
4981 \family typewriter
4977 \family typewriter
4982 %s
4978 %s
4983 \family default
4979 \family default
4984 specifiers (one per parameter).
4980 specifiers (one per parameter).
4985 The following example defines the
4981 The following example defines the
4986 \family typewriter
4982 \family typewriter
4987 %parts
4983 %parts
4988 \family default
4984 \family default
4989 function as an alias to the command '
4985 function as an alias to the command '
4990 \family typewriter
4986 \family typewriter
4991 echo first %s second %s
4987 echo first %s second %s
4992 \family default
4988 \family default
4993 ' where each
4989 ' where each
4994 \family typewriter
4990 \family typewriter
4995 %s
4991 %s
4996 \family default
4992 \family default
4997 will be replaced by a positional parameter to the call to
4993 will be replaced by a positional parameter to the call to
4998 \family typewriter
4994 \family typewriter
4999 %parts:
4995 %parts:
5000 \layout Standard
4996 \layout Standard
5001
4997
5002
4998
5003 \family typewriter
4999 \family typewriter
5004 In [1]: alias parts echo first %s second %s
5000 In [1]: alias parts echo first %s second %s
5005 \newline
5001 \newline
5006 In [2]: %parts A B
5002 In [2]: %parts A B
5007 \newline
5003 \newline
5008 first A second B
5004 first A second B
5009 \newline
5005 \newline
5010 In [3]: %parts A
5006 In [3]: %parts A
5011 \newline
5007 \newline
5012 Incorrect number of arguments: 2 expected.
5008 Incorrect number of arguments: 2 expected.
5013
5009
5014 \newline
5010 \newline
5015 parts is an alias to: 'echo first %s second %s'
5011 parts is an alias to: 'echo first %s second %s'
5016 \layout Standard
5012 \layout Standard
5017
5013
5018 If called with no parameters,
5014 If called with no parameters,
5019 \family typewriter
5015 \family typewriter
5020 %alias
5016 %alias
5021 \family default
5017 \family default
5022 prints the table of currently defined aliases.
5018 prints the table of currently defined aliases.
5023 \layout Standard
5019 \layout Standard
5024
5020
5025 The
5021 The
5026 \family typewriter
5022 \family typewriter
5027 %rehash/rehashx
5023 %rehash/rehashx
5028 \family default
5024 \family default
5029 magics allow you to load your entire
5025 magics allow you to load your entire
5030 \family typewriter
5026 \family typewriter
5031 $PATH
5027 $PATH
5032 \family default
5028 \family default
5033 as ipython aliases.
5029 as ipython aliases.
5034 See their respective docstrings (or sec.\SpecialChar ~
5030 See their respective docstrings (or sec.\SpecialChar ~
5035
5031
5036 \begin_inset LatexCommand \ref{sec:magic}
5032 \begin_inset LatexCommand \ref{sec:magic}
5037
5033
5038 \end_inset
5034 \end_inset
5039
5035
5040 for further details).
5036 for further details).
5041 \layout Subsection
5037 \layout Subsection
5042
5038
5043
5039
5044 \begin_inset LatexCommand \label{sec:dreload}
5040 \begin_inset LatexCommand \label{sec:dreload}
5045
5041
5046 \end_inset
5042 \end_inset
5047
5043
5048 Recursive reload
5044 Recursive reload
5049 \layout Standard
5045 \layout Standard
5050
5046
5051 The
5047 The
5052 \family typewriter
5048 \family typewriter
5053 dreload
5049 dreload
5054 \family default
5050 \family default
5055 function does a recursive reload of a module: changes made to the module
5051 function does a recursive reload of a module: changes made to the module
5056 since you imported will actually be available without having to exit.
5052 since you imported will actually be available without having to exit.
5057 \layout Subsection
5053 \layout Subsection
5058
5054
5059 Verbose and colored exception traceback printouts
5055 Verbose and colored exception traceback printouts
5060 \layout Standard
5056 \layout Standard
5061
5057
5062 IPython provides the option to see very detailed exception tracebacks, which
5058 IPython provides the option to see very detailed exception tracebacks, which
5063 can be especially useful when debugging large programs.
5059 can be especially useful when debugging large programs.
5064 You can run any Python file with the
5060 You can run any Python file with the
5065 \family typewriter
5061 \family typewriter
5066 %run
5062 %run
5067 \family default
5063 \family default
5068 function to benefit from these detailed tracebacks.
5064 function to benefit from these detailed tracebacks.
5069 Furthermore, both normal and verbose tracebacks can be colored (if your
5065 Furthermore, both normal and verbose tracebacks can be colored (if your
5070 terminal supports it) which makes them much easier to parse visually.
5066 terminal supports it) which makes them much easier to parse visually.
5071 \layout Standard
5067 \layout Standard
5072
5068
5073 See the magic
5069 See the magic
5074 \family typewriter
5070 \family typewriter
5075 xmode
5071 xmode
5076 \family default
5072 \family default
5077 and
5073 and
5078 \family typewriter
5074 \family typewriter
5079 colors
5075 colors
5080 \family default
5076 \family default
5081 functions for details (just type
5077 functions for details (just type
5082 \family typewriter
5078 \family typewriter
5083 %magic
5079 %magic
5084 \family default
5080 \family default
5085 ).
5081 ).
5086 \layout Standard
5082 \layout Standard
5087
5083
5088 These features are basically a terminal version of Ka-Ping Yee's
5084 These features are basically a terminal version of Ka-Ping Yee's
5089 \family typewriter
5085 \family typewriter
5090 cgitb
5086 cgitb
5091 \family default
5087 \family default
5092 module, now part of the standard Python library.
5088 module, now part of the standard Python library.
5093 \layout Subsection
5089 \layout Subsection
5094
5090
5095
5091
5096 \begin_inset LatexCommand \label{sec:cache_input}
5092 \begin_inset LatexCommand \label{sec:cache_input}
5097
5093
5098 \end_inset
5094 \end_inset
5099
5095
5100 Input caching system
5096 Input caching system
5101 \layout Standard
5097 \layout Standard
5102
5098
5103 IPython offers numbered prompts (In/Out) with input and output caching.
5099 IPython offers numbered prompts (In/Out) with input and output caching.
5104 All input is saved and can be retrieved as variables (besides the usual
5100 All input is saved and can be retrieved as variables (besides the usual
5105 arrow key recall).
5101 arrow key recall).
5106 \layout Standard
5102 \layout Standard
5107
5103
5108 The following GLOBAL variables always exist (so don't overwrite them!):
5104 The following GLOBAL variables always exist (so don't overwrite them!):
5109
5105
5110 \family typewriter
5106 \family typewriter
5111 _i
5107 _i
5112 \family default
5108 \family default
5113 : stores previous input.
5109 : stores previous input.
5114
5110
5115 \family typewriter
5111 \family typewriter
5116 _ii
5112 _ii
5117 \family default
5113 \family default
5118 : next previous.
5114 : next previous.
5119
5115
5120 \family typewriter
5116 \family typewriter
5121 _iii
5117 _iii
5122 \family default
5118 \family default
5123 : next-next previous.
5119 : next-next previous.
5124
5120
5125 \family typewriter
5121 \family typewriter
5126 _ih
5122 _ih
5127 \family default
5123 \family default
5128 : a list of all input
5124 : a list of all input
5129 \family typewriter
5125 \family typewriter
5130 _ih[n]
5126 _ih[n]
5131 \family default
5127 \family default
5132 is the input from line
5128 is the input from line
5133 \family typewriter
5129 \family typewriter
5134 n
5130 n
5135 \family default
5131 \family default
5136 and this list is aliased to the global variable
5132 and this list is aliased to the global variable
5137 \family typewriter
5133 \family typewriter
5138 In
5134 In
5139 \family default
5135 \family default
5140 .
5136 .
5141 If you overwrite
5137 If you overwrite
5142 \family typewriter
5138 \family typewriter
5143 In
5139 In
5144 \family default
5140 \family default
5145 with a variable of your own, you can remake the assignment to the internal
5141 with a variable of your own, you can remake the assignment to the internal
5146 list with a simple
5142 list with a simple
5147 \family typewriter
5143 \family typewriter
5148 'In=_ih'
5144 'In=_ih'
5149 \family default
5145 \family default
5150 .
5146 .
5151 \layout Standard
5147 \layout Standard
5152
5148
5153 Additionally, global variables named
5149 Additionally, global variables named
5154 \family typewriter
5150 \family typewriter
5155 _i<n>
5151 _i<n>
5156 \family default
5152 \family default
5157 are dynamically created (
5153 are dynamically created (
5158 \family typewriter
5154 \family typewriter
5159 <n>
5155 <n>
5160 \family default
5156 \family default
5161 being the prompt counter), such that
5157 being the prompt counter), such that
5162 \newline
5158 \newline
5163
5159
5164 \family typewriter
5160 \family typewriter
5165 _i<n> == _ih[<n>] == In[<n>].
5161 _i<n> == _ih[<n>] == In[<n>].
5166 \layout Standard
5162 \layout Standard
5167
5163
5168 For example, what you typed at prompt 14 is available as
5164 For example, what you typed at prompt 14 is available as
5169 \family typewriter
5165 \family typewriter
5170 _i14,
5166 _i14,
5171 \family default
5167 \family default
5172
5168
5173 \family typewriter
5169 \family typewriter
5174 _ih[14]
5170 _ih[14]
5175 \family default
5171 \family default
5176 and
5172 and
5177 \family typewriter
5173 \family typewriter
5178 In[14]
5174 In[14]
5179 \family default
5175 \family default
5180 .
5176 .
5181 \layout Standard
5177 \layout Standard
5182
5178
5183 This allows you to easily cut and paste multi line interactive prompts by
5179 This allows you to easily cut and paste multi line interactive prompts by
5184 printing them out: they print like a clean string, without prompt characters.
5180 printing them out: they print like a clean string, without prompt characters.
5185 You can also manipulate them like regular variables (they are strings),
5181 You can also manipulate them like regular variables (they are strings),
5186 modify or exec them (typing
5182 modify or exec them (typing
5187 \family typewriter
5183 \family typewriter
5188 'exec _i9'
5184 'exec _i9'
5189 \family default
5185 \family default
5190 will re-execute the contents of input prompt 9, '
5186 will re-execute the contents of input prompt 9, '
5191 \family typewriter
5187 \family typewriter
5192 exec In[9:14]+In[18]
5188 exec In[9:14]+In[18]
5193 \family default
5189 \family default
5194 ' will re-execute lines 9 through 13 and line 18).
5190 ' will re-execute lines 9 through 13 and line 18).
5195 \layout Standard
5191 \layout Standard
5196
5192
5197 You can also re-execute multiple lines of input easily by using the magic
5193 You can also re-execute multiple lines of input easily by using the magic
5198
5194
5199 \family typewriter
5195 \family typewriter
5200 %macro
5196 %macro
5201 \family default
5197 \family default
5202 function (which automates the process and allows re-execution without having
5198 function (which automates the process and allows re-execution without having
5203 to type '
5199 to type '
5204 \family typewriter
5200 \family typewriter
5205 exec
5201 exec
5206 \family default
5202 \family default
5207 ' every time).
5203 ' every time).
5208 The macro system also allows you to re-execute previous lines which include
5204 The macro system also allows you to re-execute previous lines which include
5209 magic function calls (which require special processing).
5205 magic function calls (which require special processing).
5210 Type
5206 Type
5211 \family typewriter
5207 \family typewriter
5212 %macro?
5208 %macro?
5213 \family default
5209 \family default
5214 or see sec.
5210 or see sec.
5215
5211
5216 \begin_inset LatexCommand \ref{sec:magic}
5212 \begin_inset LatexCommand \ref{sec:magic}
5217
5213
5218 \end_inset
5214 \end_inset
5219
5215
5220 for more details on the macro system.
5216 for more details on the macro system.
5221 \layout Standard
5217 \layout Standard
5222
5218
5223 A history function
5219 A history function
5224 \family typewriter
5220 \family typewriter
5225 %hist
5221 %hist
5226 \family default
5222 \family default
5227 allows you to see any part of your input history by printing a range of
5223 allows you to see any part of your input history by printing a range of
5228 the
5224 the
5229 \family typewriter
5225 \family typewriter
5230 _i
5226 _i
5231 \family default
5227 \family default
5232 variables.
5228 variables.
5233 \layout Subsection
5229 \layout Subsection
5234
5230
5235
5231
5236 \begin_inset LatexCommand \label{sec:cache_output}
5232 \begin_inset LatexCommand \label{sec:cache_output}
5237
5233
5238 \end_inset
5234 \end_inset
5239
5235
5240 Output caching system
5236 Output caching system
5241 \layout Standard
5237 \layout Standard
5242
5238
5243 For output that is returned from actions, a system similar to the input
5239 For output that is returned from actions, a system similar to the input
5244 cache exists but using
5240 cache exists but using
5245 \family typewriter
5241 \family typewriter
5246 _
5242 _
5247 \family default
5243 \family default
5248 instead of
5244 instead of
5249 \family typewriter
5245 \family typewriter
5250 _i
5246 _i
5251 \family default
5247 \family default
5252 .
5248 .
5253 Only actions that produce a result (NOT assignments, for example) are cached.
5249 Only actions that produce a result (NOT assignments, for example) are cached.
5254 If you are familiar with Mathematica, IPython's
5250 If you are familiar with Mathematica, IPython's
5255 \family typewriter
5251 \family typewriter
5256 _
5252 _
5257 \family default
5253 \family default
5258 variables behave exactly like Mathematica's
5254 variables behave exactly like Mathematica's
5259 \family typewriter
5255 \family typewriter
5260 %
5256 %
5261 \family default
5257 \family default
5262 variables.
5258 variables.
5263 \layout Standard
5259 \layout Standard
5264
5260
5265 The following GLOBAL variables always exist (so don't overwrite them!):
5261 The following GLOBAL variables always exist (so don't overwrite them!):
5266
5262
5267 \layout List
5263 \layout List
5268 \labelwidthstring 00.00.0000
5264 \labelwidthstring 00.00.0000
5269
5265
5270
5266
5271 \family typewriter
5267 \family typewriter
5272 \series bold
5268 \series bold
5273 _
5269 _
5274 \family default
5270 \family default
5275 \series default
5271 \series default
5276 (a
5272 (a
5277 \emph on
5273 \emph on
5278 single
5274 single
5279 \emph default
5275 \emph default
5280 underscore) : stores previous output, like Python's default interpreter.
5276 underscore) : stores previous output, like Python's default interpreter.
5281 \layout List
5277 \layout List
5282 \labelwidthstring 00.00.0000
5278 \labelwidthstring 00.00.0000
5283
5279
5284
5280
5285 \family typewriter
5281 \family typewriter
5286 \series bold
5282 \series bold
5287 __
5283 __
5288 \family default
5284 \family default
5289 \series default
5285 \series default
5290 (two underscores): next previous.
5286 (two underscores): next previous.
5291 \layout List
5287 \layout List
5292 \labelwidthstring 00.00.0000
5288 \labelwidthstring 00.00.0000
5293
5289
5294
5290
5295 \family typewriter
5291 \family typewriter
5296 \series bold
5292 \series bold
5297 ___
5293 ___
5298 \family default
5294 \family default
5299 \series default
5295 \series default
5300 (three underscores): next-next previous.
5296 (three underscores): next-next previous.
5301 \layout Standard
5297 \layout Standard
5302
5298
5303 Additionally, global variables named
5299 Additionally, global variables named
5304 \family typewriter
5300 \family typewriter
5305 _<n>
5301 _<n>
5306 \family default
5302 \family default
5307 are dynamically created (
5303 are dynamically created (
5308 \family typewriter
5304 \family typewriter
5309 <n>
5305 <n>
5310 \family default
5306 \family default
5311 being the prompt counter), such that the result of output
5307 being the prompt counter), such that the result of output
5312 \family typewriter
5308 \family typewriter
5313 <n>
5309 <n>
5314 \family default
5310 \family default
5315 is always available as
5311 is always available as
5316 \family typewriter
5312 \family typewriter
5317 _<n>
5313 _<n>
5318 \family default
5314 \family default
5319 (don't use the angle brackets, just the number, e.g.
5315 (don't use the angle brackets, just the number, e.g.
5320
5316
5321 \family typewriter
5317 \family typewriter
5322 _21
5318 _21
5323 \family default
5319 \family default
5324 ).
5320 ).
5325 \layout Standard
5321 \layout Standard
5326
5322
5327 These global variables are all stored in a global dictionary (not a list,
5323 These global variables are all stored in a global dictionary (not a list,
5328 since it only has entries for lines which returned a result) available
5324 since it only has entries for lines which returned a result) available
5329 under the names
5325 under the names
5330 \family typewriter
5326 \family typewriter
5331 _oh
5327 _oh
5332 \family default
5328 \family default
5333 and
5329 and
5334 \family typewriter
5330 \family typewriter
5335 Out
5331 Out
5336 \family default
5332 \family default
5337 (similar to
5333 (similar to
5338 \family typewriter
5334 \family typewriter
5339 _ih
5335 _ih
5340 \family default
5336 \family default
5341 and
5337 and
5342 \family typewriter
5338 \family typewriter
5343 In
5339 In
5344 \family default
5340 \family default
5345 ).
5341 ).
5346 So the output from line 12 can be obtained as
5342 So the output from line 12 can be obtained as
5347 \family typewriter
5343 \family typewriter
5348 _12
5344 _12
5349 \family default
5345 \family default
5350 ,
5346 ,
5351 \family typewriter
5347 \family typewriter
5352 Out[12]
5348 Out[12]
5353 \family default
5349 \family default
5354 or
5350 or
5355 \family typewriter
5351 \family typewriter
5356 _oh[12]
5352 _oh[12]
5357 \family default
5353 \family default
5358 .
5354 .
5359 If you accidentally overwrite the
5355 If you accidentally overwrite the
5360 \family typewriter
5356 \family typewriter
5361 Out
5357 Out
5362 \family default
5358 \family default
5363 variable you can recover it by typing
5359 variable you can recover it by typing
5364 \family typewriter
5360 \family typewriter
5365 'Out=_oh
5361 'Out=_oh
5366 \family default
5362 \family default
5367 ' at the prompt.
5363 ' at the prompt.
5368 \layout Standard
5364 \layout Standard
5369
5365
5370 This system obviously can potentially put heavy memory demands on your system,
5366 This system obviously can potentially put heavy memory demands on your system,
5371 since it prevents Python's garbage collector from removing any previously
5367 since it prevents Python's garbage collector from removing any previously
5372 computed results.
5368 computed results.
5373 You can control how many results are kept in memory with the option (at
5369 You can control how many results are kept in memory with the option (at
5374 the command line or in your
5370 the command line or in your
5375 \family typewriter
5371 \family typewriter
5376 ipythonrc
5372 ipythonrc
5377 \family default
5373 \family default
5378 file)
5374 file)
5379 \family typewriter
5375 \family typewriter
5380 cache_size
5376 cache_size
5381 \family default
5377 \family default
5382 .
5378 .
5383 If you set it to 0, the whole system is completely disabled and the prompts
5379 If you set it to 0, the whole system is completely disabled and the prompts
5384 revert to the classic
5380 revert to the classic
5385 \family typewriter
5381 \family typewriter
5386 '>>>'
5382 '>>>'
5387 \family default
5383 \family default
5388 of normal Python.
5384 of normal Python.
5389 \layout Subsection
5385 \layout Subsection
5390
5386
5391 Directory history
5387 Directory history
5392 \layout Standard
5388 \layout Standard
5393
5389
5394 Your history of visited directories is kept in the global list
5390 Your history of visited directories is kept in the global list
5395 \family typewriter
5391 \family typewriter
5396 _dh
5392 _dh
5397 \family default
5393 \family default
5398 , and the magic
5394 , and the magic
5399 \family typewriter
5395 \family typewriter
5400 %cd
5396 %cd
5401 \family default
5397 \family default
5402 command can be used to go to any entry in that list.
5398 command can be used to go to any entry in that list.
5403 The
5399 The
5404 \family typewriter
5400 \family typewriter
5405 %dhist
5401 %dhist
5406 \family default
5402 \family default
5407 command allows you to view this history.
5403 command allows you to view this history.
5408 \layout Subsection
5404 \layout Subsection
5409
5405
5410 Automatic parentheses and quotes
5406 Automatic parentheses and quotes
5411 \layout Standard
5407 \layout Standard
5412
5408
5413 These features were adapted from Nathan Gray's LazyPython.
5409 These features were adapted from Nathan Gray's LazyPython.
5414 They are meant to allow less typing for common situations.
5410 They are meant to allow less typing for common situations.
5415 \layout Subsubsection
5411 \layout Subsubsection
5416
5412
5417 Automatic parentheses
5413 Automatic parentheses
5418 \layout Standard
5414 \layout Standard
5419
5415
5420 Callable objects (i.e.
5416 Callable objects (i.e.
5421 functions, methods, etc) can be invoked like this (notice the commas between
5417 functions, methods, etc) can be invoked like this (notice the commas between
5422 the arguments):
5418 the arguments):
5423 \layout Standard
5419 \layout Standard
5424
5420
5425
5421
5426 \family typewriter
5422 \family typewriter
5427 >>> callable_ob arg1, arg2, arg3
5423 >>> callable_ob arg1, arg2, arg3
5428 \layout Standard
5424 \layout Standard
5429
5425
5430 and the input will be translated to this:
5426 and the input will be translated to this:
5431 \layout Standard
5427 \layout Standard
5432
5428
5433
5429
5434 \family typewriter
5430 \family typewriter
5435 --> callable_ob(arg1, arg2, arg3)
5431 --> callable_ob(arg1, arg2, arg3)
5436 \layout Standard
5432 \layout Standard
5437
5433
5438 You can force automatic parentheses by using '/' as the first character
5434 You can force automatic parentheses by using '/' as the first character
5439 of a line.
5435 of a line.
5440 For example:
5436 For example:
5441 \layout Standard
5437 \layout Standard
5442
5438
5443
5439
5444 \family typewriter
5440 \family typewriter
5445 >>> /globals # becomes 'globals()'
5441 >>> /globals # becomes 'globals()'
5446 \layout Standard
5442 \layout Standard
5447
5443
5448 Note that the '/' MUST be the first character on the line! This won't work:
5444 Note that the '/' MUST be the first character on the line! This won't work:
5449
5445
5450 \layout Standard
5446 \layout Standard
5451
5447
5452
5448
5453 \family typewriter
5449 \family typewriter
5454 >>> print /globals # syntax error
5450 >>> print /globals # syntax error
5455 \layout Standard
5451 \layout Standard
5456
5452
5457 In most cases the automatic algorithm should work, so you should rarely
5453 In most cases the automatic algorithm should work, so you should rarely
5458 need to explicitly invoke /.
5454 need to explicitly invoke /.
5459 One notable exception is if you are trying to call a function with a list
5455 One notable exception is if you are trying to call a function with a list
5460 of tuples as arguments (the parenthesis will confuse IPython):
5456 of tuples as arguments (the parenthesis will confuse IPython):
5461 \layout Standard
5457 \layout Standard
5462
5458
5463
5459
5464 \family typewriter
5460 \family typewriter
5465 In [1]: zip (1,2,3),(4,5,6) # won't work
5461 In [1]: zip (1,2,3),(4,5,6) # won't work
5466 \layout Standard
5462 \layout Standard
5467
5463
5468 but this will work:
5464 but this will work:
5469 \layout Standard
5465 \layout Standard
5470
5466
5471
5467
5472 \family typewriter
5468 \family typewriter
5473 In [2]: /zip (1,2,3),(4,5,6)
5469 In [2]: /zip (1,2,3),(4,5,6)
5474 \newline
5470 \newline
5475 ------> zip ((1,2,3),(4,5,6))
5471 ------> zip ((1,2,3),(4,5,6))
5476 \newline
5472 \newline
5477 Out[2]= [(1, 4), (2, 5), (3, 6)]
5473 Out[2]= [(1, 4), (2, 5), (3, 6)]
5478 \layout Standard
5474 \layout Standard
5479
5475
5480 IPython tells you that it has altered your command line by displaying the
5476 IPython tells you that it has altered your command line by displaying the
5481 new command line preceded by
5477 new command line preceded by
5482 \family typewriter
5478 \family typewriter
5483 -->
5479 -->
5484 \family default
5480 \family default
5485 .
5481 .
5486 e.g.:
5482 e.g.:
5487 \layout Standard
5483 \layout Standard
5488
5484
5489
5485
5490 \family typewriter
5486 \family typewriter
5491 In [18]: callable list
5487 In [18]: callable list
5492 \newline
5488 \newline
5493 -------> callable (list)
5489 -------> callable (list)
5494 \layout Subsubsection
5490 \layout Subsubsection
5495
5491
5496 Automatic quoting
5492 Automatic quoting
5497 \layout Standard
5493 \layout Standard
5498
5494
5499 You can force automatic quoting of a function's arguments by using
5495 You can force automatic quoting of a function's arguments by using
5500 \family typewriter
5496 \family typewriter
5501 `,'
5497 `,'
5502 \family default
5498 \family default
5503 or
5499 or
5504 \family typewriter
5500 \family typewriter
5505 `;'
5501 `;'
5506 \family default
5502 \family default
5507 as the first character of a line.
5503 as the first character of a line.
5508 For example:
5504 For example:
5509 \layout Standard
5505 \layout Standard
5510
5506
5511
5507
5512 \family typewriter
5508 \family typewriter
5513 >>> ,my_function /home/me # becomes my_function("/home/me")
5509 >>> ,my_function /home/me # becomes my_function("/home/me")
5514 \layout Standard
5510 \layout Standard
5515
5511
5516 If you use
5512 If you use
5517 \family typewriter
5513 \family typewriter
5518 `;'
5514 `;'
5519 \family default
5515 \family default
5520 instead, the whole argument is quoted as a single string (while
5516 instead, the whole argument is quoted as a single string (while
5521 \family typewriter
5517 \family typewriter
5522 `,'
5518 `,'
5523 \family default
5519 \family default
5524 splits on whitespace):
5520 splits on whitespace):
5525 \layout Standard
5521 \layout Standard
5526
5522
5527
5523
5528 \family typewriter
5524 \family typewriter
5529 >>> ,my_function a b c # becomes my_function("a","b","c")
5525 >>> ,my_function a b c # becomes my_function("a","b","c")
5530 \layout Standard
5526 \layout Standard
5531
5527
5532
5528
5533 \family typewriter
5529 \family typewriter
5534 >>> ;my_function a b c # becomes my_function("a b c")
5530 >>> ;my_function a b c # becomes my_function("a b c")
5535 \layout Standard
5531 \layout Standard
5536
5532
5537 Note that the `
5533 Note that the `
5538 \family typewriter
5534 \family typewriter
5539 ,
5535 ,
5540 \family default
5536 \family default
5541 ' or `
5537 ' or `
5542 \family typewriter
5538 \family typewriter
5543 ;
5539 ;
5544 \family default
5540 \family default
5545 ' MUST be the first character on the line! This won't work:
5541 ' MUST be the first character on the line! This won't work:
5546 \layout Standard
5542 \layout Standard
5547
5543
5548
5544
5549 \family typewriter
5545 \family typewriter
5550 >>> x = ,my_function /home/me # syntax error
5546 >>> x = ,my_function /home/me # syntax error
5551 \layout Section
5547 \layout Section
5552
5548
5553
5549
5554 \begin_inset LatexCommand \label{sec:customization}
5550 \begin_inset LatexCommand \label{sec:customization}
5555
5551
5556 \end_inset
5552 \end_inset
5557
5553
5558 Customization
5554 Customization
5559 \layout Standard
5555 \layout Standard
5560
5556
5561 As we've already mentioned, IPython reads a configuration file which can
5557 As we've already mentioned, IPython reads a configuration file which can
5562 be specified at the command line (
5558 be specified at the command line (
5563 \family typewriter
5559 \family typewriter
5564 -rcfile
5560 -rcfile
5565 \family default
5561 \family default
5566 ) or which by default is assumed to be called
5562 ) or which by default is assumed to be called
5567 \family typewriter
5563 \family typewriter
5568 ipythonrc
5564 ipythonrc
5569 \family default
5565 \family default
5570 .
5566 .
5571 Such a file is looked for in the current directory where IPython is started
5567 Such a file is looked for in the current directory where IPython is started
5572 and then in your
5568 and then in your
5573 \family typewriter
5569 \family typewriter
5574 IPYTHONDIR
5570 IPYTHONDIR
5575 \family default
5571 \family default
5576 , which allows you to have local configuration files for specific projects.
5572 , which allows you to have local configuration files for specific projects.
5577 In this section we will call these types of configuration files simply
5573 In this section we will call these types of configuration files simply
5578 rcfiles (short for resource configuration file).
5574 rcfiles (short for resource configuration file).
5579 \layout Standard
5575 \layout Standard
5580
5576
5581 The syntax of an rcfile is one of key-value pairs separated by whitespace,
5577 The syntax of an rcfile is one of key-value pairs separated by whitespace,
5582 one per line.
5578 one per line.
5583 Lines beginning with a
5579 Lines beginning with a
5584 \family typewriter
5580 \family typewriter
5585 #
5581 #
5586 \family default
5582 \family default
5587 are ignored as comments, but comments can
5583 are ignored as comments, but comments can
5588 \series bold
5584 \series bold
5589 not
5585 not
5590 \series default
5586 \series default
5591 be put on lines with data (the parser is fairly primitive).
5587 be put on lines with data (the parser is fairly primitive).
5592 Note that these are not python files, and this is deliberate, because it
5588 Note that these are not python files, and this is deliberate, because it
5593 allows us to do some things which would be quite tricky to implement if
5589 allows us to do some things which would be quite tricky to implement if
5594 they were normal python files.
5590 they were normal python files.
5595 \layout Standard
5591 \layout Standard
5596
5592
5597 First, an rcfile can contain permanent default values for almost all command
5593 First, an rcfile can contain permanent default values for almost all command
5598 line options (except things like
5594 line options (except things like
5599 \family typewriter
5595 \family typewriter
5600 -help
5596 -help
5601 \family default
5597 \family default
5602 or
5598 or
5603 \family typewriter
5599 \family typewriter
5604 -Version
5600 -Version
5605 \family default
5601 \family default
5606 ).
5602 ).
5607 Sec\SpecialChar ~
5603 Sec\SpecialChar ~
5608
5604
5609 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5605 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5610
5606
5611 \end_inset
5607 \end_inset
5612
5608
5613 contains a description of all command-line options.
5609 contains a description of all command-line options.
5614 However, values you explicitly specify at the command line override the
5610 However, values you explicitly specify at the command line override the
5615 values defined in the rcfile.
5611 values defined in the rcfile.
5616 \layout Standard
5612 \layout Standard
5617
5613
5618 Besides command line option values, the rcfile can specify values for certain
5614 Besides command line option values, the rcfile can specify values for certain
5619 extra special options which are not available at the command line.
5615 extra special options which are not available at the command line.
5620 These options are briefly described below.
5616 These options are briefly described below.
5621
5617
5622 \layout Standard
5618 \layout Standard
5623
5619
5624 Each of these options may appear as many times as you need it in the file.
5620 Each of these options may appear as many times as you need it in the file.
5625 \layout List
5621 \layout List
5626 \labelwidthstring 00.00.0000
5622 \labelwidthstring 00.00.0000
5627
5623
5628
5624
5629 \family typewriter
5625 \family typewriter
5630 \series bold
5626 \series bold
5631 include\SpecialChar ~
5627 include\SpecialChar ~
5632 <file1>\SpecialChar ~
5628 <file1>\SpecialChar ~
5633 <file2>\SpecialChar ~
5629 <file2>\SpecialChar ~
5634 ...
5630 ...
5635 \family default
5631 \family default
5636 \series default
5632 \series default
5637 : you can name
5633 : you can name
5638 \emph on
5634 \emph on
5639 other
5635 other
5640 \emph default
5636 \emph default
5641 rcfiles you want to recursively load up to 15 levels (don't use the
5637 rcfiles you want to recursively load up to 15 levels (don't use the
5642 \family typewriter
5638 \family typewriter
5643 <>
5639 <>
5644 \family default
5640 \family default
5645 brackets in your names!).
5641 brackets in your names!).
5646 This feature allows you to define a 'base' rcfile with general options
5642 This feature allows you to define a 'base' rcfile with general options
5647 and special-purpose files which can be loaded only when needed with particular
5643 and special-purpose files which can be loaded only when needed with particular
5648 configuration options.
5644 configuration options.
5649 To make this more convenient, IPython accepts the
5645 To make this more convenient, IPython accepts the
5650 \family typewriter
5646 \family typewriter
5651 -profile <name>
5647 -profile <name>
5652 \family default
5648 \family default
5653 option (abbreviates to
5649 option (abbreviates to
5654 \family typewriter
5650 \family typewriter
5655 -p <name
5651 -p <name
5656 \family default
5652 \family default
5657 >)
5653 >)
5658 \family typewriter
5654 \family typewriter
5659 which
5655 which
5660 \family default
5656 \family default
5661 tells it to look for an rcfile named
5657 tells it to look for an rcfile named
5662 \family typewriter
5658 \family typewriter
5663 ipythonrc-<name>
5659 ipythonrc-<name>
5664 \family default
5660 \family default
5665 .
5661 .
5666
5662
5667 \layout List
5663 \layout List
5668 \labelwidthstring 00.00.0000
5664 \labelwidthstring 00.00.0000
5669
5665
5670
5666
5671 \family typewriter
5667 \family typewriter
5672 \series bold
5668 \series bold
5673 import_mod\SpecialChar ~
5669 import_mod\SpecialChar ~
5674 <mod1>\SpecialChar ~
5670 <mod1>\SpecialChar ~
5675 <mod2>\SpecialChar ~
5671 <mod2>\SpecialChar ~
5676 ...
5672 ...
5677 \family default
5673 \family default
5678 \series default
5674 \series default
5679 : import modules with '
5675 : import modules with '
5680 \family typewriter
5676 \family typewriter
5681 import
5677 import
5682 \family default
5678 \family default
5683
5679
5684 \family typewriter
5680 \family typewriter
5685 <mod1>,<mod2>,...
5681 <mod1>,<mod2>,...
5686 \family default
5682 \family default
5687 '
5683 '
5688 \layout List
5684 \layout List
5689 \labelwidthstring 00.00.0000
5685 \labelwidthstring 00.00.0000
5690
5686
5691
5687
5692 \family typewriter
5688 \family typewriter
5693 \series bold
5689 \series bold
5694 import_some\SpecialChar ~
5690 import_some\SpecialChar ~
5695 <mod>\SpecialChar ~
5691 <mod>\SpecialChar ~
5696 <f1>\SpecialChar ~
5692 <f1>\SpecialChar ~
5697 <f2>\SpecialChar ~
5693 <f2>\SpecialChar ~
5698 ...
5694 ...
5699 \family default
5695 \family default
5700 \series default
5696 \series default
5701 : import functions with '
5697 : import functions with '
5702 \family typewriter
5698 \family typewriter
5703 from <mod> import
5699 from <mod> import
5704 \family default
5700 \family default
5705
5701
5706 \family typewriter
5702 \family typewriter
5707 <f1>,<f2>,...
5703 <f1>,<f2>,...
5708 \family default
5704 \family default
5709 '
5705 '
5710 \layout List
5706 \layout List
5711 \labelwidthstring 00.00.0000
5707 \labelwidthstring 00.00.0000
5712
5708
5713
5709
5714 \family typewriter
5710 \family typewriter
5715 \series bold
5711 \series bold
5716 import_all\SpecialChar ~
5712 import_all\SpecialChar ~
5717 <mod1>\SpecialChar ~
5713 <mod1>\SpecialChar ~
5718 <mod2>\SpecialChar ~
5714 <mod2>\SpecialChar ~
5719 ...
5715 ...
5720 \family default
5716 \family default
5721 \series default
5717 \series default
5722 : for each module listed import functions with '
5718 : for each module listed import functions with '
5723 \family typewriter
5719 \family typewriter
5724 from <mod> import *
5720 from <mod> import *
5725 \family default
5721 \family default
5726 '
5722 '
5727 \layout List
5723 \layout List
5728 \labelwidthstring 00.00.0000
5724 \labelwidthstring 00.00.0000
5729
5725
5730
5726
5731 \family typewriter
5727 \family typewriter
5732 \series bold
5728 \series bold
5733 execute\SpecialChar ~
5729 execute\SpecialChar ~
5734 <python\SpecialChar ~
5730 <python\SpecialChar ~
5735 code>
5731 code>
5736 \family default
5732 \family default
5737 \series default
5733 \series default
5738 : give any single-line python code to be executed.
5734 : give any single-line python code to be executed.
5739 \layout List
5735 \layout List
5740 \labelwidthstring 00.00.0000
5736 \labelwidthstring 00.00.0000
5741
5737
5742
5738
5743 \family typewriter
5739 \family typewriter
5744 \series bold
5740 \series bold
5745 execfile\SpecialChar ~
5741 execfile\SpecialChar ~
5746 <filename>
5742 <filename>
5747 \family default
5743 \family default
5748 \series default
5744 \series default
5749 : execute the python file given with an '
5745 : execute the python file given with an '
5750 \family typewriter
5746 \family typewriter
5751 execfile(filename)
5747 execfile(filename)
5752 \family default
5748 \family default
5753 ' command.
5749 ' command.
5754 Username expansion is performed on the given names.
5750 Username expansion is performed on the given names.
5755 So if you need any amount of extra fancy customization that won't fit in
5751 So if you need any amount of extra fancy customization that won't fit in
5756 any of the above 'canned' options, you can just put it in a separate python
5752 any of the above 'canned' options, you can just put it in a separate python
5757 file and execute it.
5753 file and execute it.
5758 \layout List
5754 \layout List
5759 \labelwidthstring 00.00.0000
5755 \labelwidthstring 00.00.0000
5760
5756
5761
5757
5762 \family typewriter
5758 \family typewriter
5763 \series bold
5759 \series bold
5764 alias\SpecialChar ~
5760 alias\SpecialChar ~
5765 <alias_def>
5761 <alias_def>
5766 \family default
5762 \family default
5767 \series default
5763 \series default
5768 : this is equivalent to calling '
5764 : this is equivalent to calling '
5769 \family typewriter
5765 \family typewriter
5770 %alias\SpecialChar ~
5766 %alias\SpecialChar ~
5771 <alias_def>
5767 <alias_def>
5772 \family default
5768 \family default
5773 ' at the IPython command line.
5769 ' at the IPython command line.
5774 This way, from within IPython you can do common system tasks without having
5770 This way, from within IPython you can do common system tasks without having
5775 to exit it or use the
5771 to exit it or use the
5776 \family typewriter
5772 \family typewriter
5777 !
5773 !
5778 \family default
5774 \family default
5779 escape.
5775 escape.
5780 IPython isn't meant to be a shell replacement, but it is often very useful
5776 IPython isn't meant to be a shell replacement, but it is often very useful
5781 to be able to do things with files while testing code.
5777 to be able to do things with files while testing code.
5782 This gives you the flexibility to have within IPython any aliases you may
5778 This gives you the flexibility to have within IPython any aliases you may
5783 be used to under your normal system shell.
5779 be used to under your normal system shell.
5784 \layout Subsection
5780 \layout Subsection
5785
5781
5786
5782
5787 \begin_inset LatexCommand \label{sec:ipytonrc-sample}
5783 \begin_inset LatexCommand \label{sec:ipytonrc-sample}
5788
5784
5789 \end_inset
5785 \end_inset
5790
5786
5791 Sample
5787 Sample
5792 \family typewriter
5788 \family typewriter
5793 ipythonrc
5789 ipythonrc
5794 \family default
5790 \family default
5795 file
5791 file
5796 \layout Standard
5792 \layout Standard
5797
5793
5798 The default rcfile, called
5794 The default rcfile, called
5799 \family typewriter
5795 \family typewriter
5800 ipythonrc
5796 ipythonrc
5801 \family default
5797 \family default
5802 and supplied in your
5798 and supplied in your
5803 \family typewriter
5799 \family typewriter
5804 IPYTHONDIR
5800 IPYTHONDIR
5805 \family default
5801 \family default
5806 directory contains lots of comments on all of these options.
5802 directory contains lots of comments on all of these options.
5807 We reproduce it here for reference:
5803 We reproduce it here for reference:
5808 \layout Standard
5804 \layout Standard
5809
5805
5810
5806
5811 \begin_inset ERT
5807 \begin_inset ERT
5812 status Open
5808 status Open
5813
5809
5814 \layout Standard
5810 \layout Standard
5815
5811
5816 \backslash
5812 \backslash
5817 codelist{../IPython/UserConfig/ipythonrc}
5813 codelist{../IPython/UserConfig/ipythonrc}
5818 \end_inset
5814 \end_inset
5819
5815
5820
5816
5821 \layout Subsection
5817 \layout Subsection
5822
5818
5823
5819
5824 \begin_inset LatexCommand \label{sec:prompts}
5820 \begin_inset LatexCommand \label{sec:prompts}
5825
5821
5826 \end_inset
5822 \end_inset
5827
5823
5828 Fine-tuning your prompt
5824 Fine-tuning your prompt
5829 \layout Standard
5825 \layout Standard
5830
5826
5831 IPython's prompts can be customized using a syntax similar to that of the
5827 IPython's prompts can be customized using a syntax similar to that of the
5832
5828
5833 \family typewriter
5829 \family typewriter
5834 bash
5830 bash
5835 \family default
5831 \family default
5836 shell.
5832 shell.
5837 Many of
5833 Many of
5838 \family typewriter
5834 \family typewriter
5839 bash
5835 bash
5840 \family default
5836 \family default
5841 's escapes are supported, as well as a few additional ones.
5837 's escapes are supported, as well as a few additional ones.
5842 We list them below:
5838 We list them below:
5843 \layout Description
5839 \layout Description
5844
5840
5845
5841
5846 \backslash
5842 \backslash
5847 # the prompt/history count number
5843 # the prompt/history count number
5848 \layout Description
5844 \layout Description
5849
5845
5850
5846
5851 \backslash
5847 \backslash
5852 D the prompt/history count, with the actual digits replaced by dots.
5848 D the prompt/history count, with the actual digits replaced by dots.
5853 Used mainly in continuation prompts (prompt_in2)
5849 Used mainly in continuation prompts (prompt_in2)
5854 \layout Description
5850 \layout Description
5855
5851
5856
5852
5857 \backslash
5853 \backslash
5858 w the current working directory
5854 w the current working directory
5859 \layout Description
5855 \layout Description
5860
5856
5861
5857
5862 \backslash
5858 \backslash
5863 W the basename of current working directory
5859 W the basename of current working directory
5864 \layout Description
5860 \layout Description
5865
5861
5866
5862
5867 \backslash
5863 \backslash
5868 X
5864 X
5869 \emph on
5865 \emph on
5870 n
5866 n
5871 \emph default
5867 \emph default
5872 where
5868 where
5873 \begin_inset Formula $n=0\ldots5.$
5869 \begin_inset Formula $n=0\ldots5.$
5874 \end_inset
5870 \end_inset
5875
5871
5876 The current working directory, with
5872 The current working directory, with
5877 \family typewriter
5873 \family typewriter
5878 $HOME
5874 $HOME
5879 \family default
5875 \family default
5880 replaced by
5876 replaced by
5881 \family typewriter
5877 \family typewriter
5882 ~
5878 ~
5883 \family default
5879 \family default
5884 , and filtered out to contain only
5880 , and filtered out to contain only
5885 \begin_inset Formula $n$
5881 \begin_inset Formula $n$
5886 \end_inset
5882 \end_inset
5887
5883
5888 path elements
5884 path elements
5889 \layout Description
5885 \layout Description
5890
5886
5891
5887
5892 \backslash
5888 \backslash
5893 Y
5889 Y
5894 \emph on
5890 \emph on
5895 n
5891 n
5896 \emph default
5892 \emph default
5897 Similar to
5893 Similar to
5898 \backslash
5894 \backslash
5899 X
5895 X
5900 \emph on
5896 \emph on
5901 n
5897 n
5902 \emph default
5898 \emph default
5903 , but with the
5899 , but with the
5904 \begin_inset Formula $n+1$
5900 \begin_inset Formula $n+1$
5905 \end_inset
5901 \end_inset
5906
5902
5907 element included if it is
5903 element included if it is
5908 \family typewriter
5904 \family typewriter
5909 ~
5905 ~
5910 \family default
5906 \family default
5911 (this is similar to the behavior of the %c
5907 (this is similar to the behavior of the %c
5912 \emph on
5908 \emph on
5913 n
5909 n
5914 \emph default
5910 \emph default
5915 escapes in
5911 escapes in
5916 \family typewriter
5912 \family typewriter
5917 tcsh
5913 tcsh
5918 \family default
5914 \family default
5919 )
5915 )
5920 \layout Description
5916 \layout Description
5921
5917
5922
5918
5923 \backslash
5919 \backslash
5924 u the username of the current user
5920 u the username of the current user
5925 \layout Description
5921 \layout Description
5926
5922
5927
5923
5928 \backslash
5924 \backslash
5929 $ if the effective UID is 0, a #, otherwise a $
5925 $ if the effective UID is 0, a #, otherwise a $
5930 \layout Description
5926 \layout Description
5931
5927
5932
5928
5933 \backslash
5929 \backslash
5934 h the hostname up to the first `.'
5930 h the hostname up to the first `.'
5935 \layout Description
5931 \layout Description
5936
5932
5937
5933
5938 \backslash
5934 \backslash
5939 H the hostname
5935 H the hostname
5940 \layout Description
5936 \layout Description
5941
5937
5942
5938
5943 \backslash
5939 \backslash
5944 n a newline
5940 n a newline
5945 \layout Description
5941 \layout Description
5946
5942
5947
5943
5948 \backslash
5944 \backslash
5949 r a carriage return
5945 r a carriage return
5950 \layout Description
5946 \layout Description
5951
5947
5952
5948
5953 \backslash
5949 \backslash
5954 v IPython version string
5950 v IPython version string
5955 \layout Standard
5951 \layout Standard
5956
5952
5957 In addition to these, ANSI color escapes can be insterted into the prompts,
5953 In addition to these, ANSI color escapes can be insterted into the prompts,
5958 as
5954 as
5959 \family typewriter
5955 \family typewriter
5960
5956
5961 \backslash
5957 \backslash
5962 C_
5958 C_
5963 \emph on
5959 \emph on
5964 ColorName
5960 ColorName
5965 \family default
5961 \family default
5966 \emph default
5962 \emph default
5967 .
5963 .
5968 The list of valid color names is: Black, Blue, Brown, Cyan, DarkGray, Green,
5964 The list of valid color names is: Black, Blue, Brown, Cyan, DarkGray, Green,
5969 LightBlue, LightCyan, LightGray, LightGreen, LightPurple, LightRed, NoColor,
5965 LightBlue, LightCyan, LightGray, LightGreen, LightPurple, LightRed, NoColor,
5970 Normal, Purple, Red, White, Yellow.
5966 Normal, Purple, Red, White, Yellow.
5971 \layout Standard
5967 \layout Standard
5972
5968
5973 Finally, IPython supports the evaluation of arbitrary expressions in your
5969 Finally, IPython supports the evaluation of arbitrary expressions in your
5974 prompt string.
5970 prompt string.
5975 The prompt strings are evaluated through the syntax of PEP 215, but basically
5971 The prompt strings are evaluated through the syntax of PEP 215, but basically
5976 you can use
5972 you can use
5977 \family typewriter
5973 \family typewriter
5978 $x.y
5974 $x.y
5979 \family default
5975 \family default
5980 to expand the value of
5976 to expand the value of
5981 \family typewriter
5977 \family typewriter
5982 x.y
5978 x.y
5983 \family default
5979 \family default
5984 , and for more complicated expressions you can use braces:
5980 , and for more complicated expressions you can use braces:
5985 \family typewriter
5981 \family typewriter
5986 ${foo()+x}
5982 ${foo()+x}
5987 \family default
5983 \family default
5988 will call function
5984 will call function
5989 \family typewriter
5985 \family typewriter
5990 foo
5986 foo
5991 \family default
5987 \family default
5992 and add to it the value of
5988 and add to it the value of
5993 \family typewriter
5989 \family typewriter
5994 x
5990 x
5995 \family default
5991 \family default
5996 , before putting the result into your prompt.
5992 , before putting the result into your prompt.
5997 For example, using
5993 For example, using
5998 \newline
5994 \newline
5999
5995
6000 \family typewriter
5996 \family typewriter
6001 prompt_in1 '${commands.getoutput("uptime")}
5997 prompt_in1 '${commands.getoutput("uptime")}
6002 \backslash
5998 \backslash
6003 nIn [
5999 nIn [
6004 \backslash
6000 \backslash
6005 #]: '
6001 #]: '
6006 \newline
6002 \newline
6007
6003
6008 \family default
6004 \family default
6009 will print the result of the uptime command on each prompt (assuming the
6005 will print the result of the uptime command on each prompt (assuming the
6010
6006
6011 \family typewriter
6007 \family typewriter
6012 commands
6008 commands
6013 \family default
6009 \family default
6014 module has been imported in your
6010 module has been imported in your
6015 \family typewriter
6011 \family typewriter
6016 ipythonrc
6012 ipythonrc
6017 \family default
6013 \family default
6018 file).
6014 file).
6019 \layout Subsubsection
6015 \layout Subsubsection
6020
6016
6021 Prompt examples
6017 Prompt examples
6022 \layout Standard
6018 \layout Standard
6023
6019
6024 The following options in an ipythonrc file will give you IPython's default
6020 The following options in an ipythonrc file will give you IPython's default
6025 prompts:
6021 prompts:
6026 \layout Standard
6022 \layout Standard
6027
6023
6028
6024
6029 \family typewriter
6025 \family typewriter
6030 prompt_in1 'In [
6026 prompt_in1 'In [
6031 \backslash
6027 \backslash
6032 #]:'
6028 #]:'
6033 \newline
6029 \newline
6034 prompt_in2 '\SpecialChar ~
6030 prompt_in2 '\SpecialChar ~
6035 \SpecialChar ~
6031 \SpecialChar ~
6036 \SpecialChar ~
6032 \SpecialChar ~
6037 .
6033 .
6038 \backslash
6034 \backslash
6039 D.:'
6035 D.:'
6040 \newline
6036 \newline
6041 prompt_out 'Out[
6037 prompt_out 'Out[
6042 \backslash
6038 \backslash
6043 #]:'
6039 #]:'
6044 \layout Standard
6040 \layout Standard
6045
6041
6046 which look like this:
6042 which look like this:
6047 \layout Standard
6043 \layout Standard
6048
6044
6049
6045
6050 \family typewriter
6046 \family typewriter
6051 In [1]: 1+2
6047 In [1]: 1+2
6052 \newline
6048 \newline
6053 Out[1]: 3
6049 Out[1]: 3
6054 \layout Standard
6050 \layout Standard
6055
6051
6056
6052
6057 \family typewriter
6053 \family typewriter
6058 In [2]: for i in (1,2,3):
6054 In [2]: for i in (1,2,3):
6059 \newline
6055 \newline
6060
6056
6061 \begin_inset ERT
6057 \begin_inset ERT
6062 status Collapsed
6058 status Collapsed
6063
6059
6064 \layout Standard
6060 \layout Standard
6065
6061
6066 \backslash
6062 \backslash
6067 hspace*{0mm}
6063 hspace*{0mm}
6068 \end_inset
6064 \end_inset
6069
6065
6070 \SpecialChar ~
6066 \SpecialChar ~
6071 \SpecialChar ~
6067 \SpecialChar ~
6072 \SpecialChar ~
6068 \SpecialChar ~
6073 ...: \SpecialChar ~
6069 ...: \SpecialChar ~
6074 \SpecialChar ~
6070 \SpecialChar ~
6075 \SpecialChar ~
6071 \SpecialChar ~
6076 \SpecialChar ~
6072 \SpecialChar ~
6077 print i,
6073 print i,
6078 \newline
6074 \newline
6079
6075
6080 \begin_inset ERT
6076 \begin_inset ERT
6081 status Collapsed
6077 status Collapsed
6082
6078
6083 \layout Standard
6079 \layout Standard
6084
6080
6085 \backslash
6081 \backslash
6086 hspace*{0mm}
6082 hspace*{0mm}
6087 \end_inset
6083 \end_inset
6088
6084
6089 \SpecialChar ~
6085 \SpecialChar ~
6090 \SpecialChar ~
6086 \SpecialChar ~
6091 \SpecialChar ~
6087 \SpecialChar ~
6092 ...:
6088 ...:
6093 \newline
6089 \newline
6094 1 2 3
6090 1 2 3
6095 \layout Standard
6091 \layout Standard
6096
6092
6097 These will give you a very colorful prompt with path information:
6093 These will give you a very colorful prompt with path information:
6098 \layout Standard
6094 \layout Standard
6099
6095
6100
6096
6101 \family typewriter
6097 \family typewriter
6102 #prompt_in1 '
6098 #prompt_in1 '
6103 \backslash
6099 \backslash
6104 C_Red
6100 C_Red
6105 \backslash
6101 \backslash
6106 u
6102 u
6107 \backslash
6103 \backslash
6108 C_Blue[
6104 C_Blue[
6109 \backslash
6105 \backslash
6110 C_Cyan
6106 C_Cyan
6111 \backslash
6107 \backslash
6112 Y1
6108 Y1
6113 \backslash
6109 \backslash
6114 C_Blue]
6110 C_Blue]
6115 \backslash
6111 \backslash
6116 C_LightGreen
6112 C_LightGreen
6117 \backslash
6113 \backslash
6118 #>'
6114 #>'
6119 \newline
6115 \newline
6120 prompt_in2 ' ..
6116 prompt_in2 ' ..
6121 \backslash
6117 \backslash
6122 D>'
6118 D>'
6123 \newline
6119 \newline
6124 prompt_out '<
6120 prompt_out '<
6125 \backslash
6121 \backslash
6126 #>'
6122 #>'
6127 \layout Standard
6123 \layout Standard
6128
6124
6129 which look like this:
6125 which look like this:
6130 \layout Standard
6126 \layout Standard
6131
6127
6132
6128
6133 \family typewriter
6129 \family typewriter
6134 \color red
6130 \color red
6135 fperez
6131 fperez
6136 \color blue
6132 \color blue
6137 [
6133 [
6138 \color cyan
6134 \color cyan
6139 ~/ipython
6135 ~/ipython
6140 \color blue
6136 \color blue
6141 ]
6137 ]
6142 \color green
6138 \color green
6143 1>
6139 1>
6144 \color default
6140 \color default
6145 1+2
6141 1+2
6146 \newline
6142 \newline
6147
6143
6148 \begin_inset ERT
6144 \begin_inset ERT
6149 status Collapsed
6145 status Collapsed
6150
6146
6151 \layout Standard
6147 \layout Standard
6152
6148
6153 \backslash
6149 \backslash
6154 hspace*{0mm}
6150 hspace*{0mm}
6155 \end_inset
6151 \end_inset
6156
6152
6157 \SpecialChar ~
6153 \SpecialChar ~
6158 \SpecialChar ~
6154 \SpecialChar ~
6159 \SpecialChar ~
6155 \SpecialChar ~
6160 \SpecialChar ~
6156 \SpecialChar ~
6161 \SpecialChar ~
6157 \SpecialChar ~
6162 \SpecialChar ~
6158 \SpecialChar ~
6163 \SpecialChar ~
6159 \SpecialChar ~
6164 \SpecialChar ~
6160 \SpecialChar ~
6165 \SpecialChar ~
6161 \SpecialChar ~
6166 \SpecialChar ~
6162 \SpecialChar ~
6167 \SpecialChar ~
6163 \SpecialChar ~
6168 \SpecialChar ~
6164 \SpecialChar ~
6169 \SpecialChar ~
6165 \SpecialChar ~
6170 \SpecialChar ~
6166 \SpecialChar ~
6171 \SpecialChar ~
6167 \SpecialChar ~
6172 \SpecialChar ~
6168 \SpecialChar ~
6173
6169
6174 \color red
6170 \color red
6175 <1>
6171 <1>
6176 \color default
6172 \color default
6177 3
6173 3
6178 \newline
6174 \newline
6179
6175
6180 \color red
6176 \color red
6181 fperez
6177 fperez
6182 \color blue
6178 \color blue
6183 [
6179 [
6184 \color cyan
6180 \color cyan
6185 ~/ipython
6181 ~/ipython
6186 \color blue
6182 \color blue
6187 ]
6183 ]
6188 \color green
6184 \color green
6189 2>
6185 2>
6190 \color default
6186 \color default
6191 for i in (1,2,3):
6187 for i in (1,2,3):
6192 \newline
6188 \newline
6193
6189
6194 \begin_inset ERT
6190 \begin_inset ERT
6195 status Collapsed
6191 status Collapsed
6196
6192
6197 \layout Standard
6193 \layout Standard
6198
6194
6199 \backslash
6195 \backslash
6200 hspace*{0mm}
6196 hspace*{0mm}
6201 \end_inset
6197 \end_inset
6202
6198
6203 \SpecialChar ~
6199 \SpecialChar ~
6204 \SpecialChar ~
6200 \SpecialChar ~
6205 \SpecialChar ~
6201 \SpecialChar ~
6206 \SpecialChar ~
6202 \SpecialChar ~
6207 \SpecialChar ~
6203 \SpecialChar ~
6208 \SpecialChar ~
6204 \SpecialChar ~
6209 \SpecialChar ~
6205 \SpecialChar ~
6210 \SpecialChar ~
6206 \SpecialChar ~
6211 \SpecialChar ~
6207 \SpecialChar ~
6212 \SpecialChar ~
6208 \SpecialChar ~
6213 \SpecialChar ~
6209 \SpecialChar ~
6214 \SpecialChar ~
6210 \SpecialChar ~
6215 \SpecialChar ~
6211 \SpecialChar ~
6216 \SpecialChar ~
6212 \SpecialChar ~
6217 \SpecialChar ~
6213 \SpecialChar ~
6218
6214
6219 \color green
6215 \color green
6220 ...>
6216 ...>
6221 \color default
6217 \color default
6222 \SpecialChar ~
6218 \SpecialChar ~
6223 \SpecialChar ~
6219 \SpecialChar ~
6224 \SpecialChar ~
6220 \SpecialChar ~
6225 \SpecialChar ~
6221 \SpecialChar ~
6226 print i,
6222 print i,
6227 \newline
6223 \newline
6228
6224
6229 \begin_inset ERT
6225 \begin_inset ERT
6230 status Collapsed
6226 status Collapsed
6231
6227
6232 \layout Standard
6228 \layout Standard
6233
6229
6234 \backslash
6230 \backslash
6235 hspace*{0mm}
6231 hspace*{0mm}
6236 \end_inset
6232 \end_inset
6237
6233
6238 \SpecialChar ~
6234 \SpecialChar ~
6239 \SpecialChar ~
6235 \SpecialChar ~
6240 \SpecialChar ~
6236 \SpecialChar ~
6241 \SpecialChar ~
6237 \SpecialChar ~
6242 \SpecialChar ~
6238 \SpecialChar ~
6243 \SpecialChar ~
6239 \SpecialChar ~
6244 \SpecialChar ~
6240 \SpecialChar ~
6245 \SpecialChar ~
6241 \SpecialChar ~
6246 \SpecialChar ~
6242 \SpecialChar ~
6247 \SpecialChar ~
6243 \SpecialChar ~
6248 \SpecialChar ~
6244 \SpecialChar ~
6249 \SpecialChar ~
6245 \SpecialChar ~
6250 \SpecialChar ~
6246 \SpecialChar ~
6251 \SpecialChar ~
6247 \SpecialChar ~
6252 \SpecialChar ~
6248 \SpecialChar ~
6253
6249
6254 \color green
6250 \color green
6255 ...>
6251 ...>
6256 \color default
6252 \color default
6257
6253
6258 \newline
6254 \newline
6259 1 2 3
6255 1 2 3
6260 \layout Standard
6256 \layout Standard
6261
6257
6262 The following shows the usage of dynamic expression evaluation:
6258 The following shows the usage of dynamic expression evaluation:
6263 \layout Subsection
6259 \layout Subsection
6264
6260
6265
6261
6266 \begin_inset LatexCommand \label{sec:profiles}
6262 \begin_inset LatexCommand \label{sec:profiles}
6267
6263
6268 \end_inset
6264 \end_inset
6269
6265
6270 IPython profiles
6266 IPython profiles
6271 \layout Standard
6267 \layout Standard
6272
6268
6273 As we already mentioned, IPython supports the
6269 As we already mentioned, IPython supports the
6274 \family typewriter
6270 \family typewriter
6275 -profile
6271 -profile
6276 \family default
6272 \family default
6277 command-line option (see sec.
6273 command-line option (see sec.
6278
6274
6279 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
6275 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
6280
6276
6281 \end_inset
6277 \end_inset
6282
6278
6283 ).
6279 ).
6284 A profile is nothing more than a particular configuration file like your
6280 A profile is nothing more than a particular configuration file like your
6285 basic
6281 basic
6286 \family typewriter
6282 \family typewriter
6287 ipythonrc
6283 ipythonrc
6288 \family default
6284 \family default
6289 one, but with particular customizations for a specific purpose.
6285 one, but with particular customizations for a specific purpose.
6290 When you start IPython with '
6286 When you start IPython with '
6291 \family typewriter
6287 \family typewriter
6292 ipython -profile <name>
6288 ipython -profile <name>
6293 \family default
6289 \family default
6294 ', it assumes that in your
6290 ', it assumes that in your
6295 \family typewriter
6291 \family typewriter
6296 IPYTHONDIR
6292 IPYTHONDIR
6297 \family default
6293 \family default
6298 there is a file called
6294 there is a file called
6299 \family typewriter
6295 \family typewriter
6300 ipythonrc-<name>
6296 ipythonrc-<name>
6301 \family default
6297 \family default
6302 , and loads it instead of the normal
6298 , and loads it instead of the normal
6303 \family typewriter
6299 \family typewriter
6304 ipythonrc
6300 ipythonrc
6305 \family default
6301 \family default
6306 .
6302 .
6307 \layout Standard
6303 \layout Standard
6308
6304
6309 This system allows you to maintain multiple configurations which load modules,
6305 This system allows you to maintain multiple configurations which load modules,
6310 set options, define functions, etc.
6306 set options, define functions, etc.
6311 suitable for different tasks and activate them in a very simple manner.
6307 suitable for different tasks and activate them in a very simple manner.
6312 In order to avoid having to repeat all of your basic options (common things
6308 In order to avoid having to repeat all of your basic options (common things
6313 that don't change such as your color preferences, for example), any profile
6309 that don't change such as your color preferences, for example), any profile
6314 can include another configuration file.
6310 can include another configuration file.
6315 The most common way to use profiles is then to have each one include your
6311 The most common way to use profiles is then to have each one include your
6316 basic
6312 basic
6317 \family typewriter
6313 \family typewriter
6318 ipythonrc
6314 ipythonrc
6319 \family default
6315 \family default
6320 file as a starting point, and then add further customizations.
6316 file as a starting point, and then add further customizations.
6321 \layout Standard
6317 \layout Standard
6322
6318
6323 In sections
6319 In sections
6324 \begin_inset LatexCommand \ref{sec:syntax-extensions}
6320 \begin_inset LatexCommand \ref{sec:syntax-extensions}
6325
6321
6326 \end_inset
6322 \end_inset
6327
6323
6328 and
6324 and
6329 \begin_inset LatexCommand \ref{sec:Gnuplot}
6325 \begin_inset LatexCommand \ref{sec:Gnuplot}
6330
6326
6331 \end_inset
6327 \end_inset
6332
6328
6333 we discuss some particular profiles which come as part of the standard
6329 we discuss some particular profiles which come as part of the standard
6334 IPython distribution.
6330 IPython distribution.
6335 You may also look in your
6331 You may also look in your
6336 \family typewriter
6332 \family typewriter
6337 IPYTHONDIR
6333 IPYTHONDIR
6338 \family default
6334 \family default
6339 directory, any file whose name begins with
6335 directory, any file whose name begins with
6340 \family typewriter
6336 \family typewriter
6341 ipythonrc-
6337 ipythonrc-
6342 \family default
6338 \family default
6343 is a profile.
6339 is a profile.
6344 You can use those as examples for further customizations to suit your own
6340 You can use those as examples for further customizations to suit your own
6345 needs.
6341 needs.
6346 \layout Section
6342 \layout Section
6347
6343
6348
6344
6349 \begin_inset OptArg
6345 \begin_inset OptArg
6350 collapsed false
6346 collapsed false
6351
6347
6352 \layout Standard
6348 \layout Standard
6353
6349
6354 IPython as default...
6350 IPython as default...
6355 \end_inset
6351 \end_inset
6356
6352
6357 IPython as your default Python environment
6353 IPython as your default Python environment
6358 \layout Standard
6354 \layout Standard
6359
6355
6360 Python honors the environment variable
6356 Python honors the environment variable
6361 \family typewriter
6357 \family typewriter
6362 PYTHONSTARTUP
6358 PYTHONSTARTUP
6363 \family default
6359 \family default
6364 and will execute at startup the file referenced by this variable.
6360 and will execute at startup the file referenced by this variable.
6365 If you put at the end of this file the following two lines of code:
6361 If you put at the end of this file the following two lines of code:
6366 \layout Standard
6362 \layout Standard
6367
6363
6368
6364
6369 \family typewriter
6365 \family typewriter
6370 import IPython
6366 import IPython
6371 \newline
6367 \newline
6372 IPython.Shell.IPShell().mainloop(sys_exit=1)
6368 IPython.Shell.IPShell().mainloop(sys_exit=1)
6373 \layout Standard
6369 \layout Standard
6374
6370
6375 then IPython will be your working environment anytime you start Python.
6371 then IPython will be your working environment anytime you start Python.
6376 The
6372 The
6377 \family typewriter
6373 \family typewriter
6378 sys_exit=1
6374 sys_exit=1
6379 \family default
6375 \family default
6380 is needed to have IPython issue a call to
6376 is needed to have IPython issue a call to
6381 \family typewriter
6377 \family typewriter
6382 sys.exit()
6378 sys.exit()
6383 \family default
6379 \family default
6384 when it finishes, otherwise you'll be back at the normal Python '
6380 when it finishes, otherwise you'll be back at the normal Python '
6385 \family typewriter
6381 \family typewriter
6386 >>>
6382 >>>
6387 \family default
6383 \family default
6388 ' prompt
6384 ' prompt
6389 \begin_inset Foot
6385 \begin_inset Foot
6390 collapsed true
6386 collapsed true
6391
6387
6392 \layout Standard
6388 \layout Standard
6393
6389
6394 Based on an idea by Holger Krekel.
6390 Based on an idea by Holger Krekel.
6395 \end_inset
6391 \end_inset
6396
6392
6397 .
6393 .
6398 \layout Standard
6394 \layout Standard
6399
6395
6400 This is probably useful to developers who manage multiple Python versions
6396 This is probably useful to developers who manage multiple Python versions
6401 and don't want to have correspondingly multiple IPython versions.
6397 and don't want to have correspondingly multiple IPython versions.
6402 Note that in this mode, there is no way to pass IPython any command-line
6398 Note that in this mode, there is no way to pass IPython any command-line
6403 options, as those are trapped first by Python itself.
6399 options, as those are trapped first by Python itself.
6404 \layout Section
6400 \layout Section
6405
6401
6406
6402
6407 \begin_inset LatexCommand \label{sec:embed}
6403 \begin_inset LatexCommand \label{sec:embed}
6408
6404
6409 \end_inset
6405 \end_inset
6410
6406
6411 Embedding IPython
6407 Embedding IPython
6412 \layout Standard
6408 \layout Standard
6413
6409
6414 It is possible to start an IPython instance
6410 It is possible to start an IPython instance
6415 \emph on
6411 \emph on
6416 inside
6412 inside
6417 \emph default
6413 \emph default
6418 your own Python programs.
6414 your own Python programs.
6419 This allows you to evaluate dynamically the state of your code, operate
6415 This allows you to evaluate dynamically the state of your code, operate
6420 with your variables, analyze them, etc.
6416 with your variables, analyze them, etc.
6421 Note however that any changes you make to values while in the shell do
6417 Note however that any changes you make to values while in the shell do
6422
6418
6423 \emph on
6419 \emph on
6424 not
6420 not
6425 \emph default
6421 \emph default
6426 propagate back to the running code, so it is safe to modify your values
6422 propagate back to the running code, so it is safe to modify your values
6427 because you won't break your code in bizarre ways by doing so.
6423 because you won't break your code in bizarre ways by doing so.
6428 \layout Standard
6424 \layout Standard
6429
6425
6430 This feature allows you to easily have a fully functional python environment
6426 This feature allows you to easily have a fully functional python environment
6431 for doing object introspection anywhere in your code with a simple function
6427 for doing object introspection anywhere in your code with a simple function
6432 call.
6428 call.
6433 In some cases a simple print statement is enough, but if you need to do
6429 In some cases a simple print statement is enough, but if you need to do
6434 more detailed analysis of a code fragment this feature can be very valuable.
6430 more detailed analysis of a code fragment this feature can be very valuable.
6435 \layout Standard
6431 \layout Standard
6436
6432
6437 It can also be useful in scientific computing situations where it is common
6433 It can also be useful in scientific computing situations where it is common
6438 to need to do some automatic, computationally intensive part and then stop
6434 to need to do some automatic, computationally intensive part and then stop
6439 to look at data, plots, etc
6435 to look at data, plots, etc
6440 \begin_inset Foot
6436 \begin_inset Foot
6441 collapsed true
6437 collapsed true
6442
6438
6443 \layout Standard
6439 \layout Standard
6444
6440
6445 This functionality was inspired by IDL's combination of the
6441 This functionality was inspired by IDL's combination of the
6446 \family typewriter
6442 \family typewriter
6447 stop
6443 stop
6448 \family default
6444 \family default
6449 keyword and the
6445 keyword and the
6450 \family typewriter
6446 \family typewriter
6451 .continue
6447 .continue
6452 \family default
6448 \family default
6453 executive command, which I have found very useful in the past, and by a
6449 executive command, which I have found very useful in the past, and by a
6454 posting on comp.lang.python by cmkl <cmkleffner-AT-gmx.de> on Dec.
6450 posting on comp.lang.python by cmkl <cmkleffner-AT-gmx.de> on Dec.
6455 06/01 concerning similar uses of pyrepl.
6451 06/01 concerning similar uses of pyrepl.
6456 \end_inset
6452 \end_inset
6457
6453
6458 .
6454 .
6459 Opening an IPython instance will give you full access to your data and
6455 Opening an IPython instance will give you full access to your data and
6460 functions, and you can resume program execution once you are done with
6456 functions, and you can resume program execution once you are done with
6461 the interactive part (perhaps to stop again later, as many times as needed).
6457 the interactive part (perhaps to stop again later, as many times as needed).
6462 \layout Standard
6458 \layout Standard
6463
6459
6464 The following code snippet is the bare minimum you need to include in your
6460 The following code snippet is the bare minimum you need to include in your
6465 Python programs for this to work (detailed examples follow later):
6461 Python programs for this to work (detailed examples follow later):
6466 \layout LyX-Code
6462 \layout LyX-Code
6467
6463
6468 from IPython.Shell import IPShellEmbed
6464 from IPython.Shell import IPShellEmbed
6469 \layout LyX-Code
6465 \layout LyX-Code
6470
6466
6471 ipshell = IPShellEmbed()
6467 ipshell = IPShellEmbed()
6472 \layout LyX-Code
6468 \layout LyX-Code
6473
6469
6474 ipshell() # this call anywhere in your program will start IPython
6470 ipshell() # this call anywhere in your program will start IPython
6475 \layout Standard
6471 \layout Standard
6476
6472
6477 You can run embedded instances even in code which is itself being run at
6473 You can run embedded instances even in code which is itself being run at
6478 the IPython interactive prompt with '
6474 the IPython interactive prompt with '
6479 \family typewriter
6475 \family typewriter
6480 %run\SpecialChar ~
6476 %run\SpecialChar ~
6481 <filename>
6477 <filename>
6482 \family default
6478 \family default
6483 '.
6479 '.
6484 Since it's easy to get lost as to where you are (in your top-level IPython
6480 Since it's easy to get lost as to where you are (in your top-level IPython
6485 or in your embedded one), it's a good idea in such cases to set the in/out
6481 or in your embedded one), it's a good idea in such cases to set the in/out
6486 prompts to something different for the embedded instances.
6482 prompts to something different for the embedded instances.
6487 The code examples below illustrate this.
6483 The code examples below illustrate this.
6488 \layout Standard
6484 \layout Standard
6489
6485
6490 You can also have multiple IPython instances in your program and open them
6486 You can also have multiple IPython instances in your program and open them
6491 separately, for example with different options for data presentation.
6487 separately, for example with different options for data presentation.
6492 If you close and open the same instance multiple times, its prompt counters
6488 If you close and open the same instance multiple times, its prompt counters
6493 simply continue from each execution to the next.
6489 simply continue from each execution to the next.
6494 \layout Standard
6490 \layout Standard
6495
6491
6496 Please look at the docstrings in the
6492 Please look at the docstrings in the
6497 \family typewriter
6493 \family typewriter
6498 Shell.py
6494 Shell.py
6499 \family default
6495 \family default
6500 module for more details on the use of this system.
6496 module for more details on the use of this system.
6501 \layout Standard
6497 \layout Standard
6502
6498
6503 The following sample file illustrating how to use the embedding functionality
6499 The following sample file illustrating how to use the embedding functionality
6504 is provided in the examples directory as
6500 is provided in the examples directory as
6505 \family typewriter
6501 \family typewriter
6506 example-embed.py
6502 example-embed.py
6507 \family default
6503 \family default
6508 .
6504 .
6509 It should be fairly self-explanatory:
6505 It should be fairly self-explanatory:
6510 \layout Standard
6506 \layout Standard
6511
6507
6512
6508
6513 \begin_inset ERT
6509 \begin_inset ERT
6514 status Open
6510 status Open
6515
6511
6516 \layout Standard
6512 \layout Standard
6517
6513
6518 \backslash
6514 \backslash
6519 codelist{examples/example-embed.py}
6515 codelist{examples/example-embed.py}
6520 \end_inset
6516 \end_inset
6521
6517
6522
6518
6523 \layout Standard
6519 \layout Standard
6524
6520
6525 Once you understand how the system functions, you can use the following
6521 Once you understand how the system functions, you can use the following
6526 code fragments in your programs which are ready for cut and paste:
6522 code fragments in your programs which are ready for cut and paste:
6527 \layout Standard
6523 \layout Standard
6528
6524
6529
6525
6530 \begin_inset ERT
6526 \begin_inset ERT
6531 status Open
6527 status Open
6532
6528
6533 \layout Standard
6529 \layout Standard
6534
6530
6535 \backslash
6531 \backslash
6536 codelist{examples/example-embed-short.py}
6532 codelist{examples/example-embed-short.py}
6537 \end_inset
6533 \end_inset
6538
6534
6539
6535
6540 \layout Section
6536 \layout Section
6541
6537
6542
6538
6543 \begin_inset LatexCommand \label{sec:using-pdb}
6539 \begin_inset LatexCommand \label{sec:using-pdb}
6544
6540
6545 \end_inset
6541 \end_inset
6546
6542
6547 Using the Python debugger (
6543 Using the Python debugger (
6548 \family typewriter
6544 \family typewriter
6549 pdb
6545 pdb
6550 \family default
6546 \family default
6551 )
6547 )
6552 \layout Subsection
6548 \layout Subsection
6553
6549
6554 Running entire programs via
6550 Running entire programs via
6555 \family typewriter
6551 \family typewriter
6556 pdb
6552 pdb
6557 \layout Standard
6553 \layout Standard
6558
6554
6559
6555
6560 \family typewriter
6556 \family typewriter
6561 pdb
6557 pdb
6562 \family default
6558 \family default
6563 , the Python debugger, is a powerful interactive debugger which allows you
6559 , the Python debugger, is a powerful interactive debugger which allows you
6564 to step through code, set breakpoints, watch variables, etc.
6560 to step through code, set breakpoints, watch variables, etc.
6565 IPython makes it very easy to start any script under the control of
6561 IPython makes it very easy to start any script under the control of
6566 \family typewriter
6562 \family typewriter
6567 pdb
6563 pdb
6568 \family default
6564 \family default
6569 , regardless of whether you have wrapped it into a
6565 , regardless of whether you have wrapped it into a
6570 \family typewriter
6566 \family typewriter
6571 `main()'
6567 `main()'
6572 \family default
6568 \family default
6573 function or not.
6569 function or not.
6574 For this, simply type
6570 For this, simply type
6575 \family typewriter
6571 \family typewriter
6576 `%run -d myscript'
6572 `%run -d myscript'
6577 \family default
6573 \family default
6578 at an IPython prompt.
6574 at an IPython prompt.
6579 See the
6575 See the
6580 \family typewriter
6576 \family typewriter
6581 %run
6577 %run
6582 \family default
6578 \family default
6583 command's documentation (via
6579 command's documentation (via
6584 \family typewriter
6580 \family typewriter
6585 `%run?'
6581 `%run?'
6586 \family default
6582 \family default
6587 or in Sec.\SpecialChar ~
6583 or in Sec.\SpecialChar ~
6588
6584
6589 \begin_inset LatexCommand \ref{sec:magic}
6585 \begin_inset LatexCommand \ref{sec:magic}
6590
6586
6591 \end_inset
6587 \end_inset
6592
6588
6593 ) for more details, including how to control where
6589 ) for more details, including how to control where
6594 \family typewriter
6590 \family typewriter
6595 pdb
6591 pdb
6596 \family default
6592 \family default
6597 will stop execution first.
6593 will stop execution first.
6598 \layout Standard
6594 \layout Standard
6599
6595
6600 For more information on the use of the
6596 For more information on the use of the
6601 \family typewriter
6597 \family typewriter
6602 pdb
6598 pdb
6603 \family default
6599 \family default
6604 debugger, read the included
6600 debugger, read the included
6605 \family typewriter
6601 \family typewriter
6606 pdb.doc
6602 pdb.doc
6607 \family default
6603 \family default
6608 file (part of the standard Python distribution).
6604 file (part of the standard Python distribution).
6609 On a stock Linux system it is located at
6605 On a stock Linux system it is located at
6610 \family typewriter
6606 \family typewriter
6611 /usr/lib/python2.3/pdb.doc
6607 /usr/lib/python2.3/pdb.doc
6612 \family default
6608 \family default
6613 , but the easiest way to read it is by using the
6609 , but the easiest way to read it is by using the
6614 \family typewriter
6610 \family typewriter
6615 help()
6611 help()
6616 \family default
6612 \family default
6617 function of the
6613 function of the
6618 \family typewriter
6614 \family typewriter
6619 pdb
6615 pdb
6620 \family default
6616 \family default
6621 module as follows (in an IPython prompt):
6617 module as follows (in an IPython prompt):
6622 \layout Standard
6618 \layout Standard
6623
6619
6624
6620
6625 \family typewriter
6621 \family typewriter
6626 In [1]: import pdb
6622 In [1]: import pdb
6627 \newline
6623 \newline
6628 In [2]: pdb.help()
6624 In [2]: pdb.help()
6629 \layout Standard
6625 \layout Standard
6630
6626
6631 This will load the
6627 This will load the
6632 \family typewriter
6628 \family typewriter
6633 pdb.doc
6629 pdb.doc
6634 \family default
6630 \family default
6635 document in a file viewer for you automatically.
6631 document in a file viewer for you automatically.
6636 \layout Subsection
6632 \layout Subsection
6637
6633
6638 Automatic invocation of
6634 Automatic invocation of
6639 \family typewriter
6635 \family typewriter
6640 pdb
6636 pdb
6641 \family default
6637 \family default
6642 on exceptions
6638 on exceptions
6643 \layout Standard
6639 \layout Standard
6644
6640
6645 IPython, if started with the
6641 IPython, if started with the
6646 \family typewriter
6642 \family typewriter
6647 -pdb
6643 -pdb
6648 \family default
6644 \family default
6649 option (or if the option is set in your rc file) can call the Python
6645 option (or if the option is set in your rc file) can call the Python
6650 \family typewriter
6646 \family typewriter
6651 pdb
6647 pdb
6652 \family default
6648 \family default
6653 debugger every time your code triggers an uncaught exception
6649 debugger every time your code triggers an uncaught exception
6654 \begin_inset Foot
6650 \begin_inset Foot
6655 collapsed true
6651 collapsed true
6656
6652
6657 \layout Standard
6653 \layout Standard
6658
6654
6659 Many thanks to Christopher Hart for the request which prompted adding this
6655 Many thanks to Christopher Hart for the request which prompted adding this
6660 feature to IPython.
6656 feature to IPython.
6661 \end_inset
6657 \end_inset
6662
6658
6663 .
6659 .
6664 This feature can also be toggled at any time with the
6660 This feature can also be toggled at any time with the
6665 \family typewriter
6661 \family typewriter
6666 %pdb
6662 %pdb
6667 \family default
6663 \family default
6668 magic command.
6664 magic command.
6669 This can be extremely useful in order to find the origin of subtle bugs,
6665 This can be extremely useful in order to find the origin of subtle bugs,
6670 because
6666 because
6671 \family typewriter
6667 \family typewriter
6672 pdb
6668 pdb
6673 \family default
6669 \family default
6674 opens up at the point in your code which triggered the exception, and while
6670 opens up at the point in your code which triggered the exception, and while
6675 your program is at this point `dead', all the data is still available and
6671 your program is at this point `dead', all the data is still available and
6676 you can walk up and down the stack frame and understand the origin of the
6672 you can walk up and down the stack frame and understand the origin of the
6677 problem.
6673 problem.
6678 \layout Standard
6674 \layout Standard
6679
6675
6680 Furthermore, you can use these debugging facilities both with the embedded
6676 Furthermore, you can use these debugging facilities both with the embedded
6681 IPython mode and without IPython at all.
6677 IPython mode and without IPython at all.
6682 For an embedded shell (see sec.
6678 For an embedded shell (see sec.
6683
6679
6684 \begin_inset LatexCommand \ref{sec:embed}
6680 \begin_inset LatexCommand \ref{sec:embed}
6685
6681
6686 \end_inset
6682 \end_inset
6687
6683
6688 ), simply call the constructor with
6684 ), simply call the constructor with
6689 \family typewriter
6685 \family typewriter
6690 `-pdb'
6686 `-pdb'
6691 \family default
6687 \family default
6692 in the argument string and automatically
6688 in the argument string and automatically
6693 \family typewriter
6689 \family typewriter
6694 pdb
6690 pdb
6695 \family default
6691 \family default
6696 will be called if an uncaught exception is triggered by your code.
6692 will be called if an uncaught exception is triggered by your code.
6697
6693
6698 \layout Standard
6694 \layout Standard
6699
6695
6700 For stand-alone use of the feature in your programs which do not use IPython
6696 For stand-alone use of the feature in your programs which do not use IPython
6701 at all, put the following lines toward the top of your `main' routine:
6697 at all, put the following lines toward the top of your `main' routine:
6702 \layout Standard
6698 \layout Standard
6703 \align left
6699 \align left
6704
6700
6705 \family typewriter
6701 \family typewriter
6706 import sys,IPython.ultraTB
6702 import sys,IPython.ultraTB
6707 \newline
6703 \newline
6708 sys.excepthook = IPython.ultraTB.FormattedTB(mode=`Verbose', color_scheme=`Linux',
6704 sys.excepthook = IPython.ultraTB.FormattedTB(mode=`Verbose', color_scheme=`Linux',
6709 call_pdb=1)
6705 call_pdb=1)
6710 \layout Standard
6706 \layout Standard
6711
6707
6712 The
6708 The
6713 \family typewriter
6709 \family typewriter
6714 mode
6710 mode
6715 \family default
6711 \family default
6716 keyword can be either
6712 keyword can be either
6717 \family typewriter
6713 \family typewriter
6718 `Verbose'
6714 `Verbose'
6719 \family default
6715 \family default
6720 or
6716 or
6721 \family typewriter
6717 \family typewriter
6722 `Plain'
6718 `Plain'
6723 \family default
6719 \family default
6724 , giving either very detailed or normal tracebacks respectively.
6720 , giving either very detailed or normal tracebacks respectively.
6725 The
6721 The
6726 \family typewriter
6722 \family typewriter
6727 color_scheme
6723 color_scheme
6728 \family default
6724 \family default
6729 keyword can be one of
6725 keyword can be one of
6730 \family typewriter
6726 \family typewriter
6731 `NoColor'
6727 `NoColor'
6732 \family default
6728 \family default
6733 ,
6729 ,
6734 \family typewriter
6730 \family typewriter
6735 `Linux'
6731 `Linux'
6736 \family default
6732 \family default
6737 (default) or
6733 (default) or
6738 \family typewriter
6734 \family typewriter
6739 `LightBG'
6735 `LightBG'
6740 \family default
6736 \family default
6741 .
6737 .
6742 These are the same options which can be set in IPython with
6738 These are the same options which can be set in IPython with
6743 \family typewriter
6739 \family typewriter
6744 -colors
6740 -colors
6745 \family default
6741 \family default
6746 and
6742 and
6747 \family typewriter
6743 \family typewriter
6748 -xmode
6744 -xmode
6749 \family default
6745 \family default
6750 .
6746 .
6751 \layout Standard
6747 \layout Standard
6752
6748
6753 This will give any of your programs detailed, colored tracebacks with automatic
6749 This will give any of your programs detailed, colored tracebacks with automatic
6754 invocation of
6750 invocation of
6755 \family typewriter
6751 \family typewriter
6756 pdb
6752 pdb
6757 \family default
6753 \family default
6758 .
6754 .
6759 \layout Section
6755 \layout Section
6760
6756
6761
6757
6762 \begin_inset LatexCommand \label{sec:syntax-extensions}
6758 \begin_inset LatexCommand \label{sec:syntax-extensions}
6763
6759
6764 \end_inset
6760 \end_inset
6765
6761
6766 Extensions for syntax processing
6762 Extensions for syntax processing
6767 \layout Standard
6763 \layout Standard
6768
6764
6769 This isn't for the faint of heart, because the potential for breaking things
6765 This isn't for the faint of heart, because the potential for breaking things
6770 is quite high.
6766 is quite high.
6771 But it can be a very powerful and useful feature.
6767 But it can be a very powerful and useful feature.
6772 In a nutshell, you can redefine the way IPython processes the user input
6768 In a nutshell, you can redefine the way IPython processes the user input
6773 line to accept new, special extensions to the syntax without needing to
6769 line to accept new, special extensions to the syntax without needing to
6774 change any of IPython's own code.
6770 change any of IPython's own code.
6775 \layout Standard
6771 \layout Standard
6776
6772
6777 In the
6773 In the
6778 \family typewriter
6774 \family typewriter
6779 IPython/Extensions
6775 IPython/Extensions
6780 \family default
6776 \family default
6781 directory you will find some examples supplied, which we will briefly describe
6777 directory you will find some examples supplied, which we will briefly describe
6782 now.
6778 now.
6783 These can be used `as is' (and both provide very useful functionality),
6779 These can be used `as is' (and both provide very useful functionality),
6784 or you can use them as a starting point for writing your own extensions.
6780 or you can use them as a starting point for writing your own extensions.
6785 \layout Subsection
6781 \layout Subsection
6786
6782
6787 Pasting of code starting with
6783 Pasting of code starting with
6788 \family typewriter
6784 \family typewriter
6789 `>>>
6785 `>>>
6790 \family default
6786 \family default
6791 ' or
6787 ' or
6792 \family typewriter
6788 \family typewriter
6793 `...
6789 `...
6794
6790
6795 \family default
6791 \family default
6796 '
6792 '
6797 \layout Standard
6793 \layout Standard
6798
6794
6799 In the python tutorial it is common to find code examples which have been
6795 In the python tutorial it is common to find code examples which have been
6800 taken from real python sessions.
6796 taken from real python sessions.
6801 The problem with those is that all the lines begin with either
6797 The problem with those is that all the lines begin with either
6802 \family typewriter
6798 \family typewriter
6803 `>>>
6799 `>>>
6804 \family default
6800 \family default
6805 ' or
6801 ' or
6806 \family typewriter
6802 \family typewriter
6807 `...
6803 `...
6808
6804
6809 \family default
6805 \family default
6810 ', which makes it impossible to paste them all at once.
6806 ', which makes it impossible to paste them all at once.
6811 One must instead do a line by line manual copying, carefully removing the
6807 One must instead do a line by line manual copying, carefully removing the
6812 leading extraneous characters.
6808 leading extraneous characters.
6813 \layout Standard
6809 \layout Standard
6814
6810
6815 This extension identifies those starting characters and removes them from
6811 This extension identifies those starting characters and removes them from
6816 the input automatically, so that one can paste multi-line examples directly
6812 the input automatically, so that one can paste multi-line examples directly
6817 into IPython, saving a lot of time.
6813 into IPython, saving a lot of time.
6818 Please look at the file
6814 Please look at the file
6819 \family typewriter
6815 \family typewriter
6820 InterpreterPasteInput.py
6816 InterpreterPasteInput.py
6821 \family default
6817 \family default
6822 in the
6818 in the
6823 \family typewriter
6819 \family typewriter
6824 IPython/Extensions
6820 IPython/Extensions
6825 \family default
6821 \family default
6826 directory for details on how this is done.
6822 directory for details on how this is done.
6827 \layout Standard
6823 \layout Standard
6828
6824
6829 IPython comes with a special profile enabling this feature, called
6825 IPython comes with a special profile enabling this feature, called
6830 \family typewriter
6826 \family typewriter
6831 tutorial
6827 tutorial
6832 \family default
6828 \family default
6833 \emph on
6829 \emph on
6834 .
6830 .
6835
6831
6836 \emph default
6832 \emph default
6837 Simply start IPython via
6833 Simply start IPython via
6838 \family typewriter
6834 \family typewriter
6839 `ipython\SpecialChar ~
6835 `ipython\SpecialChar ~
6840 -p\SpecialChar ~
6836 -p\SpecialChar ~
6841 tutorial'
6837 tutorial'
6842 \family default
6838 \family default
6843 and the feature will be available.
6839 and the feature will be available.
6844 In a normal IPython session you can activate the feature by importing the
6840 In a normal IPython session you can activate the feature by importing the
6845 corresponding module with:
6841 corresponding module with:
6846 \newline
6842 \newline
6847
6843
6848 \family typewriter
6844 \family typewriter
6849 In [1]: import IPython.Extensions.InterpreterPasteInput
6845 In [1]: import IPython.Extensions.InterpreterPasteInput
6850 \layout Standard
6846 \layout Standard
6851
6847
6852 The following is a 'screenshot' of how things work when this extension is
6848 The following is a 'screenshot' of how things work when this extension is
6853 on, copying an example from the standard tutorial:
6849 on, copying an example from the standard tutorial:
6854 \layout Standard
6850 \layout Standard
6855
6851
6856
6852
6857 \family typewriter
6853 \family typewriter
6858 IPython profile: tutorial
6854 IPython profile: tutorial
6859 \newline
6855 \newline
6860 \SpecialChar ~
6856 \SpecialChar ~
6861
6857
6862 \newline
6858 \newline
6863 *** Pasting of code with ">>>" or "..." has been enabled.
6859 *** Pasting of code with ">>>" or "..." has been enabled.
6864 \newline
6860 \newline
6865 \SpecialChar ~
6861 \SpecialChar ~
6866
6862
6867 \newline
6863 \newline
6868 In [1]: >>> def fib2(n): # return Fibonacci series up to n
6864 In [1]: >>> def fib2(n): # return Fibonacci series up to n
6869 \newline
6865 \newline
6870
6866
6871 \begin_inset ERT
6867 \begin_inset ERT
6872 status Collapsed
6868 status Collapsed
6873
6869
6874 \layout Standard
6870 \layout Standard
6875
6871
6876 \backslash
6872 \backslash
6877 hspace*{0mm}
6873 hspace*{0mm}
6878 \end_inset
6874 \end_inset
6879
6875
6880 \SpecialChar ~
6876 \SpecialChar ~
6881 \SpecialChar ~
6877 \SpecialChar ~
6882 ...: ...\SpecialChar ~
6878 ...: ...\SpecialChar ~
6883 \SpecialChar ~
6879 \SpecialChar ~
6884 \SpecialChar ~
6880 \SpecialChar ~
6885 \SpecialChar ~
6881 \SpecialChar ~
6886 """Return a list containing the Fibonacci series up to n."""
6882 """Return a list containing the Fibonacci series up to n."""
6887 \newline
6883 \newline
6888
6884
6889 \begin_inset ERT
6885 \begin_inset ERT
6890 status Collapsed
6886 status Collapsed
6891
6887
6892 \layout Standard
6888 \layout Standard
6893
6889
6894 \backslash
6890 \backslash
6895 hspace*{0mm}
6891 hspace*{0mm}
6896 \end_inset
6892 \end_inset
6897
6893
6898 \SpecialChar ~
6894 \SpecialChar ~
6899 \SpecialChar ~
6895 \SpecialChar ~
6900 ...: ...\SpecialChar ~
6896 ...: ...\SpecialChar ~
6901 \SpecialChar ~
6897 \SpecialChar ~
6902 \SpecialChar ~
6898 \SpecialChar ~
6903 \SpecialChar ~
6899 \SpecialChar ~
6904 result = []
6900 result = []
6905 \newline
6901 \newline
6906
6902
6907 \begin_inset ERT
6903 \begin_inset ERT
6908 status Collapsed
6904 status Collapsed
6909
6905
6910 \layout Standard
6906 \layout Standard
6911
6907
6912 \backslash
6908 \backslash
6913 hspace*{0mm}
6909 hspace*{0mm}
6914 \end_inset
6910 \end_inset
6915
6911
6916 \SpecialChar ~
6912 \SpecialChar ~
6917 \SpecialChar ~
6913 \SpecialChar ~
6918 ...: ...\SpecialChar ~
6914 ...: ...\SpecialChar ~
6919 \SpecialChar ~
6915 \SpecialChar ~
6920 \SpecialChar ~
6916 \SpecialChar ~
6921 \SpecialChar ~
6917 \SpecialChar ~
6922 a, b = 0, 1
6918 a, b = 0, 1
6923 \newline
6919 \newline
6924
6920
6925 \begin_inset ERT
6921 \begin_inset ERT
6926 status Collapsed
6922 status Collapsed
6927
6923
6928 \layout Standard
6924 \layout Standard
6929
6925
6930 \backslash
6926 \backslash
6931 hspace*{0mm}
6927 hspace*{0mm}
6932 \end_inset
6928 \end_inset
6933
6929
6934 \SpecialChar ~
6930 \SpecialChar ~
6935 \SpecialChar ~
6931 \SpecialChar ~
6936 ...: ...\SpecialChar ~
6932 ...: ...\SpecialChar ~
6937 \SpecialChar ~
6933 \SpecialChar ~
6938 \SpecialChar ~
6934 \SpecialChar ~
6939 \SpecialChar ~
6935 \SpecialChar ~
6940 while b < n:
6936 while b < n:
6941 \newline
6937 \newline
6942
6938
6943 \begin_inset ERT
6939 \begin_inset ERT
6944 status Collapsed
6940 status Collapsed
6945
6941
6946 \layout Standard
6942 \layout Standard
6947
6943
6948 \backslash
6944 \backslash
6949 hspace*{0mm}
6945 hspace*{0mm}
6950 \end_inset
6946 \end_inset
6951
6947
6952 \SpecialChar ~
6948 \SpecialChar ~
6953 \SpecialChar ~
6949 \SpecialChar ~
6954 ...: ...\SpecialChar ~
6950 ...: ...\SpecialChar ~
6955 \SpecialChar ~
6951 \SpecialChar ~
6956 \SpecialChar ~
6952 \SpecialChar ~
6957 \SpecialChar ~
6953 \SpecialChar ~
6958 \SpecialChar ~
6954 \SpecialChar ~
6959 \SpecialChar ~
6955 \SpecialChar ~
6960 \SpecialChar ~
6956 \SpecialChar ~
6961 \SpecialChar ~
6957 \SpecialChar ~
6962 result.append(b)\SpecialChar ~
6958 result.append(b)\SpecialChar ~
6963 \SpecialChar ~
6959 \SpecialChar ~
6964 \SpecialChar ~
6960 \SpecialChar ~
6965 # see below
6961 # see below
6966 \newline
6962 \newline
6967
6963
6968 \begin_inset ERT
6964 \begin_inset ERT
6969 status Collapsed
6965 status Collapsed
6970
6966
6971 \layout Standard
6967 \layout Standard
6972
6968
6973 \backslash
6969 \backslash
6974 hspace*{0mm}
6970 hspace*{0mm}
6975 \end_inset
6971 \end_inset
6976
6972
6977 \SpecialChar ~
6973 \SpecialChar ~
6978 \SpecialChar ~
6974 \SpecialChar ~
6979 ...: ...\SpecialChar ~
6975 ...: ...\SpecialChar ~
6980 \SpecialChar ~
6976 \SpecialChar ~
6981 \SpecialChar ~
6977 \SpecialChar ~
6982 \SpecialChar ~
6978 \SpecialChar ~
6983 \SpecialChar ~
6979 \SpecialChar ~
6984 \SpecialChar ~
6980 \SpecialChar ~
6985 \SpecialChar ~
6981 \SpecialChar ~
6986 \SpecialChar ~
6982 \SpecialChar ~
6987 a, b = b, a+b
6983 a, b = b, a+b
6988 \newline
6984 \newline
6989
6985
6990 \begin_inset ERT
6986 \begin_inset ERT
6991 status Collapsed
6987 status Collapsed
6992
6988
6993 \layout Standard
6989 \layout Standard
6994
6990
6995 \backslash
6991 \backslash
6996 hspace*{0mm}
6992 hspace*{0mm}
6997 \end_inset
6993 \end_inset
6998
6994
6999 \SpecialChar ~
6995 \SpecialChar ~
7000 \SpecialChar ~
6996 \SpecialChar ~
7001 ...: ...\SpecialChar ~
6997 ...: ...\SpecialChar ~
7002 \SpecialChar ~
6998 \SpecialChar ~
7003 \SpecialChar ~
6999 \SpecialChar ~
7004 \SpecialChar ~
7000 \SpecialChar ~
7005 return result
7001 return result
7006 \newline
7002 \newline
7007
7003
7008 \begin_inset ERT
7004 \begin_inset ERT
7009 status Collapsed
7005 status Collapsed
7010
7006
7011 \layout Standard
7007 \layout Standard
7012
7008
7013 \backslash
7009 \backslash
7014 hspace*{0mm}
7010 hspace*{0mm}
7015 \end_inset
7011 \end_inset
7016
7012
7017 \SpecialChar ~
7013 \SpecialChar ~
7018 \SpecialChar ~
7014 \SpecialChar ~
7019 ...:
7015 ...:
7020 \newline
7016 \newline
7021 \SpecialChar ~
7017 \SpecialChar ~
7022
7018
7023 \newline
7019 \newline
7024 In [2]: fib2(10)
7020 In [2]: fib2(10)
7025 \newline
7021 \newline
7026 Out[2]: [1, 1, 2, 3, 5, 8]
7022 Out[2]: [1, 1, 2, 3, 5, 8]
7027 \layout Standard
7023 \layout Standard
7028
7024
7029 Note that as currently written, this extension does
7025 Note that as currently written, this extension does
7030 \emph on
7026 \emph on
7031 not
7027 not
7032 \emph default
7028 \emph default
7033 recognize IPython's prompts for pasting.
7029 recognize IPython's prompts for pasting.
7034 Those are more complicated, since the user can change them very easily,
7030 Those are more complicated, since the user can change them very easily,
7035 they involve numbers and can vary in length.
7031 they involve numbers and can vary in length.
7036 One could however extract all the relevant information from the IPython
7032 One could however extract all the relevant information from the IPython
7037 instance and build an appropriate regular expression.
7033 instance and build an appropriate regular expression.
7038 This is left as an exercise for the reader.
7034 This is left as an exercise for the reader.
7039 \layout Subsection
7035 \layout Subsection
7040
7036
7041 Input of physical quantities with units
7037 Input of physical quantities with units
7042 \layout Standard
7038 \layout Standard
7043
7039
7044 The module
7040 The module
7045 \family typewriter
7041 \family typewriter
7046 PhysicalQInput
7042 PhysicalQInput
7047 \family default
7043 \family default
7048 allows a simplified form of input for physical quantities with units.
7044 allows a simplified form of input for physical quantities with units.
7049 This file is meant to be used in conjunction with the
7045 This file is meant to be used in conjunction with the
7050 \family typewriter
7046 \family typewriter
7051 PhysicalQInteractive
7047 PhysicalQInteractive
7052 \family default
7048 \family default
7053 module (in the same directory) and
7049 module (in the same directory) and
7054 \family typewriter
7050 \family typewriter
7055 Physics.PhysicalQuantities
7051 Physics.PhysicalQuantities
7056 \family default
7052 \family default
7057 from Konrad Hinsen's ScientificPython (
7053 from Konrad Hinsen's ScientificPython (
7058 \begin_inset LatexCommand \htmlurl{http://dirac.cnrs-orleans.fr/ScientificPython/}
7054 \begin_inset LatexCommand \htmlurl{http://dirac.cnrs-orleans.fr/ScientificPython/}
7059
7055
7060 \end_inset
7056 \end_inset
7061
7057
7062 ).
7058 ).
7063 \layout Standard
7059 \layout Standard
7064
7060
7065 The
7061 The
7066 \family typewriter
7062 \family typewriter
7067 Physics.PhysicalQuantities
7063 Physics.PhysicalQuantities
7068 \family default
7064 \family default
7069 module defines
7065 module defines
7070 \family typewriter
7066 \family typewriter
7071 PhysicalQuantity
7067 PhysicalQuantity
7072 \family default
7068 \family default
7073 objects, but these must be declared as instances of a class.
7069 objects, but these must be declared as instances of a class.
7074 For example, to define
7070 For example, to define
7075 \family typewriter
7071 \family typewriter
7076 v
7072 v
7077 \family default
7073 \family default
7078 as a velocity of 3\SpecialChar ~
7074 as a velocity of 3\SpecialChar ~
7079 m/s, normally you would write:
7075 m/s, normally you would write:
7080 \family typewriter
7076 \family typewriter
7081
7077
7082 \newline
7078 \newline
7083 In [1]: v = PhysicalQuantity(3,'m/s')
7079 In [1]: v = PhysicalQuantity(3,'m/s')
7084 \layout Standard
7080 \layout Standard
7085
7081
7086 Using the
7082 Using the
7087 \family typewriter
7083 \family typewriter
7088 PhysicalQ_Input
7084 PhysicalQ_Input
7089 \family default
7085 \family default
7090 extension this can be input instead as:
7086 extension this can be input instead as:
7091 \family typewriter
7087 \family typewriter
7092
7088
7093 \newline
7089 \newline
7094 In [1]: v = 3 m/s
7090 In [1]: v = 3 m/s
7095 \family default
7091 \family default
7096
7092
7097 \newline
7093 \newline
7098 which is much more convenient for interactive use (even though it is blatantly
7094 which is much more convenient for interactive use (even though it is blatantly
7099 invalid Python syntax).
7095 invalid Python syntax).
7100 \layout Standard
7096 \layout Standard
7101
7097
7102 The
7098 The
7103 \family typewriter
7099 \family typewriter
7104 physics
7100 physics
7105 \family default
7101 \family default
7106 profile supplied with IPython (enabled via
7102 profile supplied with IPython (enabled via
7107 \family typewriter
7103 \family typewriter
7108 'ipython -p physics'
7104 'ipython -p physics'
7109 \family default
7105 \family default
7110 ) uses these extensions, which you can also activate with:
7106 ) uses these extensions, which you can also activate with:
7111 \layout Standard
7107 \layout Standard
7112
7108
7113
7109
7114 \family typewriter
7110 \family typewriter
7115 from math import * # math MUST be imported BEFORE PhysicalQInteractive
7111 from math import * # math MUST be imported BEFORE PhysicalQInteractive
7116 \newline
7112 \newline
7117 from IPython.Extensions.PhysicalQInteractive import *
7113 from IPython.Extensions.PhysicalQInteractive import *
7118 \newline
7114 \newline
7119 import IPython.Extensions.PhysicalQInput
7115 import IPython.Extensions.PhysicalQInput
7120 \layout Section
7116 \layout Section
7121
7117
7122
7118
7123 \begin_inset LatexCommand \label{sec:IPython-as-shell}
7119 \begin_inset LatexCommand \label{sec:IPython-as-shell}
7124
7120
7125 \end_inset
7121 \end_inset
7126
7122
7127 IPython as a system shell
7123 IPython as a system shell
7128 \layout Standard
7124 \layout Standard
7129
7125
7130 IPython ships with a special profile called
7126 IPython ships with a special profile called
7131 \family typewriter
7127 \family typewriter
7132 pysh
7128 pysh
7133 \family default
7129 \family default
7134 , which you can activate at the command line as
7130 , which you can activate at the command line as
7135 \family typewriter
7131 \family typewriter
7136 `ipython -p pysh'
7132 `ipython -p pysh'
7137 \family default
7133 \family default
7138 .
7134 .
7139 This loads
7135 This loads
7140 \family typewriter
7136 \family typewriter
7141 InterpreterExec
7137 InterpreterExec
7142 \family default
7138 \family default
7143 , along with some additional facilities and a prompt customized for filesystem
7139 , along with some additional facilities and a prompt customized for filesystem
7144 navigation.
7140 navigation.
7145 \layout Standard
7141 \layout Standard
7146
7142
7147 Note that this does
7143 Note that this does
7148 \emph on
7144 \emph on
7149 not
7145 not
7150 \emph default
7146 \emph default
7151 make IPython a full-fledged system shell.
7147 make IPython a full-fledged system shell.
7152 In particular, it has no job control, so if you type Ctrl-Z (under Unix),
7148 In particular, it has no job control, so if you type Ctrl-Z (under Unix),
7153 you'll suspend pysh itself, not the process you just started.
7149 you'll suspend pysh itself, not the process you just started.
7154
7150
7155 \layout Standard
7151 \layout Standard
7156
7152
7157 What the shell profile allows you to do is to use the convenient and powerful
7153 What the shell profile allows you to do is to use the convenient and powerful
7158 syntax of Python to do quick scripting at the command line.
7154 syntax of Python to do quick scripting at the command line.
7159 Below we describe some of its features.
7155 Below we describe some of its features.
7160 \layout Subsection
7156 \layout Subsection
7161
7157
7162 Aliases
7158 Aliases
7163 \layout Standard
7159 \layout Standard
7164
7160
7165 All of your
7161 All of your
7166 \family typewriter
7162 \family typewriter
7167 $PATH
7163 $PATH
7168 \family default
7164 \family default
7169 has been loaded as IPython aliases, so you should be able to type any normal
7165 has been loaded as IPython aliases, so you should be able to type any normal
7170 system command and have it executed.
7166 system command and have it executed.
7171 See
7167 See
7172 \family typewriter
7168 \family typewriter
7173 %alias?
7169 %alias?
7174 \family default
7170 \family default
7175 and
7171 and
7176 \family typewriter
7172 \family typewriter
7177 %unalias?
7173 %unalias?
7178 \family default
7174 \family default
7179 for details on the alias facilities.
7175 for details on the alias facilities.
7180 See also
7176 See also
7181 \family typewriter
7177 \family typewriter
7182 %rehash?
7178 %rehash?
7183 \family default
7179 \family default
7184 and
7180 and
7185 \family typewriter
7181 \family typewriter
7186 %rehashx?
7182 %rehashx?
7187 \family default
7183 \family default
7188 for details on the mechanism used to load
7184 for details on the mechanism used to load
7189 \family typewriter
7185 \family typewriter
7190 $PATH
7186 $PATH
7191 \family default
7187 \family default
7192 .
7188 .
7193 \layout Subsection
7189 \layout Subsection
7194
7190
7195 Special syntax
7191 Special syntax
7196 \layout Standard
7192 \layout Standard
7197
7193
7198 Any lines which begin with
7194 Any lines which begin with
7199 \family typewriter
7195 \family typewriter
7200 `~'
7196 `~'
7201 \family default
7197 \family default
7202 ,
7198 ,
7203 \family typewriter
7199 \family typewriter
7204 `/'
7200 `/'
7205 \family default
7201 \family default
7206 and
7202 and
7207 \family typewriter
7203 \family typewriter
7208 `.'
7204 `.'
7209 \family default
7205 \family default
7210 will be executed as shell commands instead of as Python code.
7206 will be executed as shell commands instead of as Python code.
7211 The special escapes below are also recognized.
7207 The special escapes below are also recognized.
7212
7208
7213 \family typewriter
7209 \family typewriter
7214 !cmd
7210 !cmd
7215 \family default
7211 \family default
7216 is valid in single or multi-line input, all others are only valid in single-lin
7212 is valid in single or multi-line input, all others are only valid in single-lin
7217 e input:
7213 e input:
7218 \layout Description
7214 \layout Description
7219
7215
7220
7216
7221 \family typewriter
7217 \family typewriter
7222 !cmd
7218 !cmd
7223 \family default
7219 \family default
7224 pass `cmd' directly to the shell
7220 pass `cmd' directly to the shell
7225 \layout Description
7221 \layout Description
7226
7222
7227
7223
7228 \family typewriter
7224 \family typewriter
7229 !!cmd
7225 !!cmd
7230 \family default
7226 \family default
7231 execute `cmd' and return output as a list (split on `
7227 execute `cmd' and return output as a list (split on `
7232 \backslash
7228 \backslash
7233 n')
7229 n')
7234 \layout Description
7230 \layout Description
7235
7231
7236
7232
7237 \family typewriter
7233 \family typewriter
7238 $var=cmd
7234 $var=cmd
7239 \family default
7235 \family default
7240 capture output of cmd into var, as a string
7236 capture output of cmd into var, as a string
7241 \layout Description
7237 \layout Description
7242
7238
7243
7239
7244 \family typewriter
7240 \family typewriter
7245 $$var=cmd
7241 $$var=cmd
7246 \family default
7242 \family default
7247 capture output of cmd into var, as a list (split on `
7243 capture output of cmd into var, as a list (split on `
7248 \backslash
7244 \backslash
7249 n')
7245 n')
7250 \layout Standard
7246 \layout Standard
7251
7247
7252 The
7248 The
7253 \family typewriter
7249 \family typewriter
7254 $
7250 $
7255 \family default
7251 \family default
7256 /
7252 /
7257 \family typewriter
7253 \family typewriter
7258 $$
7254 $$
7259 \family default
7255 \family default
7260 syntaxes make Python variables from system output, which you can later
7256 syntaxes make Python variables from system output, which you can later
7261 use for further scripting.
7257 use for further scripting.
7262 The converse is also possible: when executing an alias or calling to the
7258 The converse is also possible: when executing an alias or calling to the
7263 system via
7259 system via
7264 \family typewriter
7260 \family typewriter
7265 !
7261 !
7266 \family default
7262 \family default
7267 /
7263 /
7268 \family typewriter
7264 \family typewriter
7269 !!
7265 !!
7270 \family default
7266 \family default
7271 , you can expand any python variable or expression by prepending it with
7267 , you can expand any python variable or expression by prepending it with
7272
7268
7273 \family typewriter
7269 \family typewriter
7274 $
7270 $
7275 \family default
7271 \family default
7276 .
7272 .
7277 Full details of the allowed syntax can be found in Python's PEP 215.
7273 Full details of the allowed syntax can be found in Python's PEP 215.
7278 \layout Standard
7274 \layout Standard
7279
7275
7280 A few brief examples will illustrate these (note that the indentation below
7276 A few brief examples will illustrate these (note that the indentation below
7281 may be incorrectly displayed):
7277 may be incorrectly displayed):
7282 \layout Standard
7278 \layout Standard
7283
7279
7284
7280
7285 \family typewriter
7281 \family typewriter
7286 fperez[~/test]|3> !ls *s.py
7282 fperez[~/test]|3> !ls *s.py
7287 \newline
7283 \newline
7288 scopes.py strings.py
7284 scopes.py strings.py
7289 \layout Standard
7285 \layout Standard
7290
7286
7291 ls is an internal alias, so there's no need to use
7287 ls is an internal alias, so there's no need to use
7292 \family typewriter
7288 \family typewriter
7293 !
7289 !
7294 \family default
7290 \family default
7295 :
7291 :
7296 \layout Standard
7292 \layout Standard
7297
7293
7298
7294
7299 \family typewriter
7295 \family typewriter
7300 fperez[~/test]|4> ls *s.py
7296 fperez[~/test]|4> ls *s.py
7301 \newline
7297 \newline
7302 scopes.py* strings.py
7298 scopes.py* strings.py
7303 \layout Standard
7299 \layout Standard
7304
7300
7305 !!ls will return the output into a Python variable:
7301 !!ls will return the output into a Python variable:
7306 \layout Standard
7302 \layout Standard
7307
7303
7308
7304
7309 \family typewriter
7305 \family typewriter
7310 fperez[~/test]|5> !!ls *s.py
7306 fperez[~/test]|5> !!ls *s.py
7311 \newline
7307 \newline
7312
7308
7313 \begin_inset ERT
7309 \begin_inset ERT
7314 status Collapsed
7310 status Collapsed
7315
7311
7316 \layout Standard
7312 \layout Standard
7317
7313
7318 \backslash
7314 \backslash
7319 hspace*{0mm}
7315 hspace*{0mm}
7320 \end_inset
7316 \end_inset
7321
7317
7322 \SpecialChar ~
7318 \SpecialChar ~
7323 \SpecialChar ~
7319 \SpecialChar ~
7324 \SpecialChar ~
7320 \SpecialChar ~
7325 \SpecialChar ~
7321 \SpecialChar ~
7326 \SpecialChar ~
7322 \SpecialChar ~
7327 \SpecialChar ~
7323 \SpecialChar ~
7328 \SpecialChar ~
7324 \SpecialChar ~
7329 \SpecialChar ~
7325 \SpecialChar ~
7330 \SpecialChar ~
7326 \SpecialChar ~
7331 \SpecialChar ~
7327 \SpecialChar ~
7332 \SpecialChar ~
7328 \SpecialChar ~
7333 \SpecialChar ~
7329 \SpecialChar ~
7334 \SpecialChar ~
7330 \SpecialChar ~
7335 \SpecialChar ~
7331 \SpecialChar ~
7336 <5> ['scopes.py', 'strings.py']
7332 <5> ['scopes.py', 'strings.py']
7337 \newline
7333 \newline
7338 fperez[~/test]|6> print _5
7334 fperez[~/test]|6> print _5
7339 \newline
7335 \newline
7340 ['scopes.py', 'strings.py']
7336 ['scopes.py', 'strings.py']
7341 \layout Standard
7337 \layout Standard
7342
7338
7343
7339
7344 \family typewriter
7340 \family typewriter
7345 $
7341 $
7346 \family default
7342 \family default
7347 and
7343 and
7348 \family typewriter
7344 \family typewriter
7349 $$
7345 $$
7350 \family default
7346 \family default
7351 allow direct capture to named variables:
7347 allow direct capture to named variables:
7352 \layout Standard
7348 \layout Standard
7353
7349
7354
7350
7355 \family typewriter
7351 \family typewriter
7356 fperez[~/test]|7> $astr = ls *s.py
7352 fperez[~/test]|7> $astr = ls *s.py
7357 \newline
7353 \newline
7358 fperez[~/test]|8> astr
7354 fperez[~/test]|8> astr
7359 \newline
7355 \newline
7360
7356
7361 \begin_inset ERT
7357 \begin_inset ERT
7362 status Collapsed
7358 status Collapsed
7363
7359
7364 \layout Standard
7360 \layout Standard
7365
7361
7366 \backslash
7362 \backslash
7367 hspace*{0mm}
7363 hspace*{0mm}
7368 \end_inset
7364 \end_inset
7369
7365
7370 \SpecialChar ~
7366 \SpecialChar ~
7371 \SpecialChar ~
7367 \SpecialChar ~
7372 \SpecialChar ~
7368 \SpecialChar ~
7373 \SpecialChar ~
7369 \SpecialChar ~
7374 \SpecialChar ~
7370 \SpecialChar ~
7375 \SpecialChar ~
7371 \SpecialChar ~
7376 \SpecialChar ~
7372 \SpecialChar ~
7377 \SpecialChar ~
7373 \SpecialChar ~
7378 \SpecialChar ~
7374 \SpecialChar ~
7379 \SpecialChar ~
7375 \SpecialChar ~
7380 \SpecialChar ~
7376 \SpecialChar ~
7381 \SpecialChar ~
7377 \SpecialChar ~
7382 \SpecialChar ~
7378 \SpecialChar ~
7383 \SpecialChar ~
7379 \SpecialChar ~
7384 <8> 'scopes.py
7380 <8> 'scopes.py
7385 \backslash
7381 \backslash
7386 nstrings.py'
7382 nstrings.py'
7387 \layout Standard
7383 \layout Standard
7388
7384
7389
7385
7390 \family typewriter
7386 \family typewriter
7391 fperez[~/test]|9> $$alist = ls *s.py
7387 fperez[~/test]|9> $$alist = ls *s.py
7392 \newline
7388 \newline
7393 fperez[~/test]|10> alist
7389 fperez[~/test]|10> alist
7394 \newline
7390 \newline
7395
7391
7396 \begin_inset ERT
7392 \begin_inset ERT
7397 status Collapsed
7393 status Collapsed
7398
7394
7399 \layout Standard
7395 \layout Standard
7400
7396
7401 \backslash
7397 \backslash
7402 hspace*{0mm}
7398 hspace*{0mm}
7403 \end_inset
7399 \end_inset
7404
7400
7405 \SpecialChar ~
7401 \SpecialChar ~
7406 \SpecialChar ~
7402 \SpecialChar ~
7407 \SpecialChar ~
7403 \SpecialChar ~
7408 \SpecialChar ~
7404 \SpecialChar ~
7409 \SpecialChar ~
7405 \SpecialChar ~
7410 \SpecialChar ~
7406 \SpecialChar ~
7411 \SpecialChar ~
7407 \SpecialChar ~
7412 \SpecialChar ~
7408 \SpecialChar ~
7413 \SpecialChar ~
7409 \SpecialChar ~
7414 \SpecialChar ~
7410 \SpecialChar ~
7415 \SpecialChar ~
7411 \SpecialChar ~
7416 \SpecialChar ~
7412 \SpecialChar ~
7417 \SpecialChar ~
7413 \SpecialChar ~
7418 \SpecialChar ~
7414 \SpecialChar ~
7419 <10> ['scopes.py', 'strings.py']
7415 <10> ['scopes.py', 'strings.py']
7420 \layout Standard
7416 \layout Standard
7421
7417
7422 alist is now a normal python list you can loop over.
7418 alist is now a normal python list you can loop over.
7423 Using
7419 Using
7424 \family typewriter
7420 \family typewriter
7425 $
7421 $
7426 \family default
7422 \family default
7427 will expand back the python values when alias calls are made:
7423 will expand back the python values when alias calls are made:
7428 \layout Standard
7424 \layout Standard
7429
7425
7430
7426
7431 \family typewriter
7427 \family typewriter
7432 fperez[~/test]|11> for f in alist:
7428 fperez[~/test]|11> for f in alist:
7433 \newline
7429 \newline
7434
7430
7435 \begin_inset ERT
7431 \begin_inset ERT
7436 status Collapsed
7432 status Collapsed
7437
7433
7438 \layout Standard
7434 \layout Standard
7439
7435
7440 \backslash
7436 \backslash
7441 hspace*{0mm}
7437 hspace*{0mm}
7442 \end_inset
7438 \end_inset
7443
7439
7444 \SpecialChar ~
7440 \SpecialChar ~
7445 \SpecialChar ~
7441 \SpecialChar ~
7446 \SpecialChar ~
7442 \SpecialChar ~
7447 \SpecialChar ~
7443 \SpecialChar ~
7448 \SpecialChar ~
7444 \SpecialChar ~
7449 \SpecialChar ~
7445 \SpecialChar ~
7450 \SpecialChar ~
7446 \SpecialChar ~
7451 \SpecialChar ~
7447 \SpecialChar ~
7452 \SpecialChar ~
7448 \SpecialChar ~
7453 \SpecialChar ~
7449 \SpecialChar ~
7454 \SpecialChar ~
7450 \SpecialChar ~
7455 \SpecialChar ~
7451 \SpecialChar ~
7456 \SpecialChar ~
7452 \SpecialChar ~
7457 \SpecialChar ~
7453 \SpecialChar ~
7458 |..> \SpecialChar ~
7454 |..> \SpecialChar ~
7459 \SpecialChar ~
7455 \SpecialChar ~
7460 \SpecialChar ~
7456 \SpecialChar ~
7461 \SpecialChar ~
7457 \SpecialChar ~
7462 print 'file',f,
7458 print 'file',f,
7463 \newline
7459 \newline
7464
7460
7465 \begin_inset ERT
7461 \begin_inset ERT
7466 status Collapsed
7462 status Collapsed
7467
7463
7468 \layout Standard
7464 \layout Standard
7469
7465
7470 \backslash
7466 \backslash
7471 hspace*{0mm}
7467 hspace*{0mm}
7472 \end_inset
7468 \end_inset
7473
7469
7474 \SpecialChar ~
7470 \SpecialChar ~
7475 \SpecialChar ~
7471 \SpecialChar ~
7476 \SpecialChar ~
7472 \SpecialChar ~
7477 \SpecialChar ~
7473 \SpecialChar ~
7478 \SpecialChar ~
7474 \SpecialChar ~
7479 \SpecialChar ~
7475 \SpecialChar ~
7480 \SpecialChar ~
7476 \SpecialChar ~
7481 \SpecialChar ~
7477 \SpecialChar ~
7482 \SpecialChar ~
7478 \SpecialChar ~
7483 \SpecialChar ~
7479 \SpecialChar ~
7484 \SpecialChar ~
7480 \SpecialChar ~
7485 \SpecialChar ~
7481 \SpecialChar ~
7486 \SpecialChar ~
7482 \SpecialChar ~
7487 \SpecialChar ~
7483 \SpecialChar ~
7488 |..> \SpecialChar ~
7484 |..> \SpecialChar ~
7489 \SpecialChar ~
7485 \SpecialChar ~
7490 \SpecialChar ~
7486 \SpecialChar ~
7491 \SpecialChar ~
7487 \SpecialChar ~
7492 wc -l $f
7488 wc -l $f
7493 \newline
7489 \newline
7494
7490
7495 \begin_inset ERT
7491 \begin_inset ERT
7496 status Collapsed
7492 status Collapsed
7497
7493
7498 \layout Standard
7494 \layout Standard
7499
7495
7500 \backslash
7496 \backslash
7501 hspace*{0mm}
7497 hspace*{0mm}
7502 \end_inset
7498 \end_inset
7503
7499
7504 \SpecialChar ~
7500 \SpecialChar ~
7505 \SpecialChar ~
7501 \SpecialChar ~
7506 \SpecialChar ~
7502 \SpecialChar ~
7507 \SpecialChar ~
7503 \SpecialChar ~
7508 \SpecialChar ~
7504 \SpecialChar ~
7509 \SpecialChar ~
7505 \SpecialChar ~
7510 \SpecialChar ~
7506 \SpecialChar ~
7511 \SpecialChar ~
7507 \SpecialChar ~
7512 \SpecialChar ~
7508 \SpecialChar ~
7513 \SpecialChar ~
7509 \SpecialChar ~
7514 \SpecialChar ~
7510 \SpecialChar ~
7515 \SpecialChar ~
7511 \SpecialChar ~
7516 \SpecialChar ~
7512 \SpecialChar ~
7517 \SpecialChar ~
7513 \SpecialChar ~
7518 |..>
7514 |..>
7519 \newline
7515 \newline
7520 file scopes.py 13 scopes.py
7516 file scopes.py 13 scopes.py
7521 \newline
7517 \newline
7522 file strings.py 4 strings.py
7518 file strings.py 4 strings.py
7523 \layout Standard
7519 \layout Standard
7524
7520
7525 Note that you may need to protect your variables with braces if you want
7521 Note that you may need to protect your variables with braces if you want
7526 to append strings to their names.
7522 to append strings to their names.
7527 To copy all files in alist to
7523 To copy all files in alist to
7528 \family typewriter
7524 \family typewriter
7529 .bak
7525 .bak
7530 \family default
7526 \family default
7531 extensions, you must use:
7527 extensions, you must use:
7532 \layout Standard
7528 \layout Standard
7533
7529
7534
7530
7535 \family typewriter
7531 \family typewriter
7536 fperez[~/test]|12> for f in alist:
7532 fperez[~/test]|12> for f in alist:
7537 \newline
7533 \newline
7538
7534
7539 \begin_inset ERT
7535 \begin_inset ERT
7540 status Collapsed
7536 status Collapsed
7541
7537
7542 \layout Standard
7538 \layout Standard
7543
7539
7544 \backslash
7540 \backslash
7545 hspace*{0mm}
7541 hspace*{0mm}
7546 \end_inset
7542 \end_inset
7547
7543
7548 \SpecialChar ~
7544 \SpecialChar ~
7549 \SpecialChar ~
7545 \SpecialChar ~
7550 \SpecialChar ~
7546 \SpecialChar ~
7551 \SpecialChar ~
7547 \SpecialChar ~
7552 \SpecialChar ~
7548 \SpecialChar ~
7553 \SpecialChar ~
7549 \SpecialChar ~
7554 \SpecialChar ~
7550 \SpecialChar ~
7555 \SpecialChar ~
7551 \SpecialChar ~
7556 \SpecialChar ~
7552 \SpecialChar ~
7557 \SpecialChar ~
7553 \SpecialChar ~
7558 \SpecialChar ~
7554 \SpecialChar ~
7559 \SpecialChar ~
7555 \SpecialChar ~
7560 \SpecialChar ~
7556 \SpecialChar ~
7561 \SpecialChar ~
7557 \SpecialChar ~
7562 |..> \SpecialChar ~
7558 |..> \SpecialChar ~
7563 \SpecialChar ~
7559 \SpecialChar ~
7564 \SpecialChar ~
7560 \SpecialChar ~
7565 \SpecialChar ~
7561 \SpecialChar ~
7566 cp $f ${f}.bak
7562 cp $f ${f}.bak
7567 \layout Standard
7563 \layout Standard
7568
7564
7569 If you try using
7565 If you try using
7570 \family typewriter
7566 \family typewriter
7571 $f.bak
7567 $f.bak
7572 \family default
7568 \family default
7573 , you'll get an AttributeError exception saying that your string object
7569 , you'll get an AttributeError exception saying that your string object
7574 doesn't have a
7570 doesn't have a
7575 \family typewriter
7571 \family typewriter
7576 .bak
7572 .bak
7577 \family default
7573 \family default
7578 attribute.
7574 attribute.
7579 This is because the
7575 This is because the
7580 \family typewriter
7576 \family typewriter
7581 $
7577 $
7582 \family default
7578 \family default
7583 expansion mechanism allows you to expand full Python expressions:
7579 expansion mechanism allows you to expand full Python expressions:
7584 \layout Standard
7580 \layout Standard
7585
7581
7586
7582
7587 \family typewriter
7583 \family typewriter
7588 fperez[~/test]|13> echo "sys.platform is: $sys.platform"
7584 fperez[~/test]|13> echo "sys.platform is: $sys.platform"
7589 \newline
7585 \newline
7590 sys.platform is: linux2
7586 sys.platform is: linux2
7591 \layout Standard
7587 \layout Standard
7592
7588
7593 IPython's input history handling is still active, which allows you to rerun
7589 IPython's input history handling is still active, which allows you to rerun
7594 a single block of multi-line input by simply using exec:
7590 a single block of multi-line input by simply using exec:
7595 \newline
7591 \newline
7596
7592
7597 \family typewriter
7593 \family typewriter
7598 fperez[~/test]|14> $$alist = ls *.eps
7594 fperez[~/test]|14> $$alist = ls *.eps
7599 \newline
7595 \newline
7600 fperez[~/test]|15> exec _i11
7596 fperez[~/test]|15> exec _i11
7601 \newline
7597 \newline
7602 file image2.eps 921 image2.eps
7598 file image2.eps 921 image2.eps
7603 \newline
7599 \newline
7604 file image.eps 921 image.eps
7600 file image.eps 921 image.eps
7605 \layout Standard
7601 \layout Standard
7606
7602
7607 While these are new special-case syntaxes, they are designed to allow very
7603 While these are new special-case syntaxes, they are designed to allow very
7608 efficient use of the shell with minimal typing.
7604 efficient use of the shell with minimal typing.
7609 At an interactive shell prompt, conciseness of expression wins over readability.
7605 At an interactive shell prompt, conciseness of expression wins over readability.
7610 \layout Subsection
7606 \layout Subsection
7611
7607
7612 Useful functions and modules
7608 Useful functions and modules
7613 \layout Standard
7609 \layout Standard
7614
7610
7615 The os, sys and shutil modules from the Python standard library are automaticall
7611 The os, sys and shutil modules from the Python standard library are automaticall
7616 y loaded.
7612 y loaded.
7617 Some additional functions, useful for shell usage, are listed below.
7613 Some additional functions, useful for shell usage, are listed below.
7618 You can request more help about them with `
7614 You can request more help about them with `
7619 \family typewriter
7615 \family typewriter
7620 ?
7616 ?
7621 \family default
7617 \family default
7622 '.
7618 '.
7623 \layout Description
7619 \layout Description
7624
7620
7625
7621
7626 \family typewriter
7622 \family typewriter
7627 shell
7623 shell
7628 \family default
7624 \family default
7629 - execute a command in the underlying system shell
7625 - execute a command in the underlying system shell
7630 \layout Description
7626 \layout Description
7631
7627
7632
7628
7633 \family typewriter
7629 \family typewriter
7634 system
7630 system
7635 \family default
7631 \family default
7636 - like
7632 - like
7637 \family typewriter
7633 \family typewriter
7638 shell()
7634 shell()
7639 \family default
7635 \family default
7640 , but return the exit status of the command
7636 , but return the exit status of the command
7641 \layout Description
7637 \layout Description
7642
7638
7643
7639
7644 \family typewriter
7640 \family typewriter
7645 sout
7641 sout
7646 \family default
7642 \family default
7647 - capture the output of a command as a string
7643 - capture the output of a command as a string
7648 \layout Description
7644 \layout Description
7649
7645
7650
7646
7651 \family typewriter
7647 \family typewriter
7652 lout
7648 lout
7653 \family default
7649 \family default
7654 - capture the output of a command as a list (split on `
7650 - capture the output of a command as a list (split on `
7655 \backslash
7651 \backslash
7656 n')
7652 n')
7657 \layout Description
7653 \layout Description
7658
7654
7659
7655
7660 \family typewriter
7656 \family typewriter
7661 getoutputerror
7657 getoutputerror
7662 \family default
7658 \family default
7663 - capture (output,error) of a shell commandss
7659 - capture (output,error) of a shell commandss
7664 \layout Standard
7660 \layout Standard
7665
7661
7666
7662
7667 \family typewriter
7663 \family typewriter
7668 sout
7664 sout
7669 \family default
7665 \family default
7670 /
7666 /
7671 \family typewriter
7667 \family typewriter
7672 lout
7668 lout
7673 \family default
7669 \family default
7674 are the functional equivalents of
7670 are the functional equivalents of
7675 \family typewriter
7671 \family typewriter
7676 $
7672 $
7677 \family default
7673 \family default
7678 /
7674 /
7679 \family typewriter
7675 \family typewriter
7680 $$
7676 $$
7681 \family default
7677 \family default
7682 .
7678 .
7683 They are provided to allow you to capture system output in the middle of
7679 They are provided to allow you to capture system output in the middle of
7684 true python code, function definitions, etc (where
7680 true python code, function definitions, etc (where
7685 \family typewriter
7681 \family typewriter
7686 $
7682 $
7687 \family default
7683 \family default
7688 and
7684 and
7689 \family typewriter
7685 \family typewriter
7690 $$
7686 $$
7691 \family default
7687 \family default
7692 are invalid).
7688 are invalid).
7693 \layout Subsection
7689 \layout Subsection
7694
7690
7695 Directory management
7691 Directory management
7696 \layout Standard
7692 \layout Standard
7697
7693
7698 Since each command passed by pysh to the underlying system is executed in
7694 Since each command passed by pysh to the underlying system is executed in
7699 a subshell which exits immediately, you can NOT use !cd to navigate the
7695 a subshell which exits immediately, you can NOT use !cd to navigate the
7700 filesystem.
7696 filesystem.
7701 \layout Standard
7697 \layout Standard
7702
7698
7703 Pysh provides its own builtin
7699 Pysh provides its own builtin
7704 \family typewriter
7700 \family typewriter
7705 `%cd
7701 `%cd
7706 \family default
7702 \family default
7707 ' magic command to move in the filesystem (the
7703 ' magic command to move in the filesystem (the
7708 \family typewriter
7704 \family typewriter
7709 %
7705 %
7710 \family default
7706 \family default
7711 is not required with automagic on).
7707 is not required with automagic on).
7712 It also maintains a list of visited directories (use
7708 It also maintains a list of visited directories (use
7713 \family typewriter
7709 \family typewriter
7714 %dhist
7710 %dhist
7715 \family default
7711 \family default
7716 to see it) and allows direct switching to any of them.
7712 to see it) and allows direct switching to any of them.
7717 Type
7713 Type
7718 \family typewriter
7714 \family typewriter
7719 `cd?
7715 `cd?
7720 \family default
7716 \family default
7721 ' for more details.
7717 ' for more details.
7722 \layout Standard
7718 \layout Standard
7723
7719
7724
7720
7725 \family typewriter
7721 \family typewriter
7726 %pushd
7722 %pushd
7727 \family default
7723 \family default
7728 ,
7724 ,
7729 \family typewriter
7725 \family typewriter
7730 %popd
7726 %popd
7731 \family default
7727 \family default
7732 and
7728 and
7733 \family typewriter
7729 \family typewriter
7734 %dirs
7730 %dirs
7735 \family default
7731 \family default
7736 are provided for directory stack handling.
7732 are provided for directory stack handling.
7737 \layout Subsection
7733 \layout Subsection
7738
7734
7739 Prompt customization
7735 Prompt customization
7740 \layout Standard
7736 \layout Standard
7741
7737
7742 The supplied
7738 The supplied
7743 \family typewriter
7739 \family typewriter
7744 ipythonrc-pysh
7740 ipythonrc-pysh
7745 \family default
7741 \family default
7746 profile comes with an example of a very colored and detailed prompt, mainly
7742 profile comes with an example of a very colored and detailed prompt, mainly
7747 to serve as an illustration.
7743 to serve as an illustration.
7748 The valid escape sequences, besides color names, are:
7744 The valid escape sequences, besides color names, are:
7749 \layout Description
7745 \layout Description
7750
7746
7751
7747
7752 \backslash
7748 \backslash
7753 # - Prompt number.
7749 # - Prompt number.
7754 \layout Description
7750 \layout Description
7755
7751
7756
7752
7757 \backslash
7753 \backslash
7758 D - Dots, as many as there are digits in
7754 D - Dots, as many as there are digits in
7759 \backslash
7755 \backslash
7760 # (so they align).
7756 # (so they align).
7761 \layout Description
7757 \layout Description
7762
7758
7763
7759
7764 \backslash
7760 \backslash
7765 w - Current working directory (cwd).
7761 w - Current working directory (cwd).
7766 \layout Description
7762 \layout Description
7767
7763
7768
7764
7769 \backslash
7765 \backslash
7770 W - Basename of current working directory.
7766 W - Basename of current working directory.
7771 \layout Description
7767 \layout Description
7772
7768
7773
7769
7774 \backslash
7770 \backslash
7775 X
7771 X
7776 \emph on
7772 \emph on
7777 N
7773 N
7778 \emph default
7774 \emph default
7779 - Where
7775 - Where
7780 \emph on
7776 \emph on
7781 N
7777 N
7782 \emph default
7778 \emph default
7783 =0..5.
7779 =0..5.
7784 N terms of the cwd, with $HOME written as ~.
7780 N terms of the cwd, with $HOME written as ~.
7785 \layout Description
7781 \layout Description
7786
7782
7787
7783
7788 \backslash
7784 \backslash
7789 Y
7785 Y
7790 \emph on
7786 \emph on
7791 N
7787 N
7792 \emph default
7788 \emph default
7793 - Where
7789 - Where
7794 \emph on
7790 \emph on
7795 N
7791 N
7796 \emph default
7792 \emph default
7797 =0..5.
7793 =0..5.
7798 Like X
7794 Like X
7799 \emph on
7795 \emph on
7800 N
7796 N
7801 \emph default
7797 \emph default
7802 , but if ~ is term
7798 , but if ~ is term
7803 \emph on
7799 \emph on
7804 N
7800 N
7805 \emph default
7801 \emph default
7806 +1 it's also shown.
7802 +1 it's also shown.
7807 \layout Description
7803 \layout Description
7808
7804
7809
7805
7810 \backslash
7806 \backslash
7811 u - Username.
7807 u - Username.
7812 \layout Description
7808 \layout Description
7813
7809
7814
7810
7815 \backslash
7811 \backslash
7816 H - Full hostname.
7812 H - Full hostname.
7817 \layout Description
7813 \layout Description
7818
7814
7819
7815
7820 \backslash
7816 \backslash
7821 h - Hostname up to first '.'
7817 h - Hostname up to first '.'
7822 \layout Description
7818 \layout Description
7823
7819
7824
7820
7825 \backslash
7821 \backslash
7826 $ - Root symbol ($ or #).
7822 $ - Root symbol ($ or #).
7827
7823
7828 \layout Description
7824 \layout Description
7829
7825
7830
7826
7831 \backslash
7827 \backslash
7832 t - Current time, in H:M:S format.
7828 t - Current time, in H:M:S format.
7833 \layout Description
7829 \layout Description
7834
7830
7835
7831
7836 \backslash
7832 \backslash
7837 v - IPython release version.
7833 v - IPython release version.
7838
7834
7839 \layout Description
7835 \layout Description
7840
7836
7841
7837
7842 \backslash
7838 \backslash
7843 n - Newline.
7839 n - Newline.
7844
7840
7845 \layout Description
7841 \layout Description
7846
7842
7847
7843
7848 \backslash
7844 \backslash
7849 r - Carriage return.
7845 r - Carriage return.
7850
7846
7851 \layout Description
7847 \layout Description
7852
7848
7853
7849
7854 \backslash
7850 \backslash
7855
7851
7856 \backslash
7852 \backslash
7857 - An explicitly escaped '
7853 - An explicitly escaped '
7858 \backslash
7854 \backslash
7859 '.
7855 '.
7860 \layout Standard
7856 \layout Standard
7861
7857
7862 You can configure your prompt colors using any ANSI color escape.
7858 You can configure your prompt colors using any ANSI color escape.
7863 Each color escape sets the color for any subsequent text, until another
7859 Each color escape sets the color for any subsequent text, until another
7864 escape comes in and changes things.
7860 escape comes in and changes things.
7865 The valid color escapes are:
7861 The valid color escapes are:
7866 \layout Description
7862 \layout Description
7867
7863
7868
7864
7869 \backslash
7865 \backslash
7870 C_Black
7866 C_Black
7871 \layout Description
7867 \layout Description
7872
7868
7873
7869
7874 \backslash
7870 \backslash
7875 C_Blue
7871 C_Blue
7876 \layout Description
7872 \layout Description
7877
7873
7878
7874
7879 \backslash
7875 \backslash
7880 C_Brown
7876 C_Brown
7881 \layout Description
7877 \layout Description
7882
7878
7883
7879
7884 \backslash
7880 \backslash
7885 C_Cyan
7881 C_Cyan
7886 \layout Description
7882 \layout Description
7887
7883
7888
7884
7889 \backslash
7885 \backslash
7890 C_DarkGray
7886 C_DarkGray
7891 \layout Description
7887 \layout Description
7892
7888
7893
7889
7894 \backslash
7890 \backslash
7895 C_Green
7891 C_Green
7896 \layout Description
7892 \layout Description
7897
7893
7898
7894
7899 \backslash
7895 \backslash
7900 C_LightBlue
7896 C_LightBlue
7901 \layout Description
7897 \layout Description
7902
7898
7903
7899
7904 \backslash
7900 \backslash
7905 C_LightCyan
7901 C_LightCyan
7906 \layout Description
7902 \layout Description
7907
7903
7908
7904
7909 \backslash
7905 \backslash
7910 C_LightGray
7906 C_LightGray
7911 \layout Description
7907 \layout Description
7912
7908
7913
7909
7914 \backslash
7910 \backslash
7915 C_LightGreen
7911 C_LightGreen
7916 \layout Description
7912 \layout Description
7917
7913
7918
7914
7919 \backslash
7915 \backslash
7920 C_LightPurple
7916 C_LightPurple
7921 \layout Description
7917 \layout Description
7922
7918
7923
7919
7924 \backslash
7920 \backslash
7925 C_LightRed
7921 C_LightRed
7926 \layout Description
7922 \layout Description
7927
7923
7928
7924
7929 \backslash
7925 \backslash
7930 C_Purple
7926 C_Purple
7931 \layout Description
7927 \layout Description
7932
7928
7933
7929
7934 \backslash
7930 \backslash
7935 C_Red
7931 C_Red
7936 \layout Description
7932 \layout Description
7937
7933
7938
7934
7939 \backslash
7935 \backslash
7940 C_White
7936 C_White
7941 \layout Description
7937 \layout Description
7942
7938
7943
7939
7944 \backslash
7940 \backslash
7945 C_Yellow
7941 C_Yellow
7946 \layout Description
7942 \layout Description
7947
7943
7948
7944
7949 \backslash
7945 \backslash
7950 C_Normal Stop coloring, defaults to your terminal settings.
7946 C_Normal Stop coloring, defaults to your terminal settings.
7951 \layout Section
7947 \layout Section
7952
7948
7953
7949
7954 \begin_inset LatexCommand \label{sec:Threading-support}
7950 \begin_inset LatexCommand \label{sec:Threading-support}
7955
7951
7956 \end_inset
7952 \end_inset
7957
7953
7958 Threading support
7954 Threading support
7959 \layout Standard
7955 \layout Standard
7960
7956
7961
7957
7962 \series bold
7958 \series bold
7963 WARNING:
7959 WARNING:
7964 \series default
7960 \series default
7965 The threading support is still somewhat experimental, and it has only seen
7961 The threading support is still somewhat experimental, and it has only seen
7966 reasonable testing under Linux.
7962 reasonable testing under Linux.
7967 Threaded code is particularly tricky to debug, and it tends to show extremely
7963 Threaded code is particularly tricky to debug, and it tends to show extremely
7968 platform-dependent behavior.
7964 platform-dependent behavior.
7969 Since I only have access to Linux machines, I will have to rely on user's
7965 Since I only have access to Linux machines, I will have to rely on user's
7970 experiences and assistance for this area of IPython to improve under other
7966 experiences and assistance for this area of IPython to improve under other
7971 platforms.
7967 platforms.
7972 \layout Standard
7968 \layout Standard
7973
7969
7974 IPython, via the
7970 IPython, via the
7975 \family typewriter
7971 \family typewriter
7976 -gthread
7972 -gthread
7977 \family default
7973 \family default
7978 ,
7974 ,
7979 \family typewriter
7975 \family typewriter
7980 -qthread
7976 -qthread
7981 \family default
7977 \family default
7982 and
7978 and
7983 \family typewriter
7979 \family typewriter
7984 -wthread
7980 -wthread
7985 \family default
7981 \family default
7986 options (described in Sec.\SpecialChar ~
7982 options (described in Sec.\SpecialChar ~
7987
7983
7988 \begin_inset LatexCommand \ref{sec:threading-opts}
7984 \begin_inset LatexCommand \ref{sec:threading-opts}
7989
7985
7990 \end_inset
7986 \end_inset
7991
7987
7992 ), can run in multithreaded mode to support pyGTK, Qt and WXPython applications
7988 ), can run in multithreaded mode to support pyGTK, Qt and WXPython applications
7993 respectively.
7989 respectively.
7994 These GUI toolkits need to control the python main loop of execution, so
7990 These GUI toolkits need to control the python main loop of execution, so
7995 under a normal Python interpreter, starting a pyGTK, Qt or WXPython application
7991 under a normal Python interpreter, starting a pyGTK, Qt or WXPython application
7996 will immediately freeze the shell.
7992 will immediately freeze the shell.
7997
7993
7998 \layout Standard
7994 \layout Standard
7999
7995
8000 IPython, with one of these options (you can only use one at a time), separates
7996 IPython, with one of these options (you can only use one at a time), separates
8001 the graphical loop and IPython's code execution run into different threads.
7997 the graphical loop and IPython's code execution run into different threads.
8002 This allows you to test interactively (with
7998 This allows you to test interactively (with
8003 \family typewriter
7999 \family typewriter
8004 %run
8000 %run
8005 \family default
8001 \family default
8006 , for example) your GUI code without blocking.
8002 , for example) your GUI code without blocking.
8007 \layout Standard
8003 \layout Standard
8008
8004
8009 A nice mini-tutorial on using IPython along with the Qt Designer application
8005 A nice mini-tutorial on using IPython along with the Qt Designer application
8010 is available at the SciPy wiki:
8006 is available at the SciPy wiki:
8011 \begin_inset LatexCommand \htmlurl{http://www.scipy.org/wikis/topical_software/QtWithIPythonAndDesigner}
8007 \begin_inset LatexCommand \htmlurl{http://www.scipy.org/wikis/topical_software/QtWithIPythonAndDesigner}
8012
8008
8013 \end_inset
8009 \end_inset
8014
8010
8015 .
8011 .
8016 \layout Subsection
8012 \layout Subsection
8017
8013
8018 Tk issues
8014 Tk issues
8019 \layout Standard
8015 \layout Standard
8020
8016
8021 As indicated in Sec.\SpecialChar ~
8017 As indicated in Sec.\SpecialChar ~
8022
8018
8023 \begin_inset LatexCommand \ref{sec:threading-opts}
8019 \begin_inset LatexCommand \ref{sec:threading-opts}
8024
8020
8025 \end_inset
8021 \end_inset
8026
8022
8027 , a special
8023 , a special
8028 \family typewriter
8024 \family typewriter
8029 -tk
8025 -tk
8030 \family default
8026 \family default
8031 option is provided to try and allow Tk graphical applications to coexist
8027 option is provided to try and allow Tk graphical applications to coexist
8032 interactively with WX, Qt or GTK ones.
8028 interactively with WX, Qt or GTK ones.
8033 Whether this works at all, however, is very platform and configuration
8029 Whether this works at all, however, is very platform and configuration
8034 dependent.
8030 dependent.
8035 Please experiment with simple test cases before committing to using this
8031 Please experiment with simple test cases before committing to using this
8036 combination of Tk and GTK/Qt/WX threading in a production environment.
8032 combination of Tk and GTK/Qt/WX threading in a production environment.
8037 \layout Subsection
8033 \layout Subsection
8038
8034
8039 Signals and Threads
8035 Signals and Threads
8040 \layout Standard
8036 \layout Standard
8041
8037
8042 When any of the thread systems (GTK, Qt or WX) are active, either directly
8038 When any of the thread systems (GTK, Qt or WX) are active, either directly
8043 or via
8039 or via
8044 \family typewriter
8040 \family typewriter
8045 -pylab
8041 -pylab
8046 \family default
8042 \family default
8047 with a threaded backend, it is impossible to interrupt long-running Python
8043 with a threaded backend, it is impossible to interrupt long-running Python
8048 code via
8044 code via
8049 \family typewriter
8045 \family typewriter
8050 Ctrl-C
8046 Ctrl-C
8051 \family default
8047 \family default
8052 .
8048 .
8053 IPython can not pass the KeyboardInterrupt exception (or the underlying
8049 IPython can not pass the KeyboardInterrupt exception (or the underlying
8054
8050
8055 \family typewriter
8051 \family typewriter
8056 SIGINT
8052 SIGINT
8057 \family default
8053 \family default
8058 ) across threads, so any long-running process started from IPython will
8054 ) across threads, so any long-running process started from IPython will
8059 run to completion, or will have to be killed via an external (OS-based)
8055 run to completion, or will have to be killed via an external (OS-based)
8060 mechanism.
8056 mechanism.
8061 \layout Standard
8057 \layout Standard
8062
8058
8063 To the best of my knowledge, this limitation is imposed by the Python interprete
8059 To the best of my knowledge, this limitation is imposed by the Python interprete
8064 r itself, and it comes from the difficulty of writing portable signal/threaded
8060 r itself, and it comes from the difficulty of writing portable signal/threaded
8065 code.
8061 code.
8066 If any user is an expert on this topic and can suggest a better solution,
8062 If any user is an expert on this topic and can suggest a better solution,
8067 I would love to hear about it.
8063 I would love to hear about it.
8068 In the IPython sources, look at the
8064 In the IPython sources, look at the
8069 \family typewriter
8065 \family typewriter
8070 Shell.py
8066 Shell.py
8071 \family default
8067 \family default
8072 module, and in particular at the
8068 module, and in particular at the
8073 \family typewriter
8069 \family typewriter
8074 runcode()
8070 runcode()
8075 \family default
8071 \family default
8076 method.
8072 method.
8077
8073
8078 \layout Subsection
8074 \layout Subsection
8079
8075
8080 I/O pitfalls
8076 I/O pitfalls
8081 \layout Standard
8077 \layout Standard
8082
8078
8083 Be mindful that the Python interpreter switches between threads every
8079 Be mindful that the Python interpreter switches between threads every
8084 \begin_inset Formula $N$
8080 \begin_inset Formula $N$
8085 \end_inset
8081 \end_inset
8086
8082
8087 bytecodes, where the default value as of Python\SpecialChar ~
8083 bytecodes, where the default value as of Python\SpecialChar ~
8088 2.3 is
8084 2.3 is
8089 \begin_inset Formula $N=100.$
8085 \begin_inset Formula $N=100.$
8090 \end_inset
8086 \end_inset
8091
8087
8092 This value can be read by using the
8088 This value can be read by using the
8093 \family typewriter
8089 \family typewriter
8094 sys.getcheckinterval()
8090 sys.getcheckinterval()
8095 \family default
8091 \family default
8096 function, and it can be reset via
8092 function, and it can be reset via
8097 \family typewriter
8093 \family typewriter
8098 sys.setcheckinterval(
8094 sys.setcheckinterval(
8099 \emph on
8095 \emph on
8100 N
8096 N
8101 \emph default
8097 \emph default
8102 )
8098 )
8103 \family default
8099 \family default
8104 .
8100 .
8105 This switching of threads can cause subtly confusing effects if one of
8101 This switching of threads can cause subtly confusing effects if one of
8106 your threads is doing file I/O.
8102 your threads is doing file I/O.
8107 In text mode, most systems only flush file buffers when they encounter
8103 In text mode, most systems only flush file buffers when they encounter
8108 a
8104 a
8109 \family typewriter
8105 \family typewriter
8110 `
8106 `
8111 \backslash
8107 \backslash
8112 n'
8108 n'
8113 \family default
8109 \family default
8114 .
8110 .
8115 An instruction as simple as
8111 An instruction as simple as
8116 \family typewriter
8112 \family typewriter
8117
8113
8118 \newline
8114 \newline
8119 \SpecialChar ~
8115 \SpecialChar ~
8120 \SpecialChar ~
8116 \SpecialChar ~
8121 print >> filehandle,
8117 print >> filehandle,
8122 \begin_inset Quotes eld
8118 \begin_inset Quotes eld
8123 \end_inset
8119 \end_inset
8124
8120
8125 hello world
8121 hello world
8126 \begin_inset Quotes erd
8122 \begin_inset Quotes erd
8127 \end_inset
8123 \end_inset
8128
8124
8129
8125
8130 \family default
8126 \family default
8131
8127
8132 \newline
8128 \newline
8133 actually consists of several bytecodes, so it is possible that the newline
8129 actually consists of several bytecodes, so it is possible that the newline
8134 does not reach your file before the next thread switch.
8130 does not reach your file before the next thread switch.
8135 Similarly, if you are writing to a file in binary mode, the file won't
8131 Similarly, if you are writing to a file in binary mode, the file won't
8136 be flushed until the buffer fills, and your other thread may see apparently
8132 be flushed until the buffer fills, and your other thread may see apparently
8137 truncated files.
8133 truncated files.
8138
8134
8139 \layout Standard
8135 \layout Standard
8140
8136
8141 For this reason, if you are using IPython's thread support and have (for
8137 For this reason, if you are using IPython's thread support and have (for
8142 example) a GUI application which will read data generated by files written
8138 example) a GUI application which will read data generated by files written
8143 to from the IPython thread, the safest approach is to open all of your
8139 to from the IPython thread, the safest approach is to open all of your
8144 files in unbuffered mode (the third argument to the
8140 files in unbuffered mode (the third argument to the
8145 \family typewriter
8141 \family typewriter
8146 file/open
8142 file/open
8147 \family default
8143 \family default
8148 function is the buffering value):
8144 function is the buffering value):
8149 \newline
8145 \newline
8150
8146
8151 \family typewriter
8147 \family typewriter
8152 \SpecialChar ~
8148 \SpecialChar ~
8153 \SpecialChar ~
8149 \SpecialChar ~
8154 filehandle = open(filename,mode,0)
8150 filehandle = open(filename,mode,0)
8155 \layout Standard
8151 \layout Standard
8156
8152
8157 This is obviously a brute force way of avoiding race conditions with the
8153 This is obviously a brute force way of avoiding race conditions with the
8158 file buffering.
8154 file buffering.
8159 If you want to do it cleanly, and you have a resource which is being shared
8155 If you want to do it cleanly, and you have a resource which is being shared
8160 by the interactive IPython loop and your GUI thread, you should really
8156 by the interactive IPython loop and your GUI thread, you should really
8161 handle it with thread locking and syncrhonization properties.
8157 handle it with thread locking and syncrhonization properties.
8162 The Python documentation discusses these.
8158 The Python documentation discusses these.
8163 \layout Section
8159 \layout Section
8164
8160
8165
8161
8166 \begin_inset LatexCommand \label{sec:interactive-demos}
8162 \begin_inset LatexCommand \label{sec:interactive-demos}
8167
8163
8168 \end_inset
8164 \end_inset
8169
8165
8170 Interactive demos with IPython
8166 Interactive demos with IPython
8171 \layout Standard
8167 \layout Standard
8172
8168
8173 IPython ships with a basic system for running scripts interactively in sections,
8169 IPython ships with a basic system for running scripts interactively in sections,
8174 useful when presenting code to audiences.
8170 useful when presenting code to audiences.
8175 A few tags embedded in comments (so that the script remains valid Python
8171 A few tags embedded in comments (so that the script remains valid Python
8176 code) divide a file into separate blocks, and the demo can be run one block
8172 code) divide a file into separate blocks, and the demo can be run one block
8177 at a time, with IPython printing (with syntax highlighting) the block before
8173 at a time, with IPython printing (with syntax highlighting) the block before
8178 executing it, and returning to the interactive prompt after each block.
8174 executing it, and returning to the interactive prompt after each block.
8179 The interactive namespace is updated after each block is run with the contents
8175 The interactive namespace is updated after each block is run with the contents
8180 of the demo's namespace.
8176 of the demo's namespace.
8181 \layout Standard
8177 \layout Standard
8182
8178
8183 This allows you to show a piece of code, run it and then execute interactively
8179 This allows you to show a piece of code, run it and then execute interactively
8184 commands based on the variables just created.
8180 commands based on the variables just created.
8185 Once you want to continue, you simply execute the next block of the demo.
8181 Once you want to continue, you simply execute the next block of the demo.
8186 The following listing shows the markup necessary for dividing a script
8182 The following listing shows the markup necessary for dividing a script
8187 into sections for execution as a demo.
8183 into sections for execution as a demo.
8188 \layout Standard
8184 \layout Standard
8189
8185
8190
8186
8191 \begin_inset ERT
8187 \begin_inset ERT
8192 status Open
8188 status Open
8193
8189
8194 \layout Standard
8190 \layout Standard
8195
8191
8196 \backslash
8192 \backslash
8197 codelist{examples/example-demo.py}
8193 codelist{examples/example-demo.py}
8198 \end_inset
8194 \end_inset
8199
8195
8200
8196
8201 \layout Standard
8197 \layout Standard
8202
8198
8203 In order to run a file as a demo, you must first make a
8199 In order to run a file as a demo, you must first make a
8204 \family typewriter
8200 \family typewriter
8205 Demo
8201 Demo
8206 \family default
8202 \family default
8207 object out of it.
8203 object out of it.
8208 If the file is named
8204 If the file is named
8209 \family typewriter
8205 \family typewriter
8210 myscript.py
8206 myscript.py
8211 \family default
8207 \family default
8212 , the following code will make a demo:
8208 , the following code will make a demo:
8213 \layout LyX-Code
8209 \layout LyX-Code
8214
8210
8215 from IPython.demo import Demo
8211 from IPython.demo import Demo
8216 \layout LyX-Code
8212 \layout LyX-Code
8217
8213
8218 mydemo = Demo('myscript.py')
8214 mydemo = Demo('myscript.py')
8219 \layout Standard
8215 \layout Standard
8220
8216
8221 This creates the
8217 This creates the
8222 \family typewriter
8218 \family typewriter
8223 mydemo
8219 mydemo
8224 \family default
8220 \family default
8225 object, whose blocks you run one at a time by simply calling the object
8221 object, whose blocks you run one at a time by simply calling the object
8226 with no arguments.
8222 with no arguments.
8227 If you have autocall active in IPython (the default), all you need to do
8223 If you have autocall active in IPython (the default), all you need to do
8228 is type
8224 is type
8229 \layout LyX-Code
8225 \layout LyX-Code
8230
8226
8231 mydemo
8227 mydemo
8232 \layout Standard
8228 \layout Standard
8233
8229
8234 and IPython will call it, executing each block.
8230 and IPython will call it, executing each block.
8235 Demo objects can be restarted, you can move forward or back skipping blocks,
8231 Demo objects can be restarted, you can move forward or back skipping blocks,
8236 re-execute the last block, etc.
8232 re-execute the last block, etc.
8237 Simply use the Tab key on a demo object to see its methods, and call
8233 Simply use the Tab key on a demo object to see its methods, and call
8238 \family typewriter
8234 \family typewriter
8239 `?'
8235 `?'
8240 \family default
8236 \family default
8241 on them to see their docstrings for more usage details.
8237 on them to see their docstrings for more usage details.
8242 In addition, the
8238 In addition, the
8243 \family typewriter
8239 \family typewriter
8244 demo
8240 demo
8245 \family default
8241 \family default
8246 module itself contains a comprehensive docstring, which you can access
8242 module itself contains a comprehensive docstring, which you can access
8247 via
8243 via
8248 \layout LyX-Code
8244 \layout LyX-Code
8249
8245
8250 from IPython import demo
8246 from IPython import demo
8251 \layout LyX-Code
8247 \layout LyX-Code
8252
8248
8253 demo?
8249 demo?
8254 \layout Standard
8250 \layout Standard
8255
8251
8256
8252
8257 \series bold
8253 \series bold
8258 Limitations:
8254 Limitations:
8259 \series default
8255 \series default
8260 It is important to note that these demos are limited to fairly simple uses.
8256 It is important to note that these demos are limited to fairly simple uses.
8261 In particular, you can
8257 In particular, you can
8262 \emph on
8258 \emph on
8263 not
8259 not
8264 \emph default
8260 \emph default
8265 put division marks in indented code (loops, if statements, function definitions
8261 put division marks in indented code (loops, if statements, function definitions
8266 , etc.) Supporting something like this would basically require tracking the
8262 , etc.) Supporting something like this would basically require tracking the
8267 internal execution state of the Python interpreter, so only top-level divisions
8263 internal execution state of the Python interpreter, so only top-level divisions
8268 are allowed.
8264 are allowed.
8269 If you want to be able to open an IPython instance at an arbitrary point
8265 If you want to be able to open an IPython instance at an arbitrary point
8270 in a program, you can use IPython's embedding facilities, described in
8266 in a program, you can use IPython's embedding facilities, described in
8271 detail in Sec\SpecialChar \@.
8267 detail in Sec\SpecialChar \@.
8272 \SpecialChar ~
8268 \SpecialChar ~
8273
8269
8274 \begin_inset LatexCommand \ref{sec:embed}
8270 \begin_inset LatexCommand \ref{sec:embed}
8275
8271
8276 \end_inset
8272 \end_inset
8277
8273
8278 .
8274 .
8279 \layout Section
8275 \layout Section
8280
8276
8281
8277
8282 \begin_inset LatexCommand \label{sec:matplotlib-support}
8278 \begin_inset LatexCommand \label{sec:matplotlib-support}
8283
8279
8284 \end_inset
8280 \end_inset
8285
8281
8286 Plotting with
8282 Plotting with
8287 \family typewriter
8283 \family typewriter
8288 matplotlib
8284 matplotlib
8289 \family default
8285 \family default
8290
8286
8291 \layout Standard
8287 \layout Standard
8292
8288
8293 The matplotlib library (
8289 The matplotlib library (
8294 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
8290 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
8295
8291
8296 \end_inset
8292 \end_inset
8297
8293
8298 ) provides high quality 2D plotting for Python.
8294 ) provides high quality 2D plotting for Python.
8299 Matplotlib can produce plots on screen using a variety of GUI toolkits,
8295 Matplotlib can produce plots on screen using a variety of GUI toolkits,
8300 including Tk, GTK and WXPython.
8296 including Tk, GTK and WXPython.
8301 It also provides a number of commands useful for scientific computing,
8297 It also provides a number of commands useful for scientific computing,
8302 all with a syntax compatible with that of the popular Matlab program.
8298 all with a syntax compatible with that of the popular Matlab program.
8303 \layout Standard
8299 \layout Standard
8304
8300
8305 IPython accepts the special option
8301 IPython accepts the special option
8306 \family typewriter
8302 \family typewriter
8307 -pylab
8303 -pylab
8308 \family default
8304 \family default
8309 (Sec.\SpecialChar ~
8305 (Sec.\SpecialChar ~
8310
8306
8311 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
8307 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
8312
8308
8313 \end_inset
8309 \end_inset
8314
8310
8315 ).
8311 ).
8316 This configures it to support matplotlib, honoring the settings in the
8312 This configures it to support matplotlib, honoring the settings in the
8317
8313
8318 \family typewriter
8314 \family typewriter
8319 .matplotlibrc
8315 .matplotlibrc
8320 \family default
8316 \family default
8321 file.
8317 file.
8322 IPython will detect the user's choice of matplotlib GUI backend, and automatica
8318 IPython will detect the user's choice of matplotlib GUI backend, and automatica
8323 lly select the proper threading model to prevent blocking.
8319 lly select the proper threading model to prevent blocking.
8324 It also sets matplotlib in interactive mode and modifies
8320 It also sets matplotlib in interactive mode and modifies
8325 \family typewriter
8321 \family typewriter
8326 %run
8322 %run
8327 \family default
8323 \family default
8328 slightly, so that any matplotlib-based script can be executed using
8324 slightly, so that any matplotlib-based script can be executed using
8329 \family typewriter
8325 \family typewriter
8330 %run
8326 %run
8331 \family default
8327 \family default
8332 and the final
8328 and the final
8333 \family typewriter
8329 \family typewriter
8334 show()
8330 show()
8335 \family default
8331 \family default
8336 command does not block the interactive shell.
8332 command does not block the interactive shell.
8337 \layout Standard
8333 \layout Standard
8338
8334
8339 The
8335 The
8340 \family typewriter
8336 \family typewriter
8341 -pylab
8337 -pylab
8342 \family default
8338 \family default
8343 option must be given first in order for IPython to configure its threading
8339 option must be given first in order for IPython to configure its threading
8344 mode.
8340 mode.
8345 However, you can still issue other options afterwards.
8341 However, you can still issue other options afterwards.
8346 This allows you to have a matplotlib-based environment customized with
8342 This allows you to have a matplotlib-based environment customized with
8347 additional modules using the standard IPython profile mechanism (Sec.\SpecialChar ~
8343 additional modules using the standard IPython profile mechanism (Sec.\SpecialChar ~
8348
8344
8349 \begin_inset LatexCommand \ref{sec:profiles}
8345 \begin_inset LatexCommand \ref{sec:profiles}
8350
8346
8351 \end_inset
8347 \end_inset
8352
8348
8353 ): ``
8349 ): ``
8354 \family typewriter
8350 \family typewriter
8355 ipython -pylab -p myprofile
8351 ipython -pylab -p myprofile
8356 \family default
8352 \family default
8357 '' will load the profile defined in
8353 '' will load the profile defined in
8358 \family typewriter
8354 \family typewriter
8359 ipythonrc-myprofile
8355 ipythonrc-myprofile
8360 \family default
8356 \family default
8361 after configuring matplotlib.
8357 after configuring matplotlib.
8362 \layout Section
8358 \layout Section
8363
8359
8364
8360
8365 \begin_inset LatexCommand \label{sec:Gnuplot}
8361 \begin_inset LatexCommand \label{sec:Gnuplot}
8366
8362
8367 \end_inset
8363 \end_inset
8368
8364
8369 Plotting with
8365 Plotting with
8370 \family typewriter
8366 \family typewriter
8371 Gnuplot
8367 Gnuplot
8372 \layout Standard
8368 \layout Standard
8373
8369
8374 Through the magic extension system described in sec.
8370 Through the magic extension system described in sec.
8375
8371
8376 \begin_inset LatexCommand \ref{sec:magic}
8372 \begin_inset LatexCommand \ref{sec:magic}
8377
8373
8378 \end_inset
8374 \end_inset
8379
8375
8380 , IPython incorporates a mechanism for conveniently interfacing with the
8376 , IPython incorporates a mechanism for conveniently interfacing with the
8381 Gnuplot system (
8377 Gnuplot system (
8382 \begin_inset LatexCommand \htmlurl{http://www.gnuplot.info}
8378 \begin_inset LatexCommand \htmlurl{http://www.gnuplot.info}
8383
8379
8384 \end_inset
8380 \end_inset
8385
8381
8386 ).
8382 ).
8387 Gnuplot is a very complete 2D and 3D plotting package available for many
8383 Gnuplot is a very complete 2D and 3D plotting package available for many
8388 operating systems and commonly included in modern Linux distributions.
8384 operating systems and commonly included in modern Linux distributions.
8389
8385
8390 \layout Standard
8386 \layout Standard
8391
8387
8392 Besides having Gnuplot installed, this functionality requires the
8388 Besides having Gnuplot installed, this functionality requires the
8393 \family typewriter
8389 \family typewriter
8394 Gnuplot.py
8390 Gnuplot.py
8395 \family default
8391 \family default
8396 module for interfacing python with Gnuplot.
8392 module for interfacing python with Gnuplot.
8397 It can be downloaded from:
8393 It can be downloaded from:
8398 \begin_inset LatexCommand \htmlurl{http://gnuplot-py.sourceforge.net}
8394 \begin_inset LatexCommand \htmlurl{http://gnuplot-py.sourceforge.net}
8399
8395
8400 \end_inset
8396 \end_inset
8401
8397
8402 .
8398 .
8403 \layout Subsection
8399 \layout Subsection
8404
8400
8405 Proper Gnuplot configuration
8401 Proper Gnuplot configuration
8406 \layout Standard
8402 \layout Standard
8407
8403
8408 As of version 4.0, Gnuplot has excellent mouse and interactive keyboard support.
8404 As of version 4.0, Gnuplot has excellent mouse and interactive keyboard support.
8409 However, as of
8405 However, as of
8410 \family typewriter
8406 \family typewriter
8411 Gnuplot.py
8407 Gnuplot.py
8412 \family default
8408 \family default
8413 version 1.7, a new option was added to communicate between Python and Gnuplot
8409 version 1.7, a new option was added to communicate between Python and Gnuplot
8414 via FIFOs (pipes).
8410 via FIFOs (pipes).
8415 This mechanism, while fast, also breaks the mouse system.
8411 This mechanism, while fast, also breaks the mouse system.
8416 You must therefore set the variable
8412 You must therefore set the variable
8417 \family typewriter
8413 \family typewriter
8418 prefer_fifo_data
8414 prefer_fifo_data
8419 \family default
8415 \family default
8420 to
8416 to
8421 \family typewriter
8417 \family typewriter
8422 0
8418 0
8423 \family default
8419 \family default
8424 in file
8420 in file
8425 \family typewriter
8421 \family typewriter
8426 gp_unix.py
8422 gp_unix.py
8427 \family default
8423 \family default
8428 if you wish to keep the interactive mouse and keyboard features working
8424 if you wish to keep the interactive mouse and keyboard features working
8429 properly (
8425 properly (
8430 \family typewriter
8426 \family typewriter
8431 prefer_inline_data
8427 prefer_inline_data
8432 \family default
8428 \family default
8433 also must be
8429 also must be
8434 \family typewriter
8430 \family typewriter
8435 0
8431 0
8436 \family default
8432 \family default
8437 , but this is the default so unless you've changed it manually you should
8433 , but this is the default so unless you've changed it manually you should
8438 be fine).
8434 be fine).
8439 \layout Standard
8435 \layout Standard
8440
8436
8441 'Out of the box', Gnuplot is configured with a rather poor set of size,
8437 'Out of the box', Gnuplot is configured with a rather poor set of size,
8442 color and linewidth choices which make the graphs fairly hard to read on
8438 color and linewidth choices which make the graphs fairly hard to read on
8443 modern high-resolution displays (although they work fine on old 640x480
8439 modern high-resolution displays (although they work fine on old 640x480
8444 ones).
8440 ones).
8445 Below is a section of my
8441 Below is a section of my
8446 \family typewriter
8442 \family typewriter
8447 .Xdefaults
8443 .Xdefaults
8448 \family default
8444 \family default
8449 file which I use for having a more convenient Gnuplot setup.
8445 file which I use for having a more convenient Gnuplot setup.
8450 Remember to load it by running
8446 Remember to load it by running
8451 \family typewriter
8447 \family typewriter
8452 `xrdb .Xdefaults`
8448 `xrdb .Xdefaults`
8453 \family default
8449 \family default
8454 :
8450 :
8455 \layout Standard
8451 \layout Standard
8456
8452
8457
8453
8458 \family typewriter
8454 \family typewriter
8459 !******************************************************************
8455 !******************************************************************
8460 \newline
8456 \newline
8461 ! gnuplot options
8457 ! gnuplot options
8462 \newline
8458 \newline
8463 ! modify this for a convenient window size
8459 ! modify this for a convenient window size
8464 \newline
8460 \newline
8465 gnuplot*geometry: 780x580
8461 gnuplot*geometry: 780x580
8466 \layout Standard
8462 \layout Standard
8467
8463
8468
8464
8469 \family typewriter
8465 \family typewriter
8470 ! on-screen font (not for PostScript)
8466 ! on-screen font (not for PostScript)
8471 \newline
8467 \newline
8472 gnuplot*font: -misc-fixed-bold-r-normal--15-120-100-100-c-90-iso8859-1
8468 gnuplot*font: -misc-fixed-bold-r-normal--15-120-100-100-c-90-iso8859-1
8473 \layout Standard
8469 \layout Standard
8474
8470
8475
8471
8476 \family typewriter
8472 \family typewriter
8477 ! color options
8473 ! color options
8478 \newline
8474 \newline
8479 gnuplot*background: black
8475 gnuplot*background: black
8480 \newline
8476 \newline
8481 gnuplot*textColor: white
8477 gnuplot*textColor: white
8482 \newline
8478 \newline
8483 gnuplot*borderColor: white
8479 gnuplot*borderColor: white
8484 \newline
8480 \newline
8485 gnuplot*axisColor: white
8481 gnuplot*axisColor: white
8486 \newline
8482 \newline
8487 gnuplot*line1Color: red
8483 gnuplot*line1Color: red
8488 \newline
8484 \newline
8489 gnuplot*line2Color: green
8485 gnuplot*line2Color: green
8490 \newline
8486 \newline
8491 gnuplot*line3Color: blue
8487 gnuplot*line3Color: blue
8492 \newline
8488 \newline
8493 gnuplot*line4Color: magenta
8489 gnuplot*line4Color: magenta
8494 \newline
8490 \newline
8495 gnuplot*line5Color: cyan
8491 gnuplot*line5Color: cyan
8496 \newline
8492 \newline
8497 gnuplot*line6Color: sienna
8493 gnuplot*line6Color: sienna
8498 \newline
8494 \newline
8499 gnuplot*line7Color: orange
8495 gnuplot*line7Color: orange
8500 \newline
8496 \newline
8501 gnuplot*line8Color: coral
8497 gnuplot*line8Color: coral
8502 \layout Standard
8498 \layout Standard
8503
8499
8504
8500
8505 \family typewriter
8501 \family typewriter
8506 ! multiplicative factor for point styles
8502 ! multiplicative factor for point styles
8507 \newline
8503 \newline
8508 gnuplot*pointsize: 2
8504 gnuplot*pointsize: 2
8509 \layout Standard
8505 \layout Standard
8510
8506
8511
8507
8512 \family typewriter
8508 \family typewriter
8513 ! line width options (in pixels)
8509 ! line width options (in pixels)
8514 \newline
8510 \newline
8515 gnuplot*borderWidth: 2
8511 gnuplot*borderWidth: 2
8516 \newline
8512 \newline
8517 gnuplot*axisWidth: 2
8513 gnuplot*axisWidth: 2
8518 \newline
8514 \newline
8519 gnuplot*line1Width: 2
8515 gnuplot*line1Width: 2
8520 \newline
8516 \newline
8521 gnuplot*line2Width: 2
8517 gnuplot*line2Width: 2
8522 \newline
8518 \newline
8523 gnuplot*line3Width: 2
8519 gnuplot*line3Width: 2
8524 \newline
8520 \newline
8525 gnuplot*line4Width: 2
8521 gnuplot*line4Width: 2
8526 \newline
8522 \newline
8527 gnuplot*line5Width: 2
8523 gnuplot*line5Width: 2
8528 \newline
8524 \newline
8529 gnuplot*line6Width: 2
8525 gnuplot*line6Width: 2
8530 \newline
8526 \newline
8531 gnuplot*line7Width: 2
8527 gnuplot*line7Width: 2
8532 \newline
8528 \newline
8533 gnuplot*line8Width: 2
8529 gnuplot*line8Width: 2
8534 \layout Subsection
8530 \layout Subsection
8535
8531
8536 The
8532 The
8537 \family typewriter
8533 \family typewriter
8538 IPython.GnuplotRuntime
8534 IPython.GnuplotRuntime
8539 \family default
8535 \family default
8540 module
8536 module
8541 \layout Standard
8537 \layout Standard
8542
8538
8543 IPython includes a module called
8539 IPython includes a module called
8544 \family typewriter
8540 \family typewriter
8545 Gnuplot2.py
8541 Gnuplot2.py
8546 \family default
8542 \family default
8547 which extends and improves the default
8543 which extends and improves the default
8548 \family typewriter
8544 \family typewriter
8549 Gnuplot
8545 Gnuplot
8550 \family default
8546 \family default
8551 .
8547 .
8552 \family typewriter
8548 \family typewriter
8553 py
8549 py
8554 \family default
8550 \family default
8555 (which it still relies upon).
8551 (which it still relies upon).
8556 For example, the new
8552 For example, the new
8557 \family typewriter
8553 \family typewriter
8558 plot
8554 plot
8559 \family default
8555 \family default
8560 function adds several improvements to the original making it more convenient
8556 function adds several improvements to the original making it more convenient
8561 for interactive use, and
8557 for interactive use, and
8562 \family typewriter
8558 \family typewriter
8563 hardcopy
8559 hardcopy
8564 \family default
8560 \family default
8565 fixes a bug in the original which under some circumstances blocks the creation
8561 fixes a bug in the original which under some circumstances blocks the creation
8566 of PostScript output.
8562 of PostScript output.
8567 \layout Standard
8563 \layout Standard
8568
8564
8569 For scripting use,
8565 For scripting use,
8570 \family typewriter
8566 \family typewriter
8571 GnuplotRuntime.py
8567 GnuplotRuntime.py
8572 \family default
8568 \family default
8573 is provided, which wraps
8569 is provided, which wraps
8574 \family typewriter
8570 \family typewriter
8575 Gnuplot2.py
8571 Gnuplot2.py
8576 \family default
8572 \family default
8577 and creates a series of global aliases.
8573 and creates a series of global aliases.
8578 These make it easy to control Gnuplot plotting jobs through the Python
8574 These make it easy to control Gnuplot plotting jobs through the Python
8579 language.
8575 language.
8580 \layout Standard
8576 \layout Standard
8581
8577
8582 Below is some example code which illustrates how to configure Gnuplot inside
8578 Below is some example code which illustrates how to configure Gnuplot inside
8583 your own programs but have it available for further interactive use through
8579 your own programs but have it available for further interactive use through
8584 an embedded IPython instance.
8580 an embedded IPython instance.
8585 Simply run this file at a system prompt.
8581 Simply run this file at a system prompt.
8586 This file is provided as
8582 This file is provided as
8587 \family typewriter
8583 \family typewriter
8588 example-gnuplot.py
8584 example-gnuplot.py
8589 \family default
8585 \family default
8590 in the examples directory:
8586 in the examples directory:
8591 \layout Standard
8587 \layout Standard
8592
8588
8593
8589
8594 \begin_inset ERT
8590 \begin_inset ERT
8595 status Open
8591 status Open
8596
8592
8597 \layout Standard
8593 \layout Standard
8598
8594
8599 \backslash
8595 \backslash
8600 codelist{examples/example-gnuplot.py}
8596 codelist{examples/example-gnuplot.py}
8601 \end_inset
8597 \end_inset
8602
8598
8603
8599
8604 \layout Subsection
8600 \layout Subsection
8605
8601
8606 The
8602 The
8607 \family typewriter
8603 \family typewriter
8608 numeric
8604 numeric
8609 \family default
8605 \family default
8610 profile: a scientific computing environment
8606 profile: a scientific computing environment
8611 \layout Standard
8607 \layout Standard
8612
8608
8613 The
8609 The
8614 \family typewriter
8610 \family typewriter
8615 numeric
8611 numeric
8616 \family default
8612 \family default
8617 IPython profile, which you can activate with
8613 IPython profile, which you can activate with
8618 \family typewriter
8614 \family typewriter
8619 `ipython -p numeric
8615 `ipython -p numeric
8620 \family default
8616 \family default
8621 ' will automatically load the IPython Gnuplot extensions (plus Numeric and
8617 ' will automatically load the IPython Gnuplot extensions (plus Numeric and
8622 other useful things for numerical computing), contained in the
8618 other useful things for numerical computing), contained in the
8623 \family typewriter
8619 \family typewriter
8624 IPython.GnuplotInteractive
8620 IPython.GnuplotInteractive
8625 \family default
8621 \family default
8626 module.
8622 module.
8627 This will create the globals
8623 This will create the globals
8628 \family typewriter
8624 \family typewriter
8629 Gnuplot
8625 Gnuplot
8630 \family default
8626 \family default
8631 (an alias to the improved Gnuplot2 module),
8627 (an alias to the improved Gnuplot2 module),
8632 \family typewriter
8628 \family typewriter
8633 gp
8629 gp
8634 \family default
8630 \family default
8635 (a Gnuplot active instance), the new magic commands
8631 (a Gnuplot active instance), the new magic commands
8636 \family typewriter
8632 \family typewriter
8637 %gpc
8633 %gpc
8638 \family default
8634 \family default
8639 and
8635 and
8640 \family typewriter
8636 \family typewriter
8641 %gp_set_instance
8637 %gp_set_instance
8642 \family default
8638 \family default
8643 and several other convenient globals.
8639 and several other convenient globals.
8644 Type
8640 Type
8645 \family typewriter
8641 \family typewriter
8646 gphelp()
8642 gphelp()
8647 \family default
8643 \family default
8648 for further details.
8644 for further details.
8649 \layout Standard
8645 \layout Standard
8650
8646
8651 This should turn IPython into a convenient environment for numerical computing,
8647 This should turn IPython into a convenient environment for numerical computing,
8652 with all the functions in the NumPy library and the Gnuplot facilities
8648 with all the functions in the NumPy library and the Gnuplot facilities
8653 for plotting.
8649 for plotting.
8654 Further improvements can be obtained by loading the SciPy libraries for
8650 Further improvements can be obtained by loading the SciPy libraries for
8655 scientific computing, available at
8651 scientific computing, available at
8656 \begin_inset LatexCommand \htmlurl{http://scipy.org}
8652 \begin_inset LatexCommand \htmlurl{http://scipy.org}
8657
8653
8658 \end_inset
8654 \end_inset
8659
8655
8660 .
8656 .
8661 \layout Standard
8657 \layout Standard
8662
8658
8663 If you are in the middle of a working session with numerical objects and
8659 If you are in the middle of a working session with numerical objects and
8664 need to plot them but you didn't start the
8660 need to plot them but you didn't start the
8665 \family typewriter
8661 \family typewriter
8666 numeric
8662 numeric
8667 \family default
8663 \family default
8668 profile, you can load these extensions at any time by typing
8664 profile, you can load these extensions at any time by typing
8669 \newline
8665 \newline
8670
8666
8671 \family typewriter
8667 \family typewriter
8672 from IPython.GnuplotInteractive import *
8668 from IPython.GnuplotInteractive import *
8673 \newline
8669 \newline
8674
8670
8675 \family default
8671 \family default
8676 at the IPython prompt.
8672 at the IPython prompt.
8677 This will allow you to keep your objects intact and start using Gnuplot
8673 This will allow you to keep your objects intact and start using Gnuplot
8678 to view them.
8674 to view them.
8679 \layout Section
8675 \layout Section
8680
8676
8681 Reporting bugs
8677 Reporting bugs
8682 \layout Subsection*
8678 \layout Subsection*
8683
8679
8684 Automatic crash reports
8680 Automatic crash reports
8685 \layout Standard
8681 \layout Standard
8686
8682
8687 Ideally, IPython itself shouldn't crash.
8683 Ideally, IPython itself shouldn't crash.
8688 It will catch exceptions produced by you, but bugs in its internals will
8684 It will catch exceptions produced by you, but bugs in its internals will
8689 still crash it.
8685 still crash it.
8690 \layout Standard
8686 \layout Standard
8691
8687
8692 In such a situation, IPython will leave a file named
8688 In such a situation, IPython will leave a file named
8693 \family typewriter
8689 \family typewriter
8694 IPython_crash_report.txt
8690 IPython_crash_report.txt
8695 \family default
8691 \family default
8696 in your IPYTHONDIR directory (that way if crashes happen several times
8692 in your IPYTHONDIR directory (that way if crashes happen several times
8697 it won't litter many directories, the post-mortem file is always located
8693 it won't litter many directories, the post-mortem file is always located
8698 in the same place and new occurrences just overwrite the previous one).
8694 in the same place and new occurrences just overwrite the previous one).
8699 If you can mail this file to the developers (see sec.
8695 If you can mail this file to the developers (see sec.
8700
8696
8701 \begin_inset LatexCommand \ref{sec:credits}
8697 \begin_inset LatexCommand \ref{sec:credits}
8702
8698
8703 \end_inset
8699 \end_inset
8704
8700
8705 for names and addresses), it will help us
8701 for names and addresses), it will help us
8706 \emph on
8702 \emph on
8707 a lot
8703 a lot
8708 \emph default
8704 \emph default
8709 in understanding the cause of the problem and fixing it sooner.
8705 in understanding the cause of the problem and fixing it sooner.
8710 \layout Subsection*
8706 \layout Subsection*
8711
8707
8712 The bug tracker
8708 The bug tracker
8713 \layout Standard
8709 \layout Standard
8714
8710
8715 IPython also has an online bug-tracker, located at
8711 IPython also has an online bug-tracker, located at
8716 \begin_inset LatexCommand \htmlurl{http://projects.scipy.org/ipython/ipython/report/1}
8712 \begin_inset LatexCommand \htmlurl{http://projects.scipy.org/ipython/ipython/report/1}
8717
8713
8718 \end_inset
8714 \end_inset
8719
8715
8720 .
8716 .
8721 In addition to mailing the developers, it would be a good idea to file
8717 In addition to mailing the developers, it would be a good idea to file
8722 a bug report here.
8718 a bug report here.
8723 This will ensure that the issue is properly followed to conclusion.
8719 This will ensure that the issue is properly followed to conclusion.
8724 To report new bugs you will have to register first.
8720 To report new bugs you will have to register first.
8725 \layout Standard
8721 \layout Standard
8726
8722
8727 You can also use this bug tracker to file feature requests.
8723 You can also use this bug tracker to file feature requests.
8728 \layout Section
8724 \layout Section
8729
8725
8730 Brief history
8726 Brief history
8731 \layout Subsection
8727 \layout Subsection
8732
8728
8733 Origins
8729 Origins
8734 \layout Standard
8730 \layout Standard
8735
8731
8736 The current IPython system grew out of the following three projects:
8732 The current IPython system grew out of the following three projects:
8737 \layout List
8733 \layout List
8738 \labelwidthstring 00.00.0000
8734 \labelwidthstring 00.00.0000
8739
8735
8740 ipython by Fernando P
8736 ipython by Fernando P
8741 \begin_inset ERT
8737 \begin_inset ERT
8742 status Collapsed
8738 status Collapsed
8743
8739
8744 \layout Standard
8740 \layout Standard
8745
8741
8746 \backslash
8742 \backslash
8747 '{e}
8743 '{e}
8748 \end_inset
8744 \end_inset
8749
8745
8750 rez.
8746 rez.
8751 I was working on adding Mathematica-type prompts and a flexible configuration
8747 I was working on adding Mathematica-type prompts and a flexible configuration
8752 system (something better than
8748 system (something better than
8753 \family typewriter
8749 \family typewriter
8754 $PYTHONSTARTUP
8750 $PYTHONSTARTUP
8755 \family default
8751 \family default
8756 ) to the standard Python interactive interpreter.
8752 ) to the standard Python interactive interpreter.
8757 \layout List
8753 \layout List
8758 \labelwidthstring 00.00.0000
8754 \labelwidthstring 00.00.0000
8759
8755
8760 IPP by Janko Hauser.
8756 IPP by Janko Hauser.
8761 Very well organized, great usability.
8757 Very well organized, great usability.
8762 Had an old help system.
8758 Had an old help system.
8763 IPP was used as the `container' code into which I added the functionality
8759 IPP was used as the `container' code into which I added the functionality
8764 from ipython and LazyPython.
8760 from ipython and LazyPython.
8765 \layout List
8761 \layout List
8766 \labelwidthstring 00.00.0000
8762 \labelwidthstring 00.00.0000
8767
8763
8768 LazyPython by Nathan Gray.
8764 LazyPython by Nathan Gray.
8769 Simple but
8765 Simple but
8770 \emph on
8766 \emph on
8771 very
8767 very
8772 \emph default
8768 \emph default
8773 powerful.
8769 powerful.
8774 The quick syntax (auto parens, auto quotes) and verbose/colored tracebacks
8770 The quick syntax (auto parens, auto quotes) and verbose/colored tracebacks
8775 were all taken from here.
8771 were all taken from here.
8776 \layout Standard
8772 \layout Standard
8777
8773
8778 When I found out (see sec.
8774 When I found out (see sec.
8779
8775
8780 \begin_inset LatexCommand \ref{figgins}
8776 \begin_inset LatexCommand \ref{figgins}
8781
8777
8782 \end_inset
8778 \end_inset
8783
8779
8784 ) about IPP and LazyPython I tried to join all three into a unified system.
8780 ) about IPP and LazyPython I tried to join all three into a unified system.
8785 I thought this could provide a very nice working environment, both for
8781 I thought this could provide a very nice working environment, both for
8786 regular programming and scientific computing: shell-like features, IDL/Matlab
8782 regular programming and scientific computing: shell-like features, IDL/Matlab
8787 numerics, Mathematica-type prompt history and great object introspection
8783 numerics, Mathematica-type prompt history and great object introspection
8788 and help facilities.
8784 and help facilities.
8789 I think it worked reasonably well, though it was a lot more work than I
8785 I think it worked reasonably well, though it was a lot more work than I
8790 had initially planned.
8786 had initially planned.
8791 \layout Subsection
8787 \layout Subsection
8792
8788
8793 Current status
8789 Current status
8794 \layout Standard
8790 \layout Standard
8795
8791
8796 The above listed features work, and quite well for the most part.
8792 The above listed features work, and quite well for the most part.
8797 But until a major internal restructuring is done (see below), only bug
8793 But until a major internal restructuring is done (see below), only bug
8798 fixing will be done, no other features will be added (unless very minor
8794 fixing will be done, no other features will be added (unless very minor
8799 and well localized in the cleaner parts of the code).
8795 and well localized in the cleaner parts of the code).
8800 \layout Standard
8796 \layout Standard
8801
8797
8802 IPython consists of some 18000 lines of pure python code, of which roughly
8798 IPython consists of some 18000 lines of pure python code, of which roughly
8803 two thirds is reasonably clean.
8799 two thirds is reasonably clean.
8804 The rest is, messy code which needs a massive restructuring before any
8800 The rest is, messy code which needs a massive restructuring before any
8805 further major work is done.
8801 further major work is done.
8806 Even the messy code is fairly well documented though, and most of the problems
8802 Even the messy code is fairly well documented though, and most of the problems
8807 in the (non-existent) class design are well pointed to by a PyChecker run.
8803 in the (non-existent) class design are well pointed to by a PyChecker run.
8808 So the rewriting work isn't that bad, it will just be time-consuming.
8804 So the rewriting work isn't that bad, it will just be time-consuming.
8809 \layout Subsection
8805 \layout Subsection
8810
8806
8811 Future
8807 Future
8812 \layout Standard
8808 \layout Standard
8813
8809
8814 See the separate
8810 See the separate
8815 \family typewriter
8811 \family typewriter
8816 new_design
8812 new_design
8817 \family default
8813 \family default
8818 document for details.
8814 document for details.
8819 Ultimately, I would like to see IPython become part of the standard Python
8815 Ultimately, I would like to see IPython become part of the standard Python
8820 distribution as a `big brother with batteries' to the standard Python interacti
8816 distribution as a `big brother with batteries' to the standard Python interacti
8821 ve interpreter.
8817 ve interpreter.
8822 But that will never happen with the current state of the code, so all contribut
8818 But that will never happen with the current state of the code, so all contribut
8823 ions are welcome.
8819 ions are welcome.
8824 \layout Section
8820 \layout Section
8825
8821
8826 License
8822 License
8827 \layout Standard
8823 \layout Standard
8828
8824
8829 IPython is released under the terms of the BSD license, whose general form
8825 IPython is released under the terms of the BSD license, whose general form
8830 can be found at:
8826 can be found at:
8831 \begin_inset LatexCommand \htmlurl{http://www.opensource.org/licenses/bsd-license.php}
8827 \begin_inset LatexCommand \htmlurl{http://www.opensource.org/licenses/bsd-license.php}
8832
8828
8833 \end_inset
8829 \end_inset
8834
8830
8835 .
8831 .
8836 The full text of the IPython license is reproduced below:
8832 The full text of the IPython license is reproduced below:
8837 \layout Quote
8833 \layout Quote
8838
8834
8839
8835
8840 \family typewriter
8836 \family typewriter
8841 \size small
8837 \size small
8842 IPython is released under a BSD-type license.
8838 IPython is released under a BSD-type license.
8843 \layout Quote
8839 \layout Quote
8844
8840
8845
8841
8846 \family typewriter
8842 \family typewriter
8847 \size small
8843 \size small
8848 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez <fperez@colorado.edu>.
8844 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez <fperez@colorado.edu>.
8849 \layout Quote
8845 \layout Quote
8850
8846
8851
8847
8852 \family typewriter
8848 \family typewriter
8853 \size small
8849 \size small
8854 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
8850 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
8855 \newline
8851 \newline
8856 Nathaniel Gray <n8gray@caltech.edu>.
8852 Nathaniel Gray <n8gray@caltech.edu>.
8857 \layout Quote
8853 \layout Quote
8858
8854
8859
8855
8860 \family typewriter
8856 \family typewriter
8861 \size small
8857 \size small
8862 All rights reserved.
8858 All rights reserved.
8863 \layout Quote
8859 \layout Quote
8864
8860
8865
8861
8866 \family typewriter
8862 \family typewriter
8867 \size small
8863 \size small
8868 Redistribution and use in source and binary forms, with or without modification,
8864 Redistribution and use in source and binary forms, with or without modification,
8869 are permitted provided that the following conditions are met:
8865 are permitted provided that the following conditions are met:
8870 \layout Quote
8866 \layout Quote
8871
8867
8872
8868
8873 \family typewriter
8869 \family typewriter
8874 \size small
8870 \size small
8875 a.
8871 a.
8876 Redistributions of source code must retain the above copyright notice,
8872 Redistributions of source code must retain the above copyright notice,
8877 this list of conditions and the following disclaimer.
8873 this list of conditions and the following disclaimer.
8878 \layout Quote
8874 \layout Quote
8879
8875
8880
8876
8881 \family typewriter
8877 \family typewriter
8882 \size small
8878 \size small
8883 b.
8879 b.
8884 Redistributions in binary form must reproduce the above copyright notice,
8880 Redistributions in binary form must reproduce the above copyright notice,
8885 this list of conditions and the following disclaimer in the documentation
8881 this list of conditions and the following disclaimer in the documentation
8886 and/or other materials provided with the distribution.
8882 and/or other materials provided with the distribution.
8887 \layout Quote
8883 \layout Quote
8888
8884
8889
8885
8890 \family typewriter
8886 \family typewriter
8891 \size small
8887 \size small
8892 c.
8888 c.
8893 Neither the name of the copyright holders nor the names of any contributors
8889 Neither the name of the copyright holders nor the names of any contributors
8894 to this software may be used to endorse or promote products derived from
8890 to this software may be used to endorse or promote products derived from
8895 this software without specific prior written permission.
8891 this software without specific prior written permission.
8896 \layout Quote
8892 \layout Quote
8897
8893
8898
8894
8899 \family typewriter
8895 \family typewriter
8900 \size small
8896 \size small
8901 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
8897 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
8902 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8898 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8903 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
8899 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
8904 PURPOSE ARE DISCLAIMED.
8900 PURPOSE ARE DISCLAIMED.
8905 IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8901 IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8906 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
8902 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
8907 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
8903 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
8908 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
8904 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
8909 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8905 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8910 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8906 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8911 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8907 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8912
8908
8913 \layout Standard
8909 \layout Standard
8914
8910
8915 Individual authors are the holders of the copyright for their code and are
8911 Individual authors are the holders of the copyright for their code and are
8916 listed in each file.
8912 listed in each file.
8917 \layout Standard
8913 \layout Standard
8918
8914
8919 Some files (
8915 Some files (
8920 \family typewriter
8916 \family typewriter
8921 DPyGetOpt.py
8917 DPyGetOpt.py
8922 \family default
8918 \family default
8923 , for example) may be licensed under different conditions.
8919 , for example) may be licensed under different conditions.
8924 Ultimately each file indicates clearly the conditions under which its author/au
8920 Ultimately each file indicates clearly the conditions under which its author/au
8925 thors have decided to publish the code.
8921 thors have decided to publish the code.
8926 \layout Standard
8922 \layout Standard
8927
8923
8928 Versions of IPython up to and including 0.6.3 were released under the GNU
8924 Versions of IPython up to and including 0.6.3 were released under the GNU
8929 Lesser General Public License (LGPL), available at
8925 Lesser General Public License (LGPL), available at
8930 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/copyleft/lesser.html}
8926 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/copyleft/lesser.html}
8931
8927
8932 \end_inset
8928 \end_inset
8933
8929
8934 .
8930 .
8935 \layout Section
8931 \layout Section
8936
8932
8937
8933
8938 \begin_inset LatexCommand \label{sec:credits}
8934 \begin_inset LatexCommand \label{sec:credits}
8939
8935
8940 \end_inset
8936 \end_inset
8941
8937
8942 Credits
8938 Credits
8943 \layout Standard
8939 \layout Standard
8944
8940
8945 IPython is mainly developed by Fernando P
8941 IPython is mainly developed by Fernando P
8946 \begin_inset ERT
8942 \begin_inset ERT
8947 status Collapsed
8943 status Collapsed
8948
8944
8949 \layout Standard
8945 \layout Standard
8950
8946
8951 \backslash
8947 \backslash
8952 '{e}
8948 '{e}
8953 \end_inset
8949 \end_inset
8954
8950
8955 rez
8951 rez
8956 \family typewriter
8952 \family typewriter
8957 <Fernando.Perez@colorado.edu>
8953 <Fernando.Perez@colorado.edu>
8958 \family default
8954 \family default
8959 , but the project was born from mixing in Fernando's code with the IPP project
8955 , but the project was born from mixing in Fernando's code with the IPP project
8960 by Janko Hauser
8956 by Janko Hauser
8961 \family typewriter
8957 \family typewriter
8962 <jhauser-AT-zscout.de>
8958 <jhauser-AT-zscout.de>
8963 \family default
8959 \family default
8964 and LazyPython by Nathan Gray
8960 and LazyPython by Nathan Gray
8965 \family typewriter
8961 \family typewriter
8966 <n8gray-AT-caltech.edu>
8962 <n8gray-AT-caltech.edu>
8967 \family default
8963 \family default
8968 .
8964 .
8969 For all IPython-related requests, please contact Fernando.
8965 For all IPython-related requests, please contact Fernando.
8970
8966
8971 \layout Standard
8967 \layout Standard
8972
8968
8973 As of early 2006, the following developers have joined the core team:
8969 As of early 2006, the following developers have joined the core team:
8974 \layout List
8970 \layout List
8975 \labelwidthstring 00.00.0000
8971 \labelwidthstring 00.00.0000
8976
8972
8977 Robert\SpecialChar ~
8973 Robert\SpecialChar ~
8978 Kern
8974 Kern
8979 \family typewriter
8975 \family typewriter
8980 <rkern-AT-enthought.com>
8976 <rkern-AT-enthought.com>
8981 \family default
8977 \family default
8982 : co-mentored the 2005 Google Summer of Code project to develop python interacti
8978 : co-mentored the 2005 Google Summer of Code project to develop python interacti
8983 ve notebooks (XML documents) and graphical interface.
8979 ve notebooks (XML documents) and graphical interface.
8984 This project was awarded to the students Tzanko Matev
8980 This project was awarded to the students Tzanko Matev
8985 \family typewriter
8981 \family typewriter
8986 <tsanko-AT-gmail.com>
8982 <tsanko-AT-gmail.com>
8987 \family default
8983 \family default
8988 and Toni Alatalo
8984 and Toni Alatalo
8989 \family typewriter
8985 \family typewriter
8990 <antont-AT-an.org>
8986 <antont-AT-an.org>
8991 \layout List
8987 \layout List
8992 \labelwidthstring 00.00.0000
8988 \labelwidthstring 00.00.0000
8993
8989
8994 Brian\SpecialChar ~
8990 Brian\SpecialChar ~
8995 Granger
8991 Granger
8996 \family typewriter
8992 \family typewriter
8997 <bgranger-AT-scu.edu>
8993 <bgranger-AT-scu.edu>
8998 \family default
8994 \family default
8999 : extending IPython to allow support for interactive parallel computing.
8995 : extending IPython to allow support for interactive parallel computing.
9000 \layout List
8996 \layout List
9001 \labelwidthstring 00.00.0000
8997 \labelwidthstring 00.00.0000
9002
8998
9003 Ville\SpecialChar ~
8999 Ville\SpecialChar ~
9004 Vainio
9000 Vainio
9005 \family typewriter
9001 \family typewriter
9006 <vivainio-AT-gmail.com>
9002 <vivainio-AT-gmail.com>
9007 \family default
9003 \family default
9008 : Ville is the new maintainer for the main trunk of IPython after version
9004 : Ville is the new maintainer for the main trunk of IPython after version
9009 0.7.1.
9005 0.7.1.
9010 \layout Standard
9006 \layout Standard
9011
9007
9012 User or development help should be requested via the IPython mailing lists:
9008 User or development help should be requested via the IPython mailing lists:
9013 \layout Description
9009 \layout Description
9014
9010
9015 User\SpecialChar ~
9011 User\SpecialChar ~
9016 list:
9012 list:
9017 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-user}
9013 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-user}
9018
9014
9019 \end_inset
9015 \end_inset
9020
9016
9021
9017
9022 \layout Description
9018 \layout Description
9023
9019
9024 Developer's\SpecialChar ~
9020 Developer's\SpecialChar ~
9025 list:
9021 list:
9026 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-dev}
9022 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-dev}
9027
9023
9028 \end_inset
9024 \end_inset
9029
9025
9030
9026
9031 \layout Standard
9027 \layout Standard
9032
9028
9033 The IPython project is also very grateful to
9029 The IPython project is also very grateful to
9034 \begin_inset Foot
9030 \begin_inset Foot
9035 collapsed true
9031 collapsed true
9036
9032
9037 \layout Standard
9033 \layout Standard
9038
9034
9039 I've mangled email addresses to reduce spam, since the IPython manuals can
9035 I've mangled email addresses to reduce spam, since the IPython manuals can
9040 be accessed online.
9036 be accessed online.
9041 \end_inset
9037 \end_inset
9042
9038
9043 :
9039 :
9044 \layout Standard
9040 \layout Standard
9045
9041
9046 Bill Bumgarner
9042 Bill Bumgarner
9047 \family typewriter
9043 \family typewriter
9048 <bbum-AT-friday.com>
9044 <bbum-AT-friday.com>
9049 \family default
9045 \family default
9050 : for providing the DPyGetOpt module which gives very powerful and convenient
9046 : for providing the DPyGetOpt module which gives very powerful and convenient
9051 handling of command-line options (light years ahead of what Python 2.1.1's
9047 handling of command-line options (light years ahead of what Python 2.1.1's
9052 getopt module does).
9048 getopt module does).
9053 \layout Standard
9049 \layout Standard
9054
9050
9055 Ka-Ping Yee
9051 Ka-Ping Yee
9056 \family typewriter
9052 \family typewriter
9057 <ping-AT-lfw.org>
9053 <ping-AT-lfw.org>
9058 \family default
9054 \family default
9059 : for providing the Itpl module for convenient and powerful string interpolation
9055 : for providing the Itpl module for convenient and powerful string interpolation
9060 with a much nicer syntax than formatting through the '%' operator.
9056 with a much nicer syntax than formatting through the '%' operator.
9061 \layout Standard
9057 \layout Standard
9062
9058
9063 Arnd Baecker
9059 Arnd Baecker
9064 \family typewriter
9060 \family typewriter
9065 <baecker-AT-physik.tu-dresden.de>
9061 <baecker-AT-physik.tu-dresden.de>
9066 \family default
9062 \family default
9067 : for his many very useful suggestions and comments, and lots of help with
9063 : for his many very useful suggestions and comments, and lots of help with
9068 testing and documentation checking.
9064 testing and documentation checking.
9069 Many of IPython's newer features are a result of discussions with him (bugs
9065 Many of IPython's newer features are a result of discussions with him (bugs
9070 are still my fault, not his).
9066 are still my fault, not his).
9071 \layout Standard
9067 \layout Standard
9072
9068
9073 Obviously Guido van\SpecialChar ~
9069 Obviously Guido van\SpecialChar ~
9074 Rossum and the whole Python development team, that goes
9070 Rossum and the whole Python development team, that goes
9075 without saying.
9071 without saying.
9076 \layout Standard
9072 \layout Standard
9077
9073
9078 IPython's website is generously hosted at
9074 IPython's website is generously hosted at
9079 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
9075 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
9080
9076
9081 \end_inset
9077 \end_inset
9082
9078
9083 by Enthought (
9079 by Enthought (
9084 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
9080 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
9085
9081
9086 \end_inset
9082 \end_inset
9087
9083
9088 ).
9084 ).
9089 I am very grateful to them and all of the SciPy team for their contribution.
9085 I am very grateful to them and all of the SciPy team for their contribution.
9090 \layout Standard
9086 \layout Standard
9091
9087
9092
9088
9093 \begin_inset LatexCommand \label{figgins}
9089 \begin_inset LatexCommand \label{figgins}
9094
9090
9095 \end_inset
9091 \end_inset
9096
9092
9097 Fernando would also like to thank Stephen Figgins
9093 Fernando would also like to thank Stephen Figgins
9098 \family typewriter
9094 \family typewriter
9099 <fig-AT-monitor.net>
9095 <fig-AT-monitor.net>
9100 \family default
9096 \family default
9101 , an O'Reilly Python editor.
9097 , an O'Reilly Python editor.
9102 His Oct/11/2001 article about IPP and LazyPython, was what got this project
9098 His Oct/11/2001 article about IPP and LazyPython, was what got this project
9103 started.
9099 started.
9104 You can read it at:
9100 You can read it at:
9105 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html}
9101 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html}
9106
9102
9107 \end_inset
9103 \end_inset
9108
9104
9109 .
9105 .
9110 \layout Standard
9106 \layout Standard
9111
9107
9112 And last but not least, all the kind IPython users who have emailed new
9108 And last but not least, all the kind IPython users who have emailed new
9113 code, bug reports, fixes, comments and ideas.
9109 code, bug reports, fixes, comments and ideas.
9114 A brief list follows, please let me know if I have ommitted your name by
9110 A brief list follows, please let me know if I have ommitted your name by
9115 accident:
9111 accident:
9116 \layout List
9112 \layout List
9117 \labelwidthstring 00.00.0000
9113 \labelwidthstring 00.00.0000
9118
9114
9119 Jack\SpecialChar ~
9115 Jack\SpecialChar ~
9120 Moffit
9116 Moffit
9121 \family typewriter
9117 \family typewriter
9122 <jack-AT-xiph.org>
9118 <jack-AT-xiph.org>
9123 \family default
9119 \family default
9124 Bug fixes, including the infamous color problem.
9120 Bug fixes, including the infamous color problem.
9125 This bug alone caused many lost hours and frustration, many thanks to him
9121 This bug alone caused many lost hours and frustration, many thanks to him
9126 for the fix.
9122 for the fix.
9127 I've always been a fan of Ogg & friends, now I have one more reason to
9123 I've always been a fan of Ogg & friends, now I have one more reason to
9128 like these folks.
9124 like these folks.
9129 \newline
9125 \newline
9130 Jack is also contributing with Debian packaging and many other things.
9126 Jack is also contributing with Debian packaging and many other things.
9131 \layout List
9127 \layout List
9132 \labelwidthstring 00.00.0000
9128 \labelwidthstring 00.00.0000
9133
9129
9134 Alexander\SpecialChar ~
9130 Alexander\SpecialChar ~
9135 Schmolck
9131 Schmolck
9136 \family typewriter
9132 \family typewriter
9137 <a.schmolck-AT-gmx.net>
9133 <a.schmolck-AT-gmx.net>
9138 \family default
9134 \family default
9139 Emacs work, bug reports, bug fixes, ideas, lots more.
9135 Emacs work, bug reports, bug fixes, ideas, lots more.
9140 The ipython.el mode for (X)Emacs is Alex's code, providing full support
9136 The ipython.el mode for (X)Emacs is Alex's code, providing full support
9141 for IPython under (X)Emacs.
9137 for IPython under (X)Emacs.
9142 \layout List
9138 \layout List
9143 \labelwidthstring 00.00.0000
9139 \labelwidthstring 00.00.0000
9144
9140
9145 Andrea\SpecialChar ~
9141 Andrea\SpecialChar ~
9146 Riciputi
9142 Riciputi
9147 \family typewriter
9143 \family typewriter
9148 <andrea.riciputi-AT-libero.it>
9144 <andrea.riciputi-AT-libero.it>
9149 \family default
9145 \family default
9150 Mac OSX information, Fink package management.
9146 Mac OSX information, Fink package management.
9151 \layout List
9147 \layout List
9152 \labelwidthstring 00.00.0000
9148 \labelwidthstring 00.00.0000
9153
9149
9154 Gary\SpecialChar ~
9150 Gary\SpecialChar ~
9155 Bishop
9151 Bishop
9156 \family typewriter
9152 \family typewriter
9157 <gb-AT-cs.unc.edu>
9153 <gb-AT-cs.unc.edu>
9158 \family default
9154 \family default
9159 Bug reports, and patches to work around the exception handling idiosyncracies
9155 Bug reports, and patches to work around the exception handling idiosyncracies
9160 of WxPython.
9156 of WxPython.
9161 Readline and color support for Windows.
9157 Readline and color support for Windows.
9162 \layout List
9158 \layout List
9163 \labelwidthstring 00.00.0000
9159 \labelwidthstring 00.00.0000
9164
9160
9165 Jeffrey\SpecialChar ~
9161 Jeffrey\SpecialChar ~
9166 Collins
9162 Collins
9167 \family typewriter
9163 \family typewriter
9168 <Jeff.Collins-AT-vexcel.com>
9164 <Jeff.Collins-AT-vexcel.com>
9169 \family default
9165 \family default
9170 Bug reports.
9166 Bug reports.
9171 Much improved readline support, including fixes for Python 2.3.
9167 Much improved readline support, including fixes for Python 2.3.
9172 \layout List
9168 \layout List
9173 \labelwidthstring 00.00.0000
9169 \labelwidthstring 00.00.0000
9174
9170
9175 Dryice\SpecialChar ~
9171 Dryice\SpecialChar ~
9176 Liu
9172 Liu
9177 \family typewriter
9173 \family typewriter
9178 <dryice-AT-liu.com.cn>
9174 <dryice-AT-liu.com.cn>
9179 \family default
9175 \family default
9180 FreeBSD port.
9176 FreeBSD port.
9181 \layout List
9177 \layout List
9182 \labelwidthstring 00.00.0000
9178 \labelwidthstring 00.00.0000
9183
9179
9184 Mike\SpecialChar ~
9180 Mike\SpecialChar ~
9185 Heeter
9181 Heeter
9186 \family typewriter
9182 \family typewriter
9187 <korora-AT-SDF.LONESTAR.ORG>
9183 <korora-AT-SDF.LONESTAR.ORG>
9188 \layout List
9184 \layout List
9189 \labelwidthstring 00.00.0000
9185 \labelwidthstring 00.00.0000
9190
9186
9191 Christopher\SpecialChar ~
9187 Christopher\SpecialChar ~
9192 Hart
9188 Hart
9193 \family typewriter
9189 \family typewriter
9194 <hart-AT-caltech.edu>
9190 <hart-AT-caltech.edu>
9195 \family default
9191 \family default
9196 PDB integration.
9192 PDB integration.
9197 \layout List
9193 \layout List
9198 \labelwidthstring 00.00.0000
9194 \labelwidthstring 00.00.0000
9199
9195
9200 Milan\SpecialChar ~
9196 Milan\SpecialChar ~
9201 Zamazal
9197 Zamazal
9202 \family typewriter
9198 \family typewriter
9203 <pdm-AT-zamazal.org>
9199 <pdm-AT-zamazal.org>
9204 \family default
9200 \family default
9205 Emacs info.
9201 Emacs info.
9206 \layout List
9202 \layout List
9207 \labelwidthstring 00.00.0000
9203 \labelwidthstring 00.00.0000
9208
9204
9209 Philip\SpecialChar ~
9205 Philip\SpecialChar ~
9210 Hisley
9206 Hisley
9211 \family typewriter
9207 \family typewriter
9212 <compsys-AT-starpower.net>
9208 <compsys-AT-starpower.net>
9213 \layout List
9209 \layout List
9214 \labelwidthstring 00.00.0000
9210 \labelwidthstring 00.00.0000
9215
9211
9216 Holger\SpecialChar ~
9212 Holger\SpecialChar ~
9217 Krekel
9213 Krekel
9218 \family typewriter
9214 \family typewriter
9219 <pyth-AT-devel.trillke.net>
9215 <pyth-AT-devel.trillke.net>
9220 \family default
9216 \family default
9221 Tab completion, lots more.
9217 Tab completion, lots more.
9222 \layout List
9218 \layout List
9223 \labelwidthstring 00.00.0000
9219 \labelwidthstring 00.00.0000
9224
9220
9225 Robin\SpecialChar ~
9221 Robin\SpecialChar ~
9226 Siebler
9222 Siebler
9227 \family typewriter
9223 \family typewriter
9228 <robinsiebler-AT-starband.net>
9224 <robinsiebler-AT-starband.net>
9229 \layout List
9225 \layout List
9230 \labelwidthstring 00.00.0000
9226 \labelwidthstring 00.00.0000
9231
9227
9232 Ralf\SpecialChar ~
9228 Ralf\SpecialChar ~
9233 Ahlbrink
9229 Ahlbrink
9234 \family typewriter
9230 \family typewriter
9235 <ralf_ahlbrink-AT-web.de>
9231 <ralf_ahlbrink-AT-web.de>
9236 \layout List
9232 \layout List
9237 \labelwidthstring 00.00.0000
9233 \labelwidthstring 00.00.0000
9238
9234
9239 Thorsten\SpecialChar ~
9235 Thorsten\SpecialChar ~
9240 Kampe
9236 Kampe
9241 \family typewriter
9237 \family typewriter
9242 <thorsten-AT-thorstenkampe.de>
9238 <thorsten-AT-thorstenkampe.de>
9243 \layout List
9239 \layout List
9244 \labelwidthstring 00.00.0000
9240 \labelwidthstring 00.00.0000
9245
9241
9246 Fredrik\SpecialChar ~
9242 Fredrik\SpecialChar ~
9247 Kant
9243 Kant
9248 \family typewriter
9244 \family typewriter
9249 <fredrik.kant-AT-front.com>
9245 <fredrik.kant-AT-front.com>
9250 \family default
9246 \family default
9251 Windows setup.
9247 Windows setup.
9252 \layout List
9248 \layout List
9253 \labelwidthstring 00.00.0000
9249 \labelwidthstring 00.00.0000
9254
9250
9255 Syver\SpecialChar ~
9251 Syver\SpecialChar ~
9256 Enstad
9252 Enstad
9257 \family typewriter
9253 \family typewriter
9258 <syver-en-AT-online.no>
9254 <syver-en-AT-online.no>
9259 \family default
9255 \family default
9260 Windows setup.
9256 Windows setup.
9261 \layout List
9257 \layout List
9262 \labelwidthstring 00.00.0000
9258 \labelwidthstring 00.00.0000
9263
9259
9264 Richard
9260 Richard
9265 \family typewriter
9261 \family typewriter
9266 <rxe-AT-renre-europe.com>
9262 <rxe-AT-renre-europe.com>
9267 \family default
9263 \family default
9268 Global embedding.
9264 Global embedding.
9269 \layout List
9265 \layout List
9270 \labelwidthstring 00.00.0000
9266 \labelwidthstring 00.00.0000
9271
9267
9272 Hayden\SpecialChar ~
9268 Hayden\SpecialChar ~
9273 Callow
9269 Callow
9274 \family typewriter
9270 \family typewriter
9275 <h.callow-AT-elec.canterbury.ac.nz>
9271 <h.callow-AT-elec.canterbury.ac.nz>
9276 \family default
9272 \family default
9277 Gnuplot.py 1.6 compatibility.
9273 Gnuplot.py 1.6 compatibility.
9278 \layout List
9274 \layout List
9279 \labelwidthstring 00.00.0000
9275 \labelwidthstring 00.00.0000
9280
9276
9281 Leonardo\SpecialChar ~
9277 Leonardo\SpecialChar ~
9282 Santagada
9278 Santagada
9283 \family typewriter
9279 \family typewriter
9284 <retype-AT-terra.com.br>
9280 <retype-AT-terra.com.br>
9285 \family default
9281 \family default
9286 Fixes for Windows installation.
9282 Fixes for Windows installation.
9287 \layout List
9283 \layout List
9288 \labelwidthstring 00.00.0000
9284 \labelwidthstring 00.00.0000
9289
9285
9290 Christopher\SpecialChar ~
9286 Christopher\SpecialChar ~
9291 Armstrong
9287 Armstrong
9292 \family typewriter
9288 \family typewriter
9293 <radix-AT-twistedmatrix.com>
9289 <radix-AT-twistedmatrix.com>
9294 \family default
9290 \family default
9295 Bugfixes.
9291 Bugfixes.
9296 \layout List
9292 \layout List
9297 \labelwidthstring 00.00.0000
9293 \labelwidthstring 00.00.0000
9298
9294
9299 Francois\SpecialChar ~
9295 Francois\SpecialChar ~
9300 Pinard
9296 Pinard
9301 \family typewriter
9297 \family typewriter
9302 <pinard-AT-iro.umontreal.ca>
9298 <pinard-AT-iro.umontreal.ca>
9303 \family default
9299 \family default
9304 Code and documentation fixes.
9300 Code and documentation fixes.
9305 \layout List
9301 \layout List
9306 \labelwidthstring 00.00.0000
9302 \labelwidthstring 00.00.0000
9307
9303
9308 Cory\SpecialChar ~
9304 Cory\SpecialChar ~
9309 Dodt
9305 Dodt
9310 \family typewriter
9306 \family typewriter
9311 <cdodt-AT-fcoe.k12.ca.us>
9307 <cdodt-AT-fcoe.k12.ca.us>
9312 \family default
9308 \family default
9313 Bug reports and Windows ideas.
9309 Bug reports and Windows ideas.
9314 Patches for Windows installer.
9310 Patches for Windows installer.
9315 \layout List
9311 \layout List
9316 \labelwidthstring 00.00.0000
9312 \labelwidthstring 00.00.0000
9317
9313
9318 Olivier\SpecialChar ~
9314 Olivier\SpecialChar ~
9319 Aubert
9315 Aubert
9320 \family typewriter
9316 \family typewriter
9321 <oaubert-AT-bat710.univ-lyon1.fr>
9317 <oaubert-AT-bat710.univ-lyon1.fr>
9322 \family default
9318 \family default
9323 New magics.
9319 New magics.
9324 \layout List
9320 \layout List
9325 \labelwidthstring 00.00.0000
9321 \labelwidthstring 00.00.0000
9326
9322
9327 King\SpecialChar ~
9323 King\SpecialChar ~
9328 C.\SpecialChar ~
9324 C.\SpecialChar ~
9329 Shu
9325 Shu
9330 \family typewriter
9326 \family typewriter
9331 <kingshu-AT-myrealbox.com>
9327 <kingshu-AT-myrealbox.com>
9332 \family default
9328 \family default
9333 Autoindent patch.
9329 Autoindent patch.
9334 \layout List
9330 \layout List
9335 \labelwidthstring 00.00.0000
9331 \labelwidthstring 00.00.0000
9336
9332
9337 Chris\SpecialChar ~
9333 Chris\SpecialChar ~
9338 Drexler
9334 Drexler
9339 \family typewriter
9335 \family typewriter
9340 <chris-AT-ac-drexler.de>
9336 <chris-AT-ac-drexler.de>
9341 \family default
9337 \family default
9342 Readline packages for Win32/CygWin.
9338 Readline packages for Win32/CygWin.
9343 \layout List
9339 \layout List
9344 \labelwidthstring 00.00.0000
9340 \labelwidthstring 00.00.0000
9345
9341
9346 Gustavo\SpecialChar ~
9342 Gustavo\SpecialChar ~
9347 Cordova\SpecialChar ~
9343 Cordova\SpecialChar ~
9348 Avila
9344 Avila
9349 \family typewriter
9345 \family typewriter
9350 <gcordova-AT-sismex.com>
9346 <gcordova-AT-sismex.com>
9351 \family default
9347 \family default
9352 EvalDict code for nice, lightweight string interpolation.
9348 EvalDict code for nice, lightweight string interpolation.
9353 \layout List
9349 \layout List
9354 \labelwidthstring 00.00.0000
9350 \labelwidthstring 00.00.0000
9355
9351
9356 Kasper\SpecialChar ~
9352 Kasper\SpecialChar ~
9357 Souren
9353 Souren
9358 \family typewriter
9354 \family typewriter
9359 <Kasper.Souren-AT-ircam.fr>
9355 <Kasper.Souren-AT-ircam.fr>
9360 \family default
9356 \family default
9361 Bug reports, ideas.
9357 Bug reports, ideas.
9362 \layout List
9358 \layout List
9363 \labelwidthstring 00.00.0000
9359 \labelwidthstring 00.00.0000
9364
9360
9365 Gever\SpecialChar ~
9361 Gever\SpecialChar ~
9366 Tulley
9362 Tulley
9367 \family typewriter
9363 \family typewriter
9368 <gever-AT-helium.com>
9364 <gever-AT-helium.com>
9369 \family default
9365 \family default
9370 Code contributions.
9366 Code contributions.
9371 \layout List
9367 \layout List
9372 \labelwidthstring 00.00.0000
9368 \labelwidthstring 00.00.0000
9373
9369
9374 Ralf\SpecialChar ~
9370 Ralf\SpecialChar ~
9375 Schmitt
9371 Schmitt
9376 \family typewriter
9372 \family typewriter
9377 <ralf-AT-brainbot.com>
9373 <ralf-AT-brainbot.com>
9378 \family default
9374 \family default
9379 Bug reports & fixes.
9375 Bug reports & fixes.
9380 \layout List
9376 \layout List
9381 \labelwidthstring 00.00.0000
9377 \labelwidthstring 00.00.0000
9382
9378
9383 Oliver\SpecialChar ~
9379 Oliver\SpecialChar ~
9384 Sander
9380 Sander
9385 \family typewriter
9381 \family typewriter
9386 <osander-AT-gmx.de>
9382 <osander-AT-gmx.de>
9387 \family default
9383 \family default
9388 Bug reports.
9384 Bug reports.
9389 \layout List
9385 \layout List
9390 \labelwidthstring 00.00.0000
9386 \labelwidthstring 00.00.0000
9391
9387
9392 Rod\SpecialChar ~
9388 Rod\SpecialChar ~
9393 Holland
9389 Holland
9394 \family typewriter
9390 \family typewriter
9395 <rhh-AT-structurelabs.com>
9391 <rhh-AT-structurelabs.com>
9396 \family default
9392 \family default
9397 Bug reports and fixes to logging module.
9393 Bug reports and fixes to logging module.
9398 \layout List
9394 \layout List
9399 \labelwidthstring 00.00.0000
9395 \labelwidthstring 00.00.0000
9400
9396
9401 Daniel\SpecialChar ~
9397 Daniel\SpecialChar ~
9402 'Dang'\SpecialChar ~
9398 'Dang'\SpecialChar ~
9403 Griffith
9399 Griffith
9404 \family typewriter
9400 \family typewriter
9405 <pythondev-dang-AT-lazytwinacres.net>
9401 <pythondev-dang-AT-lazytwinacres.net>
9406 \family default
9402 \family default
9407 Fixes, enhancement suggestions for system shell use.
9403 Fixes, enhancement suggestions for system shell use.
9408 \layout List
9404 \layout List
9409 \labelwidthstring 00.00.0000
9405 \labelwidthstring 00.00.0000
9410
9406
9411 Viktor\SpecialChar ~
9407 Viktor\SpecialChar ~
9412 Ransmayr
9408 Ransmayr
9413 \family typewriter
9409 \family typewriter
9414 <viktor.ransmayr-AT-t-online.de>
9410 <viktor.ransmayr-AT-t-online.de>
9415 \family default
9411 \family default
9416 Tests and reports on Windows installation issues.
9412 Tests and reports on Windows installation issues.
9417 Contributed a true Windows binary installer.
9413 Contributed a true Windows binary installer.
9418 \layout List
9414 \layout List
9419 \labelwidthstring 00.00.0000
9415 \labelwidthstring 00.00.0000
9420
9416
9421 Mike\SpecialChar ~
9417 Mike\SpecialChar ~
9422 Salib
9418 Salib
9423 \family typewriter
9419 \family typewriter
9424 <msalib-AT-mit.edu>
9420 <msalib-AT-mit.edu>
9425 \family default
9421 \family default
9426 Help fixing a subtle bug related to traceback printing.
9422 Help fixing a subtle bug related to traceback printing.
9427 \layout List
9423 \layout List
9428 \labelwidthstring 00.00.0000
9424 \labelwidthstring 00.00.0000
9429
9425
9430 W.J.\SpecialChar ~
9426 W.J.\SpecialChar ~
9431 van\SpecialChar ~
9427 van\SpecialChar ~
9432 der\SpecialChar ~
9428 der\SpecialChar ~
9433 Laan
9429 Laan
9434 \family typewriter
9430 \family typewriter
9435 <gnufnork-AT-hetdigitalegat.nl>
9431 <gnufnork-AT-hetdigitalegat.nl>
9436 \family default
9432 \family default
9437 Bash-like prompt specials.
9433 Bash-like prompt specials.
9438 \layout List
9434 \layout List
9439 \labelwidthstring 00.00.0000
9435 \labelwidthstring 00.00.0000
9440
9436
9441 Antoon\SpecialChar ~
9437 Antoon\SpecialChar ~
9442 Pardon
9438 Pardon
9443 \family typewriter
9439 \family typewriter
9444 <Antoon.Pardon-AT-rece.vub.ac.be>
9440 <Antoon.Pardon-AT-rece.vub.ac.be>
9445 \family default
9441 \family default
9446 Critical fix for the multithreaded IPython.
9442 Critical fix for the multithreaded IPython.
9447 \layout List
9443 \layout List
9448 \labelwidthstring 00.00.0000
9444 \labelwidthstring 00.00.0000
9449
9445
9450 John\SpecialChar ~
9446 John\SpecialChar ~
9451 Hunter
9447 Hunter
9452 \family typewriter
9448 \family typewriter
9453 <jdhunter-AT-nitace.bsd.uchicago.edu>
9449 <jdhunter-AT-nitace.bsd.uchicago.edu>
9454 \family default
9450 \family default
9455 Matplotlib author, helped with all the development of support for matplotlib
9451 Matplotlib author, helped with all the development of support for matplotlib
9456 in IPyhton, including making necessary changes to matplotlib itself.
9452 in IPyhton, including making necessary changes to matplotlib itself.
9457 \layout List
9453 \layout List
9458 \labelwidthstring 00.00.0000
9454 \labelwidthstring 00.00.0000
9459
9455
9460 Matthew\SpecialChar ~
9456 Matthew\SpecialChar ~
9461 Arnison
9457 Arnison
9462 \family typewriter
9458 \family typewriter
9463 <maffew-AT-cat.org.au>
9459 <maffew-AT-cat.org.au>
9464 \family default
9460 \family default
9465 Bug reports, `
9461 Bug reports, `
9466 \family typewriter
9462 \family typewriter
9467 %run -d
9463 %run -d
9468 \family default
9464 \family default
9469 ' idea.
9465 ' idea.
9470 \layout List
9466 \layout List
9471 \labelwidthstring 00.00.0000
9467 \labelwidthstring 00.00.0000
9472
9468
9473 Prabhu\SpecialChar ~
9469 Prabhu\SpecialChar ~
9474 Ramachandran
9470 Ramachandran
9475 \family typewriter
9471 \family typewriter
9476 <prabhu_r-AT-users.sourceforge.net>
9472 <prabhu_r-AT-users.sourceforge.net>
9477 \family default
9473 \family default
9478 Help with (X)Emacs support, threading patches, ideas...
9474 Help with (X)Emacs support, threading patches, ideas...
9479 \layout List
9475 \layout List
9480 \labelwidthstring 00.00.0000
9476 \labelwidthstring 00.00.0000
9481
9477
9482 Norbert\SpecialChar ~
9478 Norbert\SpecialChar ~
9483 Tretkowski
9479 Tretkowski
9484 \family typewriter
9480 \family typewriter
9485 <tretkowski-AT-inittab.de>
9481 <tretkowski-AT-inittab.de>
9486 \family default
9482 \family default
9487 help with Debian packaging and distribution.
9483 help with Debian packaging and distribution.
9488 \layout List
9484 \layout List
9489 \labelwidthstring 00.00.0000
9485 \labelwidthstring 00.00.0000
9490
9486
9491 George\SpecialChar ~
9487 George\SpecialChar ~
9492 Sakkis <
9488 Sakkis <
9493 \family typewriter
9489 \family typewriter
9494 gsakkis-AT-eden.rutgers.edu>
9490 gsakkis-AT-eden.rutgers.edu>
9495 \family default
9491 \family default
9496 New matcher for tab-completing named arguments of user-defined functions.
9492 New matcher for tab-completing named arguments of user-defined functions.
9497 \layout List
9493 \layout List
9498 \labelwidthstring 00.00.0000
9494 \labelwidthstring 00.00.0000
9499
9495
9500 JοΏ½rgen\SpecialChar ~
9496 JοΏ½rgen\SpecialChar ~
9501 Stenarson
9497 Stenarson
9502 \family typewriter
9498 \family typewriter
9503 <jorgen.stenarson-AT-bostream.nu>
9499 <jorgen.stenarson-AT-bostream.nu>
9504 \family default
9500 \family default
9505 Wildcard support implementation for searching namespaces.
9501 Wildcard support implementation for searching namespaces.
9506 \layout List
9502 \layout List
9507 \labelwidthstring 00.00.0000
9503 \labelwidthstring 00.00.0000
9508
9504
9509 Vivian\SpecialChar ~
9505 Vivian\SpecialChar ~
9510 De\SpecialChar ~
9506 De\SpecialChar ~
9511 Smedt
9507 Smedt
9512 \family typewriter
9508 \family typewriter
9513 <vivian-AT-vdesmedt.com>
9509 <vivian-AT-vdesmedt.com>
9514 \family default
9510 \family default
9515 Debugger enhancements, so that when pdb is activated from within IPython,
9511 Debugger enhancements, so that when pdb is activated from within IPython,
9516 coloring, tab completion and other features continue to work seamlessly.
9512 coloring, tab completion and other features continue to work seamlessly.
9517 \layout List
9513 \layout List
9518 \labelwidthstring 00.00.0000
9514 \labelwidthstring 00.00.0000
9519
9515
9520 Scott\SpecialChar ~
9516 Scott\SpecialChar ~
9521 Tsai
9517 Tsai
9522 \family typewriter
9518 \family typewriter
9523 <scottt958-AT-yahoo.com.tw>
9519 <scottt958-AT-yahoo.com.tw>
9524 \family default
9520 \family default
9525 Support for automatic editor invocation on syntax errors (see
9521 Support for automatic editor invocation on syntax errors (see
9526 \begin_inset LatexCommand \htmlurl{http://www.scipy.net/roundup/ipython/issue36}
9522 \begin_inset LatexCommand \htmlurl{http://www.scipy.net/roundup/ipython/issue36}
9527
9523
9528 \end_inset
9524 \end_inset
9529
9525
9530 ).
9526 ).
9531 \layout List
9527 \layout List
9532 \labelwidthstring 00.00.0000
9528 \labelwidthstring 00.00.0000
9533
9529
9534 Alexander\SpecialChar ~
9530 Alexander\SpecialChar ~
9535 Belchenko
9531 Belchenko
9536 \family typewriter
9532 \family typewriter
9537 <bialix-AT-ukr.net>
9533 <bialix-AT-ukr.net>
9538 \family default
9534 \family default
9539 Improvements for win32 paging system.
9535 Improvements for win32 paging system.
9540 \layout List
9536 \layout List
9541 \labelwidthstring 00.00.0000
9537 \labelwidthstring 00.00.0000
9542
9538
9543 Will\SpecialChar ~
9539 Will\SpecialChar ~
9544 Maier
9540 Maier
9545 \family typewriter
9541 \family typewriter
9546 <willmaier-AT-ml1.net>
9542 <willmaier-AT-ml1.net>
9547 \family default
9543 \family default
9548 Official OpenBSD port.
9544 Official OpenBSD port.
9549 \the_end
9545 \the_end
General Comments 0
You need to be logged in to leave comments. Login now