##// END OF EJS Templates
Finish up demo api/docs, manual improvements, other fixes. Manual work...
fperez -
Show More
@@ -1,2474 +1,2452 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 907 2005-09-24 00:59:56Z fperez $"""
4 $Id: Magic.py 908 2005-09-26 16:05:48Z fperez $"""
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-2004 Fernando Perez <fperez@colorado.edu>
8 # Copyright (C) 2001-2004 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 os,sys,inspect,pydoc,re,tempfile,pdb,bdb,time
24 import os,sys,inspect,pydoc,re,tempfile,pdb,bdb,time
25 try:
25 try:
26 import profile,pstats
26 import profile,pstats
27 except ImportError:
27 except ImportError:
28 profile = pstats = None
28 profile = pstats = None
29 from getopt import getopt
29 from getopt import getopt
30 from pprint import pprint, pformat
30 from pprint import pprint, pformat
31 from cStringIO import StringIO
31 from cStringIO import StringIO
32
32
33 # Homebrewed
33 # Homebrewed
34 from IPython.Struct import Struct
34 from IPython.Struct import Struct
35 from IPython.Itpl import Itpl, itpl, printpl,itplns
35 from IPython.Itpl import Itpl, itpl, printpl,itplns
36 from IPython.FakeModule import FakeModule
36 from IPython.FakeModule import FakeModule
37 from IPython import OInspect
37 from IPython import OInspect
38 from IPython.PyColorize import Parser
38 from IPython.PyColorize import Parser
39 from IPython.genutils import *
39 from IPython.genutils import *
40
40
41 # Globals to be set later by Magic constructor
41 # Globals to be set later by Magic constructor
42 MAGIC_PREFIX = ''
42 MAGIC_PREFIX = ''
43 MAGIC_ESCAPE = ''
43 MAGIC_ESCAPE = ''
44
44
45 #***************************************************************************
45 #***************************************************************************
46 # Utility functions
46 # Utility functions
47 def magic2python(cmd):
47 def magic2python(cmd):
48 """Convert a command string of magic syntax to valid Python code."""
48 """Convert a command string of magic syntax to valid Python code."""
49
49
50 if cmd.startswith('#'+MAGIC_ESCAPE) or \
50 if cmd.startswith('#'+MAGIC_ESCAPE) or \
51 cmd.startswith(MAGIC_ESCAPE):
51 cmd.startswith(MAGIC_ESCAPE):
52 if cmd[0]=='#':
52 if cmd[0]=='#':
53 cmd = cmd[1:]
53 cmd = cmd[1:]
54 # we need to return the proper line end later
54 # we need to return the proper line end later
55 if cmd[-1] == '\n':
55 if cmd[-1] == '\n':
56 endl = '\n'
56 endl = '\n'
57 else:
57 else:
58 endl = ''
58 endl = ''
59 try:
59 try:
60 func,args = cmd[1:].split(' ',1)
60 func,args = cmd[1:].split(' ',1)
61 except:
61 except:
62 func,args = cmd[1:].rstrip(),''
62 func,args = cmd[1:].rstrip(),''
63 args = args.replace('"','\\"').replace("'","\\'").rstrip()
63 args = args.replace('"','\\"').replace("'","\\'").rstrip()
64 return '%s%s ("%s")%s' % (MAGIC_PREFIX,func,args,endl)
64 return '%s%s ("%s")%s' % (MAGIC_PREFIX,func,args,endl)
65 else:
65 else:
66 return cmd
66 return cmd
67
67
68 def on_off(tag):
68 def on_off(tag):
69 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
69 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
70 return ['OFF','ON'][tag]
70 return ['OFF','ON'][tag]
71
71
72 def get_py_filename(name):
73 """Return a valid python filename in the current directory.
74
75 If the given name is not a file, it adds '.py' and searches again.
76 Raises IOError with an informative message if the file isn't found."""
77
78 name = os.path.expanduser(name)
79 if not os.path.isfile(name) and not name.endswith('.py'):
80 name += '.py'
81 if os.path.isfile(name):
82 return name
83 else:
84 raise IOError,'File `%s` not found.' % name
85
86
72
87 #****************************************************************************
73 #****************************************************************************
88 # Utility classes
74 # Utility classes
89 class Macro:
75 class Macro:
90 """Simple class to store the value of macros as strings.
76 """Simple class to store the value of macros as strings.
91
77
92 This allows us to later exec them by checking when something is an
78 This allows us to later exec them by checking when something is an
93 instance of this class."""
79 instance of this class."""
94
80
95 def __init__(self,cmds):
81 def __init__(self,cmds):
96 """Build a macro from a list of commands."""
82 """Build a macro from a list of commands."""
97
83
98 # Since the list may include multi-line entries, first make sure that
84 # Since the list may include multi-line entries, first make sure that
99 # they've been all broken up before passing it to magic2python
85 # they've been all broken up before passing it to magic2python
100 cmdlist = map(magic2python,''.join(cmds).split('\n'))
86 cmdlist = map(magic2python,''.join(cmds).split('\n'))
101 self.value = '\n'.join(cmdlist)
87 self.value = '\n'.join(cmdlist)
102
88
103 def __str__(self):
89 def __str__(self):
104 return self.value
90 return self.value
105
91
106 #***************************************************************************
92 #***************************************************************************
107 # Main class implementing Magic functionality
93 # Main class implementing Magic functionality
108 class Magic:
94 class Magic:
109 """Magic functions for InteractiveShell.
95 """Magic functions for InteractiveShell.
110
96
111 Shell functions which can be reached as %function_name. All magic
97 Shell functions which can be reached as %function_name. All magic
112 functions should accept a string, which they can parse for their own
98 functions should accept a string, which they can parse for their own
113 needs. This can make some functions easier to type, eg `%cd ../`
99 needs. This can make some functions easier to type, eg `%cd ../`
114 vs. `%cd("../")`
100 vs. `%cd("../")`
115
101
116 ALL definitions MUST begin with the prefix magic_. The user won't need it
102 ALL definitions MUST begin with the prefix magic_. The user won't need it
117 at the command line, but it is is needed in the definition. """
103 at the command line, but it is is needed in the definition. """
118
104
119 # class globals
105 # class globals
120 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
106 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
121 'Automagic is ON, % prefix NOT needed for magic functions.']
107 'Automagic is ON, % prefix NOT needed for magic functions.']
122
108
123 #......................................................................
109 #......................................................................
124 # some utility functions
110 # some utility functions
125
111
126 def __init__(self,shell):
112 def __init__(self,shell):
127 # XXX This is hackish, clean up later to avoid these messy globals
113 # XXX This is hackish, clean up later to avoid these messy globals
128 global MAGIC_PREFIX, MAGIC_ESCAPE
114 global MAGIC_PREFIX, MAGIC_ESCAPE
129
115
130 self.options_table = {}
116 self.options_table = {}
131 MAGIC_PREFIX = shell.name+'.magic_'
117 MAGIC_PREFIX = shell.name+'.magic_'
132 MAGIC_ESCAPE = shell.ESC_MAGIC
118 MAGIC_ESCAPE = shell.ESC_MAGIC
133 if profile is None:
119 if profile is None:
134 self.magic_prun = self.profile_missing_notice
120 self.magic_prun = self.profile_missing_notice
135
121
136 def profile_missing_notice(self, *args, **kwargs):
122 def profile_missing_notice(self, *args, **kwargs):
137 error("""\
123 error("""\
138 The profile module could not be found. If you are a Debian user,
124 The profile module could not be found. If you are a Debian user,
139 it has been removed from the standard Debian package because of its non-free
125 it has been removed from the standard Debian package because of its non-free
140 license. To use profiling, please install"python2.3-profiler" from non-free.""")
126 license. To use profiling, please install"python2.3-profiler" from non-free.""")
141
127
142 def default_option(self,fn,optstr):
128 def default_option(self,fn,optstr):
143 """Make an entry in the options_table for fn, with value optstr"""
129 """Make an entry in the options_table for fn, with value optstr"""
144
130
145 if fn not in self.lsmagic():
131 if fn not in self.lsmagic():
146 error("%s is not a magic function" % fn)
132 error("%s is not a magic function" % fn)
147 self.options_table[fn] = optstr
133 self.options_table[fn] = optstr
148
134
149 def lsmagic(self):
135 def lsmagic(self):
150 """Return a list of currently available magic functions.
136 """Return a list of currently available magic functions.
151
137
152 Gives a list of the bare names after mangling (['ls','cd', ...], not
138 Gives a list of the bare names after mangling (['ls','cd', ...], not
153 ['magic_ls','magic_cd',...]"""
139 ['magic_ls','magic_cd',...]"""
154
140
155 # FIXME. This needs a cleanup, in the way the magics list is built.
141 # FIXME. This needs a cleanup, in the way the magics list is built.
156
142
157 # magics in class definition
143 # magics in class definition
158 class_magic = lambda fn: fn.startswith('magic_') and \
144 class_magic = lambda fn: fn.startswith('magic_') and \
159 callable(Magic.__dict__[fn])
145 callable(Magic.__dict__[fn])
160 # in instance namespace (run-time user additions)
146 # in instance namespace (run-time user additions)
161 inst_magic = lambda fn: fn.startswith('magic_') and \
147 inst_magic = lambda fn: fn.startswith('magic_') and \
162 callable(self.__dict__[fn])
148 callable(self.__dict__[fn])
163 # and bound magics by user (so they can access self):
149 # and bound magics by user (so they can access self):
164 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
150 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
165 callable(self.__class__.__dict__[fn])
151 callable(self.__class__.__dict__[fn])
166 magics = filter(class_magic,Magic.__dict__.keys()) + \
152 magics = filter(class_magic,Magic.__dict__.keys()) + \
167 filter(inst_magic,self.__dict__.keys()) + \
153 filter(inst_magic,self.__dict__.keys()) + \
168 filter(inst_bound_magic,self.__class__.__dict__.keys())
154 filter(inst_bound_magic,self.__class__.__dict__.keys())
169 out = []
155 out = []
170 for fn in magics:
156 for fn in magics:
171 out.append(fn.replace('magic_','',1))
157 out.append(fn.replace('magic_','',1))
172 out.sort()
158 out.sort()
173 return out
159 return out
174
160
175 def set_shell(self,shell):
161 def set_shell(self,shell):
176 self.shell = shell
162 self.shell = shell
177 self.alias_table = shell.alias_table
163 self.alias_table = shell.alias_table
178
164
179 def extract_input_slices(self,slices):
165 def extract_input_slices(self,slices):
180 """Return as a string a set of input history slices.
166 """Return as a string a set of input history slices.
181
167
182 The set of slices is given as a list of strings (like ['1','4:8','9'],
168 The set of slices is given as a list of strings (like ['1','4:8','9'],
183 since this function is for use by magic functions which get their
169 since this function is for use by magic functions which get their
184 arguments as strings."""
170 arguments as strings."""
185
171
186 cmds = []
172 cmds = []
187 for chunk in slices:
173 for chunk in slices:
188 if ':' in chunk:
174 if ':' in chunk:
189 ini,fin = map(int,chunk.split(':'))
175 ini,fin = map(int,chunk.split(':'))
190 else:
176 else:
191 ini = int(chunk)
177 ini = int(chunk)
192 fin = ini+1
178 fin = ini+1
193 cmds.append(self.shell.input_hist[ini:fin])
179 cmds.append(self.shell.input_hist[ini:fin])
194 return cmds
180 return cmds
195
181
196 def _ofind(self,oname):
182 def _ofind(self,oname):
197 """Find an object in the available namespaces.
183 """Find an object in the available namespaces.
198
184
199 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
185 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
200
186
201 Has special code to detect magic functions.
187 Has special code to detect magic functions.
202 """
188 """
203
189
204 oname = oname.strip()
190 oname = oname.strip()
205
191
206 # Namespaces to search in:
192 # Namespaces to search in:
207 user_ns = self.shell.user_ns
193 user_ns = self.shell.user_ns
208 internal_ns = self.shell.internal_ns
194 internal_ns = self.shell.internal_ns
209 builtin_ns = __builtin__.__dict__
195 builtin_ns = __builtin__.__dict__
210 alias_ns = self.shell.alias_table
196 alias_ns = self.shell.alias_table
211
197
212 # Put them in a list. The order is important so that we find things in
198 # Put them in a list. The order is important so that we find things in
213 # the same order that Python finds them.
199 # the same order that Python finds them.
214 namespaces = [ ('Interactive',user_ns),
200 namespaces = [ ('Interactive',user_ns),
215 ('IPython internal',internal_ns),
201 ('IPython internal',internal_ns),
216 ('Python builtin',builtin_ns),
202 ('Python builtin',builtin_ns),
217 ('Alias',alias_ns),
203 ('Alias',alias_ns),
218 ]
204 ]
219
205
220 # initialize results to 'null'
206 # initialize results to 'null'
221 found = 0; obj = None; ospace = None; ds = None;
207 found = 0; obj = None; ospace = None; ds = None;
222 ismagic = 0; isalias = 0
208 ismagic = 0; isalias = 0
223
209
224 # Look for the given name by splitting it in parts. If the head is
210 # Look for the given name by splitting it in parts. If the head is
225 # found, then we look for all the remaining parts as members, and only
211 # found, then we look for all the remaining parts as members, and only
226 # declare success if we can find them all.
212 # declare success if we can find them all.
227 oname_parts = oname.split('.')
213 oname_parts = oname.split('.')
228 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
214 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
229 for nsname,ns in namespaces:
215 for nsname,ns in namespaces:
230 try:
216 try:
231 obj = ns[oname_head]
217 obj = ns[oname_head]
232 except KeyError:
218 except KeyError:
233 continue
219 continue
234 else:
220 else:
235 for part in oname_rest:
221 for part in oname_rest:
236 try:
222 try:
237 obj = getattr(obj,part)
223 obj = getattr(obj,part)
238 except:
224 except:
239 # Blanket except b/c some badly implemented objects
225 # Blanket except b/c some badly implemented objects
240 # allow __getattr__ to raise exceptions other than
226 # allow __getattr__ to raise exceptions other than
241 # AttributeError, which then crashes IPython.
227 # AttributeError, which then crashes IPython.
242 break
228 break
243 else:
229 else:
244 # If we finish the for loop (no break), we got all members
230 # If we finish the for loop (no break), we got all members
245 found = 1
231 found = 1
246 ospace = nsname
232 ospace = nsname
247 if ns == alias_ns:
233 if ns == alias_ns:
248 isalias = 1
234 isalias = 1
249 break # namespace loop
235 break # namespace loop
250
236
251 # Try to see if it's magic
237 # Try to see if it's magic
252 if not found:
238 if not found:
253 if oname.startswith(self.shell.ESC_MAGIC):
239 if oname.startswith(self.shell.ESC_MAGIC):
254 oname = oname[1:]
240 oname = oname[1:]
255 obj = getattr(self,'magic_'+oname,None)
241 obj = getattr(self,'magic_'+oname,None)
256 if obj is not None:
242 if obj is not None:
257 found = 1
243 found = 1
258 ospace = 'IPython internal'
244 ospace = 'IPython internal'
259 ismagic = 1
245 ismagic = 1
260
246
261 # Last try: special-case some literals like '', [], {}, etc:
247 # Last try: special-case some literals like '', [], {}, etc:
262 if not found and oname_head in ["''",'""','[]','{}','()']:
248 if not found and oname_head in ["''",'""','[]','{}','()']:
263 obj = eval(oname_head)
249 obj = eval(oname_head)
264 found = 1
250 found = 1
265 ospace = 'Interactive'
251 ospace = 'Interactive'
266
252
267 return {'found':found, 'obj':obj, 'namespace':ospace,
253 return {'found':found, 'obj':obj, 'namespace':ospace,
268 'ismagic':ismagic, 'isalias':isalias}
254 'ismagic':ismagic, 'isalias':isalias}
269
255
270 def arg_err(self,func):
256 def arg_err(self,func):
271 """Print docstring if incorrect arguments were passed"""
257 """Print docstring if incorrect arguments were passed"""
272 print 'Error in arguments:'
258 print 'Error in arguments:'
273 print OInspect.getdoc(func)
259 print OInspect.getdoc(func)
274
260
275
261
276 def format_latex(self,str):
262 def format_latex(self,str):
277 """Format a string for latex inclusion."""
263 """Format a string for latex inclusion."""
278
264
279 # Characters that need to be escaped for latex:
265 # Characters that need to be escaped for latex:
280 escape_re = re.compile(r'(%|_|\$)',re.MULTILINE)
266 escape_re = re.compile(r'(%|_|\$)',re.MULTILINE)
281 # Magic command names as headers:
267 # Magic command names as headers:
282 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
268 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
283 re.MULTILINE)
269 re.MULTILINE)
284 # Magic commands
270 # Magic commands
285 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
271 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
286 re.MULTILINE)
272 re.MULTILINE)
287 # Paragraph continue
273 # Paragraph continue
288 par_re = re.compile(r'\\$',re.MULTILINE)
274 par_re = re.compile(r'\\$',re.MULTILINE)
289
275
290 str = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',str)
276 str = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',str)
291 str = cmd_re.sub(r'\\texttt{\g<cmd>}',str)
277 str = cmd_re.sub(r'\\texttt{\g<cmd>}',str)
292 str = par_re.sub(r'\\\\',str)
278 str = par_re.sub(r'\\\\',str)
293 str = escape_re.sub(r'\\\1',str)
279 str = escape_re.sub(r'\\\1',str)
294 return str
280 return str
295
281
296 def format_screen(self,str):
282 def format_screen(self,str):
297 """Format a string for screen printing.
283 """Format a string for screen printing.
298
284
299 This removes some latex-type format codes."""
285 This removes some latex-type format codes."""
300 # Paragraph continue
286 # Paragraph continue
301 par_re = re.compile(r'\\$',re.MULTILINE)
287 par_re = re.compile(r'\\$',re.MULTILINE)
302 str = par_re.sub('',str)
288 str = par_re.sub('',str)
303 return str
289 return str
304
290
305 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
291 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
306 """Parse options passed to an argument string.
292 """Parse options passed to an argument string.
307
293
308 The interface is similar to that of getopt(), but it returns back a
294 The interface is similar to that of getopt(), but it returns back a
309 Struct with the options as keys and the stripped argument string still
295 Struct with the options as keys and the stripped argument string still
310 as a string.
296 as a string.
311
297
312 arg_str is quoted as a true sys.argv vector by calling on the fly a
298 arg_str is quoted as a true sys.argv vector by calling on the fly a
313 python process in a subshell. This allows us to easily expand
299 python process in a subshell. This allows us to easily expand
314 variables, glob files, quote arguments, etc, with all the power and
300 variables, glob files, quote arguments, etc, with all the power and
315 correctness of the underlying system shell.
301 correctness of the underlying system shell.
316
302
317 Options:
303 Options:
318 -mode: default 'string'. If given as 'list', the argument string is
304 -mode: default 'string'. If given as 'list', the argument string is
319 returned as a list (split on whitespace) instead of a string.
305 returned as a list (split on whitespace) instead of a string.
320
306
321 -list_all: put all option values in lists. Normally only options
307 -list_all: put all option values in lists. Normally only options
322 appearing more than once are put in a list."""
308 appearing more than once are put in a list."""
323
309
324 # inject default options at the beginning of the input line
310 # inject default options at the beginning of the input line
325 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
311 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
326 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
312 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
327
313
328 mode = kw.get('mode','string')
314 mode = kw.get('mode','string')
329 if mode not in ['string','list']:
315 if mode not in ['string','list']:
330 raise ValueError,'incorrect mode given: %s' % mode
316 raise ValueError,'incorrect mode given: %s' % mode
331 # Get options
317 # Get options
332 list_all = kw.get('list_all',0)
318 list_all = kw.get('list_all',0)
333
319
334 # Check if we have more than one argument to warrant extra processing:
320 # Check if we have more than one argument to warrant extra processing:
335 odict = {} # Dictionary with options
321 odict = {} # Dictionary with options
336 args = arg_str.split()
322 args = arg_str.split()
337 if len(args) >= 1:
323 if len(args) >= 1:
338 # If the list of inputs only has 0 or 1 thing in it, there's no
324 # If the list of inputs only has 0 or 1 thing in it, there's no
339 # need to look for options
325 # need to look for options
340 argv = shlex_split(arg_str)
326 argv = shlex_split(arg_str)
341 # Do regular option processing
327 # Do regular option processing
342 opts,args = getopt(argv,opt_str,*long_opts)
328 opts,args = getopt(argv,opt_str,*long_opts)
343 for o,a in opts:
329 for o,a in opts:
344 if o.startswith('--'):
330 if o.startswith('--'):
345 o = o[2:]
331 o = o[2:]
346 else:
332 else:
347 o = o[1:]
333 o = o[1:]
348 try:
334 try:
349 odict[o].append(a)
335 odict[o].append(a)
350 except AttributeError:
336 except AttributeError:
351 odict[o] = [odict[o],a]
337 odict[o] = [odict[o],a]
352 except KeyError:
338 except KeyError:
353 if list_all:
339 if list_all:
354 odict[o] = [a]
340 odict[o] = [a]
355 else:
341 else:
356 odict[o] = a
342 odict[o] = a
357
343
358 # Prepare opts,args for return
344 # Prepare opts,args for return
359 opts = Struct(odict)
345 opts = Struct(odict)
360 if mode == 'string':
346 if mode == 'string':
361 args = ' '.join(args)
347 args = ' '.join(args)
362
348
363 return opts,args
349 return opts,args
364
350
365 #......................................................................
351 #......................................................................
366 # And now the actual magic functions
352 # And now the actual magic functions
367
353
368 # Functions for IPython shell work (vars,funcs, config, etc)
354 # Functions for IPython shell work (vars,funcs, config, etc)
369 def magic_lsmagic(self, parameter_s = ''):
355 def magic_lsmagic(self, parameter_s = ''):
370 """List currently available magic functions."""
356 """List currently available magic functions."""
371 mesc = self.shell.ESC_MAGIC
357 mesc = self.shell.ESC_MAGIC
372 print 'Available magic functions:\n'+mesc+\
358 print 'Available magic functions:\n'+mesc+\
373 (' '+mesc).join(self.lsmagic())
359 (' '+mesc).join(self.lsmagic())
374 print '\n' + Magic.auto_status[self.shell.rc.automagic]
360 print '\n' + Magic.auto_status[self.shell.rc.automagic]
375 return None
361 return None
376
362
377 def magic_magic(self, parameter_s = ''):
363 def magic_magic(self, parameter_s = ''):
378 """Print information about the magic function system."""
364 """Print information about the magic function system."""
379
365
380 mode = ''
366 mode = ''
381 try:
367 try:
382 if parameter_s.split()[0] == '-latex':
368 if parameter_s.split()[0] == '-latex':
383 mode = 'latex'
369 mode = 'latex'
384 except:
370 except:
385 pass
371 pass
386
372
387 magic_docs = []
373 magic_docs = []
388 for fname in self.lsmagic():
374 for fname in self.lsmagic():
389 mname = 'magic_' + fname
375 mname = 'magic_' + fname
390 for space in (Magic,self,self.__class__):
376 for space in (Magic,self,self.__class__):
391 try:
377 try:
392 fn = space.__dict__[mname]
378 fn = space.__dict__[mname]
393 except KeyError:
379 except KeyError:
394 pass
380 pass
395 else:
381 else:
396 break
382 break
397 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
383 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
398 fname,fn.__doc__))
384 fname,fn.__doc__))
399 magic_docs = ''.join(magic_docs)
385 magic_docs = ''.join(magic_docs)
400
386
401 if mode == 'latex':
387 if mode == 'latex':
402 print self.format_latex(magic_docs)
388 print self.format_latex(magic_docs)
403 return
389 return
404 else:
390 else:
405 magic_docs = self.format_screen(magic_docs)
391 magic_docs = self.format_screen(magic_docs)
406
392
407 outmsg = """
393 outmsg = """
408 IPython's 'magic' functions
394 IPython's 'magic' functions
409 ===========================
395 ===========================
410
396
411 The magic function system provides a series of functions which allow you to
397 The magic function system provides a series of functions which allow you to
412 control the behavior of IPython itself, plus a lot of system-type
398 control the behavior of IPython itself, plus a lot of system-type
413 features. All these functions are prefixed with a % character, but parameters
399 features. All these functions are prefixed with a % character, but parameters
414 are given without parentheses or quotes.
400 are given without parentheses or quotes.
415
401
416 NOTE: If you have 'automagic' enabled (via the command line option or with the
402 NOTE: If you have 'automagic' enabled (via the command line option or with the
417 %automagic function), you don't need to type in the % explicitly. By default,
403 %automagic function), you don't need to type in the % explicitly. By default,
418 IPython ships with automagic on, so you should only rarely need the % escape.
404 IPython ships with automagic on, so you should only rarely need the % escape.
419
405
420 Example: typing '%cd mydir' (without the quotes) changes you working directory
406 Example: typing '%cd mydir' (without the quotes) changes you working directory
421 to 'mydir', if it exists.
407 to 'mydir', if it exists.
422
408
423 You can define your own magic functions to extend the system. See the supplied
409 You can define your own magic functions to extend the system. See the supplied
424 ipythonrc and example-magic.py files for details (in your ipython
410 ipythonrc and example-magic.py files for details (in your ipython
425 configuration directory, typically $HOME/.ipython/).
411 configuration directory, typically $HOME/.ipython/).
426
412
427 You can also define your own aliased names for magic functions. In your
413 You can also define your own aliased names for magic functions. In your
428 ipythonrc file, placing a line like:
414 ipythonrc file, placing a line like:
429
415
430 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
416 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
431
417
432 will define %pf as a new name for %profile.
418 will define %pf as a new name for %profile.
433
419
434 You can also call magics in code using the ipmagic() function, which IPython
420 You can also call magics in code using the ipmagic() function, which IPython
435 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
421 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
436
422
437 For a list of the available magic functions, use %lsmagic. For a description
423 For a list of the available magic functions, use %lsmagic. For a description
438 of any of them, type %magic_name?, e.g. '%cd?'.
424 of any of them, type %magic_name?, e.g. '%cd?'.
439
425
440 Currently the magic system has the following functions:\n"""
426 Currently the magic system has the following functions:\n"""
441
427
442 mesc = self.shell.ESC_MAGIC
428 mesc = self.shell.ESC_MAGIC
443 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
429 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
444 "\n\n%s%s\n\n%s" % (outmsg,
430 "\n\n%s%s\n\n%s" % (outmsg,
445 magic_docs,mesc,mesc,
431 magic_docs,mesc,mesc,
446 (' '+mesc).join(self.lsmagic()),
432 (' '+mesc).join(self.lsmagic()),
447 Magic.auto_status[self.shell.rc.automagic] ) )
433 Magic.auto_status[self.shell.rc.automagic] ) )
448
434
449 page(outmsg,screen_lines=self.shell.rc.screen_length)
435 page(outmsg,screen_lines=self.shell.rc.screen_length)
450
436
451 def magic_automagic(self, parameter_s = ''):
437 def magic_automagic(self, parameter_s = ''):
452 """Make magic functions callable without having to type the initial %.
438 """Make magic functions callable without having to type the initial %.
453
439
454 Toggles on/off (when off, you must call it as %automagic, of
440 Toggles on/off (when off, you must call it as %automagic, of
455 course). Note that magic functions have lowest priority, so if there's
441 course). Note that magic functions have lowest priority, so if there's
456 a variable whose name collides with that of a magic fn, automagic
442 a variable whose name collides with that of a magic fn, automagic
457 won't work for that function (you get the variable instead). However,
443 won't work for that function (you get the variable instead). However,
458 if you delete the variable (del var), the previously shadowed magic
444 if you delete the variable (del var), the previously shadowed magic
459 function becomes visible to automagic again."""
445 function becomes visible to automagic again."""
460
446
461 rc = self.shell.rc
447 rc = self.shell.rc
462 rc.automagic = not rc.automagic
448 rc.automagic = not rc.automagic
463 print '\n' + Magic.auto_status[rc.automagic]
449 print '\n' + Magic.auto_status[rc.automagic]
464
450
465 def magic_autocall(self, parameter_s = ''):
451 def magic_autocall(self, parameter_s = ''):
466 """Make functions callable without having to type parentheses.
452 """Make functions callable without having to type parentheses.
467
453
468 This toggles the autocall command line option on and off."""
454 This toggles the autocall command line option on and off."""
469
455
470 rc = self.shell.rc
456 rc = self.shell.rc
471 rc.autocall = not rc.autocall
457 rc.autocall = not rc.autocall
472 print "Automatic calling is:",['OFF','ON'][rc.autocall]
458 print "Automatic calling is:",['OFF','ON'][rc.autocall]
473
459
474 def magic_autoindent(self, parameter_s = ''):
460 def magic_autoindent(self, parameter_s = ''):
475 """Toggle autoindent on/off (if available)."""
461 """Toggle autoindent on/off (if available)."""
476
462
477 self.shell.set_autoindent()
463 self.shell.set_autoindent()
478 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
464 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
479
465
480 def magic_system_verbose(self, parameter_s = ''):
466 def magic_system_verbose(self, parameter_s = ''):
481 """Toggle verbose printing of system calls on/off."""
467 """Toggle verbose printing of system calls on/off."""
482
468
483 self.shell.rc_set_toggle('system_verbose')
469 self.shell.rc_set_toggle('system_verbose')
484 print "System verbose printing is:",\
470 print "System verbose printing is:",\
485 ['OFF','ON'][self.shell.rc.system_verbose]
471 ['OFF','ON'][self.shell.rc.system_verbose]
486
472
487 def magic_history(self, parameter_s = ''):
473 def magic_history(self, parameter_s = ''):
488 """Print input history (_i<n> variables), with most recent last.
474 """Print input history (_i<n> variables), with most recent last.
489
475
490 %history [-n] -> print at most 40 inputs (some may be multi-line)\\
476 %history [-n] -> print at most 40 inputs (some may be multi-line)\\
491 %history [-n] n -> print at most n inputs\\
477 %history [-n] n -> print at most n inputs\\
492 %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
478 %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
493
479
494 Each input's number <n> is shown, and is accessible as the
480 Each input's number <n> is shown, and is accessible as the
495 automatically generated variable _i<n>. Multi-line statements are
481 automatically generated variable _i<n>. Multi-line statements are
496 printed starting at a new line for easy copy/paste.
482 printed starting at a new line for easy copy/paste.
497
483
498 If option -n is used, input numbers are not printed. This is useful if
484 If option -n is used, input numbers are not printed. This is useful if
499 you want to get a printout of many lines which can be directly pasted
485 you want to get a printout of many lines which can be directly pasted
500 into a text editor.
486 into a text editor.
501
487
502 This feature is only available if numbered prompts are in use."""
488 This feature is only available if numbered prompts are in use."""
503
489
504 if not self.do_full_cache:
490 if not self.do_full_cache:
505 print 'This feature is only available if numbered prompts are in use.'
491 print 'This feature is only available if numbered prompts are in use.'
506 return
492 return
507 opts,args = self.parse_options(parameter_s,'n',mode='list')
493 opts,args = self.parse_options(parameter_s,'n',mode='list')
508
494
509 default_length = 40
495 default_length = 40
510 if len(args) == 0:
496 if len(args) == 0:
511 final = self.outputcache.prompt_count
497 final = self.outputcache.prompt_count
512 init = max(1,final-default_length)
498 init = max(1,final-default_length)
513 elif len(args) == 1:
499 elif len(args) == 1:
514 final = self.outputcache.prompt_count
500 final = self.outputcache.prompt_count
515 init = max(1,final-int(args[0]))
501 init = max(1,final-int(args[0]))
516 elif len(args) == 2:
502 elif len(args) == 2:
517 init,final = map(int,args)
503 init,final = map(int,args)
518 else:
504 else:
519 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
505 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
520 print self.magic_hist.__doc__
506 print self.magic_hist.__doc__
521 return
507 return
522 width = len(str(final))
508 width = len(str(final))
523 line_sep = ['','\n']
509 line_sep = ['','\n']
524 input_hist = self.shell.input_hist
510 input_hist = self.shell.input_hist
525 print_nums = not opts.has_key('n')
511 print_nums = not opts.has_key('n')
526 for in_num in range(init,final):
512 for in_num in range(init,final):
527 inline = input_hist[in_num]
513 inline = input_hist[in_num]
528 multiline = inline.count('\n') > 1
514 multiline = inline.count('\n') > 1
529 if print_nums:
515 if print_nums:
530 print str(in_num).ljust(width)+':'+ line_sep[multiline],
516 print str(in_num).ljust(width)+':'+ line_sep[multiline],
531 if inline.startswith('#'+self.shell.ESC_MAGIC) or \
517 if inline.startswith('#'+self.shell.ESC_MAGIC) or \
532 inline.startswith('#!'):
518 inline.startswith('#!'):
533 print inline[1:],
519 print inline[1:],
534 else:
520 else:
535 print inline,
521 print inline,
536
522
537 def magic_hist(self, parameter_s=''):
523 def magic_hist(self, parameter_s=''):
538 """Alternate name for %history."""
524 """Alternate name for %history."""
539 return self.magic_history(parameter_s)
525 return self.magic_history(parameter_s)
540
526
541 def magic_p(self, parameter_s=''):
527 def magic_p(self, parameter_s=''):
542 """Just a short alias for Python's 'print'."""
528 """Just a short alias for Python's 'print'."""
543 exec 'print ' + parameter_s in self.shell.user_ns
529 exec 'print ' + parameter_s in self.shell.user_ns
544
530
545 def magic_r(self, parameter_s=''):
531 def magic_r(self, parameter_s=''):
546 """Repeat previous input.
532 """Repeat previous input.
547
533
548 If given an argument, repeats the previous command which starts with
534 If given an argument, repeats the previous command which starts with
549 the same string, otherwise it just repeats the previous input.
535 the same string, otherwise it just repeats the previous input.
550
536
551 Shell escaped commands (with ! as first character) are not recognized
537 Shell escaped commands (with ! as first character) are not recognized
552 by this system, only pure python code and magic commands.
538 by this system, only pure python code and magic commands.
553 """
539 """
554
540
555 start = parameter_s.strip()
541 start = parameter_s.strip()
556 esc_magic = self.shell.ESC_MAGIC
542 esc_magic = self.shell.ESC_MAGIC
557 # Identify magic commands even if automagic is on (which means
543 # Identify magic commands even if automagic is on (which means
558 # the in-memory version is different from that typed by the user).
544 # the in-memory version is different from that typed by the user).
559 if self.shell.rc.automagic:
545 if self.shell.rc.automagic:
560 start_magic = esc_magic+start
546 start_magic = esc_magic+start
561 else:
547 else:
562 start_magic = start
548 start_magic = start
563 # Look through the input history in reverse
549 # Look through the input history in reverse
564 for n in range(len(self.shell.input_hist)-2,0,-1):
550 for n in range(len(self.shell.input_hist)-2,0,-1):
565 input = self.shell.input_hist[n]
551 input = self.shell.input_hist[n]
566 # skip plain 'r' lines so we don't recurse to infinity
552 # skip plain 'r' lines so we don't recurse to infinity
567 if input != 'ipmagic("r")\n' and \
553 if input != 'ipmagic("r")\n' and \
568 (input.startswith(start) or input.startswith(start_magic)):
554 (input.startswith(start) or input.startswith(start_magic)):
569 #print 'match',`input` # dbg
555 #print 'match',`input` # dbg
570 if input.startswith(esc_magic):
556 if input.startswith(esc_magic):
571 input = magic2python(input)
557 input = magic2python(input)
572 #print 'modified',`input` # dbg
558 #print 'modified',`input` # dbg
573 print 'Executing:',input,
559 print 'Executing:',input,
574 exec input in self.shell.user_ns
560 exec input in self.shell.user_ns
575 return
561 return
576 print 'No previous input matching `%s` found.' % start
562 print 'No previous input matching `%s` found.' % start
577
563
578 def magic_page(self, parameter_s=''):
564 def magic_page(self, parameter_s=''):
579 """Pretty print the object and display it through a pager.
565 """Pretty print the object and display it through a pager.
580
566
581 If no parameter is given, use _ (last output)."""
567 If no parameter is given, use _ (last output)."""
582 # After a function contributed by Olivier Aubert, slightly modified.
568 # After a function contributed by Olivier Aubert, slightly modified.
583
569
584 oname = parameter_s and parameter_s or '_'
570 oname = parameter_s and parameter_s or '_'
585 info = self._ofind(oname)
571 info = self._ofind(oname)
586 if info['found']:
572 if info['found']:
587 page(pformat(info['obj']))
573 page(pformat(info['obj']))
588 else:
574 else:
589 print 'Object `%s` not found' % oname
575 print 'Object `%s` not found' % oname
590
576
591 def magic_profile(self, parameter_s=''):
577 def magic_profile(self, parameter_s=''):
592 """Print your currently active IPyhton profile."""
578 """Print your currently active IPyhton profile."""
593 if self.shell.rc.profile:
579 if self.shell.rc.profile:
594 printpl('Current IPython profile: $self.shell.rc.profile.')
580 printpl('Current IPython profile: $self.shell.rc.profile.')
595 else:
581 else:
596 print 'No profile active.'
582 print 'No profile active.'
597
583
598 def _inspect(self,meth,oname,**kw):
584 def _inspect(self,meth,oname,**kw):
599 """Generic interface to the inspector system.
585 """Generic interface to the inspector system.
600
586
601 This function is meant to be called by pdef, pdoc & friends."""
587 This function is meant to be called by pdef, pdoc & friends."""
602
588
603 oname = oname.strip()
589 oname = oname.strip()
604 info = Struct(self._ofind(oname))
590 info = Struct(self._ofind(oname))
605 if info.found:
591 if info.found:
606 pmethod = getattr(self.shell.inspector,meth)
592 pmethod = getattr(self.shell.inspector,meth)
607 formatter = info.ismagic and self.format_screen or None
593 formatter = info.ismagic and self.format_screen or None
608 if meth == 'pdoc':
594 if meth == 'pdoc':
609 pmethod(info.obj,oname,formatter)
595 pmethod(info.obj,oname,formatter)
610 elif meth == 'pinfo':
596 elif meth == 'pinfo':
611 pmethod(info.obj,oname,formatter,info,**kw)
597 pmethod(info.obj,oname,formatter,info,**kw)
612 else:
598 else:
613 pmethod(info.obj,oname)
599 pmethod(info.obj,oname)
614 else:
600 else:
615 print 'Object `%s` not found.' % oname
601 print 'Object `%s` not found.' % oname
616 return 'not found' # so callers can take other action
602 return 'not found' # so callers can take other action
617
603
618 def magic_pdef(self, parameter_s=''):
604 def magic_pdef(self, parameter_s=''):
619 """Print the definition header for any callable object.
605 """Print the definition header for any callable object.
620
606
621 If the object is a class, print the constructor information."""
607 If the object is a class, print the constructor information."""
622 self._inspect('pdef',parameter_s)
608 self._inspect('pdef',parameter_s)
623
609
624 def magic_pdoc(self, parameter_s=''):
610 def magic_pdoc(self, parameter_s=''):
625 """Print the docstring for an object.
611 """Print the docstring for an object.
626
612
627 If the given object is a class, it will print both the class and the
613 If the given object is a class, it will print both the class and the
628 constructor docstrings."""
614 constructor docstrings."""
629 self._inspect('pdoc',parameter_s)
615 self._inspect('pdoc',parameter_s)
630
616
631 def magic_psource(self, parameter_s=''):
617 def magic_psource(self, parameter_s=''):
632 """Print (or run through pager) the source code for an object."""
618 """Print (or run through pager) the source code for an object."""
633 self._inspect('psource',parameter_s)
619 self._inspect('psource',parameter_s)
634
620
635 def magic_pfile(self, parameter_s=''):
621 def magic_pfile(self, parameter_s=''):
636 """Print (or run through pager) the file where an object is defined.
622 """Print (or run through pager) the file where an object is defined.
637
623
638 The file opens at the line where the object definition begins. IPython
624 The file opens at the line where the object definition begins. IPython
639 will honor the environment variable PAGER if set, and otherwise will
625 will honor the environment variable PAGER if set, and otherwise will
640 do its best to print the file in a convenient form.
626 do its best to print the file in a convenient form.
641
627
642 If the given argument is not an object currently defined, IPython will
628 If the given argument is not an object currently defined, IPython will
643 try to interpret it as a filename (automatically adding a .py extension
629 try to interpret it as a filename (automatically adding a .py extension
644 if needed). You can thus use %pfile as a syntax highlighting code
630 if needed). You can thus use %pfile as a syntax highlighting code
645 viewer."""
631 viewer."""
646
632
647 # first interpret argument as an object name
633 # first interpret argument as an object name
648 out = self._inspect('pfile',parameter_s)
634 out = self._inspect('pfile',parameter_s)
649 # if not, try the input as a filename
635 # if not, try the input as a filename
650 if out == 'not found':
636 if out == 'not found':
651 try:
637 try:
652 filename = get_py_filename(parameter_s)
638 filename = get_py_filename(parameter_s)
653 except IOError,msg:
639 except IOError,msg:
654 print msg
640 print msg
655 return
641 return
656 page(self.shell.inspector.format(file(filename).read()))
642 page(self.shell.inspector.format(file(filename).read()))
657
643
658 def magic_pinfo(self, parameter_s=''):
644 def magic_pinfo(self, parameter_s=''):
659 """Provide detailed information about an object.
645 """Provide detailed information about an object.
660
646
661 '%pinfo object' is just a synonym for object? or ?object."""
647 '%pinfo object' is just a synonym for object? or ?object."""
662
648
663 #print 'pinfo par: <%s>' % parameter_s # dbg
649 #print 'pinfo par: <%s>' % parameter_s # dbg
664
650
665 # detail_level: 0 -> obj? , 1 -> obj??
651 # detail_level: 0 -> obj? , 1 -> obj??
666 detail_level = 0
652 detail_level = 0
667 # We need to detect if we got called as 'pinfo pinfo foo', which can
653 # We need to detect if we got called as 'pinfo pinfo foo', which can
668 # happen if the user types 'pinfo foo?' at the cmd line.
654 # happen if the user types 'pinfo foo?' at the cmd line.
669 pinfo,qmark1,oname,qmark2 = \
655 pinfo,qmark1,oname,qmark2 = \
670 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
656 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
671 if pinfo or qmark1 or qmark2:
657 if pinfo or qmark1 or qmark2:
672 detail_level = 1
658 detail_level = 1
673 self._inspect('pinfo',oname,detail_level=detail_level)
659 self._inspect('pinfo',oname,detail_level=detail_level)
674
660
675 def magic_who_ls(self, parameter_s=''):
661 def magic_who_ls(self, parameter_s=''):
676 """Return a sorted list of all interactive variables.
662 """Return a sorted list of all interactive variables.
677
663
678 If arguments are given, only variables of types matching these
664 If arguments are given, only variables of types matching these
679 arguments are returned."""
665 arguments are returned."""
680
666
681 user_ns = self.shell.user_ns
667 user_ns = self.shell.user_ns
682 out = []
668 out = []
683 typelist = parameter_s.split()
669 typelist = parameter_s.split()
684 for i in self.shell.user_ns.keys():
670 for i in self.shell.user_ns.keys():
685 if not (i.startswith('_') or i.startswith('_i')) \
671 if not (i.startswith('_') or i.startswith('_i')) \
686 and not (self.internal_ns.has_key(i) or
672 and not (self.internal_ns.has_key(i) or
687 self.user_config_ns.has_key(i)):
673 self.user_config_ns.has_key(i)):
688 if typelist:
674 if typelist:
689 if type(user_ns[i]).__name__ in typelist:
675 if type(user_ns[i]).__name__ in typelist:
690 out.append(i)
676 out.append(i)
691 else:
677 else:
692 out.append(i)
678 out.append(i)
693 out.sort()
679 out.sort()
694 return out
680 return out
695
681
696 def magic_who(self, parameter_s=''):
682 def magic_who(self, parameter_s=''):
697 """Print all interactive variables, with some minimal formatting.
683 """Print all interactive variables, with some minimal formatting.
698
684
699 If any arguments are given, only variables whose type matches one of
685 If any arguments are given, only variables whose type matches one of
700 these are printed. For example:
686 these are printed. For example:
701
687
702 %who function str
688 %who function str
703
689
704 will only list functions and strings, excluding all other types of
690 will only list functions and strings, excluding all other types of
705 variables. To find the proper type names, simply use type(var) at a
691 variables. To find the proper type names, simply use type(var) at a
706 command line to see how python prints type names. For example:
692 command line to see how python prints type names. For example:
707
693
708 In [1]: type('hello')\\
694 In [1]: type('hello')\\
709 Out[1]: <type 'str'>
695 Out[1]: <type 'str'>
710
696
711 indicates that the type name for strings is 'str'.
697 indicates that the type name for strings is 'str'.
712
698
713 %who always excludes executed names loaded through your configuration
699 %who always excludes executed names loaded through your configuration
714 file and things which are internal to IPython.
700 file and things which are internal to IPython.
715
701
716 This is deliberate, as typically you may load many modules and the
702 This is deliberate, as typically you may load many modules and the
717 purpose of %who is to show you only what you've manually defined."""
703 purpose of %who is to show you only what you've manually defined."""
718
704
719 varlist = self.magic_who_ls(parameter_s)
705 varlist = self.magic_who_ls(parameter_s)
720 if not varlist:
706 if not varlist:
721 print 'Interactive namespace is empty.'
707 print 'Interactive namespace is empty.'
722 return
708 return
723
709
724 # if we have variables, move on...
710 # if we have variables, move on...
725
711
726 # stupid flushing problem: when prompts have no separators, stdout is
712 # stupid flushing problem: when prompts have no separators, stdout is
727 # getting lost. I'm starting to think this is a python bug. I'm having
713 # getting lost. I'm starting to think this is a python bug. I'm having
728 # to force a flush with a print because even a sys.stdout.flush
714 # to force a flush with a print because even a sys.stdout.flush
729 # doesn't seem to do anything!
715 # doesn't seem to do anything!
730
716
731 count = 0
717 count = 0
732 for i in varlist:
718 for i in varlist:
733 print i+'\t',
719 print i+'\t',
734 count += 1
720 count += 1
735 if count > 8:
721 if count > 8:
736 count = 0
722 count = 0
737 print
723 print
738 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
724 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
739
725
740 print # well, this does force a flush at the expense of an extra \n
726 print # well, this does force a flush at the expense of an extra \n
741
727
742 def magic_whos(self, parameter_s=''):
728 def magic_whos(self, parameter_s=''):
743 """Like %who, but gives some extra information about each variable.
729 """Like %who, but gives some extra information about each variable.
744
730
745 The same type filtering of %who can be applied here.
731 The same type filtering of %who can be applied here.
746
732
747 For all variables, the type is printed. Additionally it prints:
733 For all variables, the type is printed. Additionally it prints:
748
734
749 - For {},[],(): their length.
735 - For {},[],(): their length.
750
736
751 - For Numeric arrays, a summary with shape, number of elements,
737 - For Numeric arrays, a summary with shape, number of elements,
752 typecode and size in memory.
738 typecode and size in memory.
753
739
754 - Everything else: a string representation, snipping their middle if
740 - Everything else: a string representation, snipping their middle if
755 too long."""
741 too long."""
756
742
757 varnames = self.magic_who_ls(parameter_s)
743 varnames = self.magic_who_ls(parameter_s)
758 if not varnames:
744 if not varnames:
759 print 'Interactive namespace is empty.'
745 print 'Interactive namespace is empty.'
760 return
746 return
761
747
762 # if we have variables, move on...
748 # if we have variables, move on...
763
749
764 # for these types, show len() instead of data:
750 # for these types, show len() instead of data:
765 seq_types = [types.DictType,types.ListType,types.TupleType]
751 seq_types = [types.DictType,types.ListType,types.TupleType]
766
752
767 # for Numeric arrays, display summary info
753 # for Numeric arrays, display summary info
768 try:
754 try:
769 import Numeric
755 import Numeric
770 except ImportError:
756 except ImportError:
771 array_type = None
757 array_type = None
772 else:
758 else:
773 array_type = Numeric.ArrayType.__name__
759 array_type = Numeric.ArrayType.__name__
774
760
775 # Find all variable names and types so we can figure out column sizes
761 # Find all variable names and types so we can figure out column sizes
776 get_vars = lambda i: self.locals[i]
762 get_vars = lambda i: self.locals[i]
777 type_name = lambda v: type(v).__name__
763 type_name = lambda v: type(v).__name__
778 varlist = map(get_vars,varnames)
764 varlist = map(get_vars,varnames)
779 typelist = map(type_name,varlist)
765 typelist = map(type_name,varlist)
780 # column labels and # of spaces as separator
766 # column labels and # of spaces as separator
781 varlabel = 'Variable'
767 varlabel = 'Variable'
782 typelabel = 'Type'
768 typelabel = 'Type'
783 datalabel = 'Data/Info'
769 datalabel = 'Data/Info'
784 colsep = 3
770 colsep = 3
785 # variable format strings
771 # variable format strings
786 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
772 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
787 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
773 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
788 aformat = "%s: %s elems, type `%s`, %s bytes"
774 aformat = "%s: %s elems, type `%s`, %s bytes"
789 # find the size of the columns to format the output nicely
775 # find the size of the columns to format the output nicely
790 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
776 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
791 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
777 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
792 # table header
778 # table header
793 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
779 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
794 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
780 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
795 # and the table itself
781 # and the table itself
796 kb = 1024
782 kb = 1024
797 Mb = 1048576 # kb**2
783 Mb = 1048576 # kb**2
798 for vname,var,vtype in zip(varnames,varlist,typelist):
784 for vname,var,vtype in zip(varnames,varlist,typelist):
799 print itpl(vformat),
785 print itpl(vformat),
800 if vtype in seq_types:
786 if vtype in seq_types:
801 print len(var)
787 print len(var)
802 elif vtype==array_type:
788 elif vtype==array_type:
803 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
789 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
804 vsize = Numeric.size(var)
790 vsize = Numeric.size(var)
805 vbytes = vsize*var.itemsize()
791 vbytes = vsize*var.itemsize()
806 if vbytes < 100000:
792 if vbytes < 100000:
807 print aformat % (vshape,vsize,var.typecode(),vbytes)
793 print aformat % (vshape,vsize,var.typecode(),vbytes)
808 else:
794 else:
809 print aformat % (vshape,vsize,var.typecode(),vbytes),
795 print aformat % (vshape,vsize,var.typecode(),vbytes),
810 if vbytes < Mb:
796 if vbytes < Mb:
811 print '(%s kb)' % (vbytes/kb,)
797 print '(%s kb)' % (vbytes/kb,)
812 else:
798 else:
813 print '(%s Mb)' % (vbytes/Mb,)
799 print '(%s Mb)' % (vbytes/Mb,)
814 else:
800 else:
815 vstr = str(var)
801 vstr = str(var)
816 if len(vstr) < 50:
802 if len(vstr) < 50:
817 print vstr
803 print vstr
818 else:
804 else:
819 printpl(vfmt_short)
805 printpl(vfmt_short)
820
806
821 def magic_reset(self, parameter_s=''):
807 def magic_reset(self, parameter_s=''):
822 """Resets the namespace by removing all names defined by the user.
808 """Resets the namespace by removing all names defined by the user.
823
809
824 Input/Output history are left around in case you need them."""
810 Input/Output history are left around in case you need them."""
825
811
826 ans = raw_input(
812 ans = raw_input(
827 "Once deleted, variables cannot be recovered. Proceed (y/n)? ")
813 "Once deleted, variables cannot be recovered. Proceed (y/n)? ")
828 if not ans.lower() == 'y':
814 if not ans.lower() == 'y':
829 print 'Nothing done.'
815 print 'Nothing done.'
830 return
816 return
831 for i in self.magic_who_ls():
817 for i in self.magic_who_ls():
832 del(self.locals[i])
818 del(self.locals[i])
833
819
834 def magic_config(self,parameter_s=''):
820 def magic_config(self,parameter_s=''):
835 """Show IPython's internal configuration."""
821 """Show IPython's internal configuration."""
836
822
837 page('Current configuration structure:\n'+
823 page('Current configuration structure:\n'+
838 pformat(self.shell.rc.dict()))
824 pformat(self.shell.rc.dict()))
839
825
840 def magic_logstart(self,parameter_s=''):
826 def magic_logstart(self,parameter_s=''):
841 """Start logging anywhere in a session.
827 """Start logging anywhere in a session.
842
828
843 %logstart [log_name [log_mode]]
829 %logstart [log_name [log_mode]]
844
830
845 If no name is given, it defaults to a file named 'ipython.log' in your
831 If no name is given, it defaults to a file named 'ipython.log' in your
846 current directory, in 'rotate' mode (see below).
832 current directory, in 'rotate' mode (see below).
847
833
848 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
834 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
849 history up to that point and then continues logging.
835 history up to that point and then continues logging.
850
836
851 %logstart takes a second optional parameter: logging mode. This can be one
837 %logstart takes a second optional parameter: logging mode. This can be one
852 of (note that the modes are given unquoted):\\
838 of (note that the modes are given unquoted):\\
853 over: overwrite existing log.\\
839 over: overwrite existing log.\\
854 backup: rename (if exists) to name~ and start name.\\
840 backup: rename (if exists) to name~ and start name.\\
855 append: well, that says it.\\
841 append: well, that says it.\\
856 rotate: create rotating logs name.1~, name.2~, etc.
842 rotate: create rotating logs name.1~, name.2~, etc.
857 """
843 """
858
844
859 #FIXME. This function should all be moved to the Logger class.
845 #FIXME. This function should all be moved to the Logger class.
860
846
861 valid_modes = qw('over backup append rotate')
847 valid_modes = qw('over backup append rotate')
862 if self.LOG:
848 if self.LOG:
863 print 'Logging is already in place. Logfile:',self.LOG
849 print 'Logging is already in place. Logfile:',self.LOG
864 return
850 return
865
851
866 par = parameter_s.strip()
852 par = parameter_s.strip()
867 if not par:
853 if not par:
868 logname = self.LOGDEF
854 logname = self.LOGDEF
869 logmode = 'rotate' # use rotate for the auto-generated logs
855 logmode = 'rotate' # use rotate for the auto-generated logs
870 else:
856 else:
871 try:
857 try:
872 logname,logmode = par.split()
858 logname,logmode = par.split()
873 except:
859 except:
874 try:
860 try:
875 logname = par
861 logname = par
876 logmode = 'backup'
862 logmode = 'backup'
877 except:
863 except:
878 warn('Usage: %log [log_name [log_mode]]')
864 warn('Usage: %log [log_name [log_mode]]')
879 return
865 return
880 if not logmode in valid_modes:
866 if not logmode in valid_modes:
881 warn('Logging NOT activated.\n'
867 warn('Logging NOT activated.\n'
882 'Usage: %log [log_name [log_mode]]\n'
868 'Usage: %log [log_name [log_mode]]\n'
883 'Valid modes: '+str(valid_modes))
869 'Valid modes: '+str(valid_modes))
884 return
870 return
885
871
886 # If we made it this far, I think we're ok:
872 # If we made it this far, I think we're ok:
887 print 'Activating auto-logging.'
873 print 'Activating auto-logging.'
888 print 'Current session state plus future input saved to:',logname
874 print 'Current session state plus future input saved to:',logname
889 print 'Logging mode: ',logmode
875 print 'Logging mode: ',logmode
890 # put logname into rc struct as if it had been called on the command line,
876 # put logname into rc struct as if it had been called on the command line,
891 # so it ends up saved in the log header
877 # so it ends up saved in the log header
892 # Save it in case we need to restore it...
878 # Save it in case we need to restore it...
893 old_logfile = self.shell.rc.opts.get('logfile','')
879 old_logfile = self.shell.rc.opts.get('logfile','')
894 logname = os.path.expanduser(logname)
880 logname = os.path.expanduser(logname)
895 self.shell.rc.opts.logfile = logname
881 self.shell.rc.opts.logfile = logname
896 self.LOGMODE = logmode # FIXME: this should be set through a function.
882 self.LOGMODE = logmode # FIXME: this should be set through a function.
897 try:
883 try:
898 header = str(self.LOGHEAD)
884 header = str(self.LOGHEAD)
899 self.create_log(header,logname)
885 self.create_log(header,logname)
900 self.logstart(header,logname)
886 self.logstart(header,logname)
901 except:
887 except:
902 self.LOG = '' # we are NOT logging, something went wrong
888 self.LOG = '' # we are NOT logging, something went wrong
903 self.shell.rc.opts.logfile = old_logfile
889 self.shell.rc.opts.logfile = old_logfile
904 warn("Couldn't start log: "+str(sys.exc_info()[1]))
890 warn("Couldn't start log: "+str(sys.exc_info()[1]))
905 else: # log input history up to this point
891 else: # log input history up to this point
906 self.logfile.write(self.shell.user_ns['_ih'][1:])
892 self.logfile.write(self.shell.user_ns['_ih'][1:])
907 self.logfile.flush()
893 self.logfile.flush()
908
894
909 def magic_logoff(self,parameter_s=''):
895 def magic_logoff(self,parameter_s=''):
910 """Temporarily stop logging.
896 """Temporarily stop logging.
911
897
912 You must have previously started logging."""
898 You must have previously started logging."""
913 self.switch_log(0)
899 self.switch_log(0)
914
900
915 def magic_logon(self,parameter_s=''):
901 def magic_logon(self,parameter_s=''):
916 """Restart logging.
902 """Restart logging.
917
903
918 This function is for restarting logging which you've temporarily
904 This function is for restarting logging which you've temporarily
919 stopped with %logoff. For starting logging for the first time, you
905 stopped with %logoff. For starting logging for the first time, you
920 must use the %logstart function, which allows you to specify an
906 must use the %logstart function, which allows you to specify an
921 optional log filename."""
907 optional log filename."""
922
908
923 self.switch_log(1)
909 self.switch_log(1)
924
910
925 def magic_logstate(self,parameter_s=''):
911 def magic_logstate(self,parameter_s=''):
926 """Print the status of the logging system."""
912 """Print the status of the logging system."""
927
913
928 self.logstate()
914 self.logstate()
929
915
930 def magic_pdb(self, parameter_s=''):
916 def magic_pdb(self, parameter_s=''):
931 """Control the calling of the pdb interactive debugger.
917 """Control the calling of the pdb interactive debugger.
932
918
933 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
919 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
934 argument it works as a toggle.
920 argument it works as a toggle.
935
921
936 When an exception is triggered, IPython can optionally call the
922 When an exception is triggered, IPython can optionally call the
937 interactive pdb debugger after the traceback printout. %pdb toggles
923 interactive pdb debugger after the traceback printout. %pdb toggles
938 this feature on and off."""
924 this feature on and off."""
939
925
940 par = parameter_s.strip().lower()
926 par = parameter_s.strip().lower()
941
927
942 if par:
928 if par:
943 try:
929 try:
944 pdb = {'off':0,'0':0,'on':1,'1':1}[par]
930 pdb = {'off':0,'0':0,'on':1,'1':1}[par]
945 except KeyError:
931 except KeyError:
946 print 'Incorrect argument. Use on/1, off/0 or nothing for a toggle.'
932 print 'Incorrect argument. Use on/1, off/0 or nothing for a toggle.'
947 return
933 return
948 else:
934 else:
949 self.shell.InteractiveTB.call_pdb = pdb
935 self.shell.InteractiveTB.call_pdb = pdb
950 else:
936 else:
951 self.shell.InteractiveTB.call_pdb = 1 - self.shell.InteractiveTB.call_pdb
937 self.shell.InteractiveTB.call_pdb = 1 - self.shell.InteractiveTB.call_pdb
952 print 'Automatic pdb calling has been turned',\
938 print 'Automatic pdb calling has been turned',\
953 on_off(self.shell.InteractiveTB.call_pdb)
939 on_off(self.shell.InteractiveTB.call_pdb)
954
940
955
941
956 def magic_prun(self, parameter_s ='',user_mode=1,
942 def magic_prun(self, parameter_s ='',user_mode=1,
957 opts=None,arg_lst=None,prog_ns=None):
943 opts=None,arg_lst=None,prog_ns=None):
958
944
959 """Run a statement through the python code profiler.
945 """Run a statement through the python code profiler.
960
946
961 Usage:\\
947 Usage:\\
962 %prun [options] statement
948 %prun [options] statement
963
949
964 The given statement (which doesn't require quote marks) is run via the
950 The given statement (which doesn't require quote marks) is run via the
965 python profiler in a manner similar to the profile.run() function.
951 python profiler in a manner similar to the profile.run() function.
966 Namespaces are internally managed to work correctly; profile.run
952 Namespaces are internally managed to work correctly; profile.run
967 cannot be used in IPython because it makes certain assumptions about
953 cannot be used in IPython because it makes certain assumptions about
968 namespaces which do not hold under IPython.
954 namespaces which do not hold under IPython.
969
955
970 Options:
956 Options:
971
957
972 -l <limit>: you can place restrictions on what or how much of the
958 -l <limit>: you can place restrictions on what or how much of the
973 profile gets printed. The limit value can be:
959 profile gets printed. The limit value can be:
974
960
975 * A string: only information for function names containing this string
961 * A string: only information for function names containing this string
976 is printed.
962 is printed.
977
963
978 * An integer: only these many lines are printed.
964 * An integer: only these many lines are printed.
979
965
980 * A float (between 0 and 1): this fraction of the report is printed
966 * A float (between 0 and 1): this fraction of the report is printed
981 (for example, use a limit of 0.4 to see the topmost 40% only).
967 (for example, use a limit of 0.4 to see the topmost 40% only).
982
968
983 You can combine several limits with repeated use of the option. For
969 You can combine several limits with repeated use of the option. For
984 example, '-l __init__ -l 5' will print only the topmost 5 lines of
970 example, '-l __init__ -l 5' will print only the topmost 5 lines of
985 information about class constructors.
971 information about class constructors.
986
972
987 -r: return the pstats.Stats object generated by the profiling. This
973 -r: return the pstats.Stats object generated by the profiling. This
988 object has all the information about the profile in it, and you can
974 object has all the information about the profile in it, and you can
989 later use it for further analysis or in other functions.
975 later use it for further analysis or in other functions.
990
976
991 Since magic functions have a particular form of calling which prevents
977 Since magic functions have a particular form of calling which prevents
992 you from writing something like:\\
978 you from writing something like:\\
993 In [1]: p = %prun -r print 4 # invalid!\\
979 In [1]: p = %prun -r print 4 # invalid!\\
994 you must instead use IPython's automatic variables to assign this:\\
980 you must instead use IPython's automatic variables to assign this:\\
995 In [1]: %prun -r print 4 \\
981 In [1]: %prun -r print 4 \\
996 Out[1]: <pstats.Stats instance at 0x8222cec>\\
982 Out[1]: <pstats.Stats instance at 0x8222cec>\\
997 In [2]: stats = _
983 In [2]: stats = _
998
984
999 If you really need to assign this value via an explicit function call,
985 If you really need to assign this value via an explicit function call,
1000 you can always tap directly into the true name of the magic function
986 you can always tap directly into the true name of the magic function
1001 by using the ipmagic function (which IPython automatically adds to the
987 by using the ipmagic function (which IPython automatically adds to the
1002 builtins):\\
988 builtins):\\
1003 In [3]: stats = ipmagic('prun','-r print 4')
989 In [3]: stats = ipmagic('prun','-r print 4')
1004
990
1005 You can type ipmagic? for more details on ipmagic.
991 You can type ipmagic? for more details on ipmagic.
1006
992
1007 -s <key>: sort profile by given key. You can provide more than one key
993 -s <key>: sort profile by given key. You can provide more than one key
1008 by using the option several times: '-s key1 -s key2 -s key3...'. The
994 by using the option several times: '-s key1 -s key2 -s key3...'. The
1009 default sorting key is 'time'.
995 default sorting key is 'time'.
1010
996
1011 The following is copied verbatim from the profile documentation
997 The following is copied verbatim from the profile documentation
1012 referenced below:
998 referenced below:
1013
999
1014 When more than one key is provided, additional keys are used as
1000 When more than one key is provided, additional keys are used as
1015 secondary criteria when the there is equality in all keys selected
1001 secondary criteria when the there is equality in all keys selected
1016 before them.
1002 before them.
1017
1003
1018 Abbreviations can be used for any key names, as long as the
1004 Abbreviations can be used for any key names, as long as the
1019 abbreviation is unambiguous. The following are the keys currently
1005 abbreviation is unambiguous. The following are the keys currently
1020 defined:
1006 defined:
1021
1007
1022 Valid Arg Meaning\\
1008 Valid Arg Meaning\\
1023 "calls" call count\\
1009 "calls" call count\\
1024 "cumulative" cumulative time\\
1010 "cumulative" cumulative time\\
1025 "file" file name\\
1011 "file" file name\\
1026 "module" file name\\
1012 "module" file name\\
1027 "pcalls" primitive call count\\
1013 "pcalls" primitive call count\\
1028 "line" line number\\
1014 "line" line number\\
1029 "name" function name\\
1015 "name" function name\\
1030 "nfl" name/file/line\\
1016 "nfl" name/file/line\\
1031 "stdname" standard name\\
1017 "stdname" standard name\\
1032 "time" internal time
1018 "time" internal time
1033
1019
1034 Note that all sorts on statistics are in descending order (placing
1020 Note that all sorts on statistics are in descending order (placing
1035 most time consuming items first), where as name, file, and line number
1021 most time consuming items first), where as name, file, and line number
1036 searches are in ascending order (i.e., alphabetical). The subtle
1022 searches are in ascending order (i.e., alphabetical). The subtle
1037 distinction between "nfl" and "stdname" is that the standard name is a
1023 distinction between "nfl" and "stdname" is that the standard name is a
1038 sort of the name as printed, which means that the embedded line
1024 sort of the name as printed, which means that the embedded line
1039 numbers get compared in an odd way. For example, lines 3, 20, and 40
1025 numbers get compared in an odd way. For example, lines 3, 20, and 40
1040 would (if the file names were the same) appear in the string order
1026 would (if the file names were the same) appear in the string order
1041 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1027 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1042 line numbers. In fact, sort_stats("nfl") is the same as
1028 line numbers. In fact, sort_stats("nfl") is the same as
1043 sort_stats("name", "file", "line").
1029 sort_stats("name", "file", "line").
1044
1030
1045 -T <filename>: save profile results as shown on screen to a text
1031 -T <filename>: save profile results as shown on screen to a text
1046 file. The profile is still shown on screen.
1032 file. The profile is still shown on screen.
1047
1033
1048 -D <filename>: save (via dump_stats) profile statistics to given
1034 -D <filename>: save (via dump_stats) profile statistics to given
1049 filename. This data is in a format understod by the pstats module, and
1035 filename. This data is in a format understod by the pstats module, and
1050 is generated by a call to the dump_stats() method of profile
1036 is generated by a call to the dump_stats() method of profile
1051 objects. The profile is still shown on screen.
1037 objects. The profile is still shown on screen.
1052
1038
1053 If you want to run complete programs under the profiler's control, use
1039 If you want to run complete programs under the profiler's control, use
1054 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1040 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1055 contains profiler specific options as described here.
1041 contains profiler specific options as described here.
1056
1042
1057 You can read the complete documentation for the profile module with:\\
1043 You can read the complete documentation for the profile module with:\\
1058 In [1]: import profile; profile.help() """
1044 In [1]: import profile; profile.help() """
1059
1045
1060 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1046 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1061 # protect user quote marks
1047 # protect user quote marks
1062 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1048 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1063
1049
1064 if user_mode: # regular user call
1050 if user_mode: # regular user call
1065 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1051 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1066 list_all=1)
1052 list_all=1)
1067 namespace = self.shell.user_ns
1053 namespace = self.shell.user_ns
1068 else: # called to run a program by %run -p
1054 else: # called to run a program by %run -p
1069 try:
1055 try:
1070 filename = get_py_filename(arg_lst[0])
1056 filename = get_py_filename(arg_lst[0])
1071 except IOError,msg:
1057 except IOError,msg:
1072 error(msg)
1058 error(msg)
1073 return
1059 return
1074
1060
1075 arg_str = 'execfile(filename,prog_ns)'
1061 arg_str = 'execfile(filename,prog_ns)'
1076 namespace = locals()
1062 namespace = locals()
1077
1063
1078 opts.merge(opts_def)
1064 opts.merge(opts_def)
1079
1065
1080 prof = profile.Profile()
1066 prof = profile.Profile()
1081 try:
1067 try:
1082 prof = prof.runctx(arg_str,namespace,namespace)
1068 prof = prof.runctx(arg_str,namespace,namespace)
1083 sys_exit = ''
1069 sys_exit = ''
1084 except SystemExit:
1070 except SystemExit:
1085 sys_exit = """*** SystemExit exception caught in code being profiled."""
1071 sys_exit = """*** SystemExit exception caught in code being profiled."""
1086
1072
1087 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1073 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1088
1074
1089 lims = opts.l
1075 lims = opts.l
1090 if lims:
1076 if lims:
1091 lims = [] # rebuild lims with ints/floats/strings
1077 lims = [] # rebuild lims with ints/floats/strings
1092 for lim in opts.l:
1078 for lim in opts.l:
1093 try:
1079 try:
1094 lims.append(int(lim))
1080 lims.append(int(lim))
1095 except ValueError:
1081 except ValueError:
1096 try:
1082 try:
1097 lims.append(float(lim))
1083 lims.append(float(lim))
1098 except ValueError:
1084 except ValueError:
1099 lims.append(lim)
1085 lims.append(lim)
1100
1086
1101 # trap output
1087 # trap output
1102 sys_stdout = sys.stdout
1088 sys_stdout = sys.stdout
1103 stdout_trap = StringIO()
1089 stdout_trap = StringIO()
1104 try:
1090 try:
1105 sys.stdout = stdout_trap
1091 sys.stdout = stdout_trap
1106 stats.print_stats(*lims)
1092 stats.print_stats(*lims)
1107 finally:
1093 finally:
1108 sys.stdout = sys_stdout
1094 sys.stdout = sys_stdout
1109 output = stdout_trap.getvalue()
1095 output = stdout_trap.getvalue()
1110 output = output.rstrip()
1096 output = output.rstrip()
1111
1097
1112 page(output,screen_lines=self.shell.rc.screen_length)
1098 page(output,screen_lines=self.shell.rc.screen_length)
1113 print sys_exit,
1099 print sys_exit,
1114
1100
1115 dump_file = opts.D[0]
1101 dump_file = opts.D[0]
1116 text_file = opts.T[0]
1102 text_file = opts.T[0]
1117 if dump_file:
1103 if dump_file:
1118 prof.dump_stats(dump_file)
1104 prof.dump_stats(dump_file)
1119 print '\n*** Profile stats marshalled to file',\
1105 print '\n*** Profile stats marshalled to file',\
1120 `dump_file`+'.',sys_exit
1106 `dump_file`+'.',sys_exit
1121 if text_file:
1107 if text_file:
1122 file(text_file,'w').write(output)
1108 file(text_file,'w').write(output)
1123 print '\n*** Profile printout saved to text file',\
1109 print '\n*** Profile printout saved to text file',\
1124 `text_file`+'.',sys_exit
1110 `text_file`+'.',sys_exit
1125
1111
1126 if opts.has_key('r'):
1112 if opts.has_key('r'):
1127 return stats
1113 return stats
1128 else:
1114 else:
1129 return None
1115 return None
1130
1116
1131 def magic_run(self, parameter_s ='',runner=None):
1117 def magic_run(self, parameter_s ='',runner=None):
1132 """Run the named file inside IPython as a program.
1118 """Run the named file inside IPython as a program.
1133
1119
1134 Usage:\\
1120 Usage:\\
1135 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1121 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1136
1122
1137 Parameters after the filename are passed as command-line arguments to
1123 Parameters after the filename are passed as command-line arguments to
1138 the program (put in sys.argv). Then, control returns to IPython's
1124 the program (put in sys.argv). Then, control returns to IPython's
1139 prompt.
1125 prompt.
1140
1126
1141 This is similar to running at a system prompt:\\
1127 This is similar to running at a system prompt:\\
1142 $ python file args\\
1128 $ python file args\\
1143 but with the advantage of giving you IPython's tracebacks, and of
1129 but with the advantage of giving you IPython's tracebacks, and of
1144 loading all variables into your interactive namespace for further use
1130 loading all variables into your interactive namespace for further use
1145 (unless -p is used, see below).
1131 (unless -p is used, see below).
1146
1132
1147 The file is executed in a namespace initially consisting only of
1133 The file is executed in a namespace initially consisting only of
1148 __name__=='__main__' and sys.argv constructed as indicated. It thus
1134 __name__=='__main__' and sys.argv constructed as indicated. It thus
1149 sees its environment as if it were being run as a stand-alone
1135 sees its environment as if it were being run as a stand-alone
1150 program. But after execution, the IPython interactive namespace gets
1136 program. But after execution, the IPython interactive namespace gets
1151 updated with all variables defined in the program (except for __name__
1137 updated with all variables defined in the program (except for __name__
1152 and sys.argv). This allows for very convenient loading of code for
1138 and sys.argv). This allows for very convenient loading of code for
1153 interactive work, while giving each program a 'clean sheet' to run in.
1139 interactive work, while giving each program a 'clean sheet' to run in.
1154
1140
1155 Options:
1141 Options:
1156
1142
1157 -n: __name__ is NOT set to '__main__', but to the running file's name
1143 -n: __name__ is NOT set to '__main__', but to the running file's name
1158 without extension (as python does under import). This allows running
1144 without extension (as python does under import). This allows running
1159 scripts and reloading the definitions in them without calling code
1145 scripts and reloading the definitions in them without calling code
1160 protected by an ' if __name__ == "__main__" ' clause.
1146 protected by an ' if __name__ == "__main__" ' clause.
1161
1147
1162 -i: run the file in IPython's namespace instead of an empty one. This
1148 -i: run the file in IPython's namespace instead of an empty one. This
1163 is useful if you are experimenting with code written in a text editor
1149 is useful if you are experimenting with code written in a text editor
1164 which depends on variables defined interactively.
1150 which depends on variables defined interactively.
1165
1151
1166 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1152 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1167 being run. This is particularly useful if IPython is being used to
1153 being run. This is particularly useful if IPython is being used to
1168 run unittests, which always exit with a sys.exit() call. In such
1154 run unittests, which always exit with a sys.exit() call. In such
1169 cases you are interested in the output of the test results, not in
1155 cases you are interested in the output of the test results, not in
1170 seeing a traceback of the unittest module.
1156 seeing a traceback of the unittest module.
1171
1157
1172 -t: print timing information at the end of the run. IPython will give
1158 -t: print timing information at the end of the run. IPython will give
1173 you an estimated CPU time consumption for your script, which under
1159 you an estimated CPU time consumption for your script, which under
1174 Unix uses the resource module to avoid the wraparound problems of
1160 Unix uses the resource module to avoid the wraparound problems of
1175 time.clock(). Under Unix, an estimate of time spent on system tasks
1161 time.clock(). Under Unix, an estimate of time spent on system tasks
1176 is also given (for Windows platforms this is reported as 0.0).
1162 is also given (for Windows platforms this is reported as 0.0).
1177
1163
1178 If -t is given, an additional -N<N> option can be given, where <N>
1164 If -t is given, an additional -N<N> option can be given, where <N>
1179 must be an integer indicating how many times you want the script to
1165 must be an integer indicating how many times you want the script to
1180 run. The final timing report will include total and per run results.
1166 run. The final timing report will include total and per run results.
1181
1167
1182 For example (testing the script uniq_stable.py):
1168 For example (testing the script uniq_stable.py):
1183
1169
1184 In [1]: run -t uniq_stable
1170 In [1]: run -t uniq_stable
1185
1171
1186 IPython CPU timings (estimated):\\
1172 IPython CPU timings (estimated):\\
1187 User : 0.19597 s.\\
1173 User : 0.19597 s.\\
1188 System: 0.0 s.\\
1174 System: 0.0 s.\\
1189
1175
1190 In [2]: run -t -N5 uniq_stable
1176 In [2]: run -t -N5 uniq_stable
1191
1177
1192 IPython CPU timings (estimated):\\
1178 IPython CPU timings (estimated):\\
1193 Total runs performed: 5\\
1179 Total runs performed: 5\\
1194 Times : Total Per run\\
1180 Times : Total Per run\\
1195 User : 0.910862 s, 0.1821724 s.\\
1181 User : 0.910862 s, 0.1821724 s.\\
1196 System: 0.0 s, 0.0 s.
1182 System: 0.0 s, 0.0 s.
1197
1183
1198 -d: run your program under the control of pdb, the Python debugger.
1184 -d: run your program under the control of pdb, the Python debugger.
1199 This allows you to execute your program step by step, watch variables,
1185 This allows you to execute your program step by step, watch variables,
1200 etc. Internally, what IPython does is similar to calling:
1186 etc. Internally, what IPython does is similar to calling:
1201
1187
1202 pdb.run('execfile("YOURFILENAME")')
1188 pdb.run('execfile("YOURFILENAME")')
1203
1189
1204 with a breakpoint set on line 1 of your file. You can change the line
1190 with a breakpoint set on line 1 of your file. You can change the line
1205 number for this automatic breakpoint to be <N> by using the -bN option
1191 number for this automatic breakpoint to be <N> by using the -bN option
1206 (where N must be an integer). For example:
1192 (where N must be an integer). For example:
1207
1193
1208 %run -d -b40 myscript
1194 %run -d -b40 myscript
1209
1195
1210 will set the first breakpoint at line 40 in myscript.py. Note that
1196 will set the first breakpoint at line 40 in myscript.py. Note that
1211 the first breakpoint must be set on a line which actually does
1197 the first breakpoint must be set on a line which actually does
1212 something (not a comment or docstring) for it to stop execution.
1198 something (not a comment or docstring) for it to stop execution.
1213
1199
1214 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1200 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1215 first enter 'c' (without qoutes) to start execution up to the first
1201 first enter 'c' (without qoutes) to start execution up to the first
1216 breakpoint.
1202 breakpoint.
1217
1203
1218 Entering 'help' gives information about the use of the debugger. You
1204 Entering 'help' gives information about the use of the debugger. You
1219 can easily see pdb's full documentation with "import pdb;pdb.help()"
1205 can easily see pdb's full documentation with "import pdb;pdb.help()"
1220 at a prompt.
1206 at a prompt.
1221
1207
1222 -p: run program under the control of the Python profiler module (which
1208 -p: run program under the control of the Python profiler module (which
1223 prints a detailed report of execution times, function calls, etc).
1209 prints a detailed report of execution times, function calls, etc).
1224
1210
1225 You can pass other options after -p which affect the behavior of the
1211 You can pass other options after -p which affect the behavior of the
1226 profiler itself. See the docs for %prun for details.
1212 profiler itself. See the docs for %prun for details.
1227
1213
1228 In this mode, the program's variables do NOT propagate back to the
1214 In this mode, the program's variables do NOT propagate back to the
1229 IPython interactive namespace (because they remain in the namespace
1215 IPython interactive namespace (because they remain in the namespace
1230 where the profiler executes them).
1216 where the profiler executes them).
1231
1217
1232 Internally this triggers a call to %prun, see its documentation for
1218 Internally this triggers a call to %prun, see its documentation for
1233 details on the options available specifically for profiling."""
1219 details on the options available specifically for profiling."""
1234
1220
1235 # get arguments and set sys.argv for program to be run.
1221 # get arguments and set sys.argv for program to be run.
1236 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1222 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1237 mode='list',list_all=1)
1223 mode='list',list_all=1)
1238
1224
1239 try:
1225 try:
1240 filename = get_py_filename(arg_lst[0])
1226 filename = get_py_filename(arg_lst[0])
1241 except IndexError:
1227 except IndexError:
1242 warn('you must provide at least a filename.')
1228 warn('you must provide at least a filename.')
1243 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1229 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1244 return
1230 return
1245 except IOError,msg:
1231 except IOError,msg:
1246 error(msg)
1232 error(msg)
1247 return
1233 return
1248
1234
1249 # Control the response to exit() calls made by the script being run
1235 # Control the response to exit() calls made by the script being run
1250 exit_ignore = opts.has_key('e')
1236 exit_ignore = opts.has_key('e')
1251
1237
1252 # Make sure that the running script gets a proper sys.argv as if it
1238 # Make sure that the running script gets a proper sys.argv as if it
1253 # were run from a system shell.
1239 # were run from a system shell.
1254 save_argv = sys.argv # save it for later restoring
1240 save_argv = sys.argv # save it for later restoring
1255 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1241 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1256
1242
1257 if opts.has_key('i'):
1243 if opts.has_key('i'):
1258 prog_ns = self.shell.user_ns
1244 prog_ns = self.shell.user_ns
1259 __name__save = self.shell.user_ns['__name__']
1245 __name__save = self.shell.user_ns['__name__']
1260 prog_ns['__name__'] = '__main__'
1246 prog_ns['__name__'] = '__main__'
1261 else:
1247 else:
1262 if opts.has_key('n'):
1248 if opts.has_key('n'):
1263 name = os.path.splitext(os.path.basename(filename))[0]
1249 name = os.path.splitext(os.path.basename(filename))[0]
1264 else:
1250 else:
1265 name = '__main__'
1251 name = '__main__'
1266 prog_ns = {'__name__':name}
1252 prog_ns = {'__name__':name}
1267
1253
1268 # pickle fix. See iplib for an explanation
1254 # pickle fix. See iplib for an explanation
1269 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1255 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1270
1256
1271 stats = None
1257 stats = None
1272 try:
1258 try:
1273 if opts.has_key('p'):
1259 if opts.has_key('p'):
1274 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1260 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1275 else:
1261 else:
1276 if opts.has_key('d'):
1262 if opts.has_key('d'):
1277 deb = pdb.Pdb()
1263 deb = pdb.Pdb()
1278 # reset Breakpoint state, which is moronically kept
1264 # reset Breakpoint state, which is moronically kept
1279 # in a class
1265 # in a class
1280 bdb.Breakpoint.next = 1
1266 bdb.Breakpoint.next = 1
1281 bdb.Breakpoint.bplist = {}
1267 bdb.Breakpoint.bplist = {}
1282 bdb.Breakpoint.bpbynumber = [None]
1268 bdb.Breakpoint.bpbynumber = [None]
1283 # Set an initial breakpoint to stop execution
1269 # Set an initial breakpoint to stop execution
1284 maxtries = 10
1270 maxtries = 10
1285 bp = int(opts.get('b',[1])[0])
1271 bp = int(opts.get('b',[1])[0])
1286 checkline = deb.checkline(filename,bp)
1272 checkline = deb.checkline(filename,bp)
1287 if not checkline:
1273 if not checkline:
1288 for bp in range(bp+1,bp+maxtries+1):
1274 for bp in range(bp+1,bp+maxtries+1):
1289 if deb.checkline(filename,bp):
1275 if deb.checkline(filename,bp):
1290 break
1276 break
1291 else:
1277 else:
1292 msg = ("\nI failed to find a valid line to set "
1278 msg = ("\nI failed to find a valid line to set "
1293 "a breakpoint\n"
1279 "a breakpoint\n"
1294 "after trying up to line: %s.\n"
1280 "after trying up to line: %s.\n"
1295 "Please set a valid breakpoint manually "
1281 "Please set a valid breakpoint manually "
1296 "with the -b option." % bp)
1282 "with the -b option." % bp)
1297 error(msg)
1283 error(msg)
1298 return
1284 return
1299 # if we find a good linenumber, set the breakpoint
1285 # if we find a good linenumber, set the breakpoint
1300 deb.do_break('%s:%s' % (filename,bp))
1286 deb.do_break('%s:%s' % (filename,bp))
1301 # Start file run
1287 # Start file run
1302 print "NOTE: Enter 'c' at the",
1288 print "NOTE: Enter 'c' at the",
1303 print "(Pdb) prompt to start your script."
1289 print "(Pdb) prompt to start your script."
1304 deb.run('execfile("%s")' % filename,prog_ns)
1290 deb.run('execfile("%s")' % filename,prog_ns)
1305 else:
1291 else:
1306 if runner is None:
1292 if runner is None:
1307 runner = self.shell.safe_execfile
1293 runner = self.shell.safe_execfile
1308 if opts.has_key('t'):
1294 if opts.has_key('t'):
1309 try:
1295 try:
1310 nruns = int(opts['N'][0])
1296 nruns = int(opts['N'][0])
1311 if nruns < 1:
1297 if nruns < 1:
1312 error('Number of runs must be >=1')
1298 error('Number of runs must be >=1')
1313 return
1299 return
1314 except (KeyError):
1300 except (KeyError):
1315 nruns = 1
1301 nruns = 1
1316 if nruns == 1:
1302 if nruns == 1:
1317 t0 = clock2()
1303 t0 = clock2()
1318 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1304 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1319 t1 = clock2()
1305 t1 = clock2()
1320 t_usr = t1[0]-t0[0]
1306 t_usr = t1[0]-t0[0]
1321 t_sys = t1[1]-t1[1]
1307 t_sys = t1[1]-t1[1]
1322 print "\nIPython CPU timings (estimated):"
1308 print "\nIPython CPU timings (estimated):"
1323 print " User : %10s s." % t_usr
1309 print " User : %10s s." % t_usr
1324 print " System: %10s s." % t_sys
1310 print " System: %10s s." % t_sys
1325 else:
1311 else:
1326 runs = range(nruns)
1312 runs = range(nruns)
1327 t0 = clock2()
1313 t0 = clock2()
1328 for nr in runs:
1314 for nr in runs:
1329 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1315 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1330 t1 = clock2()
1316 t1 = clock2()
1331 t_usr = t1[0]-t0[0]
1317 t_usr = t1[0]-t0[0]
1332 t_sys = t1[1]-t1[1]
1318 t_sys = t1[1]-t1[1]
1333 print "\nIPython CPU timings (estimated):"
1319 print "\nIPython CPU timings (estimated):"
1334 print "Total runs performed:",nruns
1320 print "Total runs performed:",nruns
1335 print " Times : %10s %10s" % ('Total','Per run')
1321 print " Times : %10s %10s" % ('Total','Per run')
1336 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1322 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1337 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1323 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1338
1324
1339 else:
1325 else:
1340 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1326 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1341 if opts.has_key('i'):
1327 if opts.has_key('i'):
1342 self.shell.user_ns['__name__'] = __name__save
1328 self.shell.user_ns['__name__'] = __name__save
1343 else:
1329 else:
1344 # update IPython interactive namespace
1330 # update IPython interactive namespace
1345 del prog_ns['__name__']
1331 del prog_ns['__name__']
1346 self.shell.user_ns.update(prog_ns)
1332 self.shell.user_ns.update(prog_ns)
1347 finally:
1333 finally:
1348 sys.argv = save_argv
1334 sys.argv = save_argv
1349 return stats
1335 return stats
1350
1336
1351 def magic_runlog(self, parameter_s =''):
1337 def magic_runlog(self, parameter_s =''):
1352 """Run files as logs.
1338 """Run files as logs.
1353
1339
1354 Usage:\\
1340 Usage:\\
1355 %runlog file1 file2 ...
1341 %runlog file1 file2 ...
1356
1342
1357 Run the named files (treating them as log files) in sequence inside
1343 Run the named files (treating them as log files) in sequence inside
1358 the interpreter, and return to the prompt. This is much slower than
1344 the interpreter, and return to the prompt. This is much slower than
1359 %run because each line is executed in a try/except block, but it
1345 %run because each line is executed in a try/except block, but it
1360 allows running files with syntax errors in them.
1346 allows running files with syntax errors in them.
1361
1347
1362 Normally IPython will guess when a file is one of its own logfiles, so
1348 Normally IPython will guess when a file is one of its own logfiles, so
1363 you can typically use %run even for logs. This shorthand allows you to
1349 you can typically use %run even for logs. This shorthand allows you to
1364 force any file to be treated as a log file."""
1350 force any file to be treated as a log file."""
1365
1351
1366 for f in parameter_s.split():
1352 for f in parameter_s.split():
1367 self.shell.safe_execfile(f,self.shell.user_ns,
1353 self.shell.safe_execfile(f,self.shell.user_ns,
1368 self.shell.user_ns,islog=1)
1354 self.shell.user_ns,islog=1)
1369
1355
1370 def magic_time(self,parameter_s = ''):
1356 def magic_time(self,parameter_s = ''):
1371 """Time execution of a Python statement or expression.
1357 """Time execution of a Python statement or expression.
1372
1358
1373 The CPU and wall clock times are printed, and the value of the
1359 The CPU and wall clock times are printed, and the value of the
1374 expression (if any) is returned. Note that under Win32, system time
1360 expression (if any) is returned. Note that under Win32, system time
1375 is always reported as 0, since it can not be measured.
1361 is always reported as 0, since it can not be measured.
1376
1362
1377 This function provides very basic timing functionality. In Python
1363 This function provides very basic timing functionality. In Python
1378 2.3, the timeit module offers more control and sophistication, but for
1364 2.3, the timeit module offers more control and sophistication, but for
1379 now IPython supports Python 2.2, so we can not rely on timeit being
1365 now IPython supports Python 2.2, so we can not rely on timeit being
1380 present.
1366 present.
1381
1367
1382 Some examples:
1368 Some examples:
1383
1369
1384 In [1]: time 2**128
1370 In [1]: time 2**128
1385 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1371 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1386 Wall time: 0.00
1372 Wall time: 0.00
1387 Out[1]: 340282366920938463463374607431768211456L
1373 Out[1]: 340282366920938463463374607431768211456L
1388
1374
1389 In [2]: n = 1000000
1375 In [2]: n = 1000000
1390
1376
1391 In [3]: time sum(range(n))
1377 In [3]: time sum(range(n))
1392 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1378 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1393 Wall time: 1.37
1379 Wall time: 1.37
1394 Out[3]: 499999500000L
1380 Out[3]: 499999500000L
1395
1381
1396 In [4]: time print 'hello world'
1382 In [4]: time print 'hello world'
1397 hello world
1383 hello world
1398 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1384 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1399 Wall time: 0.00
1385 Wall time: 0.00
1400 """
1386 """
1401
1387
1402 # fail immediately if the given expression can't be compiled
1388 # fail immediately if the given expression can't be compiled
1403 try:
1389 try:
1404 mode = 'eval'
1390 mode = 'eval'
1405 code = compile(parameter_s,'<timed eval>',mode)
1391 code = compile(parameter_s,'<timed eval>',mode)
1406 except SyntaxError:
1392 except SyntaxError:
1407 mode = 'exec'
1393 mode = 'exec'
1408 code = compile(parameter_s,'<timed exec>',mode)
1394 code = compile(parameter_s,'<timed exec>',mode)
1409 # skew measurement as little as possible
1395 # skew measurement as little as possible
1410 glob = self.shell.user_ns
1396 glob = self.shell.user_ns
1411 clk = clock2
1397 clk = clock2
1412 wtime = time.time
1398 wtime = time.time
1413 # time execution
1399 # time execution
1414 wall_st = wtime()
1400 wall_st = wtime()
1415 if mode=='eval':
1401 if mode=='eval':
1416 st = clk()
1402 st = clk()
1417 out = eval(code,glob)
1403 out = eval(code,glob)
1418 end = clk()
1404 end = clk()
1419 else:
1405 else:
1420 st = clk()
1406 st = clk()
1421 exec code in glob
1407 exec code in glob
1422 end = clk()
1408 end = clk()
1423 out = None
1409 out = None
1424 wall_end = wtime()
1410 wall_end = wtime()
1425 # Compute actual times and report
1411 # Compute actual times and report
1426 wall_time = wall_end-wall_st
1412 wall_time = wall_end-wall_st
1427 cpu_user = end[0]-st[0]
1413 cpu_user = end[0]-st[0]
1428 cpu_sys = end[1]-st[1]
1414 cpu_sys = end[1]-st[1]
1429 cpu_tot = cpu_user+cpu_sys
1415 cpu_tot = cpu_user+cpu_sys
1430 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1416 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1431 (cpu_user,cpu_sys,cpu_tot)
1417 (cpu_user,cpu_sys,cpu_tot)
1432 print "Wall time: %.2f" % wall_time
1418 print "Wall time: %.2f" % wall_time
1433 return out
1419 return out
1434
1420
1435 def magic_macro(self,parameter_s = ''):
1421 def magic_macro(self,parameter_s = ''):
1436 """Define a set of input lines as a macro for future re-execution.
1422 """Define a set of input lines as a macro for future re-execution.
1437
1423
1438 Usage:\\
1424 Usage:\\
1439 %macro name n1:n2 n3:n4 ... n5 .. n6 ...
1425 %macro name n1:n2 n3:n4 ... n5 .. n6 ...
1440
1426
1441 This will define a global variable called `name` which is a string
1427 This will define a global variable called `name` which is a string
1442 made of joining the slices and lines you specify (n1,n2,... numbers
1428 made of joining the slices and lines you specify (n1,n2,... numbers
1443 above) from your input history into a single string. This variable
1429 above) from your input history into a single string. This variable
1444 acts like an automatic function which re-executes those lines as if
1430 acts like an automatic function which re-executes those lines as if
1445 you had typed them. You just type 'name' at the prompt and the code
1431 you had typed them. You just type 'name' at the prompt and the code
1446 executes.
1432 executes.
1447
1433
1448 Note that the slices use the standard Python slicing notation (5:8
1434 Note that the slices use the standard Python slicing notation (5:8
1449 means include lines numbered 5,6,7).
1435 means include lines numbered 5,6,7).
1450
1436
1451 For example, if your history contains (%hist prints it):
1437 For example, if your history contains (%hist prints it):
1452
1438
1453 44: x=1\\
1439 44: x=1\\
1454 45: y=3\\
1440 45: y=3\\
1455 46: z=x+y\\
1441 46: z=x+y\\
1456 47: print x\\
1442 47: print x\\
1457 48: a=5\\
1443 48: a=5\\
1458 49: print 'x',x,'y',y\\
1444 49: print 'x',x,'y',y\\
1459
1445
1460 you can create a macro with lines 44 through 47 (included) and line 49
1446 you can create a macro with lines 44 through 47 (included) and line 49
1461 called my_macro with:
1447 called my_macro with:
1462
1448
1463 In [51]: %macro my_macro 44:48 49
1449 In [51]: %macro my_macro 44:48 49
1464
1450
1465 Now, typing `my_macro` (without quotes) will re-execute all this code
1451 Now, typing `my_macro` (without quotes) will re-execute all this code
1466 in one pass.
1452 in one pass.
1467
1453
1468 You don't need to give the line-numbers in order, and any given line
1454 You don't need to give the line-numbers in order, and any given line
1469 number can appear multiple times. You can assemble macros with any
1455 number can appear multiple times. You can assemble macros with any
1470 lines from your input history in any order.
1456 lines from your input history in any order.
1471
1457
1472 The macro is a simple object which holds its value in an attribute,
1458 The macro is a simple object which holds its value in an attribute,
1473 but IPython's display system checks for macros and executes them as
1459 but IPython's display system checks for macros and executes them as
1474 code instead of printing them when you type their name.
1460 code instead of printing them when you type their name.
1475
1461
1476 You can view a macro's contents by explicitly printing it with:
1462 You can view a macro's contents by explicitly printing it with:
1477
1463
1478 'print macro_name'.
1464 'print macro_name'.
1479
1465
1480 For one-off cases which DON'T contain magic function calls in them you
1466 For one-off cases which DON'T contain magic function calls in them you
1481 can obtain similar results by explicitly executing slices from your
1467 can obtain similar results by explicitly executing slices from your
1482 input history with:
1468 input history with:
1483
1469
1484 In [60]: exec In[44:48]+In[49]"""
1470 In [60]: exec In[44:48]+In[49]"""
1485
1471
1486 args = parameter_s.split()
1472 args = parameter_s.split()
1487 name,ranges = args[0], args[1:]
1473 name,ranges = args[0], args[1:]
1488 #print 'rng',ranges # dbg
1474 #print 'rng',ranges # dbg
1489 cmds = self.extract_input_slices(ranges)
1475 cmds = self.extract_input_slices(ranges)
1490 macro = Macro(cmds)
1476 macro = Macro(cmds)
1491 self.shell.user_ns.update({name:macro})
1477 self.shell.user_ns.update({name:macro})
1492 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1478 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1493 print 'Macro contents:'
1479 print 'Macro contents:'
1494 print str(macro).rstrip(),
1480 print str(macro).rstrip(),
1495
1481
1496 def magic_save(self,parameter_s = ''):
1482 def magic_save(self,parameter_s = ''):
1497 """Save a set of lines to a given filename.
1483 """Save a set of lines to a given filename.
1498
1484
1499 Usage:\\
1485 Usage:\\
1500 %save filename n1:n2 n3:n4 ... n5 .. n6 ...
1486 %save filename n1:n2 n3:n4 ... n5 .. n6 ...
1501
1487
1502 This function uses the same syntax as %macro for line extraction, but
1488 This function uses the same syntax as %macro for line extraction, but
1503 instead of creating a macro it saves the resulting string to the
1489 instead of creating a macro it saves the resulting string to the
1504 filename you specify.
1490 filename you specify.
1505
1491
1506 It adds a '.py' extension to the file if you don't do so yourself, and
1492 It adds a '.py' extension to the file if you don't do so yourself, and
1507 it asks for confirmation before overwriting existing files."""
1493 it asks for confirmation before overwriting existing files."""
1508
1494
1509 args = parameter_s.split()
1495 args = parameter_s.split()
1510 fname,ranges = args[0], args[1:]
1496 fname,ranges = args[0], args[1:]
1511 if not fname.endswith('.py'):
1497 if not fname.endswith('.py'):
1512 fname += '.py'
1498 fname += '.py'
1513 if os.path.isfile(fname):
1499 if os.path.isfile(fname):
1514 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1500 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1515 if ans.lower() not in ['y','yes']:
1501 if ans.lower() not in ['y','yes']:
1516 print 'Operation cancelled.'
1502 print 'Operation cancelled.'
1517 return
1503 return
1518 cmds = ''.join(self.extract_input_slices(ranges))
1504 cmds = ''.join(self.extract_input_slices(ranges))
1519 f = file(fname,'w')
1505 f = file(fname,'w')
1520 f.write(cmds)
1506 f.write(cmds)
1521 f.close()
1507 f.close()
1522 print 'The following commands were written to file `%s`:' % fname
1508 print 'The following commands were written to file `%s`:' % fname
1523 print cmds
1509 print cmds
1524
1510
1525 def magic_ed(self,parameter_s = ''):
1511 def magic_ed(self,parameter_s = ''):
1526 """Alias to %edit."""
1512 """Alias to %edit."""
1527 return self.magic_edit(parameter_s)
1513 return self.magic_edit(parameter_s)
1528
1514
1529 def magic_edit(self,parameter_s = '',last_call=['','']):
1515 def magic_edit(self,parameter_s = '',last_call=['','']):
1530 """Bring up an editor and execute the resulting code.
1516 """Bring up an editor and execute the resulting code.
1531
1517
1532 Usage:
1518 Usage:
1533 %edit [options] [args]
1519 %edit [options] [args]
1534
1520
1535 %edit runs IPython's editor hook. The default version of this hook is
1521 %edit runs IPython's editor hook. The default version of this hook is
1536 set to call the __IPYTHON__.rc.editor command. This is read from your
1522 set to call the __IPYTHON__.rc.editor command. This is read from your
1537 environment variable $EDITOR. If this isn't found, it will default to
1523 environment variable $EDITOR. If this isn't found, it will default to
1538 vi under Linux/Unix and to notepad under Windows. See the end of this
1524 vi under Linux/Unix and to notepad under Windows. See the end of this
1539 docstring for how to change the editor hook.
1525 docstring for how to change the editor hook.
1540
1526
1541 You can also set the value of this editor via the command line option
1527 You can also set the value of this editor via the command line option
1542 '-editor' or in your ipythonrc file. This is useful if you wish to use
1528 '-editor' or in your ipythonrc file. This is useful if you wish to use
1543 specifically for IPython an editor different from your typical default
1529 specifically for IPython an editor different from your typical default
1544 (and for Windows users who typically don't set environment variables).
1530 (and for Windows users who typically don't set environment variables).
1545
1531
1546 This command allows you to conveniently edit multi-line code right in
1532 This command allows you to conveniently edit multi-line code right in
1547 your IPython session.
1533 your IPython session.
1548
1534
1549 If called without arguments, %edit opens up an empty editor with a
1535 If called without arguments, %edit opens up an empty editor with a
1550 temporary file and will execute the contents of this file when you
1536 temporary file and will execute the contents of this file when you
1551 close it (don't forget to save it!).
1537 close it (don't forget to save it!).
1552
1538
1553 Options:
1539 Options:
1554
1540
1555 -p: this will call the editor with the same data as the previous time
1541 -p: this will call the editor with the same data as the previous time
1556 it was used, regardless of how long ago (in your current session) it
1542 it was used, regardless of how long ago (in your current session) it
1557 was.
1543 was.
1558
1544
1559 -x: do not execute the edited code immediately upon exit. This is
1545 -x: do not execute the edited code immediately upon exit. This is
1560 mainly useful if you are editing programs which need to be called with
1546 mainly useful if you are editing programs which need to be called with
1561 command line arguments, which you can then do using %run.
1547 command line arguments, which you can then do using %run.
1562
1548
1563 Arguments:
1549 Arguments:
1564
1550
1565 If arguments are given, the following possibilites exist:
1551 If arguments are given, the following possibilites exist:
1566
1552
1567 - The arguments are numbers or pairs of colon-separated numbers (like
1553 - The arguments are numbers or pairs of colon-separated numbers (like
1568 1 4:8 9). These are interpreted as lines of previous input to be
1554 1 4:8 9). These are interpreted as lines of previous input to be
1569 loaded into the editor. The syntax is the same of the %macro command.
1555 loaded into the editor. The syntax is the same of the %macro command.
1570
1556
1571 - If the argument doesn't start with a number, it is evaluated as a
1557 - If the argument doesn't start with a number, it is evaluated as a
1572 variable and its contents loaded into the editor. You can thus edit
1558 variable and its contents loaded into the editor. You can thus edit
1573 any string which contains python code (including the result of
1559 any string which contains python code (including the result of
1574 previous edits).
1560 previous edits).
1575
1561
1576 - If the argument is the name of an object (other than a string),
1562 - If the argument is the name of an object (other than a string),
1577 IPython will try to locate the file where it was defined and open the
1563 IPython will try to locate the file where it was defined and open the
1578 editor at the point where it is defined. You can use `%edit function`
1564 editor at the point where it is defined. You can use `%edit function`
1579 to load an editor exactly at the point where 'function' is defined,
1565 to load an editor exactly at the point where 'function' is defined,
1580 edit it and have the file be executed automatically.
1566 edit it and have the file be executed automatically.
1581
1567
1582 Note: opening at an exact line is only supported under Unix, and some
1568 Note: opening at an exact line is only supported under Unix, and some
1583 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1569 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1584 '+NUMBER' parameter necessary for this feature. Good editors like
1570 '+NUMBER' parameter necessary for this feature. Good editors like
1585 (X)Emacs, vi, jed, pico and joe all do.
1571 (X)Emacs, vi, jed, pico and joe all do.
1586
1572
1587 - If the argument is not found as a variable, IPython will look for a
1573 - If the argument is not found as a variable, IPython will look for a
1588 file with that name (adding .py if necessary) and load it into the
1574 file with that name (adding .py if necessary) and load it into the
1589 editor. It will execute its contents with execfile() when you exit,
1575 editor. It will execute its contents with execfile() when you exit,
1590 loading any code in the file into your interactive namespace.
1576 loading any code in the file into your interactive namespace.
1591
1577
1592 After executing your code, %edit will return as output the code you
1578 After executing your code, %edit will return as output the code you
1593 typed in the editor (except when it was an existing file). This way
1579 typed in the editor (except when it was an existing file). This way
1594 you can reload the code in further invocations of %edit as a variable,
1580 you can reload the code in further invocations of %edit as a variable,
1595 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1581 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1596 the output.
1582 the output.
1597
1583
1598 Note that %edit is also available through the alias %ed.
1584 Note that %edit is also available through the alias %ed.
1599
1585
1600 This is an example of creating a simple function inside the editor and
1586 This is an example of creating a simple function inside the editor and
1601 then modifying it. First, start up the editor:
1587 then modifying it. First, start up the editor:
1602
1588
1603 In [1]: ed\\
1589 In [1]: ed\\
1604 Editing... done. Executing edited code...\\
1590 Editing... done. Executing edited code...\\
1605 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
1591 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
1606
1592
1607 We can then call the function foo():
1593 We can then call the function foo():
1608
1594
1609 In [2]: foo()\\
1595 In [2]: foo()\\
1610 foo() was defined in an editing session
1596 foo() was defined in an editing session
1611
1597
1612 Now we edit foo. IPython automatically loads the editor with the
1598 Now we edit foo. IPython automatically loads the editor with the
1613 (temporary) file where foo() was previously defined:
1599 (temporary) file where foo() was previously defined:
1614
1600
1615 In [3]: ed foo\\
1601 In [3]: ed foo\\
1616 Editing... done. Executing edited code...
1602 Editing... done. Executing edited code...
1617
1603
1618 And if we call foo() again we get the modified version:
1604 And if we call foo() again we get the modified version:
1619
1605
1620 In [4]: foo()\\
1606 In [4]: foo()\\
1621 foo() has now been changed!
1607 foo() has now been changed!
1622
1608
1623 Here is an example of how to edit a code snippet successive
1609 Here is an example of how to edit a code snippet successive
1624 times. First we call the editor:
1610 times. First we call the editor:
1625
1611
1626 In [8]: ed\\
1612 In [8]: ed\\
1627 Editing... done. Executing edited code...\\
1613 Editing... done. Executing edited code...\\
1628 hello\\
1614 hello\\
1629 Out[8]: "print 'hello'\\n"
1615 Out[8]: "print 'hello'\\n"
1630
1616
1631 Now we call it again with the previous output (stored in _):
1617 Now we call it again with the previous output (stored in _):
1632
1618
1633 In [9]: ed _\\
1619 In [9]: ed _\\
1634 Editing... done. Executing edited code...\\
1620 Editing... done. Executing edited code...\\
1635 hello world\\
1621 hello world\\
1636 Out[9]: "print 'hello world'\\n"
1622 Out[9]: "print 'hello world'\\n"
1637
1623
1638 Now we call it with the output #8 (stored in _8, also as Out[8]):
1624 Now we call it with the output #8 (stored in _8, also as Out[8]):
1639
1625
1640 In [10]: ed _8\\
1626 In [10]: ed _8\\
1641 Editing... done. Executing edited code...\\
1627 Editing... done. Executing edited code...\\
1642 hello again\\
1628 hello again\\
1643 Out[10]: "print 'hello again'\\n"
1629 Out[10]: "print 'hello again'\\n"
1644
1630
1645
1631
1646 Changing the default editor hook:
1632 Changing the default editor hook:
1647
1633
1648 If you wish to write your own editor hook, you can put it in a
1634 If you wish to write your own editor hook, you can put it in a
1649 configuration file which you load at startup time. The default hook
1635 configuration file which you load at startup time. The default hook
1650 is defined in the IPython.hooks module, and you can use that as a
1636 is defined in the IPython.hooks module, and you can use that as a
1651 starting example for further modifications. That file also has
1637 starting example for further modifications. That file also has
1652 general instructions on how to set a new hook for use once you've
1638 general instructions on how to set a new hook for use once you've
1653 defined it."""
1639 defined it."""
1654
1640
1655 # FIXME: This function has become a convoluted mess. It needs a
1641 # FIXME: This function has become a convoluted mess. It needs a
1656 # ground-up rewrite with clean, simple logic.
1642 # ground-up rewrite with clean, simple logic.
1657
1643
1658 def make_filename(arg):
1644 def make_filename(arg):
1659 "Make a filename from the given args"
1645 "Make a filename from the given args"
1660 try:
1646 try:
1661 filename = get_py_filename(arg)
1647 filename = get_py_filename(arg)
1662 except IOError:
1648 except IOError:
1663 if args.endswith('.py'):
1649 if args.endswith('.py'):
1664 filename = arg
1650 filename = arg
1665 else:
1651 else:
1666 filename = None
1652 filename = None
1667 return filename
1653 return filename
1668
1654
1669 # custom exceptions
1655 # custom exceptions
1670 class DataIsObject(Exception): pass
1656 class DataIsObject(Exception): pass
1671
1657
1672 opts,args = self.parse_options(parameter_s,'px')
1658 opts,args = self.parse_options(parameter_s,'px')
1673
1659
1674 # Default line number value
1660 # Default line number value
1675 lineno = None
1661 lineno = None
1676 if opts.has_key('p'):
1662 if opts.has_key('p'):
1677 args = '_%s' % last_call[0]
1663 args = '_%s' % last_call[0]
1678 if not self.shell.user_ns.has_key(args):
1664 if not self.shell.user_ns.has_key(args):
1679 args = last_call[1]
1665 args = last_call[1]
1680
1666
1681 # use last_call to remember the state of the previous call, but don't
1667 # use last_call to remember the state of the previous call, but don't
1682 # let it be clobbered by successive '-p' calls.
1668 # let it be clobbered by successive '-p' calls.
1683 try:
1669 try:
1684 last_call[0] = self.shell.outputcache.prompt_count
1670 last_call[0] = self.shell.outputcache.prompt_count
1685 if not opts.has_key('p'):
1671 if not opts.has_key('p'):
1686 last_call[1] = parameter_s
1672 last_call[1] = parameter_s
1687 except:
1673 except:
1688 pass
1674 pass
1689
1675
1690 # by default this is done with temp files, except when the given
1676 # by default this is done with temp files, except when the given
1691 # arg is a filename
1677 # arg is a filename
1692 use_temp = 1
1678 use_temp = 1
1693
1679
1694 if re.match(r'\d',args):
1680 if re.match(r'\d',args):
1695 # Mode where user specifies ranges of lines, like in %macro.
1681 # Mode where user specifies ranges of lines, like in %macro.
1696 # This means that you can't edit files whose names begin with
1682 # This means that you can't edit files whose names begin with
1697 # numbers this way. Tough.
1683 # numbers this way. Tough.
1698 ranges = args.split()
1684 ranges = args.split()
1699 data = ''.join(self.extract_input_slices(ranges))
1685 data = ''.join(self.extract_input_slices(ranges))
1700 elif args.endswith('.py'):
1686 elif args.endswith('.py'):
1701 filename = make_filename(args)
1687 filename = make_filename(args)
1702 data = ''
1688 data = ''
1703 use_temp = 0
1689 use_temp = 0
1704 elif args:
1690 elif args:
1705 try:
1691 try:
1706 # Load the parameter given as a variable. If not a string,
1692 # Load the parameter given as a variable. If not a string,
1707 # process it as an object instead (below)
1693 # process it as an object instead (below)
1708
1694
1709 #print '*** args',args,'type',type(args) # dbg
1695 #print '*** args',args,'type',type(args) # dbg
1710 data = eval(args,self.shell.user_ns)
1696 data = eval(args,self.shell.user_ns)
1711 if not type(data) in StringTypes:
1697 if not type(data) in StringTypes:
1712 raise DataIsObject
1698 raise DataIsObject
1713 except (NameError,SyntaxError):
1699 except (NameError,SyntaxError):
1714 # given argument is not a variable, try as a filename
1700 # given argument is not a variable, try as a filename
1715 filename = make_filename(args)
1701 filename = make_filename(args)
1716 if filename is None:
1702 if filename is None:
1717 warn("Argument given (%s) can't be found as a variable "
1703 warn("Argument given (%s) can't be found as a variable "
1718 "or as a filename." % args)
1704 "or as a filename." % args)
1719 return
1705 return
1720 data = ''
1706 data = ''
1721 use_temp = 0
1707 use_temp = 0
1722 except DataIsObject:
1708 except DataIsObject:
1723 # For objects, try to edit the file where they are defined
1709 # For objects, try to edit the file where they are defined
1724 try:
1710 try:
1725 filename = inspect.getabsfile(data)
1711 filename = inspect.getabsfile(data)
1726 datafile = 1
1712 datafile = 1
1727 except TypeError:
1713 except TypeError:
1728 filename = make_filename(args)
1714 filename = make_filename(args)
1729 datafile = 1
1715 datafile = 1
1730 warn('Could not find file where `%s` is defined.\n'
1716 warn('Could not find file where `%s` is defined.\n'
1731 'Opening a file named `%s`' % (args,filename))
1717 'Opening a file named `%s`' % (args,filename))
1732 # Now, make sure we can actually read the source (if it was in
1718 # Now, make sure we can actually read the source (if it was in
1733 # a temp file it's gone by now).
1719 # a temp file it's gone by now).
1734 if datafile:
1720 if datafile:
1735 try:
1721 try:
1736 lineno = inspect.getsourcelines(data)[1]
1722 lineno = inspect.getsourcelines(data)[1]
1737 except IOError:
1723 except IOError:
1738 filename = make_filename(args)
1724 filename = make_filename(args)
1739 if filename is None:
1725 if filename is None:
1740 warn('The file `%s` where `%s` was defined cannot '
1726 warn('The file `%s` where `%s` was defined cannot '
1741 'be read.' % (filename,data))
1727 'be read.' % (filename,data))
1742 return
1728 return
1743 use_temp = 0
1729 use_temp = 0
1744 else:
1730 else:
1745 data = ''
1731 data = ''
1746
1732
1747 if use_temp:
1733 if use_temp:
1748 filename = tempfile.mktemp('.py')
1734 filename = tempfile.mktemp('.py')
1749 self.shell.tempfiles.append(filename)
1735 self.shell.tempfiles.append(filename)
1750
1736
1751 if data and use_temp:
1737 if data and use_temp:
1752 tmp_file = open(filename,'w')
1738 tmp_file = open(filename,'w')
1753 tmp_file.write(data)
1739 tmp_file.write(data)
1754 tmp_file.close()
1740 tmp_file.close()
1755
1741
1756 # do actual editing here
1742 # do actual editing here
1757 print 'Editing...',
1743 print 'Editing...',
1758 sys.stdout.flush()
1744 sys.stdout.flush()
1759 self.shell.hooks.editor(filename,lineno)
1745 self.shell.hooks.editor(filename,lineno)
1760 if opts.has_key('x'): # -x prevents actual execution
1746 if opts.has_key('x'): # -x prevents actual execution
1761 print
1747 print
1762 else:
1748 else:
1763 print 'done. Executing edited code...'
1749 print 'done. Executing edited code...'
1764 try:
1750 try:
1765 execfile(filename,self.shell.user_ns)
1751 execfile(filename,self.shell.user_ns)
1766 except IOError,msg:
1752 except IOError,msg:
1767 if msg.filename == filename:
1753 if msg.filename == filename:
1768 warn('File not found. Did you forget to save?')
1754 warn('File not found. Did you forget to save?')
1769 return
1755 return
1770 else:
1756 else:
1771 self.shell.showtraceback()
1757 self.shell.showtraceback()
1772 except:
1758 except:
1773 self.shell.showtraceback()
1759 self.shell.showtraceback()
1774 if use_temp:
1760 if use_temp:
1775 contents = open(filename).read()
1761 contents = open(filename).read()
1776 return contents
1762 return contents
1777
1763
1778 def magic_xmode(self,parameter_s = ''):
1764 def magic_xmode(self,parameter_s = ''):
1779 """Switch modes for the exception handlers.
1765 """Switch modes for the exception handlers.
1780
1766
1781 Valid modes: Plain, Context and Verbose.
1767 Valid modes: Plain, Context and Verbose.
1782
1768
1783 If called without arguments, acts as a toggle."""
1769 If called without arguments, acts as a toggle."""
1784
1770
1785 new_mode = parameter_s.strip().capitalize()
1771 new_mode = parameter_s.strip().capitalize()
1786 try:
1772 try:
1787 self.InteractiveTB.set_mode(mode = new_mode)
1773 self.InteractiveTB.set_mode(mode = new_mode)
1788 print 'Exception reporting mode:',self.InteractiveTB.mode
1774 print 'Exception reporting mode:',self.InteractiveTB.mode
1789 except:
1775 except:
1790 warn('Error changing exception modes.\n' + str(sys.exc_info()[1]))
1776 warn('Error changing exception modes.\n' + str(sys.exc_info()[1]))
1791
1777
1792 def magic_colors(self,parameter_s = ''):
1778 def magic_colors(self,parameter_s = ''):
1793 """Switch color scheme for prompts, info system and exception handlers.
1779 """Switch color scheme for prompts, info system and exception handlers.
1794
1780
1795 Currently implemented schemes: NoColor, Linux, LightBG.
1781 Currently implemented schemes: NoColor, Linux, LightBG.
1796
1782
1797 Color scheme names are not case-sensitive."""
1783 Color scheme names are not case-sensitive."""
1798
1784
1799 new_scheme = parameter_s.strip()
1785 new_scheme = parameter_s.strip()
1800 if not new_scheme:
1786 if not new_scheme:
1801 print 'You must specify a color scheme.'
1787 print 'You must specify a color scheme.'
1802 return
1788 return
1803 # Under Windows, check for Gary Bishop's readline, which is necessary
1789 # Under Windows, check for Gary Bishop's readline, which is necessary
1804 # for ANSI coloring
1790 # for ANSI coloring
1805 if os.name in ['nt','dos']:
1791 if os.name in ['nt','dos']:
1806 try:
1792 try:
1807 import readline
1793 import readline
1808 except ImportError:
1794 except ImportError:
1809 has_readline = 0
1795 has_readline = 0
1810 else:
1796 else:
1811 try:
1797 try:
1812 readline.GetOutputFile()
1798 readline.GetOutputFile()
1813 except AttributeError:
1799 except AttributeError:
1814 has_readline = 0
1800 has_readline = 0
1815 else:
1801 else:
1816 has_readline = 1
1802 has_readline = 1
1817 if not has_readline:
1803 if not has_readline:
1818 msg = """\
1804 msg = """\
1819 Proper color support under MS Windows requires Gary Bishop's readline library.
1805 Proper color support under MS Windows requires Gary Bishop's readline library.
1820 You can find it at:
1806 You can find it at:
1821 http://sourceforge.net/projects/uncpythontools
1807 http://sourceforge.net/projects/uncpythontools
1822 Gary's readline needs the ctypes module, from:
1808 Gary's readline needs the ctypes module, from:
1823 http://starship.python.net/crew/theller/ctypes
1809 http://starship.python.net/crew/theller/ctypes
1824
1810
1825 Defaulting color scheme to 'NoColor'"""
1811 Defaulting color scheme to 'NoColor'"""
1826 new_scheme = 'NoColor'
1812 new_scheme = 'NoColor'
1827 warn(msg)
1813 warn(msg)
1828
1814
1829 # Set prompt colors
1815 # Set prompt colors
1830 try:
1816 try:
1831 self.shell.outputcache.set_colors(new_scheme)
1817 self.shell.outputcache.set_colors(new_scheme)
1832 except:
1818 except:
1833 warn('Error changing prompt color schemes.\n'
1819 warn('Error changing prompt color schemes.\n'
1834 + str(sys.exc_info()[1]))
1820 + str(sys.exc_info()[1]))
1835 else:
1821 else:
1836 self.shell.rc.colors = \
1822 self.shell.rc.colors = \
1837 self.shell.outputcache.color_table.active_scheme_name
1823 self.shell.outputcache.color_table.active_scheme_name
1838 # Set exception colors
1824 # Set exception colors
1839 try:
1825 try:
1840 self.shell.InteractiveTB.set_colors(scheme = new_scheme)
1826 self.shell.InteractiveTB.set_colors(scheme = new_scheme)
1841 self.shell.SyntaxTB.set_colors(scheme = new_scheme)
1827 self.shell.SyntaxTB.set_colors(scheme = new_scheme)
1842 except:
1828 except:
1843 warn('Error changing exception color schemes.\n'
1829 warn('Error changing exception color schemes.\n'
1844 + str(sys.exc_info()[1]))
1830 + str(sys.exc_info()[1]))
1845 # Set info (for 'object?') colors
1831 # Set info (for 'object?') colors
1846 if self.shell.rc.color_info:
1832 if self.shell.rc.color_info:
1847 try:
1833 try:
1848 self.shell.inspector.set_active_scheme(new_scheme)
1834 self.shell.inspector.set_active_scheme(new_scheme)
1849 except:
1835 except:
1850 warn('Error changing object inspector color schemes.\n'
1836 warn('Error changing object inspector color schemes.\n'
1851 + str(sys.exc_info()[1]))
1837 + str(sys.exc_info()[1]))
1852 else:
1838 else:
1853 self.shell.inspector.set_active_scheme('NoColor')
1839 self.shell.inspector.set_active_scheme('NoColor')
1854
1840
1855 def magic_color_info(self,parameter_s = ''):
1841 def magic_color_info(self,parameter_s = ''):
1856 """Toggle color_info.
1842 """Toggle color_info.
1857
1843
1858 The color_info configuration parameter controls whether colors are
1844 The color_info configuration parameter controls whether colors are
1859 used for displaying object details (by things like %psource, %pfile or
1845 used for displaying object details (by things like %psource, %pfile or
1860 the '?' system). This function toggles this value with each call.
1846 the '?' system). This function toggles this value with each call.
1861
1847
1862 Note that unless you have a fairly recent pager (less works better
1848 Note that unless you have a fairly recent pager (less works better
1863 than more) in your system, using colored object information displays
1849 than more) in your system, using colored object information displays
1864 will not work properly. Test it and see."""
1850 will not work properly. Test it and see."""
1865
1851
1866 self.shell.rc.color_info = 1 - self.shell.rc.color_info
1852 self.shell.rc.color_info = 1 - self.shell.rc.color_info
1867 self.magic_colors(self.shell.rc.colors)
1853 self.magic_colors(self.shell.rc.colors)
1868 print 'Object introspection functions have now coloring:',
1854 print 'Object introspection functions have now coloring:',
1869 print ['OFF','ON'][self.shell.rc.color_info]
1855 print ['OFF','ON'][self.shell.rc.color_info]
1870
1856
1871 def magic_Pprint(self, parameter_s=''):
1857 def magic_Pprint(self, parameter_s=''):
1872 """Toggle pretty printing on/off."""
1858 """Toggle pretty printing on/off."""
1873
1859
1874 self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint
1860 self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint
1875 print 'Pretty printing has been turned', \
1861 print 'Pretty printing has been turned', \
1876 ['OFF','ON'][self.shell.outputcache.Pprint]
1862 ['OFF','ON'][self.shell.outputcache.Pprint]
1877
1863
1878 def magic_Exit(self, parameter_s=''):
1864 def magic_Exit(self, parameter_s=''):
1879 """Exit IPython without confirmation."""
1865 """Exit IPython without confirmation."""
1880
1866
1881 self.shell.exit_now = True
1867 self.shell.exit_now = True
1882
1868
1883 def magic_Quit(self, parameter_s=''):
1869 def magic_Quit(self, parameter_s=''):
1884 """Exit IPython without confirmation (like %Exit)."""
1870 """Exit IPython without confirmation (like %Exit)."""
1885
1871
1886 self.shell.exit_now = True
1872 self.shell.exit_now = True
1887
1873
1888 #......................................................................
1874 #......................................................................
1889 # Functions to implement unix shell-type things
1875 # Functions to implement unix shell-type things
1890
1876
1891 def magic_alias(self, parameter_s = ''):
1877 def magic_alias(self, parameter_s = ''):
1892 """Define an alias for a system command.
1878 """Define an alias for a system command.
1893
1879
1894 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
1880 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
1895
1881
1896 Then, typing 'alias_name params' will execute the system command 'cmd
1882 Then, typing 'alias_name params' will execute the system command 'cmd
1897 params' (from your underlying operating system).
1883 params' (from your underlying operating system).
1898
1884
1899 Aliases have lower precedence than magic functions and Python normal
1885 Aliases have lower precedence than magic functions and Python normal
1900 variables, so if 'foo' is both a Python variable and an alias, the
1886 variables, so if 'foo' is both a Python variable and an alias, the
1901 alias can not be executed until 'del foo' removes the Python variable.
1887 alias can not be executed until 'del foo' removes the Python variable.
1902
1888
1903 You can use the %l specifier in an alias definition to represent the
1889 You can use the %l specifier in an alias definition to represent the
1904 whole line when the alias is called. For example:
1890 whole line when the alias is called. For example:
1905
1891
1906 In [2]: alias all echo "Input in brackets: <%l>"\\
1892 In [2]: alias all echo "Input in brackets: <%l>"\\
1907 In [3]: all hello world\\
1893 In [3]: all hello world\\
1908 Input in brackets: <hello world>
1894 Input in brackets: <hello world>
1909
1895
1910 You can also define aliases with parameters using %s specifiers (one
1896 You can also define aliases with parameters using %s specifiers (one
1911 per parameter):
1897 per parameter):
1912
1898
1913 In [1]: alias parts echo first %s second %s\\
1899 In [1]: alias parts echo first %s second %s\\
1914 In [2]: %parts A B\\
1900 In [2]: %parts A B\\
1915 first A second B\\
1901 first A second B\\
1916 In [3]: %parts A\\
1902 In [3]: %parts A\\
1917 Incorrect number of arguments: 2 expected.\\
1903 Incorrect number of arguments: 2 expected.\\
1918 parts is an alias to: 'echo first %s second %s'
1904 parts is an alias to: 'echo first %s second %s'
1919
1905
1920 Note that %l and %s are mutually exclusive. You can only use one or
1906 Note that %l and %s are mutually exclusive. You can only use one or
1921 the other in your aliases.
1907 the other in your aliases.
1922
1908
1923 Aliases expand Python variables just like system calls using ! or !!
1909 Aliases expand Python variables just like system calls using ! or !!
1924 do: all expressions prefixed with '$' get expanded. For details of
1910 do: all expressions prefixed with '$' get expanded. For details of
1925 the semantic rules, see PEP-215:
1911 the semantic rules, see PEP-215:
1926 http://www.python.org/peps/pep-0215.html. This is the library used by
1912 http://www.python.org/peps/pep-0215.html. This is the library used by
1927 IPython for variable expansion. If you want to access a true shell
1913 IPython for variable expansion. If you want to access a true shell
1928 variable, an extra $ is necessary to prevent its expansion by IPython:
1914 variable, an extra $ is necessary to prevent its expansion by IPython:
1929
1915
1930 In [6]: alias show echo\\
1916 In [6]: alias show echo\\
1931 In [7]: PATH='A Python string'\\
1917 In [7]: PATH='A Python string'\\
1932 In [8]: show $PATH\\
1918 In [8]: show $PATH\\
1933 A Python string\\
1919 A Python string\\
1934 In [9]: show $$PATH\\
1920 In [9]: show $$PATH\\
1935 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1921 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1936
1922
1937 You can use the alias facility to acess all of $PATH. See the %rehash
1923 You can use the alias facility to acess all of $PATH. See the %rehash
1938 and %rehashx functions, which automatically create aliases for the
1924 and %rehashx functions, which automatically create aliases for the
1939 contents of your $PATH.
1925 contents of your $PATH.
1940
1926
1941 If called with no parameters, %alias prints the current alias table."""
1927 If called with no parameters, %alias prints the current alias table."""
1942
1928
1943 par = parameter_s.strip()
1929 par = parameter_s.strip()
1944 if not par:
1930 if not par:
1945 if self.shell.rc.automagic:
1931 if self.shell.rc.automagic:
1946 prechar = ''
1932 prechar = ''
1947 else:
1933 else:
1948 prechar = self.shell.ESC_MAGIC
1934 prechar = self.shell.ESC_MAGIC
1949 print 'Alias\t\tSystem Command\n'+'-'*30
1935 print 'Alias\t\tSystem Command\n'+'-'*30
1950 atab = self.shell.alias_table
1936 atab = self.shell.alias_table
1951 aliases = atab.keys()
1937 aliases = atab.keys()
1952 aliases.sort()
1938 aliases.sort()
1953 for alias in aliases:
1939 for alias in aliases:
1954 print prechar+alias+'\t\t'+atab[alias][1]
1940 print prechar+alias+'\t\t'+atab[alias][1]
1955 print '-'*30+'\nTotal number of aliases:',len(aliases)
1941 print '-'*30+'\nTotal number of aliases:',len(aliases)
1956 return
1942 return
1957 try:
1943 try:
1958 alias,cmd = par.split(None,1)
1944 alias,cmd = par.split(None,1)
1959 except:
1945 except:
1960 print OInspect.getdoc(self.magic_alias)
1946 print OInspect.getdoc(self.magic_alias)
1961 else:
1947 else:
1962 nargs = cmd.count('%s')
1948 nargs = cmd.count('%s')
1963 if nargs>0 and cmd.find('%l')>=0:
1949 if nargs>0 and cmd.find('%l')>=0:
1964 error('The %s and %l specifiers are mutually exclusive '
1950 error('The %s and %l specifiers are mutually exclusive '
1965 'in alias definitions.')
1951 'in alias definitions.')
1966 else: # all looks OK
1952 else: # all looks OK
1967 self.shell.alias_table[alias] = (nargs,cmd)
1953 self.shell.alias_table[alias] = (nargs,cmd)
1968 self.shell.alias_table_validate(verbose=1)
1954 self.shell.alias_table_validate(verbose=1)
1969 # end magic_alias
1955 # end magic_alias
1970
1956
1971 def magic_unalias(self, parameter_s = ''):
1957 def magic_unalias(self, parameter_s = ''):
1972 """Remove an alias"""
1958 """Remove an alias"""
1973
1959
1974 aname = parameter_s.strip()
1960 aname = parameter_s.strip()
1975 if aname in self.shell.alias_table:
1961 if aname in self.shell.alias_table:
1976 del self.shell.alias_table[aname]
1962 del self.shell.alias_table[aname]
1977
1963
1978 def magic_rehash(self, parameter_s = ''):
1964 def magic_rehash(self, parameter_s = ''):
1979 """Update the alias table with all entries in $PATH.
1965 """Update the alias table with all entries in $PATH.
1980
1966
1981 This version does no checks on execute permissions or whether the
1967 This version does no checks on execute permissions or whether the
1982 contents of $PATH are truly files (instead of directories or something
1968 contents of $PATH are truly files (instead of directories or something
1983 else). For such a safer (but slower) version, use %rehashx."""
1969 else). For such a safer (but slower) version, use %rehashx."""
1984
1970
1985 # This function (and rehashx) manipulate the alias_table directly
1971 # This function (and rehashx) manipulate the alias_table directly
1986 # rather than calling magic_alias, for speed reasons. A rehash on a
1972 # rather than calling magic_alias, for speed reasons. A rehash on a
1987 # typical Linux box involves several thousand entries, so efficiency
1973 # typical Linux box involves several thousand entries, so efficiency
1988 # here is a top concern.
1974 # here is a top concern.
1989
1975
1990 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
1976 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
1991 alias_table = self.shell.alias_table
1977 alias_table = self.shell.alias_table
1992 for pdir in path:
1978 for pdir in path:
1993 for ff in os.listdir(pdir):
1979 for ff in os.listdir(pdir):
1994 # each entry in the alias table must be (N,name), where
1980 # each entry in the alias table must be (N,name), where
1995 # N is the number of positional arguments of the alias.
1981 # N is the number of positional arguments of the alias.
1996 alias_table[ff] = (0,ff)
1982 alias_table[ff] = (0,ff)
1997 # Make sure the alias table doesn't contain keywords or builtins
1983 # Make sure the alias table doesn't contain keywords or builtins
1998 self.shell.alias_table_validate()
1984 self.shell.alias_table_validate()
1999 # Call again init_auto_alias() so we get 'rm -i' and other modified
1985 # Call again init_auto_alias() so we get 'rm -i' and other modified
2000 # aliases since %rehash will probably clobber them
1986 # aliases since %rehash will probably clobber them
2001 self.shell.init_auto_alias()
1987 self.shell.init_auto_alias()
2002
1988
2003 def magic_rehashx(self, parameter_s = ''):
1989 def magic_rehashx(self, parameter_s = ''):
2004 """Update the alias table with all executable files in $PATH.
1990 """Update the alias table with all executable files in $PATH.
2005
1991
2006 This version explicitly checks that every entry in $PATH is a file
1992 This version explicitly checks that every entry in $PATH is a file
2007 with execute access (os.X_OK), so it is much slower than %rehash.
1993 with execute access (os.X_OK), so it is much slower than %rehash.
2008
1994
2009 Under Windows, it checks executability as a match agains a
1995 Under Windows, it checks executability as a match agains a
2010 '|'-separated string of extensions, stored in the IPython config
1996 '|'-separated string of extensions, stored in the IPython config
2011 variable win_exec_ext. This defaults to 'exe|com|bat'. """
1997 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2012
1998
2013 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
1999 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2014 alias_table = self.shell.alias_table
2000 alias_table = self.shell.alias_table
2015
2001
2016 if os.name == 'posix':
2002 if os.name == 'posix':
2017 isexec = lambda fname:os.path.isfile(fname) and \
2003 isexec = lambda fname:os.path.isfile(fname) and \
2018 os.access(fname,os.X_OK)
2004 os.access(fname,os.X_OK)
2019 else:
2005 else:
2020
2006
2021 try:
2007 try:
2022 winext = os.environ['pathext'].replace(';','|').replace('.','')
2008 winext = os.environ['pathext'].replace(';','|').replace('.','')
2023 except KeyError:
2009 except KeyError:
2024 winext = 'exe|com|bat'
2010 winext = 'exe|com|bat'
2025
2011
2026 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2012 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2027 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2013 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2028 savedir = os.getcwd()
2014 savedir = os.getcwd()
2029 try:
2015 try:
2030 # write the whole loop for posix/Windows so we don't have an if in
2016 # write the whole loop for posix/Windows so we don't have an if in
2031 # the innermost part
2017 # the innermost part
2032 if os.name == 'posix':
2018 if os.name == 'posix':
2033 for pdir in path:
2019 for pdir in path:
2034 os.chdir(pdir)
2020 os.chdir(pdir)
2035 for ff in os.listdir(pdir):
2021 for ff in os.listdir(pdir):
2036 if isexec(ff):
2022 if isexec(ff):
2037 # each entry in the alias table must be (N,name),
2023 # each entry in the alias table must be (N,name),
2038 # where N is the number of positional arguments of the
2024 # where N is the number of positional arguments of the
2039 # alias.
2025 # alias.
2040 alias_table[ff] = (0,ff)
2026 alias_table[ff] = (0,ff)
2041 else:
2027 else:
2042 for pdir in path:
2028 for pdir in path:
2043 os.chdir(pdir)
2029 os.chdir(pdir)
2044 for ff in os.listdir(pdir):
2030 for ff in os.listdir(pdir):
2045 if isexec(ff):
2031 if isexec(ff):
2046 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2032 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2047 # Make sure the alias table doesn't contain keywords or builtins
2033 # Make sure the alias table doesn't contain keywords or builtins
2048 self.shell.alias_table_validate()
2034 self.shell.alias_table_validate()
2049 # Call again init_auto_alias() so we get 'rm -i' and other
2035 # Call again init_auto_alias() so we get 'rm -i' and other
2050 # modified aliases since %rehashx will probably clobber them
2036 # modified aliases since %rehashx will probably clobber them
2051 self.shell.init_auto_alias()
2037 self.shell.init_auto_alias()
2052 finally:
2038 finally:
2053 os.chdir(savedir)
2039 os.chdir(savedir)
2054
2040
2055 def magic_pwd(self, parameter_s = ''):
2041 def magic_pwd(self, parameter_s = ''):
2056 """Return the current working directory path."""
2042 """Return the current working directory path."""
2057 return os.getcwd()
2043 return os.getcwd()
2058
2044
2059 def magic_cd(self, parameter_s=''):
2045 def magic_cd(self, parameter_s=''):
2060 """Change the current working directory.
2046 """Change the current working directory.
2061
2047
2062 This command automatically maintains an internal list of directories
2048 This command automatically maintains an internal list of directories
2063 you visit during your IPython session, in the variable _dh. The
2049 you visit during your IPython session, in the variable _dh. The
2064 command %dhist shows this history nicely formatted.
2050 command %dhist shows this history nicely formatted.
2065
2051
2066 Usage:
2052 Usage:
2067
2053
2068 cd 'dir': changes to directory 'dir'.
2054 cd 'dir': changes to directory 'dir'.
2069
2055
2070 cd -: changes to the last visited directory.
2056 cd -: changes to the last visited directory.
2071
2057
2072 cd -<n>: changes to the n-th directory in the directory history.
2058 cd -<n>: changes to the n-th directory in the directory history.
2073
2059
2074 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2060 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2075 (note: cd <bookmark_name> is enough if there is no
2061 (note: cd <bookmark_name> is enough if there is no
2076 directory <bookmark_name>, but a bookmark with the name exists.)
2062 directory <bookmark_name>, but a bookmark with the name exists.)
2077
2063
2078 Options:
2064 Options:
2079
2065
2080 -q: quiet. Do not print the working directory after the cd command is
2066 -q: quiet. Do not print the working directory after the cd command is
2081 executed. By default IPython's cd command does print this directory,
2067 executed. By default IPython's cd command does print this directory,
2082 since the default prompts do not display path information.
2068 since the default prompts do not display path information.
2083
2069
2084 Note that !cd doesn't work for this purpose because the shell where
2070 Note that !cd doesn't work for this purpose because the shell where
2085 !command runs is immediately discarded after executing 'command'."""
2071 !command runs is immediately discarded after executing 'command'."""
2086
2072
2087 parameter_s = parameter_s.strip()
2073 parameter_s = parameter_s.strip()
2088 bkms = self.shell.persist.get("bookmarks",{})
2074 bkms = self.shell.persist.get("bookmarks",{})
2089
2075
2090 numcd = re.match(r'(-)(\d+)$',parameter_s)
2076 numcd = re.match(r'(-)(\d+)$',parameter_s)
2091 # jump in directory history by number
2077 # jump in directory history by number
2092 if numcd:
2078 if numcd:
2093 nn = int(numcd.group(2))
2079 nn = int(numcd.group(2))
2094 try:
2080 try:
2095 ps = self.shell.user_ns['_dh'][nn]
2081 ps = self.shell.user_ns['_dh'][nn]
2096 except IndexError:
2082 except IndexError:
2097 print 'The requested directory does not exist in history.'
2083 print 'The requested directory does not exist in history.'
2098 return
2084 return
2099 else:
2085 else:
2100 opts = {}
2086 opts = {}
2101 else:
2087 else:
2102 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2088 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2103 # jump to previous
2089 # jump to previous
2104 if ps == '-':
2090 if ps == '-':
2105 try:
2091 try:
2106 ps = self.shell.user_ns['_dh'][-2]
2092 ps = self.shell.user_ns['_dh'][-2]
2107 except IndexError:
2093 except IndexError:
2108 print 'No previous directory to change to.'
2094 print 'No previous directory to change to.'
2109 return
2095 return
2110 # jump to bookmark
2096 # jump to bookmark
2111 elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)):
2097 elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)):
2112 if bkms.has_key(ps):
2098 if bkms.has_key(ps):
2113 target = bkms[ps]
2099 target = bkms[ps]
2114 print '(bookmark:%s) -> %s' % (ps,target)
2100 print '(bookmark:%s) -> %s' % (ps,target)
2115 ps = target
2101 ps = target
2116 else:
2102 else:
2117 if bkms:
2103 if bkms:
2118 error("Bookmark '%s' not found. "
2104 error("Bookmark '%s' not found. "
2119 "Use '%bookmark -l' to see your bookmarks." % ps)
2105 "Use '%bookmark -l' to see your bookmarks." % ps)
2120 else:
2106 else:
2121 print "Bookmarks not set - use %bookmark <bookmarkname>"
2107 print "Bookmarks not set - use %bookmark <bookmarkname>"
2122 return
2108 return
2123
2109
2124 # at this point ps should point to the target dir
2110 # at this point ps should point to the target dir
2125 if ps:
2111 if ps:
2126 try:
2112 try:
2127 os.chdir(os.path.expanduser(ps))
2113 os.chdir(os.path.expanduser(ps))
2128 except OSError:
2114 except OSError:
2129 print sys.exc_info()[1]
2115 print sys.exc_info()[1]
2130 else:
2116 else:
2131 self.shell.user_ns['_dh'].append(os.getcwd())
2117 self.shell.user_ns['_dh'].append(os.getcwd())
2132 else:
2118 else:
2133 os.chdir(self.home_dir)
2119 os.chdir(self.home_dir)
2134 self.shell.user_ns['_dh'].append(os.getcwd())
2120 self.shell.user_ns['_dh'].append(os.getcwd())
2135 if not 'q' in opts:
2121 if not 'q' in opts:
2136 print self.shell.user_ns['_dh'][-1]
2122 print self.shell.user_ns['_dh'][-1]
2137
2123
2138 def magic_dhist(self, parameter_s=''):
2124 def magic_dhist(self, parameter_s=''):
2139 """Print your history of visited directories.
2125 """Print your history of visited directories.
2140
2126
2141 %dhist -> print full history\\
2127 %dhist -> print full history\\
2142 %dhist n -> print last n entries only\\
2128 %dhist n -> print last n entries only\\
2143 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2129 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2144
2130
2145 This history is automatically maintained by the %cd command, and
2131 This history is automatically maintained by the %cd command, and
2146 always available as the global list variable _dh. You can use %cd -<n>
2132 always available as the global list variable _dh. You can use %cd -<n>
2147 to go to directory number <n>."""
2133 to go to directory number <n>."""
2148
2134
2149 dh = self.shell.user_ns['_dh']
2135 dh = self.shell.user_ns['_dh']
2150 if parameter_s:
2136 if parameter_s:
2151 try:
2137 try:
2152 args = map(int,parameter_s.split())
2138 args = map(int,parameter_s.split())
2153 except:
2139 except:
2154 self.arg_err(Magic.magic_dhist)
2140 self.arg_err(Magic.magic_dhist)
2155 return
2141 return
2156 if len(args) == 1:
2142 if len(args) == 1:
2157 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2143 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2158 elif len(args) == 2:
2144 elif len(args) == 2:
2159 ini,fin = args
2145 ini,fin = args
2160 else:
2146 else:
2161 self.arg_err(Magic.magic_dhist)
2147 self.arg_err(Magic.magic_dhist)
2162 return
2148 return
2163 else:
2149 else:
2164 ini,fin = 0,len(dh)
2150 ini,fin = 0,len(dh)
2165 nlprint(dh,
2151 nlprint(dh,
2166 header = 'Directory history (kept in _dh)',
2152 header = 'Directory history (kept in _dh)',
2167 start=ini,stop=fin)
2153 start=ini,stop=fin)
2168
2154
2169 def magic_env(self, parameter_s=''):
2155 def magic_env(self, parameter_s=''):
2170 """List environment variables."""
2156 """List environment variables."""
2171
2157
2172 # environ is an instance of UserDict
2158 # environ is an instance of UserDict
2173 return os.environ.data
2159 return os.environ.data
2174
2160
2175 def magic_pushd(self, parameter_s=''):
2161 def magic_pushd(self, parameter_s=''):
2176 """Place the current dir on stack and change directory.
2162 """Place the current dir on stack and change directory.
2177
2163
2178 Usage:\\
2164 Usage:\\
2179 %pushd ['dirname']
2165 %pushd ['dirname']
2180
2166
2181 %pushd with no arguments does a %pushd to your home directory.
2167 %pushd with no arguments does a %pushd to your home directory.
2182 """
2168 """
2183 if parameter_s == '': parameter_s = '~'
2169 if parameter_s == '': parameter_s = '~'
2184 if len(self.dir_stack)>0 and os.path.expanduser(parameter_s) != \
2170 if len(self.dir_stack)>0 and os.path.expanduser(parameter_s) != \
2185 os.path.expanduser(self.dir_stack[0]):
2171 os.path.expanduser(self.dir_stack[0]):
2186 try:
2172 try:
2187 self.magic_cd(parameter_s)
2173 self.magic_cd(parameter_s)
2188 self.dir_stack.insert(0,os.getcwd().replace(self.home_dir,'~'))
2174 self.dir_stack.insert(0,os.getcwd().replace(self.home_dir,'~'))
2189 self.magic_dirs()
2175 self.magic_dirs()
2190 except:
2176 except:
2191 print 'Invalid directory'
2177 print 'Invalid directory'
2192 else:
2178 else:
2193 print 'You are already there!'
2179 print 'You are already there!'
2194
2180
2195 def magic_popd(self, parameter_s=''):
2181 def magic_popd(self, parameter_s=''):
2196 """Change to directory popped off the top of the stack.
2182 """Change to directory popped off the top of the stack.
2197 """
2183 """
2198 if len (self.dir_stack) > 1:
2184 if len (self.dir_stack) > 1:
2199 self.dir_stack.pop(0)
2185 self.dir_stack.pop(0)
2200 self.magic_cd(self.dir_stack[0])
2186 self.magic_cd(self.dir_stack[0])
2201 print self.dir_stack[0]
2187 print self.dir_stack[0]
2202 else:
2188 else:
2203 print "You can't remove the starting directory from the stack:",\
2189 print "You can't remove the starting directory from the stack:",\
2204 self.dir_stack
2190 self.dir_stack
2205
2191
2206 def magic_dirs(self, parameter_s=''):
2192 def magic_dirs(self, parameter_s=''):
2207 """Return the current directory stack."""
2193 """Return the current directory stack."""
2208
2194
2209 return self.dir_stack[:]
2195 return self.dir_stack[:]
2210
2196
2211 def magic_sc(self, parameter_s=''):
2197 def magic_sc(self, parameter_s=''):
2212 """Shell capture - execute a shell command and capture its output.
2198 """Shell capture - execute a shell command and capture its output.
2213
2199
2214 %sc [options] varname=command
2200 %sc [options] varname=command
2215
2201
2216 IPython will run the given command using commands.getoutput(), and
2202 IPython will run the given command using commands.getoutput(), and
2217 will then update the user's interactive namespace with a variable
2203 will then update the user's interactive namespace with a variable
2218 called varname, containing the value of the call. Your command can
2204 called varname, containing the value of the call. Your command can
2219 contain shell wildcards, pipes, etc.
2205 contain shell wildcards, pipes, etc.
2220
2206
2221 The '=' sign in the syntax is mandatory, and the variable name you
2207 The '=' sign in the syntax is mandatory, and the variable name you
2222 supply must follow Python's standard conventions for valid names.
2208 supply must follow Python's standard conventions for valid names.
2223
2209
2224 Options:
2210 Options:
2225
2211
2226 -l: list output. Split the output on newlines into a list before
2212 -l: list output. Split the output on newlines into a list before
2227 assigning it to the given variable. By default the output is stored
2213 assigning it to the given variable. By default the output is stored
2228 as a single string.
2214 as a single string.
2229
2215
2230 -v: verbose. Print the contents of the variable.
2216 -v: verbose. Print the contents of the variable.
2231
2217
2232 In most cases you should not need to split as a list, because the
2218 In most cases you should not need to split as a list, because the
2233 returned value is a special type of string which can automatically
2219 returned value is a special type of string which can automatically
2234 provide its contents either as a list (split on newlines) or as a
2220 provide its contents either as a list (split on newlines) or as a
2235 space-separated string. These are convenient, respectively, either
2221 space-separated string. These are convenient, respectively, either
2236 for sequential processing or to be passed to a shell command.
2222 for sequential processing or to be passed to a shell command.
2237
2223
2238 For example:
2224 For example:
2239
2225
2240 # Capture into variable a
2226 # Capture into variable a
2241 In [9]: sc a=ls *py
2227 In [9]: sc a=ls *py
2242
2228
2243 # a is a string with embedded newlines
2229 # a is a string with embedded newlines
2244 In [10]: a
2230 In [10]: a
2245 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2231 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2246
2232
2247 # which can be seen as a list:
2233 # which can be seen as a list:
2248 In [11]: a.l
2234 In [11]: a.l
2249 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2235 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2250
2236
2251 # or as a whitespace-separated string:
2237 # or as a whitespace-separated string:
2252 In [12]: a.s
2238 In [12]: a.s
2253 Out[12]: 'setup.py win32_manual_post_install.py'
2239 Out[12]: 'setup.py win32_manual_post_install.py'
2254
2240
2255 # a.s is useful to pass as a single command line:
2241 # a.s is useful to pass as a single command line:
2256 In [13]: !wc -l $a.s
2242 In [13]: !wc -l $a.s
2257 146 setup.py
2243 146 setup.py
2258 130 win32_manual_post_install.py
2244 130 win32_manual_post_install.py
2259 276 total
2245 276 total
2260
2246
2261 # while the list form is useful to loop over:
2247 # while the list form is useful to loop over:
2262 In [14]: for f in a.l:
2248 In [14]: for f in a.l:
2263 ....: !wc -l $f
2249 ....: !wc -l $f
2264 ....:
2250 ....:
2265 146 setup.py
2251 146 setup.py
2266 130 win32_manual_post_install.py
2252 130 win32_manual_post_install.py
2267
2253
2268 Similiarly, the lists returned by the -l option are also special, in
2254 Similiarly, the lists returned by the -l option are also special, in
2269 the sense that you can equally invoke the .s attribute on them to
2255 the sense that you can equally invoke the .s attribute on them to
2270 automatically get a whitespace-separated string from their contents:
2256 automatically get a whitespace-separated string from their contents:
2271
2257
2272 In [1]: sc -l b=ls *py
2258 In [1]: sc -l b=ls *py
2273
2259
2274 In [2]: b
2260 In [2]: b
2275 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2261 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2276
2262
2277 In [3]: b.s
2263 In [3]: b.s
2278 Out[3]: 'setup.py win32_manual_post_install.py'
2264 Out[3]: 'setup.py win32_manual_post_install.py'
2279
2265
2280 In summary, both the lists and strings used for ouptut capture have
2266 In summary, both the lists and strings used for ouptut capture have
2281 the following special attributes:
2267 the following special attributes:
2282
2268
2283 .l (or .list) : value as list.
2269 .l (or .list) : value as list.
2284 .n (or .nlstr): value as newline-separated string.
2270 .n (or .nlstr): value as newline-separated string.
2285 .s (or .spstr): value as space-separated string.
2271 .s (or .spstr): value as space-separated string.
2286 """
2272 """
2287
2273
2288 opts,args = self.parse_options(parameter_s,'lv')
2274 opts,args = self.parse_options(parameter_s,'lv')
2289 # Try to get a variable name and command to run
2275 # Try to get a variable name and command to run
2290 try:
2276 try:
2291 # the variable name must be obtained from the parse_options
2277 # the variable name must be obtained from the parse_options
2292 # output, which uses shlex.split to strip options out.
2278 # output, which uses shlex.split to strip options out.
2293 var,_ = args.split('=',1)
2279 var,_ = args.split('=',1)
2294 var = var.strip()
2280 var = var.strip()
2295 # But the the command has to be extracted from the original input
2281 # But the the command has to be extracted from the original input
2296 # parameter_s, not on what parse_options returns, to avoid the
2282 # parameter_s, not on what parse_options returns, to avoid the
2297 # quote stripping which shlex.split performs on it.
2283 # quote stripping which shlex.split performs on it.
2298 _,cmd = parameter_s.split('=',1)
2284 _,cmd = parameter_s.split('=',1)
2299 except ValueError:
2285 except ValueError:
2300 var,cmd = '',''
2286 var,cmd = '',''
2301 if not var:
2287 if not var:
2302 error('you must specify a variable to assign the command to.')
2288 error('you must specify a variable to assign the command to.')
2303 return
2289 return
2304 # If all looks ok, proceed
2290 # If all looks ok, proceed
2305 out,err = self.shell.getoutputerror(cmd)
2291 out,err = self.shell.getoutputerror(cmd)
2306 if err:
2292 if err:
2307 print >> Term.cerr,err
2293 print >> Term.cerr,err
2308 if opts.has_key('l'):
2294 if opts.has_key('l'):
2309 out = SList(out.split('\n'))
2295 out = SList(out.split('\n'))
2310 else:
2296 else:
2311 out = LSString(out)
2297 out = LSString(out)
2312 if opts.has_key('v'):
2298 if opts.has_key('v'):
2313 print '%s ==\n%s' % (var,pformat(out))
2299 print '%s ==\n%s' % (var,pformat(out))
2314 self.shell.user_ns.update({var:out})
2300 self.shell.user_ns.update({var:out})
2315
2301
2316 def magic_sx(self, parameter_s=''):
2302 def magic_sx(self, parameter_s=''):
2317 """Shell execute - run a shell command and capture its output.
2303 """Shell execute - run a shell command and capture its output.
2318
2304
2319 %sx command
2305 %sx command
2320
2306
2321 IPython will run the given command using commands.getoutput(), and
2307 IPython will run the given command using commands.getoutput(), and
2322 return the result formatted as a list (split on '\\n'). Since the
2308 return the result formatted as a list (split on '\\n'). Since the
2323 output is _returned_, it will be stored in ipython's regular output
2309 output is _returned_, it will be stored in ipython's regular output
2324 cache Out[N] and in the '_N' automatic variables.
2310 cache Out[N] and in the '_N' automatic variables.
2325
2311
2326 Notes:
2312 Notes:
2327
2313
2328 1) If an input line begins with '!!', then %sx is automatically
2314 1) If an input line begins with '!!', then %sx is automatically
2329 invoked. That is, while:
2315 invoked. That is, while:
2330 !ls
2316 !ls
2331 causes ipython to simply issue system('ls'), typing
2317 causes ipython to simply issue system('ls'), typing
2332 !!ls
2318 !!ls
2333 is a shorthand equivalent to:
2319 is a shorthand equivalent to:
2334 %sx ls
2320 %sx ls
2335
2321
2336 2) %sx differs from %sc in that %sx automatically splits into a list,
2322 2) %sx differs from %sc in that %sx automatically splits into a list,
2337 like '%sc -l'. The reason for this is to make it as easy as possible
2323 like '%sc -l'. The reason for this is to make it as easy as possible
2338 to process line-oriented shell output via further python commands.
2324 to process line-oriented shell output via further python commands.
2339 %sc is meant to provide much finer control, but requires more
2325 %sc is meant to provide much finer control, but requires more
2340 typing.
2326 typing.
2341
2327
2342 3) Just like %sc -l, this is a list with special attributes:
2328 3) Just like %sc -l, this is a list with special attributes:
2343
2329
2344 .l (or .list) : value as list.
2330 .l (or .list) : value as list.
2345 .n (or .nlstr): value as newline-separated string.
2331 .n (or .nlstr): value as newline-separated string.
2346 .s (or .spstr): value as whitespace-separated string.
2332 .s (or .spstr): value as whitespace-separated string.
2347
2333
2348 This is very useful when trying to use such lists as arguments to
2334 This is very useful when trying to use such lists as arguments to
2349 system commands."""
2335 system commands."""
2350
2336
2351 if parameter_s:
2337 if parameter_s:
2352 out,err = self.shell.getoutputerror(parameter_s)
2338 out,err = self.shell.getoutputerror(parameter_s)
2353 if err:
2339 if err:
2354 print >> Term.cerr,err
2340 print >> Term.cerr,err
2355 return SList(out.split('\n'))
2341 return SList(out.split('\n'))
2356
2342
2357 def magic_bg(self, parameter_s=''):
2343 def magic_bg(self, parameter_s=''):
2358 """Run a job in the background, in a separate thread.
2344 """Run a job in the background, in a separate thread.
2359
2345
2360 For example,
2346 For example,
2361
2347
2362 %bg myfunc(x,y,z=1)
2348 %bg myfunc(x,y,z=1)
2363
2349
2364 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2350 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2365 execution starts, a message will be printed indicating the job
2351 execution starts, a message will be printed indicating the job
2366 number. If your job number is 5, you can use
2352 number. If your job number is 5, you can use
2367
2353
2368 myvar = jobs.result(5) or myvar = jobs[5].result
2354 myvar = jobs.result(5) or myvar = jobs[5].result
2369
2355
2370 to assign this result to variable 'myvar'.
2356 to assign this result to variable 'myvar'.
2371
2357
2372 IPython has a job manager, accessible via the 'jobs' object. You can
2358 IPython has a job manager, accessible via the 'jobs' object. You can
2373 type jobs? to get more information about it, and use jobs.<TAB> to see
2359 type jobs? to get more information about it, and use jobs.<TAB> to see
2374 its attributes. All attributes not starting with an underscore are
2360 its attributes. All attributes not starting with an underscore are
2375 meant for public use.
2361 meant for public use.
2376
2362
2377 In particular, look at the jobs.new() method, which is used to create
2363 In particular, look at the jobs.new() method, which is used to create
2378 new jobs. This magic %bg function is just a convenience wrapper
2364 new jobs. This magic %bg function is just a convenience wrapper
2379 around jobs.new(), for expression-based jobs. If you want to create a
2365 around jobs.new(), for expression-based jobs. If you want to create a
2380 new job with an explicit function object and arguments, you must call
2366 new job with an explicit function object and arguments, you must call
2381 jobs.new() directly.
2367 jobs.new() directly.
2382
2368
2383 The jobs.new docstring also describes in detail several important
2369 The jobs.new docstring also describes in detail several important
2384 caveats associated with a thread-based model for background job
2370 caveats associated with a thread-based model for background job
2385 execution. Type jobs.new? for details.
2371 execution. Type jobs.new? for details.
2386
2372
2387 You can check the status of all jobs with jobs.status().
2373 You can check the status of all jobs with jobs.status().
2388
2374
2389 The jobs variable is set by IPython into the Python builtin namespace.
2375 The jobs variable is set by IPython into the Python builtin namespace.
2390 If you ever declare a variable named 'jobs', you will shadow this
2376 If you ever declare a variable named 'jobs', you will shadow this
2391 name. You can either delete your global jobs variable to regain
2377 name. You can either delete your global jobs variable to regain
2392 access to the job manager, or make a new name and assign it manually
2378 access to the job manager, or make a new name and assign it manually
2393 to the manager (stored in IPython's namespace). For example, to
2379 to the manager (stored in IPython's namespace). For example, to
2394 assign the job manager to the Jobs name, use:
2380 assign the job manager to the Jobs name, use:
2395
2381
2396 Jobs = __builtins__.jobs"""
2382 Jobs = __builtins__.jobs"""
2397
2383
2398 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2384 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2399
2385
2400 def magic_bookmark(self, parameter_s=''):
2386 def magic_bookmark(self, parameter_s=''):
2401 """Manage IPython's bookmark system.
2387 """Manage IPython's bookmark system.
2402
2388
2403 %bookmark <name> - set bookmark to current dir
2389 %bookmark <name> - set bookmark to current dir
2404 %bookmark <name> <dir> - set bookmark to <dir>
2390 %bookmark <name> <dir> - set bookmark to <dir>
2405 %bookmark -l - list all bookmarks
2391 %bookmark -l - list all bookmarks
2406 %bookmark -d <name> - remove bookmark
2392 %bookmark -d <name> - remove bookmark
2407 %bookmark -r - remove all bookmarks
2393 %bookmark -r - remove all bookmarks
2408
2394
2409 You can later on access a bookmarked folder with:
2395 You can later on access a bookmarked folder with:
2410 %cd -b <name>
2396 %cd -b <name>
2411 or simply '%cd <name>' if there is no directory called <name> AND
2397 or simply '%cd <name>' if there is no directory called <name> AND
2412 there is such a bookmark defined.
2398 there is such a bookmark defined.
2413
2399
2414 Your bookmarks persist through IPython sessions, but they are
2400 Your bookmarks persist through IPython sessions, but they are
2415 associated with each profile."""
2401 associated with each profile."""
2416
2402
2417 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2403 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2418 if len(args) > 2:
2404 if len(args) > 2:
2419 error('You can only give at most two arguments')
2405 error('You can only give at most two arguments')
2420 return
2406 return
2421
2407
2422 bkms = self.shell.persist.get('bookmarks',{})
2408 bkms = self.shell.persist.get('bookmarks',{})
2423
2409
2424 if opts.has_key('d'):
2410 if opts.has_key('d'):
2425 try:
2411 try:
2426 todel = args[0]
2412 todel = args[0]
2427 except IndexError:
2413 except IndexError:
2428 error('You must provide a bookmark to delete')
2414 error('You must provide a bookmark to delete')
2429 else:
2415 else:
2430 try:
2416 try:
2431 del bkms[todel]
2417 del bkms[todel]
2432 except:
2418 except:
2433 error("Can't delete bookmark '%s'" % todel)
2419 error("Can't delete bookmark '%s'" % todel)
2434 elif opts.has_key('r'):
2420 elif opts.has_key('r'):
2435 bkms = {}
2421 bkms = {}
2436 elif opts.has_key('l'):
2422 elif opts.has_key('l'):
2437 bks = bkms.keys()
2423 bks = bkms.keys()
2438 bks.sort()
2424 bks.sort()
2439 if bks:
2425 if bks:
2440 size = max(map(len,bks))
2426 size = max(map(len,bks))
2441 else:
2427 else:
2442 size = 0
2428 size = 0
2443 fmt = '%-'+str(size)+'s -> %s'
2429 fmt = '%-'+str(size)+'s -> %s'
2444 print 'Current bookmarks:'
2430 print 'Current bookmarks:'
2445 for bk in bks:
2431 for bk in bks:
2446 print fmt % (bk,bkms[bk])
2432 print fmt % (bk,bkms[bk])
2447 else:
2433 else:
2448 if not args:
2434 if not args:
2449 error("You must specify the bookmark name")
2435 error("You must specify the bookmark name")
2450 elif len(args)==1:
2436 elif len(args)==1:
2451 bkms[args[0]] = os.getcwd()
2437 bkms[args[0]] = os.getcwd()
2452 elif len(args)==2:
2438 elif len(args)==2:
2453 bkms[args[0]] = args[1]
2439 bkms[args[0]] = args[1]
2454 self.persist['bookmarks'] = bkms
2440 self.persist['bookmarks'] = bkms
2455
2441
2456 def magic_pycat(self, parameter_s=''):
2442 def magic_pycat(self, parameter_s=''):
2457 """Show a syntax-highlighted file through a pager.
2443 """Show a syntax-highlighted file through a pager.
2458
2444
2459 This magic is similar to the cat utility, but it will assume the file
2445 This magic is similar to the cat utility, but it will assume the file
2460 to be Python source and will show it with syntax highlighting. """
2446 to be Python source and will show it with syntax highlighting. """
2461
2447
2462 try:
2448 filename = get_py_filename(parameter_s)
2463 filename = get_py_filename(parameter_s)
2449 page(self.shell.colorize(file_read(filename)),
2464 except IndexError:
2450 screen_lines=self.shell.rc.screen_length)
2465 warn('you must provide at least a filename.')
2466 return
2467 fobj=open(filename,'r')
2468 source = fobj.read()
2469 fobj.close()
2470 colorize = Parser().format
2471 colorized_src = colorize(source,'str',self.shell.rc['colors'])
2472 page(colorized_src,screen_lines=self.shell.rc.screen_length)
2473
2451
2474 # end Magic
2452 # end Magic
@@ -1,201 +1,309 b''
1 """Module for interactive demos using IPython.
1 """Module for interactive demos using IPython.
2
2
3 Sorry, but this uses Python 2.3 features, so it won't work in 2.2 environments.
3 This module implements a single class, Demo, for running Python scripts
4 interactively in IPython for demonstrations. With very simple markup (a few
5 tags in comments), you can control points where the script stops executing and
6 returns control to IPython.
7
8 The file is run in its own empty namespace (though you can pass it a string of
9 arguments as if in a command line environment, and it will see those as
10 sys.argv). But at each stop, the global IPython namespace is updated with the
11 current internal demo namespace, so you can work interactively with the data
12 accumulated so far.
13
14 By default, each block of code is printed (with syntax highlighting) before
15 executing it and you have to confirm execution. This is intended to show the
16 code to an audience first so you can discuss it, and only proceed with
17 execution once you agree. There are a few tags which allow you to modify this
18 behavior.
19
20 The supported tags are:
21
22 # <demo> --- stop ---
23
24 Defines block boundaries, the points where IPython stops execution of the
25 file and returns to the interactive prompt.
26
27 # <demo> silent
28
29 Make a block execute silently (and hence automatically). Typically used in
30 cases where you have some boilerplate or initialization code which you need
31 executed but do not want to be seen in the demo.
32
33 # <demo> auto
34
35 Make a block execute automatically, but still being printed. Useful for
36 simple code which does not warrant discussion, since it avoids the extra
37 manual confirmation.
38
39 # <demo> auto_all
40
41 This tag can _only_ be in the first block, and if given it overrides the
42 individual auto tags to make the whole demo fully automatic (no block asks
43 for confirmation). It can also be given at creation time (or the attribute
44 set later) to override what's in the file.
45
46 While _any_ python file can be run as a Demo instance, if there are no stop
47 tags the whole file will run in a single block (no different that calling
48 first %pycat and then %run). The minimal markup to make this useful is to
49 place a set of stop tags; the other tags are only there to let you fine-tune
50 the execution.
51
52 This is probably best explained with the simple example file below. You can
53 copy this into a file named ex_demo.py, and try running it via:
54
55 from IPython.demo import Demo
56 d = Demo('ex_demo.py')
57 d() <--- Call the d object (omit the parens if you have autocall on).
58
59 Each time you call the demo object, it runs the next block. The demo object
60 has a few useful methods for navigation, like again(), jump(), seek() and
61 back(). It can be reset for a new run via reset() or reloaded from disk (in
62 case you've edited the source) via reload(). See their docstrings below.
63
64 #################### EXAMPLE DEMO <ex_demo.py> ###############################
65 '''A simple interactive demo to illustrate the use of IPython's Demo class.'''
66
67 print 'Hello, welcome to an interactive IPython demo.'
68
69 # The mark below defines a block boundary, which is a point where IPython will
70 # stop execution and return to the interactive prompt.
71 # Note that in actual interactive execution,
72 # <demo> --- stop ---
73
74 x = 1
75 y = 2
76
77 # <demo> --- stop ---
78
79 # the mark below makes this block as silent
80 # <demo> silent
81
82 print 'This is a silent block, which gets executed but not printed.'
83
84 # <demo> --- stop ---
85 # <demo> auto
86 print 'This is an automatic block.'
87 print 'It is executed without asking for confirmation, but printed.'
88 z = x+y
89
90 print 'z=',x
91
92 # <demo> --- stop ---
93 # This is just another normal block.
94 print 'z is now:', z
95
96 print 'bye!'
97 ################### END EXAMPLE DEMO <ex_demo.py> ############################
98
99 WARNING: this module uses Python 2.3 features, so it won't work in 2.2
100 environments.
4 """
101 """
5 #*****************************************************************************
102 #*****************************************************************************
6 # Copyright (C) 2005 Fernando Perez. <Fernando.Perez@colorado.edu>
103 # Copyright (C) 2005 Fernando Perez. <Fernando.Perez@colorado.edu>
7 #
104 #
8 # Distributed under the terms of the BSD License. The full license is in
105 # Distributed under the terms of the BSD License. The full license is in
9 # the file COPYING, distributed as part of this software.
106 # the file COPYING, distributed as part of this software.
10 #
107 #
11 #*****************************************************************************
108 #*****************************************************************************
12
109
13 import sys
110 import sys
14 import exceptions
111 import exceptions
15 import re
112 import re
16
113
17 from IPython.PyColorize import Parser
114 from IPython.PyColorize import Parser
18 from IPython.genutils import marquee, shlex_split
115 from IPython.genutils import marquee, shlex_split, file_read
116
117 __all__ = ['Demo','DemoError']
19
118
20 class DemoError(exceptions.Exception): pass
119 class DemoError(exceptions.Exception): pass
21
120
121 def re_mark(mark):
122 return re.compile(r'^\s*#\s+<demo>\s+%s\s*$' % mark,re.MULTILINE)
123
22 class Demo:
124 class Demo:
23 def __init__(self,fname,arg_str='',mark_pause='# pause',
125
24 mark_silent='# silent',mark_auto='# auto',auto=False):
126 re_stop = re_mark('---\s?stop\s?---')
127 re_silent = re_mark('silent')
128 re_auto = re_mark('auto')
129 re_auto_all = re_mark('auto_all')
130
131 def __init__(self,fname,arg_str='',auto_all=None):
25 """Make a new demo object. To run the demo, simply call the object.
132 """Make a new demo object. To run the demo, simply call the object.
26
133
134 See the module docstring for full details and an example (you can use
135 IPython.Demo? in IPython to see it).
136
27 Inputs:
137 Inputs:
28
138
29 - fname = filename.
139 - fname = filename.
30
140
31 Optional inputs:
141 Optional inputs:
32
142
33 - arg_str(''): a string of arguments, internally converted to a list
143 - arg_str(''): a string of arguments, internally converted to a list
34 just like sys.argv, so the demo script can see a similar
144 just like sys.argv, so the demo script can see a similar
35 environment.
145 environment.
36
146
37 - mark_pause ('# pause'): marks for pausing (block boundaries). The
147 - auto_all(None): global flag to run all blocks automatically without
38 marks are turned into regexps which match them as standalone in a
39 line, with all leading/trailing whitespace ignored.
40
41 - mark_silent('# silent'): mark blocks as silent, which means that
42 they are executed without printing their content to screen. Silent
43 blocks are always automatically executed.
44
45 - mark_auto ('# auto'): mark individual blocks as automatically
46 executed (without asking for confirmation).
47
48 - auto(False): global flag to run all blocks automatically without
49 confirmation. This attribute overrides the block-level tags and
148 confirmation. This attribute overrides the block-level tags and
50 applies to the whole demo. It is an attribute of the object, and
149 applies to the whole demo. It is an attribute of the object, and
51 can be changed at runtime simply by reassigning it to a boolean
150 can be changed at runtime simply by reassigning it to a boolean
52 value.
151 value.
53 """
152 """
54
153
55 self.fname = fname
154 self.fname = fname
56 self.sys_argv = [fname] + shlex_split(arg_str)
155 self.sys_argv = [fname] + shlex_split(arg_str)
57 self.mark_pause = mark_pause
156 self.auto_all = auto_all
58 self.mark_silent = mark_silent
157
59 self.re_pause = re.compile(r'^\s*%s\s*$' % mark_pause,re.MULTILINE)
60 self.re_silent = re.compile(r'^\s*%s\s*$' % mark_silent,re.MULTILINE)
61 self.re_auto = re.compile(r'^\s*%s\s*$' % mark_auto,re.MULTILINE)
62 self.auto = auto
63
64 # get a few things from ipython. While it's a bit ugly design-wise,
158 # get a few things from ipython. While it's a bit ugly design-wise,
65 # it ensures that things like color scheme and the like are always in
159 # it ensures that things like color scheme and the like are always in
66 # sync with the ipython mode being used. This class is only meant to
160 # sync with the ipython mode being used. This class is only meant to
67 # be used inside ipython anyways, so it's OK.
161 # be used inside ipython anyways, so it's OK.
68 self.ip_showtb = __IPYTHON__.showtraceback
162 self.ip_showtb = __IPYTHON__.showtraceback
69 self.ip_ns = __IPYTHON__.user_ns
163 self.ip_ns = __IPYTHON__.user_ns
70 self.ip_colors = __IPYTHON__.rc['colors']
164 self.ip_colorize = __IPYTHON__.pycolorize
71 self.colorize = Parser().format
72
165
73 # load user data and initialize data structures
166 # load user data and initialize data structures
74 self.reload()
167 self.reload()
75
168
76 def reload(self):
169 def reload(self):
77 """Reload source from disk and initialize state."""
170 """Reload source from disk and initialize state."""
78 # read data and parse into blocks
171 # read data and parse into blocks
79 fobj = file(self.fname,'r')
172 self.src = file_read(self.fname)
80 self.src = fobj.read()
173 src_b = [b.strip() for b in self.re_stop.split(self.src) if b]
81 fobj.close()
174 self._silent = [bool(self.re_silent.findall(b)) for b in src_b]
82 src_blocks = [b.strip() for b in self.re_pause.split(self.src) if b]
175 self._auto = [bool(self.re_auto.findall(b)) for b in src_b]
83 self._silent = [bool(self.re_silent.findall(b)) for b in src_blocks]
176
84 self._auto = [bool(self.re_auto.findall(b)) for b in src_blocks]
177 # if auto_all is not given (def. None), we read it from the file
85 # strip out the 'auto' markers
178 if self.auto_all is None:
86 src_b = []
179 self.auto_all = bool(self.re_auto_all.findall(src_b[0]))
180 else:
181 self.auto_all = bool(self.auto_all)
182
183 # Clean the sources from all markup so it doesn't get displayed when
184 # running the demo
185 src_blocks = []
87 auto_strip = lambda s: self.re_auto.sub('',s)
186 auto_strip = lambda s: self.re_auto.sub('',s)
88 for i,b in enumerate(src_blocks):
187 for i,b in enumerate(src_b):
89 if self._auto[i]:
188 if self._auto[i]:
90 src_b.append(auto_strip(b))
189 src_blocks.append(auto_strip(b))
91 else:
190 else:
92 src_b.append(b)
191 src_blocks.append(b)
93 self.nblocks = len(src_b)
192 # remove the auto_all marker
94 self.src_blocks = src_b
193 src_blocks[0] = self.re_auto_all.sub('',src_blocks[0])
95
194
96 # try to colorize blocks
195 self.nblocks = len(src_blocks)
97 col_scheme = self.ip_colors
196 self.src_blocks = src_blocks
98 self.src_blocks_colored = [self.colorize(s_blk,'str',col_scheme)
197
99 for s_blk in self.src_blocks]
198 # also build syntax-highlighted source
199 self.src_blocks_colored = map(self.ip_colorize,self.src_blocks)
200
100 # ensure clean namespace and seek offset
201 # ensure clean namespace and seek offset
101 self.reset()
202 self.reset()
102
203
103 def reset(self):
204 def reset(self):
104 """Reset the namespace and seek pointer to restart the demo"""
205 """Reset the namespace and seek pointer to restart the demo"""
105 self.user_ns = {}
206 self.user_ns = {}
106 self.finished = False
207 self.finished = False
107 self.block_index = 0
208 self.block_index = 0
108
209
109 def again(self):
110 """Repeat the last block"""
111 self.block_index -= 1
112 self.finished = False
113 self()
114
115 def _validate_index(self,index):
210 def _validate_index(self,index):
116 if index<0 or index>=self.nblocks:
211 if index<0 or index>=self.nblocks:
117 raise ValueError('invalid block index %s' % index)
212 raise ValueError('invalid block index %s' % index)
118
213
119 def seek(self,index):
214 def seek(self,index):
120 """Move the current seek pointer to the given block"""
215 """Move the current seek pointer to the given block"""
121 self._validate_index(index)
216 self._validate_index(index)
122 self.block_index = index
217 self.block_index = index
123 self.finished = False
218 self.finished = False
124
219
220 def back(self,num=1):
221 """Move the seek pointer back num blocks (default is 1)."""
222 self.seek(self.block_index-num)
223
224 def jump(self,num):
225 """Jump a given number of blocks relative to the current one."""
226 self.seek(self.block_index+num)
227
228 def again(self):
229 """Move the seek pointer back one block and re-execute."""
230 self.back(1)
231 self()
232
125 def show(self,index=None):
233 def show(self,index=None):
126 """Show a single block on screen"""
234 """Show a single block on screen"""
127 if index is None:
235 if index is None:
128 if self.finished:
236 if self.finished:
129 print 'Demo finished. Use reset() if you want to rerun it.'
237 print 'Demo finished. Use reset() if you want to rerun it.'
130 return
238 return
131 index = self.block_index
239 index = self.block_index
132 else:
240 else:
133 self._validate_index(index)
241 self._validate_index(index)
134 print marquee('<%s> block # %s (%s remaining)' %
242 print marquee('<%s> block # %s (%s remaining)' %
135 (self.fname,index,self.nblocks-index-1))
243 (self.fname,index,self.nblocks-index-1))
136 print self.src_blocks_colored[index],
244 print self.src_blocks_colored[index],
137
245
138 def show_all(self):
246 def show_all(self):
139 """Show entire demo on screen, block by block"""
247 """Show entire demo on screen, block by block"""
140
248
141 fname = self.fname
249 fname = self.fname
142 nblocks = self.nblocks
250 nblocks = self.nblocks
143 silent = self._silent
251 silent = self._silent
144 for index,block in enumerate(self.src_blocks_colored):
252 for index,block in enumerate(self.src_blocks_colored):
145 if silent[index]:
253 if silent[index]:
146 print marquee('<%s> SILENT block # %s (%s remaining)' %
254 print marquee('<%s> SILENT block # %s (%s remaining)' %
147 (fname,index,nblocks-index-1))
255 (fname,index,nblocks-index-1))
148 else:
256 else:
149 print marquee('<%s> block # %s (%s remaining)' %
257 print marquee('<%s> block # %s (%s remaining)' %
150 (fname,index,nblocks-index-1))
258 (fname,index,nblocks-index-1))
151 print block,
259 print block,
152
260
153 def __call__(self,index=None):
261 def __call__(self,index=None):
154 """run a block of the demo.
262 """run a block of the demo.
155
263
156 If index is given, it should be an integer >=1 and <= nblocks. This
264 If index is given, it should be an integer >=1 and <= nblocks. This
157 means that the calling convention is one off from typical Python
265 means that the calling convention is one off from typical Python
158 lists. The reason for the inconsistency is that the demo always
266 lists. The reason for the inconsistency is that the demo always
159 prints 'Block n/N, and N is the total, so it would be very odd to use
267 prints 'Block n/N, and N is the total, so it would be very odd to use
160 zero-indexing here."""
268 zero-indexing here."""
161
269
162 if index is None and self.finished:
270 if index is None and self.finished:
163 print 'Demo finished. Use reset() if you want to rerun it.'
271 print 'Demo finished. Use reset() if you want to rerun it.'
164 return
272 return
165 if index is None:
273 if index is None:
166 index = self.block_index
274 index = self.block_index
167 self._validate_index(index)
275 self._validate_index(index)
168 try:
276 try:
169 next_block = self.src_blocks[index]
277 next_block = self.src_blocks[index]
170 self.block_index += 1
278 self.block_index += 1
171 if self._silent[index]:
279 if self._silent[index]:
172 print marquee('Executing silent block # %s (%s remaining)' %
280 print marquee('Executing silent block # %s (%s remaining)' %
173 (index,self.nblocks-index-1))
281 (index,self.nblocks-index-1))
174 else:
282 else:
175 self.show(index)
283 self.show(index)
176 if self.auto or self._auto[index]:
284 if self.auto_all or self._auto[index]:
177 print marquee('output')
285 print marquee('output')
178 else:
286 else:
179 print marquee('Press <q> to quit, <Enter> to execute...'),
287 print marquee('Press <q> to quit, <Enter> to execute...'),
180 ans = raw_input().strip()
288 ans = raw_input().strip()
181 if ans:
289 if ans:
182 print marquee('Block NOT executed')
290 print marquee('Block NOT executed')
183 return
291 return
184 try:
292 try:
185 save_argv = sys.argv
293 save_argv = sys.argv
186 sys.argv = self.sys_argv
294 sys.argv = self.sys_argv
187 exec next_block in self.user_ns
295 exec next_block in self.user_ns
188 finally:
296 finally:
189 sys.argv = save_argv
297 sys.argv = save_argv
190
298
191 except:
299 except:
192 self.ip_showtb(filename=self.fname)
300 self.ip_showtb(filename=self.fname)
193 else:
301 else:
194 self.ip_ns.update(self.user_ns)
302 self.ip_ns.update(self.user_ns)
195
303
196 if self.block_index == self.nblocks:
304 if self.block_index == self.nblocks:
197 print
305 print
198 print marquee(' END OF DEMO ')
306 print marquee(' END OF DEMO ')
199 print marquee('Use reset() if you want to rerun it.')
307 print marquee('Use reset() if you want to rerun it.')
200 self.finished = True
308 self.finished = True
201
309
@@ -1,1578 +1,1601 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 General purpose utilities.
3 General purpose utilities.
4
4
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 these things are also convenient when working at the command line.
6 these things are also convenient when working at the command line.
7
7
8 $Id: genutils.py 897 2005-09-22 09:32:46Z fperez $"""
8 $Id: genutils.py 908 2005-09-26 16:05:48Z fperez $"""
9
9
10 #*****************************************************************************
10 #*****************************************************************************
11 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
11 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
12 #
12 #
13 # Distributed under the terms of the BSD License. The full license is in
13 # Distributed under the terms of the BSD License. The full license is in
14 # the file COPYING, distributed as part of this software.
14 # the file COPYING, distributed as part of this software.
15 #*****************************************************************************
15 #*****************************************************************************
16
16
17 from __future__ import generators # 2.2 compatibility
17 from __future__ import generators # 2.2 compatibility
18
18
19 from IPython import Release
19 from IPython import Release
20 __author__ = '%s <%s>' % Release.authors['Fernando']
20 __author__ = '%s <%s>' % Release.authors['Fernando']
21 __license__ = Release.license
21 __license__ = Release.license
22
22
23 #****************************************************************************
23 #****************************************************************************
24 # required modules
24 # required modules
25 import __main__
25 import __main__
26 import types,commands,time,sys,os,re,shutil
26 import types,commands,time,sys,os,re,shutil
27 import shlex
27 import shlex
28 import tempfile
28 import tempfile
29 from IPython.Itpl import Itpl,itpl,printpl
29 from IPython.Itpl import Itpl,itpl,printpl
30 from IPython import DPyGetOpt
30 from IPython import DPyGetOpt
31
31
32 # Build objects which appeared in Python 2.3 for 2.2, to make ipython
32 # Build objects which appeared in Python 2.3 for 2.2, to make ipython
33 # 2.2-friendly
33 # 2.2-friendly
34 try:
34 try:
35 basestring
35 basestring
36 except NameError:
36 except NameError:
37 import types
37 import types
38 basestring = (types.StringType, types.UnicodeType)
38 basestring = (types.StringType, types.UnicodeType)
39 True = 1==1
39 True = 1==1
40 False = 1==0
40 False = 1==0
41
41
42 def enumerate(obj):
42 def enumerate(obj):
43 i = -1
43 i = -1
44 for item in obj:
44 for item in obj:
45 i += 1
45 i += 1
46 yield i, item
46 yield i, item
47
47
48 # add these to the builtin namespace, so that all modules find them
48 # add these to the builtin namespace, so that all modules find them
49 import __builtin__
49 import __builtin__
50 __builtin__.basestring = basestring
50 __builtin__.basestring = basestring
51 __builtin__.True = True
51 __builtin__.True = True
52 __builtin__.False = False
52 __builtin__.False = False
53 __builtin__.enumerate = enumerate
53 __builtin__.enumerate = enumerate
54
54
55 # Try to use shlex.split for converting an input string into a sys.argv-type
55 # Try to use shlex.split for converting an input string into a sys.argv-type
56 # list. This appeared in Python 2.3, so here's a quick backport for 2.2.
56 # list. This appeared in Python 2.3, so here's a quick backport for 2.2.
57 try:
57 try:
58 shlex_split = shlex.split
58 shlex_split = shlex.split
59 except AttributeError:
59 except AttributeError:
60 _quotesre = re.compile(r'[\'"](.*)[\'"]')
60 _quotesre = re.compile(r'[\'"](.*)[\'"]')
61 _wordchars = ('abcdfeghijklmnopqrstuvwxyz'
61 _wordchars = ('abcdfeghijklmnopqrstuvwxyz'
62 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.~*?'
62 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.~*?'
63 'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'
63 'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'
64 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ%s'
64 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ%s'
65 % os.sep)
65 % os.sep)
66
66
67 def shlex_split(s):
67 def shlex_split(s):
68 """Simplified backport to Python 2.2 of shlex.split().
68 """Simplified backport to Python 2.2 of shlex.split().
69
69
70 This is a quick and dirty hack, since the shlex module under 2.2 lacks
70 This is a quick and dirty hack, since the shlex module under 2.2 lacks
71 several of the features needed to really match the functionality of
71 several of the features needed to really match the functionality of
72 shlex.split() in 2.3."""
72 shlex.split() in 2.3."""
73
73
74 lex = shlex.shlex(StringIO(s))
74 lex = shlex.shlex(StringIO(s))
75 # Try to get options, extensions and path separators as characters
75 # Try to get options, extensions and path separators as characters
76 lex.wordchars = _wordchars
76 lex.wordchars = _wordchars
77 lex.commenters = ''
77 lex.commenters = ''
78 # Make a list out of the lexer by hand, since in 2.2 it's not an
78 # Make a list out of the lexer by hand, since in 2.2 it's not an
79 # iterator.
79 # iterator.
80 lout = []
80 lout = []
81 while 1:
81 while 1:
82 token = lex.get_token()
82 token = lex.get_token()
83 if token == '':
83 if token == '':
84 break
84 break
85 # Try to handle quoted tokens correctly
85 # Try to handle quoted tokens correctly
86 quotes = _quotesre.match(token)
86 quotes = _quotesre.match(token)
87 if quotes:
87 if quotes:
88 token = quotes.group(1)
88 token = quotes.group(1)
89 lout.append(token)
89 lout.append(token)
90 return lout
90 return lout
91
91
92 #****************************************************************************
92 #****************************************************************************
93 # Exceptions
93 # Exceptions
94 class Error(Exception):
94 class Error(Exception):
95 """Base class for exceptions in this module."""
95 """Base class for exceptions in this module."""
96 pass
96 pass
97
97
98 #----------------------------------------------------------------------------
98 #----------------------------------------------------------------------------
99 class IOStream:
99 class IOStream:
100 def __init__(self,stream,fallback):
100 def __init__(self,stream,fallback):
101 if not hasattr(stream,'write') or not hasattr(stream,'flush'):
101 if not hasattr(stream,'write') or not hasattr(stream,'flush'):
102 stream = fallback
102 stream = fallback
103 self.stream = stream
103 self.stream = stream
104 self._swrite = stream.write
104 self._swrite = stream.write
105 self.flush = stream.flush
105 self.flush = stream.flush
106
106
107 def write(self,data):
107 def write(self,data):
108 try:
108 try:
109 self._swrite(data)
109 self._swrite(data)
110 except:
110 except:
111 try:
111 try:
112 # print handles some unicode issues which may trip a plain
112 # print handles some unicode issues which may trip a plain
113 # write() call. Attempt to emulate write() by using a
113 # write() call. Attempt to emulate write() by using a
114 # trailing comma
114 # trailing comma
115 print >> self.stream, data,
115 print >> self.stream, data,
116 except:
116 except:
117 # if we get here, something is seriously broken.
117 # if we get here, something is seriously broken.
118 print >> sys.stderr, \
118 print >> sys.stderr, \
119 'ERROR - failed to write data to stream:', stream
119 'ERROR - failed to write data to stream:', stream
120
120
121 class IOTerm:
121 class IOTerm:
122 """ Term holds the file or file-like objects for handling I/O operations.
122 """ Term holds the file or file-like objects for handling I/O operations.
123
123
124 These are normally just sys.stdin, sys.stdout and sys.stderr but for
124 These are normally just sys.stdin, sys.stdout and sys.stderr but for
125 Windows they can can replaced to allow editing the strings before they are
125 Windows they can can replaced to allow editing the strings before they are
126 displayed."""
126 displayed."""
127
127
128 # In the future, having IPython channel all its I/O operations through
128 # In the future, having IPython channel all its I/O operations through
129 # this class will make it easier to embed it into other environments which
129 # this class will make it easier to embed it into other environments which
130 # are not a normal terminal (such as a GUI-based shell)
130 # are not a normal terminal (such as a GUI-based shell)
131 def __init__(self,cin=None,cout=None,cerr=None):
131 def __init__(self,cin=None,cout=None,cerr=None):
132 self.cin = IOStream(cin,sys.stdin)
132 self.cin = IOStream(cin,sys.stdin)
133 self.cout = IOStream(cout,sys.stdout)
133 self.cout = IOStream(cout,sys.stdout)
134 self.cerr = IOStream(cerr,sys.stderr)
134 self.cerr = IOStream(cerr,sys.stderr)
135
135
136 # Global variable to be used for all I/O
136 # Global variable to be used for all I/O
137 Term = IOTerm()
137 Term = IOTerm()
138
138
139 # Windows-specific code to load Gary Bishop's readline and configure it
139 # Windows-specific code to load Gary Bishop's readline and configure it
140 # automatically for the users
140 # automatically for the users
141 # Note: os.name on cygwin returns posix, so this should only pick up 'native'
141 # Note: os.name on cygwin returns posix, so this should only pick up 'native'
142 # windows. Cygwin returns 'cygwin' for sys.platform.
142 # windows. Cygwin returns 'cygwin' for sys.platform.
143 if os.name == 'nt':
143 if os.name == 'nt':
144 try:
144 try:
145 import readline
145 import readline
146 except ImportError:
146 except ImportError:
147 pass
147 pass
148 else:
148 else:
149 try:
149 try:
150 _out = readline.GetOutputFile()
150 _out = readline.GetOutputFile()
151 except AttributeError:
151 except AttributeError:
152 pass
152 pass
153 else:
153 else:
154 # Remake Term to use the readline i/o facilities
154 # Remake Term to use the readline i/o facilities
155 Term = IOTerm(cout=_out,cerr=_out)
155 Term = IOTerm(cout=_out,cerr=_out)
156 del _out
156 del _out
157
157
158 #****************************************************************************
158 #****************************************************************************
159 # Generic warning/error printer, used by everything else
159 # Generic warning/error printer, used by everything else
160 def warn(msg,level=2,exit_val=1):
160 def warn(msg,level=2,exit_val=1):
161 """Standard warning printer. Gives formatting consistency.
161 """Standard warning printer. Gives formatting consistency.
162
162
163 Output is sent to Term.cerr (sys.stderr by default).
163 Output is sent to Term.cerr (sys.stderr by default).
164
164
165 Options:
165 Options:
166
166
167 -level(2): allows finer control:
167 -level(2): allows finer control:
168 0 -> Do nothing, dummy function.
168 0 -> Do nothing, dummy function.
169 1 -> Print message.
169 1 -> Print message.
170 2 -> Print 'WARNING:' + message. (Default level).
170 2 -> Print 'WARNING:' + message. (Default level).
171 3 -> Print 'ERROR:' + message.
171 3 -> Print 'ERROR:' + message.
172 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val).
172 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val).
173
173
174 -exit_val (1): exit value returned by sys.exit() for a level 4
174 -exit_val (1): exit value returned by sys.exit() for a level 4
175 warning. Ignored for all other levels."""
175 warning. Ignored for all other levels."""
176
176
177 if level>0:
177 if level>0:
178 header = ['','','WARNING: ','ERROR: ','FATAL ERROR: ']
178 header = ['','','WARNING: ','ERROR: ','FATAL ERROR: ']
179 print >> Term.cerr, '%s%s' % (header[level],msg)
179 print >> Term.cerr, '%s%s' % (header[level],msg)
180 if level == 4:
180 if level == 4:
181 print >> Term.cerr,'Exiting.\n'
181 print >> Term.cerr,'Exiting.\n'
182 sys.exit(exit_val)
182 sys.exit(exit_val)
183
183
184 def info(msg):
184 def info(msg):
185 """Equivalent to warn(msg,level=1)."""
185 """Equivalent to warn(msg,level=1)."""
186
186
187 warn(msg,level=1)
187 warn(msg,level=1)
188
188
189 def error(msg):
189 def error(msg):
190 """Equivalent to warn(msg,level=3)."""
190 """Equivalent to warn(msg,level=3)."""
191
191
192 warn(msg,level=3)
192 warn(msg,level=3)
193
193
194 def fatal(msg,exit_val=1):
194 def fatal(msg,exit_val=1):
195 """Equivalent to warn(msg,exit_val=exit_val,level=4)."""
195 """Equivalent to warn(msg,exit_val=exit_val,level=4)."""
196
196
197 warn(msg,exit_val=exit_val,level=4)
197 warn(msg,exit_val=exit_val,level=4)
198
198
199 #----------------------------------------------------------------------------
199 #----------------------------------------------------------------------------
200 StringTypes = types.StringTypes
200 StringTypes = types.StringTypes
201
201
202 # Basic timing functionality
202 # Basic timing functionality
203
203
204 # If possible (Unix), use the resource module instead of time.clock()
204 # If possible (Unix), use the resource module instead of time.clock()
205 try:
205 try:
206 import resource
206 import resource
207 def clock():
207 def clock():
208 """clock() -> floating point number
208 """clock() -> floating point number
209
209
210 Return the CPU time in seconds (user time only, system time is
210 Return the CPU time in seconds (user time only, system time is
211 ignored) since the start of the process. This is done via a call to
211 ignored) since the start of the process. This is done via a call to
212 resource.getrusage, so it avoids the wraparound problems in
212 resource.getrusage, so it avoids the wraparound problems in
213 time.clock()."""
213 time.clock()."""
214
214
215 return resource.getrusage(resource.RUSAGE_SELF)[0]
215 return resource.getrusage(resource.RUSAGE_SELF)[0]
216
216
217 def clock2():
217 def clock2():
218 """clock2() -> (t_user,t_system)
218 """clock2() -> (t_user,t_system)
219
219
220 Similar to clock(), but return a tuple of user/system times."""
220 Similar to clock(), but return a tuple of user/system times."""
221 return resource.getrusage(resource.RUSAGE_SELF)[:2]
221 return resource.getrusage(resource.RUSAGE_SELF)[:2]
222
222
223 except ImportError:
223 except ImportError:
224 clock = time.clock
224 clock = time.clock
225 def clock2():
225 def clock2():
226 """Under windows, system CPU time can't be measured.
226 """Under windows, system CPU time can't be measured.
227
227
228 This just returns clock() and zero."""
228 This just returns clock() and zero."""
229 return time.clock(),0.0
229 return time.clock(),0.0
230
230
231 def timings_out(reps,func,*args,**kw):
231 def timings_out(reps,func,*args,**kw):
232 """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output)
232 """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output)
233
233
234 Execute a function reps times, return a tuple with the elapsed total
234 Execute a function reps times, return a tuple with the elapsed total
235 CPU time in seconds, the time per call and the function's output.
235 CPU time in seconds, the time per call and the function's output.
236
236
237 Under Unix, the return value is the sum of user+system time consumed by
237 Under Unix, the return value is the sum of user+system time consumed by
238 the process, computed via the resource module. This prevents problems
238 the process, computed via the resource module. This prevents problems
239 related to the wraparound effect which the time.clock() function has.
239 related to the wraparound effect which the time.clock() function has.
240
240
241 Under Windows the return value is in wall clock seconds. See the
241 Under Windows the return value is in wall clock seconds. See the
242 documentation for the time module for more details."""
242 documentation for the time module for more details."""
243
243
244 reps = int(reps)
244 reps = int(reps)
245 assert reps >=1, 'reps must be >= 1'
245 assert reps >=1, 'reps must be >= 1'
246 if reps==1:
246 if reps==1:
247 start = clock()
247 start = clock()
248 out = func(*args,**kw)
248 out = func(*args,**kw)
249 tot_time = clock()-start
249 tot_time = clock()-start
250 else:
250 else:
251 rng = xrange(reps-1) # the last time is executed separately to store output
251 rng = xrange(reps-1) # the last time is executed separately to store output
252 start = clock()
252 start = clock()
253 for dummy in rng: func(*args,**kw)
253 for dummy in rng: func(*args,**kw)
254 out = func(*args,**kw) # one last time
254 out = func(*args,**kw) # one last time
255 tot_time = clock()-start
255 tot_time = clock()-start
256 av_time = tot_time / reps
256 av_time = tot_time / reps
257 return tot_time,av_time,out
257 return tot_time,av_time,out
258
258
259 def timings(reps,func,*args,**kw):
259 def timings(reps,func,*args,**kw):
260 """timings(reps,func,*args,**kw) -> (t_total,t_per_call)
260 """timings(reps,func,*args,**kw) -> (t_total,t_per_call)
261
261
262 Execute a function reps times, return a tuple with the elapsed total CPU
262 Execute a function reps times, return a tuple with the elapsed total CPU
263 time in seconds and the time per call. These are just the first two values
263 time in seconds and the time per call. These are just the first two values
264 in timings_out()."""
264 in timings_out()."""
265
265
266 return timings_out(reps,func,*args,**kw)[0:2]
266 return timings_out(reps,func,*args,**kw)[0:2]
267
267
268 def timing(func,*args,**kw):
268 def timing(func,*args,**kw):
269 """timing(func,*args,**kw) -> t_total
269 """timing(func,*args,**kw) -> t_total
270
270
271 Execute a function once, return the elapsed total CPU time in
271 Execute a function once, return the elapsed total CPU time in
272 seconds. This is just the first value in timings_out()."""
272 seconds. This is just the first value in timings_out()."""
273
273
274 return timings_out(1,func,*args,**kw)[0]
274 return timings_out(1,func,*args,**kw)[0]
275
275
276 #****************************************************************************
276 #****************************************************************************
277 # file and system
277 # file and system
278
278
279 def system(cmd,verbose=0,debug=0,header=''):
279 def system(cmd,verbose=0,debug=0,header=''):
280 """Execute a system command, return its exit status.
280 """Execute a system command, return its exit status.
281
281
282 Options:
282 Options:
283
283
284 - verbose (0): print the command to be executed.
284 - verbose (0): print the command to be executed.
285
285
286 - debug (0): only print, do not actually execute.
286 - debug (0): only print, do not actually execute.
287
287
288 - header (''): Header to print on screen prior to the executed command (it
288 - header (''): Header to print on screen prior to the executed command (it
289 is only prepended to the command, no newlines are added).
289 is only prepended to the command, no newlines are added).
290
290
291 Note: a stateful version of this function is available through the
291 Note: a stateful version of this function is available through the
292 SystemExec class."""
292 SystemExec class."""
293
293
294 stat = 0
294 stat = 0
295 if verbose or debug: print header+cmd
295 if verbose or debug: print header+cmd
296 sys.stdout.flush()
296 sys.stdout.flush()
297 if not debug: stat = os.system(cmd)
297 if not debug: stat = os.system(cmd)
298 return stat
298 return stat
299
299
300 def shell(cmd,verbose=0,debug=0,header=''):
300 def shell(cmd,verbose=0,debug=0,header=''):
301 """Execute a command in the system shell, always return None.
301 """Execute a command in the system shell, always return None.
302
302
303 Options:
303 Options:
304
304
305 - verbose (0): print the command to be executed.
305 - verbose (0): print the command to be executed.
306
306
307 - debug (0): only print, do not actually execute.
307 - debug (0): only print, do not actually execute.
308
308
309 - header (''): Header to print on screen prior to the executed command (it
309 - header (''): Header to print on screen prior to the executed command (it
310 is only prepended to the command, no newlines are added).
310 is only prepended to the command, no newlines are added).
311
311
312 Note: this is similar to genutils.system(), but it returns None so it can
312 Note: this is similar to genutils.system(), but it returns None so it can
313 be conveniently used in interactive loops without getting the return value
313 be conveniently used in interactive loops without getting the return value
314 (typically 0) printed many times."""
314 (typically 0) printed many times."""
315
315
316 stat = 0
316 stat = 0
317 if verbose or debug: print header+cmd
317 if verbose or debug: print header+cmd
318 # flush stdout so we don't mangle python's buffering
318 # flush stdout so we don't mangle python's buffering
319 sys.stdout.flush()
319 sys.stdout.flush()
320 if not debug:
320 if not debug:
321 os.system(cmd)
321 os.system(cmd)
322
322
323 def getoutput(cmd,verbose=0,debug=0,header='',split=0):
323 def getoutput(cmd,verbose=0,debug=0,header='',split=0):
324 """Dummy substitute for perl's backquotes.
324 """Dummy substitute for perl's backquotes.
325
325
326 Executes a command and returns the output.
326 Executes a command and returns the output.
327
327
328 Accepts the same arguments as system(), plus:
328 Accepts the same arguments as system(), plus:
329
329
330 - split(0): if true, the output is returned as a list split on newlines.
330 - split(0): if true, the output is returned as a list split on newlines.
331
331
332 Note: a stateful version of this function is available through the
332 Note: a stateful version of this function is available through the
333 SystemExec class."""
333 SystemExec class."""
334
334
335 if verbose or debug: print header+cmd
335 if verbose or debug: print header+cmd
336 if not debug:
336 if not debug:
337 output = commands.getoutput(cmd)
337 output = commands.getoutput(cmd)
338 if split:
338 if split:
339 return output.split('\n')
339 return output.split('\n')
340 else:
340 else:
341 return output
341 return output
342
342
343 def getoutputerror(cmd,verbose=0,debug=0,header='',split=0):
343 def getoutputerror(cmd,verbose=0,debug=0,header='',split=0):
344 """Return (standard output,standard error) of executing cmd in a shell.
344 """Return (standard output,standard error) of executing cmd in a shell.
345
345
346 Accepts the same arguments as system(), plus:
346 Accepts the same arguments as system(), plus:
347
347
348 - split(0): if true, each of stdout/err is returned as a list split on
348 - split(0): if true, each of stdout/err is returned as a list split on
349 newlines.
349 newlines.
350
350
351 Note: a stateful version of this function is available through the
351 Note: a stateful version of this function is available through the
352 SystemExec class."""
352 SystemExec class."""
353
353
354 if verbose or debug: print header+cmd
354 if verbose or debug: print header+cmd
355 if not cmd:
355 if not cmd:
356 if split:
356 if split:
357 return [],[]
357 return [],[]
358 else:
358 else:
359 return '',''
359 return '',''
360 if not debug:
360 if not debug:
361 pin,pout,perr = os.popen3(cmd)
361 pin,pout,perr = os.popen3(cmd)
362 tout = pout.read().rstrip()
362 tout = pout.read().rstrip()
363 terr = perr.read().rstrip()
363 terr = perr.read().rstrip()
364 pin.close()
364 pin.close()
365 pout.close()
365 pout.close()
366 perr.close()
366 perr.close()
367 if split:
367 if split:
368 return tout.split('\n'),terr.split('\n')
368 return tout.split('\n'),terr.split('\n')
369 else:
369 else:
370 return tout,terr
370 return tout,terr
371
371
372 # for compatibility with older naming conventions
372 # for compatibility with older naming conventions
373 xsys = system
373 xsys = system
374 bq = getoutput
374 bq = getoutput
375
375
376 class SystemExec:
376 class SystemExec:
377 """Access the system and getoutput functions through a stateful interface.
377 """Access the system and getoutput functions through a stateful interface.
378
378
379 Note: here we refer to the system and getoutput functions from this
379 Note: here we refer to the system and getoutput functions from this
380 library, not the ones from the standard python library.
380 library, not the ones from the standard python library.
381
381
382 This class offers the system and getoutput functions as methods, but the
382 This class offers the system and getoutput functions as methods, but the
383 verbose, debug and header parameters can be set for the instance (at
383 verbose, debug and header parameters can be set for the instance (at
384 creation time or later) so that they don't need to be specified on each
384 creation time or later) so that they don't need to be specified on each
385 call.
385 call.
386
386
387 For efficiency reasons, there's no way to override the parameters on a
387 For efficiency reasons, there's no way to override the parameters on a
388 per-call basis other than by setting instance attributes. If you need
388 per-call basis other than by setting instance attributes. If you need
389 local overrides, it's best to directly call system() or getoutput().
389 local overrides, it's best to directly call system() or getoutput().
390
390
391 The following names are provided as alternate options:
391 The following names are provided as alternate options:
392 - xsys: alias to system
392 - xsys: alias to system
393 - bq: alias to getoutput
393 - bq: alias to getoutput
394
394
395 An instance can then be created as:
395 An instance can then be created as:
396 >>> sysexec = SystemExec(verbose=1,debug=0,header='Calling: ')
396 >>> sysexec = SystemExec(verbose=1,debug=0,header='Calling: ')
397
397
398 And used as:
398 And used as:
399 >>> sysexec.xsys('pwd')
399 >>> sysexec.xsys('pwd')
400 >>> dirlist = sysexec.bq('ls -l')
400 >>> dirlist = sysexec.bq('ls -l')
401 """
401 """
402
402
403 def __init__(self,verbose=0,debug=0,header='',split=0):
403 def __init__(self,verbose=0,debug=0,header='',split=0):
404 """Specify the instance's values for verbose, debug and header."""
404 """Specify the instance's values for verbose, debug and header."""
405 setattr_list(self,'verbose debug header split')
405 setattr_list(self,'verbose debug header split')
406
406
407 def system(self,cmd):
407 def system(self,cmd):
408 """Stateful interface to system(), with the same keyword parameters."""
408 """Stateful interface to system(), with the same keyword parameters."""
409
409
410 system(cmd,self.verbose,self.debug,self.header)
410 system(cmd,self.verbose,self.debug,self.header)
411
411
412 def shell(self,cmd):
412 def shell(self,cmd):
413 """Stateful interface to shell(), with the same keyword parameters."""
413 """Stateful interface to shell(), with the same keyword parameters."""
414
414
415 shell(cmd,self.verbose,self.debug,self.header)
415 shell(cmd,self.verbose,self.debug,self.header)
416
416
417 xsys = system # alias
417 xsys = system # alias
418
418
419 def getoutput(self,cmd):
419 def getoutput(self,cmd):
420 """Stateful interface to getoutput()."""
420 """Stateful interface to getoutput()."""
421
421
422 return getoutput(cmd,self.verbose,self.debug,self.header,self.split)
422 return getoutput(cmd,self.verbose,self.debug,self.header,self.split)
423
423
424 def getoutputerror(self,cmd):
424 def getoutputerror(self,cmd):
425 """Stateful interface to getoutputerror()."""
425 """Stateful interface to getoutputerror()."""
426
426
427 return getoutputerror(cmd,self.verbose,self.debug,self.header,self.split)
427 return getoutputerror(cmd,self.verbose,self.debug,self.header,self.split)
428
428
429 bq = getoutput # alias
429 bq = getoutput # alias
430
430
431 #-----------------------------------------------------------------------------
431 #-----------------------------------------------------------------------------
432 def mutex_opts(dict,ex_op):
432 def mutex_opts(dict,ex_op):
433 """Check for presence of mutually exclusive keys in a dict.
433 """Check for presence of mutually exclusive keys in a dict.
434
434
435 Call: mutex_opts(dict,[[op1a,op1b],[op2a,op2b]...]"""
435 Call: mutex_opts(dict,[[op1a,op1b],[op2a,op2b]...]"""
436 for op1,op2 in ex_op:
436 for op1,op2 in ex_op:
437 if op1 in dict and op2 in dict:
437 if op1 in dict and op2 in dict:
438 raise ValueError,'\n*** ERROR in Arguments *** '\
438 raise ValueError,'\n*** ERROR in Arguments *** '\
439 'Options '+op1+' and '+op2+' are mutually exclusive.'
439 'Options '+op1+' and '+op2+' are mutually exclusive.'
440
440
441 #-----------------------------------------------------------------------------
441 #-----------------------------------------------------------------------------
442 def get_py_filename(name):
443 """Return a valid python filename in the current directory.
444
445 If the given name is not a file, it adds '.py' and searches again.
446 Raises IOError with an informative message if the file isn't found."""
447
448 name = os.path.expanduser(name)
449 if not os.path.isfile(name) and not name.endswith('.py'):
450 name += '.py'
451 if os.path.isfile(name):
452 return name
453 else:
454 raise IOError,'File `%s` not found.' % name
455
456 #-----------------------------------------------------------------------------
442 def filefind(fname,alt_dirs = None):
457 def filefind(fname,alt_dirs = None):
443 """Return the given filename either in the current directory, if it
458 """Return the given filename either in the current directory, if it
444 exists, or in a specified list of directories.
459 exists, or in a specified list of directories.
445
460
446 ~ expansion is done on all file and directory names.
461 ~ expansion is done on all file and directory names.
447
462
448 Upon an unsuccessful search, raise an IOError exception."""
463 Upon an unsuccessful search, raise an IOError exception."""
449
464
450 if alt_dirs is None:
465 if alt_dirs is None:
451 try:
466 try:
452 alt_dirs = get_home_dir()
467 alt_dirs = get_home_dir()
453 except HomeDirError:
468 except HomeDirError:
454 alt_dirs = os.getcwd()
469 alt_dirs = os.getcwd()
455 search = [fname] + list_strings(alt_dirs)
470 search = [fname] + list_strings(alt_dirs)
456 search = map(os.path.expanduser,search)
471 search = map(os.path.expanduser,search)
457 #print 'search list for',fname,'list:',search # dbg
472 #print 'search list for',fname,'list:',search # dbg
458 fname = search[0]
473 fname = search[0]
459 if os.path.isfile(fname):
474 if os.path.isfile(fname):
460 return fname
475 return fname
461 for direc in search[1:]:
476 for direc in search[1:]:
462 testname = os.path.join(direc,fname)
477 testname = os.path.join(direc,fname)
463 #print 'testname',testname # dbg
478 #print 'testname',testname # dbg
464 if os.path.isfile(testname):
479 if os.path.isfile(testname):
465 return testname
480 return testname
466 raise IOError,'File' + `fname` + \
481 raise IOError,'File' + `fname` + \
467 ' not found in current or supplied directories:' + `alt_dirs`
482 ' not found in current or supplied directories:' + `alt_dirs`
468
483
469 #----------------------------------------------------------------------------
484 #----------------------------------------------------------------------------
485 def file_read(filename):
486 """Read a file and close it. Returns the file source."""
487 fobj=open(filename,'r');
488 source = fobj.read();
489 fobj.close()
490 return source
491
492 #----------------------------------------------------------------------------
470 def target_outdated(target,deps):
493 def target_outdated(target,deps):
471 """Determine whether a target is out of date.
494 """Determine whether a target is out of date.
472
495
473 target_outdated(target,deps) -> 1/0
496 target_outdated(target,deps) -> 1/0
474
497
475 deps: list of filenames which MUST exist.
498 deps: list of filenames which MUST exist.
476 target: single filename which may or may not exist.
499 target: single filename which may or may not exist.
477
500
478 If target doesn't exist or is older than any file listed in deps, return
501 If target doesn't exist or is older than any file listed in deps, return
479 true, otherwise return false.
502 true, otherwise return false.
480 """
503 """
481 try:
504 try:
482 target_time = os.path.getmtime(target)
505 target_time = os.path.getmtime(target)
483 except os.error:
506 except os.error:
484 return 1
507 return 1
485 for dep in deps:
508 for dep in deps:
486 dep_time = os.path.getmtime(dep)
509 dep_time = os.path.getmtime(dep)
487 if dep_time > target_time:
510 if dep_time > target_time:
488 #print "For target",target,"Dep failed:",dep # dbg
511 #print "For target",target,"Dep failed:",dep # dbg
489 #print "times (dep,tar):",dep_time,target_time # dbg
512 #print "times (dep,tar):",dep_time,target_time # dbg
490 return 1
513 return 1
491 return 0
514 return 0
492
515
493 #-----------------------------------------------------------------------------
516 #-----------------------------------------------------------------------------
494 def target_update(target,deps,cmd):
517 def target_update(target,deps,cmd):
495 """Update a target with a given command given a list of dependencies.
518 """Update a target with a given command given a list of dependencies.
496
519
497 target_update(target,deps,cmd) -> runs cmd if target is outdated.
520 target_update(target,deps,cmd) -> runs cmd if target is outdated.
498
521
499 This is just a wrapper around target_outdated() which calls the given
522 This is just a wrapper around target_outdated() which calls the given
500 command if target is outdated."""
523 command if target is outdated."""
501
524
502 if target_outdated(target,deps):
525 if target_outdated(target,deps):
503 xsys(cmd)
526 xsys(cmd)
504
527
505 #----------------------------------------------------------------------------
528 #----------------------------------------------------------------------------
506 def unquote_ends(istr):
529 def unquote_ends(istr):
507 """Remove a single pair of quotes from the endpoints of a string."""
530 """Remove a single pair of quotes from the endpoints of a string."""
508
531
509 if not istr:
532 if not istr:
510 return istr
533 return istr
511 if (istr[0]=="'" and istr[-1]=="'") or \
534 if (istr[0]=="'" and istr[-1]=="'") or \
512 (istr[0]=='"' and istr[-1]=='"'):
535 (istr[0]=='"' and istr[-1]=='"'):
513 return istr[1:-1]
536 return istr[1:-1]
514 else:
537 else:
515 return istr
538 return istr
516
539
517 #----------------------------------------------------------------------------
540 #----------------------------------------------------------------------------
518 def process_cmdline(argv,names=[],defaults={},usage=''):
541 def process_cmdline(argv,names=[],defaults={},usage=''):
519 """ Process command-line options and arguments.
542 """ Process command-line options and arguments.
520
543
521 Arguments:
544 Arguments:
522
545
523 - argv: list of arguments, typically sys.argv.
546 - argv: list of arguments, typically sys.argv.
524
547
525 - names: list of option names. See DPyGetOpt docs for details on options
548 - names: list of option names. See DPyGetOpt docs for details on options
526 syntax.
549 syntax.
527
550
528 - defaults: dict of default values.
551 - defaults: dict of default values.
529
552
530 - usage: optional usage notice to print if a wrong argument is passed.
553 - usage: optional usage notice to print if a wrong argument is passed.
531
554
532 Return a dict of options and a list of free arguments."""
555 Return a dict of options and a list of free arguments."""
533
556
534 getopt = DPyGetOpt.DPyGetOpt()
557 getopt = DPyGetOpt.DPyGetOpt()
535 getopt.setIgnoreCase(0)
558 getopt.setIgnoreCase(0)
536 getopt.parseConfiguration(names)
559 getopt.parseConfiguration(names)
537
560
538 try:
561 try:
539 getopt.processArguments(argv)
562 getopt.processArguments(argv)
540 except:
563 except:
541 print usage
564 print usage
542 warn(`sys.exc_value`,level=4)
565 warn(`sys.exc_value`,level=4)
543
566
544 defaults.update(getopt.optionValues)
567 defaults.update(getopt.optionValues)
545 args = getopt.freeValues
568 args = getopt.freeValues
546
569
547 return defaults,args
570 return defaults,args
548
571
549 #----------------------------------------------------------------------------
572 #----------------------------------------------------------------------------
550 def optstr2types(ostr):
573 def optstr2types(ostr):
551 """Convert a string of option names to a dict of type mappings.
574 """Convert a string of option names to a dict of type mappings.
552
575
553 optstr2types(str) -> {None:'string_opts',int:'int_opts',float:'float_opts'}
576 optstr2types(str) -> {None:'string_opts',int:'int_opts',float:'float_opts'}
554
577
555 This is used to get the types of all the options in a string formatted
578 This is used to get the types of all the options in a string formatted
556 with the conventions of DPyGetOpt. The 'type' None is used for options
579 with the conventions of DPyGetOpt. The 'type' None is used for options
557 which are strings (they need no further conversion). This function's main
580 which are strings (they need no further conversion). This function's main
558 use is to get a typemap for use with read_dict().
581 use is to get a typemap for use with read_dict().
559 """
582 """
560
583
561 typeconv = {None:'',int:'',float:''}
584 typeconv = {None:'',int:'',float:''}
562 typemap = {'s':None,'i':int,'f':float}
585 typemap = {'s':None,'i':int,'f':float}
563 opt_re = re.compile(r'([\w]*)([^:=]*:?=?)([sif]?)')
586 opt_re = re.compile(r'([\w]*)([^:=]*:?=?)([sif]?)')
564
587
565 for w in ostr.split():
588 for w in ostr.split():
566 oname,alias,otype = opt_re.match(w).groups()
589 oname,alias,otype = opt_re.match(w).groups()
567 if otype == '' or alias == '!': # simple switches are integers too
590 if otype == '' or alias == '!': # simple switches are integers too
568 otype = 'i'
591 otype = 'i'
569 typeconv[typemap[otype]] += oname + ' '
592 typeconv[typemap[otype]] += oname + ' '
570 return typeconv
593 return typeconv
571
594
572 #----------------------------------------------------------------------------
595 #----------------------------------------------------------------------------
573 def read_dict(filename,type_conv=None,**opt):
596 def read_dict(filename,type_conv=None,**opt):
574
597
575 """Read a dictionary of key=value pairs from an input file, optionally
598 """Read a dictionary of key=value pairs from an input file, optionally
576 performing conversions on the resulting values.
599 performing conversions on the resulting values.
577
600
578 read_dict(filename,type_conv,**opt) -> dict
601 read_dict(filename,type_conv,**opt) -> dict
579
602
580 Only one value per line is accepted, the format should be
603 Only one value per line is accepted, the format should be
581 # optional comments are ignored
604 # optional comments are ignored
582 key value\n
605 key value\n
583
606
584 Args:
607 Args:
585
608
586 - type_conv: A dictionary specifying which keys need to be converted to
609 - type_conv: A dictionary specifying which keys need to be converted to
587 which types. By default all keys are read as strings. This dictionary
610 which types. By default all keys are read as strings. This dictionary
588 should have as its keys valid conversion functions for strings
611 should have as its keys valid conversion functions for strings
589 (int,long,float,complex, or your own). The value for each key
612 (int,long,float,complex, or your own). The value for each key
590 (converter) should be a whitespace separated string containing the names
613 (converter) should be a whitespace separated string containing the names
591 of all the entries in the file to be converted using that function. For
614 of all the entries in the file to be converted using that function. For
592 keys to be left alone, use None as the conversion function (only needed
615 keys to be left alone, use None as the conversion function (only needed
593 with purge=1, see below).
616 with purge=1, see below).
594
617
595 - opt: dictionary with extra options as below (default in parens)
618 - opt: dictionary with extra options as below (default in parens)
596
619
597 purge(0): if set to 1, all keys *not* listed in type_conv are purged out
620 purge(0): if set to 1, all keys *not* listed in type_conv are purged out
598 of the dictionary to be returned. If purge is going to be used, the
621 of the dictionary to be returned. If purge is going to be used, the
599 set of keys to be left as strings also has to be explicitly specified
622 set of keys to be left as strings also has to be explicitly specified
600 using the (non-existent) conversion function None.
623 using the (non-existent) conversion function None.
601
624
602 fs(None): field separator. This is the key/value separator to be used
625 fs(None): field separator. This is the key/value separator to be used
603 when parsing the file. The None default means any whitespace [behavior
626 when parsing the file. The None default means any whitespace [behavior
604 of string.split()].
627 of string.split()].
605
628
606 strip(0): if 1, strip string values of leading/trailinig whitespace.
629 strip(0): if 1, strip string values of leading/trailinig whitespace.
607
630
608 warn(1): warning level if requested keys are not found in file.
631 warn(1): warning level if requested keys are not found in file.
609 - 0: silently ignore.
632 - 0: silently ignore.
610 - 1: inform but proceed.
633 - 1: inform but proceed.
611 - 2: raise KeyError exception.
634 - 2: raise KeyError exception.
612
635
613 no_empty(0): if 1, remove keys with whitespace strings as a value.
636 no_empty(0): if 1, remove keys with whitespace strings as a value.
614
637
615 unique([]): list of keys (or space separated string) which can't be
638 unique([]): list of keys (or space separated string) which can't be
616 repeated. If one such key is found in the file, each new instance
639 repeated. If one such key is found in the file, each new instance
617 overwrites the previous one. For keys not listed here, the behavior is
640 overwrites the previous one. For keys not listed here, the behavior is
618 to make a list of all appearances.
641 to make a list of all appearances.
619
642
620 Example:
643 Example:
621 If the input file test.ini has:
644 If the input file test.ini has:
622 i 3
645 i 3
623 x 4.5
646 x 4.5
624 y 5.5
647 y 5.5
625 s hi ho
648 s hi ho
626 Then:
649 Then:
627
650
628 >>> type_conv={int:'i',float:'x',None:'s'}
651 >>> type_conv={int:'i',float:'x',None:'s'}
629 >>> read_dict('test.ini')
652 >>> read_dict('test.ini')
630 {'i': '3', 's': 'hi ho', 'x': '4.5', 'y': '5.5'}
653 {'i': '3', 's': 'hi ho', 'x': '4.5', 'y': '5.5'}
631 >>> read_dict('test.ini',type_conv)
654 >>> read_dict('test.ini',type_conv)
632 {'i': 3, 's': 'hi ho', 'x': 4.5, 'y': '5.5'}
655 {'i': 3, 's': 'hi ho', 'x': 4.5, 'y': '5.5'}
633 >>> read_dict('test.ini',type_conv,purge=1)
656 >>> read_dict('test.ini',type_conv,purge=1)
634 {'i': 3, 's': 'hi ho', 'x': 4.5}
657 {'i': 3, 's': 'hi ho', 'x': 4.5}
635 """
658 """
636
659
637 # starting config
660 # starting config
638 opt.setdefault('purge',0)
661 opt.setdefault('purge',0)
639 opt.setdefault('fs',None) # field sep defaults to any whitespace
662 opt.setdefault('fs',None) # field sep defaults to any whitespace
640 opt.setdefault('strip',0)
663 opt.setdefault('strip',0)
641 opt.setdefault('warn',1)
664 opt.setdefault('warn',1)
642 opt.setdefault('no_empty',0)
665 opt.setdefault('no_empty',0)
643 opt.setdefault('unique','')
666 opt.setdefault('unique','')
644 if type(opt['unique']) in StringTypes:
667 if type(opt['unique']) in StringTypes:
645 unique_keys = qw(opt['unique'])
668 unique_keys = qw(opt['unique'])
646 elif type(opt['unique']) in (types.TupleType,types.ListType):
669 elif type(opt['unique']) in (types.TupleType,types.ListType):
647 unique_keys = opt['unique']
670 unique_keys = opt['unique']
648 else:
671 else:
649 raise ValueError, 'Unique keys must be given as a string, List or Tuple'
672 raise ValueError, 'Unique keys must be given as a string, List or Tuple'
650
673
651 dict = {}
674 dict = {}
652 # first read in table of values as strings
675 # first read in table of values as strings
653 file = open(filename,'r')
676 file = open(filename,'r')
654 for line in file.readlines():
677 for line in file.readlines():
655 line = line.strip()
678 line = line.strip()
656 if len(line) and line[0]=='#': continue
679 if len(line) and line[0]=='#': continue
657 if len(line)>0:
680 if len(line)>0:
658 lsplit = line.split(opt['fs'],1)
681 lsplit = line.split(opt['fs'],1)
659 try:
682 try:
660 key,val = lsplit
683 key,val = lsplit
661 except ValueError:
684 except ValueError:
662 key,val = lsplit[0],''
685 key,val = lsplit[0],''
663 key = key.strip()
686 key = key.strip()
664 if opt['strip']: val = val.strip()
687 if opt['strip']: val = val.strip()
665 if val == "''" or val == '""': val = ''
688 if val == "''" or val == '""': val = ''
666 if opt['no_empty'] and (val=='' or val.isspace()):
689 if opt['no_empty'] and (val=='' or val.isspace()):
667 continue
690 continue
668 # if a key is found more than once in the file, build a list
691 # if a key is found more than once in the file, build a list
669 # unless it's in the 'unique' list. In that case, last found in file
692 # unless it's in the 'unique' list. In that case, last found in file
670 # takes precedence. User beware.
693 # takes precedence. User beware.
671 try:
694 try:
672 if dict[key] and key in unique_keys:
695 if dict[key] and key in unique_keys:
673 dict[key] = val
696 dict[key] = val
674 elif type(dict[key]) is types.ListType:
697 elif type(dict[key]) is types.ListType:
675 dict[key].append(val)
698 dict[key].append(val)
676 else:
699 else:
677 dict[key] = [dict[key],val]
700 dict[key] = [dict[key],val]
678 except KeyError:
701 except KeyError:
679 dict[key] = val
702 dict[key] = val
680 # purge if requested
703 # purge if requested
681 if opt['purge']:
704 if opt['purge']:
682 accepted_keys = qwflat(type_conv.values())
705 accepted_keys = qwflat(type_conv.values())
683 for key in dict.keys():
706 for key in dict.keys():
684 if key in accepted_keys: continue
707 if key in accepted_keys: continue
685 del(dict[key])
708 del(dict[key])
686 # now convert if requested
709 # now convert if requested
687 if type_conv==None: return dict
710 if type_conv==None: return dict
688 conversions = type_conv.keys()
711 conversions = type_conv.keys()
689 try: conversions.remove(None)
712 try: conversions.remove(None)
690 except: pass
713 except: pass
691 for convert in conversions:
714 for convert in conversions:
692 for val in qw(type_conv[convert]):
715 for val in qw(type_conv[convert]):
693 try:
716 try:
694 dict[val] = convert(dict[val])
717 dict[val] = convert(dict[val])
695 except KeyError,e:
718 except KeyError,e:
696 if opt['warn'] == 0:
719 if opt['warn'] == 0:
697 pass
720 pass
698 elif opt['warn'] == 1:
721 elif opt['warn'] == 1:
699 print >>sys.stderr, 'Warning: key',val,\
722 print >>sys.stderr, 'Warning: key',val,\
700 'not found in file',filename
723 'not found in file',filename
701 elif opt['warn'] == 2:
724 elif opt['warn'] == 2:
702 raise KeyError,e
725 raise KeyError,e
703 else:
726 else:
704 raise ValueError,'Warning level must be 0,1 or 2'
727 raise ValueError,'Warning level must be 0,1 or 2'
705
728
706 return dict
729 return dict
707
730
708 #----------------------------------------------------------------------------
731 #----------------------------------------------------------------------------
709 def flag_calls(func):
732 def flag_calls(func):
710 """Wrap a function to detect and flag when it gets called.
733 """Wrap a function to detect and flag when it gets called.
711
734
712 This is a decorator which takes a function and wraps it in a function with
735 This is a decorator which takes a function and wraps it in a function with
713 a 'called' attribute. wrapper.called is initialized to False.
736 a 'called' attribute. wrapper.called is initialized to False.
714
737
715 The wrapper.called attribute is set to False right before each call to the
738 The wrapper.called attribute is set to False right before each call to the
716 wrapped function, so if the call fails it remains False. After the call
739 wrapped function, so if the call fails it remains False. After the call
717 completes, wrapper.called is set to True and the output is returned.
740 completes, wrapper.called is set to True and the output is returned.
718
741
719 Testing for truth in wrapper.called allows you to determine if a call to
742 Testing for truth in wrapper.called allows you to determine if a call to
720 func() was attempted and succeeded."""
743 func() was attempted and succeeded."""
721
744
722 def wrapper(*args,**kw):
745 def wrapper(*args,**kw):
723 wrapper.called = False
746 wrapper.called = False
724 out = func(*args,**kw)
747 out = func(*args,**kw)
725 wrapper.called = True
748 wrapper.called = True
726 return out
749 return out
727
750
728 wrapper.called = False
751 wrapper.called = False
729 wrapper.__doc__ = func.__doc__
752 wrapper.__doc__ = func.__doc__
730 return wrapper
753 return wrapper
731
754
732 #----------------------------------------------------------------------------
755 #----------------------------------------------------------------------------
733 class HomeDirError(Error):
756 class HomeDirError(Error):
734 pass
757 pass
735
758
736 def get_home_dir():
759 def get_home_dir():
737 """Return the closest possible equivalent to a 'home' directory.
760 """Return the closest possible equivalent to a 'home' directory.
738
761
739 We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH.
762 We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH.
740
763
741 Currently only Posix and NT are implemented, a HomeDirError exception is
764 Currently only Posix and NT are implemented, a HomeDirError exception is
742 raised for all other OSes. """
765 raised for all other OSes. """
743
766
744 isdir = os.path.isdir
767 isdir = os.path.isdir
745 env = os.environ
768 env = os.environ
746 try:
769 try:
747 homedir = env['HOME']
770 homedir = env['HOME']
748 if not isdir(homedir):
771 if not isdir(homedir):
749 # in case a user stuck some string which does NOT resolve to a
772 # in case a user stuck some string which does NOT resolve to a
750 # valid path, it's as good as if we hadn't foud it
773 # valid path, it's as good as if we hadn't foud it
751 raise KeyError
774 raise KeyError
752 return homedir
775 return homedir
753 except KeyError:
776 except KeyError:
754 if os.name == 'posix':
777 if os.name == 'posix':
755 raise HomeDirError,'undefined $HOME, IPython can not proceed.'
778 raise HomeDirError,'undefined $HOME, IPython can not proceed.'
756 elif os.name == 'nt':
779 elif os.name == 'nt':
757 # For some strange reason, win9x returns 'nt' for os.name.
780 # For some strange reason, win9x returns 'nt' for os.name.
758 try:
781 try:
759 homedir = os.path.join(env['HOMEDRIVE'],env['HOMEPATH'])
782 homedir = os.path.join(env['HOMEDRIVE'],env['HOMEPATH'])
760 if not isdir(homedir):
783 if not isdir(homedir):
761 homedir = os.path.join(env['USERPROFILE'])
784 homedir = os.path.join(env['USERPROFILE'])
762 if not isdir(homedir):
785 if not isdir(homedir):
763 raise HomeDirError
786 raise HomeDirError
764 return homedir
787 return homedir
765 except:
788 except:
766 try:
789 try:
767 # Use the registry to get the 'My Documents' folder.
790 # Use the registry to get the 'My Documents' folder.
768 import _winreg as wreg
791 import _winreg as wreg
769 key = wreg.OpenKey(wreg.HKEY_CURRENT_USER,
792 key = wreg.OpenKey(wreg.HKEY_CURRENT_USER,
770 "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
793 "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
771 homedir = wreg.QueryValueEx(key,'Personal')[0]
794 homedir = wreg.QueryValueEx(key,'Personal')[0]
772 key.Close()
795 key.Close()
773 if not isdir(homedir):
796 if not isdir(homedir):
774 e = ('Invalid "Personal" folder registry key '
797 e = ('Invalid "Personal" folder registry key '
775 'typically "My Documents".\n'
798 'typically "My Documents".\n'
776 'Value: %s\n'
799 'Value: %s\n'
777 'This is not a valid directory on your system.' %
800 'This is not a valid directory on your system.' %
778 homedir)
801 homedir)
779 raise HomeDirError(e)
802 raise HomeDirError(e)
780 return homedir
803 return homedir
781 except HomeDirError:
804 except HomeDirError:
782 raise
805 raise
783 except:
806 except:
784 return 'C:\\'
807 return 'C:\\'
785 elif os.name == 'dos':
808 elif os.name == 'dos':
786 # Desperate, may do absurd things in classic MacOS. May work under DOS.
809 # Desperate, may do absurd things in classic MacOS. May work under DOS.
787 return 'C:\\'
810 return 'C:\\'
788 else:
811 else:
789 raise HomeDirError,'support for your operating system not implemented.'
812 raise HomeDirError,'support for your operating system not implemented.'
790
813
791 #****************************************************************************
814 #****************************************************************************
792 # strings and text
815 # strings and text
793
816
794 class LSString(str):
817 class LSString(str):
795 """String derivative with a special access attributes.
818 """String derivative with a special access attributes.
796
819
797 These are normal strings, but with the special attributes:
820 These are normal strings, but with the special attributes:
798
821
799 .l (or .list) : value as list (split on newlines).
822 .l (or .list) : value as list (split on newlines).
800 .n (or .nlstr): original value (the string itself).
823 .n (or .nlstr): original value (the string itself).
801 .s (or .spstr): value as whitespace-separated string.
824 .s (or .spstr): value as whitespace-separated string.
802
825
803 Any values which require transformations are computed only once and
826 Any values which require transformations are computed only once and
804 cached.
827 cached.
805
828
806 Such strings are very useful to efficiently interact with the shell, which
829 Such strings are very useful to efficiently interact with the shell, which
807 typically only understands whitespace-separated options for commands."""
830 typically only understands whitespace-separated options for commands."""
808
831
809 def get_list(self):
832 def get_list(self):
810 try:
833 try:
811 return self.__list
834 return self.__list
812 except AttributeError:
835 except AttributeError:
813 self.__list = self.split('\n')
836 self.__list = self.split('\n')
814 return self.__list
837 return self.__list
815
838
816 l = list = property(get_list)
839 l = list = property(get_list)
817
840
818 def get_spstr(self):
841 def get_spstr(self):
819 try:
842 try:
820 return self.__spstr
843 return self.__spstr
821 except AttributeError:
844 except AttributeError:
822 self.__spstr = self.replace('\n',' ')
845 self.__spstr = self.replace('\n',' ')
823 return self.__spstr
846 return self.__spstr
824
847
825 s = spstr = property(get_spstr)
848 s = spstr = property(get_spstr)
826
849
827 def get_nlstr(self):
850 def get_nlstr(self):
828 return self
851 return self
829
852
830 n = nlstr = property(get_nlstr)
853 n = nlstr = property(get_nlstr)
831
854
832 class SList(list):
855 class SList(list):
833 """List derivative with a special access attributes.
856 """List derivative with a special access attributes.
834
857
835 These are normal lists, but with the special attributes:
858 These are normal lists, but with the special attributes:
836
859
837 .l (or .list) : value as list (the list itself).
860 .l (or .list) : value as list (the list itself).
838 .n (or .nlstr): value as a string, joined on newlines.
861 .n (or .nlstr): value as a string, joined on newlines.
839 .s (or .spstr): value as a string, joined on spaces.
862 .s (or .spstr): value as a string, joined on spaces.
840
863
841 Any values which require transformations are computed only once and
864 Any values which require transformations are computed only once and
842 cached."""
865 cached."""
843
866
844 def get_list(self):
867 def get_list(self):
845 return self
868 return self
846
869
847 l = list = property(get_list)
870 l = list = property(get_list)
848
871
849 def get_spstr(self):
872 def get_spstr(self):
850 try:
873 try:
851 return self.__spstr
874 return self.__spstr
852 except AttributeError:
875 except AttributeError:
853 self.__spstr = ' '.join(self)
876 self.__spstr = ' '.join(self)
854 return self.__spstr
877 return self.__spstr
855
878
856 s = spstr = property(get_spstr)
879 s = spstr = property(get_spstr)
857
880
858 def get_nlstr(self):
881 def get_nlstr(self):
859 try:
882 try:
860 return self.__nlstr
883 return self.__nlstr
861 except AttributeError:
884 except AttributeError:
862 self.__nlstr = '\n'.join(self)
885 self.__nlstr = '\n'.join(self)
863 return self.__nlstr
886 return self.__nlstr
864
887
865 n = nlstr = property(get_nlstr)
888 n = nlstr = property(get_nlstr)
866
889
867 def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'):
890 def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'):
868 """Take multiple lines of input.
891 """Take multiple lines of input.
869
892
870 A list with each line of input as a separate element is returned when a
893 A list with each line of input as a separate element is returned when a
871 termination string is entered (defaults to a single '.'). Input can also
894 termination string is entered (defaults to a single '.'). Input can also
872 terminate via EOF (^D in Unix, ^Z-RET in Windows).
895 terminate via EOF (^D in Unix, ^Z-RET in Windows).
873
896
874 Lines of input which end in \\ are joined into single entries (and a
897 Lines of input which end in \\ are joined into single entries (and a
875 secondary continuation prompt is issued as long as the user terminates
898 secondary continuation prompt is issued as long as the user terminates
876 lines with \\). This allows entering very long strings which are still
899 lines with \\). This allows entering very long strings which are still
877 meant to be treated as single entities.
900 meant to be treated as single entities.
878 """
901 """
879
902
880 try:
903 try:
881 if header:
904 if header:
882 header += '\n'
905 header += '\n'
883 lines = [raw_input(header + ps1)]
906 lines = [raw_input(header + ps1)]
884 except EOFError:
907 except EOFError:
885 return []
908 return []
886 terminate = [terminate_str]
909 terminate = [terminate_str]
887 try:
910 try:
888 while lines[-1:] != terminate:
911 while lines[-1:] != terminate:
889 new_line = raw_input(ps1)
912 new_line = raw_input(ps1)
890 while new_line.endswith('\\'):
913 while new_line.endswith('\\'):
891 new_line = new_line[:-1] + raw_input(ps2)
914 new_line = new_line[:-1] + raw_input(ps2)
892 lines.append(new_line)
915 lines.append(new_line)
893
916
894 return lines[:-1] # don't return the termination command
917 return lines[:-1] # don't return the termination command
895 except EOFError:
918 except EOFError:
896 print
919 print
897 return lines
920 return lines
898
921
899 #----------------------------------------------------------------------------
922 #----------------------------------------------------------------------------
900 def raw_input_ext(prompt='', ps2='... '):
923 def raw_input_ext(prompt='', ps2='... '):
901 """Similar to raw_input(), but accepts extended lines if input ends with \\."""
924 """Similar to raw_input(), but accepts extended lines if input ends with \\."""
902
925
903 line = raw_input(prompt)
926 line = raw_input(prompt)
904 while line.endswith('\\'):
927 while line.endswith('\\'):
905 line = line[:-1] + raw_input(ps2)
928 line = line[:-1] + raw_input(ps2)
906 return line
929 return line
907
930
908 #----------------------------------------------------------------------------
931 #----------------------------------------------------------------------------
909 def ask_yes_no(prompt,default=None):
932 def ask_yes_no(prompt,default=None):
910 """Asks a question and returns an integer 1/0 (y/n) answer.
933 """Asks a question and returns an integer 1/0 (y/n) answer.
911
934
912 If default is given (one of 'y','n'), it is used if the user input is
935 If default is given (one of 'y','n'), it is used if the user input is
913 empty. Otherwise the question is repeated until an answer is given.
936 empty. Otherwise the question is repeated until an answer is given.
914 If EOF occurs 20 times consecutively, the default answer is assumed,
937 If EOF occurs 20 times consecutively, the default answer is assumed,
915 or if there is no default, an exception is raised to prevent infinite
938 or if there is no default, an exception is raised to prevent infinite
916 loops.
939 loops.
917
940
918 Valid answers are: y/yes/n/no (match is not case sensitive)."""
941 Valid answers are: y/yes/n/no (match is not case sensitive)."""
919
942
920 answers = {'y':1,'n':0,'yes':1,'no':0}
943 answers = {'y':1,'n':0,'yes':1,'no':0}
921 ans = None
944 ans = None
922 eofs, max_eofs = 0, 20
945 eofs, max_eofs = 0, 20
923 while ans not in answers.keys():
946 while ans not in answers.keys():
924 try:
947 try:
925 ans = raw_input(prompt+' ').lower()
948 ans = raw_input(prompt+' ').lower()
926 if not ans: # response was an empty string
949 if not ans: # response was an empty string
927 ans = default
950 ans = default
928 eofs = 0
951 eofs = 0
929 except (EOFError,KeyboardInterrupt):
952 except (EOFError,KeyboardInterrupt):
930 eofs = eofs + 1
953 eofs = eofs + 1
931 if eofs >= max_eofs:
954 if eofs >= max_eofs:
932 if default in answers.keys():
955 if default in answers.keys():
933 ans = default
956 ans = default
934 else:
957 else:
935 raise
958 raise
936
959
937 return answers[ans]
960 return answers[ans]
938
961
939 #----------------------------------------------------------------------------
962 #----------------------------------------------------------------------------
940 def marquee(txt='',width=80,mark='*'):
963 def marquee(txt='',width=78,mark='*'):
941 """Return the input string centered in a 'marquee'."""
964 """Return the input string centered in a 'marquee'."""
942 if not txt:
965 if not txt:
943 return (mark*width)[:width]
966 return (mark*width)[:width]
944 nmark = (width-len(txt)-2)/len(mark)/2
967 nmark = (width-len(txt)-2)/len(mark)/2
945 if nmark < 0: nmark =0
968 if nmark < 0: nmark =0
946 marks = mark*nmark
969 marks = mark*nmark
947 return '%s %s %s' % (marks,txt,marks)
970 return '%s %s %s' % (marks,txt,marks)
948
971
949 #----------------------------------------------------------------------------
972 #----------------------------------------------------------------------------
950 class EvalDict:
973 class EvalDict:
951 """
974 """
952 Emulate a dict which evaluates its contents in the caller's frame.
975 Emulate a dict which evaluates its contents in the caller's frame.
953
976
954 Usage:
977 Usage:
955 >>>number = 19
978 >>>number = 19
956 >>>text = "python"
979 >>>text = "python"
957 >>>print "%(text.capitalize())s %(number/9.0).1f rules!" % EvalDict()
980 >>>print "%(text.capitalize())s %(number/9.0).1f rules!" % EvalDict()
958 """
981 """
959
982
960 # This version is due to sismex01@hebmex.com on c.l.py, and is basically a
983 # This version is due to sismex01@hebmex.com on c.l.py, and is basically a
961 # modified (shorter) version of:
984 # modified (shorter) version of:
962 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66018 by
985 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66018 by
963 # Skip Montanaro (skip@pobox.com).
986 # Skip Montanaro (skip@pobox.com).
964
987
965 def __getitem__(self, name):
988 def __getitem__(self, name):
966 frame = sys._getframe(1)
989 frame = sys._getframe(1)
967 return eval(name, frame.f_globals, frame.f_locals)
990 return eval(name, frame.f_globals, frame.f_locals)
968
991
969 EvalString = EvalDict # for backwards compatibility
992 EvalString = EvalDict # for backwards compatibility
970 #----------------------------------------------------------------------------
993 #----------------------------------------------------------------------------
971 def qw(words,flat=0,sep=None,maxsplit=-1):
994 def qw(words,flat=0,sep=None,maxsplit=-1):
972 """Similar to Perl's qw() operator, but with some more options.
995 """Similar to Perl's qw() operator, but with some more options.
973
996
974 qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit)
997 qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit)
975
998
976 words can also be a list itself, and with flat=1, the output will be
999 words can also be a list itself, and with flat=1, the output will be
977 recursively flattened. Examples:
1000 recursively flattened. Examples:
978
1001
979 >>> qw('1 2')
1002 >>> qw('1 2')
980 ['1', '2']
1003 ['1', '2']
981 >>> qw(['a b','1 2',['m n','p q']])
1004 >>> qw(['a b','1 2',['m n','p q']])
982 [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]]
1005 [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]]
983 >>> qw(['a b','1 2',['m n','p q']],flat=1)
1006 >>> qw(['a b','1 2',['m n','p q']],flat=1)
984 ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """
1007 ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """
985
1008
986 if type(words) in StringTypes:
1009 if type(words) in StringTypes:
987 return [word.strip() for word in words.split(sep,maxsplit)
1010 return [word.strip() for word in words.split(sep,maxsplit)
988 if word and not word.isspace() ]
1011 if word and not word.isspace() ]
989 if flat:
1012 if flat:
990 return flatten(map(qw,words,[1]*len(words)))
1013 return flatten(map(qw,words,[1]*len(words)))
991 return map(qw,words)
1014 return map(qw,words)
992
1015
993 #----------------------------------------------------------------------------
1016 #----------------------------------------------------------------------------
994 def qwflat(words,sep=None,maxsplit=-1):
1017 def qwflat(words,sep=None,maxsplit=-1):
995 """Calls qw(words) in flat mode. It's just a convenient shorthand."""
1018 """Calls qw(words) in flat mode. It's just a convenient shorthand."""
996 return qw(words,1,sep,maxsplit)
1019 return qw(words,1,sep,maxsplit)
997
1020
998 #-----------------------------------------------------------------------------
1021 #-----------------------------------------------------------------------------
999 def list_strings(arg):
1022 def list_strings(arg):
1000 """Always return a list of strings, given a string or list of strings
1023 """Always return a list of strings, given a string or list of strings
1001 as input."""
1024 as input."""
1002
1025
1003 if type(arg) in StringTypes: return [arg]
1026 if type(arg) in StringTypes: return [arg]
1004 else: return arg
1027 else: return arg
1005
1028
1006 #----------------------------------------------------------------------------
1029 #----------------------------------------------------------------------------
1007 def grep(pat,list,case=1):
1030 def grep(pat,list,case=1):
1008 """Simple minded grep-like function.
1031 """Simple minded grep-like function.
1009 grep(pat,list) returns occurrences of pat in list, None on failure.
1032 grep(pat,list) returns occurrences of pat in list, None on failure.
1010
1033
1011 It only does simple string matching, with no support for regexps. Use the
1034 It only does simple string matching, with no support for regexps. Use the
1012 option case=0 for case-insensitive matching."""
1035 option case=0 for case-insensitive matching."""
1013
1036
1014 # This is pretty crude. At least it should implement copying only references
1037 # This is pretty crude. At least it should implement copying only references
1015 # to the original data in case it's big. Now it copies the data for output.
1038 # to the original data in case it's big. Now it copies the data for output.
1016 out=[]
1039 out=[]
1017 if case:
1040 if case:
1018 for term in list:
1041 for term in list:
1019 if term.find(pat)>-1: out.append(term)
1042 if term.find(pat)>-1: out.append(term)
1020 else:
1043 else:
1021 lpat=pat.lower()
1044 lpat=pat.lower()
1022 for term in list:
1045 for term in list:
1023 if term.lower().find(lpat)>-1: out.append(term)
1046 if term.lower().find(lpat)>-1: out.append(term)
1024
1047
1025 if len(out): return out
1048 if len(out): return out
1026 else: return None
1049 else: return None
1027
1050
1028 #----------------------------------------------------------------------------
1051 #----------------------------------------------------------------------------
1029 def dgrep(pat,*opts):
1052 def dgrep(pat,*opts):
1030 """Return grep() on dir()+dir(__builtins__).
1053 """Return grep() on dir()+dir(__builtins__).
1031
1054
1032 A very common use of grep() when working interactively."""
1055 A very common use of grep() when working interactively."""
1033
1056
1034 return grep(pat,dir(__main__)+dir(__main__.__builtins__),*opts)
1057 return grep(pat,dir(__main__)+dir(__main__.__builtins__),*opts)
1035
1058
1036 #----------------------------------------------------------------------------
1059 #----------------------------------------------------------------------------
1037 def idgrep(pat):
1060 def idgrep(pat):
1038 """Case-insensitive dgrep()"""
1061 """Case-insensitive dgrep()"""
1039
1062
1040 return dgrep(pat,0)
1063 return dgrep(pat,0)
1041
1064
1042 #----------------------------------------------------------------------------
1065 #----------------------------------------------------------------------------
1043 def igrep(pat,list):
1066 def igrep(pat,list):
1044 """Synonym for case-insensitive grep."""
1067 """Synonym for case-insensitive grep."""
1045
1068
1046 return grep(pat,list,case=0)
1069 return grep(pat,list,case=0)
1047
1070
1048 #----------------------------------------------------------------------------
1071 #----------------------------------------------------------------------------
1049 def indent(str,nspaces=4,ntabs=0):
1072 def indent(str,nspaces=4,ntabs=0):
1050 """Indent a string a given number of spaces or tabstops.
1073 """Indent a string a given number of spaces or tabstops.
1051
1074
1052 indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces.
1075 indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces.
1053 """
1076 """
1054 if str is None:
1077 if str is None:
1055 return
1078 return
1056 ind = '\t'*ntabs+' '*nspaces
1079 ind = '\t'*ntabs+' '*nspaces
1057 outstr = '%s%s' % (ind,str.replace(os.linesep,os.linesep+ind))
1080 outstr = '%s%s' % (ind,str.replace(os.linesep,os.linesep+ind))
1058 if outstr.endswith(os.linesep+ind):
1081 if outstr.endswith(os.linesep+ind):
1059 return outstr[:-len(ind)]
1082 return outstr[:-len(ind)]
1060 else:
1083 else:
1061 return outstr
1084 return outstr
1062
1085
1063 #-----------------------------------------------------------------------------
1086 #-----------------------------------------------------------------------------
1064 def native_line_ends(filename,backup=1):
1087 def native_line_ends(filename,backup=1):
1065 """Convert (in-place) a file to line-ends native to the current OS.
1088 """Convert (in-place) a file to line-ends native to the current OS.
1066
1089
1067 If the optional backup argument is given as false, no backup of the
1090 If the optional backup argument is given as false, no backup of the
1068 original file is left. """
1091 original file is left. """
1069
1092
1070 backup_suffixes = {'posix':'~','dos':'.bak','nt':'.bak','mac':'.bak'}
1093 backup_suffixes = {'posix':'~','dos':'.bak','nt':'.bak','mac':'.bak'}
1071
1094
1072 bak_filename = filename + backup_suffixes[os.name]
1095 bak_filename = filename + backup_suffixes[os.name]
1073
1096
1074 original = open(filename).read()
1097 original = open(filename).read()
1075 shutil.copy2(filename,bak_filename)
1098 shutil.copy2(filename,bak_filename)
1076 try:
1099 try:
1077 new = open(filename,'wb')
1100 new = open(filename,'wb')
1078 new.write(os.linesep.join(original.splitlines()))
1101 new.write(os.linesep.join(original.splitlines()))
1079 new.write(os.linesep) # ALWAYS put an eol at the end of the file
1102 new.write(os.linesep) # ALWAYS put an eol at the end of the file
1080 new.close()
1103 new.close()
1081 except:
1104 except:
1082 os.rename(bak_filename,filename)
1105 os.rename(bak_filename,filename)
1083 if not backup:
1106 if not backup:
1084 try:
1107 try:
1085 os.remove(bak_filename)
1108 os.remove(bak_filename)
1086 except:
1109 except:
1087 pass
1110 pass
1088
1111
1089 #----------------------------------------------------------------------------
1112 #----------------------------------------------------------------------------
1090 def get_pager_cmd(pager_cmd = None):
1113 def get_pager_cmd(pager_cmd = None):
1091 """Return a pager command.
1114 """Return a pager command.
1092
1115
1093 Makes some attempts at finding an OS-correct one."""
1116 Makes some attempts at finding an OS-correct one."""
1094
1117
1095 if os.name == 'posix':
1118 if os.name == 'posix':
1096 default_pager_cmd = 'less -r' # -r for color control sequences
1119 default_pager_cmd = 'less -r' # -r for color control sequences
1097 elif os.name in ['nt','dos']:
1120 elif os.name in ['nt','dos']:
1098 default_pager_cmd = 'type'
1121 default_pager_cmd = 'type'
1099
1122
1100 if pager_cmd is None:
1123 if pager_cmd is None:
1101 try:
1124 try:
1102 pager_cmd = os.environ['PAGER']
1125 pager_cmd = os.environ['PAGER']
1103 except:
1126 except:
1104 pager_cmd = default_pager_cmd
1127 pager_cmd = default_pager_cmd
1105 return pager_cmd
1128 return pager_cmd
1106
1129
1107 #-----------------------------------------------------------------------------
1130 #-----------------------------------------------------------------------------
1108 def get_pager_start(pager,start):
1131 def get_pager_start(pager,start):
1109 """Return the string for paging files with an offset.
1132 """Return the string for paging files with an offset.
1110
1133
1111 This is the '+N' argument which less and more (under Unix) accept.
1134 This is the '+N' argument which less and more (under Unix) accept.
1112 """
1135 """
1113
1136
1114 if pager in ['less','more']:
1137 if pager in ['less','more']:
1115 if start:
1138 if start:
1116 start_string = '+' + str(start)
1139 start_string = '+' + str(start)
1117 else:
1140 else:
1118 start_string = ''
1141 start_string = ''
1119 else:
1142 else:
1120 start_string = ''
1143 start_string = ''
1121 return start_string
1144 return start_string
1122
1145
1123 #----------------------------------------------------------------------------
1146 #----------------------------------------------------------------------------
1124 def page_dumb(strng,start=0,screen_lines=25):
1147 def page_dumb(strng,start=0,screen_lines=25):
1125 """Very dumb 'pager' in Python, for when nothing else works.
1148 """Very dumb 'pager' in Python, for when nothing else works.
1126
1149
1127 Only moves forward, same interface as page(), except for pager_cmd and
1150 Only moves forward, same interface as page(), except for pager_cmd and
1128 mode."""
1151 mode."""
1129
1152
1130 out_ln = strng.splitlines()[start:]
1153 out_ln = strng.splitlines()[start:]
1131 screens = chop(out_ln,screen_lines-1)
1154 screens = chop(out_ln,screen_lines-1)
1132 if len(screens) == 1:
1155 if len(screens) == 1:
1133 print >>Term.cout, os.linesep.join(screens[0])
1156 print >>Term.cout, os.linesep.join(screens[0])
1134 else:
1157 else:
1135 for scr in screens[0:-1]:
1158 for scr in screens[0:-1]:
1136 print >>Term.cout, os.linesep.join(scr)
1159 print >>Term.cout, os.linesep.join(scr)
1137 ans = raw_input('---Return to continue, q to quit--- ')
1160 ans = raw_input('---Return to continue, q to quit--- ')
1138 if ans.lower().startswith('q'):
1161 if ans.lower().startswith('q'):
1139 return
1162 return
1140 print >>Term.cout, os.linesep.join(screens[-1])
1163 print >>Term.cout, os.linesep.join(screens[-1])
1141
1164
1142 #----------------------------------------------------------------------------
1165 #----------------------------------------------------------------------------
1143 def page(strng,start=0,screen_lines=0,pager_cmd = None):
1166 def page(strng,start=0,screen_lines=0,pager_cmd = None):
1144 """Print a string, piping through a pager after a certain length.
1167 """Print a string, piping through a pager after a certain length.
1145
1168
1146 The screen_lines parameter specifies the number of *usable* lines of your
1169 The screen_lines parameter specifies the number of *usable* lines of your
1147 terminal screen (total lines minus lines you need to reserve to show other
1170 terminal screen (total lines minus lines you need to reserve to show other
1148 information).
1171 information).
1149
1172
1150 If you set screen_lines to a number <=0, page() will try to auto-determine
1173 If you set screen_lines to a number <=0, page() will try to auto-determine
1151 your screen size and will only use up to (screen_size+screen_lines) for
1174 your screen size and will only use up to (screen_size+screen_lines) for
1152 printing, paging after that. That is, if you want auto-detection but need
1175 printing, paging after that. That is, if you want auto-detection but need
1153 to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for
1176 to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for
1154 auto-detection without any lines reserved simply use screen_lines = 0.
1177 auto-detection without any lines reserved simply use screen_lines = 0.
1155
1178
1156 If a string won't fit in the allowed lines, it is sent through the
1179 If a string won't fit in the allowed lines, it is sent through the
1157 specified pager command. If none given, look for PAGER in the environment,
1180 specified pager command. If none given, look for PAGER in the environment,
1158 and ultimately default to less.
1181 and ultimately default to less.
1159
1182
1160 If no system pager works, the string is sent through a 'dumb pager'
1183 If no system pager works, the string is sent through a 'dumb pager'
1161 written in python, very simplistic.
1184 written in python, very simplistic.
1162 """
1185 """
1163
1186
1164 # Ugly kludge, but calling curses.initscr() flat out crashes in emacs
1187 # Ugly kludge, but calling curses.initscr() flat out crashes in emacs
1165 TERM = os.environ.get('TERM','dumb')
1188 TERM = os.environ.get('TERM','dumb')
1166 if TERM in ['dumb','emacs'] and os.name != 'nt':
1189 if TERM in ['dumb','emacs'] and os.name != 'nt':
1167 print strng
1190 print strng
1168 return
1191 return
1169 # chop off the topmost part of the string we don't want to see
1192 # chop off the topmost part of the string we don't want to see
1170 str_lines = strng.split(os.linesep)[start:]
1193 str_lines = strng.split(os.linesep)[start:]
1171 str_toprint = os.linesep.join(str_lines)
1194 str_toprint = os.linesep.join(str_lines)
1172 num_newlines = len(str_lines)
1195 num_newlines = len(str_lines)
1173 len_str = len(str_toprint)
1196 len_str = len(str_toprint)
1174
1197
1175 # Dumb heuristics to guesstimate number of on-screen lines the string
1198 # Dumb heuristics to guesstimate number of on-screen lines the string
1176 # takes. Very basic, but good enough for docstrings in reasonable
1199 # takes. Very basic, but good enough for docstrings in reasonable
1177 # terminals. If someone later feels like refining it, it's not hard.
1200 # terminals. If someone later feels like refining it, it's not hard.
1178 numlines = max(num_newlines,int(len_str/80)+1)
1201 numlines = max(num_newlines,int(len_str/80)+1)
1179
1202
1180 screen_lines_def = 25 # default value if we can't auto-determine
1203 screen_lines_def = 25 # default value if we can't auto-determine
1181
1204
1182 # auto-determine screen size
1205 # auto-determine screen size
1183 if screen_lines <= 0:
1206 if screen_lines <= 0:
1184 if TERM=='xterm':
1207 if TERM=='xterm':
1185 try:
1208 try:
1186 import curses
1209 import curses
1187 if hasattr(curses,'initscr'):
1210 if hasattr(curses,'initscr'):
1188 use_curses = 1
1211 use_curses = 1
1189 else:
1212 else:
1190 use_curses = 0
1213 use_curses = 0
1191 except ImportError:
1214 except ImportError:
1192 use_curses = 0
1215 use_curses = 0
1193 else:
1216 else:
1194 # curses causes problems on many terminals other than xterm.
1217 # curses causes problems on many terminals other than xterm.
1195 use_curses = 0
1218 use_curses = 0
1196 if use_curses:
1219 if use_curses:
1197 scr = curses.initscr()
1220 scr = curses.initscr()
1198 screen_lines_real,screen_cols = scr.getmaxyx()
1221 screen_lines_real,screen_cols = scr.getmaxyx()
1199 curses.endwin()
1222 curses.endwin()
1200 screen_lines += screen_lines_real
1223 screen_lines += screen_lines_real
1201 #print '***Screen size:',screen_lines_real,'lines x',\
1224 #print '***Screen size:',screen_lines_real,'lines x',\
1202 #screen_cols,'columns.' # dbg
1225 #screen_cols,'columns.' # dbg
1203 else:
1226 else:
1204 screen_lines += screen_lines_def
1227 screen_lines += screen_lines_def
1205
1228
1206 #print 'numlines',numlines,'screenlines',screen_lines # dbg
1229 #print 'numlines',numlines,'screenlines',screen_lines # dbg
1207 if numlines <= screen_lines :
1230 if numlines <= screen_lines :
1208 #print '*** normal print' # dbg
1231 #print '*** normal print' # dbg
1209 print >>Term.cout, str_toprint
1232 print >>Term.cout, str_toprint
1210 else:
1233 else:
1211 # Try to open pager and default to internal one if that fails.
1234 # Try to open pager and default to internal one if that fails.
1212 # All failure modes are tagged as 'retval=1', to match the return
1235 # All failure modes are tagged as 'retval=1', to match the return
1213 # value of a failed system command. If any intermediate attempt
1236 # value of a failed system command. If any intermediate attempt
1214 # sets retval to 1, at the end we resort to our own page_dumb() pager.
1237 # sets retval to 1, at the end we resort to our own page_dumb() pager.
1215 pager_cmd = get_pager_cmd(pager_cmd)
1238 pager_cmd = get_pager_cmd(pager_cmd)
1216 pager_cmd += ' ' + get_pager_start(pager_cmd,start)
1239 pager_cmd += ' ' + get_pager_start(pager_cmd,start)
1217 if os.name == 'nt':
1240 if os.name == 'nt':
1218 if pager_cmd.startswith('type'):
1241 if pager_cmd.startswith('type'):
1219 # The default WinXP 'type' command is failing on complex strings.
1242 # The default WinXP 'type' command is failing on complex strings.
1220 retval = 1
1243 retval = 1
1221 else:
1244 else:
1222 tmpname = tempfile.mktemp('.txt')
1245 tmpname = tempfile.mktemp('.txt')
1223 tmpfile = file(tmpname,'wt')
1246 tmpfile = file(tmpname,'wt')
1224 tmpfile.write(strng)
1247 tmpfile.write(strng)
1225 tmpfile.close()
1248 tmpfile.close()
1226 cmd = "%s < %s" % (pager_cmd,tmpname)
1249 cmd = "%s < %s" % (pager_cmd,tmpname)
1227 if os.system(cmd):
1250 if os.system(cmd):
1228 retval = 1
1251 retval = 1
1229 else:
1252 else:
1230 retval = None
1253 retval = None
1231 os.remove(tmpname)
1254 os.remove(tmpname)
1232 else:
1255 else:
1233 try:
1256 try:
1234 retval = None
1257 retval = None
1235 # if I use popen4, things hang. No idea why.
1258 # if I use popen4, things hang. No idea why.
1236 #pager,shell_out = os.popen4(pager_cmd)
1259 #pager,shell_out = os.popen4(pager_cmd)
1237 pager = os.popen(pager_cmd,'w')
1260 pager = os.popen(pager_cmd,'w')
1238 pager.write(strng)
1261 pager.write(strng)
1239 pager.close()
1262 pager.close()
1240 retval = pager.close() # success returns None
1263 retval = pager.close() # success returns None
1241 except IOError,msg: # broken pipe when user quits
1264 except IOError,msg: # broken pipe when user quits
1242 if msg.args == (32,'Broken pipe'):
1265 if msg.args == (32,'Broken pipe'):
1243 retval = None
1266 retval = None
1244 else:
1267 else:
1245 retval = 1
1268 retval = 1
1246 except OSError:
1269 except OSError:
1247 # Other strange problems, sometimes seen in Win2k/cygwin
1270 # Other strange problems, sometimes seen in Win2k/cygwin
1248 retval = 1
1271 retval = 1
1249 if retval is not None:
1272 if retval is not None:
1250 page_dumb(strng,screen_lines=screen_lines)
1273 page_dumb(strng,screen_lines=screen_lines)
1251
1274
1252 #----------------------------------------------------------------------------
1275 #----------------------------------------------------------------------------
1253 def page_file(fname,start = 0, pager_cmd = None):
1276 def page_file(fname,start = 0, pager_cmd = None):
1254 """Page a file, using an optional pager command and starting line.
1277 """Page a file, using an optional pager command and starting line.
1255 """
1278 """
1256
1279
1257 pager_cmd = get_pager_cmd(pager_cmd)
1280 pager_cmd = get_pager_cmd(pager_cmd)
1258 pager_cmd += ' ' + get_pager_start(pager_cmd,start)
1281 pager_cmd += ' ' + get_pager_start(pager_cmd,start)
1259
1282
1260 try:
1283 try:
1261 if os.environ['TERM'] in ['emacs','dumb']:
1284 if os.environ['TERM'] in ['emacs','dumb']:
1262 raise EnvironmentError
1285 raise EnvironmentError
1263 xsys(pager_cmd + ' ' + fname)
1286 xsys(pager_cmd + ' ' + fname)
1264 except:
1287 except:
1265 try:
1288 try:
1266 if start > 0:
1289 if start > 0:
1267 start -= 1
1290 start -= 1
1268 page(open(fname).read(),start)
1291 page(open(fname).read(),start)
1269 except:
1292 except:
1270 print 'Unable to show file',`fname`
1293 print 'Unable to show file',`fname`
1271
1294
1272 #----------------------------------------------------------------------------
1295 #----------------------------------------------------------------------------
1273 def snip_print(str,width = 75,print_full = 0,header = ''):
1296 def snip_print(str,width = 75,print_full = 0,header = ''):
1274 """Print a string snipping the midsection to fit in width.
1297 """Print a string snipping the midsection to fit in width.
1275
1298
1276 print_full: mode control:
1299 print_full: mode control:
1277 - 0: only snip long strings
1300 - 0: only snip long strings
1278 - 1: send to page() directly.
1301 - 1: send to page() directly.
1279 - 2: snip long strings and ask for full length viewing with page()
1302 - 2: snip long strings and ask for full length viewing with page()
1280 Return 1 if snipping was necessary, 0 otherwise."""
1303 Return 1 if snipping was necessary, 0 otherwise."""
1281
1304
1282 if print_full == 1:
1305 if print_full == 1:
1283 page(header+str)
1306 page(header+str)
1284 return 0
1307 return 0
1285
1308
1286 print header,
1309 print header,
1287 if len(str) < width:
1310 if len(str) < width:
1288 print str
1311 print str
1289 snip = 0
1312 snip = 0
1290 else:
1313 else:
1291 whalf = int((width -5)/2)
1314 whalf = int((width -5)/2)
1292 print str[:whalf] + ' <...> ' + str[-whalf:]
1315 print str[:whalf] + ' <...> ' + str[-whalf:]
1293 snip = 1
1316 snip = 1
1294 if snip and print_full == 2:
1317 if snip and print_full == 2:
1295 if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y':
1318 if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y':
1296 page(str)
1319 page(str)
1297 return snip
1320 return snip
1298
1321
1299 #****************************************************************************
1322 #****************************************************************************
1300 # lists, dicts and structures
1323 # lists, dicts and structures
1301
1324
1302 def belong(candidates,checklist):
1325 def belong(candidates,checklist):
1303 """Check whether a list of items appear in a given list of options.
1326 """Check whether a list of items appear in a given list of options.
1304
1327
1305 Returns a list of 1 and 0, one for each candidate given."""
1328 Returns a list of 1 and 0, one for each candidate given."""
1306
1329
1307 return [x in checklist for x in candidates]
1330 return [x in checklist for x in candidates]
1308
1331
1309 #----------------------------------------------------------------------------
1332 #----------------------------------------------------------------------------
1310 def uniq_stable(elems):
1333 def uniq_stable(elems):
1311 """uniq_stable(elems) -> list
1334 """uniq_stable(elems) -> list
1312
1335
1313 Return from an iterable, a list of all the unique elements in the input,
1336 Return from an iterable, a list of all the unique elements in the input,
1314 but maintaining the order in which they first appear.
1337 but maintaining the order in which they first appear.
1315
1338
1316 A naive solution to this problem which just makes a dictionary with the
1339 A naive solution to this problem which just makes a dictionary with the
1317 elements as keys fails to respect the stability condition, since
1340 elements as keys fails to respect the stability condition, since
1318 dictionaries are unsorted by nature.
1341 dictionaries are unsorted by nature.
1319
1342
1320 Note: All elements in the input must be valid dictionary keys for this
1343 Note: All elements in the input must be valid dictionary keys for this
1321 routine to work, as it internally uses a dictionary for efficiency
1344 routine to work, as it internally uses a dictionary for efficiency
1322 reasons."""
1345 reasons."""
1323
1346
1324 unique = []
1347 unique = []
1325 unique_dict = {}
1348 unique_dict = {}
1326 for nn in elems:
1349 for nn in elems:
1327 if nn not in unique_dict:
1350 if nn not in unique_dict:
1328 unique.append(nn)
1351 unique.append(nn)
1329 unique_dict[nn] = None
1352 unique_dict[nn] = None
1330 return unique
1353 return unique
1331
1354
1332 #----------------------------------------------------------------------------
1355 #----------------------------------------------------------------------------
1333 class NLprinter:
1356 class NLprinter:
1334 """Print an arbitrarily nested list, indicating index numbers.
1357 """Print an arbitrarily nested list, indicating index numbers.
1335
1358
1336 An instance of this class called nlprint is available and callable as a
1359 An instance of this class called nlprint is available and callable as a
1337 function.
1360 function.
1338
1361
1339 nlprint(list,indent=' ',sep=': ') -> prints indenting each level by 'indent'
1362 nlprint(list,indent=' ',sep=': ') -> prints indenting each level by 'indent'
1340 and using 'sep' to separate the index from the value. """
1363 and using 'sep' to separate the index from the value. """
1341
1364
1342 def __init__(self):
1365 def __init__(self):
1343 self.depth = 0
1366 self.depth = 0
1344
1367
1345 def __call__(self,lst,pos='',**kw):
1368 def __call__(self,lst,pos='',**kw):
1346 """Prints the nested list numbering levels."""
1369 """Prints the nested list numbering levels."""
1347 kw.setdefault('indent',' ')
1370 kw.setdefault('indent',' ')
1348 kw.setdefault('sep',': ')
1371 kw.setdefault('sep',': ')
1349 kw.setdefault('start',0)
1372 kw.setdefault('start',0)
1350 kw.setdefault('stop',len(lst))
1373 kw.setdefault('stop',len(lst))
1351 # we need to remove start and stop from kw so they don't propagate
1374 # we need to remove start and stop from kw so they don't propagate
1352 # into a recursive call for a nested list.
1375 # into a recursive call for a nested list.
1353 start = kw['start']; del kw['start']
1376 start = kw['start']; del kw['start']
1354 stop = kw['stop']; del kw['stop']
1377 stop = kw['stop']; del kw['stop']
1355 if self.depth == 0 and 'header' in kw.keys():
1378 if self.depth == 0 and 'header' in kw.keys():
1356 print kw['header']
1379 print kw['header']
1357
1380
1358 for idx in range(start,stop):
1381 for idx in range(start,stop):
1359 elem = lst[idx]
1382 elem = lst[idx]
1360 if type(elem)==type([]):
1383 if type(elem)==type([]):
1361 self.depth += 1
1384 self.depth += 1
1362 self.__call__(elem,itpl('$pos$idx,'),**kw)
1385 self.__call__(elem,itpl('$pos$idx,'),**kw)
1363 self.depth -= 1
1386 self.depth -= 1
1364 else:
1387 else:
1365 printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem')
1388 printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem')
1366
1389
1367 nlprint = NLprinter()
1390 nlprint = NLprinter()
1368 #----------------------------------------------------------------------------
1391 #----------------------------------------------------------------------------
1369 def all_belong(candidates,checklist):
1392 def all_belong(candidates,checklist):
1370 """Check whether a list of items ALL appear in a given list of options.
1393 """Check whether a list of items ALL appear in a given list of options.
1371
1394
1372 Returns a single 1 or 0 value."""
1395 Returns a single 1 or 0 value."""
1373
1396
1374 return 1-(0 in [x in checklist for x in candidates])
1397 return 1-(0 in [x in checklist for x in candidates])
1375
1398
1376 #----------------------------------------------------------------------------
1399 #----------------------------------------------------------------------------
1377 def sort_compare(lst1,lst2,inplace = 1):
1400 def sort_compare(lst1,lst2,inplace = 1):
1378 """Sort and compare two lists.
1401 """Sort and compare two lists.
1379
1402
1380 By default it does it in place, thus modifying the lists. Use inplace = 0
1403 By default it does it in place, thus modifying the lists. Use inplace = 0
1381 to avoid that (at the cost of temporary copy creation)."""
1404 to avoid that (at the cost of temporary copy creation)."""
1382 if not inplace:
1405 if not inplace:
1383 lst1 = lst1[:]
1406 lst1 = lst1[:]
1384 lst2 = lst2[:]
1407 lst2 = lst2[:]
1385 lst1.sort(); lst2.sort()
1408 lst1.sort(); lst2.sort()
1386 return lst1 == lst2
1409 return lst1 == lst2
1387
1410
1388 #----------------------------------------------------------------------------
1411 #----------------------------------------------------------------------------
1389 def mkdict(**kwargs):
1412 def mkdict(**kwargs):
1390 """Return a dict from a keyword list.
1413 """Return a dict from a keyword list.
1391
1414
1392 It's just syntactic sugar for making ditcionary creation more convenient:
1415 It's just syntactic sugar for making ditcionary creation more convenient:
1393 # the standard way
1416 # the standard way
1394 >>>data = { 'red' : 1, 'green' : 2, 'blue' : 3 }
1417 >>>data = { 'red' : 1, 'green' : 2, 'blue' : 3 }
1395 # a cleaner way
1418 # a cleaner way
1396 >>>data = dict(red=1, green=2, blue=3)
1419 >>>data = dict(red=1, green=2, blue=3)
1397
1420
1398 If you need more than this, look at the Struct() class."""
1421 If you need more than this, look at the Struct() class."""
1399
1422
1400 return kwargs
1423 return kwargs
1401
1424
1402 #----------------------------------------------------------------------------
1425 #----------------------------------------------------------------------------
1403 def list2dict(lst):
1426 def list2dict(lst):
1404 """Takes a list of (key,value) pairs and turns it into a dict."""
1427 """Takes a list of (key,value) pairs and turns it into a dict."""
1405
1428
1406 dic = {}
1429 dic = {}
1407 for k,v in lst: dic[k] = v
1430 for k,v in lst: dic[k] = v
1408 return dic
1431 return dic
1409
1432
1410 #----------------------------------------------------------------------------
1433 #----------------------------------------------------------------------------
1411 def list2dict2(lst,default=''):
1434 def list2dict2(lst,default=''):
1412 """Takes a list and turns it into a dict.
1435 """Takes a list and turns it into a dict.
1413 Much slower than list2dict, but more versatile. This version can take
1436 Much slower than list2dict, but more versatile. This version can take
1414 lists with sublists of arbitrary length (including sclars)."""
1437 lists with sublists of arbitrary length (including sclars)."""
1415
1438
1416 dic = {}
1439 dic = {}
1417 for elem in lst:
1440 for elem in lst:
1418 if type(elem) in (types.ListType,types.TupleType):
1441 if type(elem) in (types.ListType,types.TupleType):
1419 size = len(elem)
1442 size = len(elem)
1420 if size == 0:
1443 if size == 0:
1421 pass
1444 pass
1422 elif size == 1:
1445 elif size == 1:
1423 dic[elem] = default
1446 dic[elem] = default
1424 else:
1447 else:
1425 k,v = elem[0], elem[1:]
1448 k,v = elem[0], elem[1:]
1426 if len(v) == 1: v = v[0]
1449 if len(v) == 1: v = v[0]
1427 dic[k] = v
1450 dic[k] = v
1428 else:
1451 else:
1429 dic[elem] = default
1452 dic[elem] = default
1430 return dic
1453 return dic
1431
1454
1432 #----------------------------------------------------------------------------
1455 #----------------------------------------------------------------------------
1433 def flatten(seq):
1456 def flatten(seq):
1434 """Flatten a list of lists (NOT recursive, only works for 2d lists)."""
1457 """Flatten a list of lists (NOT recursive, only works for 2d lists)."""
1435
1458
1436 # bug in python??? (YES. Fixed in 2.2, let's leave the kludgy fix in).
1459 # bug in python??? (YES. Fixed in 2.2, let's leave the kludgy fix in).
1437
1460
1438 # if the x=0 isn't made, a *global* variable x is left over after calling
1461 # if the x=0 isn't made, a *global* variable x is left over after calling
1439 # this function, with the value of the last element in the return
1462 # this function, with the value of the last element in the return
1440 # list. This does seem like a bug big time to me.
1463 # list. This does seem like a bug big time to me.
1441
1464
1442 # the problem is fixed with the x=0, which seems to force the creation of
1465 # the problem is fixed with the x=0, which seems to force the creation of
1443 # a local name
1466 # a local name
1444
1467
1445 x = 0
1468 x = 0
1446 return [x for subseq in seq for x in subseq]
1469 return [x for subseq in seq for x in subseq]
1447
1470
1448 #----------------------------------------------------------------------------
1471 #----------------------------------------------------------------------------
1449 def get_slice(seq,start=0,stop=None,step=1):
1472 def get_slice(seq,start=0,stop=None,step=1):
1450 """Get a slice of a sequence with variable step. Specify start,stop,step."""
1473 """Get a slice of a sequence with variable step. Specify start,stop,step."""
1451 if stop == None:
1474 if stop == None:
1452 stop = len(seq)
1475 stop = len(seq)
1453 item = lambda i: seq[i]
1476 item = lambda i: seq[i]
1454 return map(item,xrange(start,stop,step))
1477 return map(item,xrange(start,stop,step))
1455
1478
1456 #----------------------------------------------------------------------------
1479 #----------------------------------------------------------------------------
1457 def chop(seq,size):
1480 def chop(seq,size):
1458 """Chop a sequence into chunks of the given size."""
1481 """Chop a sequence into chunks of the given size."""
1459 chunk = lambda i: seq[i:i+size]
1482 chunk = lambda i: seq[i:i+size]
1460 return map(chunk,xrange(0,len(seq),size))
1483 return map(chunk,xrange(0,len(seq),size))
1461
1484
1462 #----------------------------------------------------------------------------
1485 #----------------------------------------------------------------------------
1463 def with(object, **args):
1486 def with(object, **args):
1464 """Set multiple attributes for an object, similar to Pascal's with.
1487 """Set multiple attributes for an object, similar to Pascal's with.
1465
1488
1466 Example:
1489 Example:
1467 with(jim,
1490 with(jim,
1468 born = 1960,
1491 born = 1960,
1469 haircolour = 'Brown',
1492 haircolour = 'Brown',
1470 eyecolour = 'Green')
1493 eyecolour = 'Green')
1471
1494
1472 Credit: Greg Ewing, in
1495 Credit: Greg Ewing, in
1473 http://mail.python.org/pipermail/python-list/2001-May/040703.html"""
1496 http://mail.python.org/pipermail/python-list/2001-May/040703.html"""
1474
1497
1475 object.__dict__.update(args)
1498 object.__dict__.update(args)
1476
1499
1477 #----------------------------------------------------------------------------
1500 #----------------------------------------------------------------------------
1478 def setattr_list(obj,alist,nspace = None):
1501 def setattr_list(obj,alist,nspace = None):
1479 """Set a list of attributes for an object taken from a namespace.
1502 """Set a list of attributes for an object taken from a namespace.
1480
1503
1481 setattr_list(obj,alist,nspace) -> sets in obj all the attributes listed in
1504 setattr_list(obj,alist,nspace) -> sets in obj all the attributes listed in
1482 alist with their values taken from nspace, which must be a dict (something
1505 alist with their values taken from nspace, which must be a dict (something
1483 like locals() will often do) If nspace isn't given, locals() of the
1506 like locals() will often do) If nspace isn't given, locals() of the
1484 *caller* is used, so in most cases you can omit it.
1507 *caller* is used, so in most cases you can omit it.
1485
1508
1486 Note that alist can be given as a string, which will be automatically
1509 Note that alist can be given as a string, which will be automatically
1487 split into a list on whitespace. If given as a list, it must be a list of
1510 split into a list on whitespace. If given as a list, it must be a list of
1488 *strings* (the variable names themselves), not of variables."""
1511 *strings* (the variable names themselves), not of variables."""
1489
1512
1490 # this grabs the local variables from the *previous* call frame -- that is
1513 # this grabs the local variables from the *previous* call frame -- that is
1491 # the locals from the function that called setattr_list().
1514 # the locals from the function that called setattr_list().
1492 # - snipped from weave.inline()
1515 # - snipped from weave.inline()
1493 if nspace is None:
1516 if nspace is None:
1494 call_frame = sys._getframe().f_back
1517 call_frame = sys._getframe().f_back
1495 nspace = call_frame.f_locals
1518 nspace = call_frame.f_locals
1496
1519
1497 if type(alist) in StringTypes:
1520 if type(alist) in StringTypes:
1498 alist = alist.split()
1521 alist = alist.split()
1499 for attr in alist:
1522 for attr in alist:
1500 val = eval(attr,nspace)
1523 val = eval(attr,nspace)
1501 setattr(obj,attr,val)
1524 setattr(obj,attr,val)
1502
1525
1503 #----------------------------------------------------------------------------
1526 #----------------------------------------------------------------------------
1504 def getattr_list(obj,alist,*args):
1527 def getattr_list(obj,alist,*args):
1505 """getattr_list(obj,alist[, default]) -> attribute list.
1528 """getattr_list(obj,alist[, default]) -> attribute list.
1506
1529
1507 Get a list of named attributes for an object. When a default argument is
1530 Get a list of named attributes for an object. When a default argument is
1508 given, it is returned when the attribute doesn't exist; without it, an
1531 given, it is returned when the attribute doesn't exist; without it, an
1509 exception is raised in that case.
1532 exception is raised in that case.
1510
1533
1511 Note that alist can be given as a string, which will be automatically
1534 Note that alist can be given as a string, which will be automatically
1512 split into a list on whitespace. If given as a list, it must be a list of
1535 split into a list on whitespace. If given as a list, it must be a list of
1513 *strings* (the variable names themselves), not of variables."""
1536 *strings* (the variable names themselves), not of variables."""
1514
1537
1515 if type(alist) in StringTypes:
1538 if type(alist) in StringTypes:
1516 alist = alist.split()
1539 alist = alist.split()
1517 if args:
1540 if args:
1518 if len(args)==1:
1541 if len(args)==1:
1519 default = args[0]
1542 default = args[0]
1520 return map(lambda attr: getattr(obj,attr,default),alist)
1543 return map(lambda attr: getattr(obj,attr,default),alist)
1521 else:
1544 else:
1522 raise ValueError,'getattr_list() takes only one optional argument'
1545 raise ValueError,'getattr_list() takes only one optional argument'
1523 else:
1546 else:
1524 return map(lambda attr: getattr(obj,attr),alist)
1547 return map(lambda attr: getattr(obj,attr),alist)
1525
1548
1526 #----------------------------------------------------------------------------
1549 #----------------------------------------------------------------------------
1527 def map_method(method,object_list,*argseq,**kw):
1550 def map_method(method,object_list,*argseq,**kw):
1528 """map_method(method,object_list,*args,**kw) -> list
1551 """map_method(method,object_list,*args,**kw) -> list
1529
1552
1530 Return a list of the results of applying the methods to the items of the
1553 Return a list of the results of applying the methods to the items of the
1531 argument sequence(s). If more than one sequence is given, the method is
1554 argument sequence(s). If more than one sequence is given, the method is
1532 called with an argument list consisting of the corresponding item of each
1555 called with an argument list consisting of the corresponding item of each
1533 sequence. All sequences must be of the same length.
1556 sequence. All sequences must be of the same length.
1534
1557
1535 Keyword arguments are passed verbatim to all objects called.
1558 Keyword arguments are passed verbatim to all objects called.
1536
1559
1537 This is Python code, so it's not nearly as fast as the builtin map()."""
1560 This is Python code, so it's not nearly as fast as the builtin map()."""
1538
1561
1539 out_list = []
1562 out_list = []
1540 idx = 0
1563 idx = 0
1541 for object in object_list:
1564 for object in object_list:
1542 try:
1565 try:
1543 handler = getattr(object, method)
1566 handler = getattr(object, method)
1544 except AttributeError:
1567 except AttributeError:
1545 out_list.append(None)
1568 out_list.append(None)
1546 else:
1569 else:
1547 if argseq:
1570 if argseq:
1548 args = map(lambda lst:lst[idx],argseq)
1571 args = map(lambda lst:lst[idx],argseq)
1549 #print 'ob',object,'hand',handler,'ar',args # dbg
1572 #print 'ob',object,'hand',handler,'ar',args # dbg
1550 out_list.append(handler(args,**kw))
1573 out_list.append(handler(args,**kw))
1551 else:
1574 else:
1552 out_list.append(handler(**kw))
1575 out_list.append(handler(**kw))
1553 idx += 1
1576 idx += 1
1554 return out_list
1577 return out_list
1555
1578
1556 #----------------------------------------------------------------------------
1579 #----------------------------------------------------------------------------
1557 # Proposed popitem() extension, written as a method
1580 # Proposed popitem() extension, written as a method
1558
1581
1559 class NotGiven: pass
1582 class NotGiven: pass
1560
1583
1561 def popkey(dct,key,default=NotGiven):
1584 def popkey(dct,key,default=NotGiven):
1562 """Return dct[key] and delete dct[key].
1585 """Return dct[key] and delete dct[key].
1563
1586
1564 If default is given, return it if dct[key] doesn't exist, otherwise raise
1587 If default is given, return it if dct[key] doesn't exist, otherwise raise
1565 KeyError. """
1588 KeyError. """
1566
1589
1567 try:
1590 try:
1568 val = dct[key]
1591 val = dct[key]
1569 except KeyError:
1592 except KeyError:
1570 if default is NotGiven:
1593 if default is NotGiven:
1571 raise
1594 raise
1572 else:
1595 else:
1573 return default
1596 return default
1574 else:
1597 else:
1575 del dct[key]
1598 del dct[key]
1576 return val
1599 return val
1577 #*************************** end of file <genutils.py> **********************
1600 #*************************** end of file <genutils.py> **********************
1578
1601
@@ -1,2047 +1,2052 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 IPython -- An enhanced Interactive Python
3 IPython -- An enhanced Interactive Python
4
4
5 Requires Python 2.1 or newer.
5 Requires Python 2.1 or newer.
6
6
7 This file contains all the classes and helper functions specific to IPython.
7 This file contains all the classes and helper functions specific to IPython.
8
8
9 $Id: iplib.py 894 2005-09-22 07:16:18Z fperez $
9 $Id: iplib.py 908 2005-09-26 16:05:48Z fperez $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
13 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
13 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
14 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
14 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
15 #
15 #
16 # Distributed under the terms of the BSD License. The full license is in
16 # Distributed under the terms of the BSD License. The full license is in
17 # the file COPYING, distributed as part of this software.
17 # the file COPYING, distributed as part of this software.
18 #
18 #
19 # Note: this code originally subclassed code.InteractiveConsole from the
19 # Note: this code originally subclassed code.InteractiveConsole from the
20 # Python standard library. Over time, much of that class has been copied
20 # Python standard library. Over time, much of that class has been copied
21 # verbatim here for modifications which could not be accomplished by
21 # verbatim here for modifications which could not be accomplished by
22 # subclassing. The Python License (sec. 2) allows for this, but it's always
22 # subclassing. The Python License (sec. 2) allows for this, but it's always
23 # nice to acknowledge credit where credit is due.
23 # nice to acknowledge credit where credit is due.
24 #*****************************************************************************
24 #*****************************************************************************
25
25
26 #****************************************************************************
26 #****************************************************************************
27 # Modules and globals
27 # Modules and globals
28
28
29 from __future__ import generators # for 2.2 backwards-compatibility
29 from __future__ import generators # for 2.2 backwards-compatibility
30
30
31 from IPython import Release
31 from IPython import Release
32 __author__ = '%s <%s>\n%s <%s>' % \
32 __author__ = '%s <%s>\n%s <%s>' % \
33 ( Release.authors['Janko'] + Release.authors['Fernando'] )
33 ( Release.authors['Janko'] + Release.authors['Fernando'] )
34 __license__ = Release.license
34 __license__ = Release.license
35 __version__ = Release.version
35 __version__ = Release.version
36
36
37 # Python standard modules
37 # Python standard modules
38 import __main__
38 import __main__
39 import __builtin__
39 import __builtin__
40 import exceptions
40 import exceptions
41 import keyword
41 import keyword
42 import new
42 import new
43 import os, sys, shutil
43 import os, sys, shutil
44 import code, glob, types, re
44 import code, glob, types, re
45 import string, StringIO
45 import string, StringIO
46 import inspect, pydoc
46 import inspect, pydoc
47 import bdb, pdb
47 import bdb, pdb
48 import UserList # don't subclass list so this works with Python2.1
48 import UserList # don't subclass list so this works with Python2.1
49 from pprint import pprint, pformat
49 from pprint import pprint, pformat
50 import cPickle as pickle
50 import cPickle as pickle
51 import traceback
51 import traceback
52
52
53 # IPython's own modules
53 # IPython's own modules
54 import IPython
54 import IPython
55 from IPython import OInspect,PyColorize,ultraTB
55 from IPython import OInspect,PyColorize,ultraTB
56 from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names
56 from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names
57 from IPython.Logger import Logger
57 from IPython.Logger import Logger
58 from IPython.Magic import Magic,magic2python,shlex_split
58 from IPython.Magic import Magic,magic2python,shlex_split
59 from IPython.usage import cmd_line_usage,interactive_usage
59 from IPython.usage import cmd_line_usage,interactive_usage
60 from IPython.Struct import Struct
60 from IPython.Struct import Struct
61 from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns
61 from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns
62 from IPython.FakeModule import FakeModule
62 from IPython.FakeModule import FakeModule
63 from IPython.background_jobs import BackgroundJobManager
63 from IPython.background_jobs import BackgroundJobManager
64 from IPython.PyColorize import Parser
64 from IPython.genutils import *
65 from IPython.genutils import *
65
66
66 # Global pointer to the running
67 # Global pointer to the running
67
68
68 # store the builtin raw_input globally, and use this always, in case user code
69 # store the builtin raw_input globally, and use this always, in case user code
69 # overwrites it (like wx.py.PyShell does)
70 # overwrites it (like wx.py.PyShell does)
70 raw_input_original = raw_input
71 raw_input_original = raw_input
71
72
72 #****************************************************************************
73 #****************************************************************************
73 # Some utility function definitions
74 # Some utility function definitions
74
75
75 class Bunch: pass
76 class Bunch: pass
76
77
77 def esc_quotes(strng):
78 def esc_quotes(strng):
78 """Return the input string with single and double quotes escaped out"""
79 """Return the input string with single and double quotes escaped out"""
79
80
80 return strng.replace('"','\\"').replace("'","\\'")
81 return strng.replace('"','\\"').replace("'","\\'")
81
82
82 def import_fail_info(mod_name,fns=None):
83 def import_fail_info(mod_name,fns=None):
83 """Inform load failure for a module."""
84 """Inform load failure for a module."""
84
85
85 if fns == None:
86 if fns == None:
86 warn("Loading of %s failed.\n" % (mod_name,))
87 warn("Loading of %s failed.\n" % (mod_name,))
87 else:
88 else:
88 warn("Loading of %s from %s failed.\n" % (fns,mod_name))
89 warn("Loading of %s from %s failed.\n" % (fns,mod_name))
89
90
90 def qw_lol(indata):
91 def qw_lol(indata):
91 """qw_lol('a b') -> [['a','b']],
92 """qw_lol('a b') -> [['a','b']],
92 otherwise it's just a call to qw().
93 otherwise it's just a call to qw().
93
94
94 We need this to make sure the modules_some keys *always* end up as a
95 We need this to make sure the modules_some keys *always* end up as a
95 list of lists."""
96 list of lists."""
96
97
97 if type(indata) in StringTypes:
98 if type(indata) in StringTypes:
98 return [qw(indata)]
99 return [qw(indata)]
99 else:
100 else:
100 return qw(indata)
101 return qw(indata)
101
102
102 def ipmagic(arg_s):
103 def ipmagic(arg_s):
103 """Call a magic function by name.
104 """Call a magic function by name.
104
105
105 Input: a string containing the name of the magic function to call and any
106 Input: a string containing the name of the magic function to call and any
106 additional arguments to be passed to the magic.
107 additional arguments to be passed to the magic.
107
108
108 ipmagic('name -opt foo bar') is equivalent to typing at the ipython
109 ipmagic('name -opt foo bar') is equivalent to typing at the ipython
109 prompt:
110 prompt:
110
111
111 In[1]: %name -opt foo bar
112 In[1]: %name -opt foo bar
112
113
113 To call a magic without arguments, simply use ipmagic('name').
114 To call a magic without arguments, simply use ipmagic('name').
114
115
115 This provides a proper Python function to call IPython's magics in any
116 This provides a proper Python function to call IPython's magics in any
116 valid Python code you can type at the interpreter, including loops and
117 valid Python code you can type at the interpreter, including loops and
117 compound statements. It is added by IPython to the Python builtin
118 compound statements. It is added by IPython to the Python builtin
118 namespace upon initialization."""
119 namespace upon initialization."""
119
120
120 args = arg_s.split(' ',1)
121 args = arg_s.split(' ',1)
121 magic_name = args[0]
122 magic_name = args[0]
122 if magic_name.startswith(__IPYTHON__.ESC_MAGIC):
123 if magic_name.startswith(__IPYTHON__.ESC_MAGIC):
123 magic_name = magic_name[1:]
124 magic_name = magic_name[1:]
124 try:
125 try:
125 magic_args = args[1]
126 magic_args = args[1]
126 except IndexError:
127 except IndexError:
127 magic_args = ''
128 magic_args = ''
128 fn = getattr(__IPYTHON__,'magic_'+magic_name,None)
129 fn = getattr(__IPYTHON__,'magic_'+magic_name,None)
129 if fn is None:
130 if fn is None:
130 error("Magic function `%s` not found." % magic_name)
131 error("Magic function `%s` not found." % magic_name)
131 else:
132 else:
132 magic_args = __IPYTHON__.var_expand(magic_args)
133 magic_args = __IPYTHON__.var_expand(magic_args)
133 return fn(magic_args)
134 return fn(magic_args)
134
135
135 def ipalias(arg_s):
136 def ipalias(arg_s):
136 """Call an alias by name.
137 """Call an alias by name.
137
138
138 Input: a string containing the name of the alias to call and any
139 Input: a string containing the name of the alias to call and any
139 additional arguments to be passed to the magic.
140 additional arguments to be passed to the magic.
140
141
141 ipalias('name -opt foo bar') is equivalent to typing at the ipython
142 ipalias('name -opt foo bar') is equivalent to typing at the ipython
142 prompt:
143 prompt:
143
144
144 In[1]: name -opt foo bar
145 In[1]: name -opt foo bar
145
146
146 To call an alias without arguments, simply use ipalias('name').
147 To call an alias without arguments, simply use ipalias('name').
147
148
148 This provides a proper Python function to call IPython's aliases in any
149 This provides a proper Python function to call IPython's aliases in any
149 valid Python code you can type at the interpreter, including loops and
150 valid Python code you can type at the interpreter, including loops and
150 compound statements. It is added by IPython to the Python builtin
151 compound statements. It is added by IPython to the Python builtin
151 namespace upon initialization."""
152 namespace upon initialization."""
152
153
153 args = arg_s.split(' ',1)
154 args = arg_s.split(' ',1)
154 alias_name = args[0]
155 alias_name = args[0]
155 try:
156 try:
156 alias_args = args[1]
157 alias_args = args[1]
157 except IndexError:
158 except IndexError:
158 alias_args = ''
159 alias_args = ''
159 if alias_name in __IPYTHON__.alias_table:
160 if alias_name in __IPYTHON__.alias_table:
160 __IPYTHON__.call_alias(alias_name,alias_args)
161 __IPYTHON__.call_alias(alias_name,alias_args)
161 else:
162 else:
162 error("Alias `%s` not found." % alias_name)
163 error("Alias `%s` not found." % alias_name)
163
164
164 #-----------------------------------------------------------------------------
165 #-----------------------------------------------------------------------------
165 # Local use classes
166 # Local use classes
166 try:
167 try:
167 from IPython import FlexCompleter
168 from IPython import FlexCompleter
168
169
169 class MagicCompleter(FlexCompleter.Completer):
170 class MagicCompleter(FlexCompleter.Completer):
170 """Extension of the completer class to work on %-prefixed lines."""
171 """Extension of the completer class to work on %-prefixed lines."""
171
172
172 def __init__(self,shell,namespace=None,omit__names=0,alias_table=None):
173 def __init__(self,shell,namespace=None,omit__names=0,alias_table=None):
173 """MagicCompleter() -> completer
174 """MagicCompleter() -> completer
174
175
175 Return a completer object suitable for use by the readline library
176 Return a completer object suitable for use by the readline library
176 via readline.set_completer().
177 via readline.set_completer().
177
178
178 Inputs:
179 Inputs:
179
180
180 - shell: a pointer to the ipython shell itself. This is needed
181 - shell: a pointer to the ipython shell itself. This is needed
181 because this completer knows about magic functions, and those can
182 because this completer knows about magic functions, and those can
182 only be accessed via the ipython instance.
183 only be accessed via the ipython instance.
183
184
184 - namespace: an optional dict where completions are performed.
185 - namespace: an optional dict where completions are performed.
185
186
186 - The optional omit__names parameter sets the completer to omit the
187 - The optional omit__names parameter sets the completer to omit the
187 'magic' names (__magicname__) for python objects unless the text
188 'magic' names (__magicname__) for python objects unless the text
188 to be completed explicitly starts with one or more underscores.
189 to be completed explicitly starts with one or more underscores.
189
190
190 - If alias_table is supplied, it should be a dictionary of aliases
191 - If alias_table is supplied, it should be a dictionary of aliases
191 to complete. """
192 to complete. """
192
193
193 FlexCompleter.Completer.__init__(self,namespace)
194 FlexCompleter.Completer.__init__(self,namespace)
194 self.magic_prefix = shell.name+'.magic_'
195 self.magic_prefix = shell.name+'.magic_'
195 self.magic_escape = shell.ESC_MAGIC
196 self.magic_escape = shell.ESC_MAGIC
196 self.readline = FlexCompleter.readline
197 self.readline = FlexCompleter.readline
197 delims = self.readline.get_completer_delims()
198 delims = self.readline.get_completer_delims()
198 delims = delims.replace(self.magic_escape,'')
199 delims = delims.replace(self.magic_escape,'')
199 self.readline.set_completer_delims(delims)
200 self.readline.set_completer_delims(delims)
200 self.get_line_buffer = self.readline.get_line_buffer
201 self.get_line_buffer = self.readline.get_line_buffer
201 self.omit__names = omit__names
202 self.omit__names = omit__names
202 self.merge_completions = shell.rc.readline_merge_completions
203 self.merge_completions = shell.rc.readline_merge_completions
203
204
204 if alias_table is None:
205 if alias_table is None:
205 alias_table = {}
206 alias_table = {}
206 self.alias_table = alias_table
207 self.alias_table = alias_table
207 # Regexp to split filenames with spaces in them
208 # Regexp to split filenames with spaces in them
208 self.space_name_re = re.compile(r'([^\\] )')
209 self.space_name_re = re.compile(r'([^\\] )')
209 # Hold a local ref. to glob.glob for speed
210 # Hold a local ref. to glob.glob for speed
210 self.glob = glob.glob
211 self.glob = glob.glob
211 # Special handling of backslashes needed in win32 platforms
212 # Special handling of backslashes needed in win32 platforms
212 if sys.platform == "win32":
213 if sys.platform == "win32":
213 self.clean_glob = self._clean_glob_win32
214 self.clean_glob = self._clean_glob_win32
214 else:
215 else:
215 self.clean_glob = self._clean_glob
216 self.clean_glob = self._clean_glob
216 self.matchers = [self.python_matches,
217 self.matchers = [self.python_matches,
217 self.file_matches,
218 self.file_matches,
218 self.alias_matches,
219 self.alias_matches,
219 self.python_func_kw_matches]
220 self.python_func_kw_matches]
220
221
221 # Code contributed by Alex Schmolck, for ipython/emacs integration
222 # Code contributed by Alex Schmolck, for ipython/emacs integration
222 def all_completions(self, text):
223 def all_completions(self, text):
223 """Return all possible completions for the benefit of emacs."""
224 """Return all possible completions for the benefit of emacs."""
224
225
225 completions = []
226 completions = []
226 try:
227 try:
227 for i in xrange(sys.maxint):
228 for i in xrange(sys.maxint):
228 res = self.complete(text, i)
229 res = self.complete(text, i)
229
230
230 if not res: break
231 if not res: break
231
232
232 completions.append(res)
233 completions.append(res)
233 #XXX workaround for ``notDefined.<tab>``
234 #XXX workaround for ``notDefined.<tab>``
234 except NameError:
235 except NameError:
235 pass
236 pass
236 return completions
237 return completions
237 # /end Alex Schmolck code.
238 # /end Alex Schmolck code.
238
239
239 def _clean_glob(self,text):
240 def _clean_glob(self,text):
240 return self.glob("%s*" % text)
241 return self.glob("%s*" % text)
241
242
242 def _clean_glob_win32(self,text):
243 def _clean_glob_win32(self,text):
243 return [f.replace("\\","/")
244 return [f.replace("\\","/")
244 for f in self.glob("%s*" % text)]
245 for f in self.glob("%s*" % text)]
245
246
246 def file_matches(self, text):
247 def file_matches(self, text):
247 """Match filneames, expanding ~USER type strings.
248 """Match filneames, expanding ~USER type strings.
248
249
249 Most of the seemingly convoluted logic in this completer is an
250 Most of the seemingly convoluted logic in this completer is an
250 attempt to handle filenames with spaces in them. And yet it's not
251 attempt to handle filenames with spaces in them. And yet it's not
251 quite perfect, because Python's readline doesn't expose all of the
252 quite perfect, because Python's readline doesn't expose all of the
252 GNU readline details needed for this to be done correctly.
253 GNU readline details needed for this to be done correctly.
253
254
254 For a filename with a space in it, the printed completions will be
255 For a filename with a space in it, the printed completions will be
255 only the parts after what's already been typed (instead of the
256 only the parts after what's already been typed (instead of the
256 full completions, as is normally done). I don't think with the
257 full completions, as is normally done). I don't think with the
257 current (as of Python 2.3) Python readline it's possible to do
258 current (as of Python 2.3) Python readline it's possible to do
258 better."""
259 better."""
259
260
260 #print 'Completer->file_matches: <%s>' % text # dbg
261 #print 'Completer->file_matches: <%s>' % text # dbg
261
262
262 # chars that require escaping with backslash - i.e. chars
263 # chars that require escaping with backslash - i.e. chars
263 # that readline treats incorrectly as delimiters, but we
264 # that readline treats incorrectly as delimiters, but we
264 # don't want to treat as delimiters in filename matching
265 # don't want to treat as delimiters in filename matching
265 # when escaped with backslash
266 # when escaped with backslash
266
267
267 protectables = ' ()[]{}'
268 protectables = ' ()[]{}'
268
269
269 def protect_filename(s):
270 def protect_filename(s):
270 return "".join([(ch in protectables and '\\' + ch or ch)
271 return "".join([(ch in protectables and '\\' + ch or ch)
271 for ch in s])
272 for ch in s])
272
273
273 lbuf = self.get_line_buffer()[:self.readline.get_endidx()]
274 lbuf = self.get_line_buffer()[:self.readline.get_endidx()]
274 open_quotes = 0 # track strings with open quotes
275 open_quotes = 0 # track strings with open quotes
275 try:
276 try:
276 lsplit = shlex_split(lbuf)[-1]
277 lsplit = shlex_split(lbuf)[-1]
277 except ValueError:
278 except ValueError:
278 # typically an unmatched ", or backslash without escaped char.
279 # typically an unmatched ", or backslash without escaped char.
279 if lbuf.count('"')==1:
280 if lbuf.count('"')==1:
280 open_quotes = 1
281 open_quotes = 1
281 lsplit = lbuf.split('"')[-1]
282 lsplit = lbuf.split('"')[-1]
282 elif lbuf.count("'")==1:
283 elif lbuf.count("'")==1:
283 open_quotes = 1
284 open_quotes = 1
284 lsplit = lbuf.split("'")[-1]
285 lsplit = lbuf.split("'")[-1]
285 else:
286 else:
286 return None
287 return None
287 except IndexError:
288 except IndexError:
288 # tab pressed on empty line
289 # tab pressed on empty line
289 lsplit = ""
290 lsplit = ""
290
291
291 if lsplit != protect_filename(lsplit):
292 if lsplit != protect_filename(lsplit):
292 # if protectables are found, do matching on the whole escaped
293 # if protectables are found, do matching on the whole escaped
293 # name
294 # name
294 has_protectables = 1
295 has_protectables = 1
295 text0,text = text,lsplit
296 text0,text = text,lsplit
296 else:
297 else:
297 has_protectables = 0
298 has_protectables = 0
298 text = os.path.expanduser(text)
299 text = os.path.expanduser(text)
299
300
300 if text == "":
301 if text == "":
301 return [protect_filename(f) for f in self.glob("*")]
302 return [protect_filename(f) for f in self.glob("*")]
302
303
303 m0 = self.clean_glob(text.replace('\\',''))
304 m0 = self.clean_glob(text.replace('\\',''))
304 if has_protectables:
305 if has_protectables:
305 # If we had protectables, we need to revert our changes to the
306 # If we had protectables, we need to revert our changes to the
306 # beginning of filename so that we don't double-write the part
307 # beginning of filename so that we don't double-write the part
307 # of the filename we have so far
308 # of the filename we have so far
308 len_lsplit = len(lsplit)
309 len_lsplit = len(lsplit)
309 matches = [text0 + protect_filename(f[len_lsplit:]) for f in m0]
310 matches = [text0 + protect_filename(f[len_lsplit:]) for f in m0]
310 else:
311 else:
311 if open_quotes:
312 if open_quotes:
312 # if we have a string with an open quote, we don't need to
313 # if we have a string with an open quote, we don't need to
313 # protect the names at all (and we _shouldn't_, as it
314 # protect the names at all (and we _shouldn't_, as it
314 # would cause bugs when the filesystem call is made).
315 # would cause bugs when the filesystem call is made).
315 matches = m0
316 matches = m0
316 else:
317 else:
317 matches = [protect_filename(f) for f in m0]
318 matches = [protect_filename(f) for f in m0]
318 if len(matches) == 1 and os.path.isdir(matches[0]):
319 if len(matches) == 1 and os.path.isdir(matches[0]):
319 # Takes care of links to directories also. Use '/'
320 # Takes care of links to directories also. Use '/'
320 # explicitly, even under Windows, so that name completions
321 # explicitly, even under Windows, so that name completions
321 # don't end up escaped.
322 # don't end up escaped.
322 matches[0] += '/'
323 matches[0] += '/'
323 return matches
324 return matches
324
325
325 def alias_matches(self, text):
326 def alias_matches(self, text):
326 """Match internal system aliases"""
327 """Match internal system aliases"""
327 #print 'Completer->alias_matches:',text # dbg
328 #print 'Completer->alias_matches:',text # dbg
328 text = os.path.expanduser(text)
329 text = os.path.expanduser(text)
329 aliases = self.alias_table.keys()
330 aliases = self.alias_table.keys()
330 if text == "":
331 if text == "":
331 return aliases
332 return aliases
332 else:
333 else:
333 return [alias for alias in aliases if alias.startswith(text)]
334 return [alias for alias in aliases if alias.startswith(text)]
334
335
335 def python_matches(self,text):
336 def python_matches(self,text):
336 """Match attributes or global python names"""
337 """Match attributes or global python names"""
337 #print 'Completer->python_matches' # dbg
338 #print 'Completer->python_matches' # dbg
338 if "." in text:
339 if "." in text:
339 try:
340 try:
340 matches = self.attr_matches(text)
341 matches = self.attr_matches(text)
341 if text.endswith('.') and self.omit__names:
342 if text.endswith('.') and self.omit__names:
342 if self.omit__names == 1:
343 if self.omit__names == 1:
343 # true if txt is _not_ a __ name, false otherwise:
344 # true if txt is _not_ a __ name, false otherwise:
344 no__name = (lambda txt:
345 no__name = (lambda txt:
345 re.match(r'.*\.__.*?__',txt) is None)
346 re.match(r'.*\.__.*?__',txt) is None)
346 else:
347 else:
347 # true if txt is _not_ a _ name, false otherwise:
348 # true if txt is _not_ a _ name, false otherwise:
348 no__name = (lambda txt:
349 no__name = (lambda txt:
349 re.match(r'.*\._.*?',txt) is None)
350 re.match(r'.*\._.*?',txt) is None)
350 matches = filter(no__name, matches)
351 matches = filter(no__name, matches)
351 except NameError:
352 except NameError:
352 # catches <undefined attributes>.<tab>
353 # catches <undefined attributes>.<tab>
353 matches = []
354 matches = []
354 else:
355 else:
355 matches = self.global_matches(text)
356 matches = self.global_matches(text)
356 # this is so completion finds magics when automagic is on:
357 # this is so completion finds magics when automagic is on:
357 if matches == [] and not text.startswith(os.sep):
358 if matches == [] and not text.startswith(os.sep):
358 matches = self.attr_matches(self.magic_prefix+text)
359 matches = self.attr_matches(self.magic_prefix+text)
359 return matches
360 return matches
360
361
361 def _default_arguments(self, obj):
362 def _default_arguments(self, obj):
362 """Return the list of default arguments of obj if it is callable,
363 """Return the list of default arguments of obj if it is callable,
363 or empty list otherwise."""
364 or empty list otherwise."""
364
365
365 if not (inspect.isfunction(obj) or inspect.ismethod(obj)):
366 if not (inspect.isfunction(obj) or inspect.ismethod(obj)):
366 # for classes, check for __init__,__new__
367 # for classes, check for __init__,__new__
367 if inspect.isclass(obj):
368 if inspect.isclass(obj):
368 obj = (getattr(obj,'__init__',None) or
369 obj = (getattr(obj,'__init__',None) or
369 getattr(obj,'__new__',None))
370 getattr(obj,'__new__',None))
370 # for all others, check if they are __call__able
371 # for all others, check if they are __call__able
371 elif hasattr(obj, '__call__'):
372 elif hasattr(obj, '__call__'):
372 obj = obj.__call__
373 obj = obj.__call__
373 # XXX: is there a way to handle the builtins ?
374 # XXX: is there a way to handle the builtins ?
374 try:
375 try:
375 args,_,_1,defaults = inspect.getargspec(obj)
376 args,_,_1,defaults = inspect.getargspec(obj)
376 if defaults:
377 if defaults:
377 return args[-len(defaults):]
378 return args[-len(defaults):]
378 except TypeError: pass
379 except TypeError: pass
379 return []
380 return []
380
381
381 def python_func_kw_matches(self,text):
382 def python_func_kw_matches(self,text):
382 """Match named parameters (kwargs) of the last open function"""
383 """Match named parameters (kwargs) of the last open function"""
383
384
384 if "." in text: # a parameter cannot be dotted
385 if "." in text: # a parameter cannot be dotted
385 return []
386 return []
386 try: regexp = self.__funcParamsRegex
387 try: regexp = self.__funcParamsRegex
387 except AttributeError:
388 except AttributeError:
388 regexp = self.__funcParamsRegex = re.compile(r'''
389 regexp = self.__funcParamsRegex = re.compile(r'''
389 '.*?' | # single quoted strings or
390 '.*?' | # single quoted strings or
390 ".*?" | # double quoted strings or
391 ".*?" | # double quoted strings or
391 \w+ | # identifier
392 \w+ | # identifier
392 \S # other characters
393 \S # other characters
393 ''', re.VERBOSE | re.DOTALL)
394 ''', re.VERBOSE | re.DOTALL)
394 # 1. find the nearest identifier that comes before an unclosed
395 # 1. find the nearest identifier that comes before an unclosed
395 # parenthesis e.g. for "foo (1+bar(x), pa", the candidate is "foo"
396 # parenthesis e.g. for "foo (1+bar(x), pa", the candidate is "foo"
396 tokens = regexp.findall(self.get_line_buffer())
397 tokens = regexp.findall(self.get_line_buffer())
397 tokens.reverse()
398 tokens.reverse()
398 iterTokens = iter(tokens); openPar = 0
399 iterTokens = iter(tokens); openPar = 0
399 for token in iterTokens:
400 for token in iterTokens:
400 if token == ')':
401 if token == ')':
401 openPar -= 1
402 openPar -= 1
402 elif token == '(':
403 elif token == '(':
403 openPar += 1
404 openPar += 1
404 if openPar > 0:
405 if openPar > 0:
405 # found the last unclosed parenthesis
406 # found the last unclosed parenthesis
406 break
407 break
407 else:
408 else:
408 return []
409 return []
409 # 2. Concatenate any dotted names (e.g. "foo.bar" for "foo.bar(x, pa" )
410 # 2. Concatenate any dotted names (e.g. "foo.bar" for "foo.bar(x, pa" )
410 ids = []
411 ids = []
411 isId = re.compile(r'\w+$').match
412 isId = re.compile(r'\w+$').match
412 while True:
413 while True:
413 try:
414 try:
414 ids.append(iterTokens.next())
415 ids.append(iterTokens.next())
415 if not isId(ids[-1]):
416 if not isId(ids[-1]):
416 ids.pop(); break
417 ids.pop(); break
417 if not iterTokens.next() == '.':
418 if not iterTokens.next() == '.':
418 break
419 break
419 except StopIteration:
420 except StopIteration:
420 break
421 break
421 # lookup the candidate callable matches either using global_matches
422 # lookup the candidate callable matches either using global_matches
422 # or attr_matches for dotted names
423 # or attr_matches for dotted names
423 if len(ids) == 1:
424 if len(ids) == 1:
424 callableMatches = self.global_matches(ids[0])
425 callableMatches = self.global_matches(ids[0])
425 else:
426 else:
426 callableMatches = self.attr_matches('.'.join(ids[::-1]))
427 callableMatches = self.attr_matches('.'.join(ids[::-1]))
427 argMatches = []
428 argMatches = []
428 for callableMatch in callableMatches:
429 for callableMatch in callableMatches:
429 try: namedArgs = self._default_arguments(eval(callableMatch,
430 try: namedArgs = self._default_arguments(eval(callableMatch,
430 self.namespace))
431 self.namespace))
431 except: continue
432 except: continue
432 for namedArg in namedArgs:
433 for namedArg in namedArgs:
433 if namedArg.startswith(text):
434 if namedArg.startswith(text):
434 argMatches.append("%s=" %namedArg)
435 argMatches.append("%s=" %namedArg)
435 return argMatches
436 return argMatches
436
437
437 def complete(self, text, state):
438 def complete(self, text, state):
438 """Return the next possible completion for 'text'.
439 """Return the next possible completion for 'text'.
439
440
440 This is called successively with state == 0, 1, 2, ... until it
441 This is called successively with state == 0, 1, 2, ... until it
441 returns None. The completion should begin with 'text'. """
442 returns None. The completion should begin with 'text'. """
442
443
443 #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg
444 #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg
444 magic_escape = self.magic_escape
445 magic_escape = self.magic_escape
445 magic_prefix = self.magic_prefix
446 magic_prefix = self.magic_prefix
446
447
447 try:
448 try:
448 if text.startswith(magic_escape):
449 if text.startswith(magic_escape):
449 text = text.replace(magic_escape,magic_prefix)
450 text = text.replace(magic_escape,magic_prefix)
450 elif text.startswith('~'):
451 elif text.startswith('~'):
451 text = os.path.expanduser(text)
452 text = os.path.expanduser(text)
452 if state == 0:
453 if state == 0:
453 # Extend the list of completions with the results of each
454 # Extend the list of completions with the results of each
454 # matcher, so we return results to the user from all
455 # matcher, so we return results to the user from all
455 # namespaces.
456 # namespaces.
456 if self.merge_completions:
457 if self.merge_completions:
457 self.matches = []
458 self.matches = []
458 for matcher in self.matchers:
459 for matcher in self.matchers:
459 self.matches.extend(matcher(text))
460 self.matches.extend(matcher(text))
460 else:
461 else:
461 for matcher in self.matchers:
462 for matcher in self.matchers:
462 self.matches = matcher(text)
463 self.matches = matcher(text)
463 if self.matches:
464 if self.matches:
464 break
465 break
465
466
466 try:
467 try:
467 return self.matches[state].replace(magic_prefix,magic_escape)
468 return self.matches[state].replace(magic_prefix,magic_escape)
468 except IndexError:
469 except IndexError:
469 return None
470 return None
470 except:
471 except:
471 # If completion fails, don't annoy the user.
472 # If completion fails, don't annoy the user.
472 pass
473 pass
473
474
474 except ImportError:
475 except ImportError:
475 pass # no readline support
476 pass # no readline support
476
477
477 except KeyError:
478 except KeyError:
478 pass # Windows doesn't set TERM, it doesn't matter
479 pass # Windows doesn't set TERM, it doesn't matter
479
480
480
481
481 class InputList(UserList.UserList):
482 class InputList(UserList.UserList):
482 """Class to store user input.
483 """Class to store user input.
483
484
484 It's basically a list, but slices return a string instead of a list, thus
485 It's basically a list, but slices return a string instead of a list, thus
485 allowing things like (assuming 'In' is an instance):
486 allowing things like (assuming 'In' is an instance):
486
487
487 exec In[4:7]
488 exec In[4:7]
488
489
489 or
490 or
490
491
491 exec In[5:9] + In[14] + In[21:25]"""
492 exec In[5:9] + In[14] + In[21:25]"""
492
493
493 def __getslice__(self,i,j):
494 def __getslice__(self,i,j):
494 return ''.join(UserList.UserList.__getslice__(self,i,j))
495 return ''.join(UserList.UserList.__getslice__(self,i,j))
495
496
496 #****************************************************************************
497 #****************************************************************************
497 # Local use exceptions
498 # Local use exceptions
498 class SpaceInInput(exceptions.Exception):
499 class SpaceInInput(exceptions.Exception):
499 pass
500 pass
500
501
501 #****************************************************************************
502 #****************************************************************************
502 # Main IPython class
503 # Main IPython class
503
504
504 class InteractiveShell(code.InteractiveConsole, Logger, Magic):
505 class InteractiveShell(code.InteractiveConsole, Logger, Magic):
505 """An enhanced console for Python."""
506 """An enhanced console for Python."""
506
507
507 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
508 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
508 user_ns = None,banner2='',
509 user_ns = None,banner2='',
509 custom_exceptions=((),None)):
510 custom_exceptions=((),None)):
510
511
511 # Put a reference to self in builtins so that any form of embedded or
512 # Put a reference to self in builtins so that any form of embedded or
512 # imported code can test for being inside IPython.
513 # imported code can test for being inside IPython.
513 __builtin__.__IPYTHON__ = self
514 __builtin__.__IPYTHON__ = self
514
515
515 # And load into builtins ipmagic/ipalias as well
516 # And load into builtins ipmagic/ipalias as well
516 __builtin__.ipmagic = ipmagic
517 __builtin__.ipmagic = ipmagic
517 __builtin__.ipalias = ipalias
518 __builtin__.ipalias = ipalias
518
519
519 # Add to __builtin__ other parts of IPython's public API
520 # Add to __builtin__ other parts of IPython's public API
520 __builtin__.ip_set_hook = self.set_hook
521 __builtin__.ip_set_hook = self.set_hook
521
522
522 # Keep in the builtins a flag for when IPython is active. We set it
523 # Keep in the builtins a flag for when IPython is active. We set it
523 # with setdefault so that multiple nested IPythons don't clobber one
524 # with setdefault so that multiple nested IPythons don't clobber one
524 # another. Each will increase its value by one upon being activated,
525 # another. Each will increase its value by one upon being activated,
525 # which also gives us a way to determine the nesting level.
526 # which also gives us a way to determine the nesting level.
526 __builtin__.__dict__.setdefault('__IPYTHON__active',0)
527 __builtin__.__dict__.setdefault('__IPYTHON__active',0)
527
528
528 # Inform the user of ipython's fast exit magics.
529 # Inform the user of ipython's fast exit magics.
529 _exit = ' Use %Exit or %Quit to exit without confirmation.'
530 _exit = ' Use %Exit or %Quit to exit without confirmation.'
530 __builtin__.exit += _exit
531 __builtin__.exit += _exit
531 __builtin__.quit += _exit
532 __builtin__.quit += _exit
532
533
533 # Create the namespace where the user will operate:
534 # Create the namespace where the user will operate:
534
535
535 # FIXME. For some strange reason, __builtins__ is showing up at user
536 # FIXME. For some strange reason, __builtins__ is showing up at user
536 # level as a dict instead of a module. This is a manual fix, but I
537 # level as a dict instead of a module. This is a manual fix, but I
537 # should really track down where the problem is coming from. Alex
538 # should really track down where the problem is coming from. Alex
538 # Schmolck reported this problem first.
539 # Schmolck reported this problem first.
539
540
540 # A useful post by Alex Martelli on this topic:
541 # A useful post by Alex Martelli on this topic:
541 # Re: inconsistent value from __builtins__
542 # Re: inconsistent value from __builtins__
542 # Von: Alex Martelli <aleaxit@yahoo.com>
543 # Von: Alex Martelli <aleaxit@yahoo.com>
543 # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends
544 # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends
544 # Gruppen: comp.lang.python
545 # Gruppen: comp.lang.python
545 # Referenzen: 1
546 # Referenzen: 1
546
547
547 # Michael Hohn <hohn@hooknose.lbl.gov> wrote:
548 # Michael Hohn <hohn@hooknose.lbl.gov> wrote:
548 # > >>> print type(builtin_check.get_global_binding('__builtins__'))
549 # > >>> print type(builtin_check.get_global_binding('__builtins__'))
549 # > <type 'dict'>
550 # > <type 'dict'>
550 # > >>> print type(__builtins__)
551 # > >>> print type(__builtins__)
551 # > <type 'module'>
552 # > <type 'module'>
552 # > Is this difference in return value intentional?
553 # > Is this difference in return value intentional?
553
554
554 # Well, it's documented that '__builtins__' can be either a dictionary
555 # Well, it's documented that '__builtins__' can be either a dictionary
555 # or a module, and it's been that way for a long time. Whether it's
556 # or a module, and it's been that way for a long time. Whether it's
556 # intentional (or sensible), I don't know. In any case, the idea is that
557 # intentional (or sensible), I don't know. In any case, the idea is that
557 # if you need to access the built-in namespace directly, you should start
558 # if you need to access the built-in namespace directly, you should start
558 # with "import __builtin__" (note, no 's') which will definitely give you
559 # with "import __builtin__" (note, no 's') which will definitely give you
559 # a module. Yeah, it's somewhat confusing:-(.
560 # a module. Yeah, it's somewhat confusing:-(.
560
561
561 if user_ns is None:
562 if user_ns is None:
562 # Set __name__ to __main__ to better match the behavior of the
563 # Set __name__ to __main__ to better match the behavior of the
563 # normal interpreter.
564 # normal interpreter.
564 self.user_ns = {'__name__' :'__main__',
565 self.user_ns = {'__name__' :'__main__',
565 '__builtins__' : __builtin__,
566 '__builtins__' : __builtin__,
566 }
567 }
567 else:
568 else:
568 self.user_ns = user_ns
569 self.user_ns = user_ns
569
570
570 # The user namespace MUST have a pointer to the shell itself.
571 # The user namespace MUST have a pointer to the shell itself.
571 self.user_ns[name] = self
572 self.user_ns[name] = self
572
573
573 # We need to insert into sys.modules something that looks like a
574 # We need to insert into sys.modules something that looks like a
574 # module but which accesses the IPython namespace, for shelve and
575 # module but which accesses the IPython namespace, for shelve and
575 # pickle to work interactively. Normally they rely on getting
576 # pickle to work interactively. Normally they rely on getting
576 # everything out of __main__, but for embedding purposes each IPython
577 # everything out of __main__, but for embedding purposes each IPython
577 # instance has its own private namespace, so we can't go shoving
578 # instance has its own private namespace, so we can't go shoving
578 # everything into __main__.
579 # everything into __main__.
579
580
580 try:
581 try:
581 main_name = self.user_ns['__name__']
582 main_name = self.user_ns['__name__']
582 except KeyError:
583 except KeyError:
583 raise KeyError,'user_ns dictionary MUST have a "__name__" key'
584 raise KeyError,'user_ns dictionary MUST have a "__name__" key'
584 else:
585 else:
585 #print "pickle hack in place" # dbg
586 #print "pickle hack in place" # dbg
586 sys.modules[main_name] = FakeModule(self.user_ns)
587 sys.modules[main_name] = FakeModule(self.user_ns)
587
588
588 # List of input with multi-line handling.
589 # List of input with multi-line handling.
589 # Fill its zero entry, user counter starts at 1
590 # Fill its zero entry, user counter starts at 1
590 self.input_hist = InputList(['\n'])
591 self.input_hist = InputList(['\n'])
591
592
592 # list of visited directories
593 # list of visited directories
593 try:
594 try:
594 self.dir_hist = [os.getcwd()]
595 self.dir_hist = [os.getcwd()]
595 except IOError, e:
596 except IOError, e:
596 self.dir_hist = []
597 self.dir_hist = []
597
598
598 # dict of output history
599 # dict of output history
599 self.output_hist = {}
600 self.output_hist = {}
600
601
601 # dict of names to be treated as system aliases. Each entry in the
602 # dict of names to be treated as system aliases. Each entry in the
602 # alias table must be a 2-tuple of the form (N,name), where N is the
603 # alias table must be a 2-tuple of the form (N,name), where N is the
603 # number of positional arguments of the alias.
604 # number of positional arguments of the alias.
604 self.alias_table = {}
605 self.alias_table = {}
605
606
606 # dict of things NOT to alias (keywords, builtins and some special magics)
607 # dict of things NOT to alias (keywords, builtins and some special magics)
607 no_alias = {}
608 no_alias = {}
608 no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias']
609 no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias']
609 for key in keyword.kwlist + no_alias_magics:
610 for key in keyword.kwlist + no_alias_magics:
610 no_alias[key] = 1
611 no_alias[key] = 1
611 no_alias.update(__builtin__.__dict__)
612 no_alias.update(__builtin__.__dict__)
612 self.no_alias = no_alias
613 self.no_alias = no_alias
613
614
614
615
615 # make global variables for user access to these
616 # make global variables for user access to these
616 self.user_ns['_ih'] = self.input_hist
617 self.user_ns['_ih'] = self.input_hist
617 self.user_ns['_oh'] = self.output_hist
618 self.user_ns['_oh'] = self.output_hist
618 self.user_ns['_dh'] = self.dir_hist
619 self.user_ns['_dh'] = self.dir_hist
619
620
620 # user aliases to input and output histories
621 # user aliases to input and output histories
621 self.user_ns['In'] = self.input_hist
622 self.user_ns['In'] = self.input_hist
622 self.user_ns['Out'] = self.output_hist
623 self.user_ns['Out'] = self.output_hist
623
624
624 # Store the actual shell's name
625 # Store the actual shell's name
625 self.name = name
626 self.name = name
626
627
627 # Object variable to store code object waiting execution. This is
628 # Object variable to store code object waiting execution. This is
628 # used mainly by the multithreaded shells, but it can come in handy in
629 # used mainly by the multithreaded shells, but it can come in handy in
629 # other situations. No need to use a Queue here, since it's a single
630 # other situations. No need to use a Queue here, since it's a single
630 # item which gets cleared once run.
631 # item which gets cleared once run.
631 self.code_to_run = None
632 self.code_to_run = None
632
633
633 # Job manager (for jobs run as background threads)
634 # Job manager (for jobs run as background threads)
634 self.jobs = BackgroundJobManager()
635 self.jobs = BackgroundJobManager()
635 # Put the job manager into builtins so it's always there.
636 # Put the job manager into builtins so it's always there.
636 __builtin__.jobs = self.jobs
637 __builtin__.jobs = self.jobs
637
638
638 # escapes for automatic behavior on the command line
639 # escapes for automatic behavior on the command line
639 self.ESC_SHELL = '!'
640 self.ESC_SHELL = '!'
640 self.ESC_HELP = '?'
641 self.ESC_HELP = '?'
641 self.ESC_MAGIC = '%'
642 self.ESC_MAGIC = '%'
642 self.ESC_QUOTE = ','
643 self.ESC_QUOTE = ','
643 self.ESC_QUOTE2 = ';'
644 self.ESC_QUOTE2 = ';'
644 self.ESC_PAREN = '/'
645 self.ESC_PAREN = '/'
645
646
646 # And their associated handlers
647 # And their associated handlers
647 self.esc_handlers = {self.ESC_PAREN:self.handle_auto,
648 self.esc_handlers = {self.ESC_PAREN:self.handle_auto,
648 self.ESC_QUOTE:self.handle_auto,
649 self.ESC_QUOTE:self.handle_auto,
649 self.ESC_QUOTE2:self.handle_auto,
650 self.ESC_QUOTE2:self.handle_auto,
650 self.ESC_MAGIC:self.handle_magic,
651 self.ESC_MAGIC:self.handle_magic,
651 self.ESC_HELP:self.handle_help,
652 self.ESC_HELP:self.handle_help,
652 self.ESC_SHELL:self.handle_shell_escape,
653 self.ESC_SHELL:self.handle_shell_escape,
653 }
654 }
654
655
655 # class initializations
656 # class initializations
656 code.InteractiveConsole.__init__(self,locals = self.user_ns)
657 code.InteractiveConsole.__init__(self,locals = self.user_ns)
657 Logger.__init__(self,log_ns = self.user_ns)
658 Logger.__init__(self,log_ns = self.user_ns)
658 Magic.__init__(self,self)
659 Magic.__init__(self,self)
659
660
660 # an ugly hack to get a pointer to the shell, so I can start writing
661 # an ugly hack to get a pointer to the shell, so I can start writing
661 # magic code via this pointer instead of the current mixin salad.
662 # magic code via this pointer instead of the current mixin salad.
662 Magic.set_shell(self,self)
663 Magic.set_shell(self,self)
663
664
665 # Python source parser/formatter for syntax highlighting
666 pyformat = Parser().format
667 self.pycolorize = lambda src: pyformat(src,'str',self.rc['colors'])
668
664 # hooks holds pointers used for user-side customizations
669 # hooks holds pointers used for user-side customizations
665 self.hooks = Struct()
670 self.hooks = Struct()
666
671
667 # Set all default hooks, defined in the IPython.hooks module.
672 # Set all default hooks, defined in the IPython.hooks module.
668 hooks = IPython.hooks
673 hooks = IPython.hooks
669 for hook_name in hooks.__all__:
674 for hook_name in hooks.__all__:
670 self.set_hook(hook_name,getattr(hooks,hook_name))
675 self.set_hook(hook_name,getattr(hooks,hook_name))
671
676
672 # Flag to mark unconditional exit
677 # Flag to mark unconditional exit
673 self.exit_now = False
678 self.exit_now = False
674
679
675 self.usage_min = """\
680 self.usage_min = """\
676 An enhanced console for Python.
681 An enhanced console for Python.
677 Some of its features are:
682 Some of its features are:
678 - Readline support if the readline library is present.
683 - Readline support if the readline library is present.
679 - Tab completion in the local namespace.
684 - Tab completion in the local namespace.
680 - Logging of input, see command-line options.
685 - Logging of input, see command-line options.
681 - System shell escape via ! , eg !ls.
686 - System shell escape via ! , eg !ls.
682 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
687 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
683 - Keeps track of locally defined variables via %who, %whos.
688 - Keeps track of locally defined variables via %who, %whos.
684 - Show object information with a ? eg ?x or x? (use ?? for more info).
689 - Show object information with a ? eg ?x or x? (use ?? for more info).
685 """
690 """
686 if usage: self.usage = usage
691 if usage: self.usage = usage
687 else: self.usage = self.usage_min
692 else: self.usage = self.usage_min
688
693
689 # Storage
694 # Storage
690 self.rc = rc # This will hold all configuration information
695 self.rc = rc # This will hold all configuration information
691 self.inputcache = []
696 self.inputcache = []
692 self._boundcache = []
697 self._boundcache = []
693 self.pager = 'less'
698 self.pager = 'less'
694 # temporary files used for various purposes. Deleted at exit.
699 # temporary files used for various purposes. Deleted at exit.
695 self.tempfiles = []
700 self.tempfiles = []
696
701
697 # Keep track of readline usage (later set by init_readline)
702 # Keep track of readline usage (later set by init_readline)
698 self.has_readline = 0
703 self.has_readline = 0
699
704
700 # for pushd/popd management
705 # for pushd/popd management
701 try:
706 try:
702 self.home_dir = get_home_dir()
707 self.home_dir = get_home_dir()
703 except HomeDirError,msg:
708 except HomeDirError,msg:
704 fatal(msg)
709 fatal(msg)
705
710
706 self.dir_stack = [os.getcwd().replace(self.home_dir,'~')]
711 self.dir_stack = [os.getcwd().replace(self.home_dir,'~')]
707
712
708 # Functions to call the underlying shell.
713 # Functions to call the underlying shell.
709
714
710 # utility to expand user variables via Itpl
715 # utility to expand user variables via Itpl
711 self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'),
716 self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'),
712 self.user_ns))
717 self.user_ns))
713 # The first is similar to os.system, but it doesn't return a value,
718 # The first is similar to os.system, but it doesn't return a value,
714 # and it allows interpolation of variables in the user's namespace.
719 # and it allows interpolation of variables in the user's namespace.
715 self.system = lambda cmd: shell(self.var_expand(cmd),
720 self.system = lambda cmd: shell(self.var_expand(cmd),
716 header='IPython system call: ',
721 header='IPython system call: ',
717 verbose=self.rc.system_verbose)
722 verbose=self.rc.system_verbose)
718 # These are for getoutput and getoutputerror:
723 # These are for getoutput and getoutputerror:
719 self.getoutput = lambda cmd: \
724 self.getoutput = lambda cmd: \
720 getoutput(self.var_expand(cmd),
725 getoutput(self.var_expand(cmd),
721 header='IPython system call: ',
726 header='IPython system call: ',
722 verbose=self.rc.system_verbose)
727 verbose=self.rc.system_verbose)
723 self.getoutputerror = lambda cmd: \
728 self.getoutputerror = lambda cmd: \
724 getoutputerror(str(ItplNS(cmd.replace('#','\#'),
729 getoutputerror(str(ItplNS(cmd.replace('#','\#'),
725 self.user_ns)),
730 self.user_ns)),
726 header='IPython system call: ',
731 header='IPython system call: ',
727 verbose=self.rc.system_verbose)
732 verbose=self.rc.system_verbose)
728
733
729 # RegExp for splitting line contents into pre-char//first
734 # RegExp for splitting line contents into pre-char//first
730 # word-method//rest. For clarity, each group in on one line.
735 # word-method//rest. For clarity, each group in on one line.
731
736
732 # WARNING: update the regexp if the above escapes are changed, as they
737 # WARNING: update the regexp if the above escapes are changed, as they
733 # are hardwired in.
738 # are hardwired in.
734
739
735 # Don't get carried away with trying to make the autocalling catch too
740 # Don't get carried away with trying to make the autocalling catch too
736 # much: it's better to be conservative rather than to trigger hidden
741 # much: it's better to be conservative rather than to trigger hidden
737 # evals() somewhere and end up causing side effects.
742 # evals() somewhere and end up causing side effects.
738
743
739 self.line_split = re.compile(r'^([\s*,;/])'
744 self.line_split = re.compile(r'^([\s*,;/])'
740 r'([\?\w\.]+\w*\s*)'
745 r'([\?\w\.]+\w*\s*)'
741 r'(\(?.*$)')
746 r'(\(?.*$)')
742
747
743 # Original re, keep around for a while in case changes break something
748 # Original re, keep around for a while in case changes break something
744 #self.line_split = re.compile(r'(^[\s*!\?%,/]?)'
749 #self.line_split = re.compile(r'(^[\s*!\?%,/]?)'
745 # r'(\s*[\?\w\.]+\w*\s*)'
750 # r'(\s*[\?\w\.]+\w*\s*)'
746 # r'(\(?.*$)')
751 # r'(\(?.*$)')
747
752
748 # RegExp to identify potential function names
753 # RegExp to identify potential function names
749 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
754 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
750 # RegExp to exclude strings with this start from autocalling
755 # RegExp to exclude strings with this start from autocalling
751 self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ')
756 self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ')
752 # try to catch also methods for stuff in lists/tuples/dicts: off
757 # try to catch also methods for stuff in lists/tuples/dicts: off
753 # (experimental). For this to work, the line_split regexp would need
758 # (experimental). For this to work, the line_split regexp would need
754 # to be modified so it wouldn't break things at '['. That line is
759 # to be modified so it wouldn't break things at '['. That line is
755 # nasty enough that I shouldn't change it until I can test it _well_.
760 # nasty enough that I shouldn't change it until I can test it _well_.
756 #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$')
761 #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$')
757
762
758 # keep track of where we started running (mainly for crash post-mortem)
763 # keep track of where we started running (mainly for crash post-mortem)
759 self.starting_dir = os.getcwd()
764 self.starting_dir = os.getcwd()
760
765
761 # Attributes for Logger mixin class, make defaults here
766 # Attributes for Logger mixin class, make defaults here
762 self._dolog = 0
767 self._dolog = 0
763 self.LOG = ''
768 self.LOG = ''
764 self.LOGDEF = '.InteractiveShell.log'
769 self.LOGDEF = '.InteractiveShell.log'
765 self.LOGMODE = 'over'
770 self.LOGMODE = 'over'
766 self.LOGHEAD = Itpl(
771 self.LOGHEAD = Itpl(
767 """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
772 """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
768 #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
773 #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
769 #log# opts = $self.rc.opts
774 #log# opts = $self.rc.opts
770 #log# args = $self.rc.args
775 #log# args = $self.rc.args
771 #log# It is safe to make manual edits below here.
776 #log# It is safe to make manual edits below here.
772 #log#-----------------------------------------------------------------------
777 #log#-----------------------------------------------------------------------
773 """)
778 """)
774 # Various switches which can be set
779 # Various switches which can be set
775 self.CACHELENGTH = 5000 # this is cheap, it's just text
780 self.CACHELENGTH = 5000 # this is cheap, it's just text
776 self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__
781 self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__
777 self.banner2 = banner2
782 self.banner2 = banner2
778
783
779 # TraceBack handlers:
784 # TraceBack handlers:
780 # Need two, one for syntax errors and one for other exceptions.
785 # Need two, one for syntax errors and one for other exceptions.
781 self.SyntaxTB = ultraTB.ListTB(color_scheme='NoColor')
786 self.SyntaxTB = ultraTB.ListTB(color_scheme='NoColor')
782 # This one is initialized with an offset, meaning we always want to
787 # This one is initialized with an offset, meaning we always want to
783 # remove the topmost item in the traceback, which is our own internal
788 # remove the topmost item in the traceback, which is our own internal
784 # code. Valid modes: ['Plain','Context','Verbose']
789 # code. Valid modes: ['Plain','Context','Verbose']
785 self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain',
790 self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain',
786 color_scheme='NoColor',
791 color_scheme='NoColor',
787 tb_offset = 1)
792 tb_offset = 1)
788 # and add any custom exception handlers the user may have specified
793 # and add any custom exception handlers the user may have specified
789 self.set_custom_exc(*custom_exceptions)
794 self.set_custom_exc(*custom_exceptions)
790
795
791 # Object inspector
796 # Object inspector
792 ins_colors = OInspect.InspectColors
797 ins_colors = OInspect.InspectColors
793 code_colors = PyColorize.ANSICodeColors
798 code_colors = PyColorize.ANSICodeColors
794 self.inspector = OInspect.Inspector(ins_colors,code_colors,'NoColor')
799 self.inspector = OInspect.Inspector(ins_colors,code_colors,'NoColor')
795 self.autoindent = 0
800 self.autoindent = 0
796
801
797 # Make some aliases automatically
802 # Make some aliases automatically
798 # Prepare list of shell aliases to auto-define
803 # Prepare list of shell aliases to auto-define
799 if os.name == 'posix':
804 if os.name == 'posix':
800 auto_alias = ('mkdir mkdir', 'rmdir rmdir',
805 auto_alias = ('mkdir mkdir', 'rmdir rmdir',
801 'mv mv -i','rm rm -i','cp cp -i',
806 'mv mv -i','rm rm -i','cp cp -i',
802 'cat cat','less less','clear clear',
807 'cat cat','less less','clear clear',
803 # a better ls
808 # a better ls
804 'ls ls -F',
809 'ls ls -F',
805 # long ls
810 # long ls
806 'll ls -lF',
811 'll ls -lF',
807 # color ls
812 # color ls
808 'lc ls -F -o --color',
813 'lc ls -F -o --color',
809 # ls normal files only
814 # ls normal files only
810 'lf ls -F -o --color %l | grep ^-',
815 'lf ls -F -o --color %l | grep ^-',
811 # ls symbolic links
816 # ls symbolic links
812 'lk ls -F -o --color %l | grep ^l',
817 'lk ls -F -o --color %l | grep ^l',
813 # directories or links to directories,
818 # directories or links to directories,
814 'ldir ls -F -o --color %l | grep /$',
819 'ldir ls -F -o --color %l | grep /$',
815 # things which are executable
820 # things which are executable
816 'lx ls -F -o --color %l | grep ^-..x',
821 'lx ls -F -o --color %l | grep ^-..x',
817 )
822 )
818 elif os.name in ['nt','dos']:
823 elif os.name in ['nt','dos']:
819 auto_alias = ('dir dir /on', 'ls dir /on',
824 auto_alias = ('dir dir /on', 'ls dir /on',
820 'ddir dir /ad /on', 'ldir dir /ad /on',
825 'ddir dir /ad /on', 'ldir dir /ad /on',
821 'mkdir mkdir','rmdir rmdir','echo echo',
826 'mkdir mkdir','rmdir rmdir','echo echo',
822 'ren ren','cls cls','copy copy')
827 'ren ren','cls cls','copy copy')
823 else:
828 else:
824 auto_alias = ()
829 auto_alias = ()
825 self.auto_alias = map(lambda s:s.split(None,1),auto_alias)
830 self.auto_alias = map(lambda s:s.split(None,1),auto_alias)
826 # Call the actual (public) initializer
831 # Call the actual (public) initializer
827 self.init_auto_alias()
832 self.init_auto_alias()
828 # end __init__
833 # end __init__
829
834
830 def set_hook(self,name,hook):
835 def set_hook(self,name,hook):
831 """set_hook(name,hook) -> sets an internal IPython hook.
836 """set_hook(name,hook) -> sets an internal IPython hook.
832
837
833 IPython exposes some of its internal API as user-modifiable hooks. By
838 IPython exposes some of its internal API as user-modifiable hooks. By
834 resetting one of these hooks, you can modify IPython's behavior to
839 resetting one of these hooks, you can modify IPython's behavior to
835 call at runtime your own routines."""
840 call at runtime your own routines."""
836
841
837 # At some point in the future, this should validate the hook before it
842 # At some point in the future, this should validate the hook before it
838 # accepts it. Probably at least check that the hook takes the number
843 # accepts it. Probably at least check that the hook takes the number
839 # of args it's supposed to.
844 # of args it's supposed to.
840 setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__))
845 setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__))
841
846
842 def set_custom_exc(self,exc_tuple,handler):
847 def set_custom_exc(self,exc_tuple,handler):
843 """set_custom_exc(exc_tuple,handler)
848 """set_custom_exc(exc_tuple,handler)
844
849
845 Set a custom exception handler, which will be called if any of the
850 Set a custom exception handler, which will be called if any of the
846 exceptions in exc_tuple occur in the mainloop (specifically, in the
851 exceptions in exc_tuple occur in the mainloop (specifically, in the
847 runcode() method.
852 runcode() method.
848
853
849 Inputs:
854 Inputs:
850
855
851 - exc_tuple: a *tuple* of valid exceptions to call the defined
856 - exc_tuple: a *tuple* of valid exceptions to call the defined
852 handler for. It is very important that you use a tuple, and NOT A
857 handler for. It is very important that you use a tuple, and NOT A
853 LIST here, because of the way Python's except statement works. If
858 LIST here, because of the way Python's except statement works. If
854 you only want to trap a single exception, use a singleton tuple:
859 you only want to trap a single exception, use a singleton tuple:
855
860
856 exc_tuple == (MyCustomException,)
861 exc_tuple == (MyCustomException,)
857
862
858 - handler: this must be defined as a function with the following
863 - handler: this must be defined as a function with the following
859 basic interface: def my_handler(self,etype,value,tb).
864 basic interface: def my_handler(self,etype,value,tb).
860
865
861 This will be made into an instance method (via new.instancemethod)
866 This will be made into an instance method (via new.instancemethod)
862 of IPython itself, and it will be called if any of the exceptions
867 of IPython itself, and it will be called if any of the exceptions
863 listed in the exc_tuple are caught. If the handler is None, an
868 listed in the exc_tuple are caught. If the handler is None, an
864 internal basic one is used, which just prints basic info.
869 internal basic one is used, which just prints basic info.
865
870
866 WARNING: by putting in your own exception handler into IPython's main
871 WARNING: by putting in your own exception handler into IPython's main
867 execution loop, you run a very good chance of nasty crashes. This
872 execution loop, you run a very good chance of nasty crashes. This
868 facility should only be used if you really know what you are doing."""
873 facility should only be used if you really know what you are doing."""
869
874
870 assert type(exc_tuple)==type(()) , \
875 assert type(exc_tuple)==type(()) , \
871 "The custom exceptions must be given AS A TUPLE."
876 "The custom exceptions must be given AS A TUPLE."
872
877
873 def dummy_handler(self,etype,value,tb):
878 def dummy_handler(self,etype,value,tb):
874 print '*** Simple custom exception handler ***'
879 print '*** Simple custom exception handler ***'
875 print 'Exception type :',etype
880 print 'Exception type :',etype
876 print 'Exception value:',value
881 print 'Exception value:',value
877 print 'Traceback :',tb
882 print 'Traceback :',tb
878 print 'Source code :','\n'.join(self.buffer)
883 print 'Source code :','\n'.join(self.buffer)
879
884
880 if handler is None: handler = dummy_handler
885 if handler is None: handler = dummy_handler
881
886
882 self.CustomTB = new.instancemethod(handler,self,self.__class__)
887 self.CustomTB = new.instancemethod(handler,self,self.__class__)
883 self.custom_exceptions = exc_tuple
888 self.custom_exceptions = exc_tuple
884
889
885 def set_custom_completer(self,completer,pos=0):
890 def set_custom_completer(self,completer,pos=0):
886 """set_custom_completer(completer,pos=0)
891 """set_custom_completer(completer,pos=0)
887
892
888 Adds a new custom completer function.
893 Adds a new custom completer function.
889
894
890 The position argument (defaults to 0) is the index in the completers
895 The position argument (defaults to 0) is the index in the completers
891 list where you want the completer to be inserted."""
896 list where you want the completer to be inserted."""
892
897
893 newcomp = new.instancemethod(completer,self.Completer,
898 newcomp = new.instancemethod(completer,self.Completer,
894 self.Completer.__class__)
899 self.Completer.__class__)
895 self.Completer.matchers.insert(pos,newcomp)
900 self.Completer.matchers.insert(pos,newcomp)
896
901
897 def complete(self,text):
902 def complete(self,text):
898 """Return a sorted list of all possible completions on text.
903 """Return a sorted list of all possible completions on text.
899
904
900 Inputs:
905 Inputs:
901
906
902 - text: a string of text to be completed on.
907 - text: a string of text to be completed on.
903
908
904 This is a wrapper around the completion mechanism, similar to what
909 This is a wrapper around the completion mechanism, similar to what
905 readline does at the command line when the TAB key is hit. By
910 readline does at the command line when the TAB key is hit. By
906 exposing it as a method, it can be used by other non-readline
911 exposing it as a method, it can be used by other non-readline
907 environments (such as GUIs) for text completion.
912 environments (such as GUIs) for text completion.
908
913
909 Simple usage example:
914 Simple usage example:
910
915
911 In [1]: x = 'hello'
916 In [1]: x = 'hello'
912
917
913 In [2]: __IP.complete('x.l')
918 In [2]: __IP.complete('x.l')
914 Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']"""
919 Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']"""
915
920
916 complete = self.Completer.complete
921 complete = self.Completer.complete
917 state = 0
922 state = 0
918 # use a dict so we get unique keys, since ipyhton's multiple
923 # use a dict so we get unique keys, since ipyhton's multiple
919 # completers can return duplicates.
924 # completers can return duplicates.
920 comps = {}
925 comps = {}
921 while True:
926 while True:
922 newcomp = complete(text,state)
927 newcomp = complete(text,state)
923 if newcomp is None:
928 if newcomp is None:
924 break
929 break
925 comps[newcomp] = 1
930 comps[newcomp] = 1
926 state += 1
931 state += 1
927 outcomps = comps.keys()
932 outcomps = comps.keys()
928 outcomps.sort()
933 outcomps.sort()
929 return outcomps
934 return outcomps
930
935
931 def post_config_initialization(self):
936 def post_config_initialization(self):
932 """Post configuration init method
937 """Post configuration init method
933
938
934 This is called after the configuration files have been processed to
939 This is called after the configuration files have been processed to
935 'finalize' the initialization."""
940 'finalize' the initialization."""
936
941
937 # dynamic data that survives through sessions
942 # dynamic data that survives through sessions
938 # XXX make the filename a config option?
943 # XXX make the filename a config option?
939 persist_base = 'persist'
944 persist_base = 'persist'
940 if self.rc.profile:
945 if self.rc.profile:
941 persist_base += '_%s' % self.rc.profile
946 persist_base += '_%s' % self.rc.profile
942 self.persist_fname = os.path.join(self.rc.ipythondir,persist_base)
947 self.persist_fname = os.path.join(self.rc.ipythondir,persist_base)
943
948
944 try:
949 try:
945 self.persist = pickle.load(file(self.persist_fname))
950 self.persist = pickle.load(file(self.persist_fname))
946 except:
951 except:
947 self.persist = {}
952 self.persist = {}
948
953
949 def init_auto_alias(self):
954 def init_auto_alias(self):
950 """Define some aliases automatically.
955 """Define some aliases automatically.
951
956
952 These are ALL parameter-less aliases"""
957 These are ALL parameter-less aliases"""
953 for alias,cmd in self.auto_alias:
958 for alias,cmd in self.auto_alias:
954 self.alias_table[alias] = (0,cmd)
959 self.alias_table[alias] = (0,cmd)
955
960
956 def alias_table_validate(self,verbose=0):
961 def alias_table_validate(self,verbose=0):
957 """Update information about the alias table.
962 """Update information about the alias table.
958
963
959 In particular, make sure no Python keywords/builtins are in it."""
964 In particular, make sure no Python keywords/builtins are in it."""
960
965
961 no_alias = self.no_alias
966 no_alias = self.no_alias
962 for k in self.alias_table.keys():
967 for k in self.alias_table.keys():
963 if k in no_alias:
968 if k in no_alias:
964 del self.alias_table[k]
969 del self.alias_table[k]
965 if verbose:
970 if verbose:
966 print ("Deleting alias <%s>, it's a Python "
971 print ("Deleting alias <%s>, it's a Python "
967 "keyword or builtin." % k)
972 "keyword or builtin." % k)
968
973
969 def set_autoindent(self,value=None):
974 def set_autoindent(self,value=None):
970 """Set the autoindent flag, checking for readline support.
975 """Set the autoindent flag, checking for readline support.
971
976
972 If called with no arguments, it acts as a toggle."""
977 If called with no arguments, it acts as a toggle."""
973
978
974 if not self.has_readline:
979 if not self.has_readline:
975 if os.name == 'posix':
980 if os.name == 'posix':
976 warn("The auto-indent feature requires the readline library")
981 warn("The auto-indent feature requires the readline library")
977 self.autoindent = 0
982 self.autoindent = 0
978 return
983 return
979 if value is None:
984 if value is None:
980 self.autoindent = not self.autoindent
985 self.autoindent = not self.autoindent
981 else:
986 else:
982 self.autoindent = value
987 self.autoindent = value
983
988
984 def rc_set_toggle(self,rc_field,value=None):
989 def rc_set_toggle(self,rc_field,value=None):
985 """Set or toggle a field in IPython's rc config. structure.
990 """Set or toggle a field in IPython's rc config. structure.
986
991
987 If called with no arguments, it acts as a toggle.
992 If called with no arguments, it acts as a toggle.
988
993
989 If called with a non-existent field, the resulting AttributeError
994 If called with a non-existent field, the resulting AttributeError
990 exception will propagate out."""
995 exception will propagate out."""
991
996
992 rc_val = getattr(self.rc,rc_field)
997 rc_val = getattr(self.rc,rc_field)
993 if value is None:
998 if value is None:
994 value = not rc_val
999 value = not rc_val
995 setattr(self.rc,rc_field,value)
1000 setattr(self.rc,rc_field,value)
996
1001
997 def user_setup(self,ipythondir,rc_suffix,mode='install'):
1002 def user_setup(self,ipythondir,rc_suffix,mode='install'):
998 """Install the user configuration directory.
1003 """Install the user configuration directory.
999
1004
1000 Can be called when running for the first time or to upgrade the user's
1005 Can be called when running for the first time or to upgrade the user's
1001 .ipython/ directory with the mode parameter. Valid modes are 'install'
1006 .ipython/ directory with the mode parameter. Valid modes are 'install'
1002 and 'upgrade'."""
1007 and 'upgrade'."""
1003
1008
1004 def wait():
1009 def wait():
1005 try:
1010 try:
1006 raw_input("Please press <RETURN> to start IPython.")
1011 raw_input("Please press <RETURN> to start IPython.")
1007 except EOFError:
1012 except EOFError:
1008 print >> Term.cout
1013 print >> Term.cout
1009 print '*'*70
1014 print '*'*70
1010
1015
1011 cwd = os.getcwd() # remember where we started
1016 cwd = os.getcwd() # remember where we started
1012 glb = glob.glob
1017 glb = glob.glob
1013 print '*'*70
1018 print '*'*70
1014 if mode == 'install':
1019 if mode == 'install':
1015 print \
1020 print \
1016 """Welcome to IPython. I will try to create a personal configuration directory
1021 """Welcome to IPython. I will try to create a personal configuration directory
1017 where you can customize many aspects of IPython's functionality in:\n"""
1022 where you can customize many aspects of IPython's functionality in:\n"""
1018 else:
1023 else:
1019 print 'I am going to upgrade your configuration in:'
1024 print 'I am going to upgrade your configuration in:'
1020
1025
1021 print ipythondir
1026 print ipythondir
1022
1027
1023 rcdirend = os.path.join('IPython','UserConfig')
1028 rcdirend = os.path.join('IPython','UserConfig')
1024 cfg = lambda d: os.path.join(d,rcdirend)
1029 cfg = lambda d: os.path.join(d,rcdirend)
1025 try:
1030 try:
1026 rcdir = filter(os.path.isdir,map(cfg,sys.path))[0]
1031 rcdir = filter(os.path.isdir,map(cfg,sys.path))[0]
1027 except IOError:
1032 except IOError:
1028 warning = """
1033 warning = """
1029 Installation error. IPython's directory was not found.
1034 Installation error. IPython's directory was not found.
1030
1035
1031 Check the following:
1036 Check the following:
1032
1037
1033 The ipython/IPython directory should be in a directory belonging to your
1038 The ipython/IPython directory should be in a directory belonging to your
1034 PYTHONPATH environment variable (that is, it should be in a directory
1039 PYTHONPATH environment variable (that is, it should be in a directory
1035 belonging to sys.path). You can copy it explicitly there or just link to it.
1040 belonging to sys.path). You can copy it explicitly there or just link to it.
1036
1041
1037 IPython will proceed with builtin defaults.
1042 IPython will proceed with builtin defaults.
1038 """
1043 """
1039 warn(warning)
1044 warn(warning)
1040 wait()
1045 wait()
1041 return
1046 return
1042
1047
1043 if mode == 'install':
1048 if mode == 'install':
1044 try:
1049 try:
1045 shutil.copytree(rcdir,ipythondir)
1050 shutil.copytree(rcdir,ipythondir)
1046 os.chdir(ipythondir)
1051 os.chdir(ipythondir)
1047 rc_files = glb("ipythonrc*")
1052 rc_files = glb("ipythonrc*")
1048 for rc_file in rc_files:
1053 for rc_file in rc_files:
1049 os.rename(rc_file,rc_file+rc_suffix)
1054 os.rename(rc_file,rc_file+rc_suffix)
1050 except:
1055 except:
1051 warning = """
1056 warning = """
1052
1057
1053 There was a problem with the installation:
1058 There was a problem with the installation:
1054 %s
1059 %s
1055 Try to correct it or contact the developers if you think it's a bug.
1060 Try to correct it or contact the developers if you think it's a bug.
1056 IPython will proceed with builtin defaults.""" % sys.exc_info()[1]
1061 IPython will proceed with builtin defaults.""" % sys.exc_info()[1]
1057 warn(warning)
1062 warn(warning)
1058 wait()
1063 wait()
1059 return
1064 return
1060
1065
1061 elif mode == 'upgrade':
1066 elif mode == 'upgrade':
1062 try:
1067 try:
1063 os.chdir(ipythondir)
1068 os.chdir(ipythondir)
1064 except:
1069 except:
1065 print """
1070 print """
1066 Can not upgrade: changing to directory %s failed. Details:
1071 Can not upgrade: changing to directory %s failed. Details:
1067 %s
1072 %s
1068 """ % (ipythondir,sys.exc_info()[1])
1073 """ % (ipythondir,sys.exc_info()[1])
1069 wait()
1074 wait()
1070 return
1075 return
1071 else:
1076 else:
1072 sources = glb(os.path.join(rcdir,'[A-Za-z]*'))
1077 sources = glb(os.path.join(rcdir,'[A-Za-z]*'))
1073 for new_full_path in sources:
1078 for new_full_path in sources:
1074 new_filename = os.path.basename(new_full_path)
1079 new_filename = os.path.basename(new_full_path)
1075 if new_filename.startswith('ipythonrc'):
1080 if new_filename.startswith('ipythonrc'):
1076 new_filename = new_filename + rc_suffix
1081 new_filename = new_filename + rc_suffix
1077 # The config directory should only contain files, skip any
1082 # The config directory should only contain files, skip any
1078 # directories which may be there (like CVS)
1083 # directories which may be there (like CVS)
1079 if os.path.isdir(new_full_path):
1084 if os.path.isdir(new_full_path):
1080 continue
1085 continue
1081 if os.path.exists(new_filename):
1086 if os.path.exists(new_filename):
1082 old_file = new_filename+'.old'
1087 old_file = new_filename+'.old'
1083 if os.path.exists(old_file):
1088 if os.path.exists(old_file):
1084 os.remove(old_file)
1089 os.remove(old_file)
1085 os.rename(new_filename,old_file)
1090 os.rename(new_filename,old_file)
1086 shutil.copy(new_full_path,new_filename)
1091 shutil.copy(new_full_path,new_filename)
1087 else:
1092 else:
1088 raise ValueError,'unrecognized mode for install:',`mode`
1093 raise ValueError,'unrecognized mode for install:',`mode`
1089
1094
1090 # Fix line-endings to those native to each platform in the config
1095 # Fix line-endings to those native to each platform in the config
1091 # directory.
1096 # directory.
1092 try:
1097 try:
1093 os.chdir(ipythondir)
1098 os.chdir(ipythondir)
1094 except:
1099 except:
1095 print """
1100 print """
1096 Problem: changing to directory %s failed.
1101 Problem: changing to directory %s failed.
1097 Details:
1102 Details:
1098 %s
1103 %s
1099
1104
1100 Some configuration files may have incorrect line endings. This should not
1105 Some configuration files may have incorrect line endings. This should not
1101 cause any problems during execution. """ % (ipythondir,sys.exc_info()[1])
1106 cause any problems during execution. """ % (ipythondir,sys.exc_info()[1])
1102 wait()
1107 wait()
1103 else:
1108 else:
1104 for fname in glb('ipythonrc*'):
1109 for fname in glb('ipythonrc*'):
1105 try:
1110 try:
1106 native_line_ends(fname,backup=0)
1111 native_line_ends(fname,backup=0)
1107 except IOError:
1112 except IOError:
1108 pass
1113 pass
1109
1114
1110 if mode == 'install':
1115 if mode == 'install':
1111 print """
1116 print """
1112 Successful installation!
1117 Successful installation!
1113
1118
1114 Please read the sections 'Initial Configuration' and 'Quick Tips' in the
1119 Please read the sections 'Initial Configuration' and 'Quick Tips' in the
1115 IPython manual (there are both HTML and PDF versions supplied with the
1120 IPython manual (there are both HTML and PDF versions supplied with the
1116 distribution) to make sure that your system environment is properly configured
1121 distribution) to make sure that your system environment is properly configured
1117 to take advantage of IPython's features."""
1122 to take advantage of IPython's features."""
1118 else:
1123 else:
1119 print """
1124 print """
1120 Successful upgrade!
1125 Successful upgrade!
1121
1126
1122 All files in your directory:
1127 All files in your directory:
1123 %(ipythondir)s
1128 %(ipythondir)s
1124 which would have been overwritten by the upgrade were backed up with a .old
1129 which would have been overwritten by the upgrade were backed up with a .old
1125 extension. If you had made particular customizations in those files you may
1130 extension. If you had made particular customizations in those files you may
1126 want to merge them back into the new files.""" % locals()
1131 want to merge them back into the new files.""" % locals()
1127 wait()
1132 wait()
1128 os.chdir(cwd)
1133 os.chdir(cwd)
1129 # end user_setup()
1134 # end user_setup()
1130
1135
1131 def atexit_operations(self):
1136 def atexit_operations(self):
1132 """This will be executed at the time of exit.
1137 """This will be executed at the time of exit.
1133
1138
1134 Saving of persistent data should be performed here. """
1139 Saving of persistent data should be performed here. """
1135
1140
1136 # input history
1141 # input history
1137 self.savehist()
1142 self.savehist()
1138
1143
1139 # Cleanup all tempfiles left around
1144 # Cleanup all tempfiles left around
1140 for tfile in self.tempfiles:
1145 for tfile in self.tempfiles:
1141 try:
1146 try:
1142 os.unlink(tfile)
1147 os.unlink(tfile)
1143 except OSError:
1148 except OSError:
1144 pass
1149 pass
1145
1150
1146 # save the "persistent data" catch-all dictionary
1151 # save the "persistent data" catch-all dictionary
1147 try:
1152 try:
1148 pickle.dump(self.persist, open(self.persist_fname,"w"))
1153 pickle.dump(self.persist, open(self.persist_fname,"w"))
1149 except:
1154 except:
1150 print "*** ERROR *** persistent data saving failed."
1155 print "*** ERROR *** persistent data saving failed."
1151
1156
1152 def savehist(self):
1157 def savehist(self):
1153 """Save input history to a file (via readline library)."""
1158 """Save input history to a file (via readline library)."""
1154 try:
1159 try:
1155 self.readline.write_history_file(self.histfile)
1160 self.readline.write_history_file(self.histfile)
1156 except:
1161 except:
1157 print 'Unable to save IPython command history to file: ' + \
1162 print 'Unable to save IPython command history to file: ' + \
1158 `self.histfile`
1163 `self.histfile`
1159
1164
1160 def pre_readline(self):
1165 def pre_readline(self):
1161 """readline hook to be used at the start of each line.
1166 """readline hook to be used at the start of each line.
1162
1167
1163 Currently it handles auto-indent only."""
1168 Currently it handles auto-indent only."""
1164
1169
1165 self.readline.insert_text(' '* self.readline_indent)
1170 self.readline.insert_text(' '* self.readline_indent)
1166
1171
1167 def init_readline(self):
1172 def init_readline(self):
1168 """Command history completion/saving/reloading."""
1173 """Command history completion/saving/reloading."""
1169 try:
1174 try:
1170 import readline
1175 import readline
1171 self.Completer = MagicCompleter(self,
1176 self.Completer = MagicCompleter(self,
1172 self.user_ns,
1177 self.user_ns,
1173 self.rc.readline_omit__names,
1178 self.rc.readline_omit__names,
1174 self.alias_table)
1179 self.alias_table)
1175 except ImportError,NameError:
1180 except ImportError,NameError:
1176 # If FlexCompleter failed to import, MagicCompleter won't be
1181 # If FlexCompleter failed to import, MagicCompleter won't be
1177 # defined. This can happen because of a problem with readline
1182 # defined. This can happen because of a problem with readline
1178 self.has_readline = 0
1183 self.has_readline = 0
1179 # no point in bugging windows users with this every time:
1184 # no point in bugging windows users with this every time:
1180 if os.name == 'posix':
1185 if os.name == 'posix':
1181 warn('Readline services not available on this platform.')
1186 warn('Readline services not available on this platform.')
1182 else:
1187 else:
1183 import atexit
1188 import atexit
1184
1189
1185 # Platform-specific configuration
1190 # Platform-specific configuration
1186 if os.name == 'nt':
1191 if os.name == 'nt':
1187 # readline under Windows modifies the default exit behavior
1192 # readline under Windows modifies the default exit behavior
1188 # from being Ctrl-Z/Return to the Unix Ctrl-D one.
1193 # from being Ctrl-Z/Return to the Unix Ctrl-D one.
1189 __builtin__.exit = __builtin__.quit = \
1194 __builtin__.exit = __builtin__.quit = \
1190 ('Use Ctrl-D (i.e. EOF) to exit. '
1195 ('Use Ctrl-D (i.e. EOF) to exit. '
1191 'Use %Exit or %Quit to exit without confirmation.')
1196 'Use %Exit or %Quit to exit without confirmation.')
1192 self.readline_startup_hook = readline.set_pre_input_hook
1197 self.readline_startup_hook = readline.set_pre_input_hook
1193 else:
1198 else:
1194 self.readline_startup_hook = readline.set_startup_hook
1199 self.readline_startup_hook = readline.set_startup_hook
1195
1200
1196 # Load user's initrc file (readline config)
1201 # Load user's initrc file (readline config)
1197 inputrc_name = os.environ.get('INPUTRC')
1202 inputrc_name = os.environ.get('INPUTRC')
1198 if inputrc_name is None:
1203 if inputrc_name is None:
1199 home_dir = get_home_dir()
1204 home_dir = get_home_dir()
1200 if home_dir is not None:
1205 if home_dir is not None:
1201 inputrc_name = os.path.join(home_dir,'.inputrc')
1206 inputrc_name = os.path.join(home_dir,'.inputrc')
1202 if os.path.isfile(inputrc_name):
1207 if os.path.isfile(inputrc_name):
1203 try:
1208 try:
1204 readline.read_init_file(inputrc_name)
1209 readline.read_init_file(inputrc_name)
1205 except:
1210 except:
1206 warn('Problems reading readline initialization file <%s>'
1211 warn('Problems reading readline initialization file <%s>'
1207 % inputrc_name)
1212 % inputrc_name)
1208
1213
1209 self.has_readline = 1
1214 self.has_readline = 1
1210 self.readline = readline
1215 self.readline = readline
1211 self.readline_indent = 0 # for auto-indenting via readline
1216 self.readline_indent = 0 # for auto-indenting via readline
1212 # save this in sys so embedded copies can restore it properly
1217 # save this in sys so embedded copies can restore it properly
1213 sys.ipcompleter = self.Completer.complete
1218 sys.ipcompleter = self.Completer.complete
1214 readline.set_completer(self.Completer.complete)
1219 readline.set_completer(self.Completer.complete)
1215
1220
1216 # Configure readline according to user's prefs
1221 # Configure readline according to user's prefs
1217 for rlcommand in self.rc.readline_parse_and_bind:
1222 for rlcommand in self.rc.readline_parse_and_bind:
1218 readline.parse_and_bind(rlcommand)
1223 readline.parse_and_bind(rlcommand)
1219
1224
1220 # remove some chars from the delimiters list
1225 # remove some chars from the delimiters list
1221 delims = readline.get_completer_delims()
1226 delims = readline.get_completer_delims()
1222 delims = delims.translate(string._idmap,
1227 delims = delims.translate(string._idmap,
1223 self.rc.readline_remove_delims)
1228 self.rc.readline_remove_delims)
1224 readline.set_completer_delims(delims)
1229 readline.set_completer_delims(delims)
1225 # otherwise we end up with a monster history after a while:
1230 # otherwise we end up with a monster history after a while:
1226 readline.set_history_length(1000)
1231 readline.set_history_length(1000)
1227 try:
1232 try:
1228 #print '*** Reading readline history' # dbg
1233 #print '*** Reading readline history' # dbg
1229 readline.read_history_file(self.histfile)
1234 readline.read_history_file(self.histfile)
1230 except IOError:
1235 except IOError:
1231 pass # It doesn't exist yet.
1236 pass # It doesn't exist yet.
1232
1237
1233 atexit.register(self.atexit_operations)
1238 atexit.register(self.atexit_operations)
1234 del atexit
1239 del atexit
1235
1240
1236 # Configure auto-indent for all platforms
1241 # Configure auto-indent for all platforms
1237 self.set_autoindent(self.rc.autoindent)
1242 self.set_autoindent(self.rc.autoindent)
1238
1243
1239 def showsyntaxerror(self, filename=None):
1244 def showsyntaxerror(self, filename=None):
1240 """Display the syntax error that just occurred.
1245 """Display the syntax error that just occurred.
1241
1246
1242 This doesn't display a stack trace because there isn't one.
1247 This doesn't display a stack trace because there isn't one.
1243
1248
1244 If a filename is given, it is stuffed in the exception instead
1249 If a filename is given, it is stuffed in the exception instead
1245 of what was there before (because Python's parser always uses
1250 of what was there before (because Python's parser always uses
1246 "<string>" when reading from a string).
1251 "<string>" when reading from a string).
1247 """
1252 """
1248 type, value, sys.last_traceback = sys.exc_info()
1253 type, value, sys.last_traceback = sys.exc_info()
1249 sys.last_type = type
1254 sys.last_type = type
1250 sys.last_value = value
1255 sys.last_value = value
1251 if filename and type is SyntaxError:
1256 if filename and type is SyntaxError:
1252 # Work hard to stuff the correct filename in the exception
1257 # Work hard to stuff the correct filename in the exception
1253 try:
1258 try:
1254 msg, (dummy_filename, lineno, offset, line) = value
1259 msg, (dummy_filename, lineno, offset, line) = value
1255 except:
1260 except:
1256 # Not the format we expect; leave it alone
1261 # Not the format we expect; leave it alone
1257 pass
1262 pass
1258 else:
1263 else:
1259 # Stuff in the right filename
1264 # Stuff in the right filename
1260 try:
1265 try:
1261 # Assume SyntaxError is a class exception
1266 # Assume SyntaxError is a class exception
1262 value = SyntaxError(msg, (filename, lineno, offset, line))
1267 value = SyntaxError(msg, (filename, lineno, offset, line))
1263 except:
1268 except:
1264 # If that failed, assume SyntaxError is a string
1269 # If that failed, assume SyntaxError is a string
1265 value = msg, (filename, lineno, offset, line)
1270 value = msg, (filename, lineno, offset, line)
1266 self.SyntaxTB(type,value,[])
1271 self.SyntaxTB(type,value,[])
1267
1272
1268 def debugger(self):
1273 def debugger(self):
1269 """Call the pdb debugger."""
1274 """Call the pdb debugger."""
1270
1275
1271 if not self.rc.pdb:
1276 if not self.rc.pdb:
1272 return
1277 return
1273 pdb.pm()
1278 pdb.pm()
1274
1279
1275 def showtraceback(self,exc_tuple = None,filename=None):
1280 def showtraceback(self,exc_tuple = None,filename=None):
1276 """Display the exception that just occurred."""
1281 """Display the exception that just occurred."""
1277
1282
1278 # Though this won't be called by syntax errors in the input line,
1283 # Though this won't be called by syntax errors in the input line,
1279 # there may be SyntaxError cases whith imported code.
1284 # there may be SyntaxError cases whith imported code.
1280 if exc_tuple is None:
1285 if exc_tuple is None:
1281 type, value, tb = sys.exc_info()
1286 type, value, tb = sys.exc_info()
1282 else:
1287 else:
1283 type, value, tb = exc_tuple
1288 type, value, tb = exc_tuple
1284 if type is SyntaxError:
1289 if type is SyntaxError:
1285 self.showsyntaxerror(filename)
1290 self.showsyntaxerror(filename)
1286 else:
1291 else:
1287 sys.last_type = type
1292 sys.last_type = type
1288 sys.last_value = value
1293 sys.last_value = value
1289 sys.last_traceback = tb
1294 sys.last_traceback = tb
1290 self.InteractiveTB()
1295 self.InteractiveTB()
1291 if self.InteractiveTB.call_pdb and self.has_readline:
1296 if self.InteractiveTB.call_pdb and self.has_readline:
1292 # pdb mucks up readline, fix it back
1297 # pdb mucks up readline, fix it back
1293 self.readline.set_completer(self.Completer.complete)
1298 self.readline.set_completer(self.Completer.complete)
1294
1299
1295 def update_cache(self, line):
1300 def update_cache(self, line):
1296 """puts line into cache"""
1301 """puts line into cache"""
1297 self.inputcache.insert(0, line) # This copies the cache every time ... :-(
1302 self.inputcache.insert(0, line) # This copies the cache every time ... :-(
1298 if len(self.inputcache) >= self.CACHELENGTH:
1303 if len(self.inputcache) >= self.CACHELENGTH:
1299 self.inputcache.pop() # This not :-)
1304 self.inputcache.pop() # This not :-)
1300
1305
1301 def name_space_init(self):
1306 def name_space_init(self):
1302 """Create local namespace."""
1307 """Create local namespace."""
1303 # We want this to be a method to facilitate embedded initialization.
1308 # We want this to be a method to facilitate embedded initialization.
1304 code.InteractiveConsole.__init__(self,self.user_ns)
1309 code.InteractiveConsole.__init__(self,self.user_ns)
1305
1310
1306 def mainloop(self,banner=None):
1311 def mainloop(self,banner=None):
1307 """Creates the local namespace and starts the mainloop.
1312 """Creates the local namespace and starts the mainloop.
1308
1313
1309 If an optional banner argument is given, it will override the
1314 If an optional banner argument is given, it will override the
1310 internally created default banner."""
1315 internally created default banner."""
1311
1316
1312 self.name_space_init()
1317 self.name_space_init()
1313 if self.rc.c: # Emulate Python's -c option
1318 if self.rc.c: # Emulate Python's -c option
1314 self.exec_init_cmd()
1319 self.exec_init_cmd()
1315 if banner is None:
1320 if banner is None:
1316 if self.rc.banner:
1321 if self.rc.banner:
1317 banner = self.BANNER+self.banner2
1322 banner = self.BANNER+self.banner2
1318 else:
1323 else:
1319 banner = ''
1324 banner = ''
1320 self.interact(banner)
1325 self.interact(banner)
1321
1326
1322 def exec_init_cmd(self):
1327 def exec_init_cmd(self):
1323 """Execute a command given at the command line.
1328 """Execute a command given at the command line.
1324
1329
1325 This emulates Python's -c option."""
1330 This emulates Python's -c option."""
1326
1331
1327 sys.argv = ['-c']
1332 sys.argv = ['-c']
1328 self.push(self.rc.c)
1333 self.push(self.rc.c)
1329
1334
1330 def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
1335 def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
1331 """Embeds IPython into a running python program.
1336 """Embeds IPython into a running python program.
1332
1337
1333 Input:
1338 Input:
1334
1339
1335 - header: An optional header message can be specified.
1340 - header: An optional header message can be specified.
1336
1341
1337 - local_ns, global_ns: working namespaces. If given as None, the
1342 - local_ns, global_ns: working namespaces. If given as None, the
1338 IPython-initialized one is updated with __main__.__dict__, so that
1343 IPython-initialized one is updated with __main__.__dict__, so that
1339 program variables become visible but user-specific configuration
1344 program variables become visible but user-specific configuration
1340 remains possible.
1345 remains possible.
1341
1346
1342 - stack_depth: specifies how many levels in the stack to go to
1347 - stack_depth: specifies how many levels in the stack to go to
1343 looking for namespaces (when local_ns and global_ns are None). This
1348 looking for namespaces (when local_ns and global_ns are None). This
1344 allows an intermediate caller to make sure that this function gets
1349 allows an intermediate caller to make sure that this function gets
1345 the namespace from the intended level in the stack. By default (0)
1350 the namespace from the intended level in the stack. By default (0)
1346 it will get its locals and globals from the immediate caller.
1351 it will get its locals and globals from the immediate caller.
1347
1352
1348 Warning: it's possible to use this in a program which is being run by
1353 Warning: it's possible to use this in a program which is being run by
1349 IPython itself (via %run), but some funny things will happen (a few
1354 IPython itself (via %run), but some funny things will happen (a few
1350 globals get overwritten). In the future this will be cleaned up, as
1355 globals get overwritten). In the future this will be cleaned up, as
1351 there is no fundamental reason why it can't work perfectly."""
1356 there is no fundamental reason why it can't work perfectly."""
1352
1357
1353 # Patch for global embedding to make sure that things don't overwrite
1358 # Patch for global embedding to make sure that things don't overwrite
1354 # user globals accidentally. Thanks to Richard <rxe@renre-europe.com>
1359 # user globals accidentally. Thanks to Richard <rxe@renre-europe.com>
1355 # FIXME. Test this a bit more carefully (the if.. is new)
1360 # FIXME. Test this a bit more carefully (the if.. is new)
1356 if local_ns is None and global_ns is None:
1361 if local_ns is None and global_ns is None:
1357 self.user_ns.update(__main__.__dict__)
1362 self.user_ns.update(__main__.__dict__)
1358
1363
1359 # Get locals and globals from caller
1364 # Get locals and globals from caller
1360 if local_ns is None or global_ns is None:
1365 if local_ns is None or global_ns is None:
1361 call_frame = sys._getframe(stack_depth).f_back
1366 call_frame = sys._getframe(stack_depth).f_back
1362
1367
1363 if local_ns is None:
1368 if local_ns is None:
1364 local_ns = call_frame.f_locals
1369 local_ns = call_frame.f_locals
1365 if global_ns is None:
1370 if global_ns is None:
1366 global_ns = call_frame.f_globals
1371 global_ns = call_frame.f_globals
1367
1372
1368 # Update namespaces and fire up interpreter
1373 # Update namespaces and fire up interpreter
1369 self.user_ns.update(local_ns)
1374 self.user_ns.update(local_ns)
1370 self.interact(header)
1375 self.interact(header)
1371
1376
1372 # Remove locals from namespace
1377 # Remove locals from namespace
1373 for k in local_ns:
1378 for k in local_ns:
1374 del self.user_ns[k]
1379 del self.user_ns[k]
1375
1380
1376 def interact(self, banner=None):
1381 def interact(self, banner=None):
1377 """Closely emulate the interactive Python console.
1382 """Closely emulate the interactive Python console.
1378
1383
1379 The optional banner argument specify the banner to print
1384 The optional banner argument specify the banner to print
1380 before the first interaction; by default it prints a banner
1385 before the first interaction; by default it prints a banner
1381 similar to the one printed by the real Python interpreter,
1386 similar to the one printed by the real Python interpreter,
1382 followed by the current class name in parentheses (so as not
1387 followed by the current class name in parentheses (so as not
1383 to confuse this with the real interpreter -- since it's so
1388 to confuse this with the real interpreter -- since it's so
1384 close!).
1389 close!).
1385
1390
1386 """
1391 """
1387 cprt = 'Type "copyright", "credits" or "license" for more information.'
1392 cprt = 'Type "copyright", "credits" or "license" for more information.'
1388 if banner is None:
1393 if banner is None:
1389 self.write("Python %s on %s\n%s\n(%s)\n" %
1394 self.write("Python %s on %s\n%s\n(%s)\n" %
1390 (sys.version, sys.platform, cprt,
1395 (sys.version, sys.platform, cprt,
1391 self.__class__.__name__))
1396 self.__class__.__name__))
1392 else:
1397 else:
1393 self.write(banner)
1398 self.write(banner)
1394
1399
1395 more = 0
1400 more = 0
1396
1401
1397 # Mark activity in the builtins
1402 # Mark activity in the builtins
1398 __builtin__.__dict__['__IPYTHON__active'] += 1
1403 __builtin__.__dict__['__IPYTHON__active'] += 1
1399
1404
1400 # exit_now is set by a call to %Exit or %Quit
1405 # exit_now is set by a call to %Exit or %Quit
1401 while not self.exit_now:
1406 while not self.exit_now:
1402 try:
1407 try:
1403 if more:
1408 if more:
1404 prompt = self.outputcache.prompt2
1409 prompt = self.outputcache.prompt2
1405 if self.autoindent:
1410 if self.autoindent:
1406 self.readline_startup_hook(self.pre_readline)
1411 self.readline_startup_hook(self.pre_readline)
1407 else:
1412 else:
1408 prompt = self.outputcache.prompt1
1413 prompt = self.outputcache.prompt1
1409 try:
1414 try:
1410 line = self.raw_input(prompt)
1415 line = self.raw_input(prompt)
1411 if self.autoindent:
1416 if self.autoindent:
1412 self.readline_startup_hook(None)
1417 self.readline_startup_hook(None)
1413 except EOFError:
1418 except EOFError:
1414 if self.autoindent:
1419 if self.autoindent:
1415 self.readline_startup_hook(None)
1420 self.readline_startup_hook(None)
1416 self.write("\n")
1421 self.write("\n")
1417 if self.rc.confirm_exit:
1422 if self.rc.confirm_exit:
1418 if ask_yes_no('Do you really want to exit ([y]/n)?','y'):
1423 if ask_yes_no('Do you really want to exit ([y]/n)?','y'):
1419 break
1424 break
1420 else:
1425 else:
1421 break
1426 break
1422 else:
1427 else:
1423 more = self.push(line)
1428 more = self.push(line)
1424 # Auto-indent management
1429 # Auto-indent management
1425 if self.autoindent:
1430 if self.autoindent:
1426 if line:
1431 if line:
1427 ini_spaces = re.match('^(\s+)',line)
1432 ini_spaces = re.match('^(\s+)',line)
1428 if ini_spaces:
1433 if ini_spaces:
1429 nspaces = ini_spaces.end()
1434 nspaces = ini_spaces.end()
1430 else:
1435 else:
1431 nspaces = 0
1436 nspaces = 0
1432 self.readline_indent = nspaces
1437 self.readline_indent = nspaces
1433
1438
1434 if line[-1] == ':':
1439 if line[-1] == ':':
1435 self.readline_indent += 4
1440 self.readline_indent += 4
1436 elif re.match(r'^\s+raise|^\s+return',line):
1441 elif re.match(r'^\s+raise|^\s+return',line):
1437 self.readline_indent -= 4
1442 self.readline_indent -= 4
1438 else:
1443 else:
1439 self.readline_indent = 0
1444 self.readline_indent = 0
1440
1445
1441 except KeyboardInterrupt:
1446 except KeyboardInterrupt:
1442 self.write("\nKeyboardInterrupt\n")
1447 self.write("\nKeyboardInterrupt\n")
1443 self.resetbuffer()
1448 self.resetbuffer()
1444 more = 0
1449 more = 0
1445 # keep cache in sync with the prompt counter:
1450 # keep cache in sync with the prompt counter:
1446 self.outputcache.prompt_count -= 1
1451 self.outputcache.prompt_count -= 1
1447
1452
1448 if self.autoindent:
1453 if self.autoindent:
1449 self.readline_indent = 0
1454 self.readline_indent = 0
1450
1455
1451 except bdb.BdbQuit:
1456 except bdb.BdbQuit:
1452 warn("The Python debugger has exited with a BdbQuit exception.\n"
1457 warn("The Python debugger has exited with a BdbQuit exception.\n"
1453 "Because of how pdb handles the stack, it is impossible\n"
1458 "Because of how pdb handles the stack, it is impossible\n"
1454 "for IPython to properly format this particular exception.\n"
1459 "for IPython to properly format this particular exception.\n"
1455 "IPython will resume normal operation.")
1460 "IPython will resume normal operation.")
1456
1461
1457 # We are off again...
1462 # We are off again...
1458 __builtin__.__dict__['__IPYTHON__active'] -= 1
1463 __builtin__.__dict__['__IPYTHON__active'] -= 1
1459
1464
1460 def excepthook(self, type, value, tb):
1465 def excepthook(self, type, value, tb):
1461 """One more defense for GUI apps that call sys.excepthook.
1466 """One more defense for GUI apps that call sys.excepthook.
1462
1467
1463 GUI frameworks like wxPython trap exceptions and call
1468 GUI frameworks like wxPython trap exceptions and call
1464 sys.excepthook themselves. I guess this is a feature that
1469 sys.excepthook themselves. I guess this is a feature that
1465 enables them to keep running after exceptions that would
1470 enables them to keep running after exceptions that would
1466 otherwise kill their mainloop. This is a bother for IPython
1471 otherwise kill their mainloop. This is a bother for IPython
1467 which excepts to catch all of the program exceptions with a try:
1472 which excepts to catch all of the program exceptions with a try:
1468 except: statement.
1473 except: statement.
1469
1474
1470 Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
1475 Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
1471 any app directly invokes sys.excepthook, it will look to the user like
1476 any app directly invokes sys.excepthook, it will look to the user like
1472 IPython crashed. In order to work around this, we can disable the
1477 IPython crashed. In order to work around this, we can disable the
1473 CrashHandler and replace it with this excepthook instead, which prints a
1478 CrashHandler and replace it with this excepthook instead, which prints a
1474 regular traceback using our InteractiveTB. In this fashion, apps which
1479 regular traceback using our InteractiveTB. In this fashion, apps which
1475 call sys.excepthook will generate a regular-looking exception from
1480 call sys.excepthook will generate a regular-looking exception from
1476 IPython, and the CrashHandler will only be triggered by real IPython
1481 IPython, and the CrashHandler will only be triggered by real IPython
1477 crashes.
1482 crashes.
1478
1483
1479 This hook should be used sparingly, only in places which are not likely
1484 This hook should be used sparingly, only in places which are not likely
1480 to be true IPython errors.
1485 to be true IPython errors.
1481 """
1486 """
1482
1487
1483 self.InteractiveTB(type, value, tb, tb_offset=0)
1488 self.InteractiveTB(type, value, tb, tb_offset=0)
1484 if self.InteractiveTB.call_pdb and self.has_readline:
1489 if self.InteractiveTB.call_pdb and self.has_readline:
1485 self.readline.set_completer(self.Completer.complete)
1490 self.readline.set_completer(self.Completer.complete)
1486
1491
1487 def call_alias(self,alias,rest=''):
1492 def call_alias(self,alias,rest=''):
1488 """Call an alias given its name and the rest of the line.
1493 """Call an alias given its name and the rest of the line.
1489
1494
1490 This function MUST be given a proper alias, because it doesn't make
1495 This function MUST be given a proper alias, because it doesn't make
1491 any checks when looking up into the alias table. The caller is
1496 any checks when looking up into the alias table. The caller is
1492 responsible for invoking it only with a valid alias."""
1497 responsible for invoking it only with a valid alias."""
1493
1498
1494 #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg
1499 #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg
1495 nargs,cmd = self.alias_table[alias]
1500 nargs,cmd = self.alias_table[alias]
1496 # Expand the %l special to be the user's input line
1501 # Expand the %l special to be the user's input line
1497 if cmd.find('%l') >= 0:
1502 if cmd.find('%l') >= 0:
1498 cmd = cmd.replace('%l',rest)
1503 cmd = cmd.replace('%l',rest)
1499 rest = ''
1504 rest = ''
1500 if nargs==0:
1505 if nargs==0:
1501 # Simple, argument-less aliases
1506 # Simple, argument-less aliases
1502 cmd = '%s %s' % (cmd,rest)
1507 cmd = '%s %s' % (cmd,rest)
1503 else:
1508 else:
1504 # Handle aliases with positional arguments
1509 # Handle aliases with positional arguments
1505 args = rest.split(None,nargs)
1510 args = rest.split(None,nargs)
1506 if len(args)< nargs:
1511 if len(args)< nargs:
1507 error('Alias <%s> requires %s arguments, %s given.' %
1512 error('Alias <%s> requires %s arguments, %s given.' %
1508 (alias,nargs,len(args)))
1513 (alias,nargs,len(args)))
1509 return
1514 return
1510 cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:]))
1515 cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:]))
1511 # Now call the macro, evaluating in the user's namespace
1516 # Now call the macro, evaluating in the user's namespace
1512 try:
1517 try:
1513 self.system(cmd)
1518 self.system(cmd)
1514 except:
1519 except:
1515 self.showtraceback()
1520 self.showtraceback()
1516
1521
1517 def runlines(self,lines):
1522 def runlines(self,lines):
1518 """Run a string of one or more lines of source.
1523 """Run a string of one or more lines of source.
1519
1524
1520 This method is capable of running a string containing multiple source
1525 This method is capable of running a string containing multiple source
1521 lines, as if they had been entered at the IPython prompt. Since it
1526 lines, as if they had been entered at the IPython prompt. Since it
1522 exposes IPython's processing machinery, the given strings can contain
1527 exposes IPython's processing machinery, the given strings can contain
1523 magic calls (%magic), special shell access (!cmd), etc."""
1528 magic calls (%magic), special shell access (!cmd), etc."""
1524
1529
1525 # We must start with a clean buffer, in case this is run from an
1530 # We must start with a clean buffer, in case this is run from an
1526 # interactive IPython session (via a magic, for example).
1531 # interactive IPython session (via a magic, for example).
1527 self.resetbuffer()
1532 self.resetbuffer()
1528 lines = lines.split('\n')
1533 lines = lines.split('\n')
1529 more = 0
1534 more = 0
1530 for line in lines:
1535 for line in lines:
1531 # skip blank lines so we don't mess up the prompt counter, but do
1536 # skip blank lines so we don't mess up the prompt counter, but do
1532 # NOT skip even a blank line if we are in a code block (more is
1537 # NOT skip even a blank line if we are in a code block (more is
1533 # true)
1538 # true)
1534 if line or more:
1539 if line or more:
1535 more = self.push((self.prefilter(line,more)))
1540 more = self.push((self.prefilter(line,more)))
1536 # IPython's runsource returns None if there was an error
1541 # IPython's runsource returns None if there was an error
1537 # compiling the code. This allows us to stop processing right
1542 # compiling the code. This allows us to stop processing right
1538 # away, so the user gets the error message at the right place.
1543 # away, so the user gets the error message at the right place.
1539 if more is None:
1544 if more is None:
1540 break
1545 break
1541 # final newline in case the input didn't have it, so that the code
1546 # final newline in case the input didn't have it, so that the code
1542 # actually does get executed
1547 # actually does get executed
1543 if more:
1548 if more:
1544 self.push('\n')
1549 self.push('\n')
1545
1550
1546 def runsource(self, source, filename="<input>", symbol="single"):
1551 def runsource(self, source, filename="<input>", symbol="single"):
1547 """Compile and run some source in the interpreter.
1552 """Compile and run some source in the interpreter.
1548
1553
1549 Arguments are as for compile_command().
1554 Arguments are as for compile_command().
1550
1555
1551 One several things can happen:
1556 One several things can happen:
1552
1557
1553 1) The input is incorrect; compile_command() raised an
1558 1) The input is incorrect; compile_command() raised an
1554 exception (SyntaxError or OverflowError). A syntax traceback
1559 exception (SyntaxError or OverflowError). A syntax traceback
1555 will be printed by calling the showsyntaxerror() method.
1560 will be printed by calling the showsyntaxerror() method.
1556
1561
1557 2) The input is incomplete, and more input is required;
1562 2) The input is incomplete, and more input is required;
1558 compile_command() returned None. Nothing happens.
1563 compile_command() returned None. Nothing happens.
1559
1564
1560 3) The input is complete; compile_command() returned a code
1565 3) The input is complete; compile_command() returned a code
1561 object. The code is executed by calling self.runcode() (which
1566 object. The code is executed by calling self.runcode() (which
1562 also handles run-time exceptions, except for SystemExit).
1567 also handles run-time exceptions, except for SystemExit).
1563
1568
1564 The return value is:
1569 The return value is:
1565
1570
1566 - True in case 2
1571 - True in case 2
1567
1572
1568 - False in the other cases, unless an exception is raised, where
1573 - False in the other cases, unless an exception is raised, where
1569 None is returned instead. This can be used by external callers to
1574 None is returned instead. This can be used by external callers to
1570 know whether to continue feeding input or not.
1575 know whether to continue feeding input or not.
1571
1576
1572 The return value can be used to decide whether to use sys.ps1 or
1577 The return value can be used to decide whether to use sys.ps1 or
1573 sys.ps2 to prompt the next line."""
1578 sys.ps2 to prompt the next line."""
1574
1579
1575 try:
1580 try:
1576 code = self.compile(source, filename, symbol)
1581 code = self.compile(source, filename, symbol)
1577 except (OverflowError, SyntaxError, ValueError):
1582 except (OverflowError, SyntaxError, ValueError):
1578 # Case 1
1583 # Case 1
1579 self.showsyntaxerror(filename)
1584 self.showsyntaxerror(filename)
1580 return None
1585 return None
1581
1586
1582 if code is None:
1587 if code is None:
1583 # Case 2
1588 # Case 2
1584 return True
1589 return True
1585
1590
1586 # Case 3
1591 # Case 3
1587 # We store the code object so that threaded shells and
1592 # We store the code object so that threaded shells and
1588 # custom exception handlers can access all this info if needed.
1593 # custom exception handlers can access all this info if needed.
1589 # The source corresponding to this can be obtained from the
1594 # The source corresponding to this can be obtained from the
1590 # buffer attribute as '\n'.join(self.buffer).
1595 # buffer attribute as '\n'.join(self.buffer).
1591 self.code_to_run = code
1596 self.code_to_run = code
1592 # now actually execute the code object
1597 # now actually execute the code object
1593 if self.runcode(code) == 0:
1598 if self.runcode(code) == 0:
1594 return False
1599 return False
1595 else:
1600 else:
1596 return None
1601 return None
1597
1602
1598 def runcode(self,code_obj):
1603 def runcode(self,code_obj):
1599 """Execute a code object.
1604 """Execute a code object.
1600
1605
1601 When an exception occurs, self.showtraceback() is called to display a
1606 When an exception occurs, self.showtraceback() is called to display a
1602 traceback.
1607 traceback.
1603
1608
1604 Return value: a flag indicating whether the code to be run completed
1609 Return value: a flag indicating whether the code to be run completed
1605 successfully:
1610 successfully:
1606
1611
1607 - 0: successful execution.
1612 - 0: successful execution.
1608 - 1: an error occurred.
1613 - 1: an error occurred.
1609 """
1614 """
1610
1615
1611 # Set our own excepthook in case the user code tries to call it
1616 # Set our own excepthook in case the user code tries to call it
1612 # directly, so that the IPython crash handler doesn't get triggered
1617 # directly, so that the IPython crash handler doesn't get triggered
1613 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
1618 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
1614 outflag = 1 # happens in more places, so it's easier as default
1619 outflag = 1 # happens in more places, so it's easier as default
1615 try:
1620 try:
1616 try:
1621 try:
1617 exec code_obj in self.locals
1622 exec code_obj in self.locals
1618 finally:
1623 finally:
1619 # Reset our crash handler in place
1624 # Reset our crash handler in place
1620 sys.excepthook = old_excepthook
1625 sys.excepthook = old_excepthook
1621 except SystemExit:
1626 except SystemExit:
1622 self.resetbuffer()
1627 self.resetbuffer()
1623 self.showtraceback()
1628 self.showtraceback()
1624 warn( __builtin__.exit,level=1)
1629 warn( __builtin__.exit,level=1)
1625 except self.custom_exceptions:
1630 except self.custom_exceptions:
1626 etype,value,tb = sys.exc_info()
1631 etype,value,tb = sys.exc_info()
1627 self.CustomTB(etype,value,tb)
1632 self.CustomTB(etype,value,tb)
1628 except:
1633 except:
1629 self.showtraceback()
1634 self.showtraceback()
1630 else:
1635 else:
1631 outflag = 0
1636 outflag = 0
1632 if code.softspace(sys.stdout, 0):
1637 if code.softspace(sys.stdout, 0):
1633 print
1638 print
1634 # Flush out code object which has been run (and source)
1639 # Flush out code object which has been run (and source)
1635 self.code_to_run = None
1640 self.code_to_run = None
1636 return outflag
1641 return outflag
1637
1642
1638 def raw_input(self, prompt=""):
1643 def raw_input(self, prompt=""):
1639 """Write a prompt and read a line.
1644 """Write a prompt and read a line.
1640
1645
1641 The returned line does not include the trailing newline.
1646 The returned line does not include the trailing newline.
1642 When the user enters the EOF key sequence, EOFError is raised.
1647 When the user enters the EOF key sequence, EOFError is raised.
1643
1648
1644 The base implementation uses the built-in function
1649 The base implementation uses the built-in function
1645 raw_input(); a subclass may replace this with a different
1650 raw_input(); a subclass may replace this with a different
1646 implementation.
1651 implementation.
1647 """
1652 """
1648 return self.prefilter(raw_input_original(prompt),
1653 return self.prefilter(raw_input_original(prompt),
1649 prompt==self.outputcache.prompt2)
1654 prompt==self.outputcache.prompt2)
1650
1655
1651 def split_user_input(self,line):
1656 def split_user_input(self,line):
1652 """Split user input into pre-char, function part and rest."""
1657 """Split user input into pre-char, function part and rest."""
1653
1658
1654 lsplit = self.line_split.match(line)
1659 lsplit = self.line_split.match(line)
1655 if lsplit is None: # no regexp match returns None
1660 if lsplit is None: # no regexp match returns None
1656 try:
1661 try:
1657 iFun,theRest = line.split(None,1)
1662 iFun,theRest = line.split(None,1)
1658 except ValueError:
1663 except ValueError:
1659 iFun,theRest = line,''
1664 iFun,theRest = line,''
1660 pre = re.match('^(\s*)(.*)',line).groups()[0]
1665 pre = re.match('^(\s*)(.*)',line).groups()[0]
1661 else:
1666 else:
1662 pre,iFun,theRest = lsplit.groups()
1667 pre,iFun,theRest = lsplit.groups()
1663
1668
1664 #print 'line:<%s>' % line # dbg
1669 #print 'line:<%s>' % line # dbg
1665 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
1670 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
1666 return pre,iFun.strip(),theRest
1671 return pre,iFun.strip(),theRest
1667
1672
1668 def _prefilter(self, line, continue_prompt):
1673 def _prefilter(self, line, continue_prompt):
1669 """Calls different preprocessors, depending on the form of line."""
1674 """Calls different preprocessors, depending on the form of line."""
1670
1675
1671 # All handlers *must* return a value, even if it's blank ('').
1676 # All handlers *must* return a value, even if it's blank ('').
1672
1677
1673 # Lines are NOT logged here. Handlers should process the line as
1678 # Lines are NOT logged here. Handlers should process the line as
1674 # needed, update the cache AND log it (so that the input cache array
1679 # needed, update the cache AND log it (so that the input cache array
1675 # stays synced).
1680 # stays synced).
1676
1681
1677 # This function is _very_ delicate, and since it's also the one which
1682 # This function is _very_ delicate, and since it's also the one which
1678 # determines IPython's response to user input, it must be as efficient
1683 # determines IPython's response to user input, it must be as efficient
1679 # as possible. For this reason it has _many_ returns in it, trying
1684 # as possible. For this reason it has _many_ returns in it, trying
1680 # always to exit as quickly as it can figure out what it needs to do.
1685 # always to exit as quickly as it can figure out what it needs to do.
1681
1686
1682 # This function is the main responsible for maintaining IPython's
1687 # This function is the main responsible for maintaining IPython's
1683 # behavior respectful of Python's semantics. So be _very_ careful if
1688 # behavior respectful of Python's semantics. So be _very_ careful if
1684 # making changes to anything here.
1689 # making changes to anything here.
1685
1690
1686 #.....................................................................
1691 #.....................................................................
1687 # Code begins
1692 # Code begins
1688
1693
1689 #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg
1694 #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg
1690
1695
1691 # save the line away in case we crash, so the post-mortem handler can
1696 # save the line away in case we crash, so the post-mortem handler can
1692 # record it
1697 # record it
1693 self._last_input_line = line
1698 self._last_input_line = line
1694
1699
1695 #print '***line: <%s>' % line # dbg
1700 #print '***line: <%s>' % line # dbg
1696
1701
1697 # the input history needs to track even empty lines
1702 # the input history needs to track even empty lines
1698 if not line.strip():
1703 if not line.strip():
1699 if not continue_prompt:
1704 if not continue_prompt:
1700 self.outputcache.prompt_count -= 1
1705 self.outputcache.prompt_count -= 1
1701 return self.handle_normal('',continue_prompt)
1706 return self.handle_normal('',continue_prompt)
1702
1707
1703 # print '***cont',continue_prompt # dbg
1708 # print '***cont',continue_prompt # dbg
1704 # special handlers are only allowed for single line statements
1709 # special handlers are only allowed for single line statements
1705 if continue_prompt and not self.rc.multi_line_specials:
1710 if continue_prompt and not self.rc.multi_line_specials:
1706 return self.handle_normal(line,continue_prompt)
1711 return self.handle_normal(line,continue_prompt)
1707
1712
1708 # For the rest, we need the structure of the input
1713 # For the rest, we need the structure of the input
1709 pre,iFun,theRest = self.split_user_input(line)
1714 pre,iFun,theRest = self.split_user_input(line)
1710 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1715 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1711
1716
1712 # First check for explicit escapes in the last/first character
1717 # First check for explicit escapes in the last/first character
1713 handler = None
1718 handler = None
1714 if line[-1] == self.ESC_HELP:
1719 if line[-1] == self.ESC_HELP:
1715 handler = self.esc_handlers.get(line[-1]) # the ? can be at the end
1720 handler = self.esc_handlers.get(line[-1]) # the ? can be at the end
1716 if handler is None:
1721 if handler is None:
1717 # look at the first character of iFun, NOT of line, so we skip
1722 # look at the first character of iFun, NOT of line, so we skip
1718 # leading whitespace in multiline input
1723 # leading whitespace in multiline input
1719 handler = self.esc_handlers.get(iFun[0:1])
1724 handler = self.esc_handlers.get(iFun[0:1])
1720 if handler is not None:
1725 if handler is not None:
1721 return handler(line,continue_prompt,pre,iFun,theRest)
1726 return handler(line,continue_prompt,pre,iFun,theRest)
1722 # Emacs ipython-mode tags certain input lines
1727 # Emacs ipython-mode tags certain input lines
1723 if line.endswith('# PYTHON-MODE'):
1728 if line.endswith('# PYTHON-MODE'):
1724 return self.handle_emacs(line,continue_prompt)
1729 return self.handle_emacs(line,continue_prompt)
1725
1730
1726 # Next, check if we can automatically execute this thing
1731 # Next, check if we can automatically execute this thing
1727
1732
1728 # Allow ! in multi-line statements if multi_line_specials is on:
1733 # Allow ! in multi-line statements if multi_line_specials is on:
1729 if continue_prompt and self.rc.multi_line_specials and \
1734 if continue_prompt and self.rc.multi_line_specials and \
1730 iFun.startswith(self.ESC_SHELL):
1735 iFun.startswith(self.ESC_SHELL):
1731 return self.handle_shell_escape(line,continue_prompt,
1736 return self.handle_shell_escape(line,continue_prompt,
1732 pre=pre,iFun=iFun,
1737 pre=pre,iFun=iFun,
1733 theRest=theRest)
1738 theRest=theRest)
1734
1739
1735 # Let's try to find if the input line is a magic fn
1740 # Let's try to find if the input line is a magic fn
1736 oinfo = None
1741 oinfo = None
1737 if hasattr(self,'magic_'+iFun):
1742 if hasattr(self,'magic_'+iFun):
1738 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1743 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1739 if oinfo['ismagic']:
1744 if oinfo['ismagic']:
1740 # Be careful not to call magics when a variable assignment is
1745 # Be careful not to call magics when a variable assignment is
1741 # being made (ls='hi', for example)
1746 # being made (ls='hi', for example)
1742 if self.rc.automagic and \
1747 if self.rc.automagic and \
1743 (len(theRest)==0 or theRest[0] not in '!=()<>,') and \
1748 (len(theRest)==0 or theRest[0] not in '!=()<>,') and \
1744 (self.rc.multi_line_specials or not continue_prompt):
1749 (self.rc.multi_line_specials or not continue_prompt):
1745 return self.handle_magic(line,continue_prompt,
1750 return self.handle_magic(line,continue_prompt,
1746 pre,iFun,theRest)
1751 pre,iFun,theRest)
1747 else:
1752 else:
1748 return self.handle_normal(line,continue_prompt)
1753 return self.handle_normal(line,continue_prompt)
1749
1754
1750 # If the rest of the line begins with an (in)equality, assginment or
1755 # If the rest of the line begins with an (in)equality, assginment or
1751 # function call, we should not call _ofind but simply execute it.
1756 # function call, we should not call _ofind but simply execute it.
1752 # This avoids spurious geattr() accesses on objects upon assignment.
1757 # This avoids spurious geattr() accesses on objects upon assignment.
1753 #
1758 #
1754 # It also allows users to assign to either alias or magic names true
1759 # It also allows users to assign to either alias or magic names true
1755 # python variables (the magic/alias systems always take second seat to
1760 # python variables (the magic/alias systems always take second seat to
1756 # true python code).
1761 # true python code).
1757 if theRest and theRest[0] in '!=()':
1762 if theRest and theRest[0] in '!=()':
1758 return self.handle_normal(line,continue_prompt)
1763 return self.handle_normal(line,continue_prompt)
1759
1764
1760 if oinfo is None:
1765 if oinfo is None:
1761 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1766 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1762
1767
1763 if not oinfo['found']:
1768 if not oinfo['found']:
1764 return self.handle_normal(line,continue_prompt)
1769 return self.handle_normal(line,continue_prompt)
1765 else:
1770 else:
1766 #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg
1771 #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg
1767 if oinfo['isalias']:
1772 if oinfo['isalias']:
1768 return self.handle_alias(line,continue_prompt,
1773 return self.handle_alias(line,continue_prompt,
1769 pre,iFun,theRest)
1774 pre,iFun,theRest)
1770
1775
1771 if self.rc.autocall and \
1776 if self.rc.autocall and \
1772 not self.re_exclude_auto.match(theRest) and \
1777 not self.re_exclude_auto.match(theRest) and \
1773 self.re_fun_name.match(iFun) and \
1778 self.re_fun_name.match(iFun) and \
1774 callable(oinfo['obj']) :
1779 callable(oinfo['obj']) :
1775 #print 'going auto' # dbg
1780 #print 'going auto' # dbg
1776 return self.handle_auto(line,continue_prompt,pre,iFun,theRest)
1781 return self.handle_auto(line,continue_prompt,pre,iFun,theRest)
1777 else:
1782 else:
1778 #print 'was callable?', callable(oinfo['obj']) # dbg
1783 #print 'was callable?', callable(oinfo['obj']) # dbg
1779 return self.handle_normal(line,continue_prompt)
1784 return self.handle_normal(line,continue_prompt)
1780
1785
1781 # If we get here, we have a normal Python line. Log and return.
1786 # If we get here, we have a normal Python line. Log and return.
1782 return self.handle_normal(line,continue_prompt)
1787 return self.handle_normal(line,continue_prompt)
1783
1788
1784 def _prefilter_dumb(self, line, continue_prompt):
1789 def _prefilter_dumb(self, line, continue_prompt):
1785 """simple prefilter function, for debugging"""
1790 """simple prefilter function, for debugging"""
1786 return self.handle_normal(line,continue_prompt)
1791 return self.handle_normal(line,continue_prompt)
1787
1792
1788 # Set the default prefilter() function (this can be user-overridden)
1793 # Set the default prefilter() function (this can be user-overridden)
1789 prefilter = _prefilter
1794 prefilter = _prefilter
1790
1795
1791 def handle_normal(self,line,continue_prompt=None,
1796 def handle_normal(self,line,continue_prompt=None,
1792 pre=None,iFun=None,theRest=None):
1797 pre=None,iFun=None,theRest=None):
1793 """Handle normal input lines. Use as a template for handlers."""
1798 """Handle normal input lines. Use as a template for handlers."""
1794
1799
1795 self.log(line,continue_prompt)
1800 self.log(line,continue_prompt)
1796 self.update_cache(line)
1801 self.update_cache(line)
1797 return line
1802 return line
1798
1803
1799 def handle_alias(self,line,continue_prompt=None,
1804 def handle_alias(self,line,continue_prompt=None,
1800 pre=None,iFun=None,theRest=None):
1805 pre=None,iFun=None,theRest=None):
1801 """Handle alias input lines. """
1806 """Handle alias input lines. """
1802
1807
1803 theRest = esc_quotes(theRest)
1808 theRest = esc_quotes(theRest)
1804 line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest)
1809 line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest)
1805 self.log(line_out,continue_prompt)
1810 self.log(line_out,continue_prompt)
1806 self.update_cache(line_out)
1811 self.update_cache(line_out)
1807 return line_out
1812 return line_out
1808
1813
1809 def handle_shell_escape(self, line, continue_prompt=None,
1814 def handle_shell_escape(self, line, continue_prompt=None,
1810 pre=None,iFun=None,theRest=None):
1815 pre=None,iFun=None,theRest=None):
1811 """Execute the line in a shell, empty return value"""
1816 """Execute the line in a shell, empty return value"""
1812
1817
1813 #print 'line in :', `line` # dbg
1818 #print 'line in :', `line` # dbg
1814 # Example of a special handler. Others follow a similar pattern.
1819 # Example of a special handler. Others follow a similar pattern.
1815 if continue_prompt: # multi-line statements
1820 if continue_prompt: # multi-line statements
1816 if iFun.startswith('!!'):
1821 if iFun.startswith('!!'):
1817 print 'SyntaxError: !! is not allowed in multiline statements'
1822 print 'SyntaxError: !! is not allowed in multiline statements'
1818 return pre
1823 return pre
1819 else:
1824 else:
1820 cmd = ("%s %s" % (iFun[1:],theRest)).replace('"','\\"')
1825 cmd = ("%s %s" % (iFun[1:],theRest)).replace('"','\\"')
1821 line_out = '%s%s.system("%s")' % (pre,self.name,cmd)
1826 line_out = '%s%s.system("%s")' % (pre,self.name,cmd)
1822 #line_out = ('%s%s.system(' % (pre,self.name)) + repr(cmd) + ')'
1827 #line_out = ('%s%s.system(' % (pre,self.name)) + repr(cmd) + ')'
1823 else: # single-line input
1828 else: # single-line input
1824 if line.startswith('!!'):
1829 if line.startswith('!!'):
1825 # rewrite iFun/theRest to properly hold the call to %sx and
1830 # rewrite iFun/theRest to properly hold the call to %sx and
1826 # the actual command to be executed, so handle_magic can work
1831 # the actual command to be executed, so handle_magic can work
1827 # correctly
1832 # correctly
1828 theRest = '%s %s' % (iFun[2:],theRest)
1833 theRest = '%s %s' % (iFun[2:],theRest)
1829 iFun = 'sx'
1834 iFun = 'sx'
1830 return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]),
1835 return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]),
1831 continue_prompt,pre,iFun,theRest)
1836 continue_prompt,pre,iFun,theRest)
1832 else:
1837 else:
1833 cmd = esc_quotes(line[1:])
1838 cmd = esc_quotes(line[1:])
1834 line_out = '%s.system("%s")' % (self.name,cmd)
1839 line_out = '%s.system("%s")' % (self.name,cmd)
1835 #line_out = ('%s.system(' % self.name) + repr(cmd)+ ')'
1840 #line_out = ('%s.system(' % self.name) + repr(cmd)+ ')'
1836 # update cache/log and return
1841 # update cache/log and return
1837 self.log(line_out,continue_prompt)
1842 self.log(line_out,continue_prompt)
1838 self.update_cache(line_out) # readline cache gets normal line
1843 self.update_cache(line_out) # readline cache gets normal line
1839 #print 'line out r:', `line_out` # dbg
1844 #print 'line out r:', `line_out` # dbg
1840 #print 'line out s:', line_out # dbg
1845 #print 'line out s:', line_out # dbg
1841 return line_out
1846 return line_out
1842
1847
1843 def handle_magic(self, line, continue_prompt=None,
1848 def handle_magic(self, line, continue_prompt=None,
1844 pre=None,iFun=None,theRest=None):
1849 pre=None,iFun=None,theRest=None):
1845 """Execute magic functions.
1850 """Execute magic functions.
1846
1851
1847 Also log them with a prepended # so the log is clean Python."""
1852 Also log them with a prepended # so the log is clean Python."""
1848
1853
1849 cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest)))
1854 cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest)))
1850 self.log(cmd,continue_prompt)
1855 self.log(cmd,continue_prompt)
1851 self.update_cache(line)
1856 self.update_cache(line)
1852 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
1857 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
1853 return cmd
1858 return cmd
1854
1859
1855 def handle_auto(self, line, continue_prompt=None,
1860 def handle_auto(self, line, continue_prompt=None,
1856 pre=None,iFun=None,theRest=None):
1861 pre=None,iFun=None,theRest=None):
1857 """Hande lines which can be auto-executed, quoting if requested."""
1862 """Hande lines which can be auto-executed, quoting if requested."""
1858
1863
1859 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1864 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1860
1865
1861 # This should only be active for single-line input!
1866 # This should only be active for single-line input!
1862 if continue_prompt:
1867 if continue_prompt:
1863 return line
1868 return line
1864
1869
1865 if pre == self.ESC_QUOTE:
1870 if pre == self.ESC_QUOTE:
1866 # Auto-quote splitting on whitespace
1871 # Auto-quote splitting on whitespace
1867 newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) )
1872 newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) )
1868 elif pre == self.ESC_QUOTE2:
1873 elif pre == self.ESC_QUOTE2:
1869 # Auto-quote whole string
1874 # Auto-quote whole string
1870 newcmd = '%s("%s")' % (iFun,theRest)
1875 newcmd = '%s("%s")' % (iFun,theRest)
1871 else:
1876 else:
1872 # Auto-paren
1877 # Auto-paren
1873 if theRest[0:1] in ('=','['):
1878 if theRest[0:1] in ('=','['):
1874 # Don't autocall in these cases. They can be either
1879 # Don't autocall in these cases. They can be either
1875 # rebindings of an existing callable's name, or item access
1880 # rebindings of an existing callable's name, or item access
1876 # for an object which is BOTH callable and implements
1881 # for an object which is BOTH callable and implements
1877 # __getitem__.
1882 # __getitem__.
1878 return '%s %s' % (iFun,theRest)
1883 return '%s %s' % (iFun,theRest)
1879 if theRest.endswith(';'):
1884 if theRest.endswith(';'):
1880 newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1])
1885 newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1])
1881 else:
1886 else:
1882 newcmd = '%s(%s)' % (iFun.rstrip(),theRest)
1887 newcmd = '%s(%s)' % (iFun.rstrip(),theRest)
1883
1888
1884 print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd
1889 print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd
1885 # log what is now valid Python, not the actual user input (without the
1890 # log what is now valid Python, not the actual user input (without the
1886 # final newline)
1891 # final newline)
1887 self.log(newcmd,continue_prompt)
1892 self.log(newcmd,continue_prompt)
1888 return newcmd
1893 return newcmd
1889
1894
1890 def handle_help(self, line, continue_prompt=None,
1895 def handle_help(self, line, continue_prompt=None,
1891 pre=None,iFun=None,theRest=None):
1896 pre=None,iFun=None,theRest=None):
1892 """Try to get some help for the object.
1897 """Try to get some help for the object.
1893
1898
1894 obj? or ?obj -> basic information.
1899 obj? or ?obj -> basic information.
1895 obj?? or ??obj -> more details.
1900 obj?? or ??obj -> more details.
1896 """
1901 """
1897
1902
1898 # We need to make sure that we don't process lines which would be
1903 # We need to make sure that we don't process lines which would be
1899 # otherwise valid python, such as "x=1 # what?"
1904 # otherwise valid python, such as "x=1 # what?"
1900 try:
1905 try:
1901 code.compile_command(line)
1906 code.compile_command(line)
1902 except SyntaxError:
1907 except SyntaxError:
1903 # We should only handle as help stuff which is NOT valid syntax
1908 # We should only handle as help stuff which is NOT valid syntax
1904 if line[0]==self.ESC_HELP:
1909 if line[0]==self.ESC_HELP:
1905 line = line[1:]
1910 line = line[1:]
1906 elif line[-1]==self.ESC_HELP:
1911 elif line[-1]==self.ESC_HELP:
1907 line = line[:-1]
1912 line = line[:-1]
1908 self.log('#?'+line)
1913 self.log('#?'+line)
1909 self.update_cache(line)
1914 self.update_cache(line)
1910 if line:
1915 if line:
1911 self.magic_pinfo(line)
1916 self.magic_pinfo(line)
1912 else:
1917 else:
1913 page(self.usage,screen_lines=self.rc.screen_length)
1918 page(self.usage,screen_lines=self.rc.screen_length)
1914 return '' # Empty string is needed here!
1919 return '' # Empty string is needed here!
1915 except:
1920 except:
1916 # Pass any other exceptions through to the normal handler
1921 # Pass any other exceptions through to the normal handler
1917 return self.handle_normal(line,continue_prompt)
1922 return self.handle_normal(line,continue_prompt)
1918 else:
1923 else:
1919 # If the code compiles ok, we should handle it normally
1924 # If the code compiles ok, we should handle it normally
1920 return self.handle_normal(line,continue_prompt)
1925 return self.handle_normal(line,continue_prompt)
1921
1926
1922 def handle_emacs(self,line,continue_prompt=None,
1927 def handle_emacs(self,line,continue_prompt=None,
1923 pre=None,iFun=None,theRest=None):
1928 pre=None,iFun=None,theRest=None):
1924 """Handle input lines marked by python-mode."""
1929 """Handle input lines marked by python-mode."""
1925
1930
1926 # Currently, nothing is done. Later more functionality can be added
1931 # Currently, nothing is done. Later more functionality can be added
1927 # here if needed.
1932 # here if needed.
1928
1933
1929 # The input cache shouldn't be updated
1934 # The input cache shouldn't be updated
1930
1935
1931 return line
1936 return line
1932
1937
1933 def write(self,data):
1938 def write(self,data):
1934 """Write a string to the default output"""
1939 """Write a string to the default output"""
1935 Term.cout.write(data)
1940 Term.cout.write(data)
1936
1941
1937 def write_err(self,data):
1942 def write_err(self,data):
1938 """Write a string to the default error output"""
1943 """Write a string to the default error output"""
1939 Term.cerr.write(data)
1944 Term.cerr.write(data)
1940
1945
1941 def safe_execfile(self,fname,*where,**kw):
1946 def safe_execfile(self,fname,*where,**kw):
1942 fname = os.path.expanduser(fname)
1947 fname = os.path.expanduser(fname)
1943
1948
1944 # find things also in current directory
1949 # find things also in current directory
1945 dname = os.path.dirname(fname)
1950 dname = os.path.dirname(fname)
1946 if not sys.path.count(dname):
1951 if not sys.path.count(dname):
1947 sys.path.append(dname)
1952 sys.path.append(dname)
1948
1953
1949 try:
1954 try:
1950 xfile = open(fname)
1955 xfile = open(fname)
1951 except:
1956 except:
1952 print >> Term.cerr, \
1957 print >> Term.cerr, \
1953 'Could not open file <%s> for safe execution.' % fname
1958 'Could not open file <%s> for safe execution.' % fname
1954 return None
1959 return None
1955
1960
1956 kw.setdefault('islog',0)
1961 kw.setdefault('islog',0)
1957 kw.setdefault('quiet',1)
1962 kw.setdefault('quiet',1)
1958 kw.setdefault('exit_ignore',0)
1963 kw.setdefault('exit_ignore',0)
1959 first = xfile.readline()
1964 first = xfile.readline()
1960 _LOGHEAD = str(self.LOGHEAD).split('\n',1)[0].strip()
1965 _LOGHEAD = str(self.LOGHEAD).split('\n',1)[0].strip()
1961 xfile.close()
1966 xfile.close()
1962 # line by line execution
1967 # line by line execution
1963 if first.startswith(_LOGHEAD) or kw['islog']:
1968 if first.startswith(_LOGHEAD) or kw['islog']:
1964 print 'Loading log file <%s> one line at a time...' % fname
1969 print 'Loading log file <%s> one line at a time...' % fname
1965 if kw['quiet']:
1970 if kw['quiet']:
1966 stdout_save = sys.stdout
1971 stdout_save = sys.stdout
1967 sys.stdout = StringIO.StringIO()
1972 sys.stdout = StringIO.StringIO()
1968 try:
1973 try:
1969 globs,locs = where[0:2]
1974 globs,locs = where[0:2]
1970 except:
1975 except:
1971 try:
1976 try:
1972 globs = locs = where[0]
1977 globs = locs = where[0]
1973 except:
1978 except:
1974 globs = locs = globals()
1979 globs = locs = globals()
1975 badblocks = []
1980 badblocks = []
1976
1981
1977 # we also need to identify indented blocks of code when replaying
1982 # we also need to identify indented blocks of code when replaying
1978 # logs and put them together before passing them to an exec
1983 # logs and put them together before passing them to an exec
1979 # statement. This takes a bit of regexp and look-ahead work in the
1984 # statement. This takes a bit of regexp and look-ahead work in the
1980 # file. It's easiest if we swallow the whole thing in memory
1985 # file. It's easiest if we swallow the whole thing in memory
1981 # first, and manually walk through the lines list moving the
1986 # first, and manually walk through the lines list moving the
1982 # counter ourselves.
1987 # counter ourselves.
1983 indent_re = re.compile('\s+\S')
1988 indent_re = re.compile('\s+\S')
1984 xfile = open(fname)
1989 xfile = open(fname)
1985 filelines = xfile.readlines()
1990 filelines = xfile.readlines()
1986 xfile.close()
1991 xfile.close()
1987 nlines = len(filelines)
1992 nlines = len(filelines)
1988 lnum = 0
1993 lnum = 0
1989 while lnum < nlines:
1994 while lnum < nlines:
1990 line = filelines[lnum]
1995 line = filelines[lnum]
1991 lnum += 1
1996 lnum += 1
1992 # don't re-insert logger status info into cache
1997 # don't re-insert logger status info into cache
1993 if line.startswith('#log#'):
1998 if line.startswith('#log#'):
1994 continue
1999 continue
1995 elif line.startswith('#%s'% self.ESC_MAGIC):
2000 elif line.startswith('#%s'% self.ESC_MAGIC):
1996 self.update_cache(line[1:])
2001 self.update_cache(line[1:])
1997 line = magic2python(line)
2002 line = magic2python(line)
1998 elif line.startswith('#!'):
2003 elif line.startswith('#!'):
1999 self.update_cache(line[1:])
2004 self.update_cache(line[1:])
2000 else:
2005 else:
2001 # build a block of code (maybe a single line) for execution
2006 # build a block of code (maybe a single line) for execution
2002 block = line
2007 block = line
2003 try:
2008 try:
2004 next = filelines[lnum] # lnum has already incremented
2009 next = filelines[lnum] # lnum has already incremented
2005 except:
2010 except:
2006 next = None
2011 next = None
2007 while next and indent_re.match(next):
2012 while next and indent_re.match(next):
2008 block += next
2013 block += next
2009 lnum += 1
2014 lnum += 1
2010 try:
2015 try:
2011 next = filelines[lnum]
2016 next = filelines[lnum]
2012 except:
2017 except:
2013 next = None
2018 next = None
2014 # now execute the block of one or more lines
2019 # now execute the block of one or more lines
2015 try:
2020 try:
2016 exec block in globs,locs
2021 exec block in globs,locs
2017 self.update_cache(block.rstrip())
2022 self.update_cache(block.rstrip())
2018 except SystemExit:
2023 except SystemExit:
2019 pass
2024 pass
2020 except:
2025 except:
2021 badblocks.append(block.rstrip())
2026 badblocks.append(block.rstrip())
2022 if kw['quiet']: # restore stdout
2027 if kw['quiet']: # restore stdout
2023 sys.stdout.close()
2028 sys.stdout.close()
2024 sys.stdout = stdout_save
2029 sys.stdout = stdout_save
2025 print 'Finished replaying log file <%s>' % fname
2030 print 'Finished replaying log file <%s>' % fname
2026 if badblocks:
2031 if badblocks:
2027 print >> sys.stderr, \
2032 print >> sys.stderr, \
2028 '\nThe following lines/blocks in file <%s> reported errors:' \
2033 '\nThe following lines/blocks in file <%s> reported errors:' \
2029 % fname
2034 % fname
2030 for badline in badblocks:
2035 for badline in badblocks:
2031 print >> sys.stderr, badline
2036 print >> sys.stderr, badline
2032 else: # regular file execution
2037 else: # regular file execution
2033 try:
2038 try:
2034 execfile(fname,*where)
2039 execfile(fname,*where)
2035 except SyntaxError:
2040 except SyntaxError:
2036 etype, evalue = sys.exc_info()[0:2]
2041 etype, evalue = sys.exc_info()[0:2]
2037 self.SyntaxTB(etype,evalue,[])
2042 self.SyntaxTB(etype,evalue,[])
2038 warn('Failure executing file: <%s>' % fname)
2043 warn('Failure executing file: <%s>' % fname)
2039 except SystemExit,status:
2044 except SystemExit,status:
2040 if not kw['exit_ignore']:
2045 if not kw['exit_ignore']:
2041 self.InteractiveTB()
2046 self.InteractiveTB()
2042 warn('Failure executing file: <%s>' % fname)
2047 warn('Failure executing file: <%s>' % fname)
2043 except:
2048 except:
2044 self.InteractiveTB()
2049 self.InteractiveTB()
2045 warn('Failure executing file: <%s>' % fname)
2050 warn('Failure executing file: <%s>' % fname)
2046
2051
2047 #************************* end of file <iplib.py> *****************************
2052 #************************* end of file <iplib.py> *****************************
@@ -1,4399 +1,4406 b''
1 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/demo.py: finish demo module, fully documented now.
4
5 * IPython/genutils.py (file_read): simple little utility to read a
6 file and ensure it's closed afterwards.
7
1 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu>
8 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu>
2
9
3 * IPython/demo.py (Demo.__init__): added support for individually
10 * IPython/demo.py (Demo.__init__): added support for individually
4 tagging blocks for automatic execution.
11 tagging blocks for automatic execution.
5
12
6 * IPython/Magic.py (magic_pycat): new %pycat magic for showing
13 * IPython/Magic.py (magic_pycat): new %pycat magic for showing
7 syntax-highlighted python sources, requested by John.
14 syntax-highlighted python sources, requested by John.
8
15
9 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
16 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
10
17
11 * IPython/demo.py (Demo.again): fix bug where again() blocks after
18 * IPython/demo.py (Demo.again): fix bug where again() blocks after
12 finishing.
19 finishing.
13
20
14 * IPython/genutils.py (shlex_split): moved from Magic to here,
21 * IPython/genutils.py (shlex_split): moved from Magic to here,
15 where all 2.2 compatibility stuff lives. I needed it for demo.py.
22 where all 2.2 compatibility stuff lives. I needed it for demo.py.
16
23
17 * IPython/demo.py (Demo.__init__): added support for silent
24 * IPython/demo.py (Demo.__init__): added support for silent
18 blocks, improved marks as regexps, docstrings written.
25 blocks, improved marks as regexps, docstrings written.
19 (Demo.__init__): better docstring, added support for sys.argv.
26 (Demo.__init__): better docstring, added support for sys.argv.
20
27
21 * IPython/genutils.py (marquee): little utility used by the demo
28 * IPython/genutils.py (marquee): little utility used by the demo
22 code, handy in general.
29 code, handy in general.
23
30
24 * IPython/demo.py (Demo.__init__): new class for interactive
31 * IPython/demo.py (Demo.__init__): new class for interactive
25 demos. Not documented yet, I just wrote it in a hurry for
32 demos. Not documented yet, I just wrote it in a hurry for
26 scipy'05. Will docstring later.
33 scipy'05. Will docstring later.
27
34
28 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
35 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
29
36
30 * IPython/Shell.py (sigint_handler): Drastic simplification which
37 * IPython/Shell.py (sigint_handler): Drastic simplification which
31 also seems to make Ctrl-C work correctly across threads! This is
38 also seems to make Ctrl-C work correctly across threads! This is
32 so simple, that I can't beleive I'd missed it before. Needs more
39 so simple, that I can't beleive I'd missed it before. Needs more
33 testing, though.
40 testing, though.
34 (KBINT): Never mind, revert changes. I'm sure I'd tried something
41 (KBINT): Never mind, revert changes. I'm sure I'd tried something
35 like this before...
42 like this before...
36
43
37 * IPython/genutils.py (get_home_dir): add protection against
44 * IPython/genutils.py (get_home_dir): add protection against
38 non-dirs in win32 registry.
45 non-dirs in win32 registry.
39
46
40 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
47 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
41 bug where dict was mutated while iterating (pysh crash).
48 bug where dict was mutated while iterating (pysh crash).
42
49
43 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
50 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
44
51
45 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
52 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
46 spurious newlines added by this routine. After a report by
53 spurious newlines added by this routine. After a report by
47 F. Mantegazza.
54 F. Mantegazza.
48
55
49 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
56 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
50
57
51 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
58 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
52 calls. These were a leftover from the GTK 1.x days, and can cause
59 calls. These were a leftover from the GTK 1.x days, and can cause
53 problems in certain cases (after a report by John Hunter).
60 problems in certain cases (after a report by John Hunter).
54
61
55 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
62 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
56 os.getcwd() fails at init time. Thanks to patch from David Remahl
63 os.getcwd() fails at init time. Thanks to patch from David Remahl
57 <chmod007 AT mac.com>.
64 <chmod007 AT mac.com>.
58 (InteractiveShell.__init__): prevent certain special magics from
65 (InteractiveShell.__init__): prevent certain special magics from
59 being shadowed by aliases. Closes
66 being shadowed by aliases. Closes
60 http://www.scipy.net/roundup/ipython/issue41.
67 http://www.scipy.net/roundup/ipython/issue41.
61
68
62 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
69 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
63
70
64 * IPython/iplib.py (InteractiveShell.complete): Added new
71 * IPython/iplib.py (InteractiveShell.complete): Added new
65 top-level completion method to expose the completion mechanism
72 top-level completion method to expose the completion mechanism
66 beyond readline-based environments.
73 beyond readline-based environments.
67
74
68 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
75 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
69
76
70 * tools/ipsvnc (svnversion): fix svnversion capture.
77 * tools/ipsvnc (svnversion): fix svnversion capture.
71
78
72 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
79 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
73 attribute to self, which was missing. Before, it was set by a
80 attribute to self, which was missing. Before, it was set by a
74 routine which in certain cases wasn't being called, so the
81 routine which in certain cases wasn't being called, so the
75 instance could end up missing the attribute. This caused a crash.
82 instance could end up missing the attribute. This caused a crash.
76 Closes http://www.scipy.net/roundup/ipython/issue40.
83 Closes http://www.scipy.net/roundup/ipython/issue40.
77
84
78 2005-08-16 Fernando Perez <fperez@colorado.edu>
85 2005-08-16 Fernando Perez <fperez@colorado.edu>
79
86
80 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
87 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
81 contains non-string attribute. Closes
88 contains non-string attribute. Closes
82 http://www.scipy.net/roundup/ipython/issue38.
89 http://www.scipy.net/roundup/ipython/issue38.
83
90
84 2005-08-14 Fernando Perez <fperez@colorado.edu>
91 2005-08-14 Fernando Perez <fperez@colorado.edu>
85
92
86 * tools/ipsvnc: Minor improvements, to add changeset info.
93 * tools/ipsvnc: Minor improvements, to add changeset info.
87
94
88 2005-08-12 Fernando Perez <fperez@colorado.edu>
95 2005-08-12 Fernando Perez <fperez@colorado.edu>
89
96
90 * IPython/iplib.py (runsource): remove self.code_to_run_src
97 * IPython/iplib.py (runsource): remove self.code_to_run_src
91 attribute. I realized this is nothing more than
98 attribute. I realized this is nothing more than
92 '\n'.join(self.buffer), and having the same data in two different
99 '\n'.join(self.buffer), and having the same data in two different
93 places is just asking for synchronization bugs. This may impact
100 places is just asking for synchronization bugs. This may impact
94 people who have custom exception handlers, so I need to warn
101 people who have custom exception handlers, so I need to warn
95 ipython-dev about it (F. Mantegazza may use them).
102 ipython-dev about it (F. Mantegazza may use them).
96
103
97 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
104 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
98
105
99 * IPython/genutils.py: fix 2.2 compatibility (generators)
106 * IPython/genutils.py: fix 2.2 compatibility (generators)
100
107
101 2005-07-18 Fernando Perez <fperez@colorado.edu>
108 2005-07-18 Fernando Perez <fperez@colorado.edu>
102
109
103 * IPython/genutils.py (get_home_dir): fix to help users with
110 * IPython/genutils.py (get_home_dir): fix to help users with
104 invalid $HOME under win32.
111 invalid $HOME under win32.
105
112
106 2005-07-17 Fernando Perez <fperez@colorado.edu>
113 2005-07-17 Fernando Perez <fperez@colorado.edu>
107
114
108 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
115 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
109 some old hacks and clean up a bit other routines; code should be
116 some old hacks and clean up a bit other routines; code should be
110 simpler and a bit faster.
117 simpler and a bit faster.
111
118
112 * IPython/iplib.py (interact): removed some last-resort attempts
119 * IPython/iplib.py (interact): removed some last-resort attempts
113 to survive broken stdout/stderr. That code was only making it
120 to survive broken stdout/stderr. That code was only making it
114 harder to abstract out the i/o (necessary for gui integration),
121 harder to abstract out the i/o (necessary for gui integration),
115 and the crashes it could prevent were extremely rare in practice
122 and the crashes it could prevent were extremely rare in practice
116 (besides being fully user-induced in a pretty violent manner).
123 (besides being fully user-induced in a pretty violent manner).
117
124
118 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
125 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
119 Nothing major yet, but the code is simpler to read; this should
126 Nothing major yet, but the code is simpler to read; this should
120 make it easier to do more serious modifications in the future.
127 make it easier to do more serious modifications in the future.
121
128
122 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
129 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
123 which broke in .15 (thanks to a report by Ville).
130 which broke in .15 (thanks to a report by Ville).
124
131
125 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
132 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
126 be quite correct, I know next to nothing about unicode). This
133 be quite correct, I know next to nothing about unicode). This
127 will allow unicode strings to be used in prompts, amongst other
134 will allow unicode strings to be used in prompts, amongst other
128 cases. It also will prevent ipython from crashing when unicode
135 cases. It also will prevent ipython from crashing when unicode
129 shows up unexpectedly in many places. If ascii encoding fails, we
136 shows up unexpectedly in many places. If ascii encoding fails, we
130 assume utf_8. Currently the encoding is not a user-visible
137 assume utf_8. Currently the encoding is not a user-visible
131 setting, though it could be made so if there is demand for it.
138 setting, though it could be made so if there is demand for it.
132
139
133 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
140 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
134
141
135 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
142 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
136
143
137 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
144 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
138
145
139 * IPython/genutils.py: Add 2.2 compatibility here, so all other
146 * IPython/genutils.py: Add 2.2 compatibility here, so all other
140 code can work transparently for 2.2/2.3.
147 code can work transparently for 2.2/2.3.
141
148
142 2005-07-16 Fernando Perez <fperez@colorado.edu>
149 2005-07-16 Fernando Perez <fperez@colorado.edu>
143
150
144 * IPython/ultraTB.py (ExceptionColors): Make a global variable
151 * IPython/ultraTB.py (ExceptionColors): Make a global variable
145 out of the color scheme table used for coloring exception
152 out of the color scheme table used for coloring exception
146 tracebacks. This allows user code to add new schemes at runtime.
153 tracebacks. This allows user code to add new schemes at runtime.
147 This is a minimally modified version of the patch at
154 This is a minimally modified version of the patch at
148 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
155 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
149 for the contribution.
156 for the contribution.
150
157
151 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
158 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
152 slightly modified version of the patch in
159 slightly modified version of the patch in
153 http://www.scipy.net/roundup/ipython/issue34, which also allows me
160 http://www.scipy.net/roundup/ipython/issue34, which also allows me
154 to remove the previous try/except solution (which was costlier).
161 to remove the previous try/except solution (which was costlier).
155 Thanks to Gaetan Lehmann <gaetan.lehmann AT jouy.inra.fr> for the fix.
162 Thanks to Gaetan Lehmann <gaetan.lehmann AT jouy.inra.fr> for the fix.
156
163
157 2005-06-08 Fernando Perez <fperez@colorado.edu>
164 2005-06-08 Fernando Perez <fperez@colorado.edu>
158
165
159 * IPython/iplib.py (write/write_err): Add methods to abstract all
166 * IPython/iplib.py (write/write_err): Add methods to abstract all
160 I/O a bit more.
167 I/O a bit more.
161
168
162 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
169 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
163 warning, reported by Aric Hagberg, fix by JD Hunter.
170 warning, reported by Aric Hagberg, fix by JD Hunter.
164
171
165 2005-06-02 *** Released version 0.6.15
172 2005-06-02 *** Released version 0.6.15
166
173
167 2005-06-01 Fernando Perez <fperez@colorado.edu>
174 2005-06-01 Fernando Perez <fperez@colorado.edu>
168
175
169 * IPython/iplib.py (MagicCompleter.file_matches): Fix
176 * IPython/iplib.py (MagicCompleter.file_matches): Fix
170 tab-completion of filenames within open-quoted strings. Note that
177 tab-completion of filenames within open-quoted strings. Note that
171 this requires that in ~/.ipython/ipythonrc, users change the
178 this requires that in ~/.ipython/ipythonrc, users change the
172 readline delimiters configuration to read:
179 readline delimiters configuration to read:
173
180
174 readline_remove_delims -/~
181 readline_remove_delims -/~
175
182
176
183
177 2005-05-31 *** Released version 0.6.14
184 2005-05-31 *** Released version 0.6.14
178
185
179 2005-05-29 Fernando Perez <fperez@colorado.edu>
186 2005-05-29 Fernando Perez <fperez@colorado.edu>
180
187
181 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
188 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
182 with files not on the filesystem. Reported by Eliyahu Sandler
189 with files not on the filesystem. Reported by Eliyahu Sandler
183 <eli@gondolin.net>
190 <eli@gondolin.net>
184
191
185 2005-05-22 Fernando Perez <fperez@colorado.edu>
192 2005-05-22 Fernando Perez <fperez@colorado.edu>
186
193
187 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
194 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
188 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
195 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
189
196
190 2005-05-19 Fernando Perez <fperez@colorado.edu>
197 2005-05-19 Fernando Perez <fperez@colorado.edu>
191
198
192 * IPython/iplib.py (safe_execfile): close a file which could be
199 * IPython/iplib.py (safe_execfile): close a file which could be
193 left open (causing problems in win32, which locks open files).
200 left open (causing problems in win32, which locks open files).
194 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
201 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
195
202
196 2005-05-18 Fernando Perez <fperez@colorado.edu>
203 2005-05-18 Fernando Perez <fperez@colorado.edu>
197
204
198 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
205 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
199 keyword arguments correctly to safe_execfile().
206 keyword arguments correctly to safe_execfile().
200
207
201 2005-05-13 Fernando Perez <fperez@colorado.edu>
208 2005-05-13 Fernando Perez <fperez@colorado.edu>
202
209
203 * ipython.1: Added info about Qt to manpage, and threads warning
210 * ipython.1: Added info about Qt to manpage, and threads warning
204 to usage page (invoked with --help).
211 to usage page (invoked with --help).
205
212
206 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
213 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
207 new matcher (it goes at the end of the priority list) to do
214 new matcher (it goes at the end of the priority list) to do
208 tab-completion on named function arguments. Submitted by George
215 tab-completion on named function arguments. Submitted by George
209 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
216 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
210 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
217 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
211 for more details.
218 for more details.
212
219
213 * IPython/Magic.py (magic_run): Added new -e flag to ignore
220 * IPython/Magic.py (magic_run): Added new -e flag to ignore
214 SystemExit exceptions in the script being run. Thanks to a report
221 SystemExit exceptions in the script being run. Thanks to a report
215 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
222 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
216 producing very annoying behavior when running unit tests.
223 producing very annoying behavior when running unit tests.
217
224
218 2005-05-12 Fernando Perez <fperez@colorado.edu>
225 2005-05-12 Fernando Perez <fperez@colorado.edu>
219
226
220 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
227 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
221 which I'd broken (again) due to a changed regexp. In the process,
228 which I'd broken (again) due to a changed regexp. In the process,
222 added ';' as an escape to auto-quote the whole line without
229 added ';' as an escape to auto-quote the whole line without
223 splitting its arguments. Thanks to a report by Jerry McRae
230 splitting its arguments. Thanks to a report by Jerry McRae
224 <qrs0xyc02-AT-sneakemail.com>.
231 <qrs0xyc02-AT-sneakemail.com>.
225
232
226 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
233 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
227 possible crashes caused by a TokenError. Reported by Ed Schofield
234 possible crashes caused by a TokenError. Reported by Ed Schofield
228 <schofield-AT-ftw.at>.
235 <schofield-AT-ftw.at>.
229
236
230 2005-05-06 Fernando Perez <fperez@colorado.edu>
237 2005-05-06 Fernando Perez <fperez@colorado.edu>
231
238
232 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
239 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
233
240
234 2005-04-29 Fernando Perez <fperez@colorado.edu>
241 2005-04-29 Fernando Perez <fperez@colorado.edu>
235
242
236 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
243 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
237 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
244 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
238 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
245 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
239 which provides support for Qt interactive usage (similar to the
246 which provides support for Qt interactive usage (similar to the
240 existing one for WX and GTK). This had been often requested.
247 existing one for WX and GTK). This had been often requested.
241
248
242 2005-04-14 *** Released version 0.6.13
249 2005-04-14 *** Released version 0.6.13
243
250
244 2005-04-08 Fernando Perez <fperez@colorado.edu>
251 2005-04-08 Fernando Perez <fperez@colorado.edu>
245
252
246 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
253 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
247 from _ofind, which gets called on almost every input line. Now,
254 from _ofind, which gets called on almost every input line. Now,
248 we only try to get docstrings if they are actually going to be
255 we only try to get docstrings if they are actually going to be
249 used (the overhead of fetching unnecessary docstrings can be
256 used (the overhead of fetching unnecessary docstrings can be
250 noticeable for certain objects, such as Pyro proxies).
257 noticeable for certain objects, such as Pyro proxies).
251
258
252 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
259 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
253 for completers. For some reason I had been passing them the state
260 for completers. For some reason I had been passing them the state
254 variable, which completers never actually need, and was in
261 variable, which completers never actually need, and was in
255 conflict with the rlcompleter API. Custom completers ONLY need to
262 conflict with the rlcompleter API. Custom completers ONLY need to
256 take the text parameter.
263 take the text parameter.
257
264
258 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
265 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
259 work correctly in pysh. I've also moved all the logic which used
266 work correctly in pysh. I've also moved all the logic which used
260 to be in pysh.py here, which will prevent problems with future
267 to be in pysh.py here, which will prevent problems with future
261 upgrades. However, this time I must warn users to update their
268 upgrades. However, this time I must warn users to update their
262 pysh profile to include the line
269 pysh profile to include the line
263
270
264 import_all IPython.Extensions.InterpreterExec
271 import_all IPython.Extensions.InterpreterExec
265
272
266 because otherwise things won't work for them. They MUST also
273 because otherwise things won't work for them. They MUST also
267 delete pysh.py and the line
274 delete pysh.py and the line
268
275
269 execfile pysh.py
276 execfile pysh.py
270
277
271 from their ipythonrc-pysh.
278 from their ipythonrc-pysh.
272
279
273 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
280 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
274 robust in the face of objects whose dir() returns non-strings
281 robust in the face of objects whose dir() returns non-strings
275 (which it shouldn't, but some broken libs like ITK do). Thanks to
282 (which it shouldn't, but some broken libs like ITK do). Thanks to
276 a patch by John Hunter (implemented differently, though). Also
283 a patch by John Hunter (implemented differently, though). Also
277 minor improvements by using .extend instead of + on lists.
284 minor improvements by using .extend instead of + on lists.
278
285
279 * pysh.py:
286 * pysh.py:
280
287
281 2005-04-06 Fernando Perez <fperez@colorado.edu>
288 2005-04-06 Fernando Perez <fperez@colorado.edu>
282
289
283 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
290 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
284 by default, so that all users benefit from it. Those who don't
291 by default, so that all users benefit from it. Those who don't
285 want it can still turn it off.
292 want it can still turn it off.
286
293
287 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
294 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
288 config file, I'd forgotten about this, so users were getting it
295 config file, I'd forgotten about this, so users were getting it
289 off by default.
296 off by default.
290
297
291 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
298 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
292 consistency. Now magics can be called in multiline statements,
299 consistency. Now magics can be called in multiline statements,
293 and python variables can be expanded in magic calls via $var.
300 and python variables can be expanded in magic calls via $var.
294 This makes the magic system behave just like aliases or !system
301 This makes the magic system behave just like aliases or !system
295 calls.
302 calls.
296
303
297 2005-03-28 Fernando Perez <fperez@colorado.edu>
304 2005-03-28 Fernando Perez <fperez@colorado.edu>
298
305
299 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
306 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
300 expensive string additions for building command. Add support for
307 expensive string additions for building command. Add support for
301 trailing ';' when autocall is used.
308 trailing ';' when autocall is used.
302
309
303 2005-03-26 Fernando Perez <fperez@colorado.edu>
310 2005-03-26 Fernando Perez <fperez@colorado.edu>
304
311
305 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
312 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
306 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
313 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
307 ipython.el robust against prompts with any number of spaces
314 ipython.el robust against prompts with any number of spaces
308 (including 0) after the ':' character.
315 (including 0) after the ':' character.
309
316
310 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
317 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
311 continuation prompt, which misled users to think the line was
318 continuation prompt, which misled users to think the line was
312 already indented. Closes debian Bug#300847, reported to me by
319 already indented. Closes debian Bug#300847, reported to me by
313 Norbert Tretkowski <tretkowski-AT-inittab.de>.
320 Norbert Tretkowski <tretkowski-AT-inittab.de>.
314
321
315 2005-03-23 Fernando Perez <fperez@colorado.edu>
322 2005-03-23 Fernando Perez <fperez@colorado.edu>
316
323
317 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
324 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
318 properly aligned if they have embedded newlines.
325 properly aligned if they have embedded newlines.
319
326
320 * IPython/iplib.py (runlines): Add a public method to expose
327 * IPython/iplib.py (runlines): Add a public method to expose
321 IPython's code execution machinery, so that users can run strings
328 IPython's code execution machinery, so that users can run strings
322 as if they had been typed at the prompt interactively.
329 as if they had been typed at the prompt interactively.
323 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
330 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
324 methods which can call the system shell, but with python variable
331 methods which can call the system shell, but with python variable
325 expansion. The three such methods are: __IPYTHON__.system,
332 expansion. The three such methods are: __IPYTHON__.system,
326 .getoutput and .getoutputerror. These need to be documented in a
333 .getoutput and .getoutputerror. These need to be documented in a
327 'public API' section (to be written) of the manual.
334 'public API' section (to be written) of the manual.
328
335
329 2005-03-20 Fernando Perez <fperez@colorado.edu>
336 2005-03-20 Fernando Perez <fperez@colorado.edu>
330
337
331 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
338 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
332 for custom exception handling. This is quite powerful, and it
339 for custom exception handling. This is quite powerful, and it
333 allows for user-installable exception handlers which can trap
340 allows for user-installable exception handlers which can trap
334 custom exceptions at runtime and treat them separately from
341 custom exceptions at runtime and treat them separately from
335 IPython's default mechanisms. At the request of Frédéric
342 IPython's default mechanisms. At the request of Frédéric
336 Mantegazza <mantegazza-AT-ill.fr>.
343 Mantegazza <mantegazza-AT-ill.fr>.
337 (InteractiveShell.set_custom_completer): public API function to
344 (InteractiveShell.set_custom_completer): public API function to
338 add new completers at runtime.
345 add new completers at runtime.
339
346
340 2005-03-19 Fernando Perez <fperez@colorado.edu>
347 2005-03-19 Fernando Perez <fperez@colorado.edu>
341
348
342 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
349 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
343 allow objects which provide their docstrings via non-standard
350 allow objects which provide their docstrings via non-standard
344 mechanisms (like Pyro proxies) to still be inspected by ipython's
351 mechanisms (like Pyro proxies) to still be inspected by ipython's
345 ? system.
352 ? system.
346
353
347 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
354 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
348 automatic capture system. I tried quite hard to make it work
355 automatic capture system. I tried quite hard to make it work
349 reliably, and simply failed. I tried many combinations with the
356 reliably, and simply failed. I tried many combinations with the
350 subprocess module, but eventually nothing worked in all needed
357 subprocess module, but eventually nothing worked in all needed
351 cases (not blocking stdin for the child, duplicating stdout
358 cases (not blocking stdin for the child, duplicating stdout
352 without blocking, etc). The new %sc/%sx still do capture to these
359 without blocking, etc). The new %sc/%sx still do capture to these
353 magical list/string objects which make shell use much more
360 magical list/string objects which make shell use much more
354 conveninent, so not all is lost.
361 conveninent, so not all is lost.
355
362
356 XXX - FIX MANUAL for the change above!
363 XXX - FIX MANUAL for the change above!
357
364
358 (runsource): I copied code.py's runsource() into ipython to modify
365 (runsource): I copied code.py's runsource() into ipython to modify
359 it a bit. Now the code object and source to be executed are
366 it a bit. Now the code object and source to be executed are
360 stored in ipython. This makes this info accessible to third-party
367 stored in ipython. This makes this info accessible to third-party
361 tools, like custom exception handlers. After a request by Frédéric
368 tools, like custom exception handlers. After a request by Frédéric
362 Mantegazza <mantegazza-AT-ill.fr>.
369 Mantegazza <mantegazza-AT-ill.fr>.
363
370
364 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
371 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
365 history-search via readline (like C-p/C-n). I'd wanted this for a
372 history-search via readline (like C-p/C-n). I'd wanted this for a
366 long time, but only recently found out how to do it. For users
373 long time, but only recently found out how to do it. For users
367 who already have their ipythonrc files made and want this, just
374 who already have their ipythonrc files made and want this, just
368 add:
375 add:
369
376
370 readline_parse_and_bind "\e[A": history-search-backward
377 readline_parse_and_bind "\e[A": history-search-backward
371 readline_parse_and_bind "\e[B": history-search-forward
378 readline_parse_and_bind "\e[B": history-search-forward
372
379
373 2005-03-18 Fernando Perez <fperez@colorado.edu>
380 2005-03-18 Fernando Perez <fperez@colorado.edu>
374
381
375 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
382 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
376 LSString and SList classes which allow transparent conversions
383 LSString and SList classes which allow transparent conversions
377 between list mode and whitespace-separated string.
384 between list mode and whitespace-separated string.
378 (magic_r): Fix recursion problem in %r.
385 (magic_r): Fix recursion problem in %r.
379
386
380 * IPython/genutils.py (LSString): New class to be used for
387 * IPython/genutils.py (LSString): New class to be used for
381 automatic storage of the results of all alias/system calls in _o
388 automatic storage of the results of all alias/system calls in _o
382 and _e (stdout/err). These provide a .l/.list attribute which
389 and _e (stdout/err). These provide a .l/.list attribute which
383 does automatic splitting on newlines. This means that for most
390 does automatic splitting on newlines. This means that for most
384 uses, you'll never need to do capturing of output with %sc/%sx
391 uses, you'll never need to do capturing of output with %sc/%sx
385 anymore, since ipython keeps this always done for you. Note that
392 anymore, since ipython keeps this always done for you. Note that
386 only the LAST results are stored, the _o/e variables are
393 only the LAST results are stored, the _o/e variables are
387 overwritten on each call. If you need to save their contents
394 overwritten on each call. If you need to save their contents
388 further, simply bind them to any other name.
395 further, simply bind them to any other name.
389
396
390 2005-03-17 Fernando Perez <fperez@colorado.edu>
397 2005-03-17 Fernando Perez <fperez@colorado.edu>
391
398
392 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
399 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
393 prompt namespace handling.
400 prompt namespace handling.
394
401
395 2005-03-16 Fernando Perez <fperez@colorado.edu>
402 2005-03-16 Fernando Perez <fperez@colorado.edu>
396
403
397 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
404 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
398 classic prompts to be '>>> ' (final space was missing, and it
405 classic prompts to be '>>> ' (final space was missing, and it
399 trips the emacs python mode).
406 trips the emacs python mode).
400 (BasePrompt.__str__): Added safe support for dynamic prompt
407 (BasePrompt.__str__): Added safe support for dynamic prompt
401 strings. Now you can set your prompt string to be '$x', and the
408 strings. Now you can set your prompt string to be '$x', and the
402 value of x will be printed from your interactive namespace. The
409 value of x will be printed from your interactive namespace. The
403 interpolation syntax includes the full Itpl support, so
410 interpolation syntax includes the full Itpl support, so
404 ${foo()+x+bar()} is a valid prompt string now, and the function
411 ${foo()+x+bar()} is a valid prompt string now, and the function
405 calls will be made at runtime.
412 calls will be made at runtime.
406
413
407 2005-03-15 Fernando Perez <fperez@colorado.edu>
414 2005-03-15 Fernando Perez <fperez@colorado.edu>
408
415
409 * IPython/Magic.py (magic_history): renamed %hist to %history, to
416 * IPython/Magic.py (magic_history): renamed %hist to %history, to
410 avoid name clashes in pylab. %hist still works, it just forwards
417 avoid name clashes in pylab. %hist still works, it just forwards
411 the call to %history.
418 the call to %history.
412
419
413 2005-03-02 *** Released version 0.6.12
420 2005-03-02 *** Released version 0.6.12
414
421
415 2005-03-02 Fernando Perez <fperez@colorado.edu>
422 2005-03-02 Fernando Perez <fperez@colorado.edu>
416
423
417 * IPython/iplib.py (handle_magic): log magic calls properly as
424 * IPython/iplib.py (handle_magic): log magic calls properly as
418 ipmagic() function calls.
425 ipmagic() function calls.
419
426
420 * IPython/Magic.py (magic_time): Improved %time to support
427 * IPython/Magic.py (magic_time): Improved %time to support
421 statements and provide wall-clock as well as CPU time.
428 statements and provide wall-clock as well as CPU time.
422
429
423 2005-02-27 Fernando Perez <fperez@colorado.edu>
430 2005-02-27 Fernando Perez <fperez@colorado.edu>
424
431
425 * IPython/hooks.py: New hooks module, to expose user-modifiable
432 * IPython/hooks.py: New hooks module, to expose user-modifiable
426 IPython functionality in a clean manner. For now only the editor
433 IPython functionality in a clean manner. For now only the editor
427 hook is actually written, and other thigns which I intend to turn
434 hook is actually written, and other thigns which I intend to turn
428 into proper hooks aren't yet there. The display and prefilter
435 into proper hooks aren't yet there. The display and prefilter
429 stuff, for example, should be hooks. But at least now the
436 stuff, for example, should be hooks. But at least now the
430 framework is in place, and the rest can be moved here with more
437 framework is in place, and the rest can be moved here with more
431 time later. IPython had had a .hooks variable for a long time for
438 time later. IPython had had a .hooks variable for a long time for
432 this purpose, but I'd never actually used it for anything.
439 this purpose, but I'd never actually used it for anything.
433
440
434 2005-02-26 Fernando Perez <fperez@colorado.edu>
441 2005-02-26 Fernando Perez <fperez@colorado.edu>
435
442
436 * IPython/ipmaker.py (make_IPython): make the default ipython
443 * IPython/ipmaker.py (make_IPython): make the default ipython
437 directory be called _ipython under win32, to follow more the
444 directory be called _ipython under win32, to follow more the
438 naming peculiarities of that platform (where buggy software like
445 naming peculiarities of that platform (where buggy software like
439 Visual Sourcesafe breaks with .named directories). Reported by
446 Visual Sourcesafe breaks with .named directories). Reported by
440 Ville Vainio.
447 Ville Vainio.
441
448
442 2005-02-23 Fernando Perez <fperez@colorado.edu>
449 2005-02-23 Fernando Perez <fperez@colorado.edu>
443
450
444 * IPython/iplib.py (InteractiveShell.__init__): removed a few
451 * IPython/iplib.py (InteractiveShell.__init__): removed a few
445 auto_aliases for win32 which were causing problems. Users can
452 auto_aliases for win32 which were causing problems. Users can
446 define the ones they personally like.
453 define the ones they personally like.
447
454
448 2005-02-21 Fernando Perez <fperez@colorado.edu>
455 2005-02-21 Fernando Perez <fperez@colorado.edu>
449
456
450 * IPython/Magic.py (magic_time): new magic to time execution of
457 * IPython/Magic.py (magic_time): new magic to time execution of
451 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
458 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
452
459
453 2005-02-19 Fernando Perez <fperez@colorado.edu>
460 2005-02-19 Fernando Perez <fperez@colorado.edu>
454
461
455 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
462 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
456 into keys (for prompts, for example).
463 into keys (for prompts, for example).
457
464
458 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
465 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
459 prompts in case users want them. This introduces a small behavior
466 prompts in case users want them. This introduces a small behavior
460 change: ipython does not automatically add a space to all prompts
467 change: ipython does not automatically add a space to all prompts
461 anymore. To get the old prompts with a space, users should add it
468 anymore. To get the old prompts with a space, users should add it
462 manually to their ipythonrc file, so for example prompt_in1 should
469 manually to their ipythonrc file, so for example prompt_in1 should
463 now read 'In [\#]: ' instead of 'In [\#]:'.
470 now read 'In [\#]: ' instead of 'In [\#]:'.
464 (BasePrompt.__init__): New option prompts_pad_left (only in rc
471 (BasePrompt.__init__): New option prompts_pad_left (only in rc
465 file) to control left-padding of secondary prompts.
472 file) to control left-padding of secondary prompts.
466
473
467 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
474 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
468 the profiler can't be imported. Fix for Debian, which removed
475 the profiler can't be imported. Fix for Debian, which removed
469 profile.py because of License issues. I applied a slightly
476 profile.py because of License issues. I applied a slightly
470 modified version of the original Debian patch at
477 modified version of the original Debian patch at
471 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
478 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
472
479
473 2005-02-17 Fernando Perez <fperez@colorado.edu>
480 2005-02-17 Fernando Perez <fperez@colorado.edu>
474
481
475 * IPython/genutils.py (native_line_ends): Fix bug which would
482 * IPython/genutils.py (native_line_ends): Fix bug which would
476 cause improper line-ends under win32 b/c I was not opening files
483 cause improper line-ends under win32 b/c I was not opening files
477 in binary mode. Bug report and fix thanks to Ville.
484 in binary mode. Bug report and fix thanks to Ville.
478
485
479 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
486 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
480 trying to catch spurious foo[1] autocalls. My fix actually broke
487 trying to catch spurious foo[1] autocalls. My fix actually broke
481 ',/' autoquote/call with explicit escape (bad regexp).
488 ',/' autoquote/call with explicit escape (bad regexp).
482
489
483 2005-02-15 *** Released version 0.6.11
490 2005-02-15 *** Released version 0.6.11
484
491
485 2005-02-14 Fernando Perez <fperez@colorado.edu>
492 2005-02-14 Fernando Perez <fperez@colorado.edu>
486
493
487 * IPython/background_jobs.py: New background job management
494 * IPython/background_jobs.py: New background job management
488 subsystem. This is implemented via a new set of classes, and
495 subsystem. This is implemented via a new set of classes, and
489 IPython now provides a builtin 'jobs' object for background job
496 IPython now provides a builtin 'jobs' object for background job
490 execution. A convenience %bg magic serves as a lightweight
497 execution. A convenience %bg magic serves as a lightweight
491 frontend for starting the more common type of calls. This was
498 frontend for starting the more common type of calls. This was
492 inspired by discussions with B. Granger and the BackgroundCommand
499 inspired by discussions with B. Granger and the BackgroundCommand
493 class described in the book Python Scripting for Computational
500 class described in the book Python Scripting for Computational
494 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
501 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
495 (although ultimately no code from this text was used, as IPython's
502 (although ultimately no code from this text was used, as IPython's
496 system is a separate implementation).
503 system is a separate implementation).
497
504
498 * IPython/iplib.py (MagicCompleter.python_matches): add new option
505 * IPython/iplib.py (MagicCompleter.python_matches): add new option
499 to control the completion of single/double underscore names
506 to control the completion of single/double underscore names
500 separately. As documented in the example ipytonrc file, the
507 separately. As documented in the example ipytonrc file, the
501 readline_omit__names variable can now be set to 2, to omit even
508 readline_omit__names variable can now be set to 2, to omit even
502 single underscore names. Thanks to a patch by Brian Wong
509 single underscore names. Thanks to a patch by Brian Wong
503 <BrianWong-AT-AirgoNetworks.Com>.
510 <BrianWong-AT-AirgoNetworks.Com>.
504 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
511 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
505 be autocalled as foo([1]) if foo were callable. A problem for
512 be autocalled as foo([1]) if foo were callable. A problem for
506 things which are both callable and implement __getitem__.
513 things which are both callable and implement __getitem__.
507 (init_readline): Fix autoindentation for win32. Thanks to a patch
514 (init_readline): Fix autoindentation for win32. Thanks to a patch
508 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
515 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
509
516
510 2005-02-12 Fernando Perez <fperez@colorado.edu>
517 2005-02-12 Fernando Perez <fperez@colorado.edu>
511
518
512 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
519 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
513 which I had written long ago to sort out user error messages which
520 which I had written long ago to sort out user error messages which
514 may occur during startup. This seemed like a good idea initially,
521 may occur during startup. This seemed like a good idea initially,
515 but it has proven a disaster in retrospect. I don't want to
522 but it has proven a disaster in retrospect. I don't want to
516 change much code for now, so my fix is to set the internal 'debug'
523 change much code for now, so my fix is to set the internal 'debug'
517 flag to true everywhere, whose only job was precisely to control
524 flag to true everywhere, whose only job was precisely to control
518 this subsystem. This closes issue 28 (as well as avoiding all
525 this subsystem. This closes issue 28 (as well as avoiding all
519 sorts of strange hangups which occur from time to time).
526 sorts of strange hangups which occur from time to time).
520
527
521 2005-02-07 Fernando Perez <fperez@colorado.edu>
528 2005-02-07 Fernando Perez <fperez@colorado.edu>
522
529
523 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
530 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
524 previous call produced a syntax error.
531 previous call produced a syntax error.
525
532
526 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
533 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
527 classes without constructor.
534 classes without constructor.
528
535
529 2005-02-06 Fernando Perez <fperez@colorado.edu>
536 2005-02-06 Fernando Perez <fperez@colorado.edu>
530
537
531 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
538 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
532 completions with the results of each matcher, so we return results
539 completions with the results of each matcher, so we return results
533 to the user from all namespaces. This breaks with ipython
540 to the user from all namespaces. This breaks with ipython
534 tradition, but I think it's a nicer behavior. Now you get all
541 tradition, but I think it's a nicer behavior. Now you get all
535 possible completions listed, from all possible namespaces (python,
542 possible completions listed, from all possible namespaces (python,
536 filesystem, magics...) After a request by John Hunter
543 filesystem, magics...) After a request by John Hunter
537 <jdhunter-AT-nitace.bsd.uchicago.edu>.
544 <jdhunter-AT-nitace.bsd.uchicago.edu>.
538
545
539 2005-02-05 Fernando Perez <fperez@colorado.edu>
546 2005-02-05 Fernando Perez <fperez@colorado.edu>
540
547
541 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
548 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
542 the call had quote characters in it (the quotes were stripped).
549 the call had quote characters in it (the quotes were stripped).
543
550
544 2005-01-31 Fernando Perez <fperez@colorado.edu>
551 2005-01-31 Fernando Perez <fperez@colorado.edu>
545
552
546 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
553 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
547 Itpl.itpl() to make the code more robust against psyco
554 Itpl.itpl() to make the code more robust against psyco
548 optimizations.
555 optimizations.
549
556
550 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
557 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
551 of causing an exception. Quicker, cleaner.
558 of causing an exception. Quicker, cleaner.
552
559
553 2005-01-28 Fernando Perez <fperez@colorado.edu>
560 2005-01-28 Fernando Perez <fperez@colorado.edu>
554
561
555 * scripts/ipython_win_post_install.py (install): hardcode
562 * scripts/ipython_win_post_install.py (install): hardcode
556 sys.prefix+'python.exe' as the executable path. It turns out that
563 sys.prefix+'python.exe' as the executable path. It turns out that
557 during the post-installation run, sys.executable resolves to the
564 during the post-installation run, sys.executable resolves to the
558 name of the binary installer! I should report this as a distutils
565 name of the binary installer! I should report this as a distutils
559 bug, I think. I updated the .10 release with this tiny fix, to
566 bug, I think. I updated the .10 release with this tiny fix, to
560 avoid annoying the lists further.
567 avoid annoying the lists further.
561
568
562 2005-01-27 *** Released version 0.6.10
569 2005-01-27 *** Released version 0.6.10
563
570
564 2005-01-27 Fernando Perez <fperez@colorado.edu>
571 2005-01-27 Fernando Perez <fperez@colorado.edu>
565
572
566 * IPython/numutils.py (norm): Added 'inf' as optional name for
573 * IPython/numutils.py (norm): Added 'inf' as optional name for
567 L-infinity norm, included references to mathworld.com for vector
574 L-infinity norm, included references to mathworld.com for vector
568 norm definitions.
575 norm definitions.
569 (amin/amax): added amin/amax for array min/max. Similar to what
576 (amin/amax): added amin/amax for array min/max. Similar to what
570 pylab ships with after the recent reorganization of names.
577 pylab ships with after the recent reorganization of names.
571 (spike/spike_odd): removed deprecated spike/spike_odd functions.
578 (spike/spike_odd): removed deprecated spike/spike_odd functions.
572
579
573 * ipython.el: committed Alex's recent fixes and improvements.
580 * ipython.el: committed Alex's recent fixes and improvements.
574 Tested with python-mode from CVS, and it looks excellent. Since
581 Tested with python-mode from CVS, and it looks excellent. Since
575 python-mode hasn't released anything in a while, I'm temporarily
582 python-mode hasn't released anything in a while, I'm temporarily
576 putting a copy of today's CVS (v 4.70) of python-mode in:
583 putting a copy of today's CVS (v 4.70) of python-mode in:
577 http://ipython.scipy.org/tmp/python-mode.el
584 http://ipython.scipy.org/tmp/python-mode.el
578
585
579 * scripts/ipython_win_post_install.py (install): Win32 fix to use
586 * scripts/ipython_win_post_install.py (install): Win32 fix to use
580 sys.executable for the executable name, instead of assuming it's
587 sys.executable for the executable name, instead of assuming it's
581 called 'python.exe' (the post-installer would have produced broken
588 called 'python.exe' (the post-installer would have produced broken
582 setups on systems with a differently named python binary).
589 setups on systems with a differently named python binary).
583
590
584 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
591 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
585 references to os.linesep, to make the code more
592 references to os.linesep, to make the code more
586 platform-independent. This is also part of the win32 coloring
593 platform-independent. This is also part of the win32 coloring
587 fixes.
594 fixes.
588
595
589 * IPython/genutils.py (page_dumb): Remove attempts to chop long
596 * IPython/genutils.py (page_dumb): Remove attempts to chop long
590 lines, which actually cause coloring bugs because the length of
597 lines, which actually cause coloring bugs because the length of
591 the line is very difficult to correctly compute with embedded
598 the line is very difficult to correctly compute with embedded
592 escapes. This was the source of all the coloring problems under
599 escapes. This was the source of all the coloring problems under
593 Win32. I think that _finally_, Win32 users have a properly
600 Win32. I think that _finally_, Win32 users have a properly
594 working ipython in all respects. This would never have happened
601 working ipython in all respects. This would never have happened
595 if not for Gary Bishop and Viktor Ransmayr's great help and work.
602 if not for Gary Bishop and Viktor Ransmayr's great help and work.
596
603
597 2005-01-26 *** Released version 0.6.9
604 2005-01-26 *** Released version 0.6.9
598
605
599 2005-01-25 Fernando Perez <fperez@colorado.edu>
606 2005-01-25 Fernando Perez <fperez@colorado.edu>
600
607
601 * setup.py: finally, we have a true Windows installer, thanks to
608 * setup.py: finally, we have a true Windows installer, thanks to
602 the excellent work of Viktor Ransmayr
609 the excellent work of Viktor Ransmayr
603 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
610 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
604 Windows users. The setup routine is quite a bit cleaner thanks to
611 Windows users. The setup routine is quite a bit cleaner thanks to
605 this, and the post-install script uses the proper functions to
612 this, and the post-install script uses the proper functions to
606 allow a clean de-installation using the standard Windows Control
613 allow a clean de-installation using the standard Windows Control
607 Panel.
614 Panel.
608
615
609 * IPython/genutils.py (get_home_dir): changed to use the $HOME
616 * IPython/genutils.py (get_home_dir): changed to use the $HOME
610 environment variable under all OSes (including win32) if
617 environment variable under all OSes (including win32) if
611 available. This will give consistency to win32 users who have set
618 available. This will give consistency to win32 users who have set
612 this variable for any reason. If os.environ['HOME'] fails, the
619 this variable for any reason. If os.environ['HOME'] fails, the
613 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
620 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
614
621
615 2005-01-24 Fernando Perez <fperez@colorado.edu>
622 2005-01-24 Fernando Perez <fperez@colorado.edu>
616
623
617 * IPython/numutils.py (empty_like): add empty_like(), similar to
624 * IPython/numutils.py (empty_like): add empty_like(), similar to
618 zeros_like() but taking advantage of the new empty() Numeric routine.
625 zeros_like() but taking advantage of the new empty() Numeric routine.
619
626
620 2005-01-23 *** Released version 0.6.8
627 2005-01-23 *** Released version 0.6.8
621
628
622 2005-01-22 Fernando Perez <fperez@colorado.edu>
629 2005-01-22 Fernando Perez <fperez@colorado.edu>
623
630
624 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
631 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
625 automatic show() calls. After discussing things with JDH, it
632 automatic show() calls. After discussing things with JDH, it
626 turns out there are too many corner cases where this can go wrong.
633 turns out there are too many corner cases where this can go wrong.
627 It's best not to try to be 'too smart', and simply have ipython
634 It's best not to try to be 'too smart', and simply have ipython
628 reproduce as much as possible the default behavior of a normal
635 reproduce as much as possible the default behavior of a normal
629 python shell.
636 python shell.
630
637
631 * IPython/iplib.py (InteractiveShell.__init__): Modified the
638 * IPython/iplib.py (InteractiveShell.__init__): Modified the
632 line-splitting regexp and _prefilter() to avoid calling getattr()
639 line-splitting regexp and _prefilter() to avoid calling getattr()
633 on assignments. This closes
640 on assignments. This closes
634 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
641 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
635 readline uses getattr(), so a simple <TAB> keypress is still
642 readline uses getattr(), so a simple <TAB> keypress is still
636 enough to trigger getattr() calls on an object.
643 enough to trigger getattr() calls on an object.
637
644
638 2005-01-21 Fernando Perez <fperez@colorado.edu>
645 2005-01-21 Fernando Perez <fperez@colorado.edu>
639
646
640 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
647 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
641 docstring under pylab so it doesn't mask the original.
648 docstring under pylab so it doesn't mask the original.
642
649
643 2005-01-21 *** Released version 0.6.7
650 2005-01-21 *** Released version 0.6.7
644
651
645 2005-01-21 Fernando Perez <fperez@colorado.edu>
652 2005-01-21 Fernando Perez <fperez@colorado.edu>
646
653
647 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
654 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
648 signal handling for win32 users in multithreaded mode.
655 signal handling for win32 users in multithreaded mode.
649
656
650 2005-01-17 Fernando Perez <fperez@colorado.edu>
657 2005-01-17 Fernando Perez <fperez@colorado.edu>
651
658
652 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
659 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
653 instances with no __init__. After a crash report by Norbert Nemec
660 instances with no __init__. After a crash report by Norbert Nemec
654 <Norbert-AT-nemec-online.de>.
661 <Norbert-AT-nemec-online.de>.
655
662
656 2005-01-14 Fernando Perez <fperez@colorado.edu>
663 2005-01-14 Fernando Perez <fperez@colorado.edu>
657
664
658 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
665 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
659 names for verbose exceptions, when multiple dotted names and the
666 names for verbose exceptions, when multiple dotted names and the
660 'parent' object were present on the same line.
667 'parent' object were present on the same line.
661
668
662 2005-01-11 Fernando Perez <fperez@colorado.edu>
669 2005-01-11 Fernando Perez <fperez@colorado.edu>
663
670
664 * IPython/genutils.py (flag_calls): new utility to trap and flag
671 * IPython/genutils.py (flag_calls): new utility to trap and flag
665 calls in functions. I need it to clean up matplotlib support.
672 calls in functions. I need it to clean up matplotlib support.
666 Also removed some deprecated code in genutils.
673 Also removed some deprecated code in genutils.
667
674
668 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
675 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
669 that matplotlib scripts called with %run, which don't call show()
676 that matplotlib scripts called with %run, which don't call show()
670 themselves, still have their plotting windows open.
677 themselves, still have their plotting windows open.
671
678
672 2005-01-05 Fernando Perez <fperez@colorado.edu>
679 2005-01-05 Fernando Perez <fperez@colorado.edu>
673
680
674 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
681 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
675 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
682 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
676
683
677 2004-12-19 Fernando Perez <fperez@colorado.edu>
684 2004-12-19 Fernando Perez <fperez@colorado.edu>
678
685
679 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
686 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
680 parent_runcode, which was an eyesore. The same result can be
687 parent_runcode, which was an eyesore. The same result can be
681 obtained with Python's regular superclass mechanisms.
688 obtained with Python's regular superclass mechanisms.
682
689
683 2004-12-17 Fernando Perez <fperez@colorado.edu>
690 2004-12-17 Fernando Perez <fperez@colorado.edu>
684
691
685 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
692 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
686 reported by Prabhu.
693 reported by Prabhu.
687 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
694 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
688 sys.stderr) instead of explicitly calling sys.stderr. This helps
695 sys.stderr) instead of explicitly calling sys.stderr. This helps
689 maintain our I/O abstractions clean, for future GUI embeddings.
696 maintain our I/O abstractions clean, for future GUI embeddings.
690
697
691 * IPython/genutils.py (info): added new utility for sys.stderr
698 * IPython/genutils.py (info): added new utility for sys.stderr
692 unified info message handling (thin wrapper around warn()).
699 unified info message handling (thin wrapper around warn()).
693
700
694 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
701 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
695 composite (dotted) names on verbose exceptions.
702 composite (dotted) names on verbose exceptions.
696 (VerboseTB.nullrepr): harden against another kind of errors which
703 (VerboseTB.nullrepr): harden against another kind of errors which
697 Python's inspect module can trigger, and which were crashing
704 Python's inspect module can trigger, and which were crashing
698 IPython. Thanks to a report by Marco Lombardi
705 IPython. Thanks to a report by Marco Lombardi
699 <mlombard-AT-ma010192.hq.eso.org>.
706 <mlombard-AT-ma010192.hq.eso.org>.
700
707
701 2004-12-13 *** Released version 0.6.6
708 2004-12-13 *** Released version 0.6.6
702
709
703 2004-12-12 Fernando Perez <fperez@colorado.edu>
710 2004-12-12 Fernando Perez <fperez@colorado.edu>
704
711
705 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
712 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
706 generated by pygtk upon initialization if it was built without
713 generated by pygtk upon initialization if it was built without
707 threads (for matplotlib users). After a crash reported by
714 threads (for matplotlib users). After a crash reported by
708 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
715 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
709
716
710 * IPython/ipmaker.py (make_IPython): fix small bug in the
717 * IPython/ipmaker.py (make_IPython): fix small bug in the
711 import_some parameter for multiple imports.
718 import_some parameter for multiple imports.
712
719
713 * IPython/iplib.py (ipmagic): simplified the interface of
720 * IPython/iplib.py (ipmagic): simplified the interface of
714 ipmagic() to take a single string argument, just as it would be
721 ipmagic() to take a single string argument, just as it would be
715 typed at the IPython cmd line.
722 typed at the IPython cmd line.
716 (ipalias): Added new ipalias() with an interface identical to
723 (ipalias): Added new ipalias() with an interface identical to
717 ipmagic(). This completes exposing a pure python interface to the
724 ipmagic(). This completes exposing a pure python interface to the
718 alias and magic system, which can be used in loops or more complex
725 alias and magic system, which can be used in loops or more complex
719 code where IPython's automatic line mangling is not active.
726 code where IPython's automatic line mangling is not active.
720
727
721 * IPython/genutils.py (timing): changed interface of timing to
728 * IPython/genutils.py (timing): changed interface of timing to
722 simply run code once, which is the most common case. timings()
729 simply run code once, which is the most common case. timings()
723 remains unchanged, for the cases where you want multiple runs.
730 remains unchanged, for the cases where you want multiple runs.
724
731
725 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
732 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
726 bug where Python2.2 crashes with exec'ing code which does not end
733 bug where Python2.2 crashes with exec'ing code which does not end
727 in a single newline. Python 2.3 is OK, so I hadn't noticed this
734 in a single newline. Python 2.3 is OK, so I hadn't noticed this
728 before.
735 before.
729
736
730 2004-12-10 Fernando Perez <fperez@colorado.edu>
737 2004-12-10 Fernando Perez <fperez@colorado.edu>
731
738
732 * IPython/Magic.py (Magic.magic_prun): changed name of option from
739 * IPython/Magic.py (Magic.magic_prun): changed name of option from
733 -t to -T, to accomodate the new -t flag in %run (the %run and
740 -t to -T, to accomodate the new -t flag in %run (the %run and
734 %prun options are kind of intermixed, and it's not easy to change
741 %prun options are kind of intermixed, and it's not easy to change
735 this with the limitations of python's getopt).
742 this with the limitations of python's getopt).
736
743
737 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
744 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
738 the execution of scripts. It's not as fine-tuned as timeit.py,
745 the execution of scripts. It's not as fine-tuned as timeit.py,
739 but it works from inside ipython (and under 2.2, which lacks
746 but it works from inside ipython (and under 2.2, which lacks
740 timeit.py). Optionally a number of runs > 1 can be given for
747 timeit.py). Optionally a number of runs > 1 can be given for
741 timing very short-running code.
748 timing very short-running code.
742
749
743 * IPython/genutils.py (uniq_stable): new routine which returns a
750 * IPython/genutils.py (uniq_stable): new routine which returns a
744 list of unique elements in any iterable, but in stable order of
751 list of unique elements in any iterable, but in stable order of
745 appearance. I needed this for the ultraTB fixes, and it's a handy
752 appearance. I needed this for the ultraTB fixes, and it's a handy
746 utility.
753 utility.
747
754
748 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
755 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
749 dotted names in Verbose exceptions. This had been broken since
756 dotted names in Verbose exceptions. This had been broken since
750 the very start, now x.y will properly be printed in a Verbose
757 the very start, now x.y will properly be printed in a Verbose
751 traceback, instead of x being shown and y appearing always as an
758 traceback, instead of x being shown and y appearing always as an
752 'undefined global'. Getting this to work was a bit tricky,
759 'undefined global'. Getting this to work was a bit tricky,
753 because by default python tokenizers are stateless. Saved by
760 because by default python tokenizers are stateless. Saved by
754 python's ability to easily add a bit of state to an arbitrary
761 python's ability to easily add a bit of state to an arbitrary
755 function (without needing to build a full-blown callable object).
762 function (without needing to build a full-blown callable object).
756
763
757 Also big cleanup of this code, which had horrendous runtime
764 Also big cleanup of this code, which had horrendous runtime
758 lookups of zillions of attributes for colorization. Moved all
765 lookups of zillions of attributes for colorization. Moved all
759 this code into a few templates, which make it cleaner and quicker.
766 this code into a few templates, which make it cleaner and quicker.
760
767
761 Printout quality was also improved for Verbose exceptions: one
768 Printout quality was also improved for Verbose exceptions: one
762 variable per line, and memory addresses are printed (this can be
769 variable per line, and memory addresses are printed (this can be
763 quite handy in nasty debugging situations, which is what Verbose
770 quite handy in nasty debugging situations, which is what Verbose
764 is for).
771 is for).
765
772
766 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
773 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
767 the command line as scripts to be loaded by embedded instances.
774 the command line as scripts to be loaded by embedded instances.
768 Doing so has the potential for an infinite recursion if there are
775 Doing so has the potential for an infinite recursion if there are
769 exceptions thrown in the process. This fixes a strange crash
776 exceptions thrown in the process. This fixes a strange crash
770 reported by Philippe MULLER <muller-AT-irit.fr>.
777 reported by Philippe MULLER <muller-AT-irit.fr>.
771
778
772 2004-12-09 Fernando Perez <fperez@colorado.edu>
779 2004-12-09 Fernando Perez <fperez@colorado.edu>
773
780
774 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
781 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
775 to reflect new names in matplotlib, which now expose the
782 to reflect new names in matplotlib, which now expose the
776 matlab-compatible interface via a pylab module instead of the
783 matlab-compatible interface via a pylab module instead of the
777 'matlab' name. The new code is backwards compatible, so users of
784 'matlab' name. The new code is backwards compatible, so users of
778 all matplotlib versions are OK. Patch by J. Hunter.
785 all matplotlib versions are OK. Patch by J. Hunter.
779
786
780 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
787 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
781 of __init__ docstrings for instances (class docstrings are already
788 of __init__ docstrings for instances (class docstrings are already
782 automatically printed). Instances with customized docstrings
789 automatically printed). Instances with customized docstrings
783 (indep. of the class) are also recognized and all 3 separate
790 (indep. of the class) are also recognized and all 3 separate
784 docstrings are printed (instance, class, constructor). After some
791 docstrings are printed (instance, class, constructor). After some
785 comments/suggestions by J. Hunter.
792 comments/suggestions by J. Hunter.
786
793
787 2004-12-05 Fernando Perez <fperez@colorado.edu>
794 2004-12-05 Fernando Perez <fperez@colorado.edu>
788
795
789 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
796 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
790 warnings when tab-completion fails and triggers an exception.
797 warnings when tab-completion fails and triggers an exception.
791
798
792 2004-12-03 Fernando Perez <fperez@colorado.edu>
799 2004-12-03 Fernando Perez <fperez@colorado.edu>
793
800
794 * IPython/Magic.py (magic_prun): Fix bug where an exception would
801 * IPython/Magic.py (magic_prun): Fix bug where an exception would
795 be triggered when using 'run -p'. An incorrect option flag was
802 be triggered when using 'run -p'. An incorrect option flag was
796 being set ('d' instead of 'D').
803 being set ('d' instead of 'D').
797 (manpage): fix missing escaped \- sign.
804 (manpage): fix missing escaped \- sign.
798
805
799 2004-11-30 *** Released version 0.6.5
806 2004-11-30 *** Released version 0.6.5
800
807
801 2004-11-30 Fernando Perez <fperez@colorado.edu>
808 2004-11-30 Fernando Perez <fperez@colorado.edu>
802
809
803 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
810 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
804 setting with -d option.
811 setting with -d option.
805
812
806 * setup.py (docfiles): Fix problem where the doc glob I was using
813 * setup.py (docfiles): Fix problem where the doc glob I was using
807 was COMPLETELY BROKEN. It was giving the right files by pure
814 was COMPLETELY BROKEN. It was giving the right files by pure
808 accident, but failed once I tried to include ipython.el. Note:
815 accident, but failed once I tried to include ipython.el. Note:
809 glob() does NOT allow you to do exclusion on multiple endings!
816 glob() does NOT allow you to do exclusion on multiple endings!
810
817
811 2004-11-29 Fernando Perez <fperez@colorado.edu>
818 2004-11-29 Fernando Perez <fperez@colorado.edu>
812
819
813 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
820 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
814 the manpage as the source. Better formatting & consistency.
821 the manpage as the source. Better formatting & consistency.
815
822
816 * IPython/Magic.py (magic_run): Added new -d option, to run
823 * IPython/Magic.py (magic_run): Added new -d option, to run
817 scripts under the control of the python pdb debugger. Note that
824 scripts under the control of the python pdb debugger. Note that
818 this required changing the %prun option -d to -D, to avoid a clash
825 this required changing the %prun option -d to -D, to avoid a clash
819 (since %run must pass options to %prun, and getopt is too dumb to
826 (since %run must pass options to %prun, and getopt is too dumb to
820 handle options with string values with embedded spaces). Thanks
827 handle options with string values with embedded spaces). Thanks
821 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
828 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
822 (magic_who_ls): added type matching to %who and %whos, so that one
829 (magic_who_ls): added type matching to %who and %whos, so that one
823 can filter their output to only include variables of certain
830 can filter their output to only include variables of certain
824 types. Another suggestion by Matthew.
831 types. Another suggestion by Matthew.
825 (magic_whos): Added memory summaries in kb and Mb for arrays.
832 (magic_whos): Added memory summaries in kb and Mb for arrays.
826 (magic_who): Improve formatting (break lines every 9 vars).
833 (magic_who): Improve formatting (break lines every 9 vars).
827
834
828 2004-11-28 Fernando Perez <fperez@colorado.edu>
835 2004-11-28 Fernando Perez <fperez@colorado.edu>
829
836
830 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
837 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
831 cache when empty lines were present.
838 cache when empty lines were present.
832
839
833 2004-11-24 Fernando Perez <fperez@colorado.edu>
840 2004-11-24 Fernando Perez <fperez@colorado.edu>
834
841
835 * IPython/usage.py (__doc__): document the re-activated threading
842 * IPython/usage.py (__doc__): document the re-activated threading
836 options for WX and GTK.
843 options for WX and GTK.
837
844
838 2004-11-23 Fernando Perez <fperez@colorado.edu>
845 2004-11-23 Fernando Perez <fperez@colorado.edu>
839
846
840 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
847 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
841 the -wthread and -gthread options, along with a new -tk one to try
848 the -wthread and -gthread options, along with a new -tk one to try
842 and coordinate Tk threading with wx/gtk. The tk support is very
849 and coordinate Tk threading with wx/gtk. The tk support is very
843 platform dependent, since it seems to require Tcl and Tk to be
850 platform dependent, since it seems to require Tcl and Tk to be
844 built with threads (Fedora1/2 appears NOT to have it, but in
851 built with threads (Fedora1/2 appears NOT to have it, but in
845 Prabhu's Debian boxes it works OK). But even with some Tk
852 Prabhu's Debian boxes it works OK). But even with some Tk
846 limitations, this is a great improvement.
853 limitations, this is a great improvement.
847
854
848 * IPython/Prompts.py (prompt_specials_color): Added \t for time
855 * IPython/Prompts.py (prompt_specials_color): Added \t for time
849 info in user prompts. Patch by Prabhu.
856 info in user prompts. Patch by Prabhu.
850
857
851 2004-11-18 Fernando Perez <fperez@colorado.edu>
858 2004-11-18 Fernando Perez <fperez@colorado.edu>
852
859
853 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
860 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
854 EOFErrors and bail, to avoid infinite loops if a non-terminating
861 EOFErrors and bail, to avoid infinite loops if a non-terminating
855 file is fed into ipython. Patch submitted in issue 19 by user,
862 file is fed into ipython. Patch submitted in issue 19 by user,
856 many thanks.
863 many thanks.
857
864
858 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
865 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
859 autoquote/parens in continuation prompts, which can cause lots of
866 autoquote/parens in continuation prompts, which can cause lots of
860 problems. Closes roundup issue 20.
867 problems. Closes roundup issue 20.
861
868
862 2004-11-17 Fernando Perez <fperez@colorado.edu>
869 2004-11-17 Fernando Perez <fperez@colorado.edu>
863
870
864 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
871 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
865 reported as debian bug #280505. I'm not sure my local changelog
872 reported as debian bug #280505. I'm not sure my local changelog
866 entry has the proper debian format (Jack?).
873 entry has the proper debian format (Jack?).
867
874
868 2004-11-08 *** Released version 0.6.4
875 2004-11-08 *** Released version 0.6.4
869
876
870 2004-11-08 Fernando Perez <fperez@colorado.edu>
877 2004-11-08 Fernando Perez <fperez@colorado.edu>
871
878
872 * IPython/iplib.py (init_readline): Fix exit message for Windows
879 * IPython/iplib.py (init_readline): Fix exit message for Windows
873 when readline is active. Thanks to a report by Eric Jones
880 when readline is active. Thanks to a report by Eric Jones
874 <eric-AT-enthought.com>.
881 <eric-AT-enthought.com>.
875
882
876 2004-11-07 Fernando Perez <fperez@colorado.edu>
883 2004-11-07 Fernando Perez <fperez@colorado.edu>
877
884
878 * IPython/genutils.py (page): Add a trap for OSError exceptions,
885 * IPython/genutils.py (page): Add a trap for OSError exceptions,
879 sometimes seen by win2k/cygwin users.
886 sometimes seen by win2k/cygwin users.
880
887
881 2004-11-06 Fernando Perez <fperez@colorado.edu>
888 2004-11-06 Fernando Perez <fperez@colorado.edu>
882
889
883 * IPython/iplib.py (interact): Change the handling of %Exit from
890 * IPython/iplib.py (interact): Change the handling of %Exit from
884 trying to propagate a SystemExit to an internal ipython flag.
891 trying to propagate a SystemExit to an internal ipython flag.
885 This is less elegant than using Python's exception mechanism, but
892 This is less elegant than using Python's exception mechanism, but
886 I can't get that to work reliably with threads, so under -pylab
893 I can't get that to work reliably with threads, so under -pylab
887 %Exit was hanging IPython. Cross-thread exception handling is
894 %Exit was hanging IPython. Cross-thread exception handling is
888 really a bitch. Thaks to a bug report by Stephen Walton
895 really a bitch. Thaks to a bug report by Stephen Walton
889 <stephen.walton-AT-csun.edu>.
896 <stephen.walton-AT-csun.edu>.
890
897
891 2004-11-04 Fernando Perez <fperez@colorado.edu>
898 2004-11-04 Fernando Perez <fperez@colorado.edu>
892
899
893 * IPython/iplib.py (raw_input_original): store a pointer to the
900 * IPython/iplib.py (raw_input_original): store a pointer to the
894 true raw_input to harden against code which can modify it
901 true raw_input to harden against code which can modify it
895 (wx.py.PyShell does this and would otherwise crash ipython).
902 (wx.py.PyShell does this and would otherwise crash ipython).
896 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
903 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
897
904
898 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
905 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
899 Ctrl-C problem, which does not mess up the input line.
906 Ctrl-C problem, which does not mess up the input line.
900
907
901 2004-11-03 Fernando Perez <fperez@colorado.edu>
908 2004-11-03 Fernando Perez <fperez@colorado.edu>
902
909
903 * IPython/Release.py: Changed licensing to BSD, in all files.
910 * IPython/Release.py: Changed licensing to BSD, in all files.
904 (name): lowercase name for tarball/RPM release.
911 (name): lowercase name for tarball/RPM release.
905
912
906 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
913 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
907 use throughout ipython.
914 use throughout ipython.
908
915
909 * IPython/Magic.py (Magic._ofind): Switch to using the new
916 * IPython/Magic.py (Magic._ofind): Switch to using the new
910 OInspect.getdoc() function.
917 OInspect.getdoc() function.
911
918
912 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
919 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
913 of the line currently being canceled via Ctrl-C. It's extremely
920 of the line currently being canceled via Ctrl-C. It's extremely
914 ugly, but I don't know how to do it better (the problem is one of
921 ugly, but I don't know how to do it better (the problem is one of
915 handling cross-thread exceptions).
922 handling cross-thread exceptions).
916
923
917 2004-10-28 Fernando Perez <fperez@colorado.edu>
924 2004-10-28 Fernando Perez <fperez@colorado.edu>
918
925
919 * IPython/Shell.py (signal_handler): add signal handlers to trap
926 * IPython/Shell.py (signal_handler): add signal handlers to trap
920 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
927 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
921 report by Francesc Alted.
928 report by Francesc Alted.
922
929
923 2004-10-21 Fernando Perez <fperez@colorado.edu>
930 2004-10-21 Fernando Perez <fperez@colorado.edu>
924
931
925 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
932 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
926 to % for pysh syntax extensions.
933 to % for pysh syntax extensions.
927
934
928 2004-10-09 Fernando Perez <fperez@colorado.edu>
935 2004-10-09 Fernando Perez <fperez@colorado.edu>
929
936
930 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
937 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
931 arrays to print a more useful summary, without calling str(arr).
938 arrays to print a more useful summary, without calling str(arr).
932 This avoids the problem of extremely lengthy computations which
939 This avoids the problem of extremely lengthy computations which
933 occur if arr is large, and appear to the user as a system lockup
940 occur if arr is large, and appear to the user as a system lockup
934 with 100% cpu activity. After a suggestion by Kristian Sandberg
941 with 100% cpu activity. After a suggestion by Kristian Sandberg
935 <Kristian.Sandberg@colorado.edu>.
942 <Kristian.Sandberg@colorado.edu>.
936 (Magic.__init__): fix bug in global magic escapes not being
943 (Magic.__init__): fix bug in global magic escapes not being
937 correctly set.
944 correctly set.
938
945
939 2004-10-08 Fernando Perez <fperez@colorado.edu>
946 2004-10-08 Fernando Perez <fperez@colorado.edu>
940
947
941 * IPython/Magic.py (__license__): change to absolute imports of
948 * IPython/Magic.py (__license__): change to absolute imports of
942 ipython's own internal packages, to start adapting to the absolute
949 ipython's own internal packages, to start adapting to the absolute
943 import requirement of PEP-328.
950 import requirement of PEP-328.
944
951
945 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
952 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
946 files, and standardize author/license marks through the Release
953 files, and standardize author/license marks through the Release
947 module instead of having per/file stuff (except for files with
954 module instead of having per/file stuff (except for files with
948 particular licenses, like the MIT/PSF-licensed codes).
955 particular licenses, like the MIT/PSF-licensed codes).
949
956
950 * IPython/Debugger.py: remove dead code for python 2.1
957 * IPython/Debugger.py: remove dead code for python 2.1
951
958
952 2004-10-04 Fernando Perez <fperez@colorado.edu>
959 2004-10-04 Fernando Perez <fperez@colorado.edu>
953
960
954 * IPython/iplib.py (ipmagic): New function for accessing magics
961 * IPython/iplib.py (ipmagic): New function for accessing magics
955 via a normal python function call.
962 via a normal python function call.
956
963
957 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
964 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
958 from '@' to '%', to accomodate the new @decorator syntax of python
965 from '@' to '%', to accomodate the new @decorator syntax of python
959 2.4.
966 2.4.
960
967
961 2004-09-29 Fernando Perez <fperez@colorado.edu>
968 2004-09-29 Fernando Perez <fperez@colorado.edu>
962
969
963 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
970 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
964 matplotlib.use to prevent running scripts which try to switch
971 matplotlib.use to prevent running scripts which try to switch
965 interactive backends from within ipython. This will just crash
972 interactive backends from within ipython. This will just crash
966 the python interpreter, so we can't allow it (but a detailed error
973 the python interpreter, so we can't allow it (but a detailed error
967 is given to the user).
974 is given to the user).
968
975
969 2004-09-28 Fernando Perez <fperez@colorado.edu>
976 2004-09-28 Fernando Perez <fperez@colorado.edu>
970
977
971 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
978 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
972 matplotlib-related fixes so that using @run with non-matplotlib
979 matplotlib-related fixes so that using @run with non-matplotlib
973 scripts doesn't pop up spurious plot windows. This requires
980 scripts doesn't pop up spurious plot windows. This requires
974 matplotlib >= 0.63, where I had to make some changes as well.
981 matplotlib >= 0.63, where I had to make some changes as well.
975
982
976 * IPython/ipmaker.py (make_IPython): update version requirement to
983 * IPython/ipmaker.py (make_IPython): update version requirement to
977 python 2.2.
984 python 2.2.
978
985
979 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
986 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
980 banner arg for embedded customization.
987 banner arg for embedded customization.
981
988
982 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
989 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
983 explicit uses of __IP as the IPython's instance name. Now things
990 explicit uses of __IP as the IPython's instance name. Now things
984 are properly handled via the shell.name value. The actual code
991 are properly handled via the shell.name value. The actual code
985 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
992 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
986 is much better than before. I'll clean things completely when the
993 is much better than before. I'll clean things completely when the
987 magic stuff gets a real overhaul.
994 magic stuff gets a real overhaul.
988
995
989 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
996 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
990 minor changes to debian dir.
997 minor changes to debian dir.
991
998
992 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
999 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
993 pointer to the shell itself in the interactive namespace even when
1000 pointer to the shell itself in the interactive namespace even when
994 a user-supplied dict is provided. This is needed for embedding
1001 a user-supplied dict is provided. This is needed for embedding
995 purposes (found by tests with Michel Sanner).
1002 purposes (found by tests with Michel Sanner).
996
1003
997 2004-09-27 Fernando Perez <fperez@colorado.edu>
1004 2004-09-27 Fernando Perez <fperez@colorado.edu>
998
1005
999 * IPython/UserConfig/ipythonrc: remove []{} from
1006 * IPython/UserConfig/ipythonrc: remove []{} from
1000 readline_remove_delims, so that things like [modname.<TAB> do
1007 readline_remove_delims, so that things like [modname.<TAB> do
1001 proper completion. This disables [].TAB, but that's a less common
1008 proper completion. This disables [].TAB, but that's a less common
1002 case than module names in list comprehensions, for example.
1009 case than module names in list comprehensions, for example.
1003 Thanks to a report by Andrea Riciputi.
1010 Thanks to a report by Andrea Riciputi.
1004
1011
1005 2004-09-09 Fernando Perez <fperez@colorado.edu>
1012 2004-09-09 Fernando Perez <fperez@colorado.edu>
1006
1013
1007 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
1014 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
1008 blocking problems in win32 and osx. Fix by John.
1015 blocking problems in win32 and osx. Fix by John.
1009
1016
1010 2004-09-08 Fernando Perez <fperez@colorado.edu>
1017 2004-09-08 Fernando Perez <fperez@colorado.edu>
1011
1018
1012 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
1019 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
1013 for Win32 and OSX. Fix by John Hunter.
1020 for Win32 and OSX. Fix by John Hunter.
1014
1021
1015 2004-08-30 *** Released version 0.6.3
1022 2004-08-30 *** Released version 0.6.3
1016
1023
1017 2004-08-30 Fernando Perez <fperez@colorado.edu>
1024 2004-08-30 Fernando Perez <fperez@colorado.edu>
1018
1025
1019 * setup.py (isfile): Add manpages to list of dependent files to be
1026 * setup.py (isfile): Add manpages to list of dependent files to be
1020 updated.
1027 updated.
1021
1028
1022 2004-08-27 Fernando Perez <fperez@colorado.edu>
1029 2004-08-27 Fernando Perez <fperez@colorado.edu>
1023
1030
1024 * IPython/Shell.py (start): I've disabled -wthread and -gthread
1031 * IPython/Shell.py (start): I've disabled -wthread and -gthread
1025 for now. They don't really work with standalone WX/GTK code
1032 for now. They don't really work with standalone WX/GTK code
1026 (though matplotlib IS working fine with both of those backends).
1033 (though matplotlib IS working fine with both of those backends).
1027 This will neeed much more testing. I disabled most things with
1034 This will neeed much more testing. I disabled most things with
1028 comments, so turning it back on later should be pretty easy.
1035 comments, so turning it back on later should be pretty easy.
1029
1036
1030 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
1037 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
1031 autocalling of expressions like r'foo', by modifying the line
1038 autocalling of expressions like r'foo', by modifying the line
1032 split regexp. Closes
1039 split regexp. Closes
1033 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
1040 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
1034 Riley <ipythonbugs-AT-sabi.net>.
1041 Riley <ipythonbugs-AT-sabi.net>.
1035 (InteractiveShell.mainloop): honor --nobanner with banner
1042 (InteractiveShell.mainloop): honor --nobanner with banner
1036 extensions.
1043 extensions.
1037
1044
1038 * IPython/Shell.py: Significant refactoring of all classes, so
1045 * IPython/Shell.py: Significant refactoring of all classes, so
1039 that we can really support ALL matplotlib backends and threading
1046 that we can really support ALL matplotlib backends and threading
1040 models (John spotted a bug with Tk which required this). Now we
1047 models (John spotted a bug with Tk which required this). Now we
1041 should support single-threaded, WX-threads and GTK-threads, both
1048 should support single-threaded, WX-threads and GTK-threads, both
1042 for generic code and for matplotlib.
1049 for generic code and for matplotlib.
1043
1050
1044 * IPython/ipmaker.py (__call__): Changed -mpthread option to
1051 * IPython/ipmaker.py (__call__): Changed -mpthread option to
1045 -pylab, to simplify things for users. Will also remove the pylab
1052 -pylab, to simplify things for users. Will also remove the pylab
1046 profile, since now all of matplotlib configuration is directly
1053 profile, since now all of matplotlib configuration is directly
1047 handled here. This also reduces startup time.
1054 handled here. This also reduces startup time.
1048
1055
1049 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
1056 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
1050 shell wasn't being correctly called. Also in IPShellWX.
1057 shell wasn't being correctly called. Also in IPShellWX.
1051
1058
1052 * IPython/iplib.py (InteractiveShell.__init__): Added option to
1059 * IPython/iplib.py (InteractiveShell.__init__): Added option to
1053 fine-tune banner.
1060 fine-tune banner.
1054
1061
1055 * IPython/numutils.py (spike): Deprecate these spike functions,
1062 * IPython/numutils.py (spike): Deprecate these spike functions,
1056 delete (long deprecated) gnuplot_exec handler.
1063 delete (long deprecated) gnuplot_exec handler.
1057
1064
1058 2004-08-26 Fernando Perez <fperez@colorado.edu>
1065 2004-08-26 Fernando Perez <fperez@colorado.edu>
1059
1066
1060 * ipython.1: Update for threading options, plus some others which
1067 * ipython.1: Update for threading options, plus some others which
1061 were missing.
1068 were missing.
1062
1069
1063 * IPython/ipmaker.py (__call__): Added -wthread option for
1070 * IPython/ipmaker.py (__call__): Added -wthread option for
1064 wxpython thread handling. Make sure threading options are only
1071 wxpython thread handling. Make sure threading options are only
1065 valid at the command line.
1072 valid at the command line.
1066
1073
1067 * scripts/ipython: moved shell selection into a factory function
1074 * scripts/ipython: moved shell selection into a factory function
1068 in Shell.py, to keep the starter script to a minimum.
1075 in Shell.py, to keep the starter script to a minimum.
1069
1076
1070 2004-08-25 Fernando Perez <fperez@colorado.edu>
1077 2004-08-25 Fernando Perez <fperez@colorado.edu>
1071
1078
1072 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
1079 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
1073 John. Along with some recent changes he made to matplotlib, the
1080 John. Along with some recent changes he made to matplotlib, the
1074 next versions of both systems should work very well together.
1081 next versions of both systems should work very well together.
1075
1082
1076 2004-08-24 Fernando Perez <fperez@colorado.edu>
1083 2004-08-24 Fernando Perez <fperez@colorado.edu>
1077
1084
1078 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
1085 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
1079 tried to switch the profiling to using hotshot, but I'm getting
1086 tried to switch the profiling to using hotshot, but I'm getting
1080 strange errors from prof.runctx() there. I may be misreading the
1087 strange errors from prof.runctx() there. I may be misreading the
1081 docs, but it looks weird. For now the profiling code will
1088 docs, but it looks weird. For now the profiling code will
1082 continue to use the standard profiler.
1089 continue to use the standard profiler.
1083
1090
1084 2004-08-23 Fernando Perez <fperez@colorado.edu>
1091 2004-08-23 Fernando Perez <fperez@colorado.edu>
1085
1092
1086 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
1093 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
1087 threaded shell, by John Hunter. It's not quite ready yet, but
1094 threaded shell, by John Hunter. It's not quite ready yet, but
1088 close.
1095 close.
1089
1096
1090 2004-08-22 Fernando Perez <fperez@colorado.edu>
1097 2004-08-22 Fernando Perez <fperez@colorado.edu>
1091
1098
1092 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
1099 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
1093 in Magic and ultraTB.
1100 in Magic and ultraTB.
1094
1101
1095 * ipython.1: document threading options in manpage.
1102 * ipython.1: document threading options in manpage.
1096
1103
1097 * scripts/ipython: Changed name of -thread option to -gthread,
1104 * scripts/ipython: Changed name of -thread option to -gthread,
1098 since this is GTK specific. I want to leave the door open for a
1105 since this is GTK specific. I want to leave the door open for a
1099 -wthread option for WX, which will most likely be necessary. This
1106 -wthread option for WX, which will most likely be necessary. This
1100 change affects usage and ipmaker as well.
1107 change affects usage and ipmaker as well.
1101
1108
1102 * IPython/Shell.py (matplotlib_shell): Add a factory function to
1109 * IPython/Shell.py (matplotlib_shell): Add a factory function to
1103 handle the matplotlib shell issues. Code by John Hunter
1110 handle the matplotlib shell issues. Code by John Hunter
1104 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1111 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1105 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
1112 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
1106 broken (and disabled for end users) for now, but it puts the
1113 broken (and disabled for end users) for now, but it puts the
1107 infrastructure in place.
1114 infrastructure in place.
1108
1115
1109 2004-08-21 Fernando Perez <fperez@colorado.edu>
1116 2004-08-21 Fernando Perez <fperez@colorado.edu>
1110
1117
1111 * ipythonrc-pylab: Add matplotlib support.
1118 * ipythonrc-pylab: Add matplotlib support.
1112
1119
1113 * matplotlib_config.py: new files for matplotlib support, part of
1120 * matplotlib_config.py: new files for matplotlib support, part of
1114 the pylab profile.
1121 the pylab profile.
1115
1122
1116 * IPython/usage.py (__doc__): documented the threading options.
1123 * IPython/usage.py (__doc__): documented the threading options.
1117
1124
1118 2004-08-20 Fernando Perez <fperez@colorado.edu>
1125 2004-08-20 Fernando Perez <fperez@colorado.edu>
1119
1126
1120 * ipython: Modified the main calling routine to handle the -thread
1127 * ipython: Modified the main calling routine to handle the -thread
1121 and -mpthread options. This needs to be done as a top-level hack,
1128 and -mpthread options. This needs to be done as a top-level hack,
1122 because it determines which class to instantiate for IPython
1129 because it determines which class to instantiate for IPython
1123 itself.
1130 itself.
1124
1131
1125 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
1132 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
1126 classes to support multithreaded GTK operation without blocking,
1133 classes to support multithreaded GTK operation without blocking,
1127 and matplotlib with all backends. This is a lot of still very
1134 and matplotlib with all backends. This is a lot of still very
1128 experimental code, and threads are tricky. So it may still have a
1135 experimental code, and threads are tricky. So it may still have a
1129 few rough edges... This code owes a lot to
1136 few rough edges... This code owes a lot to
1130 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
1137 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
1131 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
1138 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
1132 to John Hunter for all the matplotlib work.
1139 to John Hunter for all the matplotlib work.
1133
1140
1134 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
1141 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
1135 options for gtk thread and matplotlib support.
1142 options for gtk thread and matplotlib support.
1136
1143
1137 2004-08-16 Fernando Perez <fperez@colorado.edu>
1144 2004-08-16 Fernando Perez <fperez@colorado.edu>
1138
1145
1139 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
1146 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
1140 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
1147 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
1141 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
1148 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
1142
1149
1143 2004-08-11 Fernando Perez <fperez@colorado.edu>
1150 2004-08-11 Fernando Perez <fperez@colorado.edu>
1144
1151
1145 * setup.py (isfile): Fix build so documentation gets updated for
1152 * setup.py (isfile): Fix build so documentation gets updated for
1146 rpms (it was only done for .tgz builds).
1153 rpms (it was only done for .tgz builds).
1147
1154
1148 2004-08-10 Fernando Perez <fperez@colorado.edu>
1155 2004-08-10 Fernando Perez <fperez@colorado.edu>
1149
1156
1150 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
1157 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
1151
1158
1152 * iplib.py : Silence syntax error exceptions in tab-completion.
1159 * iplib.py : Silence syntax error exceptions in tab-completion.
1153
1160
1154 2004-08-05 Fernando Perez <fperez@colorado.edu>
1161 2004-08-05 Fernando Perez <fperez@colorado.edu>
1155
1162
1156 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
1163 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
1157 'color off' mark for continuation prompts. This was causing long
1164 'color off' mark for continuation prompts. This was causing long
1158 continuation lines to mis-wrap.
1165 continuation lines to mis-wrap.
1159
1166
1160 2004-08-01 Fernando Perez <fperez@colorado.edu>
1167 2004-08-01 Fernando Perez <fperez@colorado.edu>
1161
1168
1162 * IPython/ipmaker.py (make_IPython): Allow the shell class used
1169 * IPython/ipmaker.py (make_IPython): Allow the shell class used
1163 for building ipython to be a parameter. All this is necessary
1170 for building ipython to be a parameter. All this is necessary
1164 right now to have a multithreaded version, but this insane
1171 right now to have a multithreaded version, but this insane
1165 non-design will be cleaned up soon. For now, it's a hack that
1172 non-design will be cleaned up soon. For now, it's a hack that
1166 works.
1173 works.
1167
1174
1168 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
1175 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
1169 args in various places. No bugs so far, but it's a dangerous
1176 args in various places. No bugs so far, but it's a dangerous
1170 practice.
1177 practice.
1171
1178
1172 2004-07-31 Fernando Perez <fperez@colorado.edu>
1179 2004-07-31 Fernando Perez <fperez@colorado.edu>
1173
1180
1174 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
1181 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
1175 fix completion of files with dots in their names under most
1182 fix completion of files with dots in their names under most
1176 profiles (pysh was OK because the completion order is different).
1183 profiles (pysh was OK because the completion order is different).
1177
1184
1178 2004-07-27 Fernando Perez <fperez@colorado.edu>
1185 2004-07-27 Fernando Perez <fperez@colorado.edu>
1179
1186
1180 * IPython/iplib.py (InteractiveShell.__init__): build dict of
1187 * IPython/iplib.py (InteractiveShell.__init__): build dict of
1181 keywords manually, b/c the one in keyword.py was removed in python
1188 keywords manually, b/c the one in keyword.py was removed in python
1182 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
1189 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
1183 This is NOT a bug under python 2.3 and earlier.
1190 This is NOT a bug under python 2.3 and earlier.
1184
1191
1185 2004-07-26 Fernando Perez <fperez@colorado.edu>
1192 2004-07-26 Fernando Perez <fperez@colorado.edu>
1186
1193
1187 * IPython/ultraTB.py (VerboseTB.text): Add another
1194 * IPython/ultraTB.py (VerboseTB.text): Add another
1188 linecache.checkcache() call to try to prevent inspect.py from
1195 linecache.checkcache() call to try to prevent inspect.py from
1189 crashing under python 2.3. I think this fixes
1196 crashing under python 2.3. I think this fixes
1190 http://www.scipy.net/roundup/ipython/issue17.
1197 http://www.scipy.net/roundup/ipython/issue17.
1191
1198
1192 2004-07-26 *** Released version 0.6.2
1199 2004-07-26 *** Released version 0.6.2
1193
1200
1194 2004-07-26 Fernando Perez <fperez@colorado.edu>
1201 2004-07-26 Fernando Perez <fperez@colorado.edu>
1195
1202
1196 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
1203 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
1197 fail for any number.
1204 fail for any number.
1198 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
1205 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
1199 empty bookmarks.
1206 empty bookmarks.
1200
1207
1201 2004-07-26 *** Released version 0.6.1
1208 2004-07-26 *** Released version 0.6.1
1202
1209
1203 2004-07-26 Fernando Perez <fperez@colorado.edu>
1210 2004-07-26 Fernando Perez <fperez@colorado.edu>
1204
1211
1205 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
1212 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
1206
1213
1207 * IPython/iplib.py (protect_filename): Applied Ville's patch for
1214 * IPython/iplib.py (protect_filename): Applied Ville's patch for
1208 escaping '()[]{}' in filenames.
1215 escaping '()[]{}' in filenames.
1209
1216
1210 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
1217 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
1211 Python 2.2 users who lack a proper shlex.split.
1218 Python 2.2 users who lack a proper shlex.split.
1212
1219
1213 2004-07-19 Fernando Perez <fperez@colorado.edu>
1220 2004-07-19 Fernando Perez <fperez@colorado.edu>
1214
1221
1215 * IPython/iplib.py (InteractiveShell.init_readline): Add support
1222 * IPython/iplib.py (InteractiveShell.init_readline): Add support
1216 for reading readline's init file. I follow the normal chain:
1223 for reading readline's init file. I follow the normal chain:
1217 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
1224 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
1218 report by Mike Heeter. This closes
1225 report by Mike Heeter. This closes
1219 http://www.scipy.net/roundup/ipython/issue16.
1226 http://www.scipy.net/roundup/ipython/issue16.
1220
1227
1221 2004-07-18 Fernando Perez <fperez@colorado.edu>
1228 2004-07-18 Fernando Perez <fperez@colorado.edu>
1222
1229
1223 * IPython/iplib.py (__init__): Add better handling of '\' under
1230 * IPython/iplib.py (__init__): Add better handling of '\' under
1224 Win32 for filenames. After a patch by Ville.
1231 Win32 for filenames. After a patch by Ville.
1225
1232
1226 2004-07-17 Fernando Perez <fperez@colorado.edu>
1233 2004-07-17 Fernando Perez <fperez@colorado.edu>
1227
1234
1228 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1235 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1229 autocalling would be triggered for 'foo is bar' if foo is
1236 autocalling would be triggered for 'foo is bar' if foo is
1230 callable. I also cleaned up the autocall detection code to use a
1237 callable. I also cleaned up the autocall detection code to use a
1231 regexp, which is faster. Bug reported by Alexander Schmolck.
1238 regexp, which is faster. Bug reported by Alexander Schmolck.
1232
1239
1233 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
1240 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
1234 '?' in them would confuse the help system. Reported by Alex
1241 '?' in them would confuse the help system. Reported by Alex
1235 Schmolck.
1242 Schmolck.
1236
1243
1237 2004-07-16 Fernando Perez <fperez@colorado.edu>
1244 2004-07-16 Fernando Perez <fperez@colorado.edu>
1238
1245
1239 * IPython/GnuplotInteractive.py (__all__): added plot2.
1246 * IPython/GnuplotInteractive.py (__all__): added plot2.
1240
1247
1241 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
1248 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
1242 plotting dictionaries, lists or tuples of 1d arrays.
1249 plotting dictionaries, lists or tuples of 1d arrays.
1243
1250
1244 * IPython/Magic.py (Magic.magic_hist): small clenaups and
1251 * IPython/Magic.py (Magic.magic_hist): small clenaups and
1245 optimizations.
1252 optimizations.
1246
1253
1247 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
1254 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
1248 the information which was there from Janko's original IPP code:
1255 the information which was there from Janko's original IPP code:
1249
1256
1250 03.05.99 20:53 porto.ifm.uni-kiel.de
1257 03.05.99 20:53 porto.ifm.uni-kiel.de
1251 --Started changelog.
1258 --Started changelog.
1252 --make clear do what it say it does
1259 --make clear do what it say it does
1253 --added pretty output of lines from inputcache
1260 --added pretty output of lines from inputcache
1254 --Made Logger a mixin class, simplifies handling of switches
1261 --Made Logger a mixin class, simplifies handling of switches
1255 --Added own completer class. .string<TAB> expands to last history
1262 --Added own completer class. .string<TAB> expands to last history
1256 line which starts with string. The new expansion is also present
1263 line which starts with string. The new expansion is also present
1257 with Ctrl-r from the readline library. But this shows, who this
1264 with Ctrl-r from the readline library. But this shows, who this
1258 can be done for other cases.
1265 can be done for other cases.
1259 --Added convention that all shell functions should accept a
1266 --Added convention that all shell functions should accept a
1260 parameter_string This opens the door for different behaviour for
1267 parameter_string This opens the door for different behaviour for
1261 each function. @cd is a good example of this.
1268 each function. @cd is a good example of this.
1262
1269
1263 04.05.99 12:12 porto.ifm.uni-kiel.de
1270 04.05.99 12:12 porto.ifm.uni-kiel.de
1264 --added logfile rotation
1271 --added logfile rotation
1265 --added new mainloop method which freezes first the namespace
1272 --added new mainloop method which freezes first the namespace
1266
1273
1267 07.05.99 21:24 porto.ifm.uni-kiel.de
1274 07.05.99 21:24 porto.ifm.uni-kiel.de
1268 --added the docreader classes. Now there is a help system.
1275 --added the docreader classes. Now there is a help system.
1269 -This is only a first try. Currently it's not easy to put new
1276 -This is only a first try. Currently it's not easy to put new
1270 stuff in the indices. But this is the way to go. Info would be
1277 stuff in the indices. But this is the way to go. Info would be
1271 better, but HTML is every where and not everybody has an info
1278 better, but HTML is every where and not everybody has an info
1272 system installed and it's not so easy to change html-docs to info.
1279 system installed and it's not so easy to change html-docs to info.
1273 --added global logfile option
1280 --added global logfile option
1274 --there is now a hook for object inspection method pinfo needs to
1281 --there is now a hook for object inspection method pinfo needs to
1275 be provided for this. Can be reached by two '??'.
1282 be provided for this. Can be reached by two '??'.
1276
1283
1277 08.05.99 20:51 porto.ifm.uni-kiel.de
1284 08.05.99 20:51 porto.ifm.uni-kiel.de
1278 --added a README
1285 --added a README
1279 --bug in rc file. Something has changed so functions in the rc
1286 --bug in rc file. Something has changed so functions in the rc
1280 file need to reference the shell and not self. Not clear if it's a
1287 file need to reference the shell and not self. Not clear if it's a
1281 bug or feature.
1288 bug or feature.
1282 --changed rc file for new behavior
1289 --changed rc file for new behavior
1283
1290
1284 2004-07-15 Fernando Perez <fperez@colorado.edu>
1291 2004-07-15 Fernando Perez <fperez@colorado.edu>
1285
1292
1286 * IPython/Logger.py (Logger.log): fixed recent bug where the input
1293 * IPython/Logger.py (Logger.log): fixed recent bug where the input
1287 cache was falling out of sync in bizarre manners when multi-line
1294 cache was falling out of sync in bizarre manners when multi-line
1288 input was present. Minor optimizations and cleanup.
1295 input was present. Minor optimizations and cleanup.
1289
1296
1290 (Logger): Remove old Changelog info for cleanup. This is the
1297 (Logger): Remove old Changelog info for cleanup. This is the
1291 information which was there from Janko's original code:
1298 information which was there from Janko's original code:
1292
1299
1293 Changes to Logger: - made the default log filename a parameter
1300 Changes to Logger: - made the default log filename a parameter
1294
1301
1295 - put a check for lines beginning with !@? in log(). Needed
1302 - put a check for lines beginning with !@? in log(). Needed
1296 (even if the handlers properly log their lines) for mid-session
1303 (even if the handlers properly log their lines) for mid-session
1297 logging activation to work properly. Without this, lines logged
1304 logging activation to work properly. Without this, lines logged
1298 in mid session, which get read from the cache, would end up
1305 in mid session, which get read from the cache, would end up
1299 'bare' (with !@? in the open) in the log. Now they are caught
1306 'bare' (with !@? in the open) in the log. Now they are caught
1300 and prepended with a #.
1307 and prepended with a #.
1301
1308
1302 * IPython/iplib.py (InteractiveShell.init_readline): added check
1309 * IPython/iplib.py (InteractiveShell.init_readline): added check
1303 in case MagicCompleter fails to be defined, so we don't crash.
1310 in case MagicCompleter fails to be defined, so we don't crash.
1304
1311
1305 2004-07-13 Fernando Perez <fperez@colorado.edu>
1312 2004-07-13 Fernando Perez <fperez@colorado.edu>
1306
1313
1307 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
1314 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
1308 of EPS if the requested filename ends in '.eps'.
1315 of EPS if the requested filename ends in '.eps'.
1309
1316
1310 2004-07-04 Fernando Perez <fperez@colorado.edu>
1317 2004-07-04 Fernando Perez <fperez@colorado.edu>
1311
1318
1312 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
1319 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
1313 escaping of quotes when calling the shell.
1320 escaping of quotes when calling the shell.
1314
1321
1315 2004-07-02 Fernando Perez <fperez@colorado.edu>
1322 2004-07-02 Fernando Perez <fperez@colorado.edu>
1316
1323
1317 * IPython/Prompts.py (CachedOutput.update): Fix problem with
1324 * IPython/Prompts.py (CachedOutput.update): Fix problem with
1318 gettext not working because we were clobbering '_'. Fixes
1325 gettext not working because we were clobbering '_'. Fixes
1319 http://www.scipy.net/roundup/ipython/issue6.
1326 http://www.scipy.net/roundup/ipython/issue6.
1320
1327
1321 2004-07-01 Fernando Perez <fperez@colorado.edu>
1328 2004-07-01 Fernando Perez <fperez@colorado.edu>
1322
1329
1323 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
1330 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
1324 into @cd. Patch by Ville.
1331 into @cd. Patch by Ville.
1325
1332
1326 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1333 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1327 new function to store things after ipmaker runs. Patch by Ville.
1334 new function to store things after ipmaker runs. Patch by Ville.
1328 Eventually this will go away once ipmaker is removed and the class
1335 Eventually this will go away once ipmaker is removed and the class
1329 gets cleaned up, but for now it's ok. Key functionality here is
1336 gets cleaned up, but for now it's ok. Key functionality here is
1330 the addition of the persistent storage mechanism, a dict for
1337 the addition of the persistent storage mechanism, a dict for
1331 keeping data across sessions (for now just bookmarks, but more can
1338 keeping data across sessions (for now just bookmarks, but more can
1332 be implemented later).
1339 be implemented later).
1333
1340
1334 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
1341 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
1335 persistent across sections. Patch by Ville, I modified it
1342 persistent across sections. Patch by Ville, I modified it
1336 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
1343 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
1337 added a '-l' option to list all bookmarks.
1344 added a '-l' option to list all bookmarks.
1338
1345
1339 * IPython/iplib.py (InteractiveShell.atexit_operations): new
1346 * IPython/iplib.py (InteractiveShell.atexit_operations): new
1340 center for cleanup. Registered with atexit.register(). I moved
1347 center for cleanup. Registered with atexit.register(). I moved
1341 here the old exit_cleanup(). After a patch by Ville.
1348 here the old exit_cleanup(). After a patch by Ville.
1342
1349
1343 * IPython/Magic.py (get_py_filename): added '~' to the accepted
1350 * IPython/Magic.py (get_py_filename): added '~' to the accepted
1344 characters in the hacked shlex_split for python 2.2.
1351 characters in the hacked shlex_split for python 2.2.
1345
1352
1346 * IPython/iplib.py (file_matches): more fixes to filenames with
1353 * IPython/iplib.py (file_matches): more fixes to filenames with
1347 whitespace in them. It's not perfect, but limitations in python's
1354 whitespace in them. It's not perfect, but limitations in python's
1348 readline make it impossible to go further.
1355 readline make it impossible to go further.
1349
1356
1350 2004-06-29 Fernando Perez <fperez@colorado.edu>
1357 2004-06-29 Fernando Perez <fperez@colorado.edu>
1351
1358
1352 * IPython/iplib.py (file_matches): escape whitespace correctly in
1359 * IPython/iplib.py (file_matches): escape whitespace correctly in
1353 filename completions. Bug reported by Ville.
1360 filename completions. Bug reported by Ville.
1354
1361
1355 2004-06-28 Fernando Perez <fperez@colorado.edu>
1362 2004-06-28 Fernando Perez <fperez@colorado.edu>
1356
1363
1357 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
1364 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
1358 the history file will be called 'history-PROFNAME' (or just
1365 the history file will be called 'history-PROFNAME' (or just
1359 'history' if no profile is loaded). I was getting annoyed at
1366 'history' if no profile is loaded). I was getting annoyed at
1360 getting my Numerical work history clobbered by pysh sessions.
1367 getting my Numerical work history clobbered by pysh sessions.
1361
1368
1362 * IPython/iplib.py (InteractiveShell.__init__): Internal
1369 * IPython/iplib.py (InteractiveShell.__init__): Internal
1363 getoutputerror() function so that we can honor the system_verbose
1370 getoutputerror() function so that we can honor the system_verbose
1364 flag for _all_ system calls. I also added escaping of #
1371 flag for _all_ system calls. I also added escaping of #
1365 characters here to avoid confusing Itpl.
1372 characters here to avoid confusing Itpl.
1366
1373
1367 * IPython/Magic.py (shlex_split): removed call to shell in
1374 * IPython/Magic.py (shlex_split): removed call to shell in
1368 parse_options and replaced it with shlex.split(). The annoying
1375 parse_options and replaced it with shlex.split(). The annoying
1369 part was that in Python 2.2, shlex.split() doesn't exist, so I had
1376 part was that in Python 2.2, shlex.split() doesn't exist, so I had
1370 to backport it from 2.3, with several frail hacks (the shlex
1377 to backport it from 2.3, with several frail hacks (the shlex
1371 module is rather limited in 2.2). Thanks to a suggestion by Ville
1378 module is rather limited in 2.2). Thanks to a suggestion by Ville
1372 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
1379 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
1373 problem.
1380 problem.
1374
1381
1375 (Magic.magic_system_verbose): new toggle to print the actual
1382 (Magic.magic_system_verbose): new toggle to print the actual
1376 system calls made by ipython. Mainly for debugging purposes.
1383 system calls made by ipython. Mainly for debugging purposes.
1377
1384
1378 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
1385 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
1379 doesn't support persistence. Reported (and fix suggested) by
1386 doesn't support persistence. Reported (and fix suggested) by
1380 Travis Caldwell <travis_caldwell2000@yahoo.com>.
1387 Travis Caldwell <travis_caldwell2000@yahoo.com>.
1381
1388
1382 2004-06-26 Fernando Perez <fperez@colorado.edu>
1389 2004-06-26 Fernando Perez <fperez@colorado.edu>
1383
1390
1384 * IPython/Logger.py (Logger.log): fix to handle correctly empty
1391 * IPython/Logger.py (Logger.log): fix to handle correctly empty
1385 continue prompts.
1392 continue prompts.
1386
1393
1387 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
1394 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
1388 function (basically a big docstring) and a few more things here to
1395 function (basically a big docstring) and a few more things here to
1389 speedup startup. pysh.py is now very lightweight. We want because
1396 speedup startup. pysh.py is now very lightweight. We want because
1390 it gets execfile'd, while InterpreterExec gets imported, so
1397 it gets execfile'd, while InterpreterExec gets imported, so
1391 byte-compilation saves time.
1398 byte-compilation saves time.
1392
1399
1393 2004-06-25 Fernando Perez <fperez@colorado.edu>
1400 2004-06-25 Fernando Perez <fperez@colorado.edu>
1394
1401
1395 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
1402 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
1396 -NUM', which was recently broken.
1403 -NUM', which was recently broken.
1397
1404
1398 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
1405 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
1399 in multi-line input (but not !!, which doesn't make sense there).
1406 in multi-line input (but not !!, which doesn't make sense there).
1400
1407
1401 * IPython/UserConfig/ipythonrc: made autoindent on by default.
1408 * IPython/UserConfig/ipythonrc: made autoindent on by default.
1402 It's just too useful, and people can turn it off in the less
1409 It's just too useful, and people can turn it off in the less
1403 common cases where it's a problem.
1410 common cases where it's a problem.
1404
1411
1405 2004-06-24 Fernando Perez <fperez@colorado.edu>
1412 2004-06-24 Fernando Perez <fperez@colorado.edu>
1406
1413
1407 * IPython/iplib.py (InteractiveShell._prefilter): big change -
1414 * IPython/iplib.py (InteractiveShell._prefilter): big change -
1408 special syntaxes (like alias calling) is now allied in multi-line
1415 special syntaxes (like alias calling) is now allied in multi-line
1409 input. This is still _very_ experimental, but it's necessary for
1416 input. This is still _very_ experimental, but it's necessary for
1410 efficient shell usage combining python looping syntax with system
1417 efficient shell usage combining python looping syntax with system
1411 calls. For now it's restricted to aliases, I don't think it
1418 calls. For now it's restricted to aliases, I don't think it
1412 really even makes sense to have this for magics.
1419 really even makes sense to have this for magics.
1413
1420
1414 2004-06-23 Fernando Perez <fperez@colorado.edu>
1421 2004-06-23 Fernando Perez <fperez@colorado.edu>
1415
1422
1416 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
1423 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
1417 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
1424 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
1418
1425
1419 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
1426 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
1420 extensions under Windows (after code sent by Gary Bishop). The
1427 extensions under Windows (after code sent by Gary Bishop). The
1421 extensions considered 'executable' are stored in IPython's rc
1428 extensions considered 'executable' are stored in IPython's rc
1422 structure as win_exec_ext.
1429 structure as win_exec_ext.
1423
1430
1424 * IPython/genutils.py (shell): new function, like system() but
1431 * IPython/genutils.py (shell): new function, like system() but
1425 without return value. Very useful for interactive shell work.
1432 without return value. Very useful for interactive shell work.
1426
1433
1427 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
1434 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
1428 delete aliases.
1435 delete aliases.
1429
1436
1430 * IPython/iplib.py (InteractiveShell.alias_table_update): make
1437 * IPython/iplib.py (InteractiveShell.alias_table_update): make
1431 sure that the alias table doesn't contain python keywords.
1438 sure that the alias table doesn't contain python keywords.
1432
1439
1433 2004-06-21 Fernando Perez <fperez@colorado.edu>
1440 2004-06-21 Fernando Perez <fperez@colorado.edu>
1434
1441
1435 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
1442 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
1436 non-existent items are found in $PATH. Reported by Thorsten.
1443 non-existent items are found in $PATH. Reported by Thorsten.
1437
1444
1438 2004-06-20 Fernando Perez <fperez@colorado.edu>
1445 2004-06-20 Fernando Perez <fperez@colorado.edu>
1439
1446
1440 * IPython/iplib.py (complete): modified the completer so that the
1447 * IPython/iplib.py (complete): modified the completer so that the
1441 order of priorities can be easily changed at runtime.
1448 order of priorities can be easily changed at runtime.
1442
1449
1443 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
1450 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
1444 Modified to auto-execute all lines beginning with '~', '/' or '.'.
1451 Modified to auto-execute all lines beginning with '~', '/' or '.'.
1445
1452
1446 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
1453 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
1447 expand Python variables prepended with $ in all system calls. The
1454 expand Python variables prepended with $ in all system calls. The
1448 same was done to InteractiveShell.handle_shell_escape. Now all
1455 same was done to InteractiveShell.handle_shell_escape. Now all
1449 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
1456 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
1450 expansion of python variables and expressions according to the
1457 expansion of python variables and expressions according to the
1451 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
1458 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
1452
1459
1453 Though PEP-215 has been rejected, a similar (but simpler) one
1460 Though PEP-215 has been rejected, a similar (but simpler) one
1454 seems like it will go into Python 2.4, PEP-292 -
1461 seems like it will go into Python 2.4, PEP-292 -
1455 http://www.python.org/peps/pep-0292.html.
1462 http://www.python.org/peps/pep-0292.html.
1456
1463
1457 I'll keep the full syntax of PEP-215, since IPython has since the
1464 I'll keep the full syntax of PEP-215, since IPython has since the
1458 start used Ka-Ping Yee's reference implementation discussed there
1465 start used Ka-Ping Yee's reference implementation discussed there
1459 (Itpl), and I actually like the powerful semantics it offers.
1466 (Itpl), and I actually like the powerful semantics it offers.
1460
1467
1461 In order to access normal shell variables, the $ has to be escaped
1468 In order to access normal shell variables, the $ has to be escaped
1462 via an extra $. For example:
1469 via an extra $. For example:
1463
1470
1464 In [7]: PATH='a python variable'
1471 In [7]: PATH='a python variable'
1465
1472
1466 In [8]: !echo $PATH
1473 In [8]: !echo $PATH
1467 a python variable
1474 a python variable
1468
1475
1469 In [9]: !echo $$PATH
1476 In [9]: !echo $$PATH
1470 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1477 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1471
1478
1472 (Magic.parse_options): escape $ so the shell doesn't evaluate
1479 (Magic.parse_options): escape $ so the shell doesn't evaluate
1473 things prematurely.
1480 things prematurely.
1474
1481
1475 * IPython/iplib.py (InteractiveShell.call_alias): added the
1482 * IPython/iplib.py (InteractiveShell.call_alias): added the
1476 ability for aliases to expand python variables via $.
1483 ability for aliases to expand python variables via $.
1477
1484
1478 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
1485 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
1479 system, now there's a @rehash/@rehashx pair of magics. These work
1486 system, now there's a @rehash/@rehashx pair of magics. These work
1480 like the csh rehash command, and can be invoked at any time. They
1487 like the csh rehash command, and can be invoked at any time. They
1481 build a table of aliases to everything in the user's $PATH
1488 build a table of aliases to everything in the user's $PATH
1482 (@rehash uses everything, @rehashx is slower but only adds
1489 (@rehash uses everything, @rehashx is slower but only adds
1483 executable files). With this, the pysh.py-based shell profile can
1490 executable files). With this, the pysh.py-based shell profile can
1484 now simply call rehash upon startup, and full access to all
1491 now simply call rehash upon startup, and full access to all
1485 programs in the user's path is obtained.
1492 programs in the user's path is obtained.
1486
1493
1487 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
1494 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
1488 functionality is now fully in place. I removed the old dynamic
1495 functionality is now fully in place. I removed the old dynamic
1489 code generation based approach, in favor of a much lighter one
1496 code generation based approach, in favor of a much lighter one
1490 based on a simple dict. The advantage is that this allows me to
1497 based on a simple dict. The advantage is that this allows me to
1491 now have thousands of aliases with negligible cost (unthinkable
1498 now have thousands of aliases with negligible cost (unthinkable
1492 with the old system).
1499 with the old system).
1493
1500
1494 2004-06-19 Fernando Perez <fperez@colorado.edu>
1501 2004-06-19 Fernando Perez <fperez@colorado.edu>
1495
1502
1496 * IPython/iplib.py (__init__): extended MagicCompleter class to
1503 * IPython/iplib.py (__init__): extended MagicCompleter class to
1497 also complete (last in priority) on user aliases.
1504 also complete (last in priority) on user aliases.
1498
1505
1499 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
1506 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
1500 call to eval.
1507 call to eval.
1501 (ItplNS.__init__): Added a new class which functions like Itpl,
1508 (ItplNS.__init__): Added a new class which functions like Itpl,
1502 but allows configuring the namespace for the evaluation to occur
1509 but allows configuring the namespace for the evaluation to occur
1503 in.
1510 in.
1504
1511
1505 2004-06-18 Fernando Perez <fperez@colorado.edu>
1512 2004-06-18 Fernando Perez <fperez@colorado.edu>
1506
1513
1507 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
1514 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
1508 better message when 'exit' or 'quit' are typed (a common newbie
1515 better message when 'exit' or 'quit' are typed (a common newbie
1509 confusion).
1516 confusion).
1510
1517
1511 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
1518 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
1512 check for Windows users.
1519 check for Windows users.
1513
1520
1514 * IPython/iplib.py (InteractiveShell.user_setup): removed
1521 * IPython/iplib.py (InteractiveShell.user_setup): removed
1515 disabling of colors for Windows. I'll test at runtime and issue a
1522 disabling of colors for Windows. I'll test at runtime and issue a
1516 warning if Gary's readline isn't found, as to nudge users to
1523 warning if Gary's readline isn't found, as to nudge users to
1517 download it.
1524 download it.
1518
1525
1519 2004-06-16 Fernando Perez <fperez@colorado.edu>
1526 2004-06-16 Fernando Perez <fperez@colorado.edu>
1520
1527
1521 * IPython/genutils.py (Stream.__init__): changed to print errors
1528 * IPython/genutils.py (Stream.__init__): changed to print errors
1522 to sys.stderr. I had a circular dependency here. Now it's
1529 to sys.stderr. I had a circular dependency here. Now it's
1523 possible to run ipython as IDLE's shell (consider this pre-alpha,
1530 possible to run ipython as IDLE's shell (consider this pre-alpha,
1524 since true stdout things end up in the starting terminal instead
1531 since true stdout things end up in the starting terminal instead
1525 of IDLE's out).
1532 of IDLE's out).
1526
1533
1527 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
1534 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
1528 users who haven't # updated their prompt_in2 definitions. Remove
1535 users who haven't # updated their prompt_in2 definitions. Remove
1529 eventually.
1536 eventually.
1530 (multiple_replace): added credit to original ASPN recipe.
1537 (multiple_replace): added credit to original ASPN recipe.
1531
1538
1532 2004-06-15 Fernando Perez <fperez@colorado.edu>
1539 2004-06-15 Fernando Perez <fperez@colorado.edu>
1533
1540
1534 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
1541 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
1535 list of auto-defined aliases.
1542 list of auto-defined aliases.
1536
1543
1537 2004-06-13 Fernando Perez <fperez@colorado.edu>
1544 2004-06-13 Fernando Perez <fperez@colorado.edu>
1538
1545
1539 * setup.py (scriptfiles): Don't trigger win_post_install unless an
1546 * setup.py (scriptfiles): Don't trigger win_post_install unless an
1540 install was really requested (so setup.py can be used for other
1547 install was really requested (so setup.py can be used for other
1541 things under Windows).
1548 things under Windows).
1542
1549
1543 2004-06-10 Fernando Perez <fperez@colorado.edu>
1550 2004-06-10 Fernando Perez <fperez@colorado.edu>
1544
1551
1545 * IPython/Logger.py (Logger.create_log): Manually remove any old
1552 * IPython/Logger.py (Logger.create_log): Manually remove any old
1546 backup, since os.remove may fail under Windows. Fixes bug
1553 backup, since os.remove may fail under Windows. Fixes bug
1547 reported by Thorsten.
1554 reported by Thorsten.
1548
1555
1549 2004-06-09 Fernando Perez <fperez@colorado.edu>
1556 2004-06-09 Fernando Perez <fperez@colorado.edu>
1550
1557
1551 * examples/example-embed.py: fixed all references to %n (replaced
1558 * examples/example-embed.py: fixed all references to %n (replaced
1552 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
1559 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
1553 for all examples and the manual as well.
1560 for all examples and the manual as well.
1554
1561
1555 2004-06-08 Fernando Perez <fperez@colorado.edu>
1562 2004-06-08 Fernando Perez <fperez@colorado.edu>
1556
1563
1557 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
1564 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
1558 alignment and color management. All 3 prompt subsystems now
1565 alignment and color management. All 3 prompt subsystems now
1559 inherit from BasePrompt.
1566 inherit from BasePrompt.
1560
1567
1561 * tools/release: updates for windows installer build and tag rpms
1568 * tools/release: updates for windows installer build and tag rpms
1562 with python version (since paths are fixed).
1569 with python version (since paths are fixed).
1563
1570
1564 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
1571 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
1565 which will become eventually obsolete. Also fixed the default
1572 which will become eventually obsolete. Also fixed the default
1566 prompt_in2 to use \D, so at least new users start with the correct
1573 prompt_in2 to use \D, so at least new users start with the correct
1567 defaults.
1574 defaults.
1568 WARNING: Users with existing ipythonrc files will need to apply
1575 WARNING: Users with existing ipythonrc files will need to apply
1569 this fix manually!
1576 this fix manually!
1570
1577
1571 * setup.py: make windows installer (.exe). This is finally the
1578 * setup.py: make windows installer (.exe). This is finally the
1572 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
1579 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
1573 which I hadn't included because it required Python 2.3 (or recent
1580 which I hadn't included because it required Python 2.3 (or recent
1574 distutils).
1581 distutils).
1575
1582
1576 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
1583 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
1577 usage of new '\D' escape.
1584 usage of new '\D' escape.
1578
1585
1579 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
1586 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
1580 lacks os.getuid())
1587 lacks os.getuid())
1581 (CachedOutput.set_colors): Added the ability to turn coloring
1588 (CachedOutput.set_colors): Added the ability to turn coloring
1582 on/off with @colors even for manually defined prompt colors. It
1589 on/off with @colors even for manually defined prompt colors. It
1583 uses a nasty global, but it works safely and via the generic color
1590 uses a nasty global, but it works safely and via the generic color
1584 handling mechanism.
1591 handling mechanism.
1585 (Prompt2.__init__): Introduced new escape '\D' for continuation
1592 (Prompt2.__init__): Introduced new escape '\D' for continuation
1586 prompts. It represents the counter ('\#') as dots.
1593 prompts. It represents the counter ('\#') as dots.
1587 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
1594 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
1588 need to update their ipythonrc files and replace '%n' with '\D' in
1595 need to update their ipythonrc files and replace '%n' with '\D' in
1589 their prompt_in2 settings everywhere. Sorry, but there's
1596 their prompt_in2 settings everywhere. Sorry, but there's
1590 otherwise no clean way to get all prompts to properly align. The
1597 otherwise no clean way to get all prompts to properly align. The
1591 ipythonrc shipped with IPython has been updated.
1598 ipythonrc shipped with IPython has been updated.
1592
1599
1593 2004-06-07 Fernando Perez <fperez@colorado.edu>
1600 2004-06-07 Fernando Perez <fperez@colorado.edu>
1594
1601
1595 * setup.py (isfile): Pass local_icons option to latex2html, so the
1602 * setup.py (isfile): Pass local_icons option to latex2html, so the
1596 resulting HTML file is self-contained. Thanks to
1603 resulting HTML file is self-contained. Thanks to
1597 dryice-AT-liu.com.cn for the tip.
1604 dryice-AT-liu.com.cn for the tip.
1598
1605
1599 * pysh.py: I created a new profile 'shell', which implements a
1606 * pysh.py: I created a new profile 'shell', which implements a
1600 _rudimentary_ IPython-based shell. This is in NO WAY a realy
1607 _rudimentary_ IPython-based shell. This is in NO WAY a realy
1601 system shell, nor will it become one anytime soon. It's mainly
1608 system shell, nor will it become one anytime soon. It's mainly
1602 meant to illustrate the use of the new flexible bash-like prompts.
1609 meant to illustrate the use of the new flexible bash-like prompts.
1603 I guess it could be used by hardy souls for true shell management,
1610 I guess it could be used by hardy souls for true shell management,
1604 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
1611 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
1605 profile. This uses the InterpreterExec extension provided by
1612 profile. This uses the InterpreterExec extension provided by
1606 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
1613 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
1607
1614
1608 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
1615 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
1609 auto-align itself with the length of the previous input prompt
1616 auto-align itself with the length of the previous input prompt
1610 (taking into account the invisible color escapes).
1617 (taking into account the invisible color escapes).
1611 (CachedOutput.__init__): Large restructuring of this class. Now
1618 (CachedOutput.__init__): Large restructuring of this class. Now
1612 all three prompts (primary1, primary2, output) are proper objects,
1619 all three prompts (primary1, primary2, output) are proper objects,
1613 managed by the 'parent' CachedOutput class. The code is still a
1620 managed by the 'parent' CachedOutput class. The code is still a
1614 bit hackish (all prompts share state via a pointer to the cache),
1621 bit hackish (all prompts share state via a pointer to the cache),
1615 but it's overall far cleaner than before.
1622 but it's overall far cleaner than before.
1616
1623
1617 * IPython/genutils.py (getoutputerror): modified to add verbose,
1624 * IPython/genutils.py (getoutputerror): modified to add verbose,
1618 debug and header options. This makes the interface of all getout*
1625 debug and header options. This makes the interface of all getout*
1619 functions uniform.
1626 functions uniform.
1620 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
1627 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
1621
1628
1622 * IPython/Magic.py (Magic.default_option): added a function to
1629 * IPython/Magic.py (Magic.default_option): added a function to
1623 allow registering default options for any magic command. This
1630 allow registering default options for any magic command. This
1624 makes it easy to have profiles which customize the magics globally
1631 makes it easy to have profiles which customize the magics globally
1625 for a certain use. The values set through this function are
1632 for a certain use. The values set through this function are
1626 picked up by the parse_options() method, which all magics should
1633 picked up by the parse_options() method, which all magics should
1627 use to parse their options.
1634 use to parse their options.
1628
1635
1629 * IPython/genutils.py (warn): modified the warnings framework to
1636 * IPython/genutils.py (warn): modified the warnings framework to
1630 use the Term I/O class. I'm trying to slowly unify all of
1637 use the Term I/O class. I'm trying to slowly unify all of
1631 IPython's I/O operations to pass through Term.
1638 IPython's I/O operations to pass through Term.
1632
1639
1633 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
1640 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
1634 the secondary prompt to correctly match the length of the primary
1641 the secondary prompt to correctly match the length of the primary
1635 one for any prompt. Now multi-line code will properly line up
1642 one for any prompt. Now multi-line code will properly line up
1636 even for path dependent prompts, such as the new ones available
1643 even for path dependent prompts, such as the new ones available
1637 via the prompt_specials.
1644 via the prompt_specials.
1638
1645
1639 2004-06-06 Fernando Perez <fperez@colorado.edu>
1646 2004-06-06 Fernando Perez <fperez@colorado.edu>
1640
1647
1641 * IPython/Prompts.py (prompt_specials): Added the ability to have
1648 * IPython/Prompts.py (prompt_specials): Added the ability to have
1642 bash-like special sequences in the prompts, which get
1649 bash-like special sequences in the prompts, which get
1643 automatically expanded. Things like hostname, current working
1650 automatically expanded. Things like hostname, current working
1644 directory and username are implemented already, but it's easy to
1651 directory and username are implemented already, but it's easy to
1645 add more in the future. Thanks to a patch by W.J. van der Laan
1652 add more in the future. Thanks to a patch by W.J. van der Laan
1646 <gnufnork-AT-hetdigitalegat.nl>
1653 <gnufnork-AT-hetdigitalegat.nl>
1647 (prompt_specials): Added color support for prompt strings, so
1654 (prompt_specials): Added color support for prompt strings, so
1648 users can define arbitrary color setups for their prompts.
1655 users can define arbitrary color setups for their prompts.
1649
1656
1650 2004-06-05 Fernando Perez <fperez@colorado.edu>
1657 2004-06-05 Fernando Perez <fperez@colorado.edu>
1651
1658
1652 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
1659 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
1653 code to load Gary Bishop's readline and configure it
1660 code to load Gary Bishop's readline and configure it
1654 automatically. Thanks to Gary for help on this.
1661 automatically. Thanks to Gary for help on this.
1655
1662
1656 2004-06-01 Fernando Perez <fperez@colorado.edu>
1663 2004-06-01 Fernando Perez <fperez@colorado.edu>
1657
1664
1658 * IPython/Logger.py (Logger.create_log): fix bug for logging
1665 * IPython/Logger.py (Logger.create_log): fix bug for logging
1659 with no filename (previous fix was incomplete).
1666 with no filename (previous fix was incomplete).
1660
1667
1661 2004-05-25 Fernando Perez <fperez@colorado.edu>
1668 2004-05-25 Fernando Perez <fperez@colorado.edu>
1662
1669
1663 * IPython/Magic.py (Magic.parse_options): fix bug where naked
1670 * IPython/Magic.py (Magic.parse_options): fix bug where naked
1664 parens would get passed to the shell.
1671 parens would get passed to the shell.
1665
1672
1666 2004-05-20 Fernando Perez <fperez@colorado.edu>
1673 2004-05-20 Fernando Perez <fperez@colorado.edu>
1667
1674
1668 * IPython/Magic.py (Magic.magic_prun): changed default profile
1675 * IPython/Magic.py (Magic.magic_prun): changed default profile
1669 sort order to 'time' (the more common profiling need).
1676 sort order to 'time' (the more common profiling need).
1670
1677
1671 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
1678 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
1672 so that source code shown is guaranteed in sync with the file on
1679 so that source code shown is guaranteed in sync with the file on
1673 disk (also changed in psource). Similar fix to the one for
1680 disk (also changed in psource). Similar fix to the one for
1674 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
1681 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
1675 <yann.ledu-AT-noos.fr>.
1682 <yann.ledu-AT-noos.fr>.
1676
1683
1677 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
1684 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
1678 with a single option would not be correctly parsed. Closes
1685 with a single option would not be correctly parsed. Closes
1679 http://www.scipy.net/roundup/ipython/issue14. This bug had been
1686 http://www.scipy.net/roundup/ipython/issue14. This bug had been
1680 introduced in 0.6.0 (on 2004-05-06).
1687 introduced in 0.6.0 (on 2004-05-06).
1681
1688
1682 2004-05-13 *** Released version 0.6.0
1689 2004-05-13 *** Released version 0.6.0
1683
1690
1684 2004-05-13 Fernando Perez <fperez@colorado.edu>
1691 2004-05-13 Fernando Perez <fperez@colorado.edu>
1685
1692
1686 * debian/: Added debian/ directory to CVS, so that debian support
1693 * debian/: Added debian/ directory to CVS, so that debian support
1687 is publicly accessible. The debian package is maintained by Jack
1694 is publicly accessible. The debian package is maintained by Jack
1688 Moffit <jack-AT-xiph.org>.
1695 Moffit <jack-AT-xiph.org>.
1689
1696
1690 * Documentation: included the notes about an ipython-based system
1697 * Documentation: included the notes about an ipython-based system
1691 shell (the hypothetical 'pysh') into the new_design.pdf document,
1698 shell (the hypothetical 'pysh') into the new_design.pdf document,
1692 so that these ideas get distributed to users along with the
1699 so that these ideas get distributed to users along with the
1693 official documentation.
1700 official documentation.
1694
1701
1695 2004-05-10 Fernando Perez <fperez@colorado.edu>
1702 2004-05-10 Fernando Perez <fperez@colorado.edu>
1696
1703
1697 * IPython/Logger.py (Logger.create_log): fix recently introduced
1704 * IPython/Logger.py (Logger.create_log): fix recently introduced
1698 bug (misindented line) where logstart would fail when not given an
1705 bug (misindented line) where logstart would fail when not given an
1699 explicit filename.
1706 explicit filename.
1700
1707
1701 2004-05-09 Fernando Perez <fperez@colorado.edu>
1708 2004-05-09 Fernando Perez <fperez@colorado.edu>
1702
1709
1703 * IPython/Magic.py (Magic.parse_options): skip system call when
1710 * IPython/Magic.py (Magic.parse_options): skip system call when
1704 there are no options to look for. Faster, cleaner for the common
1711 there are no options to look for. Faster, cleaner for the common
1705 case.
1712 case.
1706
1713
1707 * Documentation: many updates to the manual: describing Windows
1714 * Documentation: many updates to the manual: describing Windows
1708 support better, Gnuplot updates, credits, misc small stuff. Also
1715 support better, Gnuplot updates, credits, misc small stuff. Also
1709 updated the new_design doc a bit.
1716 updated the new_design doc a bit.
1710
1717
1711 2004-05-06 *** Released version 0.6.0.rc1
1718 2004-05-06 *** Released version 0.6.0.rc1
1712
1719
1713 2004-05-06 Fernando Perez <fperez@colorado.edu>
1720 2004-05-06 Fernando Perez <fperez@colorado.edu>
1714
1721
1715 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
1722 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
1716 operations to use the vastly more efficient list/''.join() method.
1723 operations to use the vastly more efficient list/''.join() method.
1717 (FormattedTB.text): Fix
1724 (FormattedTB.text): Fix
1718 http://www.scipy.net/roundup/ipython/issue12 - exception source
1725 http://www.scipy.net/roundup/ipython/issue12 - exception source
1719 extract not updated after reload. Thanks to Mike Salib
1726 extract not updated after reload. Thanks to Mike Salib
1720 <msalib-AT-mit.edu> for pinning the source of the problem.
1727 <msalib-AT-mit.edu> for pinning the source of the problem.
1721 Fortunately, the solution works inside ipython and doesn't require
1728 Fortunately, the solution works inside ipython and doesn't require
1722 any changes to python proper.
1729 any changes to python proper.
1723
1730
1724 * IPython/Magic.py (Magic.parse_options): Improved to process the
1731 * IPython/Magic.py (Magic.parse_options): Improved to process the
1725 argument list as a true shell would (by actually using the
1732 argument list as a true shell would (by actually using the
1726 underlying system shell). This way, all @magics automatically get
1733 underlying system shell). This way, all @magics automatically get
1727 shell expansion for variables. Thanks to a comment by Alex
1734 shell expansion for variables. Thanks to a comment by Alex
1728 Schmolck.
1735 Schmolck.
1729
1736
1730 2004-04-04 Fernando Perez <fperez@colorado.edu>
1737 2004-04-04 Fernando Perez <fperez@colorado.edu>
1731
1738
1732 * IPython/iplib.py (InteractiveShell.interact): Added a special
1739 * IPython/iplib.py (InteractiveShell.interact): Added a special
1733 trap for a debugger quit exception, which is basically impossible
1740 trap for a debugger quit exception, which is basically impossible
1734 to handle by normal mechanisms, given what pdb does to the stack.
1741 to handle by normal mechanisms, given what pdb does to the stack.
1735 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
1742 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
1736
1743
1737 2004-04-03 Fernando Perez <fperez@colorado.edu>
1744 2004-04-03 Fernando Perez <fperez@colorado.edu>
1738
1745
1739 * IPython/genutils.py (Term): Standardized the names of the Term
1746 * IPython/genutils.py (Term): Standardized the names of the Term
1740 class streams to cin/cout/cerr, following C++ naming conventions
1747 class streams to cin/cout/cerr, following C++ naming conventions
1741 (I can't use in/out/err because 'in' is not a valid attribute
1748 (I can't use in/out/err because 'in' is not a valid attribute
1742 name).
1749 name).
1743
1750
1744 * IPython/iplib.py (InteractiveShell.interact): don't increment
1751 * IPython/iplib.py (InteractiveShell.interact): don't increment
1745 the prompt if there's no user input. By Daniel 'Dang' Griffith
1752 the prompt if there's no user input. By Daniel 'Dang' Griffith
1746 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
1753 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
1747 Francois Pinard.
1754 Francois Pinard.
1748
1755
1749 2004-04-02 Fernando Perez <fperez@colorado.edu>
1756 2004-04-02 Fernando Perez <fperez@colorado.edu>
1750
1757
1751 * IPython/genutils.py (Stream.__init__): Modified to survive at
1758 * IPython/genutils.py (Stream.__init__): Modified to survive at
1752 least importing in contexts where stdin/out/err aren't true file
1759 least importing in contexts where stdin/out/err aren't true file
1753 objects, such as PyCrust (they lack fileno() and mode). However,
1760 objects, such as PyCrust (they lack fileno() and mode). However,
1754 the recovery facilities which rely on these things existing will
1761 the recovery facilities which rely on these things existing will
1755 not work.
1762 not work.
1756
1763
1757 2004-04-01 Fernando Perez <fperez@colorado.edu>
1764 2004-04-01 Fernando Perez <fperez@colorado.edu>
1758
1765
1759 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
1766 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
1760 use the new getoutputerror() function, so it properly
1767 use the new getoutputerror() function, so it properly
1761 distinguishes stdout/err.
1768 distinguishes stdout/err.
1762
1769
1763 * IPython/genutils.py (getoutputerror): added a function to
1770 * IPython/genutils.py (getoutputerror): added a function to
1764 capture separately the standard output and error of a command.
1771 capture separately the standard output and error of a command.
1765 After a comment from dang on the mailing lists. This code is
1772 After a comment from dang on the mailing lists. This code is
1766 basically a modified version of commands.getstatusoutput(), from
1773 basically a modified version of commands.getstatusoutput(), from
1767 the standard library.
1774 the standard library.
1768
1775
1769 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
1776 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
1770 '!!' as a special syntax (shorthand) to access @sx.
1777 '!!' as a special syntax (shorthand) to access @sx.
1771
1778
1772 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
1779 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
1773 command and return its output as a list split on '\n'.
1780 command and return its output as a list split on '\n'.
1774
1781
1775 2004-03-31 Fernando Perez <fperez@colorado.edu>
1782 2004-03-31 Fernando Perez <fperez@colorado.edu>
1776
1783
1777 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
1784 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
1778 method to dictionaries used as FakeModule instances if they lack
1785 method to dictionaries used as FakeModule instances if they lack
1779 it. At least pydoc in python2.3 breaks for runtime-defined
1786 it. At least pydoc in python2.3 breaks for runtime-defined
1780 functions without this hack. At some point I need to _really_
1787 functions without this hack. At some point I need to _really_
1781 understand what FakeModule is doing, because it's a gross hack.
1788 understand what FakeModule is doing, because it's a gross hack.
1782 But it solves Arnd's problem for now...
1789 But it solves Arnd's problem for now...
1783
1790
1784 2004-02-27 Fernando Perez <fperez@colorado.edu>
1791 2004-02-27 Fernando Perez <fperez@colorado.edu>
1785
1792
1786 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
1793 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
1787 mode would behave erratically. Also increased the number of
1794 mode would behave erratically. Also increased the number of
1788 possible logs in rotate mod to 999. Thanks to Rod Holland
1795 possible logs in rotate mod to 999. Thanks to Rod Holland
1789 <rhh@StructureLABS.com> for the report and fixes.
1796 <rhh@StructureLABS.com> for the report and fixes.
1790
1797
1791 2004-02-26 Fernando Perez <fperez@colorado.edu>
1798 2004-02-26 Fernando Perez <fperez@colorado.edu>
1792
1799
1793 * IPython/genutils.py (page): Check that the curses module really
1800 * IPython/genutils.py (page): Check that the curses module really
1794 has the initscr attribute before trying to use it. For some
1801 has the initscr attribute before trying to use it. For some
1795 reason, the Solaris curses module is missing this. I think this
1802 reason, the Solaris curses module is missing this. I think this
1796 should be considered a Solaris python bug, but I'm not sure.
1803 should be considered a Solaris python bug, but I'm not sure.
1797
1804
1798 2004-01-17 Fernando Perez <fperez@colorado.edu>
1805 2004-01-17 Fernando Perez <fperez@colorado.edu>
1799
1806
1800 * IPython/genutils.py (Stream.__init__): Changes to try to make
1807 * IPython/genutils.py (Stream.__init__): Changes to try to make
1801 ipython robust against stdin/out/err being closed by the user.
1808 ipython robust against stdin/out/err being closed by the user.
1802 This is 'user error' (and blocks a normal python session, at least
1809 This is 'user error' (and blocks a normal python session, at least
1803 the stdout case). However, Ipython should be able to survive such
1810 the stdout case). However, Ipython should be able to survive such
1804 instances of abuse as gracefully as possible. To simplify the
1811 instances of abuse as gracefully as possible. To simplify the
1805 coding and maintain compatibility with Gary Bishop's Term
1812 coding and maintain compatibility with Gary Bishop's Term
1806 contributions, I've made use of classmethods for this. I think
1813 contributions, I've made use of classmethods for this. I think
1807 this introduces a dependency on python 2.2.
1814 this introduces a dependency on python 2.2.
1808
1815
1809 2004-01-13 Fernando Perez <fperez@colorado.edu>
1816 2004-01-13 Fernando Perez <fperez@colorado.edu>
1810
1817
1811 * IPython/numutils.py (exp_safe): simplified the code a bit and
1818 * IPython/numutils.py (exp_safe): simplified the code a bit and
1812 removed the need for importing the kinds module altogether.
1819 removed the need for importing the kinds module altogether.
1813
1820
1814 2004-01-06 Fernando Perez <fperez@colorado.edu>
1821 2004-01-06 Fernando Perez <fperez@colorado.edu>
1815
1822
1816 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
1823 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
1817 a magic function instead, after some community feedback. No
1824 a magic function instead, after some community feedback. No
1818 special syntax will exist for it, but its name is deliberately
1825 special syntax will exist for it, but its name is deliberately
1819 very short.
1826 very short.
1820
1827
1821 2003-12-20 Fernando Perez <fperez@colorado.edu>
1828 2003-12-20 Fernando Perez <fperez@colorado.edu>
1822
1829
1823 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
1830 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
1824 new functionality, to automagically assign the result of a shell
1831 new functionality, to automagically assign the result of a shell
1825 command to a variable. I'll solicit some community feedback on
1832 command to a variable. I'll solicit some community feedback on
1826 this before making it permanent.
1833 this before making it permanent.
1827
1834
1828 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
1835 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
1829 requested about callables for which inspect couldn't obtain a
1836 requested about callables for which inspect couldn't obtain a
1830 proper argspec. Thanks to a crash report sent by Etienne
1837 proper argspec. Thanks to a crash report sent by Etienne
1831 Posthumus <etienne-AT-apple01.cs.vu.nl>.
1838 Posthumus <etienne-AT-apple01.cs.vu.nl>.
1832
1839
1833 2003-12-09 Fernando Perez <fperez@colorado.edu>
1840 2003-12-09 Fernando Perez <fperez@colorado.edu>
1834
1841
1835 * IPython/genutils.py (page): patch for the pager to work across
1842 * IPython/genutils.py (page): patch for the pager to work across
1836 various versions of Windows. By Gary Bishop.
1843 various versions of Windows. By Gary Bishop.
1837
1844
1838 2003-12-04 Fernando Perez <fperez@colorado.edu>
1845 2003-12-04 Fernando Perez <fperez@colorado.edu>
1839
1846
1840 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
1847 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
1841 Gnuplot.py version 1.7, whose internal names changed quite a bit.
1848 Gnuplot.py version 1.7, whose internal names changed quite a bit.
1842 While I tested this and it looks ok, there may still be corner
1849 While I tested this and it looks ok, there may still be corner
1843 cases I've missed.
1850 cases I've missed.
1844
1851
1845 2003-12-01 Fernando Perez <fperez@colorado.edu>
1852 2003-12-01 Fernando Perez <fperez@colorado.edu>
1846
1853
1847 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
1854 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
1848 where a line like 'p,q=1,2' would fail because the automagic
1855 where a line like 'p,q=1,2' would fail because the automagic
1849 system would be triggered for @p.
1856 system would be triggered for @p.
1850
1857
1851 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
1858 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
1852 cleanups, code unmodified.
1859 cleanups, code unmodified.
1853
1860
1854 * IPython/genutils.py (Term): added a class for IPython to handle
1861 * IPython/genutils.py (Term): added a class for IPython to handle
1855 output. In most cases it will just be a proxy for stdout/err, but
1862 output. In most cases it will just be a proxy for stdout/err, but
1856 having this allows modifications to be made for some platforms,
1863 having this allows modifications to be made for some platforms,
1857 such as handling color escapes under Windows. All of this code
1864 such as handling color escapes under Windows. All of this code
1858 was contributed by Gary Bishop, with minor modifications by me.
1865 was contributed by Gary Bishop, with minor modifications by me.
1859 The actual changes affect many files.
1866 The actual changes affect many files.
1860
1867
1861 2003-11-30 Fernando Perez <fperez@colorado.edu>
1868 2003-11-30 Fernando Perez <fperez@colorado.edu>
1862
1869
1863 * IPython/iplib.py (file_matches): new completion code, courtesy
1870 * IPython/iplib.py (file_matches): new completion code, courtesy
1864 of Jeff Collins. This enables filename completion again under
1871 of Jeff Collins. This enables filename completion again under
1865 python 2.3, which disabled it at the C level.
1872 python 2.3, which disabled it at the C level.
1866
1873
1867 2003-11-11 Fernando Perez <fperez@colorado.edu>
1874 2003-11-11 Fernando Perez <fperez@colorado.edu>
1868
1875
1869 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
1876 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
1870 for Numeric.array(map(...)), but often convenient.
1877 for Numeric.array(map(...)), but often convenient.
1871
1878
1872 2003-11-05 Fernando Perez <fperez@colorado.edu>
1879 2003-11-05 Fernando Perez <fperez@colorado.edu>
1873
1880
1874 * IPython/numutils.py (frange): Changed a call from int() to
1881 * IPython/numutils.py (frange): Changed a call from int() to
1875 int(round()) to prevent a problem reported with arange() in the
1882 int(round()) to prevent a problem reported with arange() in the
1876 numpy list.
1883 numpy list.
1877
1884
1878 2003-10-06 Fernando Perez <fperez@colorado.edu>
1885 2003-10-06 Fernando Perez <fperez@colorado.edu>
1879
1886
1880 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
1887 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
1881 prevent crashes if sys lacks an argv attribute (it happens with
1888 prevent crashes if sys lacks an argv attribute (it happens with
1882 embedded interpreters which build a bare-bones sys module).
1889 embedded interpreters which build a bare-bones sys module).
1883 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
1890 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
1884
1891
1885 2003-09-24 Fernando Perez <fperez@colorado.edu>
1892 2003-09-24 Fernando Perez <fperez@colorado.edu>
1886
1893
1887 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
1894 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
1888 to protect against poorly written user objects where __getattr__
1895 to protect against poorly written user objects where __getattr__
1889 raises exceptions other than AttributeError. Thanks to a bug
1896 raises exceptions other than AttributeError. Thanks to a bug
1890 report by Oliver Sander <osander-AT-gmx.de>.
1897 report by Oliver Sander <osander-AT-gmx.de>.
1891
1898
1892 * IPython/FakeModule.py (FakeModule.__repr__): this method was
1899 * IPython/FakeModule.py (FakeModule.__repr__): this method was
1893 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
1900 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
1894
1901
1895 2003-09-09 Fernando Perez <fperez@colorado.edu>
1902 2003-09-09 Fernando Perez <fperez@colorado.edu>
1896
1903
1897 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1904 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1898 unpacking a list whith a callable as first element would
1905 unpacking a list whith a callable as first element would
1899 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
1906 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
1900 Collins.
1907 Collins.
1901
1908
1902 2003-08-25 *** Released version 0.5.0
1909 2003-08-25 *** Released version 0.5.0
1903
1910
1904 2003-08-22 Fernando Perez <fperez@colorado.edu>
1911 2003-08-22 Fernando Perez <fperez@colorado.edu>
1905
1912
1906 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
1913 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
1907 improperly defined user exceptions. Thanks to feedback from Mark
1914 improperly defined user exceptions. Thanks to feedback from Mark
1908 Russell <mrussell-AT-verio.net>.
1915 Russell <mrussell-AT-verio.net>.
1909
1916
1910 2003-08-20 Fernando Perez <fperez@colorado.edu>
1917 2003-08-20 Fernando Perez <fperez@colorado.edu>
1911
1918
1912 * IPython/OInspect.py (Inspector.pinfo): changed String Form
1919 * IPython/OInspect.py (Inspector.pinfo): changed String Form
1913 printing so that it would print multi-line string forms starting
1920 printing so that it would print multi-line string forms starting
1914 with a new line. This way the formatting is better respected for
1921 with a new line. This way the formatting is better respected for
1915 objects which work hard to make nice string forms.
1922 objects which work hard to make nice string forms.
1916
1923
1917 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
1924 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
1918 autocall would overtake data access for objects with both
1925 autocall would overtake data access for objects with both
1919 __getitem__ and __call__.
1926 __getitem__ and __call__.
1920
1927
1921 2003-08-19 *** Released version 0.5.0-rc1
1928 2003-08-19 *** Released version 0.5.0-rc1
1922
1929
1923 2003-08-19 Fernando Perez <fperez@colorado.edu>
1930 2003-08-19 Fernando Perez <fperez@colorado.edu>
1924
1931
1925 * IPython/deep_reload.py (load_tail): single tiny change here
1932 * IPython/deep_reload.py (load_tail): single tiny change here
1926 seems to fix the long-standing bug of dreload() failing to work
1933 seems to fix the long-standing bug of dreload() failing to work
1927 for dotted names. But this module is pretty tricky, so I may have
1934 for dotted names. But this module is pretty tricky, so I may have
1928 missed some subtlety. Needs more testing!.
1935 missed some subtlety. Needs more testing!.
1929
1936
1930 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
1937 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
1931 exceptions which have badly implemented __str__ methods.
1938 exceptions which have badly implemented __str__ methods.
1932 (VerboseTB.text): harden against inspect.getinnerframes crashing,
1939 (VerboseTB.text): harden against inspect.getinnerframes crashing,
1933 which I've been getting reports about from Python 2.3 users. I
1940 which I've been getting reports about from Python 2.3 users. I
1934 wish I had a simple test case to reproduce the problem, so I could
1941 wish I had a simple test case to reproduce the problem, so I could
1935 either write a cleaner workaround or file a bug report if
1942 either write a cleaner workaround or file a bug report if
1936 necessary.
1943 necessary.
1937
1944
1938 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
1945 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
1939 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
1946 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
1940 a bug report by Tjabo Kloppenburg.
1947 a bug report by Tjabo Kloppenburg.
1941
1948
1942 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
1949 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
1943 crashes. Wrapped the pdb call in a blanket try/except, since pdb
1950 crashes. Wrapped the pdb call in a blanket try/except, since pdb
1944 seems rather unstable. Thanks to a bug report by Tjabo
1951 seems rather unstable. Thanks to a bug report by Tjabo
1945 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
1952 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
1946
1953
1947 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
1954 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
1948 this out soon because of the critical fixes in the inner loop for
1955 this out soon because of the critical fixes in the inner loop for
1949 generators.
1956 generators.
1950
1957
1951 * IPython/Magic.py (Magic.getargspec): removed. This (and
1958 * IPython/Magic.py (Magic.getargspec): removed. This (and
1952 _get_def) have been obsoleted by OInspect for a long time, I
1959 _get_def) have been obsoleted by OInspect for a long time, I
1953 hadn't noticed that they were dead code.
1960 hadn't noticed that they were dead code.
1954 (Magic._ofind): restored _ofind functionality for a few literals
1961 (Magic._ofind): restored _ofind functionality for a few literals
1955 (those in ["''",'""','[]','{}','()']). But it won't work anymore
1962 (those in ["''",'""','[]','{}','()']). But it won't work anymore
1956 for things like "hello".capitalize?, since that would require a
1963 for things like "hello".capitalize?, since that would require a
1957 potentially dangerous eval() again.
1964 potentially dangerous eval() again.
1958
1965
1959 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
1966 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
1960 logic a bit more to clean up the escapes handling and minimize the
1967 logic a bit more to clean up the escapes handling and minimize the
1961 use of _ofind to only necessary cases. The interactive 'feel' of
1968 use of _ofind to only necessary cases. The interactive 'feel' of
1962 IPython should have improved quite a bit with the changes in
1969 IPython should have improved quite a bit with the changes in
1963 _prefilter and _ofind (besides being far safer than before).
1970 _prefilter and _ofind (besides being far safer than before).
1964
1971
1965 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
1972 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
1966 obscure, never reported). Edit would fail to find the object to
1973 obscure, never reported). Edit would fail to find the object to
1967 edit under some circumstances.
1974 edit under some circumstances.
1968 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
1975 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
1969 which were causing double-calling of generators. Those eval calls
1976 which were causing double-calling of generators. Those eval calls
1970 were _very_ dangerous, since code with side effects could be
1977 were _very_ dangerous, since code with side effects could be
1971 triggered. As they say, 'eval is evil'... These were the
1978 triggered. As they say, 'eval is evil'... These were the
1972 nastiest evals in IPython. Besides, _ofind is now far simpler,
1979 nastiest evals in IPython. Besides, _ofind is now far simpler,
1973 and it should also be quite a bit faster. Its use of inspect is
1980 and it should also be quite a bit faster. Its use of inspect is
1974 also safer, so perhaps some of the inspect-related crashes I've
1981 also safer, so perhaps some of the inspect-related crashes I've
1975 seen lately with Python 2.3 might be taken care of. That will
1982 seen lately with Python 2.3 might be taken care of. That will
1976 need more testing.
1983 need more testing.
1977
1984
1978 2003-08-17 Fernando Perez <fperez@colorado.edu>
1985 2003-08-17 Fernando Perez <fperez@colorado.edu>
1979
1986
1980 * IPython/iplib.py (InteractiveShell._prefilter): significant
1987 * IPython/iplib.py (InteractiveShell._prefilter): significant
1981 simplifications to the logic for handling user escapes. Faster
1988 simplifications to the logic for handling user escapes. Faster
1982 and simpler code.
1989 and simpler code.
1983
1990
1984 2003-08-14 Fernando Perez <fperez@colorado.edu>
1991 2003-08-14 Fernando Perez <fperez@colorado.edu>
1985
1992
1986 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
1993 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
1987 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
1994 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
1988 but it should be quite a bit faster. And the recursive version
1995 but it should be quite a bit faster. And the recursive version
1989 generated O(log N) intermediate storage for all rank>1 arrays,
1996 generated O(log N) intermediate storage for all rank>1 arrays,
1990 even if they were contiguous.
1997 even if they were contiguous.
1991 (l1norm): Added this function.
1998 (l1norm): Added this function.
1992 (norm): Added this function for arbitrary norms (including
1999 (norm): Added this function for arbitrary norms (including
1993 l-infinity). l1 and l2 are still special cases for convenience
2000 l-infinity). l1 and l2 are still special cases for convenience
1994 and speed.
2001 and speed.
1995
2002
1996 2003-08-03 Fernando Perez <fperez@colorado.edu>
2003 2003-08-03 Fernando Perez <fperez@colorado.edu>
1997
2004
1998 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
2005 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
1999 exceptions, which now raise PendingDeprecationWarnings in Python
2006 exceptions, which now raise PendingDeprecationWarnings in Python
2000 2.3. There were some in Magic and some in Gnuplot2.
2007 2.3. There were some in Magic and some in Gnuplot2.
2001
2008
2002 2003-06-30 Fernando Perez <fperez@colorado.edu>
2009 2003-06-30 Fernando Perez <fperez@colorado.edu>
2003
2010
2004 * IPython/genutils.py (page): modified to call curses only for
2011 * IPython/genutils.py (page): modified to call curses only for
2005 terminals where TERM=='xterm'. After problems under many other
2012 terminals where TERM=='xterm'. After problems under many other
2006 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
2013 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
2007
2014
2008 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
2015 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
2009 would be triggered when readline was absent. This was just an old
2016 would be triggered when readline was absent. This was just an old
2010 debugging statement I'd forgotten to take out.
2017 debugging statement I'd forgotten to take out.
2011
2018
2012 2003-06-20 Fernando Perez <fperez@colorado.edu>
2019 2003-06-20 Fernando Perez <fperez@colorado.edu>
2013
2020
2014 * IPython/genutils.py (clock): modified to return only user time
2021 * IPython/genutils.py (clock): modified to return only user time
2015 (not counting system time), after a discussion on scipy. While
2022 (not counting system time), after a discussion on scipy. While
2016 system time may be a useful quantity occasionally, it may much
2023 system time may be a useful quantity occasionally, it may much
2017 more easily be skewed by occasional swapping or other similar
2024 more easily be skewed by occasional swapping or other similar
2018 activity.
2025 activity.
2019
2026
2020 2003-06-05 Fernando Perez <fperez@colorado.edu>
2027 2003-06-05 Fernando Perez <fperez@colorado.edu>
2021
2028
2022 * IPython/numutils.py (identity): new function, for building
2029 * IPython/numutils.py (identity): new function, for building
2023 arbitrary rank Kronecker deltas (mostly backwards compatible with
2030 arbitrary rank Kronecker deltas (mostly backwards compatible with
2024 Numeric.identity)
2031 Numeric.identity)
2025
2032
2026 2003-06-03 Fernando Perez <fperez@colorado.edu>
2033 2003-06-03 Fernando Perez <fperez@colorado.edu>
2027
2034
2028 * IPython/iplib.py (InteractiveShell.handle_magic): protect
2035 * IPython/iplib.py (InteractiveShell.handle_magic): protect
2029 arguments passed to magics with spaces, to allow trailing '\' to
2036 arguments passed to magics with spaces, to allow trailing '\' to
2030 work normally (mainly for Windows users).
2037 work normally (mainly for Windows users).
2031
2038
2032 2003-05-29 Fernando Perez <fperez@colorado.edu>
2039 2003-05-29 Fernando Perez <fperez@colorado.edu>
2033
2040
2034 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
2041 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
2035 instead of pydoc.help. This fixes a bizarre behavior where
2042 instead of pydoc.help. This fixes a bizarre behavior where
2036 printing '%s' % locals() would trigger the help system. Now
2043 printing '%s' % locals() would trigger the help system. Now
2037 ipython behaves like normal python does.
2044 ipython behaves like normal python does.
2038
2045
2039 Note that if one does 'from pydoc import help', the bizarre
2046 Note that if one does 'from pydoc import help', the bizarre
2040 behavior returns, but this will also happen in normal python, so
2047 behavior returns, but this will also happen in normal python, so
2041 it's not an ipython bug anymore (it has to do with how pydoc.help
2048 it's not an ipython bug anymore (it has to do with how pydoc.help
2042 is implemented).
2049 is implemented).
2043
2050
2044 2003-05-22 Fernando Perez <fperez@colorado.edu>
2051 2003-05-22 Fernando Perez <fperez@colorado.edu>
2045
2052
2046 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
2053 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
2047 return [] instead of None when nothing matches, also match to end
2054 return [] instead of None when nothing matches, also match to end
2048 of line. Patch by Gary Bishop.
2055 of line. Patch by Gary Bishop.
2049
2056
2050 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
2057 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
2051 protection as before, for files passed on the command line. This
2058 protection as before, for files passed on the command line. This
2052 prevents the CrashHandler from kicking in if user files call into
2059 prevents the CrashHandler from kicking in if user files call into
2053 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
2060 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
2054 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
2061 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
2055
2062
2056 2003-05-20 *** Released version 0.4.0
2063 2003-05-20 *** Released version 0.4.0
2057
2064
2058 2003-05-20 Fernando Perez <fperez@colorado.edu>
2065 2003-05-20 Fernando Perez <fperez@colorado.edu>
2059
2066
2060 * setup.py: added support for manpages. It's a bit hackish b/c of
2067 * setup.py: added support for manpages. It's a bit hackish b/c of
2061 a bug in the way the bdist_rpm distutils target handles gzipped
2068 a bug in the way the bdist_rpm distutils target handles gzipped
2062 manpages, but it works. After a patch by Jack.
2069 manpages, but it works. After a patch by Jack.
2063
2070
2064 2003-05-19 Fernando Perez <fperez@colorado.edu>
2071 2003-05-19 Fernando Perez <fperez@colorado.edu>
2065
2072
2066 * IPython/numutils.py: added a mockup of the kinds module, since
2073 * IPython/numutils.py: added a mockup of the kinds module, since
2067 it was recently removed from Numeric. This way, numutils will
2074 it was recently removed from Numeric. This way, numutils will
2068 work for all users even if they are missing kinds.
2075 work for all users even if they are missing kinds.
2069
2076
2070 * IPython/Magic.py (Magic._ofind): Harden against an inspect
2077 * IPython/Magic.py (Magic._ofind): Harden against an inspect
2071 failure, which can occur with SWIG-wrapped extensions. After a
2078 failure, which can occur with SWIG-wrapped extensions. After a
2072 crash report from Prabhu.
2079 crash report from Prabhu.
2073
2080
2074 2003-05-16 Fernando Perez <fperez@colorado.edu>
2081 2003-05-16 Fernando Perez <fperez@colorado.edu>
2075
2082
2076 * IPython/iplib.py (InteractiveShell.excepthook): New method to
2083 * IPython/iplib.py (InteractiveShell.excepthook): New method to
2077 protect ipython from user code which may call directly
2084 protect ipython from user code which may call directly
2078 sys.excepthook (this looks like an ipython crash to the user, even
2085 sys.excepthook (this looks like an ipython crash to the user, even
2079 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2086 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2080 This is especially important to help users of WxWindows, but may
2087 This is especially important to help users of WxWindows, but may
2081 also be useful in other cases.
2088 also be useful in other cases.
2082
2089
2083 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
2090 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
2084 an optional tb_offset to be specified, and to preserve exception
2091 an optional tb_offset to be specified, and to preserve exception
2085 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2092 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2086
2093
2087 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
2094 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
2088
2095
2089 2003-05-15 Fernando Perez <fperez@colorado.edu>
2096 2003-05-15 Fernando Perez <fperez@colorado.edu>
2090
2097
2091 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
2098 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
2092 installing for a new user under Windows.
2099 installing for a new user under Windows.
2093
2100
2094 2003-05-12 Fernando Perez <fperez@colorado.edu>
2101 2003-05-12 Fernando Perez <fperez@colorado.edu>
2095
2102
2096 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
2103 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
2097 handler for Emacs comint-based lines. Currently it doesn't do
2104 handler for Emacs comint-based lines. Currently it doesn't do
2098 much (but importantly, it doesn't update the history cache). In
2105 much (but importantly, it doesn't update the history cache). In
2099 the future it may be expanded if Alex needs more functionality
2106 the future it may be expanded if Alex needs more functionality
2100 there.
2107 there.
2101
2108
2102 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
2109 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
2103 info to crash reports.
2110 info to crash reports.
2104
2111
2105 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
2112 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
2106 just like Python's -c. Also fixed crash with invalid -color
2113 just like Python's -c. Also fixed crash with invalid -color
2107 option value at startup. Thanks to Will French
2114 option value at startup. Thanks to Will French
2108 <wfrench-AT-bestweb.net> for the bug report.
2115 <wfrench-AT-bestweb.net> for the bug report.
2109
2116
2110 2003-05-09 Fernando Perez <fperez@colorado.edu>
2117 2003-05-09 Fernando Perez <fperez@colorado.edu>
2111
2118
2112 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
2119 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
2113 to EvalDict (it's a mapping, after all) and simplified its code
2120 to EvalDict (it's a mapping, after all) and simplified its code
2114 quite a bit, after a nice discussion on c.l.py where Gustavo
2121 quite a bit, after a nice discussion on c.l.py where Gustavo
2115 Córdova <gcordova-AT-sismex.com> suggested the new version.
2122 Córdova <gcordova-AT-sismex.com> suggested the new version.
2116
2123
2117 2003-04-30 Fernando Perez <fperez@colorado.edu>
2124 2003-04-30 Fernando Perez <fperez@colorado.edu>
2118
2125
2119 * IPython/genutils.py (timings_out): modified it to reduce its
2126 * IPython/genutils.py (timings_out): modified it to reduce its
2120 overhead in the common reps==1 case.
2127 overhead in the common reps==1 case.
2121
2128
2122 2003-04-29 Fernando Perez <fperez@colorado.edu>
2129 2003-04-29 Fernando Perez <fperez@colorado.edu>
2123
2130
2124 * IPython/genutils.py (timings_out): Modified to use the resource
2131 * IPython/genutils.py (timings_out): Modified to use the resource
2125 module, which avoids the wraparound problems of time.clock().
2132 module, which avoids the wraparound problems of time.clock().
2126
2133
2127 2003-04-17 *** Released version 0.2.15pre4
2134 2003-04-17 *** Released version 0.2.15pre4
2128
2135
2129 2003-04-17 Fernando Perez <fperez@colorado.edu>
2136 2003-04-17 Fernando Perez <fperez@colorado.edu>
2130
2137
2131 * setup.py (scriptfiles): Split windows-specific stuff over to a
2138 * setup.py (scriptfiles): Split windows-specific stuff over to a
2132 separate file, in an attempt to have a Windows GUI installer.
2139 separate file, in an attempt to have a Windows GUI installer.
2133 That didn't work, but part of the groundwork is done.
2140 That didn't work, but part of the groundwork is done.
2134
2141
2135 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
2142 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
2136 indent/unindent with 4 spaces. Particularly useful in combination
2143 indent/unindent with 4 spaces. Particularly useful in combination
2137 with the new auto-indent option.
2144 with the new auto-indent option.
2138
2145
2139 2003-04-16 Fernando Perez <fperez@colorado.edu>
2146 2003-04-16 Fernando Perez <fperez@colorado.edu>
2140
2147
2141 * IPython/Magic.py: various replacements of self.rc for
2148 * IPython/Magic.py: various replacements of self.rc for
2142 self.shell.rc. A lot more remains to be done to fully disentangle
2149 self.shell.rc. A lot more remains to be done to fully disentangle
2143 this class from the main Shell class.
2150 this class from the main Shell class.
2144
2151
2145 * IPython/GnuplotRuntime.py: added checks for mouse support so
2152 * IPython/GnuplotRuntime.py: added checks for mouse support so
2146 that we don't try to enable it if the current gnuplot doesn't
2153 that we don't try to enable it if the current gnuplot doesn't
2147 really support it. Also added checks so that we don't try to
2154 really support it. Also added checks so that we don't try to
2148 enable persist under Windows (where Gnuplot doesn't recognize the
2155 enable persist under Windows (where Gnuplot doesn't recognize the
2149 option).
2156 option).
2150
2157
2151 * IPython/iplib.py (InteractiveShell.interact): Added optional
2158 * IPython/iplib.py (InteractiveShell.interact): Added optional
2152 auto-indenting code, after a patch by King C. Shu
2159 auto-indenting code, after a patch by King C. Shu
2153 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
2160 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
2154 get along well with pasting indented code. If I ever figure out
2161 get along well with pasting indented code. If I ever figure out
2155 how to make that part go well, it will become on by default.
2162 how to make that part go well, it will become on by default.
2156
2163
2157 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
2164 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
2158 crash ipython if there was an unmatched '%' in the user's prompt
2165 crash ipython if there was an unmatched '%' in the user's prompt
2159 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2166 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2160
2167
2161 * IPython/iplib.py (InteractiveShell.interact): removed the
2168 * IPython/iplib.py (InteractiveShell.interact): removed the
2162 ability to ask the user whether he wants to crash or not at the
2169 ability to ask the user whether he wants to crash or not at the
2163 'last line' exception handler. Calling functions at that point
2170 'last line' exception handler. Calling functions at that point
2164 changes the stack, and the error reports would have incorrect
2171 changes the stack, and the error reports would have incorrect
2165 tracebacks.
2172 tracebacks.
2166
2173
2167 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
2174 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
2168 pass through a peger a pretty-printed form of any object. After a
2175 pass through a peger a pretty-printed form of any object. After a
2169 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
2176 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
2170
2177
2171 2003-04-14 Fernando Perez <fperez@colorado.edu>
2178 2003-04-14 Fernando Perez <fperez@colorado.edu>
2172
2179
2173 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
2180 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
2174 all files in ~ would be modified at first install (instead of
2181 all files in ~ would be modified at first install (instead of
2175 ~/.ipython). This could be potentially disastrous, as the
2182 ~/.ipython). This could be potentially disastrous, as the
2176 modification (make line-endings native) could damage binary files.
2183 modification (make line-endings native) could damage binary files.
2177
2184
2178 2003-04-10 Fernando Perez <fperez@colorado.edu>
2185 2003-04-10 Fernando Perez <fperez@colorado.edu>
2179
2186
2180 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
2187 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
2181 handle only lines which are invalid python. This now means that
2188 handle only lines which are invalid python. This now means that
2182 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
2189 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
2183 for the bug report.
2190 for the bug report.
2184
2191
2185 2003-04-01 Fernando Perez <fperez@colorado.edu>
2192 2003-04-01 Fernando Perez <fperez@colorado.edu>
2186
2193
2187 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
2194 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
2188 where failing to set sys.last_traceback would crash pdb.pm().
2195 where failing to set sys.last_traceback would crash pdb.pm().
2189 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
2196 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
2190 report.
2197 report.
2191
2198
2192 2003-03-25 Fernando Perez <fperez@colorado.edu>
2199 2003-03-25 Fernando Perez <fperez@colorado.edu>
2193
2200
2194 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
2201 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
2195 before printing it (it had a lot of spurious blank lines at the
2202 before printing it (it had a lot of spurious blank lines at the
2196 end).
2203 end).
2197
2204
2198 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
2205 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
2199 output would be sent 21 times! Obviously people don't use this
2206 output would be sent 21 times! Obviously people don't use this
2200 too often, or I would have heard about it.
2207 too often, or I would have heard about it.
2201
2208
2202 2003-03-24 Fernando Perez <fperez@colorado.edu>
2209 2003-03-24 Fernando Perez <fperez@colorado.edu>
2203
2210
2204 * setup.py (scriptfiles): renamed the data_files parameter from
2211 * setup.py (scriptfiles): renamed the data_files parameter from
2205 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
2212 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
2206 for the patch.
2213 for the patch.
2207
2214
2208 2003-03-20 Fernando Perez <fperez@colorado.edu>
2215 2003-03-20 Fernando Perez <fperez@colorado.edu>
2209
2216
2210 * IPython/genutils.py (error): added error() and fatal()
2217 * IPython/genutils.py (error): added error() and fatal()
2211 functions.
2218 functions.
2212
2219
2213 2003-03-18 *** Released version 0.2.15pre3
2220 2003-03-18 *** Released version 0.2.15pre3
2214
2221
2215 2003-03-18 Fernando Perez <fperez@colorado.edu>
2222 2003-03-18 Fernando Perez <fperez@colorado.edu>
2216
2223
2217 * setupext/install_data_ext.py
2224 * setupext/install_data_ext.py
2218 (install_data_ext.initialize_options): Class contributed by Jack
2225 (install_data_ext.initialize_options): Class contributed by Jack
2219 Moffit for fixing the old distutils hack. He is sending this to
2226 Moffit for fixing the old distutils hack. He is sending this to
2220 the distutils folks so in the future we may not need it as a
2227 the distutils folks so in the future we may not need it as a
2221 private fix.
2228 private fix.
2222
2229
2223 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
2230 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
2224 changes for Debian packaging. See his patch for full details.
2231 changes for Debian packaging. See his patch for full details.
2225 The old distutils hack of making the ipythonrc* files carry a
2232 The old distutils hack of making the ipythonrc* files carry a
2226 bogus .py extension is gone, at last. Examples were moved to a
2233 bogus .py extension is gone, at last. Examples were moved to a
2227 separate subdir under doc/, and the separate executable scripts
2234 separate subdir under doc/, and the separate executable scripts
2228 now live in their own directory. Overall a great cleanup. The
2235 now live in their own directory. Overall a great cleanup. The
2229 manual was updated to use the new files, and setup.py has been
2236 manual was updated to use the new files, and setup.py has been
2230 fixed for this setup.
2237 fixed for this setup.
2231
2238
2232 * IPython/PyColorize.py (Parser.usage): made non-executable and
2239 * IPython/PyColorize.py (Parser.usage): made non-executable and
2233 created a pycolor wrapper around it to be included as a script.
2240 created a pycolor wrapper around it to be included as a script.
2234
2241
2235 2003-03-12 *** Released version 0.2.15pre2
2242 2003-03-12 *** Released version 0.2.15pre2
2236
2243
2237 2003-03-12 Fernando Perez <fperez@colorado.edu>
2244 2003-03-12 Fernando Perez <fperez@colorado.edu>
2238
2245
2239 * IPython/ColorANSI.py (make_color_table): Finally fixed the
2246 * IPython/ColorANSI.py (make_color_table): Finally fixed the
2240 long-standing problem with garbage characters in some terminals.
2247 long-standing problem with garbage characters in some terminals.
2241 The issue was really that the \001 and \002 escapes must _only_ be
2248 The issue was really that the \001 and \002 escapes must _only_ be
2242 passed to input prompts (which call readline), but _never_ to
2249 passed to input prompts (which call readline), but _never_ to
2243 normal text to be printed on screen. I changed ColorANSI to have
2250 normal text to be printed on screen. I changed ColorANSI to have
2244 two classes: TermColors and InputTermColors, each with the
2251 two classes: TermColors and InputTermColors, each with the
2245 appropriate escapes for input prompts or normal text. The code in
2252 appropriate escapes for input prompts or normal text. The code in
2246 Prompts.py got slightly more complicated, but this very old and
2253 Prompts.py got slightly more complicated, but this very old and
2247 annoying bug is finally fixed.
2254 annoying bug is finally fixed.
2248
2255
2249 All the credit for nailing down the real origin of this problem
2256 All the credit for nailing down the real origin of this problem
2250 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
2257 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
2251 *Many* thanks to him for spending quite a bit of effort on this.
2258 *Many* thanks to him for spending quite a bit of effort on this.
2252
2259
2253 2003-03-05 *** Released version 0.2.15pre1
2260 2003-03-05 *** Released version 0.2.15pre1
2254
2261
2255 2003-03-03 Fernando Perez <fperez@colorado.edu>
2262 2003-03-03 Fernando Perez <fperez@colorado.edu>
2256
2263
2257 * IPython/FakeModule.py: Moved the former _FakeModule to a
2264 * IPython/FakeModule.py: Moved the former _FakeModule to a
2258 separate file, because it's also needed by Magic (to fix a similar
2265 separate file, because it's also needed by Magic (to fix a similar
2259 pickle-related issue in @run).
2266 pickle-related issue in @run).
2260
2267
2261 2003-03-02 Fernando Perez <fperez@colorado.edu>
2268 2003-03-02 Fernando Perez <fperez@colorado.edu>
2262
2269
2263 * IPython/Magic.py (Magic.magic_autocall): new magic to control
2270 * IPython/Magic.py (Magic.magic_autocall): new magic to control
2264 the autocall option at runtime.
2271 the autocall option at runtime.
2265 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
2272 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
2266 across Magic.py to start separating Magic from InteractiveShell.
2273 across Magic.py to start separating Magic from InteractiveShell.
2267 (Magic._ofind): Fixed to return proper namespace for dotted
2274 (Magic._ofind): Fixed to return proper namespace for dotted
2268 names. Before, a dotted name would always return 'not currently
2275 names. Before, a dotted name would always return 'not currently
2269 defined', because it would find the 'parent'. s.x would be found,
2276 defined', because it would find the 'parent'. s.x would be found,
2270 but since 'x' isn't defined by itself, it would get confused.
2277 but since 'x' isn't defined by itself, it would get confused.
2271 (Magic.magic_run): Fixed pickling problems reported by Ralf
2278 (Magic.magic_run): Fixed pickling problems reported by Ralf
2272 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
2279 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
2273 that I'd used when Mike Heeter reported similar issues at the
2280 that I'd used when Mike Heeter reported similar issues at the
2274 top-level, but now for @run. It boils down to injecting the
2281 top-level, but now for @run. It boils down to injecting the
2275 namespace where code is being executed with something that looks
2282 namespace where code is being executed with something that looks
2276 enough like a module to fool pickle.dump(). Since a pickle stores
2283 enough like a module to fool pickle.dump(). Since a pickle stores
2277 a named reference to the importing module, we need this for
2284 a named reference to the importing module, we need this for
2278 pickles to save something sensible.
2285 pickles to save something sensible.
2279
2286
2280 * IPython/ipmaker.py (make_IPython): added an autocall option.
2287 * IPython/ipmaker.py (make_IPython): added an autocall option.
2281
2288
2282 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
2289 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
2283 the auto-eval code. Now autocalling is an option, and the code is
2290 the auto-eval code. Now autocalling is an option, and the code is
2284 also vastly safer. There is no more eval() involved at all.
2291 also vastly safer. There is no more eval() involved at all.
2285
2292
2286 2003-03-01 Fernando Perez <fperez@colorado.edu>
2293 2003-03-01 Fernando Perez <fperez@colorado.edu>
2287
2294
2288 * IPython/Magic.py (Magic._ofind): Changed interface to return a
2295 * IPython/Magic.py (Magic._ofind): Changed interface to return a
2289 dict with named keys instead of a tuple.
2296 dict with named keys instead of a tuple.
2290
2297
2291 * IPython: Started using CVS for IPython as of 0.2.15pre1.
2298 * IPython: Started using CVS for IPython as of 0.2.15pre1.
2292
2299
2293 * setup.py (make_shortcut): Fixed message about directories
2300 * setup.py (make_shortcut): Fixed message about directories
2294 created during Windows installation (the directories were ok, just
2301 created during Windows installation (the directories were ok, just
2295 the printed message was misleading). Thanks to Chris Liechti
2302 the printed message was misleading). Thanks to Chris Liechti
2296 <cliechti-AT-gmx.net> for the heads up.
2303 <cliechti-AT-gmx.net> for the heads up.
2297
2304
2298 2003-02-21 Fernando Perez <fperez@colorado.edu>
2305 2003-02-21 Fernando Perez <fperez@colorado.edu>
2299
2306
2300 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
2307 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
2301 of ValueError exception when checking for auto-execution. This
2308 of ValueError exception when checking for auto-execution. This
2302 one is raised by things like Numeric arrays arr.flat when the
2309 one is raised by things like Numeric arrays arr.flat when the
2303 array is non-contiguous.
2310 array is non-contiguous.
2304
2311
2305 2003-01-31 Fernando Perez <fperez@colorado.edu>
2312 2003-01-31 Fernando Perez <fperez@colorado.edu>
2306
2313
2307 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
2314 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
2308 not return any value at all (even though the command would get
2315 not return any value at all (even though the command would get
2309 executed).
2316 executed).
2310 (xsys): Flush stdout right after printing the command to ensure
2317 (xsys): Flush stdout right after printing the command to ensure
2311 proper ordering of commands and command output in the total
2318 proper ordering of commands and command output in the total
2312 output.
2319 output.
2313 (SystemExec/xsys/bq): Switched the names of xsys/bq and
2320 (SystemExec/xsys/bq): Switched the names of xsys/bq and
2314 system/getoutput as defaults. The old ones are kept for
2321 system/getoutput as defaults. The old ones are kept for
2315 compatibility reasons, so no code which uses this library needs
2322 compatibility reasons, so no code which uses this library needs
2316 changing.
2323 changing.
2317
2324
2318 2003-01-27 *** Released version 0.2.14
2325 2003-01-27 *** Released version 0.2.14
2319
2326
2320 2003-01-25 Fernando Perez <fperez@colorado.edu>
2327 2003-01-25 Fernando Perez <fperez@colorado.edu>
2321
2328
2322 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
2329 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
2323 functions defined in previous edit sessions could not be re-edited
2330 functions defined in previous edit sessions could not be re-edited
2324 (because the temp files were immediately removed). Now temp files
2331 (because the temp files were immediately removed). Now temp files
2325 are removed only at IPython's exit.
2332 are removed only at IPython's exit.
2326 (Magic.magic_run): Improved @run to perform shell-like expansions
2333 (Magic.magic_run): Improved @run to perform shell-like expansions
2327 on its arguments (~users and $VARS). With this, @run becomes more
2334 on its arguments (~users and $VARS). With this, @run becomes more
2328 like a normal command-line.
2335 like a normal command-line.
2329
2336
2330 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
2337 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
2331 bugs related to embedding and cleaned up that code. A fairly
2338 bugs related to embedding and cleaned up that code. A fairly
2332 important one was the impossibility to access the global namespace
2339 important one was the impossibility to access the global namespace
2333 through the embedded IPython (only local variables were visible).
2340 through the embedded IPython (only local variables were visible).
2334
2341
2335 2003-01-14 Fernando Perez <fperez@colorado.edu>
2342 2003-01-14 Fernando Perez <fperez@colorado.edu>
2336
2343
2337 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
2344 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
2338 auto-calling to be a bit more conservative. Now it doesn't get
2345 auto-calling to be a bit more conservative. Now it doesn't get
2339 triggered if any of '!=()<>' are in the rest of the input line, to
2346 triggered if any of '!=()<>' are in the rest of the input line, to
2340 allow comparing callables. Thanks to Alex for the heads up.
2347 allow comparing callables. Thanks to Alex for the heads up.
2341
2348
2342 2003-01-07 Fernando Perez <fperez@colorado.edu>
2349 2003-01-07 Fernando Perez <fperez@colorado.edu>
2343
2350
2344 * IPython/genutils.py (page): fixed estimation of the number of
2351 * IPython/genutils.py (page): fixed estimation of the number of
2345 lines in a string to be paged to simply count newlines. This
2352 lines in a string to be paged to simply count newlines. This
2346 prevents over-guessing due to embedded escape sequences. A better
2353 prevents over-guessing due to embedded escape sequences. A better
2347 long-term solution would involve stripping out the control chars
2354 long-term solution would involve stripping out the control chars
2348 for the count, but it's potentially so expensive I just don't
2355 for the count, but it's potentially so expensive I just don't
2349 think it's worth doing.
2356 think it's worth doing.
2350
2357
2351 2002-12-19 *** Released version 0.2.14pre50
2358 2002-12-19 *** Released version 0.2.14pre50
2352
2359
2353 2002-12-19 Fernando Perez <fperez@colorado.edu>
2360 2002-12-19 Fernando Perez <fperez@colorado.edu>
2354
2361
2355 * tools/release (version): Changed release scripts to inform
2362 * tools/release (version): Changed release scripts to inform
2356 Andrea and build a NEWS file with a list of recent changes.
2363 Andrea and build a NEWS file with a list of recent changes.
2357
2364
2358 * IPython/ColorANSI.py (__all__): changed terminal detection
2365 * IPython/ColorANSI.py (__all__): changed terminal detection
2359 code. Seems to work better for xterms without breaking
2366 code. Seems to work better for xterms without breaking
2360 konsole. Will need more testing to determine if WinXP and Mac OSX
2367 konsole. Will need more testing to determine if WinXP and Mac OSX
2361 also work ok.
2368 also work ok.
2362
2369
2363 2002-12-18 *** Released version 0.2.14pre49
2370 2002-12-18 *** Released version 0.2.14pre49
2364
2371
2365 2002-12-18 Fernando Perez <fperez@colorado.edu>
2372 2002-12-18 Fernando Perez <fperez@colorado.edu>
2366
2373
2367 * Docs: added new info about Mac OSX, from Andrea.
2374 * Docs: added new info about Mac OSX, from Andrea.
2368
2375
2369 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
2376 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
2370 allow direct plotting of python strings whose format is the same
2377 allow direct plotting of python strings whose format is the same
2371 of gnuplot data files.
2378 of gnuplot data files.
2372
2379
2373 2002-12-16 Fernando Perez <fperez@colorado.edu>
2380 2002-12-16 Fernando Perez <fperez@colorado.edu>
2374
2381
2375 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
2382 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
2376 value of exit question to be acknowledged.
2383 value of exit question to be acknowledged.
2377
2384
2378 2002-12-03 Fernando Perez <fperez@colorado.edu>
2385 2002-12-03 Fernando Perez <fperez@colorado.edu>
2379
2386
2380 * IPython/ipmaker.py: removed generators, which had been added
2387 * IPython/ipmaker.py: removed generators, which had been added
2381 by mistake in an earlier debugging run. This was causing trouble
2388 by mistake in an earlier debugging run. This was causing trouble
2382 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
2389 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
2383 for pointing this out.
2390 for pointing this out.
2384
2391
2385 2002-11-17 Fernando Perez <fperez@colorado.edu>
2392 2002-11-17 Fernando Perez <fperez@colorado.edu>
2386
2393
2387 * Manual: updated the Gnuplot section.
2394 * Manual: updated the Gnuplot section.
2388
2395
2389 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
2396 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
2390 a much better split of what goes in Runtime and what goes in
2397 a much better split of what goes in Runtime and what goes in
2391 Interactive.
2398 Interactive.
2392
2399
2393 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
2400 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
2394 being imported from iplib.
2401 being imported from iplib.
2395
2402
2396 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
2403 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
2397 for command-passing. Now the global Gnuplot instance is called
2404 for command-passing. Now the global Gnuplot instance is called
2398 'gp' instead of 'g', which was really a far too fragile and
2405 'gp' instead of 'g', which was really a far too fragile and
2399 common name.
2406 common name.
2400
2407
2401 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
2408 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
2402 bounding boxes generated by Gnuplot for square plots.
2409 bounding boxes generated by Gnuplot for square plots.
2403
2410
2404 * IPython/genutils.py (popkey): new function added. I should
2411 * IPython/genutils.py (popkey): new function added. I should
2405 suggest this on c.l.py as a dict method, it seems useful.
2412 suggest this on c.l.py as a dict method, it seems useful.
2406
2413
2407 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
2414 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
2408 to transparently handle PostScript generation. MUCH better than
2415 to transparently handle PostScript generation. MUCH better than
2409 the previous plot_eps/replot_eps (which I removed now). The code
2416 the previous plot_eps/replot_eps (which I removed now). The code
2410 is also fairly clean and well documented now (including
2417 is also fairly clean and well documented now (including
2411 docstrings).
2418 docstrings).
2412
2419
2413 2002-11-13 Fernando Perez <fperez@colorado.edu>
2420 2002-11-13 Fernando Perez <fperez@colorado.edu>
2414
2421
2415 * IPython/Magic.py (Magic.magic_edit): fixed docstring
2422 * IPython/Magic.py (Magic.magic_edit): fixed docstring
2416 (inconsistent with options).
2423 (inconsistent with options).
2417
2424
2418 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
2425 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
2419 manually disabled, I don't know why. Fixed it.
2426 manually disabled, I don't know why. Fixed it.
2420 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
2427 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
2421 eps output.
2428 eps output.
2422
2429
2423 2002-11-12 Fernando Perez <fperez@colorado.edu>
2430 2002-11-12 Fernando Perez <fperez@colorado.edu>
2424
2431
2425 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
2432 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
2426 don't propagate up to caller. Fixes crash reported by François
2433 don't propagate up to caller. Fixes crash reported by François
2427 Pinard.
2434 Pinard.
2428
2435
2429 2002-11-09 Fernando Perez <fperez@colorado.edu>
2436 2002-11-09 Fernando Perez <fperez@colorado.edu>
2430
2437
2431 * IPython/ipmaker.py (make_IPython): fixed problem with writing
2438 * IPython/ipmaker.py (make_IPython): fixed problem with writing
2432 history file for new users.
2439 history file for new users.
2433 (make_IPython): fixed bug where initial install would leave the
2440 (make_IPython): fixed bug where initial install would leave the
2434 user running in the .ipython dir.
2441 user running in the .ipython dir.
2435 (make_IPython): fixed bug where config dir .ipython would be
2442 (make_IPython): fixed bug where config dir .ipython would be
2436 created regardless of the given -ipythondir option. Thanks to Cory
2443 created regardless of the given -ipythondir option. Thanks to Cory
2437 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
2444 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
2438
2445
2439 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
2446 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
2440 type confirmations. Will need to use it in all of IPython's code
2447 type confirmations. Will need to use it in all of IPython's code
2441 consistently.
2448 consistently.
2442
2449
2443 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
2450 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
2444 context to print 31 lines instead of the default 5. This will make
2451 context to print 31 lines instead of the default 5. This will make
2445 the crash reports extremely detailed in case the problem is in
2452 the crash reports extremely detailed in case the problem is in
2446 libraries I don't have access to.
2453 libraries I don't have access to.
2447
2454
2448 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
2455 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
2449 line of defense' code to still crash, but giving users fair
2456 line of defense' code to still crash, but giving users fair
2450 warning. I don't want internal errors to go unreported: if there's
2457 warning. I don't want internal errors to go unreported: if there's
2451 an internal problem, IPython should crash and generate a full
2458 an internal problem, IPython should crash and generate a full
2452 report.
2459 report.
2453
2460
2454 2002-11-08 Fernando Perez <fperez@colorado.edu>
2461 2002-11-08 Fernando Perez <fperez@colorado.edu>
2455
2462
2456 * IPython/iplib.py (InteractiveShell.interact): added code to trap
2463 * IPython/iplib.py (InteractiveShell.interact): added code to trap
2457 otherwise uncaught exceptions which can appear if people set
2464 otherwise uncaught exceptions which can appear if people set
2458 sys.stdout to something badly broken. Thanks to a crash report
2465 sys.stdout to something badly broken. Thanks to a crash report
2459 from henni-AT-mail.brainbot.com.
2466 from henni-AT-mail.brainbot.com.
2460
2467
2461 2002-11-04 Fernando Perez <fperez@colorado.edu>
2468 2002-11-04 Fernando Perez <fperez@colorado.edu>
2462
2469
2463 * IPython/iplib.py (InteractiveShell.interact): added
2470 * IPython/iplib.py (InteractiveShell.interact): added
2464 __IPYTHON__active to the builtins. It's a flag which goes on when
2471 __IPYTHON__active to the builtins. It's a flag which goes on when
2465 the interaction starts and goes off again when it stops. This
2472 the interaction starts and goes off again when it stops. This
2466 allows embedding code to detect being inside IPython. Before this
2473 allows embedding code to detect being inside IPython. Before this
2467 was done via __IPYTHON__, but that only shows that an IPython
2474 was done via __IPYTHON__, but that only shows that an IPython
2468 instance has been created.
2475 instance has been created.
2469
2476
2470 * IPython/Magic.py (Magic.magic_env): I realized that in a
2477 * IPython/Magic.py (Magic.magic_env): I realized that in a
2471 UserDict, instance.data holds the data as a normal dict. So I
2478 UserDict, instance.data holds the data as a normal dict. So I
2472 modified @env to return os.environ.data instead of rebuilding a
2479 modified @env to return os.environ.data instead of rebuilding a
2473 dict by hand.
2480 dict by hand.
2474
2481
2475 2002-11-02 Fernando Perez <fperez@colorado.edu>
2482 2002-11-02 Fernando Perez <fperez@colorado.edu>
2476
2483
2477 * IPython/genutils.py (warn): changed so that level 1 prints no
2484 * IPython/genutils.py (warn): changed so that level 1 prints no
2478 header. Level 2 is now the default (with 'WARNING' header, as
2485 header. Level 2 is now the default (with 'WARNING' header, as
2479 before). I think I tracked all places where changes were needed in
2486 before). I think I tracked all places where changes were needed in
2480 IPython, but outside code using the old level numbering may have
2487 IPython, but outside code using the old level numbering may have
2481 broken.
2488 broken.
2482
2489
2483 * IPython/iplib.py (InteractiveShell.runcode): added this to
2490 * IPython/iplib.py (InteractiveShell.runcode): added this to
2484 handle the tracebacks in SystemExit traps correctly. The previous
2491 handle the tracebacks in SystemExit traps correctly. The previous
2485 code (through interact) was printing more of the stack than
2492 code (through interact) was printing more of the stack than
2486 necessary, showing IPython internal code to the user.
2493 necessary, showing IPython internal code to the user.
2487
2494
2488 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
2495 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
2489 default. Now that the default at the confirmation prompt is yes,
2496 default. Now that the default at the confirmation prompt is yes,
2490 it's not so intrusive. François' argument that ipython sessions
2497 it's not so intrusive. François' argument that ipython sessions
2491 tend to be complex enough not to lose them from an accidental C-d,
2498 tend to be complex enough not to lose them from an accidental C-d,
2492 is a valid one.
2499 is a valid one.
2493
2500
2494 * IPython/iplib.py (InteractiveShell.interact): added a
2501 * IPython/iplib.py (InteractiveShell.interact): added a
2495 showtraceback() call to the SystemExit trap, and modified the exit
2502 showtraceback() call to the SystemExit trap, and modified the exit
2496 confirmation to have yes as the default.
2503 confirmation to have yes as the default.
2497
2504
2498 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
2505 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
2499 this file. It's been gone from the code for a long time, this was
2506 this file. It's been gone from the code for a long time, this was
2500 simply leftover junk.
2507 simply leftover junk.
2501
2508
2502 2002-11-01 Fernando Perez <fperez@colorado.edu>
2509 2002-11-01 Fernando Perez <fperez@colorado.edu>
2503
2510
2504 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
2511 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
2505 added. If set, IPython now traps EOF and asks for
2512 added. If set, IPython now traps EOF and asks for
2506 confirmation. After a request by François Pinard.
2513 confirmation. After a request by François Pinard.
2507
2514
2508 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
2515 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
2509 of @abort, and with a new (better) mechanism for handling the
2516 of @abort, and with a new (better) mechanism for handling the
2510 exceptions.
2517 exceptions.
2511
2518
2512 2002-10-27 Fernando Perez <fperez@colorado.edu>
2519 2002-10-27 Fernando Perez <fperez@colorado.edu>
2513
2520
2514 * IPython/usage.py (__doc__): updated the --help information and
2521 * IPython/usage.py (__doc__): updated the --help information and
2515 the ipythonrc file to indicate that -log generates
2522 the ipythonrc file to indicate that -log generates
2516 ./ipython.log. Also fixed the corresponding info in @logstart.
2523 ./ipython.log. Also fixed the corresponding info in @logstart.
2517 This and several other fixes in the manuals thanks to reports by
2524 This and several other fixes in the manuals thanks to reports by
2518 François Pinard <pinard-AT-iro.umontreal.ca>.
2525 François Pinard <pinard-AT-iro.umontreal.ca>.
2519
2526
2520 * IPython/Logger.py (Logger.switch_log): Fixed error message to
2527 * IPython/Logger.py (Logger.switch_log): Fixed error message to
2521 refer to @logstart (instead of @log, which doesn't exist).
2528 refer to @logstart (instead of @log, which doesn't exist).
2522
2529
2523 * IPython/iplib.py (InteractiveShell._prefilter): fixed
2530 * IPython/iplib.py (InteractiveShell._prefilter): fixed
2524 AttributeError crash. Thanks to Christopher Armstrong
2531 AttributeError crash. Thanks to Christopher Armstrong
2525 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
2532 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
2526 introduced recently (in 0.2.14pre37) with the fix to the eval
2533 introduced recently (in 0.2.14pre37) with the fix to the eval
2527 problem mentioned below.
2534 problem mentioned below.
2528
2535
2529 2002-10-17 Fernando Perez <fperez@colorado.edu>
2536 2002-10-17 Fernando Perez <fperez@colorado.edu>
2530
2537
2531 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
2538 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
2532 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
2539 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
2533
2540
2534 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
2541 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
2535 this function to fix a problem reported by Alex Schmolck. He saw
2542 this function to fix a problem reported by Alex Schmolck. He saw
2536 it with list comprehensions and generators, which were getting
2543 it with list comprehensions and generators, which were getting
2537 called twice. The real problem was an 'eval' call in testing for
2544 called twice. The real problem was an 'eval' call in testing for
2538 automagic which was evaluating the input line silently.
2545 automagic which was evaluating the input line silently.
2539
2546
2540 This is a potentially very nasty bug, if the input has side
2547 This is a potentially very nasty bug, if the input has side
2541 effects which must not be repeated. The code is much cleaner now,
2548 effects which must not be repeated. The code is much cleaner now,
2542 without any blanket 'except' left and with a regexp test for
2549 without any blanket 'except' left and with a regexp test for
2543 actual function names.
2550 actual function names.
2544
2551
2545 But an eval remains, which I'm not fully comfortable with. I just
2552 But an eval remains, which I'm not fully comfortable with. I just
2546 don't know how to find out if an expression could be a callable in
2553 don't know how to find out if an expression could be a callable in
2547 the user's namespace without doing an eval on the string. However
2554 the user's namespace without doing an eval on the string. However
2548 that string is now much more strictly checked so that no code
2555 that string is now much more strictly checked so that no code
2549 slips by, so the eval should only happen for things that can
2556 slips by, so the eval should only happen for things that can
2550 really be only function/method names.
2557 really be only function/method names.
2551
2558
2552 2002-10-15 Fernando Perez <fperez@colorado.edu>
2559 2002-10-15 Fernando Perez <fperez@colorado.edu>
2553
2560
2554 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
2561 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
2555 OSX information to main manual, removed README_Mac_OSX file from
2562 OSX information to main manual, removed README_Mac_OSX file from
2556 distribution. Also updated credits for recent additions.
2563 distribution. Also updated credits for recent additions.
2557
2564
2558 2002-10-10 Fernando Perez <fperez@colorado.edu>
2565 2002-10-10 Fernando Perez <fperez@colorado.edu>
2559
2566
2560 * README_Mac_OSX: Added a README for Mac OSX users for fixing
2567 * README_Mac_OSX: Added a README for Mac OSX users for fixing
2561 terminal-related issues. Many thanks to Andrea Riciputi
2568 terminal-related issues. Many thanks to Andrea Riciputi
2562 <andrea.riciputi-AT-libero.it> for writing it.
2569 <andrea.riciputi-AT-libero.it> for writing it.
2563
2570
2564 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
2571 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
2565 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2572 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2566
2573
2567 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
2574 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
2568 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
2575 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
2569 <syver-en-AT-online.no> who both submitted patches for this problem.
2576 <syver-en-AT-online.no> who both submitted patches for this problem.
2570
2577
2571 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
2578 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
2572 global embedding to make sure that things don't overwrite user
2579 global embedding to make sure that things don't overwrite user
2573 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
2580 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
2574
2581
2575 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
2582 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
2576 compatibility. Thanks to Hayden Callow
2583 compatibility. Thanks to Hayden Callow
2577 <h.callow-AT-elec.canterbury.ac.nz>
2584 <h.callow-AT-elec.canterbury.ac.nz>
2578
2585
2579 2002-10-04 Fernando Perez <fperez@colorado.edu>
2586 2002-10-04 Fernando Perez <fperez@colorado.edu>
2580
2587
2581 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
2588 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
2582 Gnuplot.File objects.
2589 Gnuplot.File objects.
2583
2590
2584 2002-07-23 Fernando Perez <fperez@colorado.edu>
2591 2002-07-23 Fernando Perez <fperez@colorado.edu>
2585
2592
2586 * IPython/genutils.py (timing): Added timings() and timing() for
2593 * IPython/genutils.py (timing): Added timings() and timing() for
2587 quick access to the most commonly needed data, the execution
2594 quick access to the most commonly needed data, the execution
2588 times. Old timing() renamed to timings_out().
2595 times. Old timing() renamed to timings_out().
2589
2596
2590 2002-07-18 Fernando Perez <fperez@colorado.edu>
2597 2002-07-18 Fernando Perez <fperez@colorado.edu>
2591
2598
2592 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
2599 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
2593 bug with nested instances disrupting the parent's tab completion.
2600 bug with nested instances disrupting the parent's tab completion.
2594
2601
2595 * IPython/iplib.py (all_completions): Added Alex Schmolck's
2602 * IPython/iplib.py (all_completions): Added Alex Schmolck's
2596 all_completions code to begin the emacs integration.
2603 all_completions code to begin the emacs integration.
2597
2604
2598 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
2605 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
2599 argument to allow titling individual arrays when plotting.
2606 argument to allow titling individual arrays when plotting.
2600
2607
2601 2002-07-15 Fernando Perez <fperez@colorado.edu>
2608 2002-07-15 Fernando Perez <fperez@colorado.edu>
2602
2609
2603 * setup.py (make_shortcut): changed to retrieve the value of
2610 * setup.py (make_shortcut): changed to retrieve the value of
2604 'Program Files' directory from the registry (this value changes in
2611 'Program Files' directory from the registry (this value changes in
2605 non-english versions of Windows). Thanks to Thomas Fanslau
2612 non-english versions of Windows). Thanks to Thomas Fanslau
2606 <tfanslau-AT-gmx.de> for the report.
2613 <tfanslau-AT-gmx.de> for the report.
2607
2614
2608 2002-07-10 Fernando Perez <fperez@colorado.edu>
2615 2002-07-10 Fernando Perez <fperez@colorado.edu>
2609
2616
2610 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
2617 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
2611 a bug in pdb, which crashes if a line with only whitespace is
2618 a bug in pdb, which crashes if a line with only whitespace is
2612 entered. Bug report submitted to sourceforge.
2619 entered. Bug report submitted to sourceforge.
2613
2620
2614 2002-07-09 Fernando Perez <fperez@colorado.edu>
2621 2002-07-09 Fernando Perez <fperez@colorado.edu>
2615
2622
2616 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
2623 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
2617 reporting exceptions (it's a bug in inspect.py, I just set a
2624 reporting exceptions (it's a bug in inspect.py, I just set a
2618 workaround).
2625 workaround).
2619
2626
2620 2002-07-08 Fernando Perez <fperez@colorado.edu>
2627 2002-07-08 Fernando Perez <fperez@colorado.edu>
2621
2628
2622 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
2629 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
2623 __IPYTHON__ in __builtins__ to show up in user_ns.
2630 __IPYTHON__ in __builtins__ to show up in user_ns.
2624
2631
2625 2002-07-03 Fernando Perez <fperez@colorado.edu>
2632 2002-07-03 Fernando Perez <fperez@colorado.edu>
2626
2633
2627 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
2634 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
2628 name from @gp_set_instance to @gp_set_default.
2635 name from @gp_set_instance to @gp_set_default.
2629
2636
2630 * IPython/ipmaker.py (make_IPython): default editor value set to
2637 * IPython/ipmaker.py (make_IPython): default editor value set to
2631 '0' (a string), to match the rc file. Otherwise will crash when
2638 '0' (a string), to match the rc file. Otherwise will crash when
2632 .strip() is called on it.
2639 .strip() is called on it.
2633
2640
2634
2641
2635 2002-06-28 Fernando Perez <fperez@colorado.edu>
2642 2002-06-28 Fernando Perez <fperez@colorado.edu>
2636
2643
2637 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
2644 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
2638 of files in current directory when a file is executed via
2645 of files in current directory when a file is executed via
2639 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
2646 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
2640
2647
2641 * setup.py (manfiles): fix for rpm builds, submitted by RA
2648 * setup.py (manfiles): fix for rpm builds, submitted by RA
2642 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
2649 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
2643
2650
2644 * IPython/ipmaker.py (make_IPython): fixed lookup of default
2651 * IPython/ipmaker.py (make_IPython): fixed lookup of default
2645 editor when set to '0'. Problem was, '0' evaluates to True (it's a
2652 editor when set to '0'. Problem was, '0' evaluates to True (it's a
2646 string!). A. Schmolck caught this one.
2653 string!). A. Schmolck caught this one.
2647
2654
2648 2002-06-27 Fernando Perez <fperez@colorado.edu>
2655 2002-06-27 Fernando Perez <fperez@colorado.edu>
2649
2656
2650 * IPython/ipmaker.py (make_IPython): fixed bug when running user
2657 * IPython/ipmaker.py (make_IPython): fixed bug when running user
2651 defined files at the cmd line. __name__ wasn't being set to
2658 defined files at the cmd line. __name__ wasn't being set to
2652 __main__.
2659 __main__.
2653
2660
2654 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
2661 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
2655 regular lists and tuples besides Numeric arrays.
2662 regular lists and tuples besides Numeric arrays.
2656
2663
2657 * IPython/Prompts.py (CachedOutput.__call__): Added output
2664 * IPython/Prompts.py (CachedOutput.__call__): Added output
2658 supression for input ending with ';'. Similar to Mathematica and
2665 supression for input ending with ';'. Similar to Mathematica and
2659 Matlab. The _* vars and Out[] list are still updated, just like
2666 Matlab. The _* vars and Out[] list are still updated, just like
2660 Mathematica behaves.
2667 Mathematica behaves.
2661
2668
2662 2002-06-25 Fernando Perez <fperez@colorado.edu>
2669 2002-06-25 Fernando Perez <fperez@colorado.edu>
2663
2670
2664 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
2671 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
2665 .ini extensions for profiels under Windows.
2672 .ini extensions for profiels under Windows.
2666
2673
2667 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
2674 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
2668 string form. Fix contributed by Alexander Schmolck
2675 string form. Fix contributed by Alexander Schmolck
2669 <a.schmolck-AT-gmx.net>
2676 <a.schmolck-AT-gmx.net>
2670
2677
2671 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
2678 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
2672 pre-configured Gnuplot instance.
2679 pre-configured Gnuplot instance.
2673
2680
2674 2002-06-21 Fernando Perez <fperez@colorado.edu>
2681 2002-06-21 Fernando Perez <fperez@colorado.edu>
2675
2682
2676 * IPython/numutils.py (exp_safe): new function, works around the
2683 * IPython/numutils.py (exp_safe): new function, works around the
2677 underflow problems in Numeric.
2684 underflow problems in Numeric.
2678 (log2): New fn. Safe log in base 2: returns exact integer answer
2685 (log2): New fn. Safe log in base 2: returns exact integer answer
2679 for exact integer powers of 2.
2686 for exact integer powers of 2.
2680
2687
2681 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
2688 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
2682 properly.
2689 properly.
2683
2690
2684 2002-06-20 Fernando Perez <fperez@colorado.edu>
2691 2002-06-20 Fernando Perez <fperez@colorado.edu>
2685
2692
2686 * IPython/genutils.py (timing): new function like
2693 * IPython/genutils.py (timing): new function like
2687 Mathematica's. Similar to time_test, but returns more info.
2694 Mathematica's. Similar to time_test, but returns more info.
2688
2695
2689 2002-06-18 Fernando Perez <fperez@colorado.edu>
2696 2002-06-18 Fernando Perez <fperez@colorado.edu>
2690
2697
2691 * IPython/Magic.py (Magic.magic_save): modified @save and @r
2698 * IPython/Magic.py (Magic.magic_save): modified @save and @r
2692 according to Mike Heeter's suggestions.
2699 according to Mike Heeter's suggestions.
2693
2700
2694 2002-06-16 Fernando Perez <fperez@colorado.edu>
2701 2002-06-16 Fernando Perez <fperez@colorado.edu>
2695
2702
2696 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
2703 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
2697 system. GnuplotMagic is gone as a user-directory option. New files
2704 system. GnuplotMagic is gone as a user-directory option. New files
2698 make it easier to use all the gnuplot stuff both from external
2705 make it easier to use all the gnuplot stuff both from external
2699 programs as well as from IPython. Had to rewrite part of
2706 programs as well as from IPython. Had to rewrite part of
2700 hardcopy() b/c of a strange bug: often the ps files simply don't
2707 hardcopy() b/c of a strange bug: often the ps files simply don't
2701 get created, and require a repeat of the command (often several
2708 get created, and require a repeat of the command (often several
2702 times).
2709 times).
2703
2710
2704 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
2711 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
2705 resolve output channel at call time, so that if sys.stderr has
2712 resolve output channel at call time, so that if sys.stderr has
2706 been redirected by user this gets honored.
2713 been redirected by user this gets honored.
2707
2714
2708 2002-06-13 Fernando Perez <fperez@colorado.edu>
2715 2002-06-13 Fernando Perez <fperez@colorado.edu>
2709
2716
2710 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
2717 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
2711 IPShell. Kept a copy with the old names to avoid breaking people's
2718 IPShell. Kept a copy with the old names to avoid breaking people's
2712 embedded code.
2719 embedded code.
2713
2720
2714 * IPython/ipython: simplified it to the bare minimum after
2721 * IPython/ipython: simplified it to the bare minimum after
2715 Holger's suggestions. Added info about how to use it in
2722 Holger's suggestions. Added info about how to use it in
2716 PYTHONSTARTUP.
2723 PYTHONSTARTUP.
2717
2724
2718 * IPython/Shell.py (IPythonShell): changed the options passing
2725 * IPython/Shell.py (IPythonShell): changed the options passing
2719 from a string with funky %s replacements to a straight list. Maybe
2726 from a string with funky %s replacements to a straight list. Maybe
2720 a bit more typing, but it follows sys.argv conventions, so there's
2727 a bit more typing, but it follows sys.argv conventions, so there's
2721 less special-casing to remember.
2728 less special-casing to remember.
2722
2729
2723 2002-06-12 Fernando Perez <fperez@colorado.edu>
2730 2002-06-12 Fernando Perez <fperez@colorado.edu>
2724
2731
2725 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
2732 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
2726 command. Thanks to a suggestion by Mike Heeter.
2733 command. Thanks to a suggestion by Mike Heeter.
2727 (Magic.magic_pfile): added behavior to look at filenames if given
2734 (Magic.magic_pfile): added behavior to look at filenames if given
2728 arg is not a defined object.
2735 arg is not a defined object.
2729 (Magic.magic_save): New @save function to save code snippets. Also
2736 (Magic.magic_save): New @save function to save code snippets. Also
2730 a Mike Heeter idea.
2737 a Mike Heeter idea.
2731
2738
2732 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
2739 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
2733 plot() and replot(). Much more convenient now, especially for
2740 plot() and replot(). Much more convenient now, especially for
2734 interactive use.
2741 interactive use.
2735
2742
2736 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
2743 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
2737 filenames.
2744 filenames.
2738
2745
2739 2002-06-02 Fernando Perez <fperez@colorado.edu>
2746 2002-06-02 Fernando Perez <fperez@colorado.edu>
2740
2747
2741 * IPython/Struct.py (Struct.__init__): modified to admit
2748 * IPython/Struct.py (Struct.__init__): modified to admit
2742 initialization via another struct.
2749 initialization via another struct.
2743
2750
2744 * IPython/genutils.py (SystemExec.__init__): New stateful
2751 * IPython/genutils.py (SystemExec.__init__): New stateful
2745 interface to xsys and bq. Useful for writing system scripts.
2752 interface to xsys and bq. Useful for writing system scripts.
2746
2753
2747 2002-05-30 Fernando Perez <fperez@colorado.edu>
2754 2002-05-30 Fernando Perez <fperez@colorado.edu>
2748
2755
2749 * MANIFEST.in: Changed docfile selection to exclude all the lyx
2756 * MANIFEST.in: Changed docfile selection to exclude all the lyx
2750 documents. This will make the user download smaller (it's getting
2757 documents. This will make the user download smaller (it's getting
2751 too big).
2758 too big).
2752
2759
2753 2002-05-29 Fernando Perez <fperez@colorado.edu>
2760 2002-05-29 Fernando Perez <fperez@colorado.edu>
2754
2761
2755 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
2762 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
2756 fix problems with shelve and pickle. Seems to work, but I don't
2763 fix problems with shelve and pickle. Seems to work, but I don't
2757 know if corner cases break it. Thanks to Mike Heeter
2764 know if corner cases break it. Thanks to Mike Heeter
2758 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
2765 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
2759
2766
2760 2002-05-24 Fernando Perez <fperez@colorado.edu>
2767 2002-05-24 Fernando Perez <fperez@colorado.edu>
2761
2768
2762 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
2769 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
2763 macros having broken.
2770 macros having broken.
2764
2771
2765 2002-05-21 Fernando Perez <fperez@colorado.edu>
2772 2002-05-21 Fernando Perez <fperez@colorado.edu>
2766
2773
2767 * IPython/Magic.py (Magic.magic_logstart): fixed recently
2774 * IPython/Magic.py (Magic.magic_logstart): fixed recently
2768 introduced logging bug: all history before logging started was
2775 introduced logging bug: all history before logging started was
2769 being written one character per line! This came from the redesign
2776 being written one character per line! This came from the redesign
2770 of the input history as a special list which slices to strings,
2777 of the input history as a special list which slices to strings,
2771 not to lists.
2778 not to lists.
2772
2779
2773 2002-05-20 Fernando Perez <fperez@colorado.edu>
2780 2002-05-20 Fernando Perez <fperez@colorado.edu>
2774
2781
2775 * IPython/Prompts.py (CachedOutput.__init__): made the color table
2782 * IPython/Prompts.py (CachedOutput.__init__): made the color table
2776 be an attribute of all classes in this module. The design of these
2783 be an attribute of all classes in this module. The design of these
2777 classes needs some serious overhauling.
2784 classes needs some serious overhauling.
2778
2785
2779 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
2786 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
2780 which was ignoring '_' in option names.
2787 which was ignoring '_' in option names.
2781
2788
2782 * IPython/ultraTB.py (FormattedTB.__init__): Changed
2789 * IPython/ultraTB.py (FormattedTB.__init__): Changed
2783 'Verbose_novars' to 'Context' and made it the new default. It's a
2790 'Verbose_novars' to 'Context' and made it the new default. It's a
2784 bit more readable and also safer than verbose.
2791 bit more readable and also safer than verbose.
2785
2792
2786 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
2793 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
2787 triple-quoted strings.
2794 triple-quoted strings.
2788
2795
2789 * IPython/OInspect.py (__all__): new module exposing the object
2796 * IPython/OInspect.py (__all__): new module exposing the object
2790 introspection facilities. Now the corresponding magics are dummy
2797 introspection facilities. Now the corresponding magics are dummy
2791 wrappers around this. Having this module will make it much easier
2798 wrappers around this. Having this module will make it much easier
2792 to put these functions into our modified pdb.
2799 to put these functions into our modified pdb.
2793 This new object inspector system uses the new colorizing module,
2800 This new object inspector system uses the new colorizing module,
2794 so source code and other things are nicely syntax highlighted.
2801 so source code and other things are nicely syntax highlighted.
2795
2802
2796 2002-05-18 Fernando Perez <fperez@colorado.edu>
2803 2002-05-18 Fernando Perez <fperez@colorado.edu>
2797
2804
2798 * IPython/ColorANSI.py: Split the coloring tools into a separate
2805 * IPython/ColorANSI.py: Split the coloring tools into a separate
2799 module so I can use them in other code easier (they were part of
2806 module so I can use them in other code easier (they were part of
2800 ultraTB).
2807 ultraTB).
2801
2808
2802 2002-05-17 Fernando Perez <fperez@colorado.edu>
2809 2002-05-17 Fernando Perez <fperez@colorado.edu>
2803
2810
2804 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
2811 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
2805 fixed it to set the global 'g' also to the called instance, as
2812 fixed it to set the global 'g' also to the called instance, as
2806 long as 'g' was still a gnuplot instance (so it doesn't overwrite
2813 long as 'g' was still a gnuplot instance (so it doesn't overwrite
2807 user's 'g' variables).
2814 user's 'g' variables).
2808
2815
2809 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
2816 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
2810 global variables (aliases to _ih,_oh) so that users which expect
2817 global variables (aliases to _ih,_oh) so that users which expect
2811 In[5] or Out[7] to work aren't unpleasantly surprised.
2818 In[5] or Out[7] to work aren't unpleasantly surprised.
2812 (InputList.__getslice__): new class to allow executing slices of
2819 (InputList.__getslice__): new class to allow executing slices of
2813 input history directly. Very simple class, complements the use of
2820 input history directly. Very simple class, complements the use of
2814 macros.
2821 macros.
2815
2822
2816 2002-05-16 Fernando Perez <fperez@colorado.edu>
2823 2002-05-16 Fernando Perez <fperez@colorado.edu>
2817
2824
2818 * setup.py (docdirbase): make doc directory be just doc/IPython
2825 * setup.py (docdirbase): make doc directory be just doc/IPython
2819 without version numbers, it will reduce clutter for users.
2826 without version numbers, it will reduce clutter for users.
2820
2827
2821 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
2828 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
2822 execfile call to prevent possible memory leak. See for details:
2829 execfile call to prevent possible memory leak. See for details:
2823 http://mail.python.org/pipermail/python-list/2002-February/088476.html
2830 http://mail.python.org/pipermail/python-list/2002-February/088476.html
2824
2831
2825 2002-05-15 Fernando Perez <fperez@colorado.edu>
2832 2002-05-15 Fernando Perez <fperez@colorado.edu>
2826
2833
2827 * IPython/Magic.py (Magic.magic_psource): made the object
2834 * IPython/Magic.py (Magic.magic_psource): made the object
2828 introspection names be more standard: pdoc, pdef, pfile and
2835 introspection names be more standard: pdoc, pdef, pfile and
2829 psource. They all print/page their output, and it makes
2836 psource. They all print/page their output, and it makes
2830 remembering them easier. Kept old names for compatibility as
2837 remembering them easier. Kept old names for compatibility as
2831 aliases.
2838 aliases.
2832
2839
2833 2002-05-14 Fernando Perez <fperez@colorado.edu>
2840 2002-05-14 Fernando Perez <fperez@colorado.edu>
2834
2841
2835 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
2842 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
2836 what the mouse problem was. The trick is to use gnuplot with temp
2843 what the mouse problem was. The trick is to use gnuplot with temp
2837 files and NOT with pipes (for data communication), because having
2844 files and NOT with pipes (for data communication), because having
2838 both pipes and the mouse on is bad news.
2845 both pipes and the mouse on is bad news.
2839
2846
2840 2002-05-13 Fernando Perez <fperez@colorado.edu>
2847 2002-05-13 Fernando Perez <fperez@colorado.edu>
2841
2848
2842 * IPython/Magic.py (Magic._ofind): fixed namespace order search
2849 * IPython/Magic.py (Magic._ofind): fixed namespace order search
2843 bug. Information would be reported about builtins even when
2850 bug. Information would be reported about builtins even when
2844 user-defined functions overrode them.
2851 user-defined functions overrode them.
2845
2852
2846 2002-05-11 Fernando Perez <fperez@colorado.edu>
2853 2002-05-11 Fernando Perez <fperez@colorado.edu>
2847
2854
2848 * IPython/__init__.py (__all__): removed FlexCompleter from
2855 * IPython/__init__.py (__all__): removed FlexCompleter from
2849 __all__ so that things don't fail in platforms without readline.
2856 __all__ so that things don't fail in platforms without readline.
2850
2857
2851 2002-05-10 Fernando Perez <fperez@colorado.edu>
2858 2002-05-10 Fernando Perez <fperez@colorado.edu>
2852
2859
2853 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
2860 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
2854 it requires Numeric, effectively making Numeric a dependency for
2861 it requires Numeric, effectively making Numeric a dependency for
2855 IPython.
2862 IPython.
2856
2863
2857 * Released 0.2.13
2864 * Released 0.2.13
2858
2865
2859 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
2866 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
2860 profiler interface. Now all the major options from the profiler
2867 profiler interface. Now all the major options from the profiler
2861 module are directly supported in IPython, both for single
2868 module are directly supported in IPython, both for single
2862 expressions (@prun) and for full programs (@run -p).
2869 expressions (@prun) and for full programs (@run -p).
2863
2870
2864 2002-05-09 Fernando Perez <fperez@colorado.edu>
2871 2002-05-09 Fernando Perez <fperez@colorado.edu>
2865
2872
2866 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
2873 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
2867 magic properly formatted for screen.
2874 magic properly formatted for screen.
2868
2875
2869 * setup.py (make_shortcut): Changed things to put pdf version in
2876 * setup.py (make_shortcut): Changed things to put pdf version in
2870 doc/ instead of doc/manual (had to change lyxport a bit).
2877 doc/ instead of doc/manual (had to change lyxport a bit).
2871
2878
2872 * IPython/Magic.py (Profile.string_stats): made profile runs go
2879 * IPython/Magic.py (Profile.string_stats): made profile runs go
2873 through pager (they are long and a pager allows searching, saving,
2880 through pager (they are long and a pager allows searching, saving,
2874 etc.)
2881 etc.)
2875
2882
2876 2002-05-08 Fernando Perez <fperez@colorado.edu>
2883 2002-05-08 Fernando Perez <fperez@colorado.edu>
2877
2884
2878 * Released 0.2.12
2885 * Released 0.2.12
2879
2886
2880 2002-05-06 Fernando Perez <fperez@colorado.edu>
2887 2002-05-06 Fernando Perez <fperez@colorado.edu>
2881
2888
2882 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
2889 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
2883 introduced); 'hist n1 n2' was broken.
2890 introduced); 'hist n1 n2' was broken.
2884 (Magic.magic_pdb): added optional on/off arguments to @pdb
2891 (Magic.magic_pdb): added optional on/off arguments to @pdb
2885 (Magic.magic_run): added option -i to @run, which executes code in
2892 (Magic.magic_run): added option -i to @run, which executes code in
2886 the IPython namespace instead of a clean one. Also added @irun as
2893 the IPython namespace instead of a clean one. Also added @irun as
2887 an alias to @run -i.
2894 an alias to @run -i.
2888
2895
2889 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
2896 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
2890 fixed (it didn't really do anything, the namespaces were wrong).
2897 fixed (it didn't really do anything, the namespaces were wrong).
2891
2898
2892 * IPython/Debugger.py (__init__): Added workaround for python 2.1
2899 * IPython/Debugger.py (__init__): Added workaround for python 2.1
2893
2900
2894 * IPython/__init__.py (__all__): Fixed package namespace, now
2901 * IPython/__init__.py (__all__): Fixed package namespace, now
2895 'import IPython' does give access to IPython.<all> as
2902 'import IPython' does give access to IPython.<all> as
2896 expected. Also renamed __release__ to Release.
2903 expected. Also renamed __release__ to Release.
2897
2904
2898 * IPython/Debugger.py (__license__): created new Pdb class which
2905 * IPython/Debugger.py (__license__): created new Pdb class which
2899 functions like a drop-in for the normal pdb.Pdb but does NOT
2906 functions like a drop-in for the normal pdb.Pdb but does NOT
2900 import readline by default. This way it doesn't muck up IPython's
2907 import readline by default. This way it doesn't muck up IPython's
2901 readline handling, and now tab-completion finally works in the
2908 readline handling, and now tab-completion finally works in the
2902 debugger -- sort of. It completes things globally visible, but the
2909 debugger -- sort of. It completes things globally visible, but the
2903 completer doesn't track the stack as pdb walks it. That's a bit
2910 completer doesn't track the stack as pdb walks it. That's a bit
2904 tricky, and I'll have to implement it later.
2911 tricky, and I'll have to implement it later.
2905
2912
2906 2002-05-05 Fernando Perez <fperez@colorado.edu>
2913 2002-05-05 Fernando Perez <fperez@colorado.edu>
2907
2914
2908 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
2915 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
2909 magic docstrings when printed via ? (explicit \'s were being
2916 magic docstrings when printed via ? (explicit \'s were being
2910 printed).
2917 printed).
2911
2918
2912 * IPython/ipmaker.py (make_IPython): fixed namespace
2919 * IPython/ipmaker.py (make_IPython): fixed namespace
2913 identification bug. Now variables loaded via logs or command-line
2920 identification bug. Now variables loaded via logs or command-line
2914 files are recognized in the interactive namespace by @who.
2921 files are recognized in the interactive namespace by @who.
2915
2922
2916 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
2923 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
2917 log replay system stemming from the string form of Structs.
2924 log replay system stemming from the string form of Structs.
2918
2925
2919 * IPython/Magic.py (Macro.__init__): improved macros to properly
2926 * IPython/Magic.py (Macro.__init__): improved macros to properly
2920 handle magic commands in them.
2927 handle magic commands in them.
2921 (Magic.magic_logstart): usernames are now expanded so 'logstart
2928 (Magic.magic_logstart): usernames are now expanded so 'logstart
2922 ~/mylog' now works.
2929 ~/mylog' now works.
2923
2930
2924 * IPython/iplib.py (complete): fixed bug where paths starting with
2931 * IPython/iplib.py (complete): fixed bug where paths starting with
2925 '/' would be completed as magic names.
2932 '/' would be completed as magic names.
2926
2933
2927 2002-05-04 Fernando Perez <fperez@colorado.edu>
2934 2002-05-04 Fernando Perez <fperez@colorado.edu>
2928
2935
2929 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
2936 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
2930 allow running full programs under the profiler's control.
2937 allow running full programs under the profiler's control.
2931
2938
2932 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
2939 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
2933 mode to report exceptions verbosely but without formatting
2940 mode to report exceptions verbosely but without formatting
2934 variables. This addresses the issue of ipython 'freezing' (it's
2941 variables. This addresses the issue of ipython 'freezing' (it's
2935 not frozen, but caught in an expensive formatting loop) when huge
2942 not frozen, but caught in an expensive formatting loop) when huge
2936 variables are in the context of an exception.
2943 variables are in the context of an exception.
2937 (VerboseTB.text): Added '--->' markers at line where exception was
2944 (VerboseTB.text): Added '--->' markers at line where exception was
2938 triggered. Much clearer to read, especially in NoColor modes.
2945 triggered. Much clearer to read, especially in NoColor modes.
2939
2946
2940 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
2947 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
2941 implemented in reverse when changing to the new parse_options().
2948 implemented in reverse when changing to the new parse_options().
2942
2949
2943 2002-05-03 Fernando Perez <fperez@colorado.edu>
2950 2002-05-03 Fernando Perez <fperez@colorado.edu>
2944
2951
2945 * IPython/Magic.py (Magic.parse_options): new function so that
2952 * IPython/Magic.py (Magic.parse_options): new function so that
2946 magics can parse options easier.
2953 magics can parse options easier.
2947 (Magic.magic_prun): new function similar to profile.run(),
2954 (Magic.magic_prun): new function similar to profile.run(),
2948 suggested by Chris Hart.
2955 suggested by Chris Hart.
2949 (Magic.magic_cd): fixed behavior so that it only changes if
2956 (Magic.magic_cd): fixed behavior so that it only changes if
2950 directory actually is in history.
2957 directory actually is in history.
2951
2958
2952 * IPython/usage.py (__doc__): added information about potential
2959 * IPython/usage.py (__doc__): added information about potential
2953 slowness of Verbose exception mode when there are huge data
2960 slowness of Verbose exception mode when there are huge data
2954 structures to be formatted (thanks to Archie Paulson).
2961 structures to be formatted (thanks to Archie Paulson).
2955
2962
2956 * IPython/ipmaker.py (make_IPython): Changed default logging
2963 * IPython/ipmaker.py (make_IPython): Changed default logging
2957 (when simply called with -log) to use curr_dir/ipython.log in
2964 (when simply called with -log) to use curr_dir/ipython.log in
2958 rotate mode. Fixed crash which was occuring with -log before
2965 rotate mode. Fixed crash which was occuring with -log before
2959 (thanks to Jim Boyle).
2966 (thanks to Jim Boyle).
2960
2967
2961 2002-05-01 Fernando Perez <fperez@colorado.edu>
2968 2002-05-01 Fernando Perez <fperez@colorado.edu>
2962
2969
2963 * Released 0.2.11 for these fixes (mainly the ultraTB one which
2970 * Released 0.2.11 for these fixes (mainly the ultraTB one which
2964 was nasty -- though somewhat of a corner case).
2971 was nasty -- though somewhat of a corner case).
2965
2972
2966 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
2973 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
2967 text (was a bug).
2974 text (was a bug).
2968
2975
2969 2002-04-30 Fernando Perez <fperez@colorado.edu>
2976 2002-04-30 Fernando Perez <fperez@colorado.edu>
2970
2977
2971 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
2978 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
2972 a print after ^D or ^C from the user so that the In[] prompt
2979 a print after ^D or ^C from the user so that the In[] prompt
2973 doesn't over-run the gnuplot one.
2980 doesn't over-run the gnuplot one.
2974
2981
2975 2002-04-29 Fernando Perez <fperez@colorado.edu>
2982 2002-04-29 Fernando Perez <fperez@colorado.edu>
2976
2983
2977 * Released 0.2.10
2984 * Released 0.2.10
2978
2985
2979 * IPython/__release__.py (version): get date dynamically.
2986 * IPython/__release__.py (version): get date dynamically.
2980
2987
2981 * Misc. documentation updates thanks to Arnd's comments. Also ran
2988 * Misc. documentation updates thanks to Arnd's comments. Also ran
2982 a full spellcheck on the manual (hadn't been done in a while).
2989 a full spellcheck on the manual (hadn't been done in a while).
2983
2990
2984 2002-04-27 Fernando Perez <fperez@colorado.edu>
2991 2002-04-27 Fernando Perez <fperez@colorado.edu>
2985
2992
2986 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
2993 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
2987 starting a log in mid-session would reset the input history list.
2994 starting a log in mid-session would reset the input history list.
2988
2995
2989 2002-04-26 Fernando Perez <fperez@colorado.edu>
2996 2002-04-26 Fernando Perez <fperez@colorado.edu>
2990
2997
2991 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
2998 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
2992 all files were being included in an update. Now anything in
2999 all files were being included in an update. Now anything in
2993 UserConfig that matches [A-Za-z]*.py will go (this excludes
3000 UserConfig that matches [A-Za-z]*.py will go (this excludes
2994 __init__.py)
3001 __init__.py)
2995
3002
2996 2002-04-25 Fernando Perez <fperez@colorado.edu>
3003 2002-04-25 Fernando Perez <fperez@colorado.edu>
2997
3004
2998 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
3005 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
2999 to __builtins__ so that any form of embedded or imported code can
3006 to __builtins__ so that any form of embedded or imported code can
3000 test for being inside IPython.
3007 test for being inside IPython.
3001
3008
3002 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
3009 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
3003 changed to GnuplotMagic because it's now an importable module,
3010 changed to GnuplotMagic because it's now an importable module,
3004 this makes the name follow that of the standard Gnuplot module.
3011 this makes the name follow that of the standard Gnuplot module.
3005 GnuplotMagic can now be loaded at any time in mid-session.
3012 GnuplotMagic can now be loaded at any time in mid-session.
3006
3013
3007 2002-04-24 Fernando Perez <fperez@colorado.edu>
3014 2002-04-24 Fernando Perez <fperez@colorado.edu>
3008
3015
3009 * IPython/numutils.py: removed SIUnits. It doesn't properly set
3016 * IPython/numutils.py: removed SIUnits. It doesn't properly set
3010 the globals (IPython has its own namespace) and the
3017 the globals (IPython has its own namespace) and the
3011 PhysicalQuantity stuff is much better anyway.
3018 PhysicalQuantity stuff is much better anyway.
3012
3019
3013 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
3020 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
3014 embedding example to standard user directory for
3021 embedding example to standard user directory for
3015 distribution. Also put it in the manual.
3022 distribution. Also put it in the manual.
3016
3023
3017 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
3024 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
3018 instance as first argument (so it doesn't rely on some obscure
3025 instance as first argument (so it doesn't rely on some obscure
3019 hidden global).
3026 hidden global).
3020
3027
3021 * IPython/UserConfig/ipythonrc.py: put () back in accepted
3028 * IPython/UserConfig/ipythonrc.py: put () back in accepted
3022 delimiters. While it prevents ().TAB from working, it allows
3029 delimiters. While it prevents ().TAB from working, it allows
3023 completions in open (... expressions. This is by far a more common
3030 completions in open (... expressions. This is by far a more common
3024 case.
3031 case.
3025
3032
3026 2002-04-23 Fernando Perez <fperez@colorado.edu>
3033 2002-04-23 Fernando Perez <fperez@colorado.edu>
3027
3034
3028 * IPython/Extensions/InterpreterPasteInput.py: new
3035 * IPython/Extensions/InterpreterPasteInput.py: new
3029 syntax-processing module for pasting lines with >>> or ... at the
3036 syntax-processing module for pasting lines with >>> or ... at the
3030 start.
3037 start.
3031
3038
3032 * IPython/Extensions/PhysicalQ_Interactive.py
3039 * IPython/Extensions/PhysicalQ_Interactive.py
3033 (PhysicalQuantityInteractive.__int__): fixed to work with either
3040 (PhysicalQuantityInteractive.__int__): fixed to work with either
3034 Numeric or math.
3041 Numeric or math.
3035
3042
3036 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
3043 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
3037 provided profiles. Now we have:
3044 provided profiles. Now we have:
3038 -math -> math module as * and cmath with its own namespace.
3045 -math -> math module as * and cmath with its own namespace.
3039 -numeric -> Numeric as *, plus gnuplot & grace
3046 -numeric -> Numeric as *, plus gnuplot & grace
3040 -physics -> same as before
3047 -physics -> same as before
3041
3048
3042 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
3049 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
3043 user-defined magics wouldn't be found by @magic if they were
3050 user-defined magics wouldn't be found by @magic if they were
3044 defined as class methods. Also cleaned up the namespace search
3051 defined as class methods. Also cleaned up the namespace search
3045 logic and the string building (to use %s instead of many repeated
3052 logic and the string building (to use %s instead of many repeated
3046 string adds).
3053 string adds).
3047
3054
3048 * IPython/UserConfig/example-magic.py (magic_foo): updated example
3055 * IPython/UserConfig/example-magic.py (magic_foo): updated example
3049 of user-defined magics to operate with class methods (cleaner, in
3056 of user-defined magics to operate with class methods (cleaner, in
3050 line with the gnuplot code).
3057 line with the gnuplot code).
3051
3058
3052 2002-04-22 Fernando Perez <fperez@colorado.edu>
3059 2002-04-22 Fernando Perez <fperez@colorado.edu>
3053
3060
3054 * setup.py: updated dependency list so that manual is updated when
3061 * setup.py: updated dependency list so that manual is updated when
3055 all included files change.
3062 all included files change.
3056
3063
3057 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
3064 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
3058 the delimiter removal option (the fix is ugly right now).
3065 the delimiter removal option (the fix is ugly right now).
3059
3066
3060 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
3067 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
3061 all of the math profile (quicker loading, no conflict between
3068 all of the math profile (quicker loading, no conflict between
3062 g-9.8 and g-gnuplot).
3069 g-9.8 and g-gnuplot).
3063
3070
3064 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
3071 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
3065 name of post-mortem files to IPython_crash_report.txt.
3072 name of post-mortem files to IPython_crash_report.txt.
3066
3073
3067 * Cleanup/update of the docs. Added all the new readline info and
3074 * Cleanup/update of the docs. Added all the new readline info and
3068 formatted all lists as 'real lists'.
3075 formatted all lists as 'real lists'.
3069
3076
3070 * IPython/ipmaker.py (make_IPython): removed now-obsolete
3077 * IPython/ipmaker.py (make_IPython): removed now-obsolete
3071 tab-completion options, since the full readline parse_and_bind is
3078 tab-completion options, since the full readline parse_and_bind is
3072 now accessible.
3079 now accessible.
3073
3080
3074 * IPython/iplib.py (InteractiveShell.init_readline): Changed
3081 * IPython/iplib.py (InteractiveShell.init_readline): Changed
3075 handling of readline options. Now users can specify any string to
3082 handling of readline options. Now users can specify any string to
3076 be passed to parse_and_bind(), as well as the delimiters to be
3083 be passed to parse_and_bind(), as well as the delimiters to be
3077 removed.
3084 removed.
3078 (InteractiveShell.__init__): Added __name__ to the global
3085 (InteractiveShell.__init__): Added __name__ to the global
3079 namespace so that things like Itpl which rely on its existence
3086 namespace so that things like Itpl which rely on its existence
3080 don't crash.
3087 don't crash.
3081 (InteractiveShell._prefilter): Defined the default with a _ so
3088 (InteractiveShell._prefilter): Defined the default with a _ so
3082 that prefilter() is easier to override, while the default one
3089 that prefilter() is easier to override, while the default one
3083 remains available.
3090 remains available.
3084
3091
3085 2002-04-18 Fernando Perez <fperez@colorado.edu>
3092 2002-04-18 Fernando Perez <fperez@colorado.edu>
3086
3093
3087 * Added information about pdb in the docs.
3094 * Added information about pdb in the docs.
3088
3095
3089 2002-04-17 Fernando Perez <fperez@colorado.edu>
3096 2002-04-17 Fernando Perez <fperez@colorado.edu>
3090
3097
3091 * IPython/ipmaker.py (make_IPython): added rc_override option to
3098 * IPython/ipmaker.py (make_IPython): added rc_override option to
3092 allow passing config options at creation time which may override
3099 allow passing config options at creation time which may override
3093 anything set in the config files or command line. This is
3100 anything set in the config files or command line. This is
3094 particularly useful for configuring embedded instances.
3101 particularly useful for configuring embedded instances.
3095
3102
3096 2002-04-15 Fernando Perez <fperez@colorado.edu>
3103 2002-04-15 Fernando Perez <fperez@colorado.edu>
3097
3104
3098 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
3105 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
3099 crash embedded instances because of the input cache falling out of
3106 crash embedded instances because of the input cache falling out of
3100 sync with the output counter.
3107 sync with the output counter.
3101
3108
3102 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
3109 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
3103 mode which calls pdb after an uncaught exception in IPython itself.
3110 mode which calls pdb after an uncaught exception in IPython itself.
3104
3111
3105 2002-04-14 Fernando Perez <fperez@colorado.edu>
3112 2002-04-14 Fernando Perez <fperez@colorado.edu>
3106
3113
3107 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
3114 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
3108 readline, fix it back after each call.
3115 readline, fix it back after each call.
3109
3116
3110 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
3117 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
3111 method to force all access via __call__(), which guarantees that
3118 method to force all access via __call__(), which guarantees that
3112 traceback references are properly deleted.
3119 traceback references are properly deleted.
3113
3120
3114 * IPython/Prompts.py (CachedOutput._display): minor fixes to
3121 * IPython/Prompts.py (CachedOutput._display): minor fixes to
3115 improve printing when pprint is in use.
3122 improve printing when pprint is in use.
3116
3123
3117 2002-04-13 Fernando Perez <fperez@colorado.edu>
3124 2002-04-13 Fernando Perez <fperez@colorado.edu>
3118
3125
3119 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
3126 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
3120 exceptions aren't caught anymore. If the user triggers one, he
3127 exceptions aren't caught anymore. If the user triggers one, he
3121 should know why he's doing it and it should go all the way up,
3128 should know why he's doing it and it should go all the way up,
3122 just like any other exception. So now @abort will fully kill the
3129 just like any other exception. So now @abort will fully kill the
3123 embedded interpreter and the embedding code (unless that happens
3130 embedded interpreter and the embedding code (unless that happens
3124 to catch SystemExit).
3131 to catch SystemExit).
3125
3132
3126 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
3133 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
3127 and a debugger() method to invoke the interactive pdb debugger
3134 and a debugger() method to invoke the interactive pdb debugger
3128 after printing exception information. Also added the corresponding
3135 after printing exception information. Also added the corresponding
3129 -pdb option and @pdb magic to control this feature, and updated
3136 -pdb option and @pdb magic to control this feature, and updated
3130 the docs. After a suggestion from Christopher Hart
3137 the docs. After a suggestion from Christopher Hart
3131 (hart-AT-caltech.edu).
3138 (hart-AT-caltech.edu).
3132
3139
3133 2002-04-12 Fernando Perez <fperez@colorado.edu>
3140 2002-04-12 Fernando Perez <fperez@colorado.edu>
3134
3141
3135 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
3142 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
3136 the exception handlers defined by the user (not the CrashHandler)
3143 the exception handlers defined by the user (not the CrashHandler)
3137 so that user exceptions don't trigger an ipython bug report.
3144 so that user exceptions don't trigger an ipython bug report.
3138
3145
3139 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
3146 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
3140 configurable (it should have always been so).
3147 configurable (it should have always been so).
3141
3148
3142 2002-03-26 Fernando Perez <fperez@colorado.edu>
3149 2002-03-26 Fernando Perez <fperez@colorado.edu>
3143
3150
3144 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
3151 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
3145 and there to fix embedding namespace issues. This should all be
3152 and there to fix embedding namespace issues. This should all be
3146 done in a more elegant way.
3153 done in a more elegant way.
3147
3154
3148 2002-03-25 Fernando Perez <fperez@colorado.edu>
3155 2002-03-25 Fernando Perez <fperez@colorado.edu>
3149
3156
3150 * IPython/genutils.py (get_home_dir): Try to make it work under
3157 * IPython/genutils.py (get_home_dir): Try to make it work under
3151 win9x also.
3158 win9x also.
3152
3159
3153 2002-03-20 Fernando Perez <fperez@colorado.edu>
3160 2002-03-20 Fernando Perez <fperez@colorado.edu>
3154
3161
3155 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
3162 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
3156 sys.displayhook untouched upon __init__.
3163 sys.displayhook untouched upon __init__.
3157
3164
3158 2002-03-19 Fernando Perez <fperez@colorado.edu>
3165 2002-03-19 Fernando Perez <fperez@colorado.edu>
3159
3166
3160 * Released 0.2.9 (for embedding bug, basically).
3167 * Released 0.2.9 (for embedding bug, basically).
3161
3168
3162 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
3169 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
3163 exceptions so that enclosing shell's state can be restored.
3170 exceptions so that enclosing shell's state can be restored.
3164
3171
3165 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
3172 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
3166 naming conventions in the .ipython/ dir.
3173 naming conventions in the .ipython/ dir.
3167
3174
3168 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
3175 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
3169 from delimiters list so filenames with - in them get expanded.
3176 from delimiters list so filenames with - in them get expanded.
3170
3177
3171 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
3178 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
3172 sys.displayhook not being properly restored after an embedded call.
3179 sys.displayhook not being properly restored after an embedded call.
3173
3180
3174 2002-03-18 Fernando Perez <fperez@colorado.edu>
3181 2002-03-18 Fernando Perez <fperez@colorado.edu>
3175
3182
3176 * Released 0.2.8
3183 * Released 0.2.8
3177
3184
3178 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
3185 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
3179 some files weren't being included in a -upgrade.
3186 some files weren't being included in a -upgrade.
3180 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
3187 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
3181 on' so that the first tab completes.
3188 on' so that the first tab completes.
3182 (InteractiveShell.handle_magic): fixed bug with spaces around
3189 (InteractiveShell.handle_magic): fixed bug with spaces around
3183 quotes breaking many magic commands.
3190 quotes breaking many magic commands.
3184
3191
3185 * setup.py: added note about ignoring the syntax error messages at
3192 * setup.py: added note about ignoring the syntax error messages at
3186 installation.
3193 installation.
3187
3194
3188 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
3195 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
3189 streamlining the gnuplot interface, now there's only one magic @gp.
3196 streamlining the gnuplot interface, now there's only one magic @gp.
3190
3197
3191 2002-03-17 Fernando Perez <fperez@colorado.edu>
3198 2002-03-17 Fernando Perez <fperez@colorado.edu>
3192
3199
3193 * IPython/UserConfig/magic_gnuplot.py: new name for the
3200 * IPython/UserConfig/magic_gnuplot.py: new name for the
3194 example-magic_pm.py file. Much enhanced system, now with a shell
3201 example-magic_pm.py file. Much enhanced system, now with a shell
3195 for communicating directly with gnuplot, one command at a time.
3202 for communicating directly with gnuplot, one command at a time.
3196
3203
3197 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
3204 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
3198 setting __name__=='__main__'.
3205 setting __name__=='__main__'.
3199
3206
3200 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
3207 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
3201 mini-shell for accessing gnuplot from inside ipython. Should
3208 mini-shell for accessing gnuplot from inside ipython. Should
3202 extend it later for grace access too. Inspired by Arnd's
3209 extend it later for grace access too. Inspired by Arnd's
3203 suggestion.
3210 suggestion.
3204
3211
3205 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
3212 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
3206 calling magic functions with () in their arguments. Thanks to Arnd
3213 calling magic functions with () in their arguments. Thanks to Arnd
3207 Baecker for pointing this to me.
3214 Baecker for pointing this to me.
3208
3215
3209 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
3216 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
3210 infinitely for integer or complex arrays (only worked with floats).
3217 infinitely for integer or complex arrays (only worked with floats).
3211
3218
3212 2002-03-16 Fernando Perez <fperez@colorado.edu>
3219 2002-03-16 Fernando Perez <fperez@colorado.edu>
3213
3220
3214 * setup.py: Merged setup and setup_windows into a single script
3221 * setup.py: Merged setup and setup_windows into a single script
3215 which properly handles things for windows users.
3222 which properly handles things for windows users.
3216
3223
3217 2002-03-15 Fernando Perez <fperez@colorado.edu>
3224 2002-03-15 Fernando Perez <fperez@colorado.edu>
3218
3225
3219 * Big change to the manual: now the magics are all automatically
3226 * Big change to the manual: now the magics are all automatically
3220 documented. This information is generated from their docstrings
3227 documented. This information is generated from their docstrings
3221 and put in a latex file included by the manual lyx file. This way
3228 and put in a latex file included by the manual lyx file. This way
3222 we get always up to date information for the magics. The manual
3229 we get always up to date information for the magics. The manual
3223 now also has proper version information, also auto-synced.
3230 now also has proper version information, also auto-synced.
3224
3231
3225 For this to work, an undocumented --magic_docstrings option was added.
3232 For this to work, an undocumented --magic_docstrings option was added.
3226
3233
3227 2002-03-13 Fernando Perez <fperez@colorado.edu>
3234 2002-03-13 Fernando Perez <fperez@colorado.edu>
3228
3235
3229 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
3236 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
3230 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
3237 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
3231
3238
3232 2002-03-12 Fernando Perez <fperez@colorado.edu>
3239 2002-03-12 Fernando Perez <fperez@colorado.edu>
3233
3240
3234 * IPython/ultraTB.py (TermColors): changed color escapes again to
3241 * IPython/ultraTB.py (TermColors): changed color escapes again to
3235 fix the (old, reintroduced) line-wrapping bug. Basically, if
3242 fix the (old, reintroduced) line-wrapping bug. Basically, if
3236 \001..\002 aren't given in the color escapes, lines get wrapped
3243 \001..\002 aren't given in the color escapes, lines get wrapped
3237 weirdly. But giving those screws up old xterms and emacs terms. So
3244 weirdly. But giving those screws up old xterms and emacs terms. So
3238 I added some logic for emacs terms to be ok, but I can't identify old
3245 I added some logic for emacs terms to be ok, but I can't identify old
3239 xterms separately ($TERM=='xterm' for many terminals, like konsole).
3246 xterms separately ($TERM=='xterm' for many terminals, like konsole).
3240
3247
3241 2002-03-10 Fernando Perez <fperez@colorado.edu>
3248 2002-03-10 Fernando Perez <fperez@colorado.edu>
3242
3249
3243 * IPython/usage.py (__doc__): Various documentation cleanups and
3250 * IPython/usage.py (__doc__): Various documentation cleanups and
3244 updates, both in usage docstrings and in the manual.
3251 updates, both in usage docstrings and in the manual.
3245
3252
3246 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
3253 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
3247 handling of caching. Set minimum acceptabe value for having a
3254 handling of caching. Set minimum acceptabe value for having a
3248 cache at 20 values.
3255 cache at 20 values.
3249
3256
3250 * IPython/iplib.py (InteractiveShell.user_setup): moved the
3257 * IPython/iplib.py (InteractiveShell.user_setup): moved the
3251 install_first_time function to a method, renamed it and added an
3258 install_first_time function to a method, renamed it and added an
3252 'upgrade' mode. Now people can update their config directory with
3259 'upgrade' mode. Now people can update their config directory with
3253 a simple command line switch (-upgrade, also new).
3260 a simple command line switch (-upgrade, also new).
3254
3261
3255 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
3262 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
3256 @file (convenient for automagic users under Python >= 2.2).
3263 @file (convenient for automagic users under Python >= 2.2).
3257 Removed @files (it seemed more like a plural than an abbrev. of
3264 Removed @files (it seemed more like a plural than an abbrev. of
3258 'file show').
3265 'file show').
3259
3266
3260 * IPython/iplib.py (install_first_time): Fixed crash if there were
3267 * IPython/iplib.py (install_first_time): Fixed crash if there were
3261 backup files ('~') in .ipython/ install directory.
3268 backup files ('~') in .ipython/ install directory.
3262
3269
3263 * IPython/ipmaker.py (make_IPython): fixes for new prompt
3270 * IPython/ipmaker.py (make_IPython): fixes for new prompt
3264 system. Things look fine, but these changes are fairly
3271 system. Things look fine, but these changes are fairly
3265 intrusive. Test them for a few days.
3272 intrusive. Test them for a few days.
3266
3273
3267 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
3274 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
3268 the prompts system. Now all in/out prompt strings are user
3275 the prompts system. Now all in/out prompt strings are user
3269 controllable. This is particularly useful for embedding, as one
3276 controllable. This is particularly useful for embedding, as one
3270 can tag embedded instances with particular prompts.
3277 can tag embedded instances with particular prompts.
3271
3278
3272 Also removed global use of sys.ps1/2, which now allows nested
3279 Also removed global use of sys.ps1/2, which now allows nested
3273 embeddings without any problems. Added command-line options for
3280 embeddings without any problems. Added command-line options for
3274 the prompt strings.
3281 the prompt strings.
3275
3282
3276 2002-03-08 Fernando Perez <fperez@colorado.edu>
3283 2002-03-08 Fernando Perez <fperez@colorado.edu>
3277
3284
3278 * IPython/UserConfig/example-embed-short.py (ipshell): added
3285 * IPython/UserConfig/example-embed-short.py (ipshell): added
3279 example file with the bare minimum code for embedding.
3286 example file with the bare minimum code for embedding.
3280
3287
3281 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
3288 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
3282 functionality for the embeddable shell to be activated/deactivated
3289 functionality for the embeddable shell to be activated/deactivated
3283 either globally or at each call.
3290 either globally or at each call.
3284
3291
3285 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
3292 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
3286 rewriting the prompt with '--->' for auto-inputs with proper
3293 rewriting the prompt with '--->' for auto-inputs with proper
3287 coloring. Now the previous UGLY hack in handle_auto() is gone, and
3294 coloring. Now the previous UGLY hack in handle_auto() is gone, and
3288 this is handled by the prompts class itself, as it should.
3295 this is handled by the prompts class itself, as it should.
3289
3296
3290 2002-03-05 Fernando Perez <fperez@colorado.edu>
3297 2002-03-05 Fernando Perez <fperez@colorado.edu>
3291
3298
3292 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
3299 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
3293 @logstart to avoid name clashes with the math log function.
3300 @logstart to avoid name clashes with the math log function.
3294
3301
3295 * Big updates to X/Emacs section of the manual.
3302 * Big updates to X/Emacs section of the manual.
3296
3303
3297 * Removed ipython_emacs. Milan explained to me how to pass
3304 * Removed ipython_emacs. Milan explained to me how to pass
3298 arguments to ipython through Emacs. Some day I'm going to end up
3305 arguments to ipython through Emacs. Some day I'm going to end up
3299 learning some lisp...
3306 learning some lisp...
3300
3307
3301 2002-03-04 Fernando Perez <fperez@colorado.edu>
3308 2002-03-04 Fernando Perez <fperez@colorado.edu>
3302
3309
3303 * IPython/ipython_emacs: Created script to be used as the
3310 * IPython/ipython_emacs: Created script to be used as the
3304 py-python-command Emacs variable so we can pass IPython
3311 py-python-command Emacs variable so we can pass IPython
3305 parameters. I can't figure out how to tell Emacs directly to pass
3312 parameters. I can't figure out how to tell Emacs directly to pass
3306 parameters to IPython, so a dummy shell script will do it.
3313 parameters to IPython, so a dummy shell script will do it.
3307
3314
3308 Other enhancements made for things to work better under Emacs'
3315 Other enhancements made for things to work better under Emacs'
3309 various types of terminals. Many thanks to Milan Zamazal
3316 various types of terminals. Many thanks to Milan Zamazal
3310 <pdm-AT-zamazal.org> for all the suggestions and pointers.
3317 <pdm-AT-zamazal.org> for all the suggestions and pointers.
3311
3318
3312 2002-03-01 Fernando Perez <fperez@colorado.edu>
3319 2002-03-01 Fernando Perez <fperez@colorado.edu>
3313
3320
3314 * IPython/ipmaker.py (make_IPython): added a --readline! option so
3321 * IPython/ipmaker.py (make_IPython): added a --readline! option so
3315 that loading of readline is now optional. This gives better
3322 that loading of readline is now optional. This gives better
3316 control to emacs users.
3323 control to emacs users.
3317
3324
3318 * IPython/ultraTB.py (__date__): Modified color escape sequences
3325 * IPython/ultraTB.py (__date__): Modified color escape sequences
3319 and now things work fine under xterm and in Emacs' term buffers
3326 and now things work fine under xterm and in Emacs' term buffers
3320 (though not shell ones). Well, in emacs you get colors, but all
3327 (though not shell ones). Well, in emacs you get colors, but all
3321 seem to be 'light' colors (no difference between dark and light
3328 seem to be 'light' colors (no difference between dark and light
3322 ones). But the garbage chars are gone, and also in xterms. It
3329 ones). But the garbage chars are gone, and also in xterms. It
3323 seems that now I'm using 'cleaner' ansi sequences.
3330 seems that now I'm using 'cleaner' ansi sequences.
3324
3331
3325 2002-02-21 Fernando Perez <fperez@colorado.edu>
3332 2002-02-21 Fernando Perez <fperez@colorado.edu>
3326
3333
3327 * Released 0.2.7 (mainly to publish the scoping fix).
3334 * Released 0.2.7 (mainly to publish the scoping fix).
3328
3335
3329 * IPython/Logger.py (Logger.logstate): added. A corresponding
3336 * IPython/Logger.py (Logger.logstate): added. A corresponding
3330 @logstate magic was created.
3337 @logstate magic was created.
3331
3338
3332 * IPython/Magic.py: fixed nested scoping problem under Python
3339 * IPython/Magic.py: fixed nested scoping problem under Python
3333 2.1.x (automagic wasn't working).
3340 2.1.x (automagic wasn't working).
3334
3341
3335 2002-02-20 Fernando Perez <fperez@colorado.edu>
3342 2002-02-20 Fernando Perez <fperez@colorado.edu>
3336
3343
3337 * Released 0.2.6.
3344 * Released 0.2.6.
3338
3345
3339 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
3346 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
3340 option so that logs can come out without any headers at all.
3347 option so that logs can come out without any headers at all.
3341
3348
3342 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
3349 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
3343 SciPy.
3350 SciPy.
3344
3351
3345 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
3352 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
3346 that embedded IPython calls don't require vars() to be explicitly
3353 that embedded IPython calls don't require vars() to be explicitly
3347 passed. Now they are extracted from the caller's frame (code
3354 passed. Now they are extracted from the caller's frame (code
3348 snatched from Eric Jones' weave). Added better documentation to
3355 snatched from Eric Jones' weave). Added better documentation to
3349 the section on embedding and the example file.
3356 the section on embedding and the example file.
3350
3357
3351 * IPython/genutils.py (page): Changed so that under emacs, it just
3358 * IPython/genutils.py (page): Changed so that under emacs, it just
3352 prints the string. You can then page up and down in the emacs
3359 prints the string. You can then page up and down in the emacs
3353 buffer itself. This is how the builtin help() works.
3360 buffer itself. This is how the builtin help() works.
3354
3361
3355 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
3362 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
3356 macro scoping: macros need to be executed in the user's namespace
3363 macro scoping: macros need to be executed in the user's namespace
3357 to work as if they had been typed by the user.
3364 to work as if they had been typed by the user.
3358
3365
3359 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
3366 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
3360 execute automatically (no need to type 'exec...'). They then
3367 execute automatically (no need to type 'exec...'). They then
3361 behave like 'true macros'. The printing system was also modified
3368 behave like 'true macros'. The printing system was also modified
3362 for this to work.
3369 for this to work.
3363
3370
3364 2002-02-19 Fernando Perez <fperez@colorado.edu>
3371 2002-02-19 Fernando Perez <fperez@colorado.edu>
3365
3372
3366 * IPython/genutils.py (page_file): new function for paging files
3373 * IPython/genutils.py (page_file): new function for paging files
3367 in an OS-independent way. Also necessary for file viewing to work
3374 in an OS-independent way. Also necessary for file viewing to work
3368 well inside Emacs buffers.
3375 well inside Emacs buffers.
3369 (page): Added checks for being in an emacs buffer.
3376 (page): Added checks for being in an emacs buffer.
3370 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
3377 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
3371 same bug in iplib.
3378 same bug in iplib.
3372
3379
3373 2002-02-18 Fernando Perez <fperez@colorado.edu>
3380 2002-02-18 Fernando Perez <fperez@colorado.edu>
3374
3381
3375 * IPython/iplib.py (InteractiveShell.init_readline): modified use
3382 * IPython/iplib.py (InteractiveShell.init_readline): modified use
3376 of readline so that IPython can work inside an Emacs buffer.
3383 of readline so that IPython can work inside an Emacs buffer.
3377
3384
3378 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
3385 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
3379 method signatures (they weren't really bugs, but it looks cleaner
3386 method signatures (they weren't really bugs, but it looks cleaner
3380 and keeps PyChecker happy).
3387 and keeps PyChecker happy).
3381
3388
3382 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
3389 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
3383 for implementing various user-defined hooks. Currently only
3390 for implementing various user-defined hooks. Currently only
3384 display is done.
3391 display is done.
3385
3392
3386 * IPython/Prompts.py (CachedOutput._display): changed display
3393 * IPython/Prompts.py (CachedOutput._display): changed display
3387 functions so that they can be dynamically changed by users easily.
3394 functions so that they can be dynamically changed by users easily.
3388
3395
3389 * IPython/Extensions/numeric_formats.py (num_display): added an
3396 * IPython/Extensions/numeric_formats.py (num_display): added an
3390 extension for printing NumPy arrays in flexible manners. It
3397 extension for printing NumPy arrays in flexible manners. It
3391 doesn't do anything yet, but all the structure is in
3398 doesn't do anything yet, but all the structure is in
3392 place. Ultimately the plan is to implement output format control
3399 place. Ultimately the plan is to implement output format control
3393 like in Octave.
3400 like in Octave.
3394
3401
3395 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
3402 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
3396 methods are found at run-time by all the automatic machinery.
3403 methods are found at run-time by all the automatic machinery.
3397
3404
3398 2002-02-17 Fernando Perez <fperez@colorado.edu>
3405 2002-02-17 Fernando Perez <fperez@colorado.edu>
3399
3406
3400 * setup_Windows.py (make_shortcut): documented. Cleaned up the
3407 * setup_Windows.py (make_shortcut): documented. Cleaned up the
3401 whole file a little.
3408 whole file a little.
3402
3409
3403 * ToDo: closed this document. Now there's a new_design.lyx
3410 * ToDo: closed this document. Now there's a new_design.lyx
3404 document for all new ideas. Added making a pdf of it for the
3411 document for all new ideas. Added making a pdf of it for the
3405 end-user distro.
3412 end-user distro.
3406
3413
3407 * IPython/Logger.py (Logger.switch_log): Created this to replace
3414 * IPython/Logger.py (Logger.switch_log): Created this to replace
3408 logon() and logoff(). It also fixes a nasty crash reported by
3415 logon() and logoff(). It also fixes a nasty crash reported by
3409 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
3416 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
3410
3417
3411 * IPython/iplib.py (complete): got auto-completion to work with
3418 * IPython/iplib.py (complete): got auto-completion to work with
3412 automagic (I had wanted this for a long time).
3419 automagic (I had wanted this for a long time).
3413
3420
3414 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
3421 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
3415 to @file, since file() is now a builtin and clashes with automagic
3422 to @file, since file() is now a builtin and clashes with automagic
3416 for @file.
3423 for @file.
3417
3424
3418 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
3425 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
3419 of this was previously in iplib, which had grown to more than 2000
3426 of this was previously in iplib, which had grown to more than 2000
3420 lines, way too long. No new functionality, but it makes managing
3427 lines, way too long. No new functionality, but it makes managing
3421 the code a bit easier.
3428 the code a bit easier.
3422
3429
3423 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
3430 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
3424 information to crash reports.
3431 information to crash reports.
3425
3432
3426 2002-02-12 Fernando Perez <fperez@colorado.edu>
3433 2002-02-12 Fernando Perez <fperez@colorado.edu>
3427
3434
3428 * Released 0.2.5.
3435 * Released 0.2.5.
3429
3436
3430 2002-02-11 Fernando Perez <fperez@colorado.edu>
3437 2002-02-11 Fernando Perez <fperez@colorado.edu>
3431
3438
3432 * Wrote a relatively complete Windows installer. It puts
3439 * Wrote a relatively complete Windows installer. It puts
3433 everything in place, creates Start Menu entries and fixes the
3440 everything in place, creates Start Menu entries and fixes the
3434 color issues. Nothing fancy, but it works.
3441 color issues. Nothing fancy, but it works.
3435
3442
3436 2002-02-10 Fernando Perez <fperez@colorado.edu>
3443 2002-02-10 Fernando Perez <fperez@colorado.edu>
3437
3444
3438 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
3445 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
3439 os.path.expanduser() call so that we can type @run ~/myfile.py and
3446 os.path.expanduser() call so that we can type @run ~/myfile.py and
3440 have thigs work as expected.
3447 have thigs work as expected.
3441
3448
3442 * IPython/genutils.py (page): fixed exception handling so things
3449 * IPython/genutils.py (page): fixed exception handling so things
3443 work both in Unix and Windows correctly. Quitting a pager triggers
3450 work both in Unix and Windows correctly. Quitting a pager triggers
3444 an IOError/broken pipe in Unix, and in windows not finding a pager
3451 an IOError/broken pipe in Unix, and in windows not finding a pager
3445 is also an IOError, so I had to actually look at the return value
3452 is also an IOError, so I had to actually look at the return value
3446 of the exception, not just the exception itself. Should be ok now.
3453 of the exception, not just the exception itself. Should be ok now.
3447
3454
3448 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
3455 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
3449 modified to allow case-insensitive color scheme changes.
3456 modified to allow case-insensitive color scheme changes.
3450
3457
3451 2002-02-09 Fernando Perez <fperez@colorado.edu>
3458 2002-02-09 Fernando Perez <fperez@colorado.edu>
3452
3459
3453 * IPython/genutils.py (native_line_ends): new function to leave
3460 * IPython/genutils.py (native_line_ends): new function to leave
3454 user config files with os-native line-endings.
3461 user config files with os-native line-endings.
3455
3462
3456 * README and manual updates.
3463 * README and manual updates.
3457
3464
3458 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
3465 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
3459 instead of StringType to catch Unicode strings.
3466 instead of StringType to catch Unicode strings.
3460
3467
3461 * IPython/genutils.py (filefind): fixed bug for paths with
3468 * IPython/genutils.py (filefind): fixed bug for paths with
3462 embedded spaces (very common in Windows).
3469 embedded spaces (very common in Windows).
3463
3470
3464 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
3471 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
3465 files under Windows, so that they get automatically associated
3472 files under Windows, so that they get automatically associated
3466 with a text editor. Windows makes it a pain to handle
3473 with a text editor. Windows makes it a pain to handle
3467 extension-less files.
3474 extension-less files.
3468
3475
3469 * IPython/iplib.py (InteractiveShell.init_readline): Made the
3476 * IPython/iplib.py (InteractiveShell.init_readline): Made the
3470 warning about readline only occur for Posix. In Windows there's no
3477 warning about readline only occur for Posix. In Windows there's no
3471 way to get readline, so why bother with the warning.
3478 way to get readline, so why bother with the warning.
3472
3479
3473 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
3480 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
3474 for __str__ instead of dir(self), since dir() changed in 2.2.
3481 for __str__ instead of dir(self), since dir() changed in 2.2.
3475
3482
3476 * Ported to Windows! Tested on XP, I suspect it should work fine
3483 * Ported to Windows! Tested on XP, I suspect it should work fine
3477 on NT/2000, but I don't think it will work on 98 et al. That
3484 on NT/2000, but I don't think it will work on 98 et al. That
3478 series of Windows is such a piece of junk anyway that I won't try
3485 series of Windows is such a piece of junk anyway that I won't try
3479 porting it there. The XP port was straightforward, showed a few
3486 porting it there. The XP port was straightforward, showed a few
3480 bugs here and there (fixed all), in particular some string
3487 bugs here and there (fixed all), in particular some string
3481 handling stuff which required considering Unicode strings (which
3488 handling stuff which required considering Unicode strings (which
3482 Windows uses). This is good, but hasn't been too tested :) No
3489 Windows uses). This is good, but hasn't been too tested :) No
3483 fancy installer yet, I'll put a note in the manual so people at
3490 fancy installer yet, I'll put a note in the manual so people at
3484 least make manually a shortcut.
3491 least make manually a shortcut.
3485
3492
3486 * IPython/iplib.py (Magic.magic_colors): Unified the color options
3493 * IPython/iplib.py (Magic.magic_colors): Unified the color options
3487 into a single one, "colors". This now controls both prompt and
3494 into a single one, "colors". This now controls both prompt and
3488 exception color schemes, and can be changed both at startup
3495 exception color schemes, and can be changed both at startup
3489 (either via command-line switches or via ipythonrc files) and at
3496 (either via command-line switches or via ipythonrc files) and at
3490 runtime, with @colors.
3497 runtime, with @colors.
3491 (Magic.magic_run): renamed @prun to @run and removed the old
3498 (Magic.magic_run): renamed @prun to @run and removed the old
3492 @run. The two were too similar to warrant keeping both.
3499 @run. The two were too similar to warrant keeping both.
3493
3500
3494 2002-02-03 Fernando Perez <fperez@colorado.edu>
3501 2002-02-03 Fernando Perez <fperez@colorado.edu>
3495
3502
3496 * IPython/iplib.py (install_first_time): Added comment on how to
3503 * IPython/iplib.py (install_first_time): Added comment on how to
3497 configure the color options for first-time users. Put a <return>
3504 configure the color options for first-time users. Put a <return>
3498 request at the end so that small-terminal users get a chance to
3505 request at the end so that small-terminal users get a chance to
3499 read the startup info.
3506 read the startup info.
3500
3507
3501 2002-01-23 Fernando Perez <fperez@colorado.edu>
3508 2002-01-23 Fernando Perez <fperez@colorado.edu>
3502
3509
3503 * IPython/iplib.py (CachedOutput.update): Changed output memory
3510 * IPython/iplib.py (CachedOutput.update): Changed output memory
3504 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
3511 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
3505 input history we still use _i. Did this b/c these variable are
3512 input history we still use _i. Did this b/c these variable are
3506 very commonly used in interactive work, so the less we need to
3513 very commonly used in interactive work, so the less we need to
3507 type the better off we are.
3514 type the better off we are.
3508 (Magic.magic_prun): updated @prun to better handle the namespaces
3515 (Magic.magic_prun): updated @prun to better handle the namespaces
3509 the file will run in, including a fix for __name__ not being set
3516 the file will run in, including a fix for __name__ not being set
3510 before.
3517 before.
3511
3518
3512 2002-01-20 Fernando Perez <fperez@colorado.edu>
3519 2002-01-20 Fernando Perez <fperez@colorado.edu>
3513
3520
3514 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
3521 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
3515 extra garbage for Python 2.2. Need to look more carefully into
3522 extra garbage for Python 2.2. Need to look more carefully into
3516 this later.
3523 this later.
3517
3524
3518 2002-01-19 Fernando Perez <fperez@colorado.edu>
3525 2002-01-19 Fernando Perez <fperez@colorado.edu>
3519
3526
3520 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
3527 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
3521 display SyntaxError exceptions properly formatted when they occur
3528 display SyntaxError exceptions properly formatted when they occur
3522 (they can be triggered by imported code).
3529 (they can be triggered by imported code).
3523
3530
3524 2002-01-18 Fernando Perez <fperez@colorado.edu>
3531 2002-01-18 Fernando Perez <fperez@colorado.edu>
3525
3532
3526 * IPython/iplib.py (InteractiveShell.safe_execfile): now
3533 * IPython/iplib.py (InteractiveShell.safe_execfile): now
3527 SyntaxError exceptions are reported nicely formatted, instead of
3534 SyntaxError exceptions are reported nicely formatted, instead of
3528 spitting out only offset information as before.
3535 spitting out only offset information as before.
3529 (Magic.magic_prun): Added the @prun function for executing
3536 (Magic.magic_prun): Added the @prun function for executing
3530 programs with command line args inside IPython.
3537 programs with command line args inside IPython.
3531
3538
3532 2002-01-16 Fernando Perez <fperez@colorado.edu>
3539 2002-01-16 Fernando Perez <fperez@colorado.edu>
3533
3540
3534 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
3541 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
3535 to *not* include the last item given in a range. This brings their
3542 to *not* include the last item given in a range. This brings their
3536 behavior in line with Python's slicing:
3543 behavior in line with Python's slicing:
3537 a[n1:n2] -> a[n1]...a[n2-1]
3544 a[n1:n2] -> a[n1]...a[n2-1]
3538 It may be a bit less convenient, but I prefer to stick to Python's
3545 It may be a bit less convenient, but I prefer to stick to Python's
3539 conventions *everywhere*, so users never have to wonder.
3546 conventions *everywhere*, so users never have to wonder.
3540 (Magic.magic_macro): Added @macro function to ease the creation of
3547 (Magic.magic_macro): Added @macro function to ease the creation of
3541 macros.
3548 macros.
3542
3549
3543 2002-01-05 Fernando Perez <fperez@colorado.edu>
3550 2002-01-05 Fernando Perez <fperez@colorado.edu>
3544
3551
3545 * Released 0.2.4.
3552 * Released 0.2.4.
3546
3553
3547 * IPython/iplib.py (Magic.magic_pdef):
3554 * IPython/iplib.py (Magic.magic_pdef):
3548 (InteractiveShell.safe_execfile): report magic lines and error
3555 (InteractiveShell.safe_execfile): report magic lines and error
3549 lines without line numbers so one can easily copy/paste them for
3556 lines without line numbers so one can easily copy/paste them for
3550 re-execution.
3557 re-execution.
3551
3558
3552 * Updated manual with recent changes.
3559 * Updated manual with recent changes.
3553
3560
3554 * IPython/iplib.py (Magic.magic_oinfo): added constructor
3561 * IPython/iplib.py (Magic.magic_oinfo): added constructor
3555 docstring printing when class? is called. Very handy for knowing
3562 docstring printing when class? is called. Very handy for knowing
3556 how to create class instances (as long as __init__ is well
3563 how to create class instances (as long as __init__ is well
3557 documented, of course :)
3564 documented, of course :)
3558 (Magic.magic_doc): print both class and constructor docstrings.
3565 (Magic.magic_doc): print both class and constructor docstrings.
3559 (Magic.magic_pdef): give constructor info if passed a class and
3566 (Magic.magic_pdef): give constructor info if passed a class and
3560 __call__ info for callable object instances.
3567 __call__ info for callable object instances.
3561
3568
3562 2002-01-04 Fernando Perez <fperez@colorado.edu>
3569 2002-01-04 Fernando Perez <fperez@colorado.edu>
3563
3570
3564 * Made deep_reload() off by default. It doesn't always work
3571 * Made deep_reload() off by default. It doesn't always work
3565 exactly as intended, so it's probably safer to have it off. It's
3572 exactly as intended, so it's probably safer to have it off. It's
3566 still available as dreload() anyway, so nothing is lost.
3573 still available as dreload() anyway, so nothing is lost.
3567
3574
3568 2002-01-02 Fernando Perez <fperez@colorado.edu>
3575 2002-01-02 Fernando Perez <fperez@colorado.edu>
3569
3576
3570 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
3577 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
3571 so I wanted an updated release).
3578 so I wanted an updated release).
3572
3579
3573 2001-12-27 Fernando Perez <fperez@colorado.edu>
3580 2001-12-27 Fernando Perez <fperez@colorado.edu>
3574
3581
3575 * IPython/iplib.py (InteractiveShell.interact): Added the original
3582 * IPython/iplib.py (InteractiveShell.interact): Added the original
3576 code from 'code.py' for this module in order to change the
3583 code from 'code.py' for this module in order to change the
3577 handling of a KeyboardInterrupt. This was necessary b/c otherwise
3584 handling of a KeyboardInterrupt. This was necessary b/c otherwise
3578 the history cache would break when the user hit Ctrl-C, and
3585 the history cache would break when the user hit Ctrl-C, and
3579 interact() offers no way to add any hooks to it.
3586 interact() offers no way to add any hooks to it.
3580
3587
3581 2001-12-23 Fernando Perez <fperez@colorado.edu>
3588 2001-12-23 Fernando Perez <fperez@colorado.edu>
3582
3589
3583 * setup.py: added check for 'MANIFEST' before trying to remove
3590 * setup.py: added check for 'MANIFEST' before trying to remove
3584 it. Thanks to Sean Reifschneider.
3591 it. Thanks to Sean Reifschneider.
3585
3592
3586 2001-12-22 Fernando Perez <fperez@colorado.edu>
3593 2001-12-22 Fernando Perez <fperez@colorado.edu>
3587
3594
3588 * Released 0.2.2.
3595 * Released 0.2.2.
3589
3596
3590 * Finished (reasonably) writing the manual. Later will add the
3597 * Finished (reasonably) writing the manual. Later will add the
3591 python-standard navigation stylesheets, but for the time being
3598 python-standard navigation stylesheets, but for the time being
3592 it's fairly complete. Distribution will include html and pdf
3599 it's fairly complete. Distribution will include html and pdf
3593 versions.
3600 versions.
3594
3601
3595 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
3602 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
3596 (MayaVi author).
3603 (MayaVi author).
3597
3604
3598 2001-12-21 Fernando Perez <fperez@colorado.edu>
3605 2001-12-21 Fernando Perez <fperez@colorado.edu>
3599
3606
3600 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
3607 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
3601 good public release, I think (with the manual and the distutils
3608 good public release, I think (with the manual and the distutils
3602 installer). The manual can use some work, but that can go
3609 installer). The manual can use some work, but that can go
3603 slowly. Otherwise I think it's quite nice for end users. Next
3610 slowly. Otherwise I think it's quite nice for end users. Next
3604 summer, rewrite the guts of it...
3611 summer, rewrite the guts of it...
3605
3612
3606 * Changed format of ipythonrc files to use whitespace as the
3613 * Changed format of ipythonrc files to use whitespace as the
3607 separator instead of an explicit '='. Cleaner.
3614 separator instead of an explicit '='. Cleaner.
3608
3615
3609 2001-12-20 Fernando Perez <fperez@colorado.edu>
3616 2001-12-20 Fernando Perez <fperez@colorado.edu>
3610
3617
3611 * Started a manual in LyX. For now it's just a quick merge of the
3618 * Started a manual in LyX. For now it's just a quick merge of the
3612 various internal docstrings and READMEs. Later it may grow into a
3619 various internal docstrings and READMEs. Later it may grow into a
3613 nice, full-blown manual.
3620 nice, full-blown manual.
3614
3621
3615 * Set up a distutils based installer. Installation should now be
3622 * Set up a distutils based installer. Installation should now be
3616 trivially simple for end-users.
3623 trivially simple for end-users.
3617
3624
3618 2001-12-11 Fernando Perez <fperez@colorado.edu>
3625 2001-12-11 Fernando Perez <fperez@colorado.edu>
3619
3626
3620 * Released 0.2.0. First public release, announced it at
3627 * Released 0.2.0. First public release, announced it at
3621 comp.lang.python. From now on, just bugfixes...
3628 comp.lang.python. From now on, just bugfixes...
3622
3629
3623 * Went through all the files, set copyright/license notices and
3630 * Went through all the files, set copyright/license notices and
3624 cleaned up things. Ready for release.
3631 cleaned up things. Ready for release.
3625
3632
3626 2001-12-10 Fernando Perez <fperez@colorado.edu>
3633 2001-12-10 Fernando Perez <fperez@colorado.edu>
3627
3634
3628 * Changed the first-time installer not to use tarfiles. It's more
3635 * Changed the first-time installer not to use tarfiles. It's more
3629 robust now and less unix-dependent. Also makes it easier for
3636 robust now and less unix-dependent. Also makes it easier for
3630 people to later upgrade versions.
3637 people to later upgrade versions.
3631
3638
3632 * Changed @exit to @abort to reflect the fact that it's pretty
3639 * Changed @exit to @abort to reflect the fact that it's pretty
3633 brutal (a sys.exit()). The difference between @abort and Ctrl-D
3640 brutal (a sys.exit()). The difference between @abort and Ctrl-D
3634 becomes significant only when IPyhton is embedded: in that case,
3641 becomes significant only when IPyhton is embedded: in that case,
3635 C-D closes IPython only, but @abort kills the enclosing program
3642 C-D closes IPython only, but @abort kills the enclosing program
3636 too (unless it had called IPython inside a try catching
3643 too (unless it had called IPython inside a try catching
3637 SystemExit).
3644 SystemExit).
3638
3645
3639 * Created Shell module which exposes the actuall IPython Shell
3646 * Created Shell module which exposes the actuall IPython Shell
3640 classes, currently the normal and the embeddable one. This at
3647 classes, currently the normal and the embeddable one. This at
3641 least offers a stable interface we won't need to change when
3648 least offers a stable interface we won't need to change when
3642 (later) the internals are rewritten. That rewrite will be confined
3649 (later) the internals are rewritten. That rewrite will be confined
3643 to iplib and ipmaker, but the Shell interface should remain as is.
3650 to iplib and ipmaker, but the Shell interface should remain as is.
3644
3651
3645 * Added embed module which offers an embeddable IPShell object,
3652 * Added embed module which offers an embeddable IPShell object,
3646 useful to fire up IPython *inside* a running program. Great for
3653 useful to fire up IPython *inside* a running program. Great for
3647 debugging or dynamical data analysis.
3654 debugging or dynamical data analysis.
3648
3655
3649 2001-12-08 Fernando Perez <fperez@colorado.edu>
3656 2001-12-08 Fernando Perez <fperez@colorado.edu>
3650
3657
3651 * Fixed small bug preventing seeing info from methods of defined
3658 * Fixed small bug preventing seeing info from methods of defined
3652 objects (incorrect namespace in _ofind()).
3659 objects (incorrect namespace in _ofind()).
3653
3660
3654 * Documentation cleanup. Moved the main usage docstrings to a
3661 * Documentation cleanup. Moved the main usage docstrings to a
3655 separate file, usage.py (cleaner to maintain, and hopefully in the
3662 separate file, usage.py (cleaner to maintain, and hopefully in the
3656 future some perlpod-like way of producing interactive, man and
3663 future some perlpod-like way of producing interactive, man and
3657 html docs out of it will be found).
3664 html docs out of it will be found).
3658
3665
3659 * Added @profile to see your profile at any time.
3666 * Added @profile to see your profile at any time.
3660
3667
3661 * Added @p as an alias for 'print'. It's especially convenient if
3668 * Added @p as an alias for 'print'. It's especially convenient if
3662 using automagic ('p x' prints x).
3669 using automagic ('p x' prints x).
3663
3670
3664 * Small cleanups and fixes after a pychecker run.
3671 * Small cleanups and fixes after a pychecker run.
3665
3672
3666 * Changed the @cd command to handle @cd - and @cd -<n> for
3673 * Changed the @cd command to handle @cd - and @cd -<n> for
3667 visiting any directory in _dh.
3674 visiting any directory in _dh.
3668
3675
3669 * Introduced _dh, a history of visited directories. @dhist prints
3676 * Introduced _dh, a history of visited directories. @dhist prints
3670 it out with numbers.
3677 it out with numbers.
3671
3678
3672 2001-12-07 Fernando Perez <fperez@colorado.edu>
3679 2001-12-07 Fernando Perez <fperez@colorado.edu>
3673
3680
3674 * Released 0.1.22
3681 * Released 0.1.22
3675
3682
3676 * Made initialization a bit more robust against invalid color
3683 * Made initialization a bit more robust against invalid color
3677 options in user input (exit, not traceback-crash).
3684 options in user input (exit, not traceback-crash).
3678
3685
3679 * Changed the bug crash reporter to write the report only in the
3686 * Changed the bug crash reporter to write the report only in the
3680 user's .ipython directory. That way IPython won't litter people's
3687 user's .ipython directory. That way IPython won't litter people's
3681 hard disks with crash files all over the place. Also print on
3688 hard disks with crash files all over the place. Also print on
3682 screen the necessary mail command.
3689 screen the necessary mail command.
3683
3690
3684 * With the new ultraTB, implemented LightBG color scheme for light
3691 * With the new ultraTB, implemented LightBG color scheme for light
3685 background terminals. A lot of people like white backgrounds, so I
3692 background terminals. A lot of people like white backgrounds, so I
3686 guess we should at least give them something readable.
3693 guess we should at least give them something readable.
3687
3694
3688 2001-12-06 Fernando Perez <fperez@colorado.edu>
3695 2001-12-06 Fernando Perez <fperez@colorado.edu>
3689
3696
3690 * Modified the structure of ultraTB. Now there's a proper class
3697 * Modified the structure of ultraTB. Now there's a proper class
3691 for tables of color schemes which allow adding schemes easily and
3698 for tables of color schemes which allow adding schemes easily and
3692 switching the active scheme without creating a new instance every
3699 switching the active scheme without creating a new instance every
3693 time (which was ridiculous). The syntax for creating new schemes
3700 time (which was ridiculous). The syntax for creating new schemes
3694 is also cleaner. I think ultraTB is finally done, with a clean
3701 is also cleaner. I think ultraTB is finally done, with a clean
3695 class structure. Names are also much cleaner (now there's proper
3702 class structure. Names are also much cleaner (now there's proper
3696 color tables, no need for every variable to also have 'color' in
3703 color tables, no need for every variable to also have 'color' in
3697 its name).
3704 its name).
3698
3705
3699 * Broke down genutils into separate files. Now genutils only
3706 * Broke down genutils into separate files. Now genutils only
3700 contains utility functions, and classes have been moved to their
3707 contains utility functions, and classes have been moved to their
3701 own files (they had enough independent functionality to warrant
3708 own files (they had enough independent functionality to warrant
3702 it): ConfigLoader, OutputTrap, Struct.
3709 it): ConfigLoader, OutputTrap, Struct.
3703
3710
3704 2001-12-05 Fernando Perez <fperez@colorado.edu>
3711 2001-12-05 Fernando Perez <fperez@colorado.edu>
3705
3712
3706 * IPython turns 21! Released version 0.1.21, as a candidate for
3713 * IPython turns 21! Released version 0.1.21, as a candidate for
3707 public consumption. If all goes well, release in a few days.
3714 public consumption. If all goes well, release in a few days.
3708
3715
3709 * Fixed path bug (files in Extensions/ directory wouldn't be found
3716 * Fixed path bug (files in Extensions/ directory wouldn't be found
3710 unless IPython/ was explicitly in sys.path).
3717 unless IPython/ was explicitly in sys.path).
3711
3718
3712 * Extended the FlexCompleter class as MagicCompleter to allow
3719 * Extended the FlexCompleter class as MagicCompleter to allow
3713 completion of @-starting lines.
3720 completion of @-starting lines.
3714
3721
3715 * Created __release__.py file as a central repository for release
3722 * Created __release__.py file as a central repository for release
3716 info that other files can read from.
3723 info that other files can read from.
3717
3724
3718 * Fixed small bug in logging: when logging was turned on in
3725 * Fixed small bug in logging: when logging was turned on in
3719 mid-session, old lines with special meanings (!@?) were being
3726 mid-session, old lines with special meanings (!@?) were being
3720 logged without the prepended comment, which is necessary since
3727 logged without the prepended comment, which is necessary since
3721 they are not truly valid python syntax. This should make session
3728 they are not truly valid python syntax. This should make session
3722 restores produce less errors.
3729 restores produce less errors.
3723
3730
3724 * The namespace cleanup forced me to make a FlexCompleter class
3731 * The namespace cleanup forced me to make a FlexCompleter class
3725 which is nothing but a ripoff of rlcompleter, but with selectable
3732 which is nothing but a ripoff of rlcompleter, but with selectable
3726 namespace (rlcompleter only works in __main__.__dict__). I'll try
3733 namespace (rlcompleter only works in __main__.__dict__). I'll try
3727 to submit a note to the authors to see if this change can be
3734 to submit a note to the authors to see if this change can be
3728 incorporated in future rlcompleter releases (Dec.6: done)
3735 incorporated in future rlcompleter releases (Dec.6: done)
3729
3736
3730 * More fixes to namespace handling. It was a mess! Now all
3737 * More fixes to namespace handling. It was a mess! Now all
3731 explicit references to __main__.__dict__ are gone (except when
3738 explicit references to __main__.__dict__ are gone (except when
3732 really needed) and everything is handled through the namespace
3739 really needed) and everything is handled through the namespace
3733 dicts in the IPython instance. We seem to be getting somewhere
3740 dicts in the IPython instance. We seem to be getting somewhere
3734 with this, finally...
3741 with this, finally...
3735
3742
3736 * Small documentation updates.
3743 * Small documentation updates.
3737
3744
3738 * Created the Extensions directory under IPython (with an
3745 * Created the Extensions directory under IPython (with an
3739 __init__.py). Put the PhysicalQ stuff there. This directory should
3746 __init__.py). Put the PhysicalQ stuff there. This directory should
3740 be used for all special-purpose extensions.
3747 be used for all special-purpose extensions.
3741
3748
3742 * File renaming:
3749 * File renaming:
3743 ipythonlib --> ipmaker
3750 ipythonlib --> ipmaker
3744 ipplib --> iplib
3751 ipplib --> iplib
3745 This makes a bit more sense in terms of what these files actually do.
3752 This makes a bit more sense in terms of what these files actually do.
3746
3753
3747 * Moved all the classes and functions in ipythonlib to ipplib, so
3754 * Moved all the classes and functions in ipythonlib to ipplib, so
3748 now ipythonlib only has make_IPython(). This will ease up its
3755 now ipythonlib only has make_IPython(). This will ease up its
3749 splitting in smaller functional chunks later.
3756 splitting in smaller functional chunks later.
3750
3757
3751 * Cleaned up (done, I think) output of @whos. Better column
3758 * Cleaned up (done, I think) output of @whos. Better column
3752 formatting, and now shows str(var) for as much as it can, which is
3759 formatting, and now shows str(var) for as much as it can, which is
3753 typically what one gets with a 'print var'.
3760 typically what one gets with a 'print var'.
3754
3761
3755 2001-12-04 Fernando Perez <fperez@colorado.edu>
3762 2001-12-04 Fernando Perez <fperez@colorado.edu>
3756
3763
3757 * Fixed namespace problems. Now builtin/IPyhton/user names get
3764 * Fixed namespace problems. Now builtin/IPyhton/user names get
3758 properly reported in their namespace. Internal namespace handling
3765 properly reported in their namespace. Internal namespace handling
3759 is finally getting decent (not perfect yet, but much better than
3766 is finally getting decent (not perfect yet, but much better than
3760 the ad-hoc mess we had).
3767 the ad-hoc mess we had).
3761
3768
3762 * Removed -exit option. If people just want to run a python
3769 * Removed -exit option. If people just want to run a python
3763 script, that's what the normal interpreter is for. Less
3770 script, that's what the normal interpreter is for. Less
3764 unnecessary options, less chances for bugs.
3771 unnecessary options, less chances for bugs.
3765
3772
3766 * Added a crash handler which generates a complete post-mortem if
3773 * Added a crash handler which generates a complete post-mortem if
3767 IPython crashes. This will help a lot in tracking bugs down the
3774 IPython crashes. This will help a lot in tracking bugs down the
3768 road.
3775 road.
3769
3776
3770 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
3777 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
3771 which were boud to functions being reassigned would bypass the
3778 which were boud to functions being reassigned would bypass the
3772 logger, breaking the sync of _il with the prompt counter. This
3779 logger, breaking the sync of _il with the prompt counter. This
3773 would then crash IPython later when a new line was logged.
3780 would then crash IPython later when a new line was logged.
3774
3781
3775 2001-12-02 Fernando Perez <fperez@colorado.edu>
3782 2001-12-02 Fernando Perez <fperez@colorado.edu>
3776
3783
3777 * Made IPython a package. This means people don't have to clutter
3784 * Made IPython a package. This means people don't have to clutter
3778 their sys.path with yet another directory. Changed the INSTALL
3785 their sys.path with yet another directory. Changed the INSTALL
3779 file accordingly.
3786 file accordingly.
3780
3787
3781 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
3788 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
3782 sorts its output (so @who shows it sorted) and @whos formats the
3789 sorts its output (so @who shows it sorted) and @whos formats the
3783 table according to the width of the first column. Nicer, easier to
3790 table according to the width of the first column. Nicer, easier to
3784 read. Todo: write a generic table_format() which takes a list of
3791 read. Todo: write a generic table_format() which takes a list of
3785 lists and prints it nicely formatted, with optional row/column
3792 lists and prints it nicely formatted, with optional row/column
3786 separators and proper padding and justification.
3793 separators and proper padding and justification.
3787
3794
3788 * Released 0.1.20
3795 * Released 0.1.20
3789
3796
3790 * Fixed bug in @log which would reverse the inputcache list (a
3797 * Fixed bug in @log which would reverse the inputcache list (a
3791 copy operation was missing).
3798 copy operation was missing).
3792
3799
3793 * Code cleanup. @config was changed to use page(). Better, since
3800 * Code cleanup. @config was changed to use page(). Better, since
3794 its output is always quite long.
3801 its output is always quite long.
3795
3802
3796 * Itpl is back as a dependency. I was having too many problems
3803 * Itpl is back as a dependency. I was having too many problems
3797 getting the parametric aliases to work reliably, and it's just
3804 getting the parametric aliases to work reliably, and it's just
3798 easier to code weird string operations with it than playing %()s
3805 easier to code weird string operations with it than playing %()s
3799 games. It's only ~6k, so I don't think it's too big a deal.
3806 games. It's only ~6k, so I don't think it's too big a deal.
3800
3807
3801 * Found (and fixed) a very nasty bug with history. !lines weren't
3808 * Found (and fixed) a very nasty bug with history. !lines weren't
3802 getting cached, and the out of sync caches would crash
3809 getting cached, and the out of sync caches would crash
3803 IPython. Fixed it by reorganizing the prefilter/handlers/logger
3810 IPython. Fixed it by reorganizing the prefilter/handlers/logger
3804 division of labor a bit better. Bug fixed, cleaner structure.
3811 division of labor a bit better. Bug fixed, cleaner structure.
3805
3812
3806 2001-12-01 Fernando Perez <fperez@colorado.edu>
3813 2001-12-01 Fernando Perez <fperez@colorado.edu>
3807
3814
3808 * Released 0.1.19
3815 * Released 0.1.19
3809
3816
3810 * Added option -n to @hist to prevent line number printing. Much
3817 * Added option -n to @hist to prevent line number printing. Much
3811 easier to copy/paste code this way.
3818 easier to copy/paste code this way.
3812
3819
3813 * Created global _il to hold the input list. Allows easy
3820 * Created global _il to hold the input list. Allows easy
3814 re-execution of blocks of code by slicing it (inspired by Janko's
3821 re-execution of blocks of code by slicing it (inspired by Janko's
3815 comment on 'macros').
3822 comment on 'macros').
3816
3823
3817 * Small fixes and doc updates.
3824 * Small fixes and doc updates.
3818
3825
3819 * Rewrote @history function (was @h). Renamed it to @hist, @h is
3826 * Rewrote @history function (was @h). Renamed it to @hist, @h is
3820 much too fragile with automagic. Handles properly multi-line
3827 much too fragile with automagic. Handles properly multi-line
3821 statements and takes parameters.
3828 statements and takes parameters.
3822
3829
3823 2001-11-30 Fernando Perez <fperez@colorado.edu>
3830 2001-11-30 Fernando Perez <fperez@colorado.edu>
3824
3831
3825 * Version 0.1.18 released.
3832 * Version 0.1.18 released.
3826
3833
3827 * Fixed nasty namespace bug in initial module imports.
3834 * Fixed nasty namespace bug in initial module imports.
3828
3835
3829 * Added copyright/license notes to all code files (except
3836 * Added copyright/license notes to all code files (except
3830 DPyGetOpt). For the time being, LGPL. That could change.
3837 DPyGetOpt). For the time being, LGPL. That could change.
3831
3838
3832 * Rewrote a much nicer README, updated INSTALL, cleaned up
3839 * Rewrote a much nicer README, updated INSTALL, cleaned up
3833 ipythonrc-* samples.
3840 ipythonrc-* samples.
3834
3841
3835 * Overall code/documentation cleanup. Basically ready for
3842 * Overall code/documentation cleanup. Basically ready for
3836 release. Only remaining thing: licence decision (LGPL?).
3843 release. Only remaining thing: licence decision (LGPL?).
3837
3844
3838 * Converted load_config to a class, ConfigLoader. Now recursion
3845 * Converted load_config to a class, ConfigLoader. Now recursion
3839 control is better organized. Doesn't include the same file twice.
3846 control is better organized. Doesn't include the same file twice.
3840
3847
3841 2001-11-29 Fernando Perez <fperez@colorado.edu>
3848 2001-11-29 Fernando Perez <fperez@colorado.edu>
3842
3849
3843 * Got input history working. Changed output history variables from
3850 * Got input history working. Changed output history variables from
3844 _p to _o so that _i is for input and _o for output. Just cleaner
3851 _p to _o so that _i is for input and _o for output. Just cleaner
3845 convention.
3852 convention.
3846
3853
3847 * Implemented parametric aliases. This pretty much allows the
3854 * Implemented parametric aliases. This pretty much allows the
3848 alias system to offer full-blown shell convenience, I think.
3855 alias system to offer full-blown shell convenience, I think.
3849
3856
3850 * Version 0.1.17 released, 0.1.18 opened.
3857 * Version 0.1.17 released, 0.1.18 opened.
3851
3858
3852 * dot_ipython/ipythonrc (alias): added documentation.
3859 * dot_ipython/ipythonrc (alias): added documentation.
3853 (xcolor): Fixed small bug (xcolors -> xcolor)
3860 (xcolor): Fixed small bug (xcolors -> xcolor)
3854
3861
3855 * Changed the alias system. Now alias is a magic command to define
3862 * Changed the alias system. Now alias is a magic command to define
3856 aliases just like the shell. Rationale: the builtin magics should
3863 aliases just like the shell. Rationale: the builtin magics should
3857 be there for things deeply connected to IPython's
3864 be there for things deeply connected to IPython's
3858 architecture. And this is a much lighter system for what I think
3865 architecture. And this is a much lighter system for what I think
3859 is the really important feature: allowing users to define quickly
3866 is the really important feature: allowing users to define quickly
3860 magics that will do shell things for them, so they can customize
3867 magics that will do shell things for them, so they can customize
3861 IPython easily to match their work habits. If someone is really
3868 IPython easily to match their work habits. If someone is really
3862 desperate to have another name for a builtin alias, they can
3869 desperate to have another name for a builtin alias, they can
3863 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
3870 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
3864 works.
3871 works.
3865
3872
3866 2001-11-28 Fernando Perez <fperez@colorado.edu>
3873 2001-11-28 Fernando Perez <fperez@colorado.edu>
3867
3874
3868 * Changed @file so that it opens the source file at the proper
3875 * Changed @file so that it opens the source file at the proper
3869 line. Since it uses less, if your EDITOR environment is
3876 line. Since it uses less, if your EDITOR environment is
3870 configured, typing v will immediately open your editor of choice
3877 configured, typing v will immediately open your editor of choice
3871 right at the line where the object is defined. Not as quick as
3878 right at the line where the object is defined. Not as quick as
3872 having a direct @edit command, but for all intents and purposes it
3879 having a direct @edit command, but for all intents and purposes it
3873 works. And I don't have to worry about writing @edit to deal with
3880 works. And I don't have to worry about writing @edit to deal with
3874 all the editors, less does that.
3881 all the editors, less does that.
3875
3882
3876 * Version 0.1.16 released, 0.1.17 opened.
3883 * Version 0.1.16 released, 0.1.17 opened.
3877
3884
3878 * Fixed some nasty bugs in the page/page_dumb combo that could
3885 * Fixed some nasty bugs in the page/page_dumb combo that could
3879 crash IPython.
3886 crash IPython.
3880
3887
3881 2001-11-27 Fernando Perez <fperez@colorado.edu>
3888 2001-11-27 Fernando Perez <fperez@colorado.edu>
3882
3889
3883 * Version 0.1.15 released, 0.1.16 opened.
3890 * Version 0.1.15 released, 0.1.16 opened.
3884
3891
3885 * Finally got ? and ?? to work for undefined things: now it's
3892 * Finally got ? and ?? to work for undefined things: now it's
3886 possible to type {}.get? and get information about the get method
3893 possible to type {}.get? and get information about the get method
3887 of dicts, or os.path? even if only os is defined (so technically
3894 of dicts, or os.path? even if only os is defined (so technically
3888 os.path isn't). Works at any level. For example, after import os,
3895 os.path isn't). Works at any level. For example, after import os,
3889 os?, os.path?, os.path.abspath? all work. This is great, took some
3896 os?, os.path?, os.path.abspath? all work. This is great, took some
3890 work in _ofind.
3897 work in _ofind.
3891
3898
3892 * Fixed more bugs with logging. The sanest way to do it was to add
3899 * Fixed more bugs with logging. The sanest way to do it was to add
3893 to @log a 'mode' parameter. Killed two in one shot (this mode
3900 to @log a 'mode' parameter. Killed two in one shot (this mode
3894 option was a request of Janko's). I think it's finally clean
3901 option was a request of Janko's). I think it's finally clean
3895 (famous last words).
3902 (famous last words).
3896
3903
3897 * Added a page_dumb() pager which does a decent job of paging on
3904 * Added a page_dumb() pager which does a decent job of paging on
3898 screen, if better things (like less) aren't available. One less
3905 screen, if better things (like less) aren't available. One less
3899 unix dependency (someday maybe somebody will port this to
3906 unix dependency (someday maybe somebody will port this to
3900 windows).
3907 windows).
3901
3908
3902 * Fixed problem in magic_log: would lock of logging out if log
3909 * Fixed problem in magic_log: would lock of logging out if log
3903 creation failed (because it would still think it had succeeded).
3910 creation failed (because it would still think it had succeeded).
3904
3911
3905 * Improved the page() function using curses to auto-detect screen
3912 * Improved the page() function using curses to auto-detect screen
3906 size. Now it can make a much better decision on whether to print
3913 size. Now it can make a much better decision on whether to print
3907 or page a string. Option screen_length was modified: a value 0
3914 or page a string. Option screen_length was modified: a value 0
3908 means auto-detect, and that's the default now.
3915 means auto-detect, and that's the default now.
3909
3916
3910 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
3917 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
3911 go out. I'll test it for a few days, then talk to Janko about
3918 go out. I'll test it for a few days, then talk to Janko about
3912 licences and announce it.
3919 licences and announce it.
3913
3920
3914 * Fixed the length of the auto-generated ---> prompt which appears
3921 * Fixed the length of the auto-generated ---> prompt which appears
3915 for auto-parens and auto-quotes. Getting this right isn't trivial,
3922 for auto-parens and auto-quotes. Getting this right isn't trivial,
3916 with all the color escapes, different prompt types and optional
3923 with all the color escapes, different prompt types and optional
3917 separators. But it seems to be working in all the combinations.
3924 separators. But it seems to be working in all the combinations.
3918
3925
3919 2001-11-26 Fernando Perez <fperez@colorado.edu>
3926 2001-11-26 Fernando Perez <fperez@colorado.edu>
3920
3927
3921 * Wrote a regexp filter to get option types from the option names
3928 * Wrote a regexp filter to get option types from the option names
3922 string. This eliminates the need to manually keep two duplicate
3929 string. This eliminates the need to manually keep two duplicate
3923 lists.
3930 lists.
3924
3931
3925 * Removed the unneeded check_option_names. Now options are handled
3932 * Removed the unneeded check_option_names. Now options are handled
3926 in a much saner manner and it's easy to visually check that things
3933 in a much saner manner and it's easy to visually check that things
3927 are ok.
3934 are ok.
3928
3935
3929 * Updated version numbers on all files I modified to carry a
3936 * Updated version numbers on all files I modified to carry a
3930 notice so Janko and Nathan have clear version markers.
3937 notice so Janko and Nathan have clear version markers.
3931
3938
3932 * Updated docstring for ultraTB with my changes. I should send
3939 * Updated docstring for ultraTB with my changes. I should send
3933 this to Nathan.
3940 this to Nathan.
3934
3941
3935 * Lots of small fixes. Ran everything through pychecker again.
3942 * Lots of small fixes. Ran everything through pychecker again.
3936
3943
3937 * Made loading of deep_reload an cmd line option. If it's not too
3944 * Made loading of deep_reload an cmd line option. If it's not too
3938 kosher, now people can just disable it. With -nodeep_reload it's
3945 kosher, now people can just disable it. With -nodeep_reload it's
3939 still available as dreload(), it just won't overwrite reload().
3946 still available as dreload(), it just won't overwrite reload().
3940
3947
3941 * Moved many options to the no| form (-opt and -noopt
3948 * Moved many options to the no| form (-opt and -noopt
3942 accepted). Cleaner.
3949 accepted). Cleaner.
3943
3950
3944 * Changed magic_log so that if called with no parameters, it uses
3951 * Changed magic_log so that if called with no parameters, it uses
3945 'rotate' mode. That way auto-generated logs aren't automatically
3952 'rotate' mode. That way auto-generated logs aren't automatically
3946 over-written. For normal logs, now a backup is made if it exists
3953 over-written. For normal logs, now a backup is made if it exists
3947 (only 1 level of backups). A new 'backup' mode was added to the
3954 (only 1 level of backups). A new 'backup' mode was added to the
3948 Logger class to support this. This was a request by Janko.
3955 Logger class to support this. This was a request by Janko.
3949
3956
3950 * Added @logoff/@logon to stop/restart an active log.
3957 * Added @logoff/@logon to stop/restart an active log.
3951
3958
3952 * Fixed a lot of bugs in log saving/replay. It was pretty
3959 * Fixed a lot of bugs in log saving/replay. It was pretty
3953 broken. Now special lines (!@,/) appear properly in the command
3960 broken. Now special lines (!@,/) appear properly in the command
3954 history after a log replay.
3961 history after a log replay.
3955
3962
3956 * Tried and failed to implement full session saving via pickle. My
3963 * Tried and failed to implement full session saving via pickle. My
3957 idea was to pickle __main__.__dict__, but modules can't be
3964 idea was to pickle __main__.__dict__, but modules can't be
3958 pickled. This would be a better alternative to replaying logs, but
3965 pickled. This would be a better alternative to replaying logs, but
3959 seems quite tricky to get to work. Changed -session to be called
3966 seems quite tricky to get to work. Changed -session to be called
3960 -logplay, which more accurately reflects what it does. And if we
3967 -logplay, which more accurately reflects what it does. And if we
3961 ever get real session saving working, -session is now available.
3968 ever get real session saving working, -session is now available.
3962
3969
3963 * Implemented color schemes for prompts also. As for tracebacks,
3970 * Implemented color schemes for prompts also. As for tracebacks,
3964 currently only NoColor and Linux are supported. But now the
3971 currently only NoColor and Linux are supported. But now the
3965 infrastructure is in place, based on a generic ColorScheme
3972 infrastructure is in place, based on a generic ColorScheme
3966 class. So writing and activating new schemes both for the prompts
3973 class. So writing and activating new schemes both for the prompts
3967 and the tracebacks should be straightforward.
3974 and the tracebacks should be straightforward.
3968
3975
3969 * Version 0.1.13 released, 0.1.14 opened.
3976 * Version 0.1.13 released, 0.1.14 opened.
3970
3977
3971 * Changed handling of options for output cache. Now counter is
3978 * Changed handling of options for output cache. Now counter is
3972 hardwired starting at 1 and one specifies the maximum number of
3979 hardwired starting at 1 and one specifies the maximum number of
3973 entries *in the outcache* (not the max prompt counter). This is
3980 entries *in the outcache* (not the max prompt counter). This is
3974 much better, since many statements won't increase the cache
3981 much better, since many statements won't increase the cache
3975 count. It also eliminated some confusing options, now there's only
3982 count. It also eliminated some confusing options, now there's only
3976 one: cache_size.
3983 one: cache_size.
3977
3984
3978 * Added 'alias' magic function and magic_alias option in the
3985 * Added 'alias' magic function and magic_alias option in the
3979 ipythonrc file. Now the user can easily define whatever names he
3986 ipythonrc file. Now the user can easily define whatever names he
3980 wants for the magic functions without having to play weird
3987 wants for the magic functions without having to play weird
3981 namespace games. This gives IPython a real shell-like feel.
3988 namespace games. This gives IPython a real shell-like feel.
3982
3989
3983 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
3990 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
3984 @ or not).
3991 @ or not).
3985
3992
3986 This was one of the last remaining 'visible' bugs (that I know
3993 This was one of the last remaining 'visible' bugs (that I know
3987 of). I think if I can clean up the session loading so it works
3994 of). I think if I can clean up the session loading so it works
3988 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
3995 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
3989 about licensing).
3996 about licensing).
3990
3997
3991 2001-11-25 Fernando Perez <fperez@colorado.edu>
3998 2001-11-25 Fernando Perez <fperez@colorado.edu>
3992
3999
3993 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
4000 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
3994 there's a cleaner distinction between what ? and ?? show.
4001 there's a cleaner distinction between what ? and ?? show.
3995
4002
3996 * Added screen_length option. Now the user can define his own
4003 * Added screen_length option. Now the user can define his own
3997 screen size for page() operations.
4004 screen size for page() operations.
3998
4005
3999 * Implemented magic shell-like functions with automatic code
4006 * Implemented magic shell-like functions with automatic code
4000 generation. Now adding another function is just a matter of adding
4007 generation. Now adding another function is just a matter of adding
4001 an entry to a dict, and the function is dynamically generated at
4008 an entry to a dict, and the function is dynamically generated at
4002 run-time. Python has some really cool features!
4009 run-time. Python has some really cool features!
4003
4010
4004 * Renamed many options to cleanup conventions a little. Now all
4011 * Renamed many options to cleanup conventions a little. Now all
4005 are lowercase, and only underscores where needed. Also in the code
4012 are lowercase, and only underscores where needed. Also in the code
4006 option name tables are clearer.
4013 option name tables are clearer.
4007
4014
4008 * Changed prompts a little. Now input is 'In [n]:' instead of
4015 * Changed prompts a little. Now input is 'In [n]:' instead of
4009 'In[n]:='. This allows it the numbers to be aligned with the
4016 'In[n]:='. This allows it the numbers to be aligned with the
4010 Out[n] numbers, and removes usage of ':=' which doesn't exist in
4017 Out[n] numbers, and removes usage of ':=' which doesn't exist in
4011 Python (it was a Mathematica thing). The '...' continuation prompt
4018 Python (it was a Mathematica thing). The '...' continuation prompt
4012 was also changed a little to align better.
4019 was also changed a little to align better.
4013
4020
4014 * Fixed bug when flushing output cache. Not all _p<n> variables
4021 * Fixed bug when flushing output cache. Not all _p<n> variables
4015 exist, so their deletion needs to be wrapped in a try:
4022 exist, so their deletion needs to be wrapped in a try:
4016
4023
4017 * Figured out how to properly use inspect.formatargspec() (it
4024 * Figured out how to properly use inspect.formatargspec() (it
4018 requires the args preceded by *). So I removed all the code from
4025 requires the args preceded by *). So I removed all the code from
4019 _get_pdef in Magic, which was just replicating that.
4026 _get_pdef in Magic, which was just replicating that.
4020
4027
4021 * Added test to prefilter to allow redefining magic function names
4028 * Added test to prefilter to allow redefining magic function names
4022 as variables. This is ok, since the @ form is always available,
4029 as variables. This is ok, since the @ form is always available,
4023 but whe should allow the user to define a variable called 'ls' if
4030 but whe should allow the user to define a variable called 'ls' if
4024 he needs it.
4031 he needs it.
4025
4032
4026 * Moved the ToDo information from README into a separate ToDo.
4033 * Moved the ToDo information from README into a separate ToDo.
4027
4034
4028 * General code cleanup and small bugfixes. I think it's close to a
4035 * General code cleanup and small bugfixes. I think it's close to a
4029 state where it can be released, obviously with a big 'beta'
4036 state where it can be released, obviously with a big 'beta'
4030 warning on it.
4037 warning on it.
4031
4038
4032 * Got the magic function split to work. Now all magics are defined
4039 * Got the magic function split to work. Now all magics are defined
4033 in a separate class. It just organizes things a bit, and now
4040 in a separate class. It just organizes things a bit, and now
4034 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
4041 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
4035 was too long).
4042 was too long).
4036
4043
4037 * Changed @clear to @reset to avoid potential confusions with
4044 * Changed @clear to @reset to avoid potential confusions with
4038 the shell command clear. Also renamed @cl to @clear, which does
4045 the shell command clear. Also renamed @cl to @clear, which does
4039 exactly what people expect it to from their shell experience.
4046 exactly what people expect it to from their shell experience.
4040
4047
4041 Added a check to the @reset command (since it's so
4048 Added a check to the @reset command (since it's so
4042 destructive, it's probably a good idea to ask for confirmation).
4049 destructive, it's probably a good idea to ask for confirmation).
4043 But now reset only works for full namespace resetting. Since the
4050 But now reset only works for full namespace resetting. Since the
4044 del keyword is already there for deleting a few specific
4051 del keyword is already there for deleting a few specific
4045 variables, I don't see the point of having a redundant magic
4052 variables, I don't see the point of having a redundant magic
4046 function for the same task.
4053 function for the same task.
4047
4054
4048 2001-11-24 Fernando Perez <fperez@colorado.edu>
4055 2001-11-24 Fernando Perez <fperez@colorado.edu>
4049
4056
4050 * Updated the builtin docs (esp. the ? ones).
4057 * Updated the builtin docs (esp. the ? ones).
4051
4058
4052 * Ran all the code through pychecker. Not terribly impressed with
4059 * Ran all the code through pychecker. Not terribly impressed with
4053 it: lots of spurious warnings and didn't really find anything of
4060 it: lots of spurious warnings and didn't really find anything of
4054 substance (just a few modules being imported and not used).
4061 substance (just a few modules being imported and not used).
4055
4062
4056 * Implemented the new ultraTB functionality into IPython. New
4063 * Implemented the new ultraTB functionality into IPython. New
4057 option: xcolors. This chooses color scheme. xmode now only selects
4064 option: xcolors. This chooses color scheme. xmode now only selects
4058 between Plain and Verbose. Better orthogonality.
4065 between Plain and Verbose. Better orthogonality.
4059
4066
4060 * Large rewrite of ultraTB. Much cleaner now, with a separation of
4067 * Large rewrite of ultraTB. Much cleaner now, with a separation of
4061 mode and color scheme for the exception handlers. Now it's
4068 mode and color scheme for the exception handlers. Now it's
4062 possible to have the verbose traceback with no coloring.
4069 possible to have the verbose traceback with no coloring.
4063
4070
4064 2001-11-23 Fernando Perez <fperez@colorado.edu>
4071 2001-11-23 Fernando Perez <fperez@colorado.edu>
4065
4072
4066 * Version 0.1.12 released, 0.1.13 opened.
4073 * Version 0.1.12 released, 0.1.13 opened.
4067
4074
4068 * Removed option to set auto-quote and auto-paren escapes by
4075 * Removed option to set auto-quote and auto-paren escapes by
4069 user. The chances of breaking valid syntax are just too high. If
4076 user. The chances of breaking valid syntax are just too high. If
4070 someone *really* wants, they can always dig into the code.
4077 someone *really* wants, they can always dig into the code.
4071
4078
4072 * Made prompt separators configurable.
4079 * Made prompt separators configurable.
4073
4080
4074 2001-11-22 Fernando Perez <fperez@colorado.edu>
4081 2001-11-22 Fernando Perez <fperez@colorado.edu>
4075
4082
4076 * Small bugfixes in many places.
4083 * Small bugfixes in many places.
4077
4084
4078 * Removed the MyCompleter class from ipplib. It seemed redundant
4085 * Removed the MyCompleter class from ipplib. It seemed redundant
4079 with the C-p,C-n history search functionality. Less code to
4086 with the C-p,C-n history search functionality. Less code to
4080 maintain.
4087 maintain.
4081
4088
4082 * Moved all the original ipython.py code into ipythonlib.py. Right
4089 * Moved all the original ipython.py code into ipythonlib.py. Right
4083 now it's just one big dump into a function called make_IPython, so
4090 now it's just one big dump into a function called make_IPython, so
4084 no real modularity has been gained. But at least it makes the
4091 no real modularity has been gained. But at least it makes the
4085 wrapper script tiny, and since ipythonlib is a module, it gets
4092 wrapper script tiny, and since ipythonlib is a module, it gets
4086 compiled and startup is much faster.
4093 compiled and startup is much faster.
4087
4094
4088 This is a reasobably 'deep' change, so we should test it for a
4095 This is a reasobably 'deep' change, so we should test it for a
4089 while without messing too much more with the code.
4096 while without messing too much more with the code.
4090
4097
4091 2001-11-21 Fernando Perez <fperez@colorado.edu>
4098 2001-11-21 Fernando Perez <fperez@colorado.edu>
4092
4099
4093 * Version 0.1.11 released, 0.1.12 opened for further work.
4100 * Version 0.1.11 released, 0.1.12 opened for further work.
4094
4101
4095 * Removed dependency on Itpl. It was only needed in one place. It
4102 * Removed dependency on Itpl. It was only needed in one place. It
4096 would be nice if this became part of python, though. It makes life
4103 would be nice if this became part of python, though. It makes life
4097 *a lot* easier in some cases.
4104 *a lot* easier in some cases.
4098
4105
4099 * Simplified the prefilter code a bit. Now all handlers are
4106 * Simplified the prefilter code a bit. Now all handlers are
4100 expected to explicitly return a value (at least a blank string).
4107 expected to explicitly return a value (at least a blank string).
4101
4108
4102 * Heavy edits in ipplib. Removed the help system altogether. Now
4109 * Heavy edits in ipplib. Removed the help system altogether. Now
4103 obj?/?? is used for inspecting objects, a magic @doc prints
4110 obj?/?? is used for inspecting objects, a magic @doc prints
4104 docstrings, and full-blown Python help is accessed via the 'help'
4111 docstrings, and full-blown Python help is accessed via the 'help'
4105 keyword. This cleans up a lot of code (less to maintain) and does
4112 keyword. This cleans up a lot of code (less to maintain) and does
4106 the job. Since 'help' is now a standard Python component, might as
4113 the job. Since 'help' is now a standard Python component, might as
4107 well use it and remove duplicate functionality.
4114 well use it and remove duplicate functionality.
4108
4115
4109 Also removed the option to use ipplib as a standalone program. By
4116 Also removed the option to use ipplib as a standalone program. By
4110 now it's too dependent on other parts of IPython to function alone.
4117 now it's too dependent on other parts of IPython to function alone.
4111
4118
4112 * Fixed bug in genutils.pager. It would crash if the pager was
4119 * Fixed bug in genutils.pager. It would crash if the pager was
4113 exited immediately after opening (broken pipe).
4120 exited immediately after opening (broken pipe).
4114
4121
4115 * Trimmed down the VerboseTB reporting a little. The header is
4122 * Trimmed down the VerboseTB reporting a little. The header is
4116 much shorter now and the repeated exception arguments at the end
4123 much shorter now and the repeated exception arguments at the end
4117 have been removed. For interactive use the old header seemed a bit
4124 have been removed. For interactive use the old header seemed a bit
4118 excessive.
4125 excessive.
4119
4126
4120 * Fixed small bug in output of @whos for variables with multi-word
4127 * Fixed small bug in output of @whos for variables with multi-word
4121 types (only first word was displayed).
4128 types (only first word was displayed).
4122
4129
4123 2001-11-17 Fernando Perez <fperez@colorado.edu>
4130 2001-11-17 Fernando Perez <fperez@colorado.edu>
4124
4131
4125 * Version 0.1.10 released, 0.1.11 opened for further work.
4132 * Version 0.1.10 released, 0.1.11 opened for further work.
4126
4133
4127 * Modified dirs and friends. dirs now *returns* the stack (not
4134 * Modified dirs and friends. dirs now *returns* the stack (not
4128 prints), so one can manipulate it as a variable. Convenient to
4135 prints), so one can manipulate it as a variable. Convenient to
4129 travel along many directories.
4136 travel along many directories.
4130
4137
4131 * Fixed bug in magic_pdef: would only work with functions with
4138 * Fixed bug in magic_pdef: would only work with functions with
4132 arguments with default values.
4139 arguments with default values.
4133
4140
4134 2001-11-14 Fernando Perez <fperez@colorado.edu>
4141 2001-11-14 Fernando Perez <fperez@colorado.edu>
4135
4142
4136 * Added the PhysicsInput stuff to dot_ipython so it ships as an
4143 * Added the PhysicsInput stuff to dot_ipython so it ships as an
4137 example with IPython. Various other minor fixes and cleanups.
4144 example with IPython. Various other minor fixes and cleanups.
4138
4145
4139 * Version 0.1.9 released, 0.1.10 opened for further work.
4146 * Version 0.1.9 released, 0.1.10 opened for further work.
4140
4147
4141 * Added sys.path to the list of directories searched in the
4148 * Added sys.path to the list of directories searched in the
4142 execfile= option. It used to be the current directory and the
4149 execfile= option. It used to be the current directory and the
4143 user's IPYTHONDIR only.
4150 user's IPYTHONDIR only.
4144
4151
4145 2001-11-13 Fernando Perez <fperez@colorado.edu>
4152 2001-11-13 Fernando Perez <fperez@colorado.edu>
4146
4153
4147 * Reinstated the raw_input/prefilter separation that Janko had
4154 * Reinstated the raw_input/prefilter separation that Janko had
4148 initially. This gives a more convenient setup for extending the
4155 initially. This gives a more convenient setup for extending the
4149 pre-processor from the outside: raw_input always gets a string,
4156 pre-processor from the outside: raw_input always gets a string,
4150 and prefilter has to process it. We can then redefine prefilter
4157 and prefilter has to process it. We can then redefine prefilter
4151 from the outside and implement extensions for special
4158 from the outside and implement extensions for special
4152 purposes.
4159 purposes.
4153
4160
4154 Today I got one for inputting PhysicalQuantity objects
4161 Today I got one for inputting PhysicalQuantity objects
4155 (from Scientific) without needing any function calls at
4162 (from Scientific) without needing any function calls at
4156 all. Extremely convenient, and it's all done as a user-level
4163 all. Extremely convenient, and it's all done as a user-level
4157 extension (no IPython code was touched). Now instead of:
4164 extension (no IPython code was touched). Now instead of:
4158 a = PhysicalQuantity(4.2,'m/s**2')
4165 a = PhysicalQuantity(4.2,'m/s**2')
4159 one can simply say
4166 one can simply say
4160 a = 4.2 m/s**2
4167 a = 4.2 m/s**2
4161 or even
4168 or even
4162 a = 4.2 m/s^2
4169 a = 4.2 m/s^2
4163
4170
4164 I use this, but it's also a proof of concept: IPython really is
4171 I use this, but it's also a proof of concept: IPython really is
4165 fully user-extensible, even at the level of the parsing of the
4172 fully user-extensible, even at the level of the parsing of the
4166 command line. It's not trivial, but it's perfectly doable.
4173 command line. It's not trivial, but it's perfectly doable.
4167
4174
4168 * Added 'add_flip' method to inclusion conflict resolver. Fixes
4175 * Added 'add_flip' method to inclusion conflict resolver. Fixes
4169 the problem of modules being loaded in the inverse order in which
4176 the problem of modules being loaded in the inverse order in which
4170 they were defined in
4177 they were defined in
4171
4178
4172 * Version 0.1.8 released, 0.1.9 opened for further work.
4179 * Version 0.1.8 released, 0.1.9 opened for further work.
4173
4180
4174 * Added magics pdef, source and file. They respectively show the
4181 * Added magics pdef, source and file. They respectively show the
4175 definition line ('prototype' in C), source code and full python
4182 definition line ('prototype' in C), source code and full python
4176 file for any callable object. The object inspector oinfo uses
4183 file for any callable object. The object inspector oinfo uses
4177 these to show the same information.
4184 these to show the same information.
4178
4185
4179 * Version 0.1.7 released, 0.1.8 opened for further work.
4186 * Version 0.1.7 released, 0.1.8 opened for further work.
4180
4187
4181 * Separated all the magic functions into a class called Magic. The
4188 * Separated all the magic functions into a class called Magic. The
4182 InteractiveShell class was becoming too big for Xemacs to handle
4189 InteractiveShell class was becoming too big for Xemacs to handle
4183 (de-indenting a line would lock it up for 10 seconds while it
4190 (de-indenting a line would lock it up for 10 seconds while it
4184 backtracked on the whole class!)
4191 backtracked on the whole class!)
4185
4192
4186 FIXME: didn't work. It can be done, but right now namespaces are
4193 FIXME: didn't work. It can be done, but right now namespaces are
4187 all messed up. Do it later (reverted it for now, so at least
4194 all messed up. Do it later (reverted it for now, so at least
4188 everything works as before).
4195 everything works as before).
4189
4196
4190 * Got the object introspection system (magic_oinfo) working! I
4197 * Got the object introspection system (magic_oinfo) working! I
4191 think this is pretty much ready for release to Janko, so he can
4198 think this is pretty much ready for release to Janko, so he can
4192 test it for a while and then announce it. Pretty much 100% of what
4199 test it for a while and then announce it. Pretty much 100% of what
4193 I wanted for the 'phase 1' release is ready. Happy, tired.
4200 I wanted for the 'phase 1' release is ready. Happy, tired.
4194
4201
4195 2001-11-12 Fernando Perez <fperez@colorado.edu>
4202 2001-11-12 Fernando Perez <fperez@colorado.edu>
4196
4203
4197 * Version 0.1.6 released, 0.1.7 opened for further work.
4204 * Version 0.1.6 released, 0.1.7 opened for further work.
4198
4205
4199 * Fixed bug in printing: it used to test for truth before
4206 * Fixed bug in printing: it used to test for truth before
4200 printing, so 0 wouldn't print. Now checks for None.
4207 printing, so 0 wouldn't print. Now checks for None.
4201
4208
4202 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
4209 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
4203 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
4210 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
4204 reaches by hand into the outputcache. Think of a better way to do
4211 reaches by hand into the outputcache. Think of a better way to do
4205 this later.
4212 this later.
4206
4213
4207 * Various small fixes thanks to Nathan's comments.
4214 * Various small fixes thanks to Nathan's comments.
4208
4215
4209 * Changed magic_pprint to magic_Pprint. This way it doesn't
4216 * Changed magic_pprint to magic_Pprint. This way it doesn't
4210 collide with pprint() and the name is consistent with the command
4217 collide with pprint() and the name is consistent with the command
4211 line option.
4218 line option.
4212
4219
4213 * Changed prompt counter behavior to be fully like
4220 * Changed prompt counter behavior to be fully like
4214 Mathematica's. That is, even input that doesn't return a result
4221 Mathematica's. That is, even input that doesn't return a result
4215 raises the prompt counter. The old behavior was kind of confusing
4222 raises the prompt counter. The old behavior was kind of confusing
4216 (getting the same prompt number several times if the operation
4223 (getting the same prompt number several times if the operation
4217 didn't return a result).
4224 didn't return a result).
4218
4225
4219 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
4226 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
4220
4227
4221 * Fixed -Classic mode (wasn't working anymore).
4228 * Fixed -Classic mode (wasn't working anymore).
4222
4229
4223 * Added colored prompts using Nathan's new code. Colors are
4230 * Added colored prompts using Nathan's new code. Colors are
4224 currently hardwired, they can be user-configurable. For
4231 currently hardwired, they can be user-configurable. For
4225 developers, they can be chosen in file ipythonlib.py, at the
4232 developers, they can be chosen in file ipythonlib.py, at the
4226 beginning of the CachedOutput class def.
4233 beginning of the CachedOutput class def.
4227
4234
4228 2001-11-11 Fernando Perez <fperez@colorado.edu>
4235 2001-11-11 Fernando Perez <fperez@colorado.edu>
4229
4236
4230 * Version 0.1.5 released, 0.1.6 opened for further work.
4237 * Version 0.1.5 released, 0.1.6 opened for further work.
4231
4238
4232 * Changed magic_env to *return* the environment as a dict (not to
4239 * Changed magic_env to *return* the environment as a dict (not to
4233 print it). This way it prints, but it can also be processed.
4240 print it). This way it prints, but it can also be processed.
4234
4241
4235 * Added Verbose exception reporting to interactive
4242 * Added Verbose exception reporting to interactive
4236 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
4243 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
4237 traceback. Had to make some changes to the ultraTB file. This is
4244 traceback. Had to make some changes to the ultraTB file. This is
4238 probably the last 'big' thing in my mental todo list. This ties
4245 probably the last 'big' thing in my mental todo list. This ties
4239 in with the next entry:
4246 in with the next entry:
4240
4247
4241 * Changed -Xi and -Xf to a single -xmode option. Now all the user
4248 * Changed -Xi and -Xf to a single -xmode option. Now all the user
4242 has to specify is Plain, Color or Verbose for all exception
4249 has to specify is Plain, Color or Verbose for all exception
4243 handling.
4250 handling.
4244
4251
4245 * Removed ShellServices option. All this can really be done via
4252 * Removed ShellServices option. All this can really be done via
4246 the magic system. It's easier to extend, cleaner and has automatic
4253 the magic system. It's easier to extend, cleaner and has automatic
4247 namespace protection and documentation.
4254 namespace protection and documentation.
4248
4255
4249 2001-11-09 Fernando Perez <fperez@colorado.edu>
4256 2001-11-09 Fernando Perez <fperez@colorado.edu>
4250
4257
4251 * Fixed bug in output cache flushing (missing parameter to
4258 * Fixed bug in output cache flushing (missing parameter to
4252 __init__). Other small bugs fixed (found using pychecker).
4259 __init__). Other small bugs fixed (found using pychecker).
4253
4260
4254 * Version 0.1.4 opened for bugfixing.
4261 * Version 0.1.4 opened for bugfixing.
4255
4262
4256 2001-11-07 Fernando Perez <fperez@colorado.edu>
4263 2001-11-07 Fernando Perez <fperez@colorado.edu>
4257
4264
4258 * Version 0.1.3 released, mainly because of the raw_input bug.
4265 * Version 0.1.3 released, mainly because of the raw_input bug.
4259
4266
4260 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
4267 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
4261 and when testing for whether things were callable, a call could
4268 and when testing for whether things were callable, a call could
4262 actually be made to certain functions. They would get called again
4269 actually be made to certain functions. They would get called again
4263 once 'really' executed, with a resulting double call. A disaster
4270 once 'really' executed, with a resulting double call. A disaster
4264 in many cases (list.reverse() would never work!).
4271 in many cases (list.reverse() would never work!).
4265
4272
4266 * Removed prefilter() function, moved its code to raw_input (which
4273 * Removed prefilter() function, moved its code to raw_input (which
4267 after all was just a near-empty caller for prefilter). This saves
4274 after all was just a near-empty caller for prefilter). This saves
4268 a function call on every prompt, and simplifies the class a tiny bit.
4275 a function call on every prompt, and simplifies the class a tiny bit.
4269
4276
4270 * Fix _ip to __ip name in magic example file.
4277 * Fix _ip to __ip name in magic example file.
4271
4278
4272 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
4279 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
4273 work with non-gnu versions of tar.
4280 work with non-gnu versions of tar.
4274
4281
4275 2001-11-06 Fernando Perez <fperez@colorado.edu>
4282 2001-11-06 Fernando Perez <fperez@colorado.edu>
4276
4283
4277 * Version 0.1.2. Just to keep track of the recent changes.
4284 * Version 0.1.2. Just to keep track of the recent changes.
4278
4285
4279 * Fixed nasty bug in output prompt routine. It used to check 'if
4286 * Fixed nasty bug in output prompt routine. It used to check 'if
4280 arg != None...'. Problem is, this fails if arg implements a
4287 arg != None...'. Problem is, this fails if arg implements a
4281 special comparison (__cmp__) which disallows comparing to
4288 special comparison (__cmp__) which disallows comparing to
4282 None. Found it when trying to use the PhysicalQuantity module from
4289 None. Found it when trying to use the PhysicalQuantity module from
4283 ScientificPython.
4290 ScientificPython.
4284
4291
4285 2001-11-05 Fernando Perez <fperez@colorado.edu>
4292 2001-11-05 Fernando Perez <fperez@colorado.edu>
4286
4293
4287 * Also added dirs. Now the pushd/popd/dirs family functions
4294 * Also added dirs. Now the pushd/popd/dirs family functions
4288 basically like the shell, with the added convenience of going home
4295 basically like the shell, with the added convenience of going home
4289 when called with no args.
4296 when called with no args.
4290
4297
4291 * pushd/popd slightly modified to mimic shell behavior more
4298 * pushd/popd slightly modified to mimic shell behavior more
4292 closely.
4299 closely.
4293
4300
4294 * Added env,pushd,popd from ShellServices as magic functions. I
4301 * Added env,pushd,popd from ShellServices as magic functions. I
4295 think the cleanest will be to port all desired functions from
4302 think the cleanest will be to port all desired functions from
4296 ShellServices as magics and remove ShellServices altogether. This
4303 ShellServices as magics and remove ShellServices altogether. This
4297 will provide a single, clean way of adding functionality
4304 will provide a single, clean way of adding functionality
4298 (shell-type or otherwise) to IP.
4305 (shell-type or otherwise) to IP.
4299
4306
4300 2001-11-04 Fernando Perez <fperez@colorado.edu>
4307 2001-11-04 Fernando Perez <fperez@colorado.edu>
4301
4308
4302 * Added .ipython/ directory to sys.path. This way users can keep
4309 * Added .ipython/ directory to sys.path. This way users can keep
4303 customizations there and access them via import.
4310 customizations there and access them via import.
4304
4311
4305 2001-11-03 Fernando Perez <fperez@colorado.edu>
4312 2001-11-03 Fernando Perez <fperez@colorado.edu>
4306
4313
4307 * Opened version 0.1.1 for new changes.
4314 * Opened version 0.1.1 for new changes.
4308
4315
4309 * Changed version number to 0.1.0: first 'public' release, sent to
4316 * Changed version number to 0.1.0: first 'public' release, sent to
4310 Nathan and Janko.
4317 Nathan and Janko.
4311
4318
4312 * Lots of small fixes and tweaks.
4319 * Lots of small fixes and tweaks.
4313
4320
4314 * Minor changes to whos format. Now strings are shown, snipped if
4321 * Minor changes to whos format. Now strings are shown, snipped if
4315 too long.
4322 too long.
4316
4323
4317 * Changed ShellServices to work on __main__ so they show up in @who
4324 * Changed ShellServices to work on __main__ so they show up in @who
4318
4325
4319 * Help also works with ? at the end of a line:
4326 * Help also works with ? at the end of a line:
4320 ?sin and sin?
4327 ?sin and sin?
4321 both produce the same effect. This is nice, as often I use the
4328 both produce the same effect. This is nice, as often I use the
4322 tab-complete to find the name of a method, but I used to then have
4329 tab-complete to find the name of a method, but I used to then have
4323 to go to the beginning of the line to put a ? if I wanted more
4330 to go to the beginning of the line to put a ? if I wanted more
4324 info. Now I can just add the ? and hit return. Convenient.
4331 info. Now I can just add the ? and hit return. Convenient.
4325
4332
4326 2001-11-02 Fernando Perez <fperez@colorado.edu>
4333 2001-11-02 Fernando Perez <fperez@colorado.edu>
4327
4334
4328 * Python version check (>=2.1) added.
4335 * Python version check (>=2.1) added.
4329
4336
4330 * Added LazyPython documentation. At this point the docs are quite
4337 * Added LazyPython documentation. At this point the docs are quite
4331 a mess. A cleanup is in order.
4338 a mess. A cleanup is in order.
4332
4339
4333 * Auto-installer created. For some bizarre reason, the zipfiles
4340 * Auto-installer created. For some bizarre reason, the zipfiles
4334 module isn't working on my system. So I made a tar version
4341 module isn't working on my system. So I made a tar version
4335 (hopefully the command line options in various systems won't kill
4342 (hopefully the command line options in various systems won't kill
4336 me).
4343 me).
4337
4344
4338 * Fixes to Struct in genutils. Now all dictionary-like methods are
4345 * Fixes to Struct in genutils. Now all dictionary-like methods are
4339 protected (reasonably).
4346 protected (reasonably).
4340
4347
4341 * Added pager function to genutils and changed ? to print usage
4348 * Added pager function to genutils and changed ? to print usage
4342 note through it (it was too long).
4349 note through it (it was too long).
4343
4350
4344 * Added the LazyPython functionality. Works great! I changed the
4351 * Added the LazyPython functionality. Works great! I changed the
4345 auto-quote escape to ';', it's on home row and next to '. But
4352 auto-quote escape to ';', it's on home row and next to '. But
4346 both auto-quote and auto-paren (still /) escapes are command-line
4353 both auto-quote and auto-paren (still /) escapes are command-line
4347 parameters.
4354 parameters.
4348
4355
4349
4356
4350 2001-11-01 Fernando Perez <fperez@colorado.edu>
4357 2001-11-01 Fernando Perez <fperez@colorado.edu>
4351
4358
4352 * Version changed to 0.0.7. Fairly large change: configuration now
4359 * Version changed to 0.0.7. Fairly large change: configuration now
4353 is all stored in a directory, by default .ipython. There, all
4360 is all stored in a directory, by default .ipython. There, all
4354 config files have normal looking names (not .names)
4361 config files have normal looking names (not .names)
4355
4362
4356 * Version 0.0.6 Released first to Lucas and Archie as a test
4363 * Version 0.0.6 Released first to Lucas and Archie as a test
4357 run. Since it's the first 'semi-public' release, change version to
4364 run. Since it's the first 'semi-public' release, change version to
4358 > 0.0.6 for any changes now.
4365 > 0.0.6 for any changes now.
4359
4366
4360 * Stuff I had put in the ipplib.py changelog:
4367 * Stuff I had put in the ipplib.py changelog:
4361
4368
4362 Changes to InteractiveShell:
4369 Changes to InteractiveShell:
4363
4370
4364 - Made the usage message a parameter.
4371 - Made the usage message a parameter.
4365
4372
4366 - Require the name of the shell variable to be given. It's a bit
4373 - Require the name of the shell variable to be given. It's a bit
4367 of a hack, but allows the name 'shell' not to be hardwire in the
4374 of a hack, but allows the name 'shell' not to be hardwire in the
4368 magic (@) handler, which is problematic b/c it requires
4375 magic (@) handler, which is problematic b/c it requires
4369 polluting the global namespace with 'shell'. This in turn is
4376 polluting the global namespace with 'shell'. This in turn is
4370 fragile: if a user redefines a variable called shell, things
4377 fragile: if a user redefines a variable called shell, things
4371 break.
4378 break.
4372
4379
4373 - magic @: all functions available through @ need to be defined
4380 - magic @: all functions available through @ need to be defined
4374 as magic_<name>, even though they can be called simply as
4381 as magic_<name>, even though they can be called simply as
4375 @<name>. This allows the special command @magic to gather
4382 @<name>. This allows the special command @magic to gather
4376 information automatically about all existing magic functions,
4383 information automatically about all existing magic functions,
4377 even if they are run-time user extensions, by parsing the shell
4384 even if they are run-time user extensions, by parsing the shell
4378 instance __dict__ looking for special magic_ names.
4385 instance __dict__ looking for special magic_ names.
4379
4386
4380 - mainloop: added *two* local namespace parameters. This allows
4387 - mainloop: added *two* local namespace parameters. This allows
4381 the class to differentiate between parameters which were there
4388 the class to differentiate between parameters which were there
4382 before and after command line initialization was processed. This
4389 before and after command line initialization was processed. This
4383 way, later @who can show things loaded at startup by the
4390 way, later @who can show things loaded at startup by the
4384 user. This trick was necessary to make session saving/reloading
4391 user. This trick was necessary to make session saving/reloading
4385 really work: ideally after saving/exiting/reloading a session,
4392 really work: ideally after saving/exiting/reloading a session,
4386 *everythin* should look the same, including the output of @who. I
4393 *everythin* should look the same, including the output of @who. I
4387 was only able to make this work with this double namespace
4394 was only able to make this work with this double namespace
4388 trick.
4395 trick.
4389
4396
4390 - added a header to the logfile which allows (almost) full
4397 - added a header to the logfile which allows (almost) full
4391 session restoring.
4398 session restoring.
4392
4399
4393 - prepend lines beginning with @ or !, with a and log
4400 - prepend lines beginning with @ or !, with a and log
4394 them. Why? !lines: may be useful to know what you did @lines:
4401 them. Why? !lines: may be useful to know what you did @lines:
4395 they may affect session state. So when restoring a session, at
4402 they may affect session state. So when restoring a session, at
4396 least inform the user of their presence. I couldn't quite get
4403 least inform the user of their presence. I couldn't quite get
4397 them to properly re-execute, but at least the user is warned.
4404 them to properly re-execute, but at least the user is warned.
4398
4405
4399 * Started ChangeLog.
4406 * Started ChangeLog.
@@ -1,8819 +1,8928 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{hyperref}
6 \usepackage{color}
7
8 % A few colors to replace the defaults for certain link types
9 \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
10 \definecolor{darkorange}{rgb}{.71,0.21,0.01}
11 \definecolor{darkred}{rgb}{.52,0.08,0.01}
12 \definecolor{darkgreen}{rgb}{.12,.54,.11}
13
14 % Use and configure listings package for nicely formatted code
15 \usepackage{listings}
16 \lstset{
17 language=Python,
18 basicstyle=\small\ttfamily,
19 commentstyle=\ttfamily\color{blue},
20 stringstyle=\ttfamily\color{darkorange},
21 showstringspaces=false,
22 breaklines=true,
23 postbreak = \space\dots
24 }
25
26 \usepackage[%pdftex, % needed for pdflatex
27 breaklinks=true, % so long urls are correctly broken across lines
28 colorlinks=true,
29 urlcolor=blue,
30 linkcolor=darkred,
31 citecolor=darkgreen,
32 ]{hyperref}
33
7 \usepackage{html}
34 \usepackage{html}
35
36 % This helps prevent overly long lines that stretch beyond the margins
37 \sloppy
8 \end_preamble
38 \end_preamble
9 \language english
39 \language english
10 \inputencoding latin1
40 \inputencoding latin1
11 \fontscheme default
41 \fontscheme palatino
12 \graphics default
42 \graphics default
13 \paperfontsize default
43 \paperfontsize 10
14 \spacing single
44 \spacing single
15 \papersize Default
45 \papersize Default
16 \paperpackage a4
46 \paperpackage a4
17 \use_geometry 1
47 \use_geometry 1
18 \use_amsmath 0
48 \use_amsmath 0
19 \use_natbib 0
49 \use_natbib 0
20 \use_numerical_citations 0
50 \use_numerical_citations 0
21 \paperorientation portrait
51 \paperorientation portrait
22 \leftmargin 1.25in
52 \leftmargin 1.1in
23 \topmargin 1in
53 \topmargin 1in
24 \rightmargin 1.25in
54 \rightmargin 1.1in
25 \bottommargin 1in
55 \bottommargin 1in
26 \secnumdepth 3
56 \secnumdepth 3
27 \tocdepth 3
57 \tocdepth 3
28 \paragraph_separation skip
58 \paragraph_separation skip
29 \defskip medskip
59 \defskip medskip
30 \quotes_language english
60 \quotes_language english
31 \quotes_times 2
61 \quotes_times 2
32 \papercolumns 1
62 \papercolumns 1
33 \papersides 1
63 \papersides 1
34 \paperpagestyle fancy
64 \paperpagestyle fancy
35
65
36 \layout Title
66 \layout Title
37
67
38 IPython
68 IPython
39 \newline
69 \newline
40
70
41 \size larger
71 \size larger
42 An enhanced Interactive Python
72 An enhanced Interactive Python
43 \size large
73 \size large
44
74
45 \newline
75 \newline
46 User Manual, v.
76 User Manual, v.
47 __version__
77 __version__
48 \layout Author
78 \layout Author
49
79
50 Fernando P�rez
80 Fernando P�rez
51 \layout Standard
81 \layout Standard
52
82
53
83
54 \begin_inset ERT
84 \begin_inset ERT
55 status Collapsed
85 status Collapsed
56
86
57 \layout Standard
87 \layout Standard
58
88
59 \backslash
89 \backslash
60 latex{
90 latex{
61 \end_inset
91 \end_inset
62
92
63
93
64 \begin_inset LatexCommand \tableofcontents{}
94 \begin_inset LatexCommand \tableofcontents{}
65
95
66 \end_inset
96 \end_inset
67
97
68
98
69 \begin_inset ERT
99 \begin_inset ERT
70 status Collapsed
100 status Collapsed
71
101
72 \layout Standard
102 \layout Standard
73 }
103 }
74 \end_inset
104 \end_inset
75
105
76
106
77 \layout Standard
107 \layout Standard
78
108
79
109
80 \begin_inset ERT
110 \begin_inset ERT
81 status Open
111 status Open
82
112
83 \layout Standard
113 \layout Standard
84
114
85 \backslash
115 \backslash
86 html{
116 html{
87 \backslash
117 \backslash
88 bodytext{bgcolor=#ffffff}}
118 bodytext{bgcolor=#ffffff}}
89 \end_inset
119 \end_inset
90
120
91
121
92 \layout Section
122 \layout Section
93 \pagebreak_top
123 \pagebreak_top
94 Overview
124 Overview
95 \layout Standard
125 \layout Standard
96
126
97 One of Python's most useful features is its interactive interpreter.
127 One of Python's most useful features is its interactive interpreter.
98 This system allows very fast testing of ideas without the overhead of creating
128 This system allows very fast testing of ideas without the overhead of creating
99 test files as is typical in most programming languages.
129 test files as is typical in most programming languages.
100 However, the interpreter supplied with the standard Python distribution
130 However, the interpreter supplied with the standard Python distribution
101 is somewhat limited for extended interactive use.
131 is somewhat limited for extended interactive use.
102 \layout Standard
132 \layout Standard
103
133
104 IPython is a free software project (released under the BSD license) which
134 IPython is a free software project (released under the BSD license) which
105 tries to:
135 tries to:
106 \layout Enumerate
136 \layout Enumerate
107
137
108 Provide an interactive shell superior to Python's default.
138 Provide an interactive shell superior to Python's default.
109 IPython has many features for object introspection, system shell access,
139 IPython has many features for object introspection, system shell access,
110 and its own special command system for adding functionality when working
140 and its own special command system for adding functionality when working
111 interactively.
141 interactively.
112 It tries to be a very efficient environment both for Python code development
142 It tries to be a very efficient environment both for Python code development
113 and for exploration of problems using Python objects (in situations like
143 and for exploration of problems using Python objects (in situations like
114 data analysis).
144 data analysis).
115 \layout Enumerate
145 \layout Enumerate
116
146
117 Serve as an embeddable, ready to use interpreter for your own programs.
147 Serve as an embeddable, ready to use interpreter for your own programs.
118 IPython can be started with a single call from inside another program,
148 IPython can be started with a single call from inside another program,
119 providing access to the current namespace.
149 providing access to the current namespace.
120 This can be very useful both for debugging purposes and for situations
150 This can be very useful both for debugging purposes and for situations
121 where a blend of batch-processing and interactive exploration are needed.
151 where a blend of batch-processing and interactive exploration are needed.
122 \layout Enumerate
152 \layout Enumerate
123
153
124 Offer a flexible framework which can be used as the base environment for
154 Offer a flexible framework which can be used as the base environment for
125 other systems with Python as the underlying language.
155 other systems with Python as the underlying language.
126 Specifically scientific environments like Mathematica, IDL and Matlab inspired
156 Specifically scientific environments like Mathematica, IDL and Matlab inspired
127 its design, but similar ideas can be useful in many fields.
157 its design, but similar ideas can be useful in many fields.
128 \layout Subsection
158 \layout Subsection
129
159
130 Main features
160 Main features
131 \layout Itemize
161 \layout Itemize
132
162
133 Dynamic object introspection.
163 Dynamic object introspection.
134 One can access docstrings, function definition prototypes, source code,
164 One can access docstrings, function definition prototypes, source code,
135 source files and other details of any object accessible to the interpreter
165 source files and other details of any object accessible to the interpreter
136 with a single keystroke (`
166 with a single keystroke (`
137 \family typewriter
167 \family typewriter
138 ?
168 ?
139 \family default
169 \family default
140 ').
170 ').
141 \layout Itemize
171 \layout Itemize
142
172
143 Completion in the local namespace, by typing TAB at the prompt.
173 Completion in the local namespace, by typing TAB at the prompt.
144 This works for keywords, methods, variables and files in the current directory.
174 This works for keywords, methods, variables and files in the current directory.
145 This is supported via the readline library, and full access to configuring
175 This is supported via the readline library, and full access to configuring
146 readline's behavior is provided.
176 readline's behavior is provided.
147 \layout Itemize
177 \layout Itemize
148
178
149 Numbered input/output prompts with command history (persistent across sessions
179 Numbered input/output prompts with command history (persistent across sessions
150 and tied to each profile), full searching in this history and caching of
180 and tied to each profile), full searching in this history and caching of
151 all input and output.
181 all input and output.
152 \layout Itemize
182 \layout Itemize
153
183
154 User-extensible `magic' commands.
184 User-extensible `magic' commands.
155 A set of commands prefixed with
185 A set of commands prefixed with
156 \family typewriter
186 \family typewriter
157 %
187 %
158 \family default
188 \family default
159 is available for controlling IPython itself and provides directory control,
189 is available for controlling IPython itself and provides directory control,
160 namespace information and many aliases to common system shell commands.
190 namespace information and many aliases to common system shell commands.
161 \layout Itemize
191 \layout Itemize
162
192
163 Alias facility for defining your own system aliases.
193 Alias facility for defining your own system aliases.
164 \layout Itemize
194 \layout Itemize
165
195
166 Complete system shell access.
196 Complete system shell access.
167 Lines starting with ! are passed directly to the system shell, and using
197 Lines starting with ! are passed directly to the system shell, and using
168 !! captures shell output into python variables for further use.
198 !! captures shell output into python variables for further use.
169 \layout Itemize
199 \layout Itemize
170
200
171 All calls to the system (via aliases or via !) have their standard output/error
201 All calls to the system (via aliases or via !) have their standard output/error
172 automatically stored as strings, and also available as lists.
202 automatically stored as strings, and also available as lists.
173 \layout Itemize
203 \layout Itemize
174
204
175 Background execution of Python commands in a separate thread.
205 Background execution of Python commands in a separate thread.
176 IPython has an internal job manager called
206 IPython has an internal job manager called
177 \family typewriter
207 \family typewriter
178 jobs
208 jobs
179 \family default
209 \family default
180 , and a conveninence backgrounding magic function called
210 , and a conveninence backgrounding magic function called
181 \family typewriter
211 \family typewriter
182 %bg
212 %bg
183 \family default
213 \family default
184 .
214 .
185 \layout Itemize
215 \layout Itemize
186
216
187 The ability to expand python variables when calling the system shell.
217 The ability to expand python variables when calling the system shell.
188 In a shell command, any python variable prefixed with
218 In a shell command, any python variable prefixed with
189 \family typewriter
219 \family typewriter
190 $
220 $
191 \family default
221 \family default
192 is expanded.
222 is expanded.
193 A double
223 A double
194 \family typewriter
224 \family typewriter
195 $$
225 $$
196 \family default
226 \family default
197 allows passing a literal
227 allows passing a literal
198 \family typewriter
228 \family typewriter
199 $
229 $
200 \family default
230 \family default
201 to the shell (for access to shell and environment variables like
231 to the shell (for access to shell and environment variables like
202 \family typewriter
232 \family typewriter
203 $PATH
233 $PATH
204 \family default
234 \family default
205 ).
235 ).
206 \layout Itemize
236 \layout Itemize
207
237
208 Filesystem navigation, via a magic
238 Filesystem navigation, via a magic
209 \family typewriter
239 \family typewriter
210 %cd
240 %cd
211 \family default
241 \family default
212 command, along with a persistent bookmark system (using
242 command, along with a persistent bookmark system (using
213 \family typewriter
243 \family typewriter
214 %bookmark
244 %bookmark
215 \family default
245 \family default
216 ) for fast access to frequently visited directories.
246 ) for fast access to frequently visited directories.
217 \layout Itemize
247 \layout Itemize
218
248
219 Automatic indentation (optional) of code as you type (through the readline
249 Automatic indentation (optional) of code as you type (through the readline
220 library).
250 library).
221 \layout Itemize
251 \layout Itemize
222
252
223 Macro system for quickly re-executing multiple lines of previous input with
253 Macro system for quickly re-executing multiple lines of previous input with
224 a single name.
254 a single name.
225 \layout Itemize
255 \layout Itemize
226
256
227 Session logging (you can then later use these logs as code in your programs).
257 Session logging (you can then later use these logs as code in your programs).
228 \layout Itemize
258 \layout Itemize
229
259
230 Session restoring: logs can be replayed to restore a previous session to
260 Session restoring: logs can be replayed to restore a previous session to
231 the state where you left it.
261 the state where you left it.
232 \layout Itemize
262 \layout Itemize
233
263
234 Verbose and colored exception traceback printouts.
264 Verbose and colored exception traceback printouts.
235 Easier to parse visually, and in verbose mode they produce a lot of useful
265 Easier to parse visually, and in verbose mode they produce a lot of useful
236 debugging information (basically a terminal version of the cgitb module).
266 debugging information (basically a terminal version of the cgitb module).
237 \layout Itemize
267 \layout Itemize
238
268
239 Auto-parentheses: callable objects can be executed without parentheses:
269 Auto-parentheses: callable objects can be executed without parentheses:
240
270
241 \family typewriter
271 \family typewriter
242 `sin 3'
272 `sin 3'
243 \family default
273 \family default
244 is automatically converted to
274 is automatically converted to
245 \family typewriter
275 \family typewriter
246 `sin(3)
276 `sin(3)
247 \family default
277 \family default
248 '.
278 '.
249 \layout Itemize
279 \layout Itemize
250
280
251 Auto-quoting: using `
281 Auto-quoting: using `
252 \family typewriter
282 \family typewriter
253 ,
283 ,
254 \family default
284 \family default
255 ' or `
285 ' or `
256 \family typewriter
286 \family typewriter
257 ;
287 ;
258 \family default
288 \family default
259 ' as the first character forces auto-quoting of the rest of the line:
289 ' as the first character forces auto-quoting of the rest of the line:
260 \family typewriter
290 \family typewriter
261 `,my_function a\SpecialChar ~
291 `,my_function a\SpecialChar ~
262 b'
292 b'
263 \family default
293 \family default
264 becomes automatically
294 becomes automatically
265 \family typewriter
295 \family typewriter
266 `my_function("a","b")'
296 `my_function("a","b")'
267 \family default
297 \family default
268 , while
298 , while
269 \family typewriter
299 \family typewriter
270 `;my_function a\SpecialChar ~
300 `;my_function a\SpecialChar ~
271 b'
301 b'
272 \family default
302 \family default
273 becomes
303 becomes
274 \family typewriter
304 \family typewriter
275 `my_function("a b")'
305 `my_function("a b")'
276 \family default
306 \family default
277 .
307 .
278 \layout Itemize
308 \layout Itemize
279
309
280 Extensible input syntax.
310 Extensible input syntax.
281 You can define filters that pre-process user input to simplify input in
311 You can define filters that pre-process user input to simplify input in
282 special situations.
312 special situations.
283 This allows for example pasting multi-line code fragments which start with
313 This allows for example pasting multi-line code fragments which start with
284
314
285 \family typewriter
315 \family typewriter
286 `>>>'
316 `>>>'
287 \family default
317 \family default
288 or
318 or
289 \family typewriter
319 \family typewriter
290 `...'
320 `...'
291 \family default
321 \family default
292 such as those from other python sessions or the standard Python documentation.
322 such as those from other python sessions or the standard Python documentation.
293 \layout Itemize
323 \layout Itemize
294
324
295 Flexible configuration system.
325 Flexible configuration system.
296 It uses a configuration file which allows permanent setting of all command-line
326 It uses a configuration file which allows permanent setting of all command-line
297 options, module loading, code and file execution.
327 options, module loading, code and file execution.
298 The system allows recursive file inclusion, so you can have a base file
328 The system allows recursive file inclusion, so you can have a base file
299 with defaults and layers which load other customizations for particular
329 with defaults and layers which load other customizations for particular
300 projects.
330 projects.
301 \layout Itemize
331 \layout Itemize
302
332
303 Embeddable.
333 Embeddable.
304 You can call IPython as a python shell inside your own python programs.
334 You can call IPython as a python shell inside your own python programs.
305 This can be used both for debugging code or for providing interactive abilities
335 This can be used both for debugging code or for providing interactive abilities
306 to your programs with knowledge about the local namespaces (very useful
336 to your programs with knowledge about the local namespaces (very useful
307 in debugging and data analysis situations).
337 in debugging and data analysis situations).
308 \layout Itemize
338 \layout Itemize
309
339
310 Easy debugger access.
340 Easy debugger access.
311 You can set IPython to call up the Python debugger (pdb) every time there
341 You can set IPython to call up the Python debugger (pdb) every time there
312 is an uncaught exception.
342 is an uncaught exception.
313 This drops you inside the code which triggered the exception with all the
343 This drops you inside the code which triggered the exception with all the
314 data live and it is possible to navigate the stack to rapidly isolate the
344 data live and it is possible to navigate the stack to rapidly isolate the
315 source of a bug.
345 source of a bug.
316 The
346 The
317 \family typewriter
347 \family typewriter
318 %run
348 %run
319 \family default
349 \family default
320 magic command --with the
350 magic command --with the
321 \family typewriter
351 \family typewriter
322 -d
352 -d
323 \family default
353 \family default
324 option-- can run any script under
354 option-- can run any script under
325 \family typewriter
355 \family typewriter
326 pdb
356 pdb
327 \family default
357 \family default
328 's control, automatically setting initial breakpoints for you.
358 's control, automatically setting initial breakpoints for you.
329 \layout Itemize
359 \layout Itemize
330
360
331 Profiler support.
361 Profiler support.
332 You can run single statements (similar to
362 You can run single statements (similar to
333 \family typewriter
363 \family typewriter
334 profile.run()
364 profile.run()
335 \family default
365 \family default
336 ) or complete programs under the profiler's control.
366 ) or complete programs under the profiler's control.
337 While this is possible with the standard
367 While this is possible with the standard
338 \family typewriter
368 \family typewriter
339 profile
369 profile
340 \family default
370 \family default
341 module, IPython wraps this functionality with magic commands (see
371 module, IPython wraps this functionality with magic commands (see
342 \family typewriter
372 \family typewriter
343 `%prun'
373 `%prun'
344 \family default
374 \family default
345 and
375 and
346 \family typewriter
376 \family typewriter
347 `%run -p
377 `%run -p
348 \family default
378 \family default
349 ') convenient for rapid interactive work.
379 ') convenient for rapid interactive work.
350 \layout Subsection
380 \layout Subsection
351
381
352 Portability and Python requirements
382 Portability and Python requirements
353 \layout Standard
383 \layout Standard
354
384
355
385
356 \series bold
386 \series bold
357 Python requirements:
387 Python requirements:
358 \series default
388 \series default
359 IPython works with Python version 2.2 or newer.
389 IPython works with Python version 2.2 or newer.
360 It has been tested with Python 2.4 and no problems have been reported.
390 It has been tested with Python 2.4 and no problems have been reported.
361 Support for Python 2.1 hasn't been recently tested, since I don't have access
391 Support for Python 2.1 hasn't been recently tested, since I don't have access
362 to it on any of my systems.
392 to it on any of my systems.
363 But I suspect there may be some problems with Python 2.1, because some of
393 But I suspect there may be some problems with Python 2.1, because some of
364 the newer code may use 2.2 features.
394 the newer code may use 2.2 features.
365 \layout Standard
395 \layout Standard
366
396
367 IPython is developed under
397 IPython is developed under
368 \series bold
398 \series bold
369 Linux
399 Linux
370 \series default
400 \series default
371 , but it should work in any reasonable Unix-type system (tested OK under
401 , but it should work in any reasonable Unix-type system (tested OK under
372 Solaris and the *BSD family, for which a port exists thanks to Dryice Liu).
402 Solaris and the *BSD family, for which a port exists thanks to Dryice Liu).
373 \layout Standard
403 \layout Standard
374
404
375
405
376 \series bold
406 \series bold
377 Mac OS X
407 Mac OS X
378 \series default
408 \series default
379 : it works, apparently without any problems (thanks to Jim Boyle at Lawrence
409 : it works, apparently without any problems (thanks to Jim Boyle at Lawrence
380 Livermore for the information).
410 Livermore for the information).
381 Thanks to Andrea Riciputi, Fink support is available.
411 Thanks to Andrea Riciputi, Fink support is available.
382 \layout Standard
412 \layout Standard
383
413
384
414
385 \series bold
415 \series bold
386 CygWin
416 CygWin
387 \series default
417 \series default
388 : it works mostly OK, though some users have reported problems with prompt
418 : it works mostly OK, though some users have reported problems with prompt
389 coloring.
419 coloring.
390 No satisfactory solution to this has been found so far, you may want to
420 No satisfactory solution to this has been found so far, you may want to
391 disable colors permanently in the
421 disable colors permanently in the
392 \family typewriter
422 \family typewriter
393 ipythonrc
423 ipythonrc
394 \family default
424 \family default
395 configuration file if you experience problems.
425 configuration file if you experience problems.
396 If you have proper color support under cygwin, please post to the IPython
426 If you have proper color support under cygwin, please post to the IPython
397 mailing list so this issue can be resolved for all users.
427 mailing list so this issue can be resolved for all users.
398 \layout Standard
428 \layout Standard
399
429
400
430
401 \series bold
431 \series bold
402 Windows
432 Windows
403 \series default
433 \series default
404 : it works well under Windows XP/2k, and I suspect NT should behave similarly.
434 : it works well under Windows XP/2k, and I suspect NT should behave similarly.
405 Section\SpecialChar ~
435 Section\SpecialChar ~
406
436
407 \begin_inset LatexCommand \ref{sub:Under-Windows}
437 \begin_inset LatexCommand \ref{sub:Under-Windows}
408
438
409 \end_inset
439 \end_inset
410
440
411 describes installation details for Windows, including some additional tools
441 describes installation details for Windows, including some additional tools
412 needed on this platform.
442 needed on this platform.
413 \layout Standard
443 \layout Standard
414
444
415 Windows 9x support is present, and has been reported to work fine (at least
445 Windows 9x support is present, and has been reported to work fine (at least
416 on WinME).
446 on WinME).
417 \layout Standard
447 \layout Standard
418
448
419 Please note, however, that I have very little access to and experience with
449 Please note, however, that I have very little access to and experience with
420 Windows development.
450 Windows development.
421 For this reason, Windows-specific bugs tend to linger far longer than I
451 For this reason, Windows-specific bugs tend to linger far longer than I
422 would like, and often I just can't find a satisfactory solution.
452 would like, and often I just can't find a satisfactory solution.
423 If any Windows user wants to join in with development help, all hands are
453 If any Windows user wants to join in with development help, all hands are
424 always welcome.
454 always welcome.
425 \layout Subsection
455 \layout Subsection
426
456
427 Location
457 Location
428 \layout Standard
458 \layout Standard
429
459
430 IPython is generously hosted at
460 IPython is generously hosted at
431 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
461 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
432
462
433 \end_inset
463 \end_inset
434
464
435 by the SciPy project.
465 by the SciPy project.
436 This site offers downloads, CVS access, mailing lists and a bug tracking
466 This site offers downloads, subversion access, mailing lists and a bug
437 system.
467 tracking system.
438 I am very grateful to Enthought (
468 I am very grateful to Enthought (
439 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
469 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
440
470
441 \end_inset
471 \end_inset
442
472
443 ) and all of the SciPy team for their contribution.
473 ) and all of the SciPy team for their contribution.
444 \layout Section
474 \layout Section
445
475
446
476
447 \begin_inset LatexCommand \label{sec:install}
477 \begin_inset LatexCommand \label{sec:install}
448
478
449 \end_inset
479 \end_inset
450
480
451 Installation
481 Installation
452 \layout Subsection
482 \layout Subsection
453
483
454 Instant instructions
484 Instant instructions
455 \layout Standard
485 \layout Standard
456
486
457 If you are of the impatient kind, under Linux/Unix simply untar/unzip the
487 If you are of the impatient kind, under Linux/Unix simply untar/unzip the
458 download, then install with
488 download, then install with
459 \family typewriter
489 \family typewriter
460 `python setup.py install'
490 `python setup.py install'
461 \family default
491 \family default
462 .
492 .
463 Under Windows, double-click on the provided
493 Under Windows, double-click on the provided
464 \family typewriter
494 \family typewriter
465 .exe
495 .exe
466 \family default
496 \family default
467 binary installer.
497 binary installer.
468 \layout Standard
498 \layout Standard
469
499
470 Then, take a look at Sections
500 Then, take a look at Sections
471 \begin_inset LatexCommand \ref{sec:good_config}
501 \begin_inset LatexCommand \ref{sec:good_config}
472
502
473 \end_inset
503 \end_inset
474
504
475 for configuring things optimally and
505 for configuring things optimally and
476 \begin_inset LatexCommand \ref{sec:quick_tips}
506 \begin_inset LatexCommand \ref{sec:quick_tips}
477
507
478 \end_inset
508 \end_inset
479
509
480 for quick tips on efficient use of IPython.
510 for quick tips on efficient use of IPython.
481 You can later refer to the rest of the manual for all the gory details.
511 You can later refer to the rest of the manual for all the gory details.
482 \layout Standard
512 \layout Standard
483
513
484 See the notes in sec.
514 See the notes in sec.
485
515
486 \begin_inset LatexCommand \ref{sec:upgrade}
516 \begin_inset LatexCommand \ref{sec:upgrade}
487
517
488 \end_inset
518 \end_inset
489
519
490 for upgrading IPython versions.
520 for upgrading IPython versions.
491 \layout Subsection
521 \layout Subsection
492
522
493 Detailed Unix instructions (Linux, Mac OS X, etc.)
523 Detailed Unix instructions (Linux, Mac OS X, etc.)
494 \layout Standard
524 \layout Standard
495
525
496
526
497 \begin_inset ERT
527 \begin_inset ERT
498 status Open
528 status Open
499
529
500 \layout Standard
530 \layout Standard
501
531
502 \backslash
532 \backslash
503 html{
533 html{
504 \backslash
534 \backslash
505 textbf{A warning to readers of the HTML version of this manual}: all options below are preceded with with TWO dashes and no intervening space between the dashes (e.g. Dash-Dash-home). The default HTML conversion tools mangle these into a single dash.}
535 textbf{A warning to readers of the HTML version of this manual}: all options below are preceded with with TWO dashes and no intervening space between the dashes (e.g. Dash-Dash-home). The default HTML conversion tools mangle these into a single dash.}
506 \end_inset
536 \end_inset
507
537
508
538
509 \layout Standard
539 \layout Standard
510
540
511 For RPM based systems, simply install the supplied package in the usual
541 For RPM based systems, simply install the supplied package in the usual
512 manner.
542 manner.
513 If you download the tar archive, the process is:
543 If you download the tar archive, the process is:
514 \layout Enumerate
544 \layout Enumerate
515
545
516 Unzip/untar the
546 Unzip/untar the
517 \family typewriter
547 \family typewriter
518 ipython-XXX.tar.gz
548 ipython-XXX.tar.gz
519 \family default
549 \family default
520 file wherever you want (
550 file wherever you want (
521 \family typewriter
551 \family typewriter
522 XXX
552 XXX
523 \family default
553 \family default
524 is the version number).
554 is the version number).
525 It will make a directory called
555 It will make a directory called
526 \family typewriter
556 \family typewriter
527 ipython-XXX.
557 ipython-XXX.
528
558
529 \family default
559 \family default
530 Change into that directory where you will find the files
560 Change into that directory where you will find the files
531 \family typewriter
561 \family typewriter
532 README
562 README
533 \family default
563 \family default
534 and
564 and
535 \family typewriter
565 \family typewriter
536 setup.py
566 setup.py
537 \family default
567 \family default
538 .
568 .
539
569
540 \family typewriter
570 \family typewriter
541 O
571 O
542 \family default
572 \family default
543 nce you've completed the installation, you can safely remove this directory.
573 nce you've completed the installation, you can safely remove this directory.
544
574
545 \layout Enumerate
575 \layout Enumerate
546
576
547 If you are installing over a previous installation of version 0.2.0 or earlier,
577 If you are installing over a previous installation of version 0.2.0 or earlier,
548 first remove your
578 first remove your
549 \family typewriter
579 \family typewriter
550 $HOME/.ipython
580 $HOME/.ipython
551 \family default
581 \family default
552 directory, since the configuration file format has changed somewhat (the
582 directory, since the configuration file format has changed somewhat (the
553 '=' were removed from all option specifications).
583 '=' were removed from all option specifications).
554 Or you can call ipython with the
584 Or you can call ipython with the
555 \family typewriter
585 \family typewriter
556 -upgrade
586 -upgrade
557 \family default
587 \family default
558 option and it will do this automatically for you.
588 option and it will do this automatically for you.
559 \layout Enumerate
589 \layout Enumerate
560
590
561 IPython uses distutils, so you can install it by simply typing at the system
591 IPython uses distutils, so you can install it by simply typing at the system
562 prompt (don't type the
592 prompt (don't type the
563 \family typewriter
593 \family typewriter
564 $
594 $
565 \family default
595 \family default
566 )
596 )
567 \newline
597 \newline
568
598
569 \family typewriter
599 \family typewriter
570 $ python setup.py install
600 $ python setup.py install
571 \family default
601 \family default
572
602
573 \newline
603 \newline
574 Note that this assumes you have root access to your machine.
604 Note that this assumes you have root access to your machine.
575 If you don't have root access or don't want IPython to go in the default
605 If you don't have root access or don't want IPython to go in the default
576 python directories, you'll need to use the
606 python directories, you'll need to use the
577 \family typewriter
607 \family typewriter
578 --home
608 --home
579 \family default
609 \family default
580 option (or
610 option (or
581 \family typewriter
611 \family typewriter
582 --prefix
612 --prefix
583 \family default
613 \family default
584 ).
614 ).
585 For example:
615 For example:
586 \newline
616 \newline
587
617
588 \family typewriter
618 \family typewriter
589 $ python setup.py install --home $HOME/local
619 $ python setup.py install --home $HOME/local
590 \family default
620 \family default
591
621
592 \newline
622 \newline
593 will install
623 will install
594 \begin_inset Foot
624 \begin_inset Foot
595 collapsed true
625 collapsed true
596
626
597 \layout Standard
627 \layout Standard
598
628
599 If you are reading these instructions in HTML format, please note that the
629 If you are reading these instructions in HTML format, please note that the
600 option is --home, with
630 option is --home, with
601 \emph on
631 \emph on
602 two
632 two
603 \emph default
633 \emph default
604 dashes.
634 dashes.
605 The automatic HTML conversion program seems to eat up one of the dashes,
635 The automatic HTML conversion program seems to eat up one of the dashes,
606 unfortunately (it's ok in the PDF version).
636 unfortunately (it's ok in the PDF version).
607 \end_inset
637 \end_inset
608
638
609 IPython into
639 IPython into
610 \family typewriter
640 \family typewriter
611 $HOME/local
641 $HOME/local
612 \family default
642 \family default
613 and its subdirectories (creating them if necessary).
643 and its subdirectories (creating them if necessary).
614 \newline
644 \newline
615 You can type
645 You can type
616 \newline
646 \newline
617
647
618 \family typewriter
648 \family typewriter
619 $ python setup.py --help
649 $ python setup.py --help
620 \family default
650 \family default
621
651
622 \newline
652 \newline
623 for more details.
653 for more details.
624 \newline
654 \newline
625 Note that if you change the default location for
655 Note that if you change the default location for
626 \family typewriter
656 \family typewriter
627 --home
657 --home
628 \family default
658 \family default
629 at installation, IPython may end up installed at a location which is not
659 at installation, IPython may end up installed at a location which is not
630 part of your
660 part of your
631 \family typewriter
661 \family typewriter
632 $PYTHONPATH
662 $PYTHONPATH
633 \family default
663 \family default
634 environment variable.
664 environment variable.
635 In this case, you'll need to configure this variable to include the actual
665 In this case, you'll need to configure this variable to include the actual
636 directory where the
666 directory where the
637 \family typewriter
667 \family typewriter
638 IPython/
668 IPython/
639 \family default
669 \family default
640 directory ended (typically the value you give to
670 directory ended (typically the value you give to
641 \family typewriter
671 \family typewriter
642 --home
672 --home
643 \family default
673 \family default
644 plus
674 plus
645 \family typewriter
675 \family typewriter
646 /lib/python
676 /lib/python
647 \family default
677 \family default
648 ).
678 ).
649 \layout Subsubsection
679 \layout Subsubsection
650
680
651 Mac OSX information
681 Mac OSX information
652 \layout Standard
682 \layout Standard
653
683
654 Under OSX, there is a choice you need to make.
684 Under OSX, there is a choice you need to make.
655 Apple ships its own build of Python, which lives in the core OSX filesystem
685 Apple ships its own build of Python, which lives in the core OSX filesystem
656 hierarchy.
686 hierarchy.
657 You can also manually install a separate Python, either purely by hand
687 You can also manually install a separate Python, either purely by hand
658 (typically in
688 (typically in
659 \family typewriter
689 \family typewriter
660 /usr/local
690 /usr/local
661 \family default
691 \family default
662 ) or by using Fink, which puts everything under
692 ) or by using Fink, which puts everything under
663 \family typewriter
693 \family typewriter
664 /sw
694 /sw
665 \family default
695 \family default
666 .
696 .
667 Which route to follow is a matter of personal preference, as I've seen
697 Which route to follow is a matter of personal preference, as I've seen
668 users who favor each of the approaches.
698 users who favor each of the approaches.
669 Here I will simply list the known installation issues under OSX, along
699 Here I will simply list the known installation issues under OSX, along
670 with their solutions.
700 with their solutions.
671 \layout Subsubsection*
701 \layout Subsubsection*
672
702
673 GUI problems
703 GUI problems
674 \layout Standard
704 \layout Standard
675
705
676 The following instructions apply to an install of IPython under OSX from
706 The following instructions apply to an install of IPython under OSX from
677 unpacking the
707 unpacking the
678 \family typewriter
708 \family typewriter
679 .tar.gz
709 .tar.gz
680 \family default
710 \family default
681 distribution and installing it for the default Python interpreter shipped
711 distribution and installing it for the default Python interpreter shipped
682 by Apple.
712 by Apple.
683 If you are using a fink install, fink will take care of these details for
713 If you are using a fink install, fink will take care of these details for
684 you, by installing IPython against fink's Python.
714 you, by installing IPython against fink's Python.
685 \layout Standard
715 \layout Standard
686
716
687 IPython offers various forms of support for interacting with graphical applicati
717 IPython offers various forms of support for interacting with graphical applicati
688 ons from the command line, from simple Tk apps (which are in principle always
718 ons from the command line, from simple Tk apps (which are in principle always
689 supported by Python) to interactive control of WX, QT and GTK apps.
719 supported by Python) to interactive control of WX, QT and GTK apps.
690 Under OSX, however, this requires that ipython is installed by calling
720 Under OSX, however, this requires that ipython is installed by calling
691 the special
721 the special
692 \family typewriter
722 \family typewriter
693 pythonw
723 pythonw
694 \family default
724 \family default
695 script at installation time, which takes care of coordinating things with
725 script at installation time, which takes care of coordinating things with
696 Apple's graphical environment.
726 Apple's graphical environment.
697 \layout Standard
727 \layout Standard
698
728
699 So when installing under OSX, it is best to use the following command
729 So when installing under OSX, it is best to use the following command
700 \begin_inset ERT
730 \begin_inset ERT
701 status Collapsed
731 status Collapsed
702
732
703 \layout Standard
733 \layout Standard
704
734
705 \backslash
735 \backslash
706 html{
736 html{
707 \backslash
737 \backslash
708 emph{[Again, in the HTML manual, the option is called -~-install=scripts, with TWO dashes and no intervening space between the dashes]}}
738 emph{[Again, in the HTML manual, the option is called -~-install=scripts, with TWO dashes and no intervening space between the dashes]}}
709 \end_inset
739 \end_inset
710
740
711 :
741 :
712 \family typewriter
742 \family typewriter
713
743
714 \newline
744 \newline
715 \SpecialChar ~
745 \SpecialChar ~
716 \SpecialChar ~
746 \SpecialChar ~
717 $ sudo pythonw setup.py install --install-scripts=/usr/local/bin
747 $ sudo pythonw setup.py install --install-scripts=/usr/local/bin
718 \family default
748 \family default
719
749
720 \newline
750 \newline
721 or
751 or
722 \family typewriter
752 \family typewriter
723
753
724 \newline
754 \newline
725 \SpecialChar ~
755 \SpecialChar ~
726 \SpecialChar ~
756 \SpecialChar ~
727 $ sudo pythonw setup.py install --install-scripts=/usr/bin
757 $ sudo pythonw setup.py install --install-scripts=/usr/bin
728 \newline
758 \newline
729
759
730 \family default
760 \family default
731 depending on where you like to keep hand-installed executables.
761 depending on where you like to keep hand-installed executables.
732 \layout Standard
762 \layout Standard
733
763
734 The resulting script will have an appropriate shebang line (the first line
764 The resulting script will have an appropriate shebang line (the first line
735 in the script whic begins with
765 in the script whic begins with
736 \family typewriter
766 \family typewriter
737 #!...
767 #!...
738 \family default
768 \family default
739 ) such that the ipython interpreter can interact with the OS X GUI.
769 ) such that the ipython interpreter can interact with the OS X GUI.
740 If the installed version does not work and has a shebang line that points
770 If the installed version does not work and has a shebang line that points
741 to, for example, just
771 to, for example, just
742 \family typewriter
772 \family typewriter
743 /usr/bin/python
773 /usr/bin/python
744 \family default
774 \family default
745 , then you might have a stale, cached version in your
775 , then you might have a stale, cached version in your
746 \family typewriter
776 \family typewriter
747 build/scripts-<python-version>
777 build/scripts-<python-version>
748 \family default
778 \family default
749 directory.
779 directory.
750 Delete that directory and rerun the
780 Delete that directory and rerun the
751 \family typewriter
781 \family typewriter
752 setup.py
782 setup.py
753 \family default
783 \family default
754 .
784 .
755
785
756 \layout Standard
786 \layout Standard
757
787
758 It is also a good idea to use the special flag
788 It is also a good idea to use the special flag
759 \family typewriter
789 \family typewriter
760 --install-scripts
790 --install-scripts
761 \family default
791 \family default
762 as indicated above, to ensure that the ipython scripts end up in a location
792 as indicated above, to ensure that the ipython scripts end up in a location
763 which is part of your
793 which is part of your
764 \family typewriter
794 \family typewriter
765 $PATH
795 $PATH
766 \family default
796 \family default
767 .
797 .
768 Otherwise Apple's Python will put the scripts in an internal directory
798 Otherwise Apple's Python will put the scripts in an internal directory
769 not available by default at the command line (if you use
799 not available by default at the command line (if you use
770 \family typewriter
800 \family typewriter
771 /usr/local/bin
801 /usr/local/bin
772 \family default
802 \family default
773 , you need to make sure this is in your
803 , you need to make sure this is in your
774 \family typewriter
804 \family typewriter
775 $PATH
805 $PATH
776 \family default
806 \family default
777 , which may not be true by default).
807 , which may not be true by default).
778 \layout Subsubsection*
808 \layout Subsubsection*
779
809
780 Readline problems
810 Readline problems
781 \layout Standard
811 \layout Standard
782
812
783 By default, the Python version shipped by Apple does
813 By default, the Python version shipped by Apple does
784 \emph on
814 \emph on
785 not
815 not
786 \emph default
816 \emph default
787 include the readline library, so central to IPython's behavior.
817 include the readline library, so central to IPython's behavior.
788 If you install IPython against Apple's Python, you will not have arrow
818 If you install IPython against Apple's Python, you will not have arrow
789 keys, tab completion, etc.
819 keys, tab completion, etc.
790 For Mac OSX 10.3 (Panther), you can find a prebuilt readline library here:
820 For Mac OSX 10.3 (Panther), you can find a prebuilt readline library here:
791 \newline
821 \newline
792
822
793 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip}
823 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip}
794
824
795 \end_inset
825 \end_inset
796
826
797
827
798 \layout Standard
828 \layout Standard
799
829
800 If you are using OSX 10.4 (Tiger), after installing this package you need
830 If you are using OSX 10.4 (Tiger), after installing this package you need
801 to either:
831 to either:
802 \layout Enumerate
832 \layout Enumerate
803
833
804 move
834 move
805 \family typewriter
835 \family typewriter
806 readline.so
836 readline.so
807 \family default
837 \family default
808 from
838 from
809 \family typewriter
839 \family typewriter
810 /Library/Python/2.3
840 /Library/Python/2.3
811 \family default
841 \family default
812 to
842 to
813 \family typewriter
843 \family typewriter
814 /Library/Python/2.3/site-packages
844 /Library/Python/2.3/site-packages
815 \family default
845 \family default
816 , or
846 , or
817 \layout Enumerate
847 \layout Enumerate
818
848
819 install
849 install
820 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/TigerPython23Compat.pkg.zip}
850 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/TigerPython23Compat.pkg.zip}
821
851
822 \end_inset
852 \end_inset
823
853
824
854
825 \layout Standard
855 \layout Standard
826
856
827 Users installing against Fink's Python or a properly hand-built one should
857 Users installing against Fink's Python or a properly hand-built one should
828 not have this problem.
858 not have this problem.
829 \layout Subsection
859 \layout Subsection
830
860
831
861
832 \begin_inset LatexCommand \label{sub:Under-Windows}
862 \begin_inset LatexCommand \label{sub:Under-Windows}
833
863
834 \end_inset
864 \end_inset
835
865
836 Windows instructions
866 Windows instructions
837 \layout Standard
867 \layout Standard
838
868
839 While you can use IPython under Windows with only a stock Python installation,
869 While you can use IPython under Windows with only a stock Python installation,
840 there is one extension,
870 there is one extension,
841 \family typewriter
871 \family typewriter
842 readline
872 readline
843 \family default
873 \family default
844 , which will make the whole experience a lot more pleasant.
874 , which will make the whole experience a lot more pleasant.
845 It is almost a requirement, since IPython will complain in its absence
875 It is almost a requirement, since IPython will complain in its absence
846 (though it will function).
876 (though it will function).
847
877
848 \layout Standard
878 \layout Standard
849
879
850 The
880 The
851 \family typewriter
881 \family typewriter
852 readline
882 readline
853 \family default
883 \family default
854 extension needs two other libraries to work, so in all you need:
884 extension needs two other libraries to work, so in all you need:
855 \layout Enumerate
885 \layout Enumerate
856
886
857
887
858 \family typewriter
888 \family typewriter
859 PyWin32
889 PyWin32
860 \family default
890 \family default
861 from
891 from
862 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
892 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
863
893
864 \end_inset
894 \end_inset
865
895
866 .
896 .
867 \layout Enumerate
897 \layout Enumerate
868
898
869
899
870 \family typewriter
900 \family typewriter
871 CTypes
901 CTypes
872 \family default
902 \family default
873 from
903 from
874 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
904 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
875
905
876 \end_inset
906 \end_inset
877
907
878 (you
908 (you
879 \emph on
909 \emph on
880 must
910 must
881 \emph default
911 \emph default
882 use version 0.9.1 or newer).
912 use version 0.9.1 or newer).
883 \layout Enumerate
913 \layout Enumerate
884
914
885
915
886 \family typewriter
916 \family typewriter
887 Readline
917 Readline
888 \family default
918 \family default
889 for Windows from
919 for Windows from
890 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/uncpythontools}
920 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/uncpythontools}
891
921
892 \end_inset
922 \end_inset
893
923
894 .
924 .
895 \layout Standard
925 \layout Standard
896
926
897
927
898 \series bold
928 \series bold
899 Warning about a broken readline-like library:
929 Warning about a broken readline-like library:
900 \series default
930 \series default
901 several users have reported problems stemming from using the pseudo-readline
931 several users have reported problems stemming from using the pseudo-readline
902 library at
932 library at
903 \begin_inset LatexCommand \htmlurl{http://newcenturycomputers.net/projects/readline.html}
933 \begin_inset LatexCommand \htmlurl{http://newcenturycomputers.net/projects/readline.html}
904
934
905 \end_inset
935 \end_inset
906
936
907 .
937 .
908 This is a broken library which, while called readline, only implements
938 This is a broken library which, while called readline, only implements
909 an incomplete subset of the readline API.
939 an incomplete subset of the readline API.
910 Since it is still called readline, it fools IPython's detection mechanisms
940 Since it is still called readline, it fools IPython's detection mechanisms
911 and causes unpredictable crashes later.
941 and causes unpredictable crashes later.
912 If you wish to use IPython under Windows, you must NOT use this library,
942 If you wish to use IPython under Windows, you must NOT use this library,
913 which for all purposes is (at least as of version 1.6) terminally broken.
943 which for all purposes is (at least as of version 1.6) terminally broken.
914 \layout Subsubsection
944 \layout Subsubsection
915
945
916 Gary Bishop's readline and color support for Windows
946 Gary Bishop's readline and color support for Windows
917 \layout Standard
947 \layout Standard
918
948
919 Some of IPython's very useful features are:
949 Some of IPython's very useful features are:
920 \layout Itemize
950 \layout Itemize
921
951
922 Integrated readline support (Tab-based file, object and attribute completion,
952 Integrated readline support (Tab-based file, object and attribute completion,
923 input history across sessions, editable command line, etc.)
953 input history across sessions, editable command line, etc.)
924 \layout Itemize
954 \layout Itemize
925
955
926 Coloring of prompts, code and tracebacks.
956 Coloring of prompts, code and tracebacks.
927 \layout Standard
957 \layout Standard
928
958
929 These, by default, are only available under Unix-like operating systems.
959 These, by default, are only available under Unix-like operating systems.
930 However, thanks to Gary Bishop's work, Windows XP/2k users can also benefit
960 However, thanks to Gary Bishop's work, Windows XP/2k users can also benefit
931 from them.
961 from them.
932 His readline library implements both GNU readline functionality and color
962 His readline library implements both GNU readline functionality and color
933 support, so that IPython under Windows XP/2k can be as friendly and powerful
963 support, so that IPython under Windows XP/2k can be as friendly and powerful
934 as under Unix-like environments.
964 as under Unix-like environments.
935 \layout Standard
965 \layout Standard
936
966
937 You can find Gary's tools at
967 You can find Gary's tools at
938 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/uncpythontools}
968 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/uncpythontools}
939
969
940 \end_inset
970 \end_inset
941
971
942 ; Gary's
972 ; Gary's
943 \family typewriter
973 \family typewriter
944 readline
974 readline
945 \family default
975 \family default
946 requires in turn the
976 requires in turn the
947 \family typewriter
977 \family typewriter
948 ctypes
978 ctypes
949 \family default
979 \family default
950 library by Thomas Heller, available at
980 library by Thomas Heller, available at
951 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
981 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
952
982
953 \end_inset
983 \end_inset
954
984
955 , and Mark Hammond's
985 , and Mark Hammond's
956 \family typewriter
986 \family typewriter
957 PyWin32
987 PyWin32
958 \family default
988 \family default
959 from
989 from
960 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
990 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
961
991
962 \end_inset
992 \end_inset
963
993
964 (
994 (
965 \family typewriter
995 \family typewriter
966 PyWin32
996 PyWin32
967 \family default
997 \family default
968 is great for anything Windows-related anyway, so you might as well get
998 is great for anything Windows-related anyway, so you might as well get
969 it).
999 it).
970 \layout Standard
1000 \layout Standard
971
1001
972 Under MS\SpecialChar ~
1002 Under MS\SpecialChar ~
973 Windows, IPython will complain if it can not find this
1003 Windows, IPython will complain if it can not find this
974 \family typewriter
1004 \family typewriter
975 readline
1005 readline
976 \family default
1006 \family default
977 library at startup and any time the
1007 library at startup and any time the
978 \family typewriter
1008 \family typewriter
979 %colors
1009 %colors
980 \family default
1010 \family default
981 command is issued, so you can consider it to be a quasi-requirement.
1011 command is issued, so you can consider it to be a quasi-requirement.
982 \layout Subsubsection
1012 \layout Subsubsection
983
1013
984 Installation procedure
1014 Installation procedure
985 \layout Standard
1015 \layout Standard
986
1016
987 Once you have the above installed, from the IPython download directory grab
1017 Once you have the above installed, from the IPython download directory grab
988 the
1018 the
989 \family typewriter
1019 \family typewriter
990 ipython-XXX.win32.exe
1020 ipython-XXX.win32.exe
991 \family default
1021 \family default
992 file, where
1022 file, where
993 \family typewriter
1023 \family typewriter
994 XXX
1024 XXX
995 \family default
1025 \family default
996 represents the version number.
1026 represents the version number.
997 This is a regular windows executable installer, which you can simply double-cli
1027 This is a regular windows executable installer, which you can simply double-cli
998 ck to install.
1028 ck to install.
999 It will add an entry for IPython to your Start Menu, as well as registering
1029 It will add an entry for IPython to your Start Menu, as well as registering
1000 IPython in the Windows list of applications, so you can later uninstall
1030 IPython in the Windows list of applications, so you can later uninstall
1001 it from the Control Panel.
1031 it from the Control Panel.
1002
1032
1003 \layout Standard
1033 \layout Standard
1004
1034
1005 IPython tries to install the configuration information in a directory named
1035 IPython tries to install the configuration information in a directory named
1006
1036
1007 \family typewriter
1037 \family typewriter
1008 .ipython
1038 .ipython
1009 \family default
1039 \family default
1010 (
1040 (
1011 \family typewriter
1041 \family typewriter
1012 _ipython
1042 _ipython
1013 \family default
1043 \family default
1014 under Windows) located in your `home' directory.
1044 under Windows) located in your `home' directory.
1015 IPython sets this directory by looking for a
1045 IPython sets this directory by looking for a
1016 \family typewriter
1046 \family typewriter
1017 HOME
1047 HOME
1018 \family default
1048 \family default
1019 environment variable; if such a variable does not exist, it uses
1049 environment variable; if such a variable does not exist, it uses
1020 \family typewriter
1050 \family typewriter
1021 HOMEDRIVE
1051 HOMEDRIVE
1022 \backslash
1052 \backslash
1023 HOMEPATH
1053 HOMEPATH
1024 \family default
1054 \family default
1025 (these are always defined by Windows).
1055 (these are always defined by Windows).
1026 This typically gives something like
1056 This typically gives something like
1027 \family typewriter
1057 \family typewriter
1028 C:
1058 C:
1029 \backslash
1059 \backslash
1030 Documents and Settings
1060 Documents and Settings
1031 \backslash
1061 \backslash
1032 YourUserName
1062 YourUserName
1033 \family default
1063 \family default
1034 , but your local details may vary.
1064 , but your local details may vary.
1035 In this directory you will find all the files that configure IPython's
1065 In this directory you will find all the files that configure IPython's
1036 defaults, and you can put there your profiles and extensions.
1066 defaults, and you can put there your profiles and extensions.
1037 This directory is automatically added by IPython to
1067 This directory is automatically added by IPython to
1038 \family typewriter
1068 \family typewriter
1039 sys.path
1069 sys.path
1040 \family default
1070 \family default
1041 , so anything you place there can be found by
1071 , so anything you place there can be found by
1042 \family typewriter
1072 \family typewriter
1043 import
1073 import
1044 \family default
1074 \family default
1045 statements.
1075 statements.
1046 \layout Paragraph
1076 \layout Paragraph
1047
1077
1048 Upgrading
1078 Upgrading
1049 \layout Standard
1079 \layout Standard
1050
1080
1051 For an IPython upgrade, you should first uninstall the previous version.
1081 For an IPython upgrade, you should first uninstall the previous version.
1052 This will ensure that all files and directories (such as the documentation)
1082 This will ensure that all files and directories (such as the documentation)
1053 which carry embedded version strings in their names are properly removed.
1083 which carry embedded version strings in their names are properly removed.
1054 \layout Paragraph
1084 \layout Paragraph
1055
1085
1056 Manual installation under Win32
1086 Manual installation under Win32
1057 \layout Standard
1087 \layout Standard
1058
1088
1059 In case the automatic installer does not work for some reason, you can download
1089 In case the automatic installer does not work for some reason, you can download
1060 the
1090 the
1061 \family typewriter
1091 \family typewriter
1062 ipython-XXX.tar.gz
1092 ipython-XXX.tar.gz
1063 \family default
1093 \family default
1064 file, which contains the full IPython source distribution (the popular
1094 file, which contains the full IPython source distribution (the popular
1065 WinZip can read
1095 WinZip can read
1066 \family typewriter
1096 \family typewriter
1067 .tar.gz
1097 .tar.gz
1068 \family default
1098 \family default
1069 files).
1099 files).
1070 After uncompressing the archive, you can install it at a command terminal
1100 After uncompressing the archive, you can install it at a command terminal
1071 just like any other Python module, by using
1101 just like any other Python module, by using
1072 \family typewriter
1102 \family typewriter
1073 `python setup.py install'
1103 `python setup.py install'
1074 \family default
1104 \family default
1075 .
1105 .
1076
1106
1077 \layout Standard
1107 \layout Standard
1078
1108
1079 After the installation, run the supplied
1109 After the installation, run the supplied
1080 \family typewriter
1110 \family typewriter
1081 win32_manual_post_install.py
1111 win32_manual_post_install.py
1082 \family default
1112 \family default
1083 script, which creates the necessary Start Menu shortcuts for you.
1113 script, which creates the necessary Start Menu shortcuts for you.
1084 \layout Subsection
1114 \layout Subsection
1085
1115
1086
1116
1087 \begin_inset LatexCommand \label{sec:upgrade}
1117 \begin_inset LatexCommand \label{sec:upgrade}
1088
1118
1089 \end_inset
1119 \end_inset
1090
1120
1091 Upgrading from a previous version
1121 Upgrading from a previous version
1092 \layout Standard
1122 \layout Standard
1093
1123
1094 If you are upgrading from a previous version of IPython, after doing the
1124 If you are upgrading from a previous version of IPython, after doing the
1095 routine installation described above, you should call IPython with the
1125 routine installation described above, you should call IPython with the
1096
1126
1097 \family typewriter
1127 \family typewriter
1098 -upgrade
1128 -upgrade
1099 \family default
1129 \family default
1100 option the first time you run your new copy.
1130 option the first time you run your new copy.
1101 This will automatically update your configuration directory while preserving
1131 This will automatically update your configuration directory while preserving
1102 copies of your old files.
1132 copies of your old files.
1103 You can then later merge back any personal customizations you may have
1133 You can then later merge back any personal customizations you may have
1104 made into the new files.
1134 made into the new files.
1105 It is a good idea to do this as there may be new options available in the
1135 It is a good idea to do this as there may be new options available in the
1106 new configuration files which you will not have.
1136 new configuration files which you will not have.
1107 \layout Standard
1137 \layout Standard
1108
1138
1109 Under Windows, if you don't know how to call python scripts with arguments
1139 Under Windows, if you don't know how to call python scripts with arguments
1110 from a command line, simply delete the old config directory and IPython
1140 from a command line, simply delete the old config directory and IPython
1111 will make a new one.
1141 will make a new one.
1112 Win2k and WinXP users will find it in
1142 Win2k and WinXP users will find it in
1113 \family typewriter
1143 \family typewriter
1114 C:
1144 C:
1115 \backslash
1145 \backslash
1116 Documents and Settings
1146 Documents and Settings
1117 \backslash
1147 \backslash
1118 YourUserName
1148 YourUserName
1119 \backslash
1149 \backslash
1120 .ipython
1150 .ipython
1121 \family default
1151 \family default
1122 , and Win 9x users under
1152 , and Win 9x users under
1123 \family typewriter
1153 \family typewriter
1124 C:
1154 C:
1125 \backslash
1155 \backslash
1126 Program Files
1156 Program Files
1127 \backslash
1157 \backslash
1128 IPython
1158 IPython
1129 \backslash
1159 \backslash
1130 .ipython.
1160 .ipython.
1131 \layout Section
1161 \layout Section
1132
1162
1133
1163
1134 \begin_inset LatexCommand \label{sec:good_config}
1164 \begin_inset LatexCommand \label{sec:good_config}
1135
1165
1136 \end_inset
1166 \end_inset
1137
1167
1138
1168
1139 \begin_inset OptArg
1169 \begin_inset OptArg
1140 collapsed true
1170 collapsed true
1141
1171
1142 \layout Standard
1172 \layout Standard
1143
1173
1144 Initial configuration
1174 Initial configuration
1145 \begin_inset ERT
1175 \begin_inset ERT
1146 status Collapsed
1176 status Collapsed
1147
1177
1148 \layout Standard
1178 \layout Standard
1149
1179
1150 \backslash
1180 \backslash
1151 ldots
1181 ldots
1152 \end_inset
1182 \end_inset
1153
1183
1154
1184
1155 \end_inset
1185 \end_inset
1156
1186
1157 Initial configuration of your environment
1187 Initial configuration of your environment
1158 \layout Standard
1188 \layout Standard
1159
1189
1160 This section will help you set various things in your environment for your
1190 This section will help you set various things in your environment for your
1161 IPython sessions to be as efficient as possible.
1191 IPython sessions to be as efficient as possible.
1162 All of IPython's configuration information, along with several example
1192 All of IPython's configuration information, along with several example
1163 files, is stored in a directory named by default
1193 files, is stored in a directory named by default
1164 \family typewriter
1194 \family typewriter
1165 $HOME/.ipython
1195 $HOME/.ipython
1166 \family default
1196 \family default
1167 .
1197 .
1168 You can change this by defining the environment variable
1198 You can change this by defining the environment variable
1169 \family typewriter
1199 \family typewriter
1170 IPYTHONDIR
1200 IPYTHONDIR
1171 \family default
1201 \family default
1172 , or at runtime with the command line option
1202 , or at runtime with the command line option
1173 \family typewriter
1203 \family typewriter
1174 -ipythondir
1204 -ipythondir
1175 \family default
1205 \family default
1176 .
1206 .
1177 \layout Standard
1207 \layout Standard
1178
1208
1179 If all goes well, the first time you run IPython it should automatically
1209 If all goes well, the first time you run IPython it should automatically
1180 create a user copy of the config directory for you, based on its builtin
1210 create a user copy of the config directory for you, based on its builtin
1181 defaults.
1211 defaults.
1182 You can look at the files it creates to learn more about configuring the
1212 You can look at the files it creates to learn more about configuring the
1183 system.
1213 system.
1184 The main file you will modify to configure IPython's behavior is called
1214 The main file you will modify to configure IPython's behavior is called
1185
1215
1186 \family typewriter
1216 \family typewriter
1187 ipythonrc
1217 ipythonrc
1188 \family default
1218 \family default
1189 (with a
1219 (with a
1190 \family typewriter
1220 \family typewriter
1191 .ini
1221 .ini
1192 \family default
1222 \family default
1193 extension under Windows), included for reference in Sec.
1223 extension under Windows), included for reference in Sec.
1194
1224
1195 \begin_inset LatexCommand \ref{sec:ipytonrc-sample}
1225 \begin_inset LatexCommand \ref{sec:ipytonrc-sample}
1196
1226
1197 \end_inset
1227 \end_inset
1198
1228
1199 .
1229 .
1200 This file is very commented and has many variables you can change to suit
1230 This file is very commented and has many variables you can change to suit
1201 your taste, you can find more details in Sec.
1231 your taste, you can find more details in Sec.
1202
1232
1203 \begin_inset LatexCommand \ref{sec:customization}
1233 \begin_inset LatexCommand \ref{sec:customization}
1204
1234
1205 \end_inset
1235 \end_inset
1206
1236
1207 .
1237 .
1208 Here we discuss the basic things you will want to make sure things are
1238 Here we discuss the basic things you will want to make sure things are
1209 working properly from the beginning.
1239 working properly from the beginning.
1210 \layout Subsection
1240 \layout Subsection
1211
1241
1212
1242
1213 \begin_inset LatexCommand \label{sec:help-access}
1243 \begin_inset LatexCommand \label{sec:help-access}
1214
1244
1215 \end_inset
1245 \end_inset
1216
1246
1217 Access to the Python help system
1247 Access to the Python help system
1218 \layout Standard
1248 \layout Standard
1219
1249
1220 This is true for Python in general (not just for IPython): you should have
1250 This is true for Python in general (not just for IPython): you should have
1221 an environment variable called
1251 an environment variable called
1222 \family typewriter
1252 \family typewriter
1223 PYTHONDOCS
1253 PYTHONDOCS
1224 \family default
1254 \family default
1225 pointing to the directory where your HTML Python documentation lives.
1255 pointing to the directory where your HTML Python documentation lives.
1226 In my system it's
1256 In my system it's
1227 \family typewriter
1257 \family typewriter
1228 /usr/share/doc/python-docs-2.3.4/html
1258 /usr/share/doc/python-docs-2.3.4/html
1229 \family default
1259 \family default
1230 , check your local details or ask your systems administrator.
1260 , check your local details or ask your systems administrator.
1231
1261
1232 \layout Standard
1262 \layout Standard
1233
1263
1234 This is the directory which holds the HTML version of the Python manuals.
1264 This is the directory which holds the HTML version of the Python manuals.
1235 Unfortunately it seems that different Linux distributions package these
1265 Unfortunately it seems that different Linux distributions package these
1236 files differently, so you may have to look around a bit.
1266 files differently, so you may have to look around a bit.
1237 Below I show the contents of this directory on my system for reference:
1267 Below I show the contents of this directory on my system for reference:
1238 \layout Standard
1268 \layout Standard
1239
1269
1240
1270
1241 \family typewriter
1271 \family typewriter
1242 [html]> ls
1272 [html]> ls
1243 \newline
1273 \newline
1244 about.dat acks.html dist/ ext/ index.html lib/ modindex.html stdabout.dat tut/
1274 about.dat acks.html dist/ ext/ index.html lib/ modindex.html stdabout.dat tut/
1245 about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
1275 about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
1246 \layout Standard
1276 \layout Standard
1247
1277
1248 You should really make sure this variable is correctly set so that Python's
1278 You should really make sure this variable is correctly set so that Python's
1249 pydoc-based help system works.
1279 pydoc-based help system works.
1250 It is a powerful and convenient system with full access to the Python manuals
1280 It is a powerful and convenient system with full access to the Python manuals
1251 and all modules accessible to you.
1281 and all modules accessible to you.
1252 \layout Standard
1282 \layout Standard
1253
1283
1254 Under Windows it seems that pydoc finds the documentation automatically,
1284 Under Windows it seems that pydoc finds the documentation automatically,
1255 so no extra setup appears necessary.
1285 so no extra setup appears necessary.
1256 \layout Subsection
1286 \layout Subsection
1257
1287
1258 Editor
1288 Editor
1259 \layout Standard
1289 \layout Standard
1260
1290
1261 The
1291 The
1262 \family typewriter
1292 \family typewriter
1263 %edit
1293 %edit
1264 \family default
1294 \family default
1265 command (and its alias
1295 command (and its alias
1266 \family typewriter
1296 \family typewriter
1267 %ed
1297 %ed
1268 \family default
1298 \family default
1269 ) will invoke the editor set in your environment as
1299 ) will invoke the editor set in your environment as
1270 \family typewriter
1300 \family typewriter
1271 EDITOR
1301 EDITOR
1272 \family default
1302 \family default
1273 .
1303 .
1274 If this variable is not set, it will default to
1304 If this variable is not set, it will default to
1275 \family typewriter
1305 \family typewriter
1276 vi
1306 vi
1277 \family default
1307 \family default
1278 under Linux/Unix and to
1308 under Linux/Unix and to
1279 \family typewriter
1309 \family typewriter
1280 notepad
1310 notepad
1281 \family default
1311 \family default
1282 under Windows.
1312 under Windows.
1283 You may want to set this variable properly and to a lightweight editor
1313 You may want to set this variable properly and to a lightweight editor
1284 which doesn't take too long to start (that is, something other than a new
1314 which doesn't take too long to start (that is, something other than a new
1285 instance of
1315 instance of
1286 \family typewriter
1316 \family typewriter
1287 Emacs
1317 Emacs
1288 \family default
1318 \family default
1289 ).
1319 ).
1290 This way you can edit multi-line code quickly and with the power of a real
1320 This way you can edit multi-line code quickly and with the power of a real
1291 editor right inside IPython.
1321 editor right inside IPython.
1292
1322
1293 \layout Standard
1323 \layout Standard
1294
1324
1295 If you are a dedicated
1325 If you are a dedicated
1296 \family typewriter
1326 \family typewriter
1297 Emacs
1327 Emacs
1298 \family default
1328 \family default
1299 user, you should set up the
1329 user, you should set up the
1300 \family typewriter
1330 \family typewriter
1301 Emacs
1331 Emacs
1302 \family default
1332 \family default
1303 server so that new requests are handled by the original process.
1333 server so that new requests are handled by the original process.
1304 This means that almost no time is spent in handling the request (assuming
1334 This means that almost no time is spent in handling the request (assuming
1305 an
1335 an
1306 \family typewriter
1336 \family typewriter
1307 Emacs
1337 Emacs
1308 \family default
1338 \family default
1309 process is already running).
1339 process is already running).
1310 For this to work, you need to set your
1340 For this to work, you need to set your
1311 \family typewriter
1341 \family typewriter
1312 EDITOR
1342 EDITOR
1313 \family default
1343 \family default
1314 environment variable to
1344 environment variable to
1315 \family typewriter
1345 \family typewriter
1316 'emacsclient'
1346 'emacsclient'
1317 \family default
1347 \family default
1318 .
1348 .
1319
1349
1320 \family typewriter
1350 \family typewriter
1321
1351
1322 \family default
1352 \family default
1323 The code below, supplied by Francois Pinard, can then be used in your
1353 The code below, supplied by Francois Pinard, can then be used in your
1324 \family typewriter
1354 \family typewriter
1325 .emacs
1355 .emacs
1326 \family default
1356 \family default
1327 file to enable the server:
1357 file to enable the server:
1328 \layout Standard
1358 \layout Standard
1329
1359
1330
1360
1331 \family typewriter
1361 \family typewriter
1332 (defvar server-buffer-clients)
1362 (defvar server-buffer-clients)
1333 \newline
1363 \newline
1334 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
1364 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
1335 \newline
1365 \newline
1336
1366
1337 \begin_inset ERT
1367 \begin_inset ERT
1338 status Collapsed
1368 status Collapsed
1339
1369
1340 \layout Standard
1370 \layout Standard
1341
1371
1342 \backslash
1372 \backslash
1343 hspace*{0mm}
1373 hspace*{0mm}
1344 \end_inset
1374 \end_inset
1345
1375
1346 \SpecialChar ~
1376 \SpecialChar ~
1347 \SpecialChar ~
1377 \SpecialChar ~
1348 (server-start)
1378 (server-start)
1349 \newline
1379 \newline
1350
1380
1351 \begin_inset ERT
1381 \begin_inset ERT
1352 status Collapsed
1382 status Collapsed
1353
1383
1354 \layout Standard
1384 \layout Standard
1355
1385
1356 \backslash
1386 \backslash
1357 hspace*{0mm}
1387 hspace*{0mm}
1358 \end_inset
1388 \end_inset
1359
1389
1360 \SpecialChar ~
1390 \SpecialChar ~
1361 \SpecialChar ~
1391 \SpecialChar ~
1362 (defun fp-kill-server-with-buffer-routine ()
1392 (defun fp-kill-server-with-buffer-routine ()
1363 \newline
1393 \newline
1364
1394
1365 \begin_inset ERT
1395 \begin_inset ERT
1366 status Collapsed
1396 status Collapsed
1367
1397
1368 \layout Standard
1398 \layout Standard
1369
1399
1370 \backslash
1400 \backslash
1371 hspace*{0mm}
1401 hspace*{0mm}
1372 \end_inset
1402 \end_inset
1373
1403
1374 \SpecialChar ~
1404 \SpecialChar ~
1375 \SpecialChar ~
1405 \SpecialChar ~
1376 \SpecialChar ~
1406 \SpecialChar ~
1377 \SpecialChar ~
1407 \SpecialChar ~
1378 (and server-buffer-clients (server-done)))
1408 (and server-buffer-clients (server-done)))
1379 \newline
1409 \newline
1380
1410
1381 \begin_inset ERT
1411 \begin_inset ERT
1382 status Collapsed
1412 status Collapsed
1383
1413
1384 \layout Standard
1414 \layout Standard
1385
1415
1386 \backslash
1416 \backslash
1387 hspace*{0mm}
1417 hspace*{0mm}
1388 \end_inset
1418 \end_inset
1389
1419
1390 \SpecialChar ~
1420 \SpecialChar ~
1391 \SpecialChar ~
1421 \SpecialChar ~
1392 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
1422 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
1393 \layout Standard
1423 \layout Standard
1394
1424
1395 You can also set the value of this editor via the commmand-line option '-
1425 You can also set the value of this editor via the commmand-line option '-
1396 \family typewriter
1426 \family typewriter
1397 editor'
1427 editor'
1398 \family default
1428 \family default
1399 or in your
1429 or in your
1400 \family typewriter
1430 \family typewriter
1401 ipythonrc
1431 ipythonrc
1402 \family default
1432 \family default
1403 file.
1433 file.
1404 This is useful if you wish to use specifically for IPython an editor different
1434 This is useful if you wish to use specifically for IPython an editor different
1405 from your typical default (and for Windows users who tend to use fewer
1435 from your typical default (and for Windows users who tend to use fewer
1406 environment variables).
1436 environment variables).
1407 \layout Subsection
1437 \layout Subsection
1408
1438
1409 Color
1439 Color
1410 \layout Standard
1440 \layout Standard
1411
1441
1412 The default IPython configuration has most bells and whistles turned on
1442 The default IPython configuration has most bells and whistles turned on
1413 (they're pretty safe).
1443 (they're pretty safe).
1414 But there's one that
1444 But there's one that
1415 \emph on
1445 \emph on
1416 may
1446 may
1417 \emph default
1447 \emph default
1418 cause problems on some systems: the use of color on screen for displaying
1448 cause problems on some systems: the use of color on screen for displaying
1419 information.
1449 information.
1420 This is very useful, since IPython can show prompts and exception tracebacks
1450 This is very useful, since IPython can show prompts and exception tracebacks
1421 with various colors, display syntax-highlighted source code, and in general
1451 with various colors, display syntax-highlighted source code, and in general
1422 make it easier to visually parse information.
1452 make it easier to visually parse information.
1423 \layout Standard
1453 \layout Standard
1424
1454
1425 The following terminals seem to handle the color sequences fine:
1455 The following terminals seem to handle the color sequences fine:
1426 \layout Itemize
1456 \layout Itemize
1427
1457
1428 Linux main text console, KDE Konsole, Gnome Terminal, E-term, rxvt, xterm.
1458 Linux main text console, KDE Konsole, Gnome Terminal, E-term, rxvt, xterm.
1429 \layout Itemize
1459 \layout Itemize
1430
1460
1431 CDE terminal (tested under Solaris).
1461 CDE terminal (tested under Solaris).
1432 This one boldfaces light colors.
1462 This one boldfaces light colors.
1433 \layout Itemize
1463 \layout Itemize
1434
1464
1435 (X)Emacs buffers.
1465 (X)Emacs buffers.
1436 See sec.
1466 See sec.
1437 \begin_inset LatexCommand \ref{sec:emacs}
1467 \begin_inset LatexCommand \ref{sec:emacs}
1438
1468
1439 \end_inset
1469 \end_inset
1440
1470
1441 for more details on using IPython with (X)Emacs.
1471 for more details on using IPython with (X)Emacs.
1442 \layout Itemize
1472 \layout Itemize
1443
1473
1444 A Windows (XP/2k) command prompt
1474 A Windows (XP/2k) command prompt
1445 \emph on
1475 \emph on
1446 with Gary Bishop's support extensions
1476 with Gary Bishop's support extensions
1447 \emph default
1477 \emph default
1448 .
1478 .
1449 Gary's extensions are discussed in Sec.\SpecialChar ~
1479 Gary's extensions are discussed in Sec.\SpecialChar ~
1450
1480
1451 \begin_inset LatexCommand \ref{sub:Under-Windows}
1481 \begin_inset LatexCommand \ref{sub:Under-Windows}
1452
1482
1453 \end_inset
1483 \end_inset
1454
1484
1455 .
1485 .
1456 \layout Itemize
1486 \layout Itemize
1457
1487
1458 A Windows (XP/2k) CygWin shell.
1488 A Windows (XP/2k) CygWin shell.
1459 Although some users have reported problems; it is not clear whether there
1489 Although some users have reported problems; it is not clear whether there
1460 is an issue for everyone or only under specific configurations.
1490 is an issue for everyone or only under specific configurations.
1461 If you have full color support under cygwin, please post to the IPython
1491 If you have full color support under cygwin, please post to the IPython
1462 mailing list so this issue can be resolved for all users.
1492 mailing list so this issue can be resolved for all users.
1463 \layout Standard
1493 \layout Standard
1464
1494
1465 These have shown problems:
1495 These have shown problems:
1466 \layout Itemize
1496 \layout Itemize
1467
1497
1468 Windows command prompt in WinXP/2k logged into a Linux machine via telnet
1498 Windows command prompt in WinXP/2k logged into a Linux machine via telnet
1469 or ssh.
1499 or ssh.
1470 \layout Itemize
1500 \layout Itemize
1471
1501
1472 Windows native command prompt in WinXP/2k,
1502 Windows native command prompt in WinXP/2k,
1473 \emph on
1503 \emph on
1474 without
1504 without
1475 \emph default
1505 \emph default
1476 Gary Bishop's extensions.
1506 Gary Bishop's extensions.
1477 Once Gary's readline library is installed, the normal WinXP/2k command
1507 Once Gary's readline library is installed, the normal WinXP/2k command
1478 prompt works perfectly.
1508 prompt works perfectly.
1479 \layout Standard
1509 \layout Standard
1480
1510
1481 Currently the following color schemes are available:
1511 Currently the following color schemes are available:
1482 \layout Itemize
1512 \layout Itemize
1483
1513
1484
1514
1485 \family typewriter
1515 \family typewriter
1486 NoColor
1516 NoColor
1487 \family default
1517 \family default
1488 : uses no color escapes at all (all escapes are empty
1518 : uses no color escapes at all (all escapes are empty
1489 \begin_inset Quotes eld
1519 \begin_inset Quotes eld
1490 \end_inset
1520 \end_inset
1491
1521
1492
1522
1493 \begin_inset Quotes eld
1523 \begin_inset Quotes eld
1494 \end_inset
1524 \end_inset
1495
1525
1496 strings).
1526 strings).
1497 This 'scheme' is thus fully safe to use in any terminal.
1527 This 'scheme' is thus fully safe to use in any terminal.
1498 \layout Itemize
1528 \layout Itemize
1499
1529
1500
1530
1501 \family typewriter
1531 \family typewriter
1502 Linux
1532 Linux
1503 \family default
1533 \family default
1504 : works well in Linux console type environments: dark background with light
1534 : works well in Linux console type environments: dark background with light
1505 fonts.
1535 fonts.
1506 It uses bright colors for information, so it is difficult to read if you
1536 It uses bright colors for information, so it is difficult to read if you
1507 have a light colored background.
1537 have a light colored background.
1508 \layout Itemize
1538 \layout Itemize
1509
1539
1510
1540
1511 \family typewriter
1541 \family typewriter
1512 LightBG
1542 LightBG
1513 \family default
1543 \family default
1514 : the basic colors are similar to those in the
1544 : the basic colors are similar to those in the
1515 \family typewriter
1545 \family typewriter
1516 Linux
1546 Linux
1517 \family default
1547 \family default
1518 scheme but darker.
1548 scheme but darker.
1519 It is easy to read in terminals with light backgrounds.
1549 It is easy to read in terminals with light backgrounds.
1520 \layout Standard
1550 \layout Standard
1521
1551
1522 IPython uses colors for two main groups of things: prompts and tracebacks
1552 IPython uses colors for two main groups of things: prompts and tracebacks
1523 which are directly printed to the terminal, and the object introspection
1553 which are directly printed to the terminal, and the object introspection
1524 system which passes large sets of data through a pager.
1554 system which passes large sets of data through a pager.
1525 \layout Subsubsection
1555 \layout Subsubsection
1526
1556
1527 Input/Output prompts and exception tracebacks
1557 Input/Output prompts and exception tracebacks
1528 \layout Standard
1558 \layout Standard
1529
1559
1530 You can test whether the colored prompts and tracebacks work on your system
1560 You can test whether the colored prompts and tracebacks work on your system
1531 interactively by typing
1561 interactively by typing
1532 \family typewriter
1562 \family typewriter
1533 '%colors Linux'
1563 '%colors Linux'
1534 \family default
1564 \family default
1535 at the prompt (use '
1565 at the prompt (use '
1536 \family typewriter
1566 \family typewriter
1537 %colors LightBG'
1567 %colors LightBG'
1538 \family default
1568 \family default
1539 if your terminal has a light background).
1569 if your terminal has a light background).
1540 If the input prompt shows garbage like:
1570 If the input prompt shows garbage like:
1541 \newline
1571 \newline
1542
1572
1543 \family typewriter
1573 \family typewriter
1544 [0;32mIn [[1;32m1[0;32m]: [0;00m
1574 [0;32mIn [[1;32m1[0;32m]: [0;00m
1545 \family default
1575 \family default
1546
1576
1547 \newline
1577 \newline
1548 instead of (in color) something like:
1578 instead of (in color) something like:
1549 \newline
1579 \newline
1550
1580
1551 \family typewriter
1581 \family typewriter
1552 In [1]:
1582 In [1]:
1553 \family default
1583 \family default
1554
1584
1555 \newline
1585 \newline
1556 this means that your terminal doesn't properly handle color escape sequences.
1586 this means that your terminal doesn't properly handle color escape sequences.
1557 You can go to a 'no color' mode by typing '
1587 You can go to a 'no color' mode by typing '
1558 \family typewriter
1588 \family typewriter
1559 %colors NoColor
1589 %colors NoColor
1560 \family default
1590 \family default
1561 '.
1591 '.
1562
1592
1563 \layout Standard
1593 \layout Standard
1564
1594
1565 You can try using a different terminal emulator program.
1595 You can try using a different terminal emulator program.
1566 To permanently set your color preferences, edit the file
1596 To permanently set your color preferences, edit the file
1567 \family typewriter
1597 \family typewriter
1568 $HOME/.ipython/ipythonrc
1598 $HOME/.ipython/ipythonrc
1569 \family default
1599 \family default
1570 and set the
1600 and set the
1571 \family typewriter
1601 \family typewriter
1572 colors
1602 colors
1573 \family default
1603 \family default
1574 option to the desired value.
1604 option to the desired value.
1575 \layout Subsubsection
1605 \layout Subsubsection
1576
1606
1577 Object details (types, docstrings, source code, etc.)
1607 Object details (types, docstrings, source code, etc.)
1578 \layout Standard
1608 \layout Standard
1579
1609
1580 IPython has a set of special functions for studying the objects you are
1610 IPython has a set of special functions for studying the objects you are
1581 working with, discussed in detail in Sec.
1611 working with, discussed in detail in Sec.
1582
1612
1583 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1613 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1584
1614
1585 \end_inset
1615 \end_inset
1586
1616
1587 .
1617 .
1588 But this system relies on passing information which is longer than your
1618 But this system relies on passing information which is longer than your
1589 screen through a data pager, such as the common Unix
1619 screen through a data pager, such as the common Unix
1590 \family typewriter
1620 \family typewriter
1591 less
1621 less
1592 \family default
1622 \family default
1593 and
1623 and
1594 \family typewriter
1624 \family typewriter
1595 more
1625 more
1596 \family default
1626 \family default
1597 programs.
1627 programs.
1598 In order to be able to see this information in color, your pager needs
1628 In order to be able to see this information in color, your pager needs
1599 to be properly configured.
1629 to be properly configured.
1600 I strongly recommend using
1630 I strongly recommend using
1601 \family typewriter
1631 \family typewriter
1602 less
1632 less
1603 \family default
1633 \family default
1604 instead of
1634 instead of
1605 \family typewriter
1635 \family typewriter
1606 more
1636 more
1607 \family default
1637 \family default
1608 , as it seems that
1638 , as it seems that
1609 \family typewriter
1639 \family typewriter
1610 more
1640 more
1611 \family default
1641 \family default
1612 simply can not understand colored text correctly.
1642 simply can not understand colored text correctly.
1613 \layout Standard
1643 \layout Standard
1614
1644
1615 In order to configure
1645 In order to configure
1616 \family typewriter
1646 \family typewriter
1617 less
1647 less
1618 \family default
1648 \family default
1619 as your default pager, do the following:
1649 as your default pager, do the following:
1620 \layout Enumerate
1650 \layout Enumerate
1621
1651
1622 Set the environment
1652 Set the environment
1623 \family typewriter
1653 \family typewriter
1624 PAGER
1654 PAGER
1625 \family default
1655 \family default
1626 variable to
1656 variable to
1627 \family typewriter
1657 \family typewriter
1628 less
1658 less
1629 \family default
1659 \family default
1630 .
1660 .
1631 \layout Enumerate
1661 \layout Enumerate
1632
1662
1633 Set the environment
1663 Set the environment
1634 \family typewriter
1664 \family typewriter
1635 LESS
1665 LESS
1636 \family default
1666 \family default
1637 variable to
1667 variable to
1638 \family typewriter
1668 \family typewriter
1639 -r
1669 -r
1640 \family default
1670 \family default
1641 (plus any other options you always want to pass to
1671 (plus any other options you always want to pass to
1642 \family typewriter
1672 \family typewriter
1643 less
1673 less
1644 \family default
1674 \family default
1645 by default).
1675 by default).
1646 This tells
1676 This tells
1647 \family typewriter
1677 \family typewriter
1648 less
1678 less
1649 \family default
1679 \family default
1650 to properly interpret control sequences, which is how color information
1680 to properly interpret control sequences, which is how color information
1651 is given to your terminal.
1681 is given to your terminal.
1652 \layout Standard
1682 \layout Standard
1653
1683
1654 For the
1684 For the
1655 \family typewriter
1685 \family typewriter
1656 csh
1686 csh
1657 \family default
1687 \family default
1658 or
1688 or
1659 \family typewriter
1689 \family typewriter
1660 tcsh
1690 tcsh
1661 \family default
1691 \family default
1662 shells, add to your
1692 shells, add to your
1663 \family typewriter
1693 \family typewriter
1664 ~/.cshrc
1694 ~/.cshrc
1665 \family default
1695 \family default
1666 file the lines:
1696 file the lines:
1667 \layout Standard
1697 \layout Standard
1668
1698
1669
1699
1670 \family typewriter
1700 \family typewriter
1671 setenv PAGER less
1701 setenv PAGER less
1672 \newline
1702 \newline
1673 setenv LESS -r
1703 setenv LESS -r
1674 \layout Standard
1704 \layout Standard
1675
1705
1676 There is similar syntax for other Unix shells, look at your system documentation
1706 There is similar syntax for other Unix shells, look at your system documentation
1677 for details.
1707 for details.
1678 \layout Standard
1708 \layout Standard
1679
1709
1680 If you are on a system which lacks proper data pagers (such as Windows),
1710 If you are on a system which lacks proper data pagers (such as Windows),
1681 IPython will use a very limited builtin pager.
1711 IPython will use a very limited builtin pager.
1682 \layout Subsection
1712 \layout Subsection
1683
1713
1684
1714
1685 \begin_inset LatexCommand \label{sec:emacs}
1715 \begin_inset LatexCommand \label{sec:emacs}
1686
1716
1687 \end_inset
1717 \end_inset
1688
1718
1689 (X)Emacs configuration
1719 (X)Emacs configuration
1690 \layout Standard
1720 \layout Standard
1691
1721
1692 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, currently
1722 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, currently
1693 (X)Emacs and IPython get along very well.
1723 (X)Emacs and IPython get along very well.
1694
1724
1695 \layout Standard
1725 \layout Standard
1696
1726
1697
1727
1698 \series bold
1728 \series bold
1699 Important note:
1729 Important note:
1700 \series default
1730 \series default
1701 You will need to use a recent enough version of
1731 You will need to use a recent enough version of
1702 \family typewriter
1732 \family typewriter
1703 python-mode.el
1733 python-mode.el
1704 \family default
1734 \family default
1705 , along with the file
1735 , along with the file
1706 \family typewriter
1736 \family typewriter
1707 ipython.el
1737 ipython.el
1708 \family default
1738 \family default
1709 .
1739 .
1710 You can check that the version you have of
1740 You can check that the version you have of
1711 \family typewriter
1741 \family typewriter
1712 python-mode.el
1742 python-mode.el
1713 \family default
1743 \family default
1714 is new enough by either looking at the revision number in the file itself,
1744 is new enough by either looking at the revision number in the file itself,
1715 or asking for it in (X)Emacs via
1745 or asking for it in (X)Emacs via
1716 \family typewriter
1746 \family typewriter
1717 M-x py-version
1747 M-x py-version
1718 \family default
1748 \family default
1719 .
1749 .
1720 Versions 4.68 and newer contain the necessary fixes for proper IPython support.
1750 Versions 4.68 and newer contain the necessary fixes for proper IPython support.
1721 \layout Standard
1751 \layout Standard
1722
1752
1723 The file
1753 The file
1724 \family typewriter
1754 \family typewriter
1725 ipython.el
1755 ipython.el
1726 \family default
1756 \family default
1727 is included with the IPython distribution, in the documentation directory
1757 is included with the IPython distribution, in the documentation directory
1728 (where this manual resides in PDF and HTML formats).
1758 (where this manual resides in PDF and HTML formats).
1729 \layout Standard
1759 \layout Standard
1730
1760
1731 Once you put these files in your Emacs path, all you need in your
1761 Once you put these files in your Emacs path, all you need in your
1732 \family typewriter
1762 \family typewriter
1733 .emacs
1763 .emacs
1734 \family default
1764 \family default
1735 file is:
1765 file is:
1736 \layout Standard
1766 \layout Standard
1737
1767
1738
1768
1739 \family typewriter
1769 \family typewriter
1740 (require 'ipython)
1770 (require 'ipython)
1741 \layout Standard
1771 \layout Standard
1742
1772
1743 This should give you full support for executing code snippets via IPython,
1773 This should give you full support for executing code snippets via IPython,
1744 opening IPython as your Python shell via
1774 opening IPython as your Python shell via
1745 \family typewriter
1775 \family typewriter
1746 C-c\SpecialChar ~
1776 C-c\SpecialChar ~
1747 !
1777 !
1748 \family default
1778 \family default
1749 , etc.
1779 , etc.
1750
1780
1751 \layout Subsubsection*
1781 \layout Subsubsection*
1752
1782
1753 Notes
1783 Notes
1754 \layout Itemize
1784 \layout Itemize
1755
1785
1756 There is one caveat you should be aware of: you must start the IPython shell
1786 There is one caveat you should be aware of: you must start the IPython shell
1757
1787
1758 \emph on
1788 \emph on
1759 before
1789 before
1760 \emph default
1790 \emph default
1761 attempting to execute any code regions via
1791 attempting to execute any code regions via
1762 \family typewriter
1792 \family typewriter
1763 C-c\SpecialChar ~
1793 C-c\SpecialChar ~
1764 |
1794 |
1765 \family default
1795 \family default
1766 .
1796 .
1767 Simply type
1797 Simply type
1768 \family typewriter
1798 \family typewriter
1769 C-c\SpecialChar ~
1799 C-c\SpecialChar ~
1770 !
1800 !
1771 \family default
1801 \family default
1772 to start IPython before passing any code regions to the interpreter, and
1802 to start IPython before passing any code regions to the interpreter, and
1773 you shouldn't experience any problems.
1803 you shouldn't experience any problems.
1774 \newline
1804 \newline
1775 This is due to a bug in Python itself, which has been fixed for Python 2.3,
1805 This is due to a bug in Python itself, which has been fixed for Python 2.3,
1776 but exists as of Python 2.2.2 (reported as SF bug [ 737947 ]).
1806 but exists as of Python 2.2.2 (reported as SF bug [ 737947 ]).
1777 \layout Itemize
1807 \layout Itemize
1778
1808
1779 The (X)Emacs support is maintained by Alexander Schmolck, so all comments/reques
1809 The (X)Emacs support is maintained by Alexander Schmolck, so all comments/reques
1780 ts should be directed to him through the IPython mailing lists.
1810 ts should be directed to him through the IPython mailing lists.
1781
1811
1782 \layout Itemize
1812 \layout Itemize
1783
1813
1784 This code is still somewhat experimental so it's a bit rough around the
1814 This code is still somewhat experimental so it's a bit rough around the
1785 edges (although in practice, it works quite well).
1815 edges (although in practice, it works quite well).
1786 \layout Itemize
1816 \layout Itemize
1787
1817
1788 Be aware that if you customize
1818 Be aware that if you customize
1789 \family typewriter
1819 \family typewriter
1790 py-python-command
1820 py-python-command
1791 \family default
1821 \family default
1792 previously, this value will override what
1822 previously, this value will override what
1793 \family typewriter
1823 \family typewriter
1794 ipython.el
1824 ipython.el
1795 \family default
1825 \family default
1796 does (because loading the customization variables comes later).
1826 does (because loading the customization variables comes later).
1797 \layout Section
1827 \layout Section
1798
1828
1799
1829
1800 \begin_inset LatexCommand \label{sec:quick_tips}
1830 \begin_inset LatexCommand \label{sec:quick_tips}
1801
1831
1802 \end_inset
1832 \end_inset
1803
1833
1804 Quick tips
1834 Quick tips
1805 \layout Standard
1835 \layout Standard
1806
1836
1807 IPython can be used as an improved replacement for the Python prompt, and
1837 IPython can be used as an improved replacement for the Python prompt, and
1808 for that you don't really need to read any more of this manual.
1838 for that you don't really need to read any more of this manual.
1809 But in this section we'll try to summarize a few tips on how to make the
1839 But in this section we'll try to summarize a few tips on how to make the
1810 most effective use of it for everyday Python development, highlighting
1840 most effective use of it for everyday Python development, highlighting
1811 things you might miss in the rest of the manual (which is getting long).
1841 things you might miss in the rest of the manual (which is getting long).
1812 We'll give references to parts in the manual which provide more detail
1842 We'll give references to parts in the manual which provide more detail
1813 when appropriate.
1843 when appropriate.
1814 \layout Standard
1844 \layout Standard
1815
1845
1816 The following article by Jeremy Jones provides an introductory tutorial
1846 The following article by Jeremy Jones provides an introductory tutorial
1817 about IPython:
1847 about IPython:
1818 \newline
1848 \newline
1819
1849
1820 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html}
1850 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html}
1821
1851
1822 \end_inset
1852 \end_inset
1823
1853
1824
1854
1825 \layout Itemize
1855 \layout Itemize
1826
1856
1827 The TAB key.
1857 The TAB key.
1828 TAB-completion, especially for attributes, is a convenient way to explore
1858 TAB-completion, especially for attributes, is a convenient way to explore
1829 the structure of any object you're dealing with.
1859 the structure of any object you're dealing with.
1830 Simply type
1860 Simply type
1831 \family typewriter
1861 \family typewriter
1832 object_name.<TAB>
1862 object_name.<TAB>
1833 \family default
1863 \family default
1834 and a list of the object's attributes will be printed (see sec.
1864 and a list of the object's attributes will be printed (see sec.
1835
1865
1836 \begin_inset LatexCommand \ref{sec:readline}
1866 \begin_inset LatexCommand \ref{sec:readline}
1837
1867
1838 \end_inset
1868 \end_inset
1839
1869
1840 for more).
1870 for more).
1841 Tab completion also works on file and directory names, which combined with
1871 Tab completion also works on file and directory names, which combined with
1842 IPython's alias system allows you to do from within IPython many of the
1872 IPython's alias system allows you to do from within IPython many of the
1843 things you normally would need the system shell for.
1873 things you normally would need the system shell for.
1844
1874
1845 \layout Itemize
1875 \layout Itemize
1846
1876
1847 Explore your objects.
1877 Explore your objects.
1848 Typing
1878 Typing
1849 \family typewriter
1879 \family typewriter
1850 object_name?
1880 object_name?
1851 \family default
1881 \family default
1852 will print all sorts of details about any object, including docstrings,
1882 will print all sorts of details about any object, including docstrings,
1853 function definition lines (for call arguments) and constructor details
1883 function definition lines (for call arguments) and constructor details
1854 for classes.
1884 for classes.
1855 The magic commands
1885 The magic commands
1856 \family typewriter
1886 \family typewriter
1857 %pdoc
1887 %pdoc
1858 \family default
1888 \family default
1859 ,
1889 ,
1860 \family typewriter
1890 \family typewriter
1861 %pdef
1891 %pdef
1862 \family default
1892 \family default
1863 ,
1893 ,
1864 \family typewriter
1894 \family typewriter
1865 %psource
1895 %psource
1866 \family default
1896 \family default
1867 and
1897 and
1868 \family typewriter
1898 \family typewriter
1869 %pfile
1899 %pfile
1870 \family default
1900 \family default
1871 will respectively print the docstring, function definition line, full source
1901 will respectively print the docstring, function definition line, full source
1872 code and the complete file for any object (when they can be found).
1902 code and the complete file for any object (when they can be found).
1873 If automagic is on (it is by default), you don't need to type the '
1903 If automagic is on (it is by default), you don't need to type the '
1874 \family typewriter
1904 \family typewriter
1875 %
1905 %
1876 \family default
1906 \family default
1877 ' explicitly.
1907 ' explicitly.
1878 See sec.
1908 See sec.
1879
1909
1880 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1910 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1881
1911
1882 \end_inset
1912 \end_inset
1883
1913
1884 for more.
1914 for more.
1885 \layout Itemize
1915 \layout Itemize
1886
1916
1887 The
1917 The
1888 \family typewriter
1918 \family typewriter
1889 %run
1919 %run
1890 \family default
1920 \family default
1891 magic command allows you to run any python script and load all of its data
1921 magic command allows you to run any python script and load all of its data
1892 directly into the interactive namespace.
1922 directly into the interactive namespace.
1893 Since the file is re-read from disk each time, changes you make to it are
1923 Since the file is re-read from disk each time, changes you make to it are
1894 reflected immediately (in contrast to the behavior of
1924 reflected immediately (in contrast to the behavior of
1895 \family typewriter
1925 \family typewriter
1896 import
1926 import
1897 \family default
1927 \family default
1898 ).
1928 ).
1899 I rarely use
1929 I rarely use
1900 \family typewriter
1930 \family typewriter
1901 import
1931 import
1902 \family default
1932 \family default
1903 for code I am testing, relying on
1933 for code I am testing, relying on
1904 \family typewriter
1934 \family typewriter
1905 %run
1935 %run
1906 \family default
1936 \family default
1907 instead.
1937 instead.
1908 See sec.
1938 See sec.
1909
1939
1910 \begin_inset LatexCommand \ref{sec:magic}
1940 \begin_inset LatexCommand \ref{sec:magic}
1911
1941
1912 \end_inset
1942 \end_inset
1913
1943
1914 for more on this and other magic commands, or type the name of any magic
1944 for more on this and other magic commands, or type the name of any magic
1915 command and ? to get details on it.
1945 command and ? to get details on it.
1916 See also sec.
1946 See also sec.
1917
1947
1918 \begin_inset LatexCommand \ref{sec:dreload}
1948 \begin_inset LatexCommand \ref{sec:dreload}
1919
1949
1920 \end_inset
1950 \end_inset
1921
1951
1922 for a recursive reload command.
1952 for a recursive reload command.
1923 \newline
1953 \newline
1924
1954
1925 \family typewriter
1955 \family typewriter
1926 %run
1956 %run
1927 \family default
1957 \family default
1928 also has special flags for timing the execution of your scripts (
1958 also has special flags for timing the execution of your scripts (
1929 \family typewriter
1959 \family typewriter
1930 -t
1960 -t
1931 \family default
1961 \family default
1932 ) and for executing them under the control of either Python's
1962 ) and for executing them under the control of either Python's
1933 \family typewriter
1963 \family typewriter
1934 pdb
1964 pdb
1935 \family default
1965 \family default
1936 debugger (
1966 debugger (
1937 \family typewriter
1967 \family typewriter
1938 -d
1968 -d
1939 \family default
1969 \family default
1940 ) or profiler (
1970 ) or profiler (
1941 \family typewriter
1971 \family typewriter
1942 -p
1972 -p
1943 \family default
1973 \family default
1944 ).
1974 ).
1945 With all of these,
1975 With all of these,
1946 \family typewriter
1976 \family typewriter
1947 %run
1977 %run
1948 \family default
1978 \family default
1949 can be used as the main tool for efficient interactive development of code
1979 can be used as the main tool for efficient interactive development of code
1950 which you write in your editor of choice.
1980 which you write in your editor of choice.
1951 \layout Itemize
1981 \layout Itemize
1952
1982
1953 Use the Python debugger,
1983 Use the Python debugger,
1954 \family typewriter
1984 \family typewriter
1955 pdb
1985 pdb
1956 \family default
1986 \family default
1957
1987
1958 \begin_inset Foot
1988 \begin_inset Foot
1959 collapsed true
1989 collapsed true
1960
1990
1961 \layout Standard
1991 \layout Standard
1962
1992
1963 Thanks to Christian Hart and Matthew Arnison for the suggestions leading
1993 Thanks to Christian Hart and Matthew Arnison for the suggestions leading
1964 to IPython's improved debugger and profiler support.
1994 to IPython's improved debugger and profiler support.
1965 \end_inset
1995 \end_inset
1966
1996
1967 .
1997 .
1968 The
1998 The
1969 \family typewriter
1999 \family typewriter
1970 %pdb
2000 %pdb
1971 \family default
2001 \family default
1972 command allows you to toggle on and off the automatic invocation of the
2002 command allows you to toggle on and off the automatic invocation of the
1973 pdb debugger at any uncaught exception.
2003 pdb debugger at any uncaught exception.
1974 The advantage of this is that pdb starts
2004 The advantage of this is that pdb starts
1975 \emph on
2005 \emph on
1976 inside
2006 inside
1977 \emph default
2007 \emph default
1978 the function where the exception occurred, with all data still available.
2008 the function where the exception occurred, with all data still available.
1979 You can print variables, see code, execute statements and even walk up
2009 You can print variables, see code, execute statements and even walk up
1980 and down the call stack to track down the true source of the problem (which
2010 and down the call stack to track down the true source of the problem (which
1981 often is many layers in the stack above where the exception gets triggered).
2011 often is many layers in the stack above where the exception gets triggered).
1982 \newline
2012 \newline
1983 Running programs with
2013 Running programs with
1984 \family typewriter
2014 \family typewriter
1985 %run
2015 %run
1986 \family default
2016 \family default
1987 and pdb active can be an efficient to develop and debug code, in many cases
2017 and pdb active can be an efficient to develop and debug code, in many cases
1988 eliminating the need for
2018 eliminating the need for
1989 \family typewriter
2019 \family typewriter
1990 print
2020 print
1991 \family default
2021 \family default
1992 statements or external debugging tools.
2022 statements or external debugging tools.
1993 I often simply put a
2023 I often simply put a
1994 \family typewriter
2024 \family typewriter
1995 1/0
2025 1/0
1996 \family default
2026 \family default
1997 in a place where I want to take a look so that pdb gets called, quickly
2027 in a place where I want to take a look so that pdb gets called, quickly
1998 view whatever variables I need to or test various pieces of code and then
2028 view whatever variables I need to or test various pieces of code and then
1999 remove the
2029 remove the
2000 \family typewriter
2030 \family typewriter
2001 1/0
2031 1/0
2002 \family default
2032 \family default
2003 .
2033 .
2004 \newline
2034 \newline
2005 Note also that `
2035 Note also that `
2006 \family typewriter
2036 \family typewriter
2007 %run -d
2037 %run -d
2008 \family default
2038 \family default
2009 ' activates
2039 ' activates
2010 \family typewriter
2040 \family typewriter
2011 pdb
2041 pdb
2012 \family default
2042 \family default
2013 and automatically sets initial breakpoints for you to step through your
2043 and automatically sets initial breakpoints for you to step through your
2014 code, watch variables, etc.
2044 code, watch variables, etc.
2015 See Sec.\SpecialChar ~
2045 See Sec.\SpecialChar ~
2016
2046
2017 \begin_inset LatexCommand \ref{sec:cache_output}
2047 \begin_inset LatexCommand \ref{sec:cache_output}
2018
2048
2019 \end_inset
2049 \end_inset
2020
2050
2021 for details.
2051 for details.
2022 \layout Itemize
2052 \layout Itemize
2023
2053
2024 Use the output cache.
2054 Use the output cache.
2025 All output results are automatically stored in a global dictionary named
2055 All output results are automatically stored in a global dictionary named
2026
2056
2027 \family typewriter
2057 \family typewriter
2028 Out
2058 Out
2029 \family default
2059 \family default
2030 and variables named
2060 and variables named
2031 \family typewriter
2061 \family typewriter
2032 _1
2062 _1
2033 \family default
2063 \family default
2034 ,
2064 ,
2035 \family typewriter
2065 \family typewriter
2036 _2
2066 _2
2037 \family default
2067 \family default
2038 , etc.
2068 , etc.
2039 alias them.
2069 alias them.
2040 For example, the result of input line 4 is available either as
2070 For example, the result of input line 4 is available either as
2041 \family typewriter
2071 \family typewriter
2042 Out[4]
2072 Out[4]
2043 \family default
2073 \family default
2044 or as
2074 or as
2045 \family typewriter
2075 \family typewriter
2046 _4
2076 _4
2047 \family default
2077 \family default
2048 .
2078 .
2049 Additionally, three variables named
2079 Additionally, three variables named
2050 \family typewriter
2080 \family typewriter
2051 _
2081 _
2052 \family default
2082 \family default
2053 ,
2083 ,
2054 \family typewriter
2084 \family typewriter
2055 __
2085 __
2056 \family default
2086 \family default
2057 and
2087 and
2058 \family typewriter
2088 \family typewriter
2059 ___
2089 ___
2060 \family default
2090 \family default
2061 are always kept updated with the for the last three results.
2091 are always kept updated with the for the last three results.
2062 This allows you to recall any previous result and further use it for new
2092 This allows you to recall any previous result and further use it for new
2063 calculations.
2093 calculations.
2064 See Sec.\SpecialChar ~
2094 See Sec.\SpecialChar ~
2065
2095
2066 \begin_inset LatexCommand \ref{sec:cache_output}
2096 \begin_inset LatexCommand \ref{sec:cache_output}
2067
2097
2068 \end_inset
2098 \end_inset
2069
2099
2070 for more.
2100 for more.
2071 \layout Itemize
2101 \layout Itemize
2072
2102
2073 Put a '
2103 Put a '
2074 \family typewriter
2104 \family typewriter
2075 ;
2105 ;
2076 \family default
2106 \family default
2077 ' at the end of a line to supress the printing of output.
2107 ' at the end of a line to supress the printing of output.
2078 This is useful when doing calculations which generate long output you are
2108 This is useful when doing calculations which generate long output you are
2079 not interested in seeing.
2109 not interested in seeing.
2080 The
2110 The
2081 \family typewriter
2111 \family typewriter
2082 _*
2112 _*
2083 \family default
2113 \family default
2084 variables and the
2114 variables and the
2085 \family typewriter
2115 \family typewriter
2086 Out[]
2116 Out[]
2087 \family default
2117 \family default
2088 list do get updated with the contents of the output, even if it is not
2118 list do get updated with the contents of the output, even if it is not
2089 printed.
2119 printed.
2090 You can thus still access the generated results this way for further processing.
2120 You can thus still access the generated results this way for further processing.
2091 \layout Itemize
2121 \layout Itemize
2092
2122
2093 A similar system exists for caching input.
2123 A similar system exists for caching input.
2094 All input is stored in a global list called
2124 All input is stored in a global list called
2095 \family typewriter
2125 \family typewriter
2096 In
2126 In
2097 \family default
2127 \family default
2098 , so you can re-execute lines 22 through 28 plus line 34 by typing
2128 , so you can re-execute lines 22 through 28 plus line 34 by typing
2099 \family typewriter
2129 \family typewriter
2100 'exec In[22:29]+In[34]'
2130 'exec In[22:29]+In[34]'
2101 \family default
2131 \family default
2102 (using Python slicing notation).
2132 (using Python slicing notation).
2103 If you need to execute the same set of lines often, you can assign them
2133 If you need to execute the same set of lines often, you can assign them
2104 to a macro with the
2134 to a macro with the
2105 \family typewriter
2135 \family typewriter
2106 %macro
2136 %macro
2107 \family default
2137 \family default
2108
2138
2109 \family typewriter
2139 \family typewriter
2110 function.
2140 function.
2111
2141
2112 \family default
2142 \family default
2113 See sec.
2143 See sec.
2114
2144
2115 \begin_inset LatexCommand \ref{sec:cache_input}
2145 \begin_inset LatexCommand \ref{sec:cache_input}
2116
2146
2117 \end_inset
2147 \end_inset
2118
2148
2119 for more.
2149 for more.
2120 \layout Itemize
2150 \layout Itemize
2121
2151
2122 Use your input history.
2152 Use your input history.
2123 The
2153 The
2124 \family typewriter
2154 \family typewriter
2125 %hist
2155 %hist
2126 \family default
2156 \family default
2127 command can show you all previous input, without line numbers if desired
2157 command can show you all previous input, without line numbers if desired
2128 (option
2158 (option
2129 \family typewriter
2159 \family typewriter
2130 -n
2160 -n
2131 \family default
2161 \family default
2132 ) so you can directly copy and paste code either back in IPython or in a
2162 ) so you can directly copy and paste code either back in IPython or in a
2133 text editor.
2163 text editor.
2134 You can also save all your history by turning on logging via
2164 You can also save all your history by turning on logging via
2135 \family typewriter
2165 \family typewriter
2136 %logstart
2166 %logstart
2137 \family default
2167 \family default
2138 ; these logs can later be either reloaded as IPython sessions or used as
2168 ; these logs can later be either reloaded as IPython sessions or used as
2139 code for your programs.
2169 code for your programs.
2140 \layout Itemize
2170 \layout Itemize
2141
2171
2142 Define your own macros with
2172 Define your own macros with
2143 \family typewriter
2173 \family typewriter
2144 %macro
2174 %macro
2145 \family default
2175 \family default
2146 .
2176 .
2147 This can be useful for automating sequences of expressions when working
2177 This can be useful for automating sequences of expressions when working
2148 interactively.
2178 interactively.
2149 \layout Itemize
2179 \layout Itemize
2150
2180
2151 Define your own system aliases.
2181 Define your own system aliases.
2152 Even though IPython gives you access to your system shell via the
2182 Even though IPython gives you access to your system shell via the
2153 \family typewriter
2183 \family typewriter
2154 !
2184 !
2155 \family default
2185 \family default
2156 prefix, it is convenient to have aliases to the system commands you use
2186 prefix, it is convenient to have aliases to the system commands you use
2157 most often.
2187 most often.
2158 This allows you to work seamlessly from inside IPython with the same commands
2188 This allows you to work seamlessly from inside IPython with the same commands
2159 you are used to in your system shell.
2189 you are used to in your system shell.
2160 \newline
2190 \newline
2161 IPython comes with some pre-defined aliases and a complete system for changing
2191 IPython comes with some pre-defined aliases and a complete system for changing
2162 directories, both via a stack (see
2192 directories, both via a stack (see
2163 \family typewriter
2193 \family typewriter
2164 %pushd
2194 %pushd
2165 \family default
2195 \family default
2166 ,
2196 ,
2167 \family typewriter
2197 \family typewriter
2168 %popd
2198 %popd
2169 \family default
2199 \family default
2170 and
2200 and
2171 \family typewriter
2201 \family typewriter
2172 %ds
2202 %ds
2173 \family default
2203 \family default
2174 ) and via direct
2204 ) and via direct
2175 \family typewriter
2205 \family typewriter
2176 %cd
2206 %cd
2177 \family default
2207 \family default
2178 .
2208 .
2179 The latter keeps a history of visited directories and allows you to go
2209 The latter keeps a history of visited directories and allows you to go
2180 to any previously visited one.
2210 to any previously visited one.
2181 \layout Itemize
2211 \layout Itemize
2182
2212
2183 Use Python to manipulate the results of system commands.
2213 Use Python to manipulate the results of system commands.
2184 The `
2214 The `
2185 \family typewriter
2215 \family typewriter
2186 !!
2216 !!
2187 \family default
2217 \family default
2188 ' special syntax, and the
2218 ' special syntax, and the
2189 \family typewriter
2219 \family typewriter
2190 %sc
2220 %sc
2191 \family default
2221 \family default
2192 and
2222 and
2193 \family typewriter
2223 \family typewriter
2194 %sx
2224 %sx
2195 \family default
2225 \family default
2196 magic commands allow you to capture system output into Python variables.
2226 magic commands allow you to capture system output into Python variables.
2197 \layout Itemize
2227 \layout Itemize
2198
2228
2199 Expand python variables when calling the shell (either via
2229 Expand python variables when calling the shell (either via
2200 \family typewriter
2230 \family typewriter
2201 `!'
2231 `!'
2202 \family default
2232 \family default
2203 and
2233 and
2204 \family typewriter
2234 \family typewriter
2205 `!!'
2235 `!!'
2206 \family default
2236 \family default
2207 or via aliases) by prepending a
2237 or via aliases) by prepending a
2208 \family typewriter
2238 \family typewriter
2209 $
2239 $
2210 \family default
2240 \family default
2211 in front of them.
2241 in front of them.
2212 You can also expand complete python expressions.
2242 You can also expand complete python expressions.
2213 See sec.\SpecialChar ~
2243 See sec.\SpecialChar ~
2214
2244
2215 \begin_inset LatexCommand \ref{sub:System-shell-access}
2245 \begin_inset LatexCommand \ref{sub:System-shell-access}
2216
2246
2217 \end_inset
2247 \end_inset
2218
2248
2219 for more.
2249 for more.
2220 \layout Itemize
2250 \layout Itemize
2221
2251
2222 Use profiles to maintain different configurations (modules to load, function
2252 Use profiles to maintain different configurations (modules to load, function
2223 definitions, option settings) for particular tasks.
2253 definitions, option settings) for particular tasks.
2224 You can then have customized versions of IPython for specific purposes.
2254 You can then have customized versions of IPython for specific purposes.
2225 See sec.\SpecialChar ~
2255 See sec.\SpecialChar ~
2226
2256
2227 \begin_inset LatexCommand \ref{sec:profiles}
2257 \begin_inset LatexCommand \ref{sec:profiles}
2228
2258
2229 \end_inset
2259 \end_inset
2230
2260
2231 for more.
2261 for more.
2232 \layout Itemize
2262 \layout Itemize
2233
2263
2234 Embed IPython in your programs.
2264 Embed IPython in your programs.
2235 A few lines of code are enough to load a complete IPython inside your own
2265 A few lines of code are enough to load a complete IPython inside your own
2236 programs, giving you the ability to work with your data interactively after
2266 programs, giving you the ability to work with your data interactively after
2237 automatic processing has been completed.
2267 automatic processing has been completed.
2238 See sec.\SpecialChar ~
2268 See sec.\SpecialChar ~
2239
2269
2240 \begin_inset LatexCommand \ref{sec:embed}
2270 \begin_inset LatexCommand \ref{sec:embed}
2241
2271
2242 \end_inset
2272 \end_inset
2243
2273
2244 for more.
2274 for more.
2245 \layout Itemize
2275 \layout Itemize
2246
2276
2247 Use the Python profiler.
2277 Use the Python profiler.
2248 When dealing with performance issues, the
2278 When dealing with performance issues, the
2249 \family typewriter
2279 \family typewriter
2250 %run
2280 %run
2251 \family default
2281 \family default
2252 command with a
2282 command with a
2253 \family typewriter
2283 \family typewriter
2254 -p
2284 -p
2255 \family default
2285 \family default
2256 option allows you to run complete programs under the control of the Python
2286 option allows you to run complete programs under the control of the Python
2257 profiler.
2287 profiler.
2258 The
2288 The
2259 \family typewriter
2289 \family typewriter
2260 %prun
2290 %prun
2261 \family default
2291 \family default
2262 command does a similar job for single Python expressions (like function
2292 command does a similar job for single Python expressions (like function
2263 calls).
2293 calls).
2264 \layout Itemize
2294 \layout Itemize
2265
2295
2266 Use
2296 Use
2267 \family typewriter
2297 \family typewriter
2268 %edit
2298 %edit
2269 \family default
2299 \family default
2270 to have almost multiline editing.
2300 to have almost multiline editing.
2271 While IPython doesn't support true multiline editing, this command allows
2301 While IPython doesn't support true multiline editing, this command allows
2272 you to call an editor on the spot, and IPython will execute the code you
2302 you to call an editor on the spot, and IPython will execute the code you
2273 type in there as if it were typed interactively.
2303 type in there as if it were typed interactively.
2304 \layout Itemize
2305
2306 Use the IPython.demo.Demo class to load any Python script as an interactive
2307 demo.
2308 With a minimal amount of simple markup, you can control the execution of
2309 the script, stopping as needed.
2310 See sec.\SpecialChar ~
2311
2312 \begin_inset LatexCommand \ref{sec:interactive-demos}
2313
2314 \end_inset
2315
2316 for more.
2274 \layout Standard
2317 \layout Standard
2275
2318
2276 If you have your own favorite tip on using IPython efficiently for a certain
2319 If you have your own favorite tip on using IPython efficiently for a certain
2277 task (especially things which can't be done in the normal Python interpreter),
2320 task (especially things which can't be done in the normal Python interpreter),
2278 don't hesitate to send it!
2321 don't hesitate to send it!
2279 \layout Section
2322 \layout Section
2280
2323
2281 Command-line use
2324 Command-line use
2282 \layout Standard
2325 \layout Standard
2283
2326
2284 You start IPython with the command:
2327 You start IPython with the command:
2285 \layout Standard
2328 \layout Standard
2286
2329
2287
2330
2288 \family typewriter
2331 \family typewriter
2289 $ ipython [options] files
2332 $ ipython [options] files
2290 \layout Standard
2333 \layout Standard
2291
2334
2292 If invoked with no options, it executes all the files listed in sequence
2335 If invoked with no options, it executes all the files listed in sequence
2293 and drops you into the interpreter while still acknowledging any options
2336 and drops you into the interpreter while still acknowledging any options
2294 you may have set in your ipythonrc file.
2337 you may have set in your ipythonrc file.
2295 This behavior is different from standard Python, which when called as
2338 This behavior is different from standard Python, which when called as
2296 \family typewriter
2339 \family typewriter
2297 python -i
2340 python -i
2298 \family default
2341 \family default
2299 will only execute one file and ignore your configuration setup.
2342 will only execute one file and ignore your configuration setup.
2300 \layout Standard
2343 \layout Standard
2301
2344
2302 Please note that some of the configuration options are not available at
2345 Please note that some of the configuration options are not available at
2303 the command line, simply because they are not practical here.
2346 the command line, simply because they are not practical here.
2304 Look into your ipythonrc configuration file for details on those.
2347 Look into your ipythonrc configuration file for details on those.
2305 This file typically installed in the
2348 This file typically installed in the
2306 \family typewriter
2349 \family typewriter
2307 $HOME/.ipython
2350 $HOME/.ipython
2308 \family default
2351 \family default
2309 directory.
2352 directory.
2310 For Windows users,
2353 For Windows users,
2311 \family typewriter
2354 \family typewriter
2312 $HOME
2355 $HOME
2313 \family default
2356 \family default
2314 resolves to
2357 resolves to
2315 \family typewriter
2358 \family typewriter
2316 C:
2359 C:
2317 \backslash
2360 \backslash
2318
2361
2319 \backslash
2362 \backslash
2320 Documents and Settings
2363 Documents and Settings
2321 \backslash
2364 \backslash
2322
2365
2323 \backslash
2366 \backslash
2324 YourUserName
2367 YourUserName
2325 \family default
2368 \family default
2326 in most instances.
2369 in most instances.
2327 In the rest of this text, we will refer to this directory as
2370 In the rest of this text, we will refer to this directory as
2328 \family typewriter
2371 \family typewriter
2329 IPYTHONDIR
2372 IPYTHONDIR
2330 \family default
2373 \family default
2331 .
2374 .
2332 \layout Subsection
2375 \layout Subsection
2333
2376
2334
2377
2335 \begin_inset LatexCommand \label{sec:threading-opts}
2378 \begin_inset LatexCommand \label{sec:threading-opts}
2336
2379
2337 \end_inset
2380 \end_inset
2338
2381
2339 Special Threading Options
2382 Special Threading Options
2340 \layout Standard
2383 \layout Standard
2341
2384
2342 The following special options are ONLY valid at the beginning of the command
2385 The following special options are ONLY valid at the beginning of the command
2343 line, and not later.
2386 line, and not later.
2344 This is because they control the initial- ization of ipython itself, before
2387 This is because they control the initial- ization of ipython itself, before
2345 the normal option-handling mechanism is active.
2388 the normal option-handling mechanism is active.
2346 \layout List
2389 \layout List
2347 \labelwidthstring 00.00.0000
2390 \labelwidthstring 00.00.0000
2348
2391
2349
2392
2350 \family typewriter
2393 \family typewriter
2351 \series bold
2394 \series bold
2352 -gthread,\SpecialChar ~
2395 -gthread,\SpecialChar ~
2353 -wthread,\SpecialChar ~
2396 -wthread,\SpecialChar ~
2354 -pylab:
2397 -pylab:
2355 \family default
2398 \family default
2356 \series default
2399 \series default
2357 Only
2400 Only
2358 \emph on
2401 \emph on
2359 one
2402 one
2360 \emph default
2403 \emph default
2361 of these can be given, and it can only be given as the first option passed
2404 of these can be given, and it can only be given as the first option passed
2362 to IPython (it will have no effect in any other position).
2405 to IPython (it will have no effect in any other position).
2363 They provide threading support for the GTK and WXPython toolkits, and for
2406 They provide threading support for the GTK and WXPython toolkits, and for
2364 the matplotlib library.
2407 the matplotlib library.
2365 \layout List
2408 \layout List
2366 \labelwidthstring 00.00.0000
2409 \labelwidthstring 00.00.0000
2367
2410
2368 \SpecialChar ~
2411 \SpecialChar ~
2369 If
2412 If
2370 \family typewriter
2413 \family typewriter
2371 -gthread
2414 -gthread
2372 \family default
2415 \family default
2373 is given, IPython starts running a separate thread for GTK operation, so
2416 is given, IPython starts running a separate thread for GTK operation, so
2374 that pyGTK-based programs can open and control GUIs without blocking IPython.
2417 that pyGTK-based programs can open and control GUIs without blocking IPython.
2375
2418
2376 \layout List
2419 \layout List
2377 \labelwidthstring 00.00.0000
2420 \labelwidthstring 00.00.0000
2378
2421
2379 \SpecialChar ~
2422 \SpecialChar ~
2380 Similarly,
2423 Similarly,
2381 \family typewriter
2424 \family typewriter
2382 -wthread
2425 -wthread
2383 \family default
2426 \family default
2384 instantiates IPython with threading support for the WXPython toolkit.
2427 instantiates IPython with threading support for the WXPython toolkit.
2385 You can control WX application windows from within IPython.
2428 You can control WX application windows from within IPython.
2386 \layout List
2429 \layout List
2387 \labelwidthstring 00.00.0000
2430 \labelwidthstring 00.00.0000
2388
2431
2389 \SpecialChar ~
2432 \SpecialChar ~
2390 If
2433 If
2391 \family typewriter
2434 \family typewriter
2392 -pylab
2435 -pylab
2393 \family default
2436 \family default
2394 is given, IPython loads special support for the mat- plotlib library (
2437 is given, IPython loads special support for the mat- plotlib library (
2395 \begin_inset LatexCommand \htmlurl{http://matplotlib.sourceforge.net}
2438 \begin_inset LatexCommand \htmlurl{http://matplotlib.sourceforge.net}
2396
2439
2397 \end_inset
2440 \end_inset
2398
2441
2399 ), allowing interactive usage of any of its backends as defined in the user's
2442 ), allowing interactive usage of any of its backends as defined in the user's
2400 .matplotlibrc file.
2443 .matplotlibrc file.
2401 It automatically activates GTK or WX threading for IPyhton if the choice
2444 It automatically activates GTK or WX threading for IPyhton if the choice
2402 of matplotlib backend requires it.
2445 of matplotlib backend requires it.
2403 It also modifies the
2446 It also modifies the
2404 \family typewriter
2447 \family typewriter
2405 %run
2448 %run
2406 \family default
2449 \family default
2407 command to correctly execute (without blocking) any matplotlib-based script
2450 command to correctly execute (without blocking) any matplotlib-based script
2408 which calls
2451 which calls
2409 \family typewriter
2452 \family typewriter
2410 show()
2453 show()
2411 \family default
2454 \family default
2412 at the end.
2455 at the end.
2413
2456
2414 \layout List
2457 \layout List
2415 \labelwidthstring 00.00.0000
2458 \labelwidthstring 00.00.0000
2416
2459
2417
2460
2418 \family typewriter
2461 \family typewriter
2419 \series bold
2462 \series bold
2420 -tk
2463 -tk
2421 \family default
2464 \family default
2422 \series default
2465 \series default
2423 The
2466 The
2424 \family typewriter
2467 \family typewriter
2425 -g/wthread
2468 -g/wthread
2426 \family default
2469 \family default
2427 options, and
2470 options, and
2428 \family typewriter
2471 \family typewriter
2429 -pylab
2472 -pylab
2430 \family default
2473 \family default
2431 (if matplotlib is configured to use WX or GTK), will normally block Tk
2474 (if matplotlib is configured to use WX or GTK), will normally block Tk
2432 graphical interfaces.
2475 graphical interfaces.
2433 This means that when either GTK or WX threading is active, any attempt
2476 This means that when either GTK or WX threading is active, any attempt
2434 to open a Tk GUI will result in a dead window, and pos- sibly cause the
2477 to open a Tk GUI will result in a dead window, and pos- sibly cause the
2435 Python interpreter to crash.
2478 Python interpreter to crash.
2436 An extra option,
2479 An extra option,
2437 \family typewriter
2480 \family typewriter
2438 -tk
2481 -tk
2439 \family default
2482 \family default
2440 , is available to address this issue.
2483 , is available to address this issue.
2441 It can
2484 It can
2442 \emph on
2485 \emph on
2443 only
2486 only
2444 \emph default
2487 \emph default
2445 be given as a
2488 be given as a
2446 \emph on
2489 \emph on
2447 second
2490 second
2448 \emph default
2491 \emph default
2449 option after any of the above (
2492 option after any of the above (
2450 \family typewriter
2493 \family typewriter
2451 -gthread
2494 -gthread
2452 \family default
2495 \family default
2453 ,
2496 ,
2454 \family typewriter
2497 \family typewriter
2455 -wthread
2498 -wthread
2456 \family default
2499 \family default
2457 or
2500 or
2458 \family typewriter
2501 \family typewriter
2459 -pylab
2502 -pylab
2460 \family default
2503 \family default
2461 ).
2504 ).
2462 \layout List
2505 \layout List
2463 \labelwidthstring 00.00.0000
2506 \labelwidthstring 00.00.0000
2464
2507
2465 \SpecialChar ~
2508 \SpecialChar ~
2466 If
2509 If
2467 \family typewriter
2510 \family typewriter
2468 -tk
2511 -tk
2469 \family default
2512 \family default
2470 is given, IPython will try to coordinate Tk threading with WX or GTK.
2513 is given, IPython will try to coordinate Tk threading with WX or GTK.
2471 This is however potentially unreliable, and you will have to test on your
2514 This is however potentially unreliable, and you will have to test on your
2472 platform and Python configuration to determine whether it works for you.
2515 platform and Python configuration to determine whether it works for you.
2473 Debian users have reported success, apparently due to the fact that Debian
2516 Debian users have reported success, apparently due to the fact that Debian
2474 builds all of Tcl, Tk, Tkinter and Python with pthreads support.
2517 builds all of Tcl, Tk, Tkinter and Python with pthreads support.
2475 Under other Linux environments (such as Fedora Core 2), this option has
2518 Under other Linux environments (such as Fedora Core 2), this option has
2476 caused random crashes and lockups of the Python interpreter.
2519 caused random crashes and lockups of the Python interpreter.
2477 Under other operating systems (Mac OSX and Windows), you'll need to try
2520 Under other operating systems (Mac OSX and Windows), you'll need to try
2478 it to find out, since currently no user reports are available.
2521 it to find out, since currently no user reports are available.
2479 \layout List
2522 \layout List
2480 \labelwidthstring 00.00.0000
2523 \labelwidthstring 00.00.0000
2481
2524
2482 \SpecialChar ~
2525 \SpecialChar ~
2483 There is unfortunately no way for IPython to determine at run time whether
2526 There is unfortunately no way for IPython to determine at run time whether
2484
2527
2485 \family typewriter
2528 \family typewriter
2486 -tk
2529 -tk
2487 \family default
2530 \family default
2488 will work reliably or not, so you will need to do some experiments before
2531 will work reliably or not, so you will need to do some experiments before
2489 relying on it for regular work.
2532 relying on it for regular work.
2490
2533
2491 \layout Subsection
2534 \layout Subsection
2492
2535
2493
2536
2494 \begin_inset LatexCommand \label{sec:cmd-line-opts}
2537 \begin_inset LatexCommand \label{sec:cmd-line-opts}
2495
2538
2496 \end_inset
2539 \end_inset
2497
2540
2498 Regular Options
2541 Regular Options
2499 \layout Standard
2542 \layout Standard
2500
2543
2501 After the above threading options have been given, regular options can follow
2544 After the above threading options have been given, regular options can follow
2502 in any order.
2545 in any order.
2503 All options can be abbreviated to their shortest non-ambiguous form and
2546 All options can be abbreviated to their shortest non-ambiguous form and
2504 are case-sensitive.
2547 are case-sensitive.
2505 One or two dashes can be used.
2548 One or two dashes can be used.
2506 Some options have an alternate short form, indicated after a
2549 Some options have an alternate short form, indicated after a
2507 \family typewriter
2550 \family typewriter
2508 |
2551 |
2509 \family default
2552 \family default
2510 .
2553 .
2511 \layout Standard
2554 \layout Standard
2512
2555
2513 Most options can also be set from your ipythonrc configuration file.
2556 Most options can also be set from your ipythonrc configuration file.
2514 See the provided example for more details on what the options do.
2557 See the provided example for more details on what the options do.
2515 Options given at the command line override the values set in the ipythonrc
2558 Options given at the command line override the values set in the ipythonrc
2516 file.
2559 file.
2517 \layout Standard
2560 \layout Standard
2518
2561
2519 All options with a
2562 All options with a
2520 \family typewriter
2563 \family typewriter
2521 no|
2564 no|
2522 \family default
2565 \family default
2523 prepended can be specified in 'no' form (
2566 prepended can be specified in 'no' form (
2524 \family typewriter
2567 \family typewriter
2525 -nooption
2568 -nooption
2526 \family default
2569 \family default
2527 instead of
2570 instead of
2528 \family typewriter
2571 \family typewriter
2529 -option
2572 -option
2530 \family default
2573 \family default
2531 ) to turn the feature off.
2574 ) to turn the feature off.
2532 \layout List
2575 \layout List
2533 \labelwidthstring 00.00.0000
2576 \labelwidthstring 00.00.0000
2534
2577
2535
2578
2536 \family typewriter
2579 \family typewriter
2537 \series bold
2580 \series bold
2538 -help
2581 -help
2539 \family default
2582 \family default
2540 \series default
2583 \series default
2541 : print a help message and exit.
2584 : print a help message and exit.
2542 \layout List
2585 \layout List
2543 \labelwidthstring 00.00.0000
2586 \labelwidthstring 00.00.0000
2544
2587
2545
2588
2546 \family typewriter
2589 \family typewriter
2547 \series bold
2590 \series bold
2548 -pylab:
2591 -pylab:
2549 \family default
2592 \family default
2550 \series default
2593 \series default
2551 this can
2594 this can
2552 \emph on
2595 \emph on
2553 only
2596 only
2554 \emph default
2597 \emph default
2555 be given as the
2598 be given as the
2556 \emph on
2599 \emph on
2557 first
2600 first
2558 \emph default
2601 \emph default
2559 option passed to IPython (it will have no effect in any other position).
2602 option passed to IPython (it will have no effect in any other position).
2560 It adds special support for the matplotlib library (
2603 It adds special support for the matplotlib library (
2561 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
2604 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
2562
2605
2563 \end_inset
2606 \end_inset
2564
2607
2565 ), allowing interactive usage of any of its backends as defined in the user's
2608 ), allowing interactive usage of any of its backends as defined in the user's
2566
2609
2567 \family typewriter
2610 \family typewriter
2568 .matplotlibrc
2611 .matplotlibrc
2569 \family default
2612 \family default
2570 file.
2613 file.
2571 It automatically activates GTK or WX threading for IPyhton if the choice
2614 It automatically activates GTK or WX threading for IPyhton if the choice
2572 of matplotlib backend requires it.
2615 of matplotlib backend requires it.
2573 It also modifies the
2616 It also modifies the
2574 \family typewriter
2617 \family typewriter
2575 %run
2618 %run
2576 \family default
2619 \family default
2577 command to correctly execute (without blocking) any matplotlib-based script
2620 command to correctly execute (without blocking) any matplotlib-based script
2578 which calls
2621 which calls
2579 \family typewriter
2622 \family typewriter
2580 show()
2623 show()
2581 \family default
2624 \family default
2582 at the end.
2625 at the end.
2583 See Sec.\SpecialChar ~
2626 See Sec.\SpecialChar ~
2584
2627
2585 \begin_inset LatexCommand \ref{sec:matplotlib-support}
2628 \begin_inset LatexCommand \ref{sec:matplotlib-support}
2586
2629
2587 \end_inset
2630 \end_inset
2588
2631
2589 for more details.
2632 for more details.
2590 \layout List
2633 \layout List
2591 \labelwidthstring 00.00.0000
2634 \labelwidthstring 00.00.0000
2592
2635
2593
2636
2594 \family typewriter
2637 \family typewriter
2595 \series bold
2638 \series bold
2596 -no|automagic
2639 -no|automagic
2597 \series default
2640 \series default
2598 :
2641 :
2599 \family default
2642 \family default
2600 make magic commands automatic (without needing their first character to
2643 make magic commands automatic (without needing their first character to
2601 be
2644 be
2602 \family typewriter
2645 \family typewriter
2603 %
2646 %
2604 \family default
2647 \family default
2605 ).
2648 ).
2606 Type
2649 Type
2607 \family typewriter
2650 \family typewriter
2608 %magic
2651 %magic
2609 \family default
2652 \family default
2610 at the IPython prompt for more information.
2653 at the IPython prompt for more information.
2611 \layout List
2654 \layout List
2612 \labelwidthstring 00.00.0000
2655 \labelwidthstring 00.00.0000
2613
2656
2614
2657
2615 \family typewriter
2658 \family typewriter
2616 \series bold
2659 \series bold
2617 -no|banner
2660 -no|banner
2618 \series default
2661 \series default
2619 :
2662 :
2620 \family default
2663 \family default
2621 Print the initial information banner (default on).
2664 Print the initial information banner (default on).
2622 \layout List
2665 \layout List
2623 \labelwidthstring 00.00.0000
2666 \labelwidthstring 00.00.0000
2624
2667
2625
2668
2626 \family typewriter
2669 \family typewriter
2627 \series bold
2670 \series bold
2628 -c\SpecialChar ~
2671 -c\SpecialChar ~
2629 <command>:
2672 <command>:
2630 \family default
2673 \family default
2631 \series default
2674 \series default
2632 execute the given command string, and set sys.argv to
2675 execute the given command string, and set sys.argv to
2633 \family typewriter
2676 \family typewriter
2634 ['c']
2677 ['c']
2635 \family default
2678 \family default
2636 .
2679 .
2637 This is similar to the
2680 This is similar to the
2638 \family typewriter
2681 \family typewriter
2639 -c
2682 -c
2640 \family default
2683 \family default
2641 option in the normal Python interpreter.
2684 option in the normal Python interpreter.
2642
2685
2643 \layout List
2686 \layout List
2644 \labelwidthstring 00.00.0000
2687 \labelwidthstring 00.00.0000
2645
2688
2646
2689
2647 \family typewriter
2690 \family typewriter
2648 \series bold
2691 \series bold
2649 -cache_size|cs\SpecialChar ~
2692 -cache_size|cs\SpecialChar ~
2650 <n>
2693 <n>
2651 \series default
2694 \series default
2652 :
2695 :
2653 \family default
2696 \family default
2654 size of the output cache (maximum number of entries to hold in memory).
2697 size of the output cache (maximum number of entries to hold in memory).
2655 The default is 1000, you can change it permanently in your config file.
2698 The default is 1000, you can change it permanently in your config file.
2656 Setting it to 0 completely disables the caching system, and the minimum
2699 Setting it to 0 completely disables the caching system, and the minimum
2657 value accepted is 20 (if you provide a value less than 20, it is reset
2700 value accepted is 20 (if you provide a value less than 20, it is reset
2658 to 0 and a warning is issued) This limit is defined because otherwise you'll
2701 to 0 and a warning is issued) This limit is defined because otherwise you'll
2659 spend more time re-flushing a too small cache than working.
2702 spend more time re-flushing a too small cache than working.
2660 \layout List
2703 \layout List
2661 \labelwidthstring 00.00.0000
2704 \labelwidthstring 00.00.0000
2662
2705
2663
2706
2664 \family typewriter
2707 \family typewriter
2665 \series bold
2708 \series bold
2666 -classic|cl
2709 -classic|cl
2667 \series default
2710 \series default
2668 :
2711 :
2669 \family default
2712 \family default
2670 Gives IPython a similar feel to the classic Python prompt.
2713 Gives IPython a similar feel to the classic Python prompt.
2671 \layout List
2714 \layout List
2672 \labelwidthstring 00.00.0000
2715 \labelwidthstring 00.00.0000
2673
2716
2674
2717
2675 \family typewriter
2718 \family typewriter
2676 \series bold
2719 \series bold
2677 -colors\SpecialChar ~
2720 -colors\SpecialChar ~
2678 <scheme>:
2721 <scheme>:
2679 \family default
2722 \family default
2680 \series default
2723 \series default
2681 Color scheme for prompts and exception reporting.
2724 Color scheme for prompts and exception reporting.
2682 Currently implemented: NoColor, Linux and LightBG.
2725 Currently implemented: NoColor, Linux and LightBG.
2683 \layout List
2726 \layout List
2684 \labelwidthstring 00.00.0000
2727 \labelwidthstring 00.00.0000
2685
2728
2686
2729
2687 \family typewriter
2730 \family typewriter
2688 \series bold
2731 \series bold
2689 -no|color_info:
2732 -no|color_info:
2690 \family default
2733 \family default
2691 \series default
2734 \series default
2692 IPython can display information about objects via a set of functions, and
2735 IPython can display information about objects via a set of functions, and
2693 optionally can use colors for this, syntax highlighting source code and
2736 optionally can use colors for this, syntax highlighting source code and
2694 various other elements.
2737 various other elements.
2695 However, because this information is passed through a pager (like 'less')
2738 However, because this information is passed through a pager (like 'less')
2696 and many pagers get confused with color codes, this option is off by default.
2739 and many pagers get confused with color codes, this option is off by default.
2697 You can test it and turn it on permanently in your ipythonrc file if it
2740 You can test it and turn it on permanently in your ipythonrc file if it
2698 works for you.
2741 works for you.
2699 As a reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
2742 As a reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
2700 that in RedHat 7.2 doesn't.
2743 that in RedHat 7.2 doesn't.
2701 \layout List
2744 \layout List
2702 \labelwidthstring 00.00.0000
2745 \labelwidthstring 00.00.0000
2703
2746
2704 \SpecialChar ~
2747 \SpecialChar ~
2705 Test it and turn it on permanently if it works with your system.
2748 Test it and turn it on permanently if it works with your system.
2706 The magic function
2749 The magic function
2707 \family typewriter
2750 \family typewriter
2708 %color_info
2751 %color_info
2709 \family default
2752 \family default
2710 allows you to toggle this interactively for testing.
2753 allows you to toggle this interactively for testing.
2711 \layout List
2754 \layout List
2712 \labelwidthstring 00.00.0000
2755 \labelwidthstring 00.00.0000
2713
2756
2714
2757
2715 \family typewriter
2758 \family typewriter
2716 \series bold
2759 \series bold
2717 -no|debug
2760 -no|debug
2718 \family default
2761 \family default
2719 \series default
2762 \series default
2720 : Show information about the loading process.
2763 : Show information about the loading process.
2721 Very useful to pin down problems with your configuration files or to get
2764 Very useful to pin down problems with your configuration files or to get
2722 details about session restores.
2765 details about session restores.
2723 \layout List
2766 \layout List
2724 \labelwidthstring 00.00.0000
2767 \labelwidthstring 00.00.0000
2725
2768
2726
2769
2727 \family typewriter
2770 \family typewriter
2728 \series bold
2771 \series bold
2729 -no|deep_reload
2772 -no|deep_reload
2730 \series default
2773 \series default
2731 :
2774 :
2732 \family default
2775 \family default
2733 IPython can use the
2776 IPython can use the
2734 \family typewriter
2777 \family typewriter
2735 deep_reload
2778 deep_reload
2736 \family default
2779 \family default
2737 module which reloads changes in modules recursively (it replaces the
2780 module which reloads changes in modules recursively (it replaces the
2738 \family typewriter
2781 \family typewriter
2739 reload()
2782 reload()
2740 \family default
2783 \family default
2741 function, so you don't need to change anything to use it).
2784 function, so you don't need to change anything to use it).
2742
2785
2743 \family typewriter
2786 \family typewriter
2744 deep_reload()
2787 deep_reload()
2745 \family default
2788 \family default
2746 forces a full reload of modules whose code may have changed, which the
2789 forces a full reload of modules whose code may have changed, which the
2747 default
2790 default
2748 \family typewriter
2791 \family typewriter
2749 reload()
2792 reload()
2750 \family default
2793 \family default
2751 function does not.
2794 function does not.
2752 \layout List
2795 \layout List
2753 \labelwidthstring 00.00.0000
2796 \labelwidthstring 00.00.0000
2754
2797
2755 \SpecialChar ~
2798 \SpecialChar ~
2756 When deep_reload is off, IPython will use the normal
2799 When deep_reload is off, IPython will use the normal
2757 \family typewriter
2800 \family typewriter
2758 reload()
2801 reload()
2759 \family default
2802 \family default
2760 , but deep_reload will still be available as
2803 , but deep_reload will still be available as
2761 \family typewriter
2804 \family typewriter
2762 dreload()
2805 dreload()
2763 \family default
2806 \family default
2764 .
2807 .
2765 This feature is off by default [which means that you have both normal
2808 This feature is off by default [which means that you have both normal
2766 \family typewriter
2809 \family typewriter
2767 reload()
2810 reload()
2768 \family default
2811 \family default
2769 and
2812 and
2770 \family typewriter
2813 \family typewriter
2771 dreload()
2814 dreload()
2772 \family default
2815 \family default
2773 ].
2816 ].
2774 \layout List
2817 \layout List
2775 \labelwidthstring 00.00.0000
2818 \labelwidthstring 00.00.0000
2776
2819
2777
2820
2778 \family typewriter
2821 \family typewriter
2779 \series bold
2822 \series bold
2780 -editor\SpecialChar ~
2823 -editor\SpecialChar ~
2781 <name>
2824 <name>
2782 \family default
2825 \family default
2783 \series default
2826 \series default
2784 : Which editor to use with the
2827 : Which editor to use with the
2785 \family typewriter
2828 \family typewriter
2786 %edit
2829 %edit
2787 \family default
2830 \family default
2788 command.
2831 command.
2789 By default, IPython will honor your
2832 By default, IPython will honor your
2790 \family typewriter
2833 \family typewriter
2791 EDITOR
2834 EDITOR
2792 \family default
2835 \family default
2793 environment variable (if not set, vi is the Unix default and notepad the
2836 environment variable (if not set, vi is the Unix default and notepad the
2794 Windows one).
2837 Windows one).
2795 Since this editor is invoked on the fly by IPython and is meant for editing
2838 Since this editor is invoked on the fly by IPython and is meant for editing
2796 small code snippets, you may want to use a small, lightweight editor here
2839 small code snippets, you may want to use a small, lightweight editor here
2797 (in case your default
2840 (in case your default
2798 \family typewriter
2841 \family typewriter
2799 EDITOR
2842 EDITOR
2800 \family default
2843 \family default
2801 is something like Emacs).
2844 is something like Emacs).
2802 \layout List
2845 \layout List
2803 \labelwidthstring 00.00.0000
2846 \labelwidthstring 00.00.0000
2804
2847
2805
2848
2806 \family typewriter
2849 \family typewriter
2807 \series bold
2850 \series bold
2808 -ipythondir\SpecialChar ~
2851 -ipythondir\SpecialChar ~
2809 <name>
2852 <name>
2810 \series default
2853 \series default
2811 :
2854 :
2812 \family default
2855 \family default
2813 name of your IPython configuration directory
2856 name of your IPython configuration directory
2814 \family typewriter
2857 \family typewriter
2815 IPYTHONDIR
2858 IPYTHONDIR
2816 \family default
2859 \family default
2817 .
2860 .
2818 This can also be specified through the environment variable
2861 This can also be specified through the environment variable
2819 \family typewriter
2862 \family typewriter
2820 IPYTHONDIR
2863 IPYTHONDIR
2821 \family default
2864 \family default
2822 .
2865 .
2823 \layout List
2866 \layout List
2824 \labelwidthstring 00.00.0000
2867 \labelwidthstring 00.00.0000
2825
2868
2826
2869
2827 \family typewriter
2870 \family typewriter
2828 \series bold
2871 \series bold
2829 -log|l
2872 -log|l
2830 \family default
2873 \family default
2831 \series default
2874 \series default
2832 : generate a log file of all input.
2875 : generate a log file of all input.
2833 Defaults to
2876 Defaults to
2834 \family typewriter
2877 \family typewriter
2835 $IPYTHONDIR/log
2878 $IPYTHONDIR/log
2836 \family default
2879 \family default
2837 .
2880 .
2838 You can use this to later restore a session by loading your logfile as
2881 You can use this to later restore a session by loading your logfile as
2839 a file to be executed with option
2882 a file to be executed with option
2840 \family typewriter
2883 \family typewriter
2841 -logplay
2884 -logplay
2842 \family default
2885 \family default
2843 (see below).
2886 (see below).
2844 \layout List
2887 \layout List
2845 \labelwidthstring 00.00.0000
2888 \labelwidthstring 00.00.0000
2846
2889
2847
2890
2848 \family typewriter
2891 \family typewriter
2849 \series bold
2892 \series bold
2850 -logfile|lf\SpecialChar ~
2893 -logfile|lf\SpecialChar ~
2851 <name>
2894 <name>
2852 \series default
2895 \series default
2853 :
2896 :
2854 \family default
2897 \family default
2855 specify the name of your logfile.
2898 specify the name of your logfile.
2856 \layout List
2899 \layout List
2857 \labelwidthstring 00.00.0000
2900 \labelwidthstring 00.00.0000
2858
2901
2859
2902
2860 \family typewriter
2903 \family typewriter
2861 \series bold
2904 \series bold
2862 -logplay|lp\SpecialChar ~
2905 -logplay|lp\SpecialChar ~
2863 <name>
2906 <name>
2864 \series default
2907 \series default
2865 :
2908 :
2866 \family default
2909 \family default
2867 you can replay a previous log.
2910 you can replay a previous log.
2868 For restoring a session as close as possible to the state you left it in,
2911 For restoring a session as close as possible to the state you left it in,
2869 use this option (don't just run the logfile).
2912 use this option (don't just run the logfile).
2870 With
2913 With
2871 \family typewriter
2914 \family typewriter
2872 -logplay
2915 -logplay
2873 \family default
2916 \family default
2874 , IPython will try to reconstruct the previous working environment in full,
2917 , IPython will try to reconstruct the previous working environment in full,
2875 not just execute the commands in the logfile.
2918 not just execute the commands in the logfile.
2876 \layout List
2919 \layout List
2877 \labelwidthstring 00.00.0000
2920 \labelwidthstring 00.00.0000
2878
2921
2879 \SpecialChar ~
2922 \SpecialChar ~
2880 When a session is restored, logging is automatically turned on again with
2923 When a session is restored, logging is automatically turned on again with
2881 the name of the logfile it was invoked with (it is read from the log header).
2924 the name of the logfile it was invoked with (it is read from the log header).
2882 So once you've turned logging on for a session, you can quit IPython and
2925 So once you've turned logging on for a session, you can quit IPython and
2883 reload it as many times as you want and it will continue to log its history
2926 reload it as many times as you want and it will continue to log its history
2884 and restore from the beginning every time.
2927 and restore from the beginning every time.
2885 \layout List
2928 \layout List
2886 \labelwidthstring 00.00.0000
2929 \labelwidthstring 00.00.0000
2887
2930
2888 \SpecialChar ~
2931 \SpecialChar ~
2889 Caveats: there are limitations in this option.
2932 Caveats: there are limitations in this option.
2890 The history variables
2933 The history variables
2891 \family typewriter
2934 \family typewriter
2892 _i*
2935 _i*
2893 \family default
2936 \family default
2894 ,
2937 ,
2895 \family typewriter
2938 \family typewriter
2896 _*
2939 _*
2897 \family default
2940 \family default
2898 and
2941 and
2899 \family typewriter
2942 \family typewriter
2900 _dh
2943 _dh
2901 \family default
2944 \family default
2902 don't get restored properly.
2945 don't get restored properly.
2903 In the future we will try to implement full session saving by writing and
2946 In the future we will try to implement full session saving by writing and
2904 retrieving a 'snapshot' of the memory state of IPython.
2947 retrieving a 'snapshot' of the memory state of IPython.
2905 But our first attempts failed because of inherent limitations of Python's
2948 But our first attempts failed because of inherent limitations of Python's
2906 Pickle module, so this may have to wait.
2949 Pickle module, so this may have to wait.
2907 \layout List
2950 \layout List
2908 \labelwidthstring 00.00.0000
2951 \labelwidthstring 00.00.0000
2909
2952
2910
2953
2911 \family typewriter
2954 \family typewriter
2912 \series bold
2955 \series bold
2913 -no|messages
2956 -no|messages
2914 \series default
2957 \series default
2915 :
2958 :
2916 \family default
2959 \family default
2917 Print messages which IPython collects about its startup process (default
2960 Print messages which IPython collects about its startup process (default
2918 on).
2961 on).
2919 \layout List
2962 \layout List
2920 \labelwidthstring 00.00.0000
2963 \labelwidthstring 00.00.0000
2921
2964
2922
2965
2923 \family typewriter
2966 \family typewriter
2924 \series bold
2967 \series bold
2925 -no|pdb
2968 -no|pdb
2926 \family default
2969 \family default
2927 \series default
2970 \series default
2928 : Automatically call the pdb debugger after every uncaught exception.
2971 : Automatically call the pdb debugger after every uncaught exception.
2929 If you are used to debugging using pdb, this puts you automatically inside
2972 If you are used to debugging using pdb, this puts you automatically inside
2930 of it after any call (either in IPython or in code called by it) which
2973 of it after any call (either in IPython or in code called by it) which
2931 triggers an exception which goes uncaught.
2974 triggers an exception which goes uncaught.
2932 \layout List
2975 \layout List
2933 \labelwidthstring 00.00.0000
2976 \labelwidthstring 00.00.0000
2934
2977
2935
2978
2936 \family typewriter
2979 \family typewriter
2937 \series bold
2980 \series bold
2938 -no|pprint
2981 -no|pprint
2939 \series default
2982 \series default
2940 :
2983 :
2941 \family default
2984 \family default
2942 ipython can optionally use the pprint (pretty printer) module for displaying
2985 ipython can optionally use the pprint (pretty printer) module for displaying
2943 results.
2986 results.
2944 pprint tends to give a nicer display of nested data structures.
2987 pprint tends to give a nicer display of nested data structures.
2945 If you like it, you can turn it on permanently in your config file (default
2988 If you like it, you can turn it on permanently in your config file (default
2946 off).
2989 off).
2947 \layout List
2990 \layout List
2948 \labelwidthstring 00.00.0000
2991 \labelwidthstring 00.00.0000
2949
2992
2950
2993
2951 \family typewriter
2994 \family typewriter
2952 \series bold
2995 \series bold
2953 -profile|p <name>
2996 -profile|p <name>
2954 \series default
2997 \series default
2955 :
2998 :
2956 \family default
2999 \family default
2957 assume that your config file is
3000 assume that your config file is
2958 \family typewriter
3001 \family typewriter
2959 ipythonrc-<name>
3002 ipythonrc-<name>
2960 \family default
3003 \family default
2961 (looks in current dir first, then in
3004 (looks in current dir first, then in
2962 \family typewriter
3005 \family typewriter
2963 IPYTHONDIR
3006 IPYTHONDIR
2964 \family default
3007 \family default
2965 ).
3008 ).
2966 This is a quick way to keep and load multiple config files for different
3009 This is a quick way to keep and load multiple config files for different
2967 tasks, especially if you use the include option of config files.
3010 tasks, especially if you use the include option of config files.
2968 You can keep a basic
3011 You can keep a basic
2969 \family typewriter
3012 \family typewriter
2970 IPYTHONDIR/ipythonrc
3013 IPYTHONDIR/ipythonrc
2971 \family default
3014 \family default
2972 file and then have other 'profiles' which include this one and load extra
3015 file and then have other 'profiles' which include this one and load extra
2973 things for particular tasks.
3016 things for particular tasks.
2974 For example:
3017 For example:
2975 \layout List
3018 \layout List
2976 \labelwidthstring 00.00.0000
3019 \labelwidthstring 00.00.0000
2977
3020
2978
3021
2979 \family typewriter
3022 \family typewriter
2980 \SpecialChar ~
3023 \SpecialChar ~
2981
3024
2982 \family default
3025 \family default
2983 1.
3026 1.
2984
3027
2985 \family typewriter
3028 \family typewriter
2986 $HOME/.ipython/ipythonrc
3029 $HOME/.ipython/ipythonrc
2987 \family default
3030 \family default
2988 : load basic things you always want.
3031 : load basic things you always want.
2989 \layout List
3032 \layout List
2990 \labelwidthstring 00.00.0000
3033 \labelwidthstring 00.00.0000
2991
3034
2992
3035
2993 \family typewriter
3036 \family typewriter
2994 \SpecialChar ~
3037 \SpecialChar ~
2995
3038
2996 \family default
3039 \family default
2997 2.
3040 2.
2998
3041
2999 \family typewriter
3042 \family typewriter
3000 $HOME/.ipython/ipythonrc-math
3043 $HOME/.ipython/ipythonrc-math
3001 \family default
3044 \family default
3002 : load (1) and basic math-related modules.
3045 : load (1) and basic math-related modules.
3003
3046
3004 \layout List
3047 \layout List
3005 \labelwidthstring 00.00.0000
3048 \labelwidthstring 00.00.0000
3006
3049
3007
3050
3008 \family typewriter
3051 \family typewriter
3009 \SpecialChar ~
3052 \SpecialChar ~
3010
3053
3011 \family default
3054 \family default
3012 3.
3055 3.
3013
3056
3014 \family typewriter
3057 \family typewriter
3015 $HOME/.ipython/ipythonrc-numeric
3058 $HOME/.ipython/ipythonrc-numeric
3016 \family default
3059 \family default
3017 : load (1) and Numeric and plotting modules.
3060 : load (1) and Numeric and plotting modules.
3018 \layout List
3061 \layout List
3019 \labelwidthstring 00.00.0000
3062 \labelwidthstring 00.00.0000
3020
3063
3021 \SpecialChar ~
3064 \SpecialChar ~
3022 Since it is possible to create an endless loop by having circular file
3065 Since it is possible to create an endless loop by having circular file
3023 inclusions, IPython will stop if it reaches 15 recursive inclusions.
3066 inclusions, IPython will stop if it reaches 15 recursive inclusions.
3024 \layout List
3067 \layout List
3025 \labelwidthstring 00.00.0000
3068 \labelwidthstring 00.00.0000
3026
3069
3027
3070
3028 \family typewriter
3071 \family typewriter
3029 \series bold
3072 \series bold
3030 -prompt_in1|pi1\SpecialChar ~
3073 -prompt_in1|pi1\SpecialChar ~
3031 <string>:
3074 <string>:
3032 \family default
3075 \family default
3033 \series default
3076 \series default
3034 Specify the string used for input prompts.
3077 Specify the string used for input prompts.
3035 Note that if you are using numbered prompts, the number is represented
3078 Note that if you are using numbered prompts, the number is represented
3036 with a '
3079 with a '
3037 \backslash
3080 \backslash
3038 #' in the string.
3081 #' in the string.
3039 Don't forget to quote strings with spaces embedded in them.
3082 Don't forget to quote strings with spaces embedded in them.
3040 Default: '
3083 Default: '
3041 \family typewriter
3084 \family typewriter
3042 In\SpecialChar ~
3085 In\SpecialChar ~
3043 [
3086 [
3044 \backslash
3087 \backslash
3045 #]:
3088 #]:
3046 \family default
3089 \family default
3047 '.
3090 '.
3048 Sec.\SpecialChar ~
3091 Sec.\SpecialChar ~
3049
3092
3050 \begin_inset LatexCommand \ref{sec:prompts}
3093 \begin_inset LatexCommand \ref{sec:prompts}
3051
3094
3052 \end_inset
3095 \end_inset
3053
3096
3054 discusses in detail all the available escapes to customize your prompts.
3097 discusses in detail all the available escapes to customize your prompts.
3055 \layout List
3098 \layout List
3056 \labelwidthstring 00.00.0000
3099 \labelwidthstring 00.00.0000
3057
3100
3058
3101
3059 \family typewriter
3102 \family typewriter
3060 \series bold
3103 \series bold
3061 -prompt_in2|pi2\SpecialChar ~
3104 -prompt_in2|pi2\SpecialChar ~
3062 <string>:
3105 <string>:
3063 \family default
3106 \family default
3064 \series default
3107 \series default
3065 Similar to the previous option, but used for the continuation prompts.
3108 Similar to the previous option, but used for the continuation prompts.
3066 The special sequence '
3109 The special sequence '
3067 \family typewriter
3110 \family typewriter
3068
3111
3069 \backslash
3112 \backslash
3070 D
3113 D
3071 \family default
3114 \family default
3072 ' is similar to '
3115 ' is similar to '
3073 \family typewriter
3116 \family typewriter
3074
3117
3075 \backslash
3118 \backslash
3076 #
3119 #
3077 \family default
3120 \family default
3078 ', but with all digits replaced dots (so you can have your continuation
3121 ', but with all digits replaced dots (so you can have your continuation
3079 prompt aligned with your input prompt).
3122 prompt aligned with your input prompt).
3080 Default: '
3123 Default: '
3081 \family typewriter
3124 \family typewriter
3082 \SpecialChar ~
3125 \SpecialChar ~
3083 \SpecialChar ~
3126 \SpecialChar ~
3084 \SpecialChar ~
3127 \SpecialChar ~
3085 .
3128 .
3086 \backslash
3129 \backslash
3087 D.:
3130 D.:
3088 \family default
3131 \family default
3089 ' (note three spaces at the start for alignment with '
3132 ' (note three spaces at the start for alignment with '
3090 \family typewriter
3133 \family typewriter
3091 In\SpecialChar ~
3134 In\SpecialChar ~
3092 [
3135 [
3093 \backslash
3136 \backslash
3094 #]
3137 #]
3095 \family default
3138 \family default
3096 ').
3139 ').
3097 \layout List
3140 \layout List
3098 \labelwidthstring 00.00.0000
3141 \labelwidthstring 00.00.0000
3099
3142
3100
3143
3101 \family typewriter
3144 \family typewriter
3102 \series bold
3145 \series bold
3103 -prompt_out|po\SpecialChar ~
3146 -prompt_out|po\SpecialChar ~
3104 <string>:
3147 <string>:
3105 \family default
3148 \family default
3106 \series default
3149 \series default
3107 String used for output prompts, also uses numbers like
3150 String used for output prompts, also uses numbers like
3108 \family typewriter
3151 \family typewriter
3109 prompt_in1
3152 prompt_in1
3110 \family default
3153 \family default
3111 .
3154 .
3112 Default: '
3155 Default: '
3113 \family typewriter
3156 \family typewriter
3114 Out[
3157 Out[
3115 \backslash
3158 \backslash
3116 #]:
3159 #]:
3117 \family default
3160 \family default
3118 '
3161 '
3119 \layout List
3162 \layout List
3120 \labelwidthstring 00.00.0000
3163 \labelwidthstring 00.00.0000
3121
3164
3122
3165
3123 \family typewriter
3166 \family typewriter
3124 \series bold
3167 \series bold
3125 -quick
3168 -quick
3126 \family default
3169 \family default
3127 \series default
3170 \series default
3128 : start in bare bones mode (no config file loaded).
3171 : start in bare bones mode (no config file loaded).
3129 \layout List
3172 \layout List
3130 \labelwidthstring 00.00.0000
3173 \labelwidthstring 00.00.0000
3131
3174
3132
3175
3133 \family typewriter
3176 \family typewriter
3134 \series bold
3177 \series bold
3135 -rcfile\SpecialChar ~
3178 -rcfile\SpecialChar ~
3136 <name>
3179 <name>
3137 \series default
3180 \series default
3138 :
3181 :
3139 \family default
3182 \family default
3140 name of your IPython resource configuration file.
3183 name of your IPython resource configuration file.
3141 Normally IPython loads ipythonrc (from current directory) or
3184 Normally IPython loads ipythonrc (from current directory) or
3142 \family typewriter
3185 \family typewriter
3143 IPYTHONDIR/ipythonrc
3186 IPYTHONDIR/ipythonrc
3144 \family default
3187 \family default
3145 .
3188 .
3146 \layout List
3189 \layout List
3147 \labelwidthstring 00.00.0000
3190 \labelwidthstring 00.00.0000
3148
3191
3149 \SpecialChar ~
3192 \SpecialChar ~
3150 If the loading of your config file fails, IPython starts with a bare bones
3193 If the loading of your config file fails, IPython starts with a bare bones
3151 configuration (no modules loaded at all).
3194 configuration (no modules loaded at all).
3152 \layout List
3195 \layout List
3153 \labelwidthstring 00.00.0000
3196 \labelwidthstring 00.00.0000
3154
3197
3155
3198
3156 \family typewriter
3199 \family typewriter
3157 \series bold
3200 \series bold
3158 -no|readline
3201 -no|readline
3159 \family default
3202 \family default
3160 \series default
3203 \series default
3161 : use the readline library, which is needed to support name completion and
3204 : use the readline library, which is needed to support name completion and
3162 command history, among other things.
3205 command history, among other things.
3163 It is enabled by default, but may cause problems for users of X/Emacs in
3206 It is enabled by default, but may cause problems for users of X/Emacs in
3164 Python comint or shell buffers.
3207 Python comint or shell buffers.
3165 \layout List
3208 \layout List
3166 \labelwidthstring 00.00.0000
3209 \labelwidthstring 00.00.0000
3167
3210
3168 \SpecialChar ~
3211 \SpecialChar ~
3169 Note that X/Emacs 'eterm' buffers (opened with
3212 Note that X/Emacs 'eterm' buffers (opened with
3170 \family typewriter
3213 \family typewriter
3171 M-x\SpecialChar ~
3214 M-x\SpecialChar ~
3172 term
3215 term
3173 \family default
3216 \family default
3174 ) support IPython's readline and syntax coloring fine, only 'emacs' (
3217 ) support IPython's readline and syntax coloring fine, only 'emacs' (
3175 \family typewriter
3218 \family typewriter
3176 M-x\SpecialChar ~
3219 M-x\SpecialChar ~
3177 shell
3220 shell
3178 \family default
3221 \family default
3179 and
3222 and
3180 \family typewriter
3223 \family typewriter
3181 C-c\SpecialChar ~
3224 C-c\SpecialChar ~
3182 !
3225 !
3183 \family default
3226 \family default
3184 ) buffers do not.
3227 ) buffers do not.
3185 \layout List
3228 \layout List
3186 \labelwidthstring 00.00.0000
3229 \labelwidthstring 00.00.0000
3187
3230
3188
3231
3189 \family typewriter
3232 \family typewriter
3190 \series bold
3233 \series bold
3191 -screen_length|sl\SpecialChar ~
3234 -screen_length|sl\SpecialChar ~
3192 <n>
3235 <n>
3193 \series default
3236 \series default
3194 :
3237 :
3195 \family default
3238 \family default
3196 number of lines of your screen.
3239 number of lines of your screen.
3197 This is used to control printing of very long strings.
3240 This is used to control printing of very long strings.
3198 Strings longer than this number of lines will be sent through a pager instead
3241 Strings longer than this number of lines will be sent through a pager instead
3199 of directly printed.
3242 of directly printed.
3200 \layout List
3243 \layout List
3201 \labelwidthstring 00.00.0000
3244 \labelwidthstring 00.00.0000
3202
3245
3203 \SpecialChar ~
3246 \SpecialChar ~
3204 The default value for this is 0, which means IPython will auto-detect your
3247 The default value for this is 0, which means IPython will auto-detect your
3205 screen size every time it needs to print certain potentially long strings
3248 screen size every time it needs to print certain potentially long strings
3206 (this doesn't change the behavior of the 'print' keyword, it's only triggered
3249 (this doesn't change the behavior of the 'print' keyword, it's only triggered
3207 internally).
3250 internally).
3208 If for some reason this isn't working well (it needs curses support), specify
3251 If for some reason this isn't working well (it needs curses support), specify
3209 it yourself.
3252 it yourself.
3210 Otherwise don't change the default.
3253 Otherwise don't change the default.
3211 \layout List
3254 \layout List
3212 \labelwidthstring 00.00.0000
3255 \labelwidthstring 00.00.0000
3213
3256
3214
3257
3215 \family typewriter
3258 \family typewriter
3216 \series bold
3259 \series bold
3217 -separate_in|si\SpecialChar ~
3260 -separate_in|si\SpecialChar ~
3218 <string>
3261 <string>
3219 \series default
3262 \series default
3220 :
3263 :
3221 \family default
3264 \family default
3222 separator before input prompts.
3265 separator before input prompts.
3223 Default: '
3266 Default: '
3224 \family typewriter
3267 \family typewriter
3225
3268
3226 \backslash
3269 \backslash
3227 n
3270 n
3228 \family default
3271 \family default
3229 '
3272 '
3230 \layout List
3273 \layout List
3231 \labelwidthstring 00.00.0000
3274 \labelwidthstring 00.00.0000
3232
3275
3233
3276
3234 \family typewriter
3277 \family typewriter
3235 \series bold
3278 \series bold
3236 -separate_out|so\SpecialChar ~
3279 -separate_out|so\SpecialChar ~
3237 <string>
3280 <string>
3238 \family default
3281 \family default
3239 \series default
3282 \series default
3240 : separator before output prompts.
3283 : separator before output prompts.
3241 Default: nothing.
3284 Default: nothing.
3242 \layout List
3285 \layout List
3243 \labelwidthstring 00.00.0000
3286 \labelwidthstring 00.00.0000
3244
3287
3245
3288
3246 \family typewriter
3289 \family typewriter
3247 \series bold
3290 \series bold
3248 -separate_out2|so2\SpecialChar ~
3291 -separate_out2|so2\SpecialChar ~
3249 <string>
3292 <string>
3250 \series default
3293 \series default
3251 :
3294 :
3252 \family default
3295 \family default
3253 separator after output prompts.
3296 separator after output prompts.
3254 Default: nothing.
3297 Default: nothing.
3255 \layout List
3298 \layout List
3256 \labelwidthstring 00.00.0000
3299 \labelwidthstring 00.00.0000
3257
3300
3258 \SpecialChar ~
3301 \SpecialChar ~
3259 For these three options, use the value 0 to specify no separator.
3302 For these three options, use the value 0 to specify no separator.
3260 \layout List
3303 \layout List
3261 \labelwidthstring 00.00.0000
3304 \labelwidthstring 00.00.0000
3262
3305
3263
3306
3264 \family typewriter
3307 \family typewriter
3265 \series bold
3308 \series bold
3266 -nosep
3309 -nosep
3267 \series default
3310 \series default
3268 :
3311 :
3269 \family default
3312 \family default
3270 shorthand for
3313 shorthand for
3271 \family typewriter
3314 \family typewriter
3272 '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'
3315 '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'
3273 \family default
3316 \family default
3274 .
3317 .
3275 Simply removes all input/output separators.
3318 Simply removes all input/output separators.
3276 \layout List
3319 \layout List
3277 \labelwidthstring 00.00.0000
3320 \labelwidthstring 00.00.0000
3278
3321
3279
3322
3280 \family typewriter
3323 \family typewriter
3281 \series bold
3324 \series bold
3282 -upgrade
3325 -upgrade
3283 \family default
3326 \family default
3284 \series default
3327 \series default
3285 : allows you to upgrade your
3328 : allows you to upgrade your
3286 \family typewriter
3329 \family typewriter
3287 IPYTHONDIR
3330 IPYTHONDIR
3288 \family default
3331 \family default
3289 configuration when you install a new version of IPython.
3332 configuration when you install a new version of IPython.
3290 Since new versions may include new command line options or example files,
3333 Since new versions may include new command line options or example files,
3291 this copies updated ipythonrc-type files.
3334 this copies updated ipythonrc-type files.
3292 However, it backs up (with a
3335 However, it backs up (with a
3293 \family typewriter
3336 \family typewriter
3294 .old
3337 .old
3295 \family default
3338 \family default
3296 extension) all files which it overwrites so that you can merge back any
3339 extension) all files which it overwrites so that you can merge back any
3297 customizations you might have in your personal files.
3340 customizations you might have in your personal files.
3298 \layout List
3341 \layout List
3299 \labelwidthstring 00.00.0000
3342 \labelwidthstring 00.00.0000
3300
3343
3301
3344
3302 \family typewriter
3345 \family typewriter
3303 \series bold
3346 \series bold
3304 -Version
3347 -Version
3305 \series default
3348 \series default
3306 :
3349 :
3307 \family default
3350 \family default
3308 print version information and exit.
3351 print version information and exit.
3309 \layout List
3352 \layout List
3310 \labelwidthstring 00.00.0000
3353 \labelwidthstring 00.00.0000
3311
3354
3312
3355
3313 \family typewriter
3356 \family typewriter
3314 \series bold
3357 \series bold
3315 -xmode <modename>
3358 -xmode <modename>
3316 \series default
3359 \series default
3317 :
3360 :
3318 \family default
3361 \family default
3319 Mode for exception reporting.
3362 Mode for exception reporting.
3320 \layout List
3363 \layout List
3321 \labelwidthstring 00.00.0000
3364 \labelwidthstring 00.00.0000
3322
3365
3323 \SpecialChar ~
3366 \SpecialChar ~
3324 Valid modes: Plain, Context and Verbose.
3367 Valid modes: Plain, Context and Verbose.
3325 \layout List
3368 \layout List
3326 \labelwidthstring 00.00.0000
3369 \labelwidthstring 00.00.0000
3327
3370
3328 \SpecialChar ~
3371 \SpecialChar ~
3329 Plain: similar to python's normal traceback printing.
3372 Plain: similar to python's normal traceback printing.
3330 \layout List
3373 \layout List
3331 \labelwidthstring 00.00.0000
3374 \labelwidthstring 00.00.0000
3332
3375
3333 \SpecialChar ~
3376 \SpecialChar ~
3334 Context: prints 5 lines of context source code around each line in the
3377 Context: prints 5 lines of context source code around each line in the
3335 traceback.
3378 traceback.
3336 \layout List
3379 \layout List
3337 \labelwidthstring 00.00.0000
3380 \labelwidthstring 00.00.0000
3338
3381
3339 \SpecialChar ~
3382 \SpecialChar ~
3340 Verbose: similar to Context, but additionally prints the variables currently
3383 Verbose: similar to Context, but additionally prints the variables currently
3341 visible where the exception happened (shortening their strings if too long).
3384 visible where the exception happened (shortening their strings if too long).
3342 This can potentially be very slow, if you happen to have a huge data structure
3385 This can potentially be very slow, if you happen to have a huge data structure
3343 whose string representation is complex to compute.
3386 whose string representation is complex to compute.
3344 Your computer may appear to freeze for a while with cpu usage at 100%.
3387 Your computer may appear to freeze for a while with cpu usage at 100%.
3345 If this occurs, you can cancel the traceback with Ctrl-C (maybe hitting
3388 If this occurs, you can cancel the traceback with Ctrl-C (maybe hitting
3346 it more than once).
3389 it more than once).
3347 \layout Section
3390 \layout Section
3348
3391
3349 Interactive use
3392 Interactive use
3350 \layout Standard
3393 \layout Standard
3351
3394
3352
3395
3353 \series bold
3396 \series bold
3354 Warning
3397 Warning
3355 \series default
3398 \series default
3356 : IPython relies on the existence of a global variable called
3399 : IPython relies on the existence of a global variable called
3357 \family typewriter
3400 \family typewriter
3358 __IP
3401 __IP
3359 \family default
3402 \family default
3360 which controls the shell itself.
3403 which controls the shell itself.
3361 If you redefine
3404 If you redefine
3362 \family typewriter
3405 \family typewriter
3363 __IP
3406 __IP
3364 \family default
3407 \family default
3365 to anything, bizarre behavior will quickly occur.
3408 to anything, bizarre behavior will quickly occur.
3366 \layout Standard
3409 \layout Standard
3367
3410
3368 Other than the above warning, IPython is meant to work as a drop-in replacement
3411 Other than the above warning, IPython is meant to work as a drop-in replacement
3369 for the standard interactive interpreter.
3412 for the standard interactive interpreter.
3370 As such, any code which is valid python should execute normally under IPython
3413 As such, any code which is valid python should execute normally under IPython
3371 (cases where this is not true should be reported as bugs).
3414 (cases where this is not true should be reported as bugs).
3372 It does, however, offer many features which are not available at a standard
3415 It does, however, offer many features which are not available at a standard
3373 python prompt.
3416 python prompt.
3374 What follows is a list of these.
3417 What follows is a list of these.
3375 \layout Subsection
3418 \layout Subsection
3376
3419
3377 Caution for Windows users
3420 Caution for Windows users
3378 \layout Standard
3421 \layout Standard
3379
3422
3380 Windows, unfortunately, uses the `
3423 Windows, unfortunately, uses the `
3381 \family typewriter
3424 \family typewriter
3382
3425
3383 \backslash
3426 \backslash
3384
3427
3385 \family default
3428 \family default
3386 ' character as a path separator.
3429 ' character as a path separator.
3387 This is a terrible choice, because `
3430 This is a terrible choice, because `
3388 \family typewriter
3431 \family typewriter
3389
3432
3390 \backslash
3433 \backslash
3391
3434
3392 \family default
3435 \family default
3393 ' also represents the escape character in most modern programming languages,
3436 ' also represents the escape character in most modern programming languages,
3394 including Python.
3437 including Python.
3395 For this reason, issuing many of the commands discussed below (especially
3438 For this reason, issuing many of the commands discussed below (especially
3396 magics which affect the filesystem) with `
3439 magics which affect the filesystem) with `
3397 \family typewriter
3440 \family typewriter
3398
3441
3399 \backslash
3442 \backslash
3400
3443
3401 \family default
3444 \family default
3402 ' in them will cause strange errors.
3445 ' in them will cause strange errors.
3403 \layout Standard
3446 \layout Standard
3404
3447
3405 A partial solution is to use instead the `
3448 A partial solution is to use instead the `
3406 \family typewriter
3449 \family typewriter
3407 /
3450 /
3408 \family default
3451 \family default
3409 ' character as a path separator, which Windows recognizes in
3452 ' character as a path separator, which Windows recognizes in
3410 \emph on
3453 \emph on
3411 most
3454 most
3412 \emph default
3455 \emph default
3413 situations.
3456 situations.
3414 However, in Windows commands `
3457 However, in Windows commands `
3415 \family typewriter
3458 \family typewriter
3416 /
3459 /
3417 \family default
3460 \family default
3418 ' flags options, so you can not use it for the root directory.
3461 ' flags options, so you can not use it for the root directory.
3419 This means that paths beginning at the root must be typed in a contrived
3462 This means that paths beginning at the root must be typed in a contrived
3420 manner like:
3463 manner like:
3421 \newline
3464 \newline
3422
3465
3423 \family typewriter
3466 \family typewriter
3424 %copy
3467 %copy
3425 \backslash
3468 \backslash
3426 opt/foo/bar.txt
3469 opt/foo/bar.txt
3427 \backslash
3470 \backslash
3428 tmp
3471 tmp
3429 \layout Standard
3472 \layout Standard
3430
3473
3431 There is no sensible thing IPython can do to truly work around this flaw
3474 There is no sensible thing IPython can do to truly work around this flaw
3432 in Windows
3475 in Windows
3433 \begin_inset Foot
3476 \begin_inset Foot
3434 collapsed true
3477 collapsed true
3435
3478
3436 \layout Standard
3479 \layout Standard
3437
3480
3438 If anyone comes up with a
3481 If anyone comes up with a
3439 \emph on
3482 \emph on
3440 clean
3483 clean
3441 \emph default
3484 \emph default
3442 solution which works consistently and does not negatively impact other
3485 solution which works consistently and does not negatively impact other
3443 platforms at all, I'll gladly accept a patch.
3486 platforms at all, I'll gladly accept a patch.
3444 \end_inset
3487 \end_inset
3445
3488
3446 .
3489 .
3447 \layout Subsection
3490 \layout Subsection
3448
3491
3449
3492
3450 \begin_inset LatexCommand \label{sec:magic}
3493 \begin_inset LatexCommand \label{sec:magic}
3451
3494
3452 \end_inset
3495 \end_inset
3453
3496
3454 Magic command system
3497 Magic command system
3455 \layout Standard
3498 \layout Standard
3456
3499
3457 IPython will treat any line whose first character is a
3500 IPython will treat any line whose first character is a
3458 \family typewriter
3501 \family typewriter
3459 %
3502 %
3460 \family default
3503 \family default
3461 as a special call to a 'magic' function.
3504 as a special call to a 'magic' function.
3462 These allow you to control the behavior of IPython itself, plus a lot of
3505 These allow you to control the behavior of IPython itself, plus a lot of
3463 system-type features.
3506 system-type features.
3464 They are all prefixed with a
3507 They are all prefixed with a
3465 \family typewriter
3508 \family typewriter
3466 %
3509 %
3467 \family default
3510 \family default
3468 character, but parameters are given without parentheses or quotes.
3511 character, but parameters are given without parentheses or quotes.
3469 \layout Standard
3512 \layout Standard
3470
3513
3471 Example: typing
3514 Example: typing
3472 \family typewriter
3515 \family typewriter
3473 '%cd mydir'
3516 '%cd mydir'
3474 \family default
3517 \family default
3475 (without the quotes) changes you working directory to
3518 (without the quotes) changes you working directory to
3476 \family typewriter
3519 \family typewriter
3477 'mydir'
3520 'mydir'
3478 \family default
3521 \family default
3479 , if it exists.
3522 , if it exists.
3480 \layout Standard
3523 \layout Standard
3481
3524
3482 If you have 'automagic' enabled (in your
3525 If you have 'automagic' enabled (in your
3483 \family typewriter
3526 \family typewriter
3484 ipythonrc
3527 ipythonrc
3485 \family default
3528 \family default
3486 file, via the command line option
3529 file, via the command line option
3487 \family typewriter
3530 \family typewriter
3488 -automagic
3531 -automagic
3489 \family default
3532 \family default
3490 or with the
3533 or with the
3491 \family typewriter
3534 \family typewriter
3492 %automagic
3535 %automagic
3493 \family default
3536 \family default
3494 function), you don't need to type in the
3537 function), you don't need to type in the
3495 \family typewriter
3538 \family typewriter
3496 %
3539 %
3497 \family default
3540 \family default
3498 explicitly.
3541 explicitly.
3499 IPython will scan its internal list of magic functions and call one if
3542 IPython will scan its internal list of magic functions and call one if
3500 it exists.
3543 it exists.
3501 With automagic on you can then just type '
3544 With automagic on you can then just type '
3502 \family typewriter
3545 \family typewriter
3503 cd mydir
3546 cd mydir
3504 \family default
3547 \family default
3505 ' to go to directory '
3548 ' to go to directory '
3506 \family typewriter
3549 \family typewriter
3507 mydir
3550 mydir
3508 \family default
3551 \family default
3509 '.
3552 '.
3510 The automagic system has the lowest possible precedence in name searches,
3553 The automagic system has the lowest possible precedence in name searches,
3511 so defining an identifier with the same name as an existing magic function
3554 so defining an identifier with the same name as an existing magic function
3512 will shadow it for automagic use.
3555 will shadow it for automagic use.
3513 You can still access the shadowed magic function by explicitly using the
3556 You can still access the shadowed magic function by explicitly using the
3514
3557
3515 \family typewriter
3558 \family typewriter
3516 %
3559 %
3517 \family default
3560 \family default
3518 character at the beginning of the line.
3561 character at the beginning of the line.
3519 \layout Standard
3562 \layout Standard
3520
3563
3521 An example (with automagic on) should clarify all this:
3564 An example (with automagic on) should clarify all this:
3522 \layout LyX-Code
3565 \layout LyX-Code
3523
3566
3524 In [1]: cd ipython # %cd is called by automagic
3567 In [1]: cd ipython # %cd is called by automagic
3525 \layout LyX-Code
3568 \layout LyX-Code
3526
3569
3527 /home/fperez/ipython
3570 /home/fperez/ipython
3528 \layout LyX-Code
3571 \layout LyX-Code
3529
3572
3530 In [2]: cd=1 # now cd is just a variable
3573 In [2]: cd=1 # now cd is just a variable
3531 \layout LyX-Code
3574 \layout LyX-Code
3532
3575
3533 In [3]: cd ..
3576 In [3]: cd ..
3534 # and doesn't work as a function anymore
3577 # and doesn't work as a function anymore
3535 \layout LyX-Code
3578 \layout LyX-Code
3536
3579
3537 ------------------------------------------------------------
3580 ------------------------------------------------------------
3538 \layout LyX-Code
3581 \layout LyX-Code
3539
3582
3540 File "<console>", line 1
3583 File "<console>", line 1
3541 \layout LyX-Code
3584 \layout LyX-Code
3542
3585
3543 cd ..
3586 cd ..
3544 \layout LyX-Code
3587 \layout LyX-Code
3545
3588
3546 ^
3589 ^
3547 \layout LyX-Code
3590 \layout LyX-Code
3548
3591
3549 SyntaxError: invalid syntax
3592 SyntaxError: invalid syntax
3550 \layout LyX-Code
3593 \layout LyX-Code
3551
3594
3552 \layout LyX-Code
3595 \layout LyX-Code
3553
3596
3554 In [4]: %cd ..
3597 In [4]: %cd ..
3555 # but %cd always works
3598 # but %cd always works
3556 \layout LyX-Code
3599 \layout LyX-Code
3557
3600
3558 /home/fperez
3601 /home/fperez
3559 \layout LyX-Code
3602 \layout LyX-Code
3560
3603
3561 In [5]: del cd # if you remove the cd variable
3604 In [5]: del cd # if you remove the cd variable
3562 \layout LyX-Code
3605 \layout LyX-Code
3563
3606
3564 In [6]: cd ipython # automagic can work again
3607 In [6]: cd ipython # automagic can work again
3565 \layout LyX-Code
3608 \layout LyX-Code
3566
3609
3567 /home/fperez/ipython
3610 /home/fperez/ipython
3568 \layout Standard
3611 \layout Standard
3569
3612
3570 You can define your own magic functions to extend the system.
3613 You can define your own magic functions to extend the system.
3571 The following is a snippet of code which shows how to do it.
3614 The following is a snippet of code which shows how to do it.
3572 It is provided as file
3615 It is provided as file
3573 \family typewriter
3616 \family typewriter
3574 example-magic.py
3617 example-magic.py
3575 \family default
3618 \family default
3576 in the examples directory:
3619 in the examples directory:
3577 \layout Standard
3620 \layout Standard
3578
3621
3579
3622
3580 \begin_inset Include \verbatiminput{examples/example-magic.py}
3623 \begin_inset ERT
3581 preview false
3624 status Open
3625
3626 \layout Standard
3582
3627
3628 \backslash
3629 lstinputlisting{examples/example-magic.py}
3583 \end_inset
3630 \end_inset
3584
3631
3585
3632
3586 \layout Standard
3633 \layout Standard
3587
3634
3588 You can also define your own aliased names for magic functions.
3635 You can also define your own aliased names for magic functions.
3589 In your
3636 In your
3590 \family typewriter
3637 \family typewriter
3591 ipythonrc
3638 ipythonrc
3592 \family default
3639 \family default
3593 file, placing a line like:
3640 file, placing a line like:
3594 \layout Standard
3641 \layout Standard
3595
3642
3596
3643
3597 \family typewriter
3644 \family typewriter
3598 execute __IP.magic_cl = __IP.magic_clear
3645 execute __IP.magic_cl = __IP.magic_clear
3599 \layout Standard
3646 \layout Standard
3600
3647
3601 will define
3648 will define
3602 \family typewriter
3649 \family typewriter
3603 %cl
3650 %cl
3604 \family default
3651 \family default
3605 as a new name for
3652 as a new name for
3606 \family typewriter
3653 \family typewriter
3607 %clear
3654 %clear
3608 \family default
3655 \family default
3609 .
3656 .
3610 \layout Standard
3657 \layout Standard
3611
3658
3612 Type
3659 Type
3613 \family typewriter
3660 \family typewriter
3614 %magic
3661 %magic
3615 \family default
3662 \family default
3616 for more information, including a list of all available magic functions
3663 for more information, including a list of all available magic functions
3617 at any time and their docstrings.
3664 at any time and their docstrings.
3618 You can also type
3665 You can also type
3619 \family typewriter
3666 \family typewriter
3620 %magic_function_name?
3667 %magic_function_name?
3621 \family default
3668 \family default
3622 (see sec.
3669 (see sec.
3623
3670
3624 \begin_inset LatexCommand \ref{sec:dyn-object-info}
3671 \begin_inset LatexCommand \ref{sec:dyn-object-info}
3625
3672
3626 \end_inset
3673 \end_inset
3627
3674
3628 for information on the
3675 for information on the
3629 \family typewriter
3676 \family typewriter
3630 '?'
3677 '?'
3631 \family default
3678 \family default
3632 system) to get information about any particular magic function you are
3679 system) to get information about any particular magic function you are
3633 interested in.
3680 interested in.
3634 \layout Subsubsection
3681 \layout Subsubsection
3635
3682
3636 Magic commands
3683 Magic commands
3637 \layout Standard
3684 \layout Standard
3638
3685
3639 The rest of this section is automatically generated for each release from
3686 The rest of this section is automatically generated for each release from
3640 the docstrings in the IPython code.
3687 the docstrings in the IPython code.
3641 Therefore the formatting is somewhat minimal, but this method has the advantage
3688 Therefore the formatting is somewhat minimal, but this method has the advantage
3642 of having information always in sync with the code.
3689 of having information always in sync with the code.
3643 \layout Standard
3690 \layout Standard
3644
3691
3645 A list of all the magic commands available in IPython's
3692 A list of all the magic commands available in IPython's
3646 \emph on
3693 \emph on
3647 default
3694 default
3648 \emph default
3695 \emph default
3649 installation follows.
3696 installation follows.
3650 This is similar to what you'll see by simply typing
3697 This is similar to what you'll see by simply typing
3651 \family typewriter
3698 \family typewriter
3652 %magic
3699 %magic
3653 \family default
3700 \family default
3654 at the prompt, but that will also give you information about magic commands
3701 at the prompt, but that will also give you information about magic commands
3655 you may have added as part of your personal customizations.
3702 you may have added as part of your personal customizations.
3656 \layout Standard
3703 \layout Standard
3657
3704
3658
3705
3659 \begin_inset Include \input{magic.tex}
3706 \begin_inset Include \input{magic.tex}
3660 preview false
3707 preview false
3661
3708
3662 \end_inset
3709 \end_inset
3663
3710
3664
3711
3665 \layout Subsection
3712 \layout Subsection
3666
3713
3667 Access to the standard Python help
3714 Access to the standard Python help
3668 \layout Standard
3715 \layout Standard
3669
3716
3670 As of Python 2.1, a help system is available with access to object docstrings
3717 As of Python 2.1, a help system is available with access to object docstrings
3671 and the Python manuals.
3718 and the Python manuals.
3672 Simply type
3719 Simply type
3673 \family typewriter
3720 \family typewriter
3674 'help'
3721 'help'
3675 \family default
3722 \family default
3676 (no quotes) to access it.
3723 (no quotes) to access it.
3677 You can also type
3724 You can also type
3678 \family typewriter
3725 \family typewriter
3679 help(object)
3726 help(object)
3680 \family default
3727 \family default
3681 to obtain information about a given object, and
3728 to obtain information about a given object, and
3682 \family typewriter
3729 \family typewriter
3683 help('keyword')
3730 help('keyword')
3684 \family default
3731 \family default
3685 for information on a keyword.
3732 for information on a keyword.
3686 As noted in sec.
3733 As noted in sec.
3687
3734
3688 \begin_inset LatexCommand \ref{sec:help-access}
3735 \begin_inset LatexCommand \ref{sec:help-access}
3689
3736
3690 \end_inset
3737 \end_inset
3691
3738
3692 , you need to properly configure your environment variable
3739 , you need to properly configure your environment variable
3693 \family typewriter
3740 \family typewriter
3694 PYTHONDOCS
3741 PYTHONDOCS
3695 \family default
3742 \family default
3696 for this feature to work correctly.
3743 for this feature to work correctly.
3697 \layout Subsection
3744 \layout Subsection
3698
3745
3699
3746
3700 \begin_inset LatexCommand \label{sec:dyn-object-info}
3747 \begin_inset LatexCommand \label{sec:dyn-object-info}
3701
3748
3702 \end_inset
3749 \end_inset
3703
3750
3704 Dynamic object information
3751 Dynamic object information
3705 \layout Standard
3752 \layout Standard
3706
3753
3707 Typing
3754 Typing
3708 \family typewriter
3755 \family typewriter
3709 ?word
3756 ?word
3710 \family default
3757 \family default
3711 or
3758 or
3712 \family typewriter
3759 \family typewriter
3713 word?
3760 word?
3714 \family default
3761 \family default
3715 prints detailed information about an object.
3762 prints detailed information about an object.
3716 If certain strings in the object are too long (docstrings, code, etc.) they
3763 If certain strings in the object are too long (docstrings, code, etc.) they
3717 get snipped in the center for brevity.
3764 get snipped in the center for brevity.
3718 This system gives access variable types and values, full source code for
3765 This system gives access variable types and values, full source code for
3719 any object (if available), function prototypes and other useful information.
3766 any object (if available), function prototypes and other useful information.
3720 \layout Standard
3767 \layout Standard
3721
3768
3722 Typing
3769 Typing
3723 \family typewriter
3770 \family typewriter
3724 ??word
3771 ??word
3725 \family default
3772 \family default
3726 or
3773 or
3727 \family typewriter
3774 \family typewriter
3728 word??
3775 word??
3729 \family default
3776 \family default
3730 gives access to the full information without snipping long strings.
3777 gives access to the full information without snipping long strings.
3731 Long strings are sent to the screen through the
3778 Long strings are sent to the screen through the
3732 \family typewriter
3779 \family typewriter
3733 less
3780 less
3734 \family default
3781 \family default
3735 pager if longer than the screen and printed otherwise.
3782 pager if longer than the screen and printed otherwise.
3736 On systems lacking the
3783 On systems lacking the
3737 \family typewriter
3784 \family typewriter
3738 less
3785 less
3739 \family default
3786 \family default
3740 command, IPython uses a very basic internal pager.
3787 command, IPython uses a very basic internal pager.
3741 \layout Standard
3788 \layout Standard
3742
3789
3743 The following magic functions are particularly useful for gathering information
3790 The following magic functions are particularly useful for gathering information
3744 about your working environment.
3791 about your working environment.
3745 You can get more details by typing
3792 You can get more details by typing
3746 \family typewriter
3793 \family typewriter
3747 %magic
3794 %magic
3748 \family default
3795 \family default
3749 or querying them individually (use
3796 or querying them individually (use
3750 \family typewriter
3797 \family typewriter
3751 %function_name?
3798 %function_name?
3752 \family default
3799 \family default
3753 with or without the
3800 with or without the
3754 \family typewriter
3801 \family typewriter
3755 %
3802 %
3756 \family default
3803 \family default
3757 ), this is just a summary:
3804 ), this is just a summary:
3758 \layout List
3805 \layout List
3759 \labelwidthstring 00.00.0000
3806 \labelwidthstring 00.00.0000
3760
3807
3761
3808
3762 \family typewriter
3809 \family typewriter
3763 \series bold
3810 \series bold
3764 %pdoc\SpecialChar ~
3811 %pdoc\SpecialChar ~
3765 <object>
3812 <object>
3766 \family default
3813 \family default
3767 \series default
3814 \series default
3768 : Print (or run through a pager if too long) the docstring for an object.
3815 : Print (or run through a pager if too long) the docstring for an object.
3769 If the given object is a class, it will print both the class and the constructo
3816 If the given object is a class, it will print both the class and the constructo
3770 r docstrings.
3817 r docstrings.
3771 \layout List
3818 \layout List
3772 \labelwidthstring 00.00.0000
3819 \labelwidthstring 00.00.0000
3773
3820
3774
3821
3775 \family typewriter
3822 \family typewriter
3776 \series bold
3823 \series bold
3777 %pdef\SpecialChar ~
3824 %pdef\SpecialChar ~
3778 <object>
3825 <object>
3779 \family default
3826 \family default
3780 \series default
3827 \series default
3781 : Print the definition header for any callable object.
3828 : Print the definition header for any callable object.
3782 If the object is a class, print the constructor information.
3829 If the object is a class, print the constructor information.
3783 \layout List
3830 \layout List
3784 \labelwidthstring 00.00.0000
3831 \labelwidthstring 00.00.0000
3785
3832
3786
3833
3787 \family typewriter
3834 \family typewriter
3788 \series bold
3835 \series bold
3789 %psource\SpecialChar ~
3836 %psource\SpecialChar ~
3790 <object>
3837 <object>
3791 \family default
3838 \family default
3792 \series default
3839 \series default
3793 : Print (or run through a pager if too long) the source code for an object.
3840 : Print (or run through a pager if too long) the source code for an object.
3794 \layout List
3841 \layout List
3795 \labelwidthstring 00.00.0000
3842 \labelwidthstring 00.00.0000
3796
3843
3797
3844
3798 \family typewriter
3845 \family typewriter
3799 \series bold
3846 \series bold
3800 %pfile\SpecialChar ~
3847 %pfile\SpecialChar ~
3801 <object>
3848 <object>
3802 \family default
3849 \family default
3803 \series default
3850 \series default
3804 : Show the entire source file where an object was defined via a pager, opening
3851 : Show the entire source file where an object was defined via a pager, opening
3805 it at the line where the object definition begins.
3852 it at the line where the object definition begins.
3806 \layout List
3853 \layout List
3807 \labelwidthstring 00.00.0000
3854 \labelwidthstring 00.00.0000
3808
3855
3809
3856
3810 \family typewriter
3857 \family typewriter
3811 \series bold
3858 \series bold
3812 %who/%whos
3859 %who/%whos
3813 \family default
3860 \family default
3814 \series default
3861 \series default
3815 : These functions give information about identifiers you have defined interactiv
3862 : These functions give information about identifiers you have defined interactiv
3816 ely (not things you loaded or defined in your configuration files).
3863 ely (not things you loaded or defined in your configuration files).
3817
3864
3818 \family typewriter
3865 \family typewriter
3819 %who
3866 %who
3820 \family default
3867 \family default
3821 just prints a list of identifiers and
3868 just prints a list of identifiers and
3822 \family typewriter
3869 \family typewriter
3823 %whos
3870 %whos
3824 \family default
3871 \family default
3825 prints a table with some basic details about each identifier.
3872 prints a table with some basic details about each identifier.
3826 \layout Standard
3873 \layout Standard
3827
3874
3828 Note that the dynamic object information functions (
3875 Note that the dynamic object information functions (
3829 \family typewriter
3876 \family typewriter
3830 ?/??, %pdoc, %pfile, %pdef, %psource
3877 ?/??, %pdoc, %pfile, %pdef, %psource
3831 \family default
3878 \family default
3832 ) give you access to documentation even on things which are not really defined
3879 ) give you access to documentation even on things which are not really defined
3833 as separate identifiers.
3880 as separate identifiers.
3834 Try for example typing
3881 Try for example typing
3835 \family typewriter
3882 \family typewriter
3836 {}.get?
3883 {}.get?
3837 \family default
3884 \family default
3838 or after doing
3885 or after doing
3839 \family typewriter
3886 \family typewriter
3840 import os
3887 import os
3841 \family default
3888 \family default
3842 , type
3889 , type
3843 \family typewriter
3890 \family typewriter
3844 os.path.abspath??
3891 os.path.abspath??
3845 \family default
3892 \family default
3846 .
3893 .
3847 \layout Subsection
3894 \layout Subsection
3848
3895
3849
3896
3850 \begin_inset LatexCommand \label{sec:readline}
3897 \begin_inset LatexCommand \label{sec:readline}
3851
3898
3852 \end_inset
3899 \end_inset
3853
3900
3854 Readline-based features
3901 Readline-based features
3855 \layout Standard
3902 \layout Standard
3856
3903
3857 These features require the GNU readline library, so they won't work if your
3904 These features require the GNU readline library, so they won't work if your
3858 Python installation lacks readline support.
3905 Python installation lacks readline support.
3859 We will first describe the default behavior IPython uses, and then how
3906 We will first describe the default behavior IPython uses, and then how
3860 to change it to suit your preferences.
3907 to change it to suit your preferences.
3861 \layout Subsubsection
3908 \layout Subsubsection
3862
3909
3863 Command line completion
3910 Command line completion
3864 \layout Standard
3911 \layout Standard
3865
3912
3866 At any time, hitting TAB will complete any available python commands or
3913 At any time, hitting TAB will complete any available python commands or
3867 variable names, and show you a list of the possible completions if there's
3914 variable names, and show you a list of the possible completions if there's
3868 no unambiguous one.
3915 no unambiguous one.
3869 It will also complete filenames in the current directory if no python names
3916 It will also complete filenames in the current directory if no python names
3870 match what you've typed so far.
3917 match what you've typed so far.
3871 \layout Subsubsection
3918 \layout Subsubsection
3872
3919
3873 Search command history
3920 Search command history
3874 \layout Standard
3921 \layout Standard
3875
3922
3876 IPython provides two ways for searching through previous input and thus
3923 IPython provides two ways for searching through previous input and thus
3877 reduce the need for repetitive typing:
3924 reduce the need for repetitive typing:
3878 \layout Enumerate
3925 \layout Enumerate
3879
3926
3880 Start typing, and then use
3927 Start typing, and then use
3881 \family typewriter
3928 \family typewriter
3882 Ctrl-p
3929 Ctrl-p
3883 \family default
3930 \family default
3884 (previous,up) and
3931 (previous,up) and
3885 \family typewriter
3932 \family typewriter
3886 Ctrl-n
3933 Ctrl-n
3887 \family default
3934 \family default
3888 (next,down) to search through only the history items that match what you've
3935 (next,down) to search through only the history items that match what you've
3889 typed so far.
3936 typed so far.
3890 If you use
3937 If you use
3891 \family typewriter
3938 \family typewriter
3892 Ctrl-p/Ctrl-n
3939 Ctrl-p/Ctrl-n
3893 \family default
3940 \family default
3894 at a blank prompt, they just behave like normal arrow keys.
3941 at a blank prompt, they just behave like normal arrow keys.
3895 \layout Enumerate
3942 \layout Enumerate
3896
3943
3897 Hit
3944 Hit
3898 \family typewriter
3945 \family typewriter
3899 Ctrl-r
3946 Ctrl-r
3900 \family default
3947 \family default
3901 : opens a search prompt.
3948 : opens a search prompt.
3902 Begin typing and the system searches your history for lines that contain
3949 Begin typing and the system searches your history for lines that contain
3903 what you've typed so far, completing as much as it can.
3950 what you've typed so far, completing as much as it can.
3904 \layout Subsubsection
3951 \layout Subsubsection
3905
3952
3906 Persistent command history across sessions
3953 Persistent command history across sessions
3907 \layout Standard
3954 \layout Standard
3908
3955
3909 IPython will save your input history when it leaves and reload it next time
3956 IPython will save your input history when it leaves and reload it next time
3910 you restart it.
3957 you restart it.
3911 By default, the history file is named
3958 By default, the history file is named
3912 \family typewriter
3959 \family typewriter
3913 $IPYTHONDIR/history
3960 $IPYTHONDIR/history
3914 \family default
3961 \family default
3915 , but if you've loaded a named profile, '
3962 , but if you've loaded a named profile, '
3916 \family typewriter
3963 \family typewriter
3917 -PROFILE_NAME
3964 -PROFILE_NAME
3918 \family default
3965 \family default
3919 ' is appended to the name.
3966 ' is appended to the name.
3920 This allows you to keep separate histories related to various tasks: commands
3967 This allows you to keep separate histories related to various tasks: commands
3921 related to numerical work will not be clobbered by a system shell history,
3968 related to numerical work will not be clobbered by a system shell history,
3922 for example.
3969 for example.
3923 \layout Subsubsection
3970 \layout Subsubsection
3924
3971
3925 Autoindent
3972 Autoindent
3926 \layout Standard
3973 \layout Standard
3927
3974
3928 IPython can recognize lines ending in ':' and indent the next line, while
3975 IPython can recognize lines ending in ':' and indent the next line, while
3929 also un-indenting automatically after 'raise' or 'return'.
3976 also un-indenting automatically after 'raise' or 'return'.
3930
3977
3931 \layout Standard
3978 \layout Standard
3932
3979
3933 This feature uses the readline library, so it will honor your
3980 This feature uses the readline library, so it will honor your
3934 \family typewriter
3981 \family typewriter
3935 ~/.inputrc
3982 ~/.inputrc
3936 \family default
3983 \family default
3937 configuration (or whatever file your
3984 configuration (or whatever file your
3938 \family typewriter
3985 \family typewriter
3939 INPUTRC
3986 INPUTRC
3940 \family default
3987 \family default
3941 variable points to).
3988 variable points to).
3942 Adding the following lines to your
3989 Adding the following lines to your
3943 \family typewriter
3990 \family typewriter
3944 .inputrc
3991 .inputrc
3945 \family default
3992 \family default
3946 file can make indenting/unindenting more convenient (
3993 file can make indenting/unindenting more convenient (
3947 \family typewriter
3994 \family typewriter
3948 M-i
3995 M-i
3949 \family default
3996 \family default
3950 indents,
3997 indents,
3951 \family typewriter
3998 \family typewriter
3952 M-u
3999 M-u
3953 \family default
4000 \family default
3954 unindents):
4001 unindents):
3955 \layout Standard
4002 \layout Standard
3956
4003
3957
4004
3958 \family typewriter
4005 \family typewriter
3959 $if Python
4006 $if Python
3960 \newline
4007 \newline
3961 "
4008 "
3962 \backslash
4009 \backslash
3963 M-i": "\SpecialChar ~
4010 M-i": "\SpecialChar ~
3964 \SpecialChar ~
4011 \SpecialChar ~
3965 \SpecialChar ~
4012 \SpecialChar ~
3966 \SpecialChar ~
4013 \SpecialChar ~
3967 "
4014 "
3968 \newline
4015 \newline
3969 "
4016 "
3970 \backslash
4017 \backslash
3971 M-u": "
4018 M-u": "
3972 \backslash
4019 \backslash
3973 d
4020 d
3974 \backslash
4021 \backslash
3975 d
4022 d
3976 \backslash
4023 \backslash
3977 d
4024 d
3978 \backslash
4025 \backslash
3979 d"
4026 d"
3980 \newline
4027 \newline
3981 $endif
4028 $endif
3982 \layout Standard
4029 \layout Standard
3983
4030
3984 Note that there are 4 spaces between the quote marks after
4031 Note that there are 4 spaces between the quote marks after
3985 \family typewriter
4032 \family typewriter
3986 "M-i"
4033 "M-i"
3987 \family default
4034 \family default
3988 above.
4035 above.
3989 \layout Standard
4036 \layout Standard
3990
4037
3991
4038
3992 \series bold
4039 \series bold
3993 Warning:
4040 Warning:
3994 \series default
4041 \series default
3995 this feature is ON by default, but it can cause problems with the pasting
4042 this feature is ON by default, but it can cause problems with the pasting
3996 of multi-line indented code (the pasted code gets re-indented on each line).
4043 of multi-line indented code (the pasted code gets re-indented on each line).
3997 A magic function
4044 A magic function
3998 \family typewriter
4045 \family typewriter
3999 %autoindent
4046 %autoindent
4000 \family default
4047 \family default
4001 allows you to toggle it on/off at runtime.
4048 allows you to toggle it on/off at runtime.
4002 You can also disable it permanently on in your
4049 You can also disable it permanently on in your
4003 \family typewriter
4050 \family typewriter
4004 ipythonrc
4051 ipythonrc
4005 \family default
4052 \family default
4006 file (set
4053 file (set
4007 \family typewriter
4054 \family typewriter
4008 autoindent 0
4055 autoindent 0
4009 \family default
4056 \family default
4010 ).
4057 ).
4011 \layout Subsubsection
4058 \layout Subsubsection
4012
4059
4013 Customizing readline behavior
4060 Customizing readline behavior
4014 \layout Standard
4061 \layout Standard
4015
4062
4016 All these features are based on the GNU readline library, which has an extremely
4063 All these features are based on the GNU readline library, which has an extremely
4017 customizable interface.
4064 customizable interface.
4018 Normally, readline is configured via a file which defines the behavior
4065 Normally, readline is configured via a file which defines the behavior
4019 of the library; the details of the syntax for this can be found in the
4066 of the library; the details of the syntax for this can be found in the
4020 readline documentation available with your system or on the Internet.
4067 readline documentation available with your system or on the Internet.
4021 IPython doesn't read this file (if it exists) directly, but it does support
4068 IPython doesn't read this file (if it exists) directly, but it does support
4022 passing to readline valid options via a simple interface.
4069 passing to readline valid options via a simple interface.
4023 In brief, you can customize readline by setting the following options in
4070 In brief, you can customize readline by setting the following options in
4024 your
4071 your
4025 \family typewriter
4072 \family typewriter
4026 ipythonrc
4073 ipythonrc
4027 \family default
4074 \family default
4028 configuration file (note that these options can
4075 configuration file (note that these options can
4029 \emph on
4076 \emph on
4030 not
4077 not
4031 \emph default
4078 \emph default
4032 be specified at the command line):
4079 be specified at the command line):
4033 \layout List
4080 \layout List
4034 \labelwidthstring 00.00.0000
4081 \labelwidthstring 00.00.0000
4035
4082
4036
4083
4037 \family typewriter
4084 \family typewriter
4038 \series bold
4085 \series bold
4039 readline_parse_and_bind:
4086 readline_parse_and_bind:
4040 \family default
4087 \family default
4041 \series default
4088 \series default
4042 this option can appear as many times as you want, each time defining a
4089 this option can appear as many times as you want, each time defining a
4043 string to be executed via a
4090 string to be executed via a
4044 \family typewriter
4091 \family typewriter
4045 readline.parse_and_bind()
4092 readline.parse_and_bind()
4046 \family default
4093 \family default
4047 command.
4094 command.
4048 The syntax for valid commands of this kind can be found by reading the
4095 The syntax for valid commands of this kind can be found by reading the
4049 documentation for the GNU readline library, as these commands are of the
4096 documentation for the GNU readline library, as these commands are of the
4050 kind which readline accepts in its configuration file.
4097 kind which readline accepts in its configuration file.
4051 \layout List
4098 \layout List
4052 \labelwidthstring 00.00.0000
4099 \labelwidthstring 00.00.0000
4053
4100
4054
4101
4055 \family typewriter
4102 \family typewriter
4056 \series bold
4103 \series bold
4057 readline_remove_delims:
4104 readline_remove_delims:
4058 \family default
4105 \family default
4059 \series default
4106 \series default
4060 a string of characters to be removed from the default word-delimiters list
4107 a string of characters to be removed from the default word-delimiters list
4061 used by readline, so that completions may be performed on strings which
4108 used by readline, so that completions may be performed on strings which
4062 contain them.
4109 contain them.
4063 Do not change the default value unless you know what you're doing.
4110 Do not change the default value unless you know what you're doing.
4064 \layout List
4111 \layout List
4065 \labelwidthstring 00.00.0000
4112 \labelwidthstring 00.00.0000
4066
4113
4067
4114
4068 \family typewriter
4115 \family typewriter
4069 \series bold
4116 \series bold
4070 readline_omit__names
4117 readline_omit__names
4071 \family default
4118 \family default
4072 \series default
4119 \series default
4073 : when tab-completion is enabled, hitting
4120 : when tab-completion is enabled, hitting
4074 \family typewriter
4121 \family typewriter
4075 <tab>
4122 <tab>
4076 \family default
4123 \family default
4077 after a '
4124 after a '
4078 \family typewriter
4125 \family typewriter
4079 .
4126 .
4080 \family default
4127 \family default
4081 ' in a name will complete all attributes of an object, including all the
4128 ' in a name will complete all attributes of an object, including all the
4082 special methods whose names include double underscores (like
4129 special methods whose names include double underscores (like
4083 \family typewriter
4130 \family typewriter
4084 __getitem__
4131 __getitem__
4085 \family default
4132 \family default
4086 or
4133 or
4087 \family typewriter
4134 \family typewriter
4088 __class__
4135 __class__
4089 \family default
4136 \family default
4090 ).
4137 ).
4091 If you'd rather not see these names by default, you can set this option
4138 If you'd rather not see these names by default, you can set this option
4092 to 1.
4139 to 1.
4093 Note that even when this option is set, you can still see those names by
4140 Note that even when this option is set, you can still see those names by
4094 explicitly typing a
4141 explicitly typing a
4095 \family typewriter
4142 \family typewriter
4096 _
4143 _
4097 \family default
4144 \family default
4098 after the period and hitting
4145 after the period and hitting
4099 \family typewriter
4146 \family typewriter
4100 <tab>
4147 <tab>
4101 \family default
4148 \family default
4102 : '
4149 : '
4103 \family typewriter
4150 \family typewriter
4104 name._<tab>
4151 name._<tab>
4105 \family default
4152 \family default
4106 ' will always complete attribute names starting with '
4153 ' will always complete attribute names starting with '
4107 \family typewriter
4154 \family typewriter
4108 _
4155 _
4109 \family default
4156 \family default
4110 '.
4157 '.
4111 \layout List
4158 \layout List
4112 \labelwidthstring 00.00.0000
4159 \labelwidthstring 00.00.0000
4113
4160
4114 \SpecialChar ~
4161 \SpecialChar ~
4115 This option is off by default so that new users see all attributes of any
4162 This option is off by default so that new users see all attributes of any
4116 objects they are dealing with.
4163 objects they are dealing with.
4117 \layout Standard
4164 \layout Standard
4118
4165
4119 You will find the default values along with a corresponding detailed explanation
4166 You will find the default values along with a corresponding detailed explanation
4120 in your
4167 in your
4121 \family typewriter
4168 \family typewriter
4122 ipythonrc
4169 ipythonrc
4123 \family default
4170 \family default
4124 file.
4171 file.
4125 \layout Subsection
4172 \layout Subsection
4126
4173
4127 Session logging and restoring
4174 Session logging and restoring
4128 \layout Standard
4175 \layout Standard
4129
4176
4130 You can log all input from a session either by starting IPython with the
4177 You can log all input from a session either by starting IPython with the
4131 command line switches
4178 command line switches
4132 \family typewriter
4179 \family typewriter
4133 -log
4180 -log
4134 \family default
4181 \family default
4135 or
4182 or
4136 \family typewriter
4183 \family typewriter
4137 -logfile
4184 -logfile
4138 \family default
4185 \family default
4139 (see sec.
4186 (see sec.
4140
4187
4141 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
4188 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
4142
4189
4143 \end_inset
4190 \end_inset
4144
4191
4145 )or by activating the logging at any moment with the magic function
4192 )or by activating the logging at any moment with the magic function
4146 \family typewriter
4193 \family typewriter
4147 %logstart
4194 %logstart
4148 \family default
4195 \family default
4149 .
4196 .
4150
4197
4151 \layout Standard
4198 \layout Standard
4152
4199
4153 Log files can later be reloaded with the
4200 Log files can later be reloaded with the
4154 \family typewriter
4201 \family typewriter
4155 -logplay
4202 -logplay
4156 \family default
4203 \family default
4157 option and IPython will attempt to 'replay' the log by executing all the
4204 option and IPython will attempt to 'replay' the log by executing all the
4158 lines in it, thus restoring the state of a previous session.
4205 lines in it, thus restoring the state of a previous session.
4159 This feature is not quite perfect, but can still be useful in many cases.
4206 This feature is not quite perfect, but can still be useful in many cases.
4160 \layout Standard
4207 \layout Standard
4161
4208
4162 The log files can also be used as a way to have a permanent record of any
4209 The log files can also be used as a way to have a permanent record of any
4163 code you wrote while experimenting.
4210 code you wrote while experimenting.
4164 Log files are regular text files which you can later open in your favorite
4211 Log files are regular text files which you can later open in your favorite
4165 text editor to extract code or to 'clean them up' before using them to
4212 text editor to extract code or to 'clean them up' before using them to
4166 replay a session.
4213 replay a session.
4167 \layout Standard
4214 \layout Standard
4168
4215
4169 The
4216 The
4170 \family typewriter
4217 \family typewriter
4171 %logstart
4218 %logstart
4172 \family default
4219 \family default
4173 function for activating logging in mid-session is used as follows:
4220 function for activating logging in mid-session is used as follows:
4174 \layout Standard
4221 \layout Standard
4175
4222
4176
4223
4177 \family typewriter
4224 \family typewriter
4178 %logstart [log_name [log_mode]]
4225 %logstart [log_name [log_mode]]
4179 \layout Standard
4226 \layout Standard
4180
4227
4181 If no name is given, it defaults to a file named
4228 If no name is given, it defaults to a file named
4182 \family typewriter
4229 \family typewriter
4183 'log'
4230 'log'
4184 \family default
4231 \family default
4185 in your IPYTHONDIR directory, in
4232 in your IPYTHONDIR directory, in
4186 \family typewriter
4233 \family typewriter
4187 'rotate'
4234 'rotate'
4188 \family default
4235 \family default
4189 mode (see below).
4236 mode (see below).
4190 \layout Standard
4237 \layout Standard
4191
4238
4192 '
4239 '
4193 \family typewriter
4240 \family typewriter
4194 %logstart name
4241 %logstart name
4195 \family default
4242 \family default
4196 ' saves to file
4243 ' saves to file
4197 \family typewriter
4244 \family typewriter
4198 'name'
4245 'name'
4199 \family default
4246 \family default
4200 in
4247 in
4201 \family typewriter
4248 \family typewriter
4202 'backup'
4249 'backup'
4203 \family default
4250 \family default
4204 mode.
4251 mode.
4205 It saves your history up to that point and then continues logging.
4252 It saves your history up to that point and then continues logging.
4206 \layout Standard
4253 \layout Standard
4207
4254
4208
4255
4209 \family typewriter
4256 \family typewriter
4210 %logstart
4257 %logstart
4211 \family default
4258 \family default
4212 takes a second optional parameter: logging mode.
4259 takes a second optional parameter: logging mode.
4213 This can be one of (note that the modes are given unquoted):
4260 This can be one of (note that the modes are given unquoted):
4214 \layout List
4261 \layout List
4215 \labelwidthstring 00.00.0000
4262 \labelwidthstring 00.00.0000
4216
4263
4217
4264
4218 \family typewriter
4265 \family typewriter
4219 over
4266 over
4220 \family default
4267 \family default
4221 : overwrite existing
4268 : overwrite existing
4222 \family typewriter
4269 \family typewriter
4223 log_name
4270 log_name
4224 \family default
4271 \family default
4225 .
4272 .
4226 \layout List
4273 \layout List
4227 \labelwidthstring 00.00.0000
4274 \labelwidthstring 00.00.0000
4228
4275
4229
4276
4230 \family typewriter
4277 \family typewriter
4231 backup
4278 backup
4232 \family default
4279 \family default
4233 : rename (if exists) to
4280 : rename (if exists) to
4234 \family typewriter
4281 \family typewriter
4235 log_name~
4282 log_name~
4236 \family default
4283 \family default
4237 and start
4284 and start
4238 \family typewriter
4285 \family typewriter
4239 log_name
4286 log_name
4240 \family default
4287 \family default
4241 .
4288 .
4242 \layout List
4289 \layout List
4243 \labelwidthstring 00.00.0000
4290 \labelwidthstring 00.00.0000
4244
4291
4245
4292
4246 \family typewriter
4293 \family typewriter
4247 append
4294 append
4248 \family default
4295 \family default
4249 : well, that says it.
4296 : well, that says it.
4250 \layout List
4297 \layout List
4251 \labelwidthstring 00.00.0000
4298 \labelwidthstring 00.00.0000
4252
4299
4253
4300
4254 \family typewriter
4301 \family typewriter
4255 rotate
4302 rotate
4256 \family default
4303 \family default
4257 : create rotating logs
4304 : create rotating logs
4258 \family typewriter
4305 \family typewriter
4259 log_name
4306 log_name
4260 \family default
4307 \family default
4261 .
4308 .
4262 \family typewriter
4309 \family typewriter
4263 1~
4310 1~
4264 \family default
4311 \family default
4265 ,
4312 ,
4266 \family typewriter
4313 \family typewriter
4267 log_name.2~
4314 log_name.2~
4268 \family default
4315 \family default
4269 , etc.
4316 , etc.
4270 \layout Standard
4317 \layout Standard
4271
4318
4272 The
4319 The
4273 \family typewriter
4320 \family typewriter
4274 %logoff
4321 %logoff
4275 \family default
4322 \family default
4276 and
4323 and
4277 \family typewriter
4324 \family typewriter
4278 %logon
4325 %logon
4279 \family default
4326 \family default
4280 functions allow you to temporarily stop and resume logging to a file which
4327 functions allow you to temporarily stop and resume logging to a file which
4281 had previously been started with
4328 had previously been started with
4282 \family typewriter
4329 \family typewriter
4283 %logstart
4330 %logstart
4284 \family default
4331 \family default
4285 .
4332 .
4286 They will fail (with an explanation) if you try to use them before logging
4333 They will fail (with an explanation) if you try to use them before logging
4287 has been started.
4334 has been started.
4288 \layout Subsection
4335 \layout Subsection
4289
4336
4290
4337
4291 \begin_inset LatexCommand \label{sub:System-shell-access}
4338 \begin_inset LatexCommand \label{sub:System-shell-access}
4292
4339
4293 \end_inset
4340 \end_inset
4294
4341
4295 System shell access
4342 System shell access
4296 \layout Standard
4343 \layout Standard
4297
4344
4298 Any input line beginning with a
4345 Any input line beginning with a
4299 \family typewriter
4346 \family typewriter
4300 !
4347 !
4301 \family default
4348 \family default
4302 character is passed verbatim (minus the
4349 character is passed verbatim (minus the
4303 \family typewriter
4350 \family typewriter
4304 !
4351 !
4305 \family default
4352 \family default
4306 , of course) to the underlying operating system.
4353 , of course) to the underlying operating system.
4307 For example, typing
4354 For example, typing
4308 \family typewriter
4355 \family typewriter
4309 !ls
4356 !ls
4310 \family default
4357 \family default
4311 will run
4358 will run
4312 \family typewriter
4359 \family typewriter
4313 'ls'
4360 'ls'
4314 \family default
4361 \family default
4315 in the current directory.
4362 in the current directory.
4316 \layout Subsubsection
4363 \layout Subsubsection
4317
4364
4318 Manual capture of command output
4365 Manual capture of command output
4319 \layout Standard
4366 \layout Standard
4320
4367
4321 If the input line begins with
4368 If the input line begins with
4322 \emph on
4369 \emph on
4323 two
4370 two
4324 \emph default
4371 \emph default
4325 exclamation marks,
4372 exclamation marks,
4326 \family typewriter
4373 \family typewriter
4327 !!
4374 !!
4328 \family default
4375 \family default
4329 , the command is executed but its output is captured and returned as a python
4376 , the command is executed but its output is captured and returned as a python
4330 list, split on newlines.
4377 list, split on newlines.
4331 Any output sent by the subprocess to standard error is printed separately,
4378 Any output sent by the subprocess to standard error is printed separately,
4332 so that the resulting list only captures standard output.
4379 so that the resulting list only captures standard output.
4333 The
4380 The
4334 \family typewriter
4381 \family typewriter
4335 !!
4382 !!
4336 \family default
4383 \family default
4337 syntax is a shorthand for the
4384 syntax is a shorthand for the
4338 \family typewriter
4385 \family typewriter
4339 %sx
4386 %sx
4340 \family default
4387 \family default
4341 magic command.
4388 magic command.
4342 \layout Standard
4389 \layout Standard
4343
4390
4344 Finally, the
4391 Finally, the
4345 \family typewriter
4392 \family typewriter
4346 %sc
4393 %sc
4347 \family default
4394 \family default
4348 magic (short for `shell capture') is similar to
4395 magic (short for `shell capture') is similar to
4349 \family typewriter
4396 \family typewriter
4350 %sx
4397 %sx
4351 \family default
4398 \family default
4352 , but allowing more fine-grained control of the capture details, and storing
4399 , but allowing more fine-grained control of the capture details, and storing
4353 the result directly into a named variable.
4400 the result directly into a named variable.
4354 \layout Standard
4401 \layout Standard
4355
4402
4356 See Sec.\SpecialChar ~
4403 See Sec.\SpecialChar ~
4357
4404
4358 \begin_inset LatexCommand \ref{sec:magic}
4405 \begin_inset LatexCommand \ref{sec:magic}
4359
4406
4360 \end_inset
4407 \end_inset
4361
4408
4362 for details on the magics
4409 for details on the magics
4363 \family typewriter
4410 \family typewriter
4364 %sc
4411 %sc
4365 \family default
4412 \family default
4366 and
4413 and
4367 \family typewriter
4414 \family typewriter
4368 %sx
4415 %sx
4369 \family default
4416 \family default
4370 , or use IPython's own help (
4417 , or use IPython's own help (
4371 \family typewriter
4418 \family typewriter
4372 sc?
4419 sc?
4373 \family default
4420 \family default
4374 and
4421 and
4375 \family typewriter
4422 \family typewriter
4376 sx?
4423 sx?
4377 \family default
4424 \family default
4378 ) for further details.
4425 ) for further details.
4379 \layout Standard
4426 \layout Standard
4380
4427
4381 IPython also allows you to expand the value of python variables when making
4428 IPython also allows you to expand the value of python variables when making
4382 system calls.
4429 system calls.
4383 Any python variable or expression which you prepend with
4430 Any python variable or expression which you prepend with
4384 \family typewriter
4431 \family typewriter
4385 $
4432 $
4386 \family default
4433 \family default
4387 will get expanded before the system call is made.
4434 will get expanded before the system call is made.
4388
4435
4389 \layout Standard
4436 \layout Standard
4390
4437
4391
4438
4392 \family typewriter
4439 \family typewriter
4393 In [1]: pyvar='Hello world'
4440 In [1]: pyvar='Hello world'
4394 \newline
4441 \newline
4395 In [2]: !echo "A python variable: $pyvar"
4442 In [2]: !echo "A python variable: $pyvar"
4396 \newline
4443 \newline
4397 A python variable: Hello world
4444 A python variable: Hello world
4398 \layout Standard
4445 \layout Standard
4399
4446
4400 If you want the shell to actually see a literal
4447 If you want the shell to actually see a literal
4401 \family typewriter
4448 \family typewriter
4402 $
4449 $
4403 \family default
4450 \family default
4404 , you need to type it twice:
4451 , you need to type it twice:
4405 \layout Standard
4452 \layout Standard
4406
4453
4407
4454
4408 \family typewriter
4455 \family typewriter
4409 In [3]: !echo "A system variable: $$HOME"
4456 In [3]: !echo "A system variable: $$HOME"
4410 \newline
4457 \newline
4411 A system variable: /home/fperez
4458 A system variable: /home/fperez
4412 \layout Standard
4459 \layout Standard
4413
4460
4414 You can pass arbitrary expressions, though you'll need to delimit them with
4461 You can pass arbitrary expressions, though you'll need to delimit them with
4415
4462
4416 \family typewriter
4463 \family typewriter
4417 {}
4464 {}
4418 \family default
4465 \family default
4419 if there is ambiguity as to the extent of the expression:
4466 if there is ambiguity as to the extent of the expression:
4420 \layout Standard
4467 \layout Standard
4421
4468
4422
4469
4423 \family typewriter
4470 \family typewriter
4424 In [5]: x=10
4471 In [5]: x=10
4425 \newline
4472 \newline
4426 In [6]: y=20
4473 In [6]: y=20
4427 \newline
4474 \newline
4428 In [13]: !echo $x+y
4475 In [13]: !echo $x+y
4429 \newline
4476 \newline
4430 10+y
4477 10+y
4431 \newline
4478 \newline
4432 In [7]: !echo ${x+y}
4479 In [7]: !echo ${x+y}
4433 \newline
4480 \newline
4434 30
4481 30
4435 \layout Standard
4482 \layout Standard
4436
4483
4437 Even object attributes can be expanded:
4484 Even object attributes can be expanded:
4438 \layout Standard
4485 \layout Standard
4439
4486
4440
4487
4441 \family typewriter
4488 \family typewriter
4442 In [12]: !echo $sys.argv
4489 In [12]: !echo $sys.argv
4443 \newline
4490 \newline
4444 [/home/fperez/usr/bin/ipython]
4491 [/home/fperez/usr/bin/ipython]
4445 \layout Subsection
4492 \layout Subsection
4446
4493
4447 System command aliases
4494 System command aliases
4448 \layout Standard
4495 \layout Standard
4449
4496
4450 The
4497 The
4451 \family typewriter
4498 \family typewriter
4452 %alias
4499 %alias
4453 \family default
4500 \family default
4454 magic function and the
4501 magic function and the
4455 \family typewriter
4502 \family typewriter
4456 alias
4503 alias
4457 \family default
4504 \family default
4458 option in the
4505 option in the
4459 \family typewriter
4506 \family typewriter
4460 ipythonrc
4507 ipythonrc
4461 \family default
4508 \family default
4462 configuration file allow you to define magic functions which are in fact
4509 configuration file allow you to define magic functions which are in fact
4463 system shell commands.
4510 system shell commands.
4464 These aliases can have parameters.
4511 These aliases can have parameters.
4465
4512
4466 \layout Standard
4513 \layout Standard
4467
4514
4468 '
4515 '
4469 \family typewriter
4516 \family typewriter
4470 %alias alias_name cmd
4517 %alias alias_name cmd
4471 \family default
4518 \family default
4472 ' defines '
4519 ' defines '
4473 \family typewriter
4520 \family typewriter
4474 alias_name
4521 alias_name
4475 \family default
4522 \family default
4476 ' as an alias for '
4523 ' as an alias for '
4477 \family typewriter
4524 \family typewriter
4478 cmd
4525 cmd
4479 \family default
4526 \family default
4480 '
4527 '
4481 \layout Standard
4528 \layout Standard
4482
4529
4483 Then, typing '
4530 Then, typing '
4484 \family typewriter
4531 \family typewriter
4485 %alias_name params
4532 %alias_name params
4486 \family default
4533 \family default
4487 ' will execute the system command '
4534 ' will execute the system command '
4488 \family typewriter
4535 \family typewriter
4489 cmd params
4536 cmd params
4490 \family default
4537 \family default
4491 ' (from your underlying operating system).
4538 ' (from your underlying operating system).
4492
4539
4493 \layout Standard
4540 \layout Standard
4494
4541
4495 You can also define aliases with parameters using
4542 You can also define aliases with parameters using
4496 \family typewriter
4543 \family typewriter
4497 %s
4544 %s
4498 \family default
4545 \family default
4499 specifiers (one per parameter).
4546 specifiers (one per parameter).
4500 The following example defines the
4547 The following example defines the
4501 \family typewriter
4548 \family typewriter
4502 %parts
4549 %parts
4503 \family default
4550 \family default
4504 function as an alias to the command '
4551 function as an alias to the command '
4505 \family typewriter
4552 \family typewriter
4506 echo first %s second %s
4553 echo first %s second %s
4507 \family default
4554 \family default
4508 ' where each
4555 ' where each
4509 \family typewriter
4556 \family typewriter
4510 %s
4557 %s
4511 \family default
4558 \family default
4512 will be replaced by a positional parameter to the call to
4559 will be replaced by a positional parameter to the call to
4513 \family typewriter
4560 \family typewriter
4514 %parts:
4561 %parts:
4515 \layout Standard
4562 \layout Standard
4516
4563
4517
4564
4518 \family typewriter
4565 \family typewriter
4519 In [1]: alias parts echo first %s second %s
4566 In [1]: alias parts echo first %s second %s
4520 \newline
4567 \newline
4521 In [2]: %parts A B
4568 In [2]: %parts A B
4522 \newline
4569 \newline
4523 first A second B
4570 first A second B
4524 \newline
4571 \newline
4525 In [3]: %parts A
4572 In [3]: %parts A
4526 \newline
4573 \newline
4527 Incorrect number of arguments: 2 expected.
4574 Incorrect number of arguments: 2 expected.
4528
4575
4529 \newline
4576 \newline
4530 parts is an alias to: 'echo first %s second %s'
4577 parts is an alias to: 'echo first %s second %s'
4531 \layout Standard
4578 \layout Standard
4532
4579
4533 If called with no parameters,
4580 If called with no parameters,
4534 \family typewriter
4581 \family typewriter
4535 %alias
4582 %alias
4536 \family default
4583 \family default
4537 prints the table of currently defined aliases.
4584 prints the table of currently defined aliases.
4538 \layout Standard
4585 \layout Standard
4539
4586
4540 The
4587 The
4541 \family typewriter
4588 \family typewriter
4542 %rehash/rehashx
4589 %rehash/rehashx
4543 \family default
4590 \family default
4544 magics allow you to load your entire
4591 magics allow you to load your entire
4545 \family typewriter
4592 \family typewriter
4546 $PATH
4593 $PATH
4547 \family default
4594 \family default
4548 as ipython aliases.
4595 as ipython aliases.
4549 See their respective docstrings (or sec.\SpecialChar ~
4596 See their respective docstrings (or sec.\SpecialChar ~
4550
4597
4551 \begin_inset LatexCommand \ref{sec:magic}
4598 \begin_inset LatexCommand \ref{sec:magic}
4552
4599
4553 \end_inset
4600 \end_inset
4554
4601
4555 for further details).
4602 for further details).
4556 \layout Subsection
4603 \layout Subsection
4557
4604
4558
4605
4559 \begin_inset LatexCommand \label{sec:dreload}
4606 \begin_inset LatexCommand \label{sec:dreload}
4560
4607
4561 \end_inset
4608 \end_inset
4562
4609
4563 Recursive reload
4610 Recursive reload
4564 \layout Standard
4611 \layout Standard
4565
4612
4566 The
4613 The
4567 \family typewriter
4614 \family typewriter
4568 %dreload
4615 %dreload
4569 \family default
4616 \family default
4570 command does a recursive reload of a module: changes made to the module
4617 command does a recursive reload of a module: changes made to the module
4571 since you imported will actually be available without having to exit.
4618 since you imported will actually be available without having to exit.
4572 \layout Subsection
4619 \layout Subsection
4573
4620
4574 Verbose and colored exception traceback printouts
4621 Verbose and colored exception traceback printouts
4575 \layout Standard
4622 \layout Standard
4576
4623
4577 IPython provides the option to see very detailed exception tracebacks, which
4624 IPython provides the option to see very detailed exception tracebacks, which
4578 can be especially useful when debugging large programs.
4625 can be especially useful when debugging large programs.
4579 You can run any Python file with the
4626 You can run any Python file with the
4580 \family typewriter
4627 \family typewriter
4581 %run
4628 %run
4582 \family default
4629 \family default
4583 function to benefit from these detailed tracebacks.
4630 function to benefit from these detailed tracebacks.
4584 Furthermore, both normal and verbose tracebacks can be colored (if your
4631 Furthermore, both normal and verbose tracebacks can be colored (if your
4585 terminal supports it) which makes them much easier to parse visually.
4632 terminal supports it) which makes them much easier to parse visually.
4586 \layout Standard
4633 \layout Standard
4587
4634
4588 See the magic
4635 See the magic
4589 \family typewriter
4636 \family typewriter
4590 xmode
4637 xmode
4591 \family default
4638 \family default
4592 and
4639 and
4593 \family typewriter
4640 \family typewriter
4594 colors
4641 colors
4595 \family default
4642 \family default
4596 functions for details (just type
4643 functions for details (just type
4597 \family typewriter
4644 \family typewriter
4598 %magic
4645 %magic
4599 \family default
4646 \family default
4600 ).
4647 ).
4601 \layout Standard
4648 \layout Standard
4602
4649
4603 These features are basically a terminal version of Ka-Ping Yee's
4650 These features are basically a terminal version of Ka-Ping Yee's
4604 \family typewriter
4651 \family typewriter
4605 cgitb
4652 cgitb
4606 \family default
4653 \family default
4607 module, now part of the standard Python library.
4654 module, now part of the standard Python library.
4608 \layout Subsection
4655 \layout Subsection
4609
4656
4610
4657
4611 \begin_inset LatexCommand \label{sec:cache_input}
4658 \begin_inset LatexCommand \label{sec:cache_input}
4612
4659
4613 \end_inset
4660 \end_inset
4614
4661
4615 Input caching system
4662 Input caching system
4616 \layout Standard
4663 \layout Standard
4617
4664
4618 IPython offers numbered prompts (In/Out) with input and output caching.
4665 IPython offers numbered prompts (In/Out) with input and output caching.
4619 All input is saved and can be retrieved as variables (besides the usual
4666 All input is saved and can be retrieved as variables (besides the usual
4620 arrow key recall).
4667 arrow key recall).
4621 \layout Standard
4668 \layout Standard
4622
4669
4623 The following GLOBAL variables always exist (so don't overwrite them!):
4670 The following GLOBAL variables always exist (so don't overwrite them!):
4624
4671
4625 \family typewriter
4672 \family typewriter
4626 _i
4673 _i
4627 \family default
4674 \family default
4628 : stores previous input.
4675 : stores previous input.
4629
4676
4630 \family typewriter
4677 \family typewriter
4631 _ii
4678 _ii
4632 \family default
4679 \family default
4633 : next previous.
4680 : next previous.
4634
4681
4635 \family typewriter
4682 \family typewriter
4636 _iii
4683 _iii
4637 \family default
4684 \family default
4638 : next-next previous.
4685 : next-next previous.
4639
4686
4640 \family typewriter
4687 \family typewriter
4641 _ih
4688 _ih
4642 \family default
4689 \family default
4643 : a list of all input
4690 : a list of all input
4644 \family typewriter
4691 \family typewriter
4645 _ih[n]
4692 _ih[n]
4646 \family default
4693 \family default
4647 is the input from line
4694 is the input from line
4648 \family typewriter
4695 \family typewriter
4649 n
4696 n
4650 \family default
4697 \family default
4651 and this list is aliased to the global variable
4698 and this list is aliased to the global variable
4652 \family typewriter
4699 \family typewriter
4653 In
4700 In
4654 \family default
4701 \family default
4655 .
4702 .
4656 If you overwrite
4703 If you overwrite
4657 \family typewriter
4704 \family typewriter
4658 In
4705 In
4659 \family default
4706 \family default
4660 with a variable of your own, you can remake the assignment to the internal
4707 with a variable of your own, you can remake the assignment to the internal
4661 list with a simple
4708 list with a simple
4662 \family typewriter
4709 \family typewriter
4663 'In=_ih'
4710 'In=_ih'
4664 \family default
4711 \family default
4665 .
4712 .
4666 \layout Standard
4713 \layout Standard
4667
4714
4668 Additionally, global variables named
4715 Additionally, global variables named
4669 \family typewriter
4716 \family typewriter
4670 _i<n>
4717 _i<n>
4671 \family default
4718 \family default
4672 are dynamically created (
4719 are dynamically created (
4673 \family typewriter
4720 \family typewriter
4674 <n>
4721 <n>
4675 \family default
4722 \family default
4676 being the prompt counter), such that
4723 being the prompt counter), such that
4677 \newline
4724 \newline
4678
4725
4679 \family typewriter
4726 \family typewriter
4680 _i<n> == _ih[<n>] == In[<n>].
4727 _i<n> == _ih[<n>] == In[<n>].
4681 \layout Standard
4728 \layout Standard
4682
4729
4683 For example, what you typed at prompt 14 is available as
4730 For example, what you typed at prompt 14 is available as
4684 \family typewriter
4731 \family typewriter
4685 _i14,
4732 _i14,
4686 \family default
4733 \family default
4687
4734
4688 \family typewriter
4735 \family typewriter
4689 _ih[14]
4736 _ih[14]
4690 \family default
4737 \family default
4691 and
4738 and
4692 \family typewriter
4739 \family typewriter
4693 In[14]
4740 In[14]
4694 \family default
4741 \family default
4695 .
4742 .
4696 \layout Standard
4743 \layout Standard
4697
4744
4698 This allows you to easily cut and paste multi line interactive prompts by
4745 This allows you to easily cut and paste multi line interactive prompts by
4699 printing them out: they print like a clean string, without prompt characters.
4746 printing them out: they print like a clean string, without prompt characters.
4700 You can also manipulate them like regular variables (they are strings),
4747 You can also manipulate them like regular variables (they are strings),
4701 modify or exec them (typing
4748 modify or exec them (typing
4702 \family typewriter
4749 \family typewriter
4703 'exec _i9'
4750 'exec _i9'
4704 \family default
4751 \family default
4705 will re-execute the contents of input prompt 9, '
4752 will re-execute the contents of input prompt 9, '
4706 \family typewriter
4753 \family typewriter
4707 exec In[9:14]+In[18]
4754 exec In[9:14]+In[18]
4708 \family default
4755 \family default
4709 ' will re-execute lines 9 through 13 and line 18).
4756 ' will re-execute lines 9 through 13 and line 18).
4710 \layout Standard
4757 \layout Standard
4711
4758
4712 You can also re-execute multiple lines of input easily by using the magic
4759 You can also re-execute multiple lines of input easily by using the magic
4713
4760
4714 \family typewriter
4761 \family typewriter
4715 %macro
4762 %macro
4716 \family default
4763 \family default
4717 function (which automates the process and allows re-execution without having
4764 function (which automates the process and allows re-execution without having
4718 to type '
4765 to type '
4719 \family typewriter
4766 \family typewriter
4720 exec
4767 exec
4721 \family default
4768 \family default
4722 ' every time).
4769 ' every time).
4723 The macro system also allows you to re-execute previous lines which include
4770 The macro system also allows you to re-execute previous lines which include
4724 magic function calls (which require special processing).
4771 magic function calls (which require special processing).
4725 Type
4772 Type
4726 \family typewriter
4773 \family typewriter
4727 %macro?
4774 %macro?
4728 \family default
4775 \family default
4729 or see sec.
4776 or see sec.
4730
4777
4731 \begin_inset LatexCommand \ref{sec:magic}
4778 \begin_inset LatexCommand \ref{sec:magic}
4732
4779
4733 \end_inset
4780 \end_inset
4734
4781
4735 for more details on the macro system.
4782 for more details on the macro system.
4736 \layout Standard
4783 \layout Standard
4737
4784
4738 A history function
4785 A history function
4739 \family typewriter
4786 \family typewriter
4740 %hist
4787 %hist
4741 \family default
4788 \family default
4742 allows you to see any part of your input history by printing a range of
4789 allows you to see any part of your input history by printing a range of
4743 the
4790 the
4744 \family typewriter
4791 \family typewriter
4745 _i
4792 _i
4746 \family default
4793 \family default
4747 variables.
4794 variables.
4748 \layout Subsection
4795 \layout Subsection
4749
4796
4750
4797
4751 \begin_inset LatexCommand \label{sec:cache_output}
4798 \begin_inset LatexCommand \label{sec:cache_output}
4752
4799
4753 \end_inset
4800 \end_inset
4754
4801
4755 Output caching system
4802 Output caching system
4756 \layout Standard
4803 \layout Standard
4757
4804
4758 For output that is returned from actions, a system similar to the input
4805 For output that is returned from actions, a system similar to the input
4759 cache exists but using
4806 cache exists but using
4760 \family typewriter
4807 \family typewriter
4761 _
4808 _
4762 \family default
4809 \family default
4763 instead of
4810 instead of
4764 \family typewriter
4811 \family typewriter
4765 _i
4812 _i
4766 \family default
4813 \family default
4767 .
4814 .
4768 Only actions that produce a result (NOT assignments, for example) are cached.
4815 Only actions that produce a result (NOT assignments, for example) are cached.
4769 If you are familiar with Mathematica, IPython's
4816 If you are familiar with Mathematica, IPython's
4770 \family typewriter
4817 \family typewriter
4771 _
4818 _
4772 \family default
4819 \family default
4773 variables behave exactly like Mathematica's
4820 variables behave exactly like Mathematica's
4774 \family typewriter
4821 \family typewriter
4775 %
4822 %
4776 \family default
4823 \family default
4777 variables.
4824 variables.
4778 \layout Standard
4825 \layout Standard
4779
4826
4780 The following GLOBAL variables always exist (so don't overwrite them!):
4827 The following GLOBAL variables always exist (so don't overwrite them!):
4781
4828
4782 \layout List
4829 \layout List
4783 \labelwidthstring 00.00.0000
4830 \labelwidthstring 00.00.0000
4784
4831
4785
4832
4786 \family typewriter
4833 \family typewriter
4787 \series bold
4834 \series bold
4788 _
4835 _
4789 \family default
4836 \family default
4790 \series default
4837 \series default
4791 (a
4838 (a
4792 \emph on
4839 \emph on
4793 single
4840 single
4794 \emph default
4841 \emph default
4795 underscore) : stores previous output, like Python's default interpreter.
4842 underscore) : stores previous output, like Python's default interpreter.
4796 \layout List
4843 \layout List
4797 \labelwidthstring 00.00.0000
4844 \labelwidthstring 00.00.0000
4798
4845
4799
4846
4800 \family typewriter
4847 \family typewriter
4801 \series bold
4848 \series bold
4802 __
4849 __
4803 \family default
4850 \family default
4804 \series default
4851 \series default
4805 (two underscores): next previous.
4852 (two underscores): next previous.
4806 \layout List
4853 \layout List
4807 \labelwidthstring 00.00.0000
4854 \labelwidthstring 00.00.0000
4808
4855
4809
4856
4810 \family typewriter
4857 \family typewriter
4811 \series bold
4858 \series bold
4812 ___
4859 ___
4813 \family default
4860 \family default
4814 \series default
4861 \series default
4815 (three underscores): next-next previous.
4862 (three underscores): next-next previous.
4816 \layout Standard
4863 \layout Standard
4817
4864
4818 Additionally, global variables named
4865 Additionally, global variables named
4819 \family typewriter
4866 \family typewriter
4820 _<n>
4867 _<n>
4821 \family default
4868 \family default
4822 are dynamically created (
4869 are dynamically created (
4823 \family typewriter
4870 \family typewriter
4824 <n>
4871 <n>
4825 \family default
4872 \family default
4826 being the prompt counter), such that the result of output
4873 being the prompt counter), such that the result of output
4827 \family typewriter
4874 \family typewriter
4828 <n>
4875 <n>
4829 \family default
4876 \family default
4830 is always available as
4877 is always available as
4831 \family typewriter
4878 \family typewriter
4832 _<n>
4879 _<n>
4833 \family default
4880 \family default
4834 (don't use the angle brackets, just the number, e.g.
4881 (don't use the angle brackets, just the number, e.g.
4835
4882
4836 \family typewriter
4883 \family typewriter
4837 _21
4884 _21
4838 \family default
4885 \family default
4839 ).
4886 ).
4840 \layout Standard
4887 \layout Standard
4841
4888
4842 These global variables are all stored in a global dictionary (not a list,
4889 These global variables are all stored in a global dictionary (not a list,
4843 since it only has entries for lines which returned a result) available
4890 since it only has entries for lines which returned a result) available
4844 under the names
4891 under the names
4845 \family typewriter
4892 \family typewriter
4846 _oh
4893 _oh
4847 \family default
4894 \family default
4848 and
4895 and
4849 \family typewriter
4896 \family typewriter
4850 Out
4897 Out
4851 \family default
4898 \family default
4852 (similar to
4899 (similar to
4853 \family typewriter
4900 \family typewriter
4854 _ih
4901 _ih
4855 \family default
4902 \family default
4856 and
4903 and
4857 \family typewriter
4904 \family typewriter
4858 In
4905 In
4859 \family default
4906 \family default
4860 ).
4907 ).
4861 So the output from line 12 can be obtained as
4908 So the output from line 12 can be obtained as
4862 \family typewriter
4909 \family typewriter
4863 _12
4910 _12
4864 \family default
4911 \family default
4865 ,
4912 ,
4866 \family typewriter
4913 \family typewriter
4867 Out[12]
4914 Out[12]
4868 \family default
4915 \family default
4869 or
4916 or
4870 \family typewriter
4917 \family typewriter
4871 _oh[12]
4918 _oh[12]
4872 \family default
4919 \family default
4873 .
4920 .
4874 If you accidentally overwrite the
4921 If you accidentally overwrite the
4875 \family typewriter
4922 \family typewriter
4876 Out
4923 Out
4877 \family default
4924 \family default
4878 variable you can recover it by typing
4925 variable you can recover it by typing
4879 \family typewriter
4926 \family typewriter
4880 'Out=_oh
4927 'Out=_oh
4881 \family default
4928 \family default
4882 ' at the prompt.
4929 ' at the prompt.
4883 \layout Standard
4930 \layout Standard
4884
4931
4885 This system obviously can potentially put heavy memory demands on your system,
4932 This system obviously can potentially put heavy memory demands on your system,
4886 since it prevents Python's garbage collector from removing any previously
4933 since it prevents Python's garbage collector from removing any previously
4887 computed results.
4934 computed results.
4888 You can control how many results are kept in memory with the option (at
4935 You can control how many results are kept in memory with the option (at
4889 the command line or in your
4936 the command line or in your
4890 \family typewriter
4937 \family typewriter
4891 ipythonrc
4938 ipythonrc
4892 \family default
4939 \family default
4893 file)
4940 file)
4894 \family typewriter
4941 \family typewriter
4895 cache_size
4942 cache_size
4896 \family default
4943 \family default
4897 .
4944 .
4898 If you set it to 0, the whole system is completely disabled and the prompts
4945 If you set it to 0, the whole system is completely disabled and the prompts
4899 revert to the classic
4946 revert to the classic
4900 \family typewriter
4947 \family typewriter
4901 '>>>'
4948 '>>>'
4902 \family default
4949 \family default
4903 of normal Python.
4950 of normal Python.
4904 \layout Subsection
4951 \layout Subsection
4905
4952
4906 Directory history
4953 Directory history
4907 \layout Standard
4954 \layout Standard
4908
4955
4909 Your history of visited directories is kept in the global list
4956 Your history of visited directories is kept in the global list
4910 \family typewriter
4957 \family typewriter
4911 _dh
4958 _dh
4912 \family default
4959 \family default
4913 , and the magic
4960 , and the magic
4914 \family typewriter
4961 \family typewriter
4915 %cd
4962 %cd
4916 \family default
4963 \family default
4917 command can be used to go to any entry in that list.
4964 command can be used to go to any entry in that list.
4918 The
4965 The
4919 \family typewriter
4966 \family typewriter
4920 %dhist
4967 %dhist
4921 \family default
4968 \family default
4922 command allows you to view this history.
4969 command allows you to view this history.
4923 \layout Subsection
4970 \layout Subsection
4924
4971
4925 Automatic parentheses and quotes
4972 Automatic parentheses and quotes
4926 \layout Standard
4973 \layout Standard
4927
4974
4928 These features were adapted from Nathan Gray's LazyPython.
4975 These features were adapted from Nathan Gray's LazyPython.
4929 They are meant to allow less typing for common situations.
4976 They are meant to allow less typing for common situations.
4930 \layout Subsubsection
4977 \layout Subsubsection
4931
4978
4932 Automatic parentheses
4979 Automatic parentheses
4933 \layout Standard
4980 \layout Standard
4934
4981
4935 Callable objects (i.e.
4982 Callable objects (i.e.
4936 functions, methods, etc) can be invoked like this (notice the commas between
4983 functions, methods, etc) can be invoked like this (notice the commas between
4937 the arguments):
4984 the arguments):
4938 \layout Standard
4985 \layout Standard
4939
4986
4940
4987
4941 \family typewriter
4988 \family typewriter
4942 >>> callable_ob arg1, arg2, arg3
4989 >>> callable_ob arg1, arg2, arg3
4943 \layout Standard
4990 \layout Standard
4944
4991
4945 and the input will be translated to this:
4992 and the input will be translated to this:
4946 \layout Standard
4993 \layout Standard
4947
4994
4948
4995
4949 \family typewriter
4996 \family typewriter
4950 --> callable_ob(arg1, arg2, arg3)
4997 --> callable_ob(arg1, arg2, arg3)
4951 \layout Standard
4998 \layout Standard
4952
4999
4953 You can force automatic parentheses by using '/' as the first character
5000 You can force automatic parentheses by using '/' as the first character
4954 of a line.
5001 of a line.
4955 For example:
5002 For example:
4956 \layout Standard
5003 \layout Standard
4957
5004
4958
5005
4959 \family typewriter
5006 \family typewriter
4960 >>> /globals # becomes 'globals()'
5007 >>> /globals # becomes 'globals()'
4961 \layout Standard
5008 \layout Standard
4962
5009
4963 Note that the '/' MUST be the first character on the line! This won't work:
5010 Note that the '/' MUST be the first character on the line! This won't work:
4964
5011
4965 \layout Standard
5012 \layout Standard
4966
5013
4967
5014
4968 \family typewriter
5015 \family typewriter
4969 >>> print /globals # syntax error
5016 >>> print /globals # syntax error
4970 \layout Standard
5017 \layout Standard
4971
5018
4972 In most cases the automatic algorithm should work, so you should rarely
5019 In most cases the automatic algorithm should work, so you should rarely
4973 need to explicitly invoke /.
5020 need to explicitly invoke /.
4974 One notable exception is if you are trying to call a function with a list
5021 One notable exception is if you are trying to call a function with a list
4975 of tuples as arguments (the parenthesis will confuse IPython):
5022 of tuples as arguments (the parenthesis will confuse IPython):
4976 \layout Standard
5023 \layout Standard
4977
5024
4978
5025
4979 \family typewriter
5026 \family typewriter
4980 In [1]: zip (1,2,3),(4,5,6) # won't work
5027 In [1]: zip (1,2,3),(4,5,6) # won't work
4981 \layout Standard
5028 \layout Standard
4982
5029
4983 but this will work:
5030 but this will work:
4984 \layout Standard
5031 \layout Standard
4985
5032
4986
5033
4987 \family typewriter
5034 \family typewriter
4988 In [2]: /zip (1,2,3),(4,5,6)
5035 In [2]: /zip (1,2,3),(4,5,6)
4989 \newline
5036 \newline
4990 ------> zip ((1,2,3),(4,5,6))
5037 ------> zip ((1,2,3),(4,5,6))
4991 \newline
5038 \newline
4992 Out[2]= [(1, 4), (2, 5), (3, 6)]
5039 Out[2]= [(1, 4), (2, 5), (3, 6)]
4993 \layout Standard
5040 \layout Standard
4994
5041
4995 IPython tells you that it has altered your command line by displaying the
5042 IPython tells you that it has altered your command line by displaying the
4996 new command line preceded by
5043 new command line preceded by
4997 \family typewriter
5044 \family typewriter
4998 -->
5045 -->
4999 \family default
5046 \family default
5000 .
5047 .
5001 e.g.:
5048 e.g.:
5002 \layout Standard
5049 \layout Standard
5003
5050
5004
5051
5005 \family typewriter
5052 \family typewriter
5006 In [18]: callable list
5053 In [18]: callable list
5007 \newline
5054 \newline
5008 -------> callable (list)
5055 -------> callable (list)
5009 \layout Subsubsection
5056 \layout Subsubsection
5010
5057
5011 Automatic quoting
5058 Automatic quoting
5012 \layout Standard
5059 \layout Standard
5013
5060
5014 You can force automatic quoting of a function's arguments by using
5061 You can force automatic quoting of a function's arguments by using
5015 \family typewriter
5062 \family typewriter
5016 `,'
5063 `,'
5017 \family default
5064 \family default
5018 or
5065 or
5019 \family typewriter
5066 \family typewriter
5020 `;'
5067 `;'
5021 \family default
5068 \family default
5022 as the first character of a line.
5069 as the first character of a line.
5023 For example:
5070 For example:
5024 \layout Standard
5071 \layout Standard
5025
5072
5026
5073
5027 \family typewriter
5074 \family typewriter
5028 >>> ,my_function /home/me # becomes my_function("/home/me")
5075 >>> ,my_function /home/me # becomes my_function("/home/me")
5029 \layout Standard
5076 \layout Standard
5030
5077
5031 If you use
5078 If you use
5032 \family typewriter
5079 \family typewriter
5033 `;'
5080 `;'
5034 \family default
5081 \family default
5035 instead, the whole argument is quoted as a single string (while
5082 instead, the whole argument is quoted as a single string (while
5036 \family typewriter
5083 \family typewriter
5037 `,'
5084 `,'
5038 \family default
5085 \family default
5039 splits on whitespace):
5086 splits on whitespace):
5040 \layout Standard
5087 \layout Standard
5041
5088
5042
5089
5043 \family typewriter
5090 \family typewriter
5044 >>> ,my_function a b c # becomes my_function("a","b","c")
5091 >>> ,my_function a b c # becomes my_function("a","b","c")
5045 \layout Standard
5092 \layout Standard
5046
5093
5047
5094
5048 \family typewriter
5095 \family typewriter
5049 >>> ;my_function a b c # becomes my_function("a b c")
5096 >>> ;my_function a b c # becomes my_function("a b c")
5050 \layout Standard
5097 \layout Standard
5051
5098
5052 Note that the `
5099 Note that the `
5053 \family typewriter
5100 \family typewriter
5054 ,
5101 ,
5055 \family default
5102 \family default
5056 ' or `
5103 ' or `
5057 \family typewriter
5104 \family typewriter
5058 ;
5105 ;
5059 \family default
5106 \family default
5060 ' MUST be the first character on the line! This won't work:
5107 ' MUST be the first character on the line! This won't work:
5061 \layout Standard
5108 \layout Standard
5062
5109
5063
5110
5064 \family typewriter
5111 \family typewriter
5065 >>> x = ,my_function /home/me # syntax error
5112 >>> x = ,my_function /home/me # syntax error
5066 \layout Section
5113 \layout Section
5067
5114
5068
5115
5069 \begin_inset LatexCommand \label{sec:customization}
5116 \begin_inset LatexCommand \label{sec:customization}
5070
5117
5071 \end_inset
5118 \end_inset
5072
5119
5073 Customization
5120 Customization
5074 \layout Standard
5121 \layout Standard
5075
5122
5076 As we've already mentioned, IPython reads a configuration file which can
5123 As we've already mentioned, IPython reads a configuration file which can
5077 be specified at the command line (
5124 be specified at the command line (
5078 \family typewriter
5125 \family typewriter
5079 -rcfile
5126 -rcfile
5080 \family default
5127 \family default
5081 ) or which by default is assumed to be called
5128 ) or which by default is assumed to be called
5082 \family typewriter
5129 \family typewriter
5083 ipythonrc
5130 ipythonrc
5084 \family default
5131 \family default
5085 .
5132 .
5086 Such a file is looked for in the current directory where IPython is started
5133 Such a file is looked for in the current directory where IPython is started
5087 and then in your
5134 and then in your
5088 \family typewriter
5135 \family typewriter
5089 IPYTHONDIR
5136 IPYTHONDIR
5090 \family default
5137 \family default
5091 , which allows you to have local configuration files for specific projects.
5138 , which allows you to have local configuration files for specific projects.
5092 In this section we will call these types of configuration files simply
5139 In this section we will call these types of configuration files simply
5093 rcfiles (short for resource configuration file).
5140 rcfiles (short for resource configuration file).
5094 \layout Standard
5141 \layout Standard
5095
5142
5096 The syntax of an rcfile is one of key-value pairs separated by whitespace,
5143 The syntax of an rcfile is one of key-value pairs separated by whitespace,
5097 one per line.
5144 one per line.
5098 Lines beginning with a
5145 Lines beginning with a
5099 \family typewriter
5146 \family typewriter
5100 #
5147 #
5101 \family default
5148 \family default
5102 are ignored as comments, but comments can
5149 are ignored as comments, but comments can
5103 \series bold
5150 \series bold
5104 not
5151 not
5105 \series default
5152 \series default
5106 be put on lines with data (the parser is fairly primitive).
5153 be put on lines with data (the parser is fairly primitive).
5107 Note that these are not python files, and this is deliberate, because it
5154 Note that these are not python files, and this is deliberate, because it
5108 allows us to do some things which would be quite tricky to implement if
5155 allows us to do some things which would be quite tricky to implement if
5109 they were normal python files.
5156 they were normal python files.
5110 \layout Standard
5157 \layout Standard
5111
5158
5112 First, an rcfile can contain permanent default values for almost all command
5159 First, an rcfile can contain permanent default values for almost all command
5113 line options (except things like
5160 line options (except things like
5114 \family typewriter
5161 \family typewriter
5115 -help
5162 -help
5116 \family default
5163 \family default
5117 or
5164 or
5118 \family typewriter
5165 \family typewriter
5119 -Version
5166 -Version
5120 \family default
5167 \family default
5121 ).
5168 ).
5122 Sec\SpecialChar ~
5169 Sec\SpecialChar ~
5123
5170
5124 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5171 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5125
5172
5126 \end_inset
5173 \end_inset
5127
5174
5128 contains a description of all command-line options.
5175 contains a description of all command-line options.
5129 However, values you explicitly specify at the command line override the
5176 However, values you explicitly specify at the command line override the
5130 values defined in the rcfile.
5177 values defined in the rcfile.
5131 \layout Standard
5178 \layout Standard
5132
5179
5133 Besides command line option values, the rcfile can specify values for certain
5180 Besides command line option values, the rcfile can specify values for certain
5134 extra special options which are not available at the command line.
5181 extra special options which are not available at the command line.
5135 These options are briefly described below.
5182 These options are briefly described below.
5136
5183
5137 \layout Standard
5184 \layout Standard
5138
5185
5139 Each of these options may appear as many times as you need it in the file.
5186 Each of these options may appear as many times as you need it in the file.
5140 \layout List
5187 \layout List
5141 \labelwidthstring 00.00.0000
5188 \labelwidthstring 00.00.0000
5142
5189
5143
5190
5144 \family typewriter
5191 \family typewriter
5145 \series bold
5192 \series bold
5146 include\SpecialChar ~
5193 include\SpecialChar ~
5147 <file1>\SpecialChar ~
5194 <file1>\SpecialChar ~
5148 <file2>\SpecialChar ~
5195 <file2>\SpecialChar ~
5149 ...
5196 ...
5150 \family default
5197 \family default
5151 \series default
5198 \series default
5152 : you can name
5199 : you can name
5153 \emph on
5200 \emph on
5154 other
5201 other
5155 \emph default
5202 \emph default
5156 rcfiles you want to recursively load up to 15 levels (don't use the
5203 rcfiles you want to recursively load up to 15 levels (don't use the
5157 \family typewriter
5204 \family typewriter
5158 <>
5205 <>
5159 \family default
5206 \family default
5160 brackets in your names!).
5207 brackets in your names!).
5161 This feature allows you to define a 'base' rcfile with general options
5208 This feature allows you to define a 'base' rcfile with general options
5162 and special-purpose files which can be loaded only when needed with particular
5209 and special-purpose files which can be loaded only when needed with particular
5163 configuration options.
5210 configuration options.
5164 To make this more convenient, IPython accepts the
5211 To make this more convenient, IPython accepts the
5165 \family typewriter
5212 \family typewriter
5166 -profile <name>
5213 -profile <name>
5167 \family default
5214 \family default
5168 option (abbreviates to
5215 option (abbreviates to
5169 \family typewriter
5216 \family typewriter
5170 -p <name
5217 -p <name
5171 \family default
5218 \family default
5172 >)
5219 >)
5173 \family typewriter
5220 \family typewriter
5174 which
5221 which
5175 \family default
5222 \family default
5176 tells it to look for an rcfile named
5223 tells it to look for an rcfile named
5177 \family typewriter
5224 \family typewriter
5178 ipythonrc-<name>
5225 ipythonrc-<name>
5179 \family default
5226 \family default
5180 .
5227 .
5181
5228
5182 \layout List
5229 \layout List
5183 \labelwidthstring 00.00.0000
5230 \labelwidthstring 00.00.0000
5184
5231
5185
5232
5186 \family typewriter
5233 \family typewriter
5187 \series bold
5234 \series bold
5188 import_mod\SpecialChar ~
5235 import_mod\SpecialChar ~
5189 <mod1>\SpecialChar ~
5236 <mod1>\SpecialChar ~
5190 <mod2>\SpecialChar ~
5237 <mod2>\SpecialChar ~
5191 ...
5238 ...
5192 \family default
5239 \family default
5193 \series default
5240 \series default
5194 : import modules with '
5241 : import modules with '
5195 \family typewriter
5242 \family typewriter
5196 import
5243 import
5197 \family default
5244 \family default
5198
5245
5199 \family typewriter
5246 \family typewriter
5200 <mod1>,<mod2>,...
5247 <mod1>,<mod2>,...
5201 \family default
5248 \family default
5202 '
5249 '
5203 \layout List
5250 \layout List
5204 \labelwidthstring 00.00.0000
5251 \labelwidthstring 00.00.0000
5205
5252
5206
5253
5207 \family typewriter
5254 \family typewriter
5208 \series bold
5255 \series bold
5209 import_some\SpecialChar ~
5256 import_some\SpecialChar ~
5210 <mod>\SpecialChar ~
5257 <mod>\SpecialChar ~
5211 <f1>\SpecialChar ~
5258 <f1>\SpecialChar ~
5212 <f2>\SpecialChar ~
5259 <f2>\SpecialChar ~
5213 ...
5260 ...
5214 \family default
5261 \family default
5215 \series default
5262 \series default
5216 : import functions with '
5263 : import functions with '
5217 \family typewriter
5264 \family typewriter
5218 from <mod> import
5265 from <mod> import
5219 \family default
5266 \family default
5220
5267
5221 \family typewriter
5268 \family typewriter
5222 <f1>,<f2>,...
5269 <f1>,<f2>,...
5223 \family default
5270 \family default
5224 '
5271 '
5225 \layout List
5272 \layout List
5226 \labelwidthstring 00.00.0000
5273 \labelwidthstring 00.00.0000
5227
5274
5228
5275
5229 \family typewriter
5276 \family typewriter
5230 \series bold
5277 \series bold
5231 import_all\SpecialChar ~
5278 import_all\SpecialChar ~
5232 <mod1>\SpecialChar ~
5279 <mod1>\SpecialChar ~
5233 <mod2>\SpecialChar ~
5280 <mod2>\SpecialChar ~
5234 ...
5281 ...
5235 \family default
5282 \family default
5236 \series default
5283 \series default
5237 : for each module listed import functions with '
5284 : for each module listed import functions with '
5238 \family typewriter
5285 \family typewriter
5239 from <mod> import *
5286 from <mod> import *
5240 \family default
5287 \family default
5241 '
5288 '
5242 \layout List
5289 \layout List
5243 \labelwidthstring 00.00.0000
5290 \labelwidthstring 00.00.0000
5244
5291
5245
5292
5246 \family typewriter
5293 \family typewriter
5247 \series bold
5294 \series bold
5248 execute\SpecialChar ~
5295 execute\SpecialChar ~
5249 <python\SpecialChar ~
5296 <python\SpecialChar ~
5250 code>
5297 code>
5251 \family default
5298 \family default
5252 \series default
5299 \series default
5253 : give any single-line python code to be executed.
5300 : give any single-line python code to be executed.
5254 \layout List
5301 \layout List
5255 \labelwidthstring 00.00.0000
5302 \labelwidthstring 00.00.0000
5256
5303
5257
5304
5258 \family typewriter
5305 \family typewriter
5259 \series bold
5306 \series bold
5260 execfile\SpecialChar ~
5307 execfile\SpecialChar ~
5261 <filename>
5308 <filename>
5262 \family default
5309 \family default
5263 \series default
5310 \series default
5264 : execute the python file given with an '
5311 : execute the python file given with an '
5265 \family typewriter
5312 \family typewriter
5266 execfile(filename)
5313 execfile(filename)
5267 \family default
5314 \family default
5268 ' command.
5315 ' command.
5269 Username expansion is performed on the given names.
5316 Username expansion is performed on the given names.
5270 So if you need any amount of extra fancy customization that won't fit in
5317 So if you need any amount of extra fancy customization that won't fit in
5271 any of the above 'canned' options, you can just put it in a separate python
5318 any of the above 'canned' options, you can just put it in a separate python
5272 file and execute it.
5319 file and execute it.
5273 \layout List
5320 \layout List
5274 \labelwidthstring 00.00.0000
5321 \labelwidthstring 00.00.0000
5275
5322
5276
5323
5277 \family typewriter
5324 \family typewriter
5278 \series bold
5325 \series bold
5279 alias\SpecialChar ~
5326 alias\SpecialChar ~
5280 <alias_def>
5327 <alias_def>
5281 \family default
5328 \family default
5282 \series default
5329 \series default
5283 : this is equivalent to calling '
5330 : this is equivalent to calling '
5284 \family typewriter
5331 \family typewriter
5285 %alias\SpecialChar ~
5332 %alias\SpecialChar ~
5286 <alias_def>
5333 <alias_def>
5287 \family default
5334 \family default
5288 ' at the IPython command line.
5335 ' at the IPython command line.
5289 This way, from within IPython you can do common system tasks without having
5336 This way, from within IPython you can do common system tasks without having
5290 to exit it or use the
5337 to exit it or use the
5291 \family typewriter
5338 \family typewriter
5292 !
5339 !
5293 \family default
5340 \family default
5294 escape.
5341 escape.
5295 IPython isn't meant to be a shell replacement, but it is often very useful
5342 IPython isn't meant to be a shell replacement, but it is often very useful
5296 to be able to do things with files while testing code.
5343 to be able to do things with files while testing code.
5297 This gives you the flexibility to have within IPython any aliases you may
5344 This gives you the flexibility to have within IPython any aliases you may
5298 be used to under your normal system shell.
5345 be used to under your normal system shell.
5299 \layout Subsection
5346 \layout Subsection
5300
5347
5301
5348
5302 \begin_inset LatexCommand \label{sec:ipytonrc-sample}
5349 \begin_inset LatexCommand \label{sec:ipytonrc-sample}
5303
5350
5304 \end_inset
5351 \end_inset
5305
5352
5306 Sample
5353 Sample
5307 \family typewriter
5354 \family typewriter
5308 ipythonrc
5355 ipythonrc
5309 \family default
5356 \family default
5310 file
5357 file
5311 \layout Standard
5358 \layout Standard
5312
5359
5313 The default rcfile, called
5360 The default rcfile, called
5314 \family typewriter
5361 \family typewriter
5315 ipythonrc
5362 ipythonrc
5316 \family default
5363 \family default
5317 and supplied in your
5364 and supplied in your
5318 \family typewriter
5365 \family typewriter
5319 IPYTHONDIR
5366 IPYTHONDIR
5320 \family default
5367 \family default
5321 directory contains lots of comments on all of these options.
5368 directory contains lots of comments on all of these options.
5322 We reproduce it here for reference:
5369 We reproduce it here for reference:
5323 \layout Standard
5370 \layout Standard
5324
5371
5325
5372
5326 \begin_inset Include \verbatiminput{../IPython/UserConfig/ipythonrc}
5373 \begin_inset ERT
5327 preview false
5374 status Open
5328
5375
5376 \layout Standard
5377
5378 \backslash
5379 lstinputlisting{../IPython/UserConfig/ipythonrc}
5329 \end_inset
5380 \end_inset
5330
5381
5331
5382
5332 \layout Subsection
5383 \layout Subsection
5333
5384
5334
5385
5335 \begin_inset LatexCommand \label{sec:prompts}
5386 \begin_inset LatexCommand \label{sec:prompts}
5336
5387
5337 \end_inset
5388 \end_inset
5338
5389
5339 Fine-tuning your prompt
5390 Fine-tuning your prompt
5340 \layout Standard
5391 \layout Standard
5341
5392
5342 IPython's prompts can be customized using a syntax similar to that of the
5393 IPython's prompts can be customized using a syntax similar to that of the
5343
5394
5344 \family typewriter
5395 \family typewriter
5345 bash
5396 bash
5346 \family default
5397 \family default
5347 shell.
5398 shell.
5348 Many of
5399 Many of
5349 \family typewriter
5400 \family typewriter
5350 bash
5401 bash
5351 \family default
5402 \family default
5352 's escapes are supported, as well as a few additional ones.
5403 's escapes are supported, as well as a few additional ones.
5353 We list them below:
5404 We list them below:
5354 \layout Description
5405 \layout Description
5355
5406
5356
5407
5357 \backslash
5408 \backslash
5358 # the prompt/history count number
5409 # the prompt/history count number
5359 \layout Description
5410 \layout Description
5360
5411
5361
5412
5362 \backslash
5413 \backslash
5363 D the prompt/history count, with the actual digits replaced by dots.
5414 D the prompt/history count, with the actual digits replaced by dots.
5364 Used mainly in continuation prompts (prompt_in2)
5415 Used mainly in continuation prompts (prompt_in2)
5365 \layout Description
5416 \layout Description
5366
5417
5367
5418
5368 \backslash
5419 \backslash
5369 w the current working directory
5420 w the current working directory
5370 \layout Description
5421 \layout Description
5371
5422
5372
5423
5373 \backslash
5424 \backslash
5374 W the basename of current working directory
5425 W the basename of current working directory
5375 \layout Description
5426 \layout Description
5376
5427
5377
5428
5378 \backslash
5429 \backslash
5379 X
5430 X
5380 \emph on
5431 \emph on
5381 n
5432 n
5382 \emph default
5433 \emph default
5383 where
5434 where
5384 \begin_inset Formula $n=0\ldots5.$
5435 \begin_inset Formula $n=0\ldots5.$
5385 \end_inset
5436 \end_inset
5386
5437
5387 The current working directory, with
5438 The current working directory, with
5388 \family typewriter
5439 \family typewriter
5389 $HOME
5440 $HOME
5390 \family default
5441 \family default
5391 replaced by
5442 replaced by
5392 \family typewriter
5443 \family typewriter
5393 ~
5444 ~
5394 \family default
5445 \family default
5395 , and filtered out to contain only
5446 , and filtered out to contain only
5396 \begin_inset Formula $n$
5447 \begin_inset Formula $n$
5397 \end_inset
5448 \end_inset
5398
5449
5399 path elements
5450 path elements
5400 \layout Description
5451 \layout Description
5401
5452
5402
5453
5403 \backslash
5454 \backslash
5404 Y
5455 Y
5405 \emph on
5456 \emph on
5406 n
5457 n
5407 \emph default
5458 \emph default
5408 Similar to
5459 Similar to
5409 \backslash
5460 \backslash
5410 X
5461 X
5411 \emph on
5462 \emph on
5412 n
5463 n
5413 \emph default
5464 \emph default
5414 , but with the
5465 , but with the
5415 \begin_inset Formula $n+1$
5466 \begin_inset Formula $n+1$
5416 \end_inset
5467 \end_inset
5417
5468
5418 element included if it is
5469 element included if it is
5419 \family typewriter
5470 \family typewriter
5420 ~
5471 ~
5421 \family default
5472 \family default
5422 (this is similar to the behavior of the %c
5473 (this is similar to the behavior of the %c
5423 \emph on
5474 \emph on
5424 n
5475 n
5425 \emph default
5476 \emph default
5426 escapes in
5477 escapes in
5427 \family typewriter
5478 \family typewriter
5428 tcsh
5479 tcsh
5429 \family default
5480 \family default
5430 )
5481 )
5431 \layout Description
5482 \layout Description
5432
5483
5433
5484
5434 \backslash
5485 \backslash
5435 u the username of the current user
5486 u the username of the current user
5436 \layout Description
5487 \layout Description
5437
5488
5438
5489
5439 \backslash
5490 \backslash
5440 $ if the effective UID is 0, a #, otherwise a $
5491 $ if the effective UID is 0, a #, otherwise a $
5441 \layout Description
5492 \layout Description
5442
5493
5443
5494
5444 \backslash
5495 \backslash
5445 h the hostname up to the first `.'
5496 h the hostname up to the first `.'
5446 \layout Description
5497 \layout Description
5447
5498
5448
5499
5449 \backslash
5500 \backslash
5450 H the hostname
5501 H the hostname
5451 \layout Description
5502 \layout Description
5452
5503
5453
5504
5454 \backslash
5505 \backslash
5455 n a newline
5506 n a newline
5456 \layout Description
5507 \layout Description
5457
5508
5458
5509
5459 \backslash
5510 \backslash
5460 r a carriage return
5511 r a carriage return
5461 \layout Description
5512 \layout Description
5462
5513
5463
5514
5464 \backslash
5515 \backslash
5465 v IPython version string
5516 v IPython version string
5466 \layout Standard
5517 \layout Standard
5467
5518
5468 In addition to these, ANSI color escapes can be insterted into the prompts,
5519 In addition to these, ANSI color escapes can be insterted into the prompts,
5469 as
5520 as
5470 \family typewriter
5521 \family typewriter
5471
5522
5472 \backslash
5523 \backslash
5473 C_
5524 C_
5474 \emph on
5525 \emph on
5475 ColorName
5526 ColorName
5476 \family default
5527 \family default
5477 \emph default
5528 \emph default
5478 .
5529 .
5479 The list of valid color names is: Black, Blue, Brown, Cyan, DarkGray, Green,
5530 The list of valid color names is: Black, Blue, Brown, Cyan, DarkGray, Green,
5480 LightBlue, LightCyan, LightGray, LightGreen, LightPurple, LightRed, NoColor,
5531 LightBlue, LightCyan, LightGray, LightGreen, LightPurple, LightRed, NoColor,
5481 Normal, Purple, Red, White, Yellow.
5532 Normal, Purple, Red, White, Yellow.
5482 \layout Standard
5533 \layout Standard
5483
5534
5484 Finally, IPython supports the evaluation of arbitrary expressions in your
5535 Finally, IPython supports the evaluation of arbitrary expressions in your
5485 prompt string.
5536 prompt string.
5486 The prompt strings are evaluated through the syntax of PEP 215, but basically
5537 The prompt strings are evaluated through the syntax of PEP 215, but basically
5487 you can use
5538 you can use
5488 \family typewriter
5539 \family typewriter
5489 $x.y
5540 $x.y
5490 \family default
5541 \family default
5491 to expand the value of
5542 to expand the value of
5492 \family typewriter
5543 \family typewriter
5493 x.y
5544 x.y
5494 \family default
5545 \family default
5495 , and for more complicated expressions you can use braces:
5546 , and for more complicated expressions you can use braces:
5496 \family typewriter
5547 \family typewriter
5497 ${foo()+x}
5548 ${foo()+x}
5498 \family default
5549 \family default
5499 will call function
5550 will call function
5500 \family typewriter
5551 \family typewriter
5501 foo
5552 foo
5502 \family default
5553 \family default
5503 and add to it the value of
5554 and add to it the value of
5504 \family typewriter
5555 \family typewriter
5505 x
5556 x
5506 \family default
5557 \family default
5507 , before putting the result into your prompt.
5558 , before putting the result into your prompt.
5508 For example, using
5559 For example, using
5509 \newline
5560 \newline
5510
5561
5511 \family typewriter
5562 \family typewriter
5512 prompt_in1 '${commands.getoutput("uptime")}
5563 prompt_in1 '${commands.getoutput("uptime")}
5513 \backslash
5564 \backslash
5514 nIn [
5565 nIn [
5515 \backslash
5566 \backslash
5516 #]: '
5567 #]: '
5517 \newline
5568 \newline
5518
5569
5519 \family default
5570 \family default
5520 will print the result of the uptime command on each prompt (assuming the
5571 will print the result of the uptime command on each prompt (assuming the
5521
5572
5522 \family typewriter
5573 \family typewriter
5523 commands
5574 commands
5524 \family default
5575 \family default
5525 module has been imported in your
5576 module has been imported in your
5526 \family typewriter
5577 \family typewriter
5527 ipythonrc
5578 ipythonrc
5528 \family default
5579 \family default
5529 file).
5580 file).
5530 \layout Subsubsection
5581 \layout Subsubsection
5531
5582
5532 Prompt examples
5583 Prompt examples
5533 \layout Standard
5584 \layout Standard
5534
5585
5535 The following options in an ipythonrc file will give you IPython's default
5586 The following options in an ipythonrc file will give you IPython's default
5536 prompts:
5587 prompts:
5537 \layout Standard
5588 \layout Standard
5538
5589
5539
5590
5540 \family typewriter
5591 \family typewriter
5541 prompt_in1 'In [
5592 prompt_in1 'In [
5542 \backslash
5593 \backslash
5543 #]:'
5594 #]:'
5544 \newline
5595 \newline
5545 prompt_in2 '\SpecialChar ~
5596 prompt_in2 '\SpecialChar ~
5546 \SpecialChar ~
5597 \SpecialChar ~
5547 \SpecialChar ~
5598 \SpecialChar ~
5548 .
5599 .
5549 \backslash
5600 \backslash
5550 D.:'
5601 D.:'
5551 \newline
5602 \newline
5552 prompt_out 'Out[
5603 prompt_out 'Out[
5553 \backslash
5604 \backslash
5554 #]:'
5605 #]:'
5555 \layout Standard
5606 \layout Standard
5556
5607
5557 which look like this:
5608 which look like this:
5558 \layout Standard
5609 \layout Standard
5559
5610
5560
5611
5561 \family typewriter
5612 \family typewriter
5562 In [1]: 1+2
5613 In [1]: 1+2
5563 \newline
5614 \newline
5564 Out[1]: 3
5615 Out[1]: 3
5565 \layout Standard
5616 \layout Standard
5566
5617
5567
5618
5568 \family typewriter
5619 \family typewriter
5569 In [2]: for i in (1,2,3):
5620 In [2]: for i in (1,2,3):
5570 \newline
5621 \newline
5571
5622
5572 \begin_inset ERT
5623 \begin_inset ERT
5573 status Collapsed
5624 status Collapsed
5574
5625
5575 \layout Standard
5626 \layout Standard
5576
5627
5577 \backslash
5628 \backslash
5578 hspace*{0mm}
5629 hspace*{0mm}
5579 \end_inset
5630 \end_inset
5580
5631
5581 \SpecialChar ~
5632 \SpecialChar ~
5582 \SpecialChar ~
5633 \SpecialChar ~
5583 \SpecialChar ~
5634 \SpecialChar ~
5584 ...: \SpecialChar ~
5635 ...: \SpecialChar ~
5585 \SpecialChar ~
5636 \SpecialChar ~
5586 \SpecialChar ~
5637 \SpecialChar ~
5587 \SpecialChar ~
5638 \SpecialChar ~
5588 print i,
5639 print i,
5589 \newline
5640 \newline
5590
5641
5591 \begin_inset ERT
5642 \begin_inset ERT
5592 status Collapsed
5643 status Collapsed
5593
5644
5594 \layout Standard
5645 \layout Standard
5595
5646
5596 \backslash
5647 \backslash
5597 hspace*{0mm}
5648 hspace*{0mm}
5598 \end_inset
5649 \end_inset
5599
5650
5600 \SpecialChar ~
5651 \SpecialChar ~
5601 \SpecialChar ~
5652 \SpecialChar ~
5602 \SpecialChar ~
5653 \SpecialChar ~
5603 ...:
5654 ...:
5604 \newline
5655 \newline
5605 1 2 3
5656 1 2 3
5606 \layout Standard
5657 \layout Standard
5607
5658
5608 These will give you a very colorful prompt with path information:
5659 These will give you a very colorful prompt with path information:
5609 \layout Standard
5660 \layout Standard
5610
5661
5611
5662
5612 \family typewriter
5663 \family typewriter
5613 #prompt_in1 '
5664 #prompt_in1 '
5614 \backslash
5665 \backslash
5615 C_Red
5666 C_Red
5616 \backslash
5667 \backslash
5617 u
5668 u
5618 \backslash
5669 \backslash
5619 C_Blue[
5670 C_Blue[
5620 \backslash
5671 \backslash
5621 C_Cyan
5672 C_Cyan
5622 \backslash
5673 \backslash
5623 Y1
5674 Y1
5624 \backslash
5675 \backslash
5625 C_Blue]
5676 C_Blue]
5626 \backslash
5677 \backslash
5627 C_LightGreen
5678 C_LightGreen
5628 \backslash
5679 \backslash
5629 #>'
5680 #>'
5630 \newline
5681 \newline
5631 prompt_in2 ' ..
5682 prompt_in2 ' ..
5632 \backslash
5683 \backslash
5633 D>'
5684 D>'
5634 \newline
5685 \newline
5635 prompt_out '<
5686 prompt_out '<
5636 \backslash
5687 \backslash
5637 #>'
5688 #>'
5638 \layout Standard
5689 \layout Standard
5639
5690
5640 which look like this:
5691 which look like this:
5641 \layout Standard
5692 \layout Standard
5642
5693
5643
5694
5644 \family typewriter
5695 \family typewriter
5645 \color red
5696 \color red
5646 fperez
5697 fperez
5647 \color blue
5698 \color blue
5648 [
5699 [
5649 \color cyan
5700 \color cyan
5650 ~/ipython
5701 ~/ipython
5651 \color blue
5702 \color blue
5652 ]
5703 ]
5653 \color green
5704 \color green
5654 1>
5705 1>
5655 \color default
5706 \color default
5656 1+2
5707 1+2
5657 \newline
5708 \newline
5658
5709
5659 \begin_inset ERT
5710 \begin_inset ERT
5660 status Collapsed
5711 status Collapsed
5661
5712
5662 \layout Standard
5713 \layout Standard
5663
5714
5664 \backslash
5715 \backslash
5665 hspace*{0mm}
5716 hspace*{0mm}
5666 \end_inset
5717 \end_inset
5667
5718
5668 \SpecialChar ~
5719 \SpecialChar ~
5669 \SpecialChar ~
5720 \SpecialChar ~
5670 \SpecialChar ~
5721 \SpecialChar ~
5671 \SpecialChar ~
5722 \SpecialChar ~
5672 \SpecialChar ~
5723 \SpecialChar ~
5673 \SpecialChar ~
5724 \SpecialChar ~
5674 \SpecialChar ~
5725 \SpecialChar ~
5675 \SpecialChar ~
5726 \SpecialChar ~
5676 \SpecialChar ~
5727 \SpecialChar ~
5677 \SpecialChar ~
5728 \SpecialChar ~
5678 \SpecialChar ~
5729 \SpecialChar ~
5679 \SpecialChar ~
5730 \SpecialChar ~
5680 \SpecialChar ~
5731 \SpecialChar ~
5681 \SpecialChar ~
5732 \SpecialChar ~
5682 \SpecialChar ~
5733 \SpecialChar ~
5683 \SpecialChar ~
5734 \SpecialChar ~
5684
5735
5685 \color red
5736 \color red
5686 <1>
5737 <1>
5687 \color default
5738 \color default
5688 3
5739 3
5689 \newline
5740 \newline
5690
5741
5691 \color red
5742 \color red
5692 fperez
5743 fperez
5693 \color blue
5744 \color blue
5694 [
5745 [
5695 \color cyan
5746 \color cyan
5696 ~/ipython
5747 ~/ipython
5697 \color blue
5748 \color blue
5698 ]
5749 ]
5699 \color green
5750 \color green
5700 2>
5751 2>
5701 \color default
5752 \color default
5702 for i in (1,2,3):
5753 for i in (1,2,3):
5703 \newline
5754 \newline
5704
5755
5705 \begin_inset ERT
5756 \begin_inset ERT
5706 status Collapsed
5757 status Collapsed
5707
5758
5708 \layout Standard
5759 \layout Standard
5709
5760
5710 \backslash
5761 \backslash
5711 hspace*{0mm}
5762 hspace*{0mm}
5712 \end_inset
5763 \end_inset
5713
5764
5714 \SpecialChar ~
5765 \SpecialChar ~
5715 \SpecialChar ~
5766 \SpecialChar ~
5716 \SpecialChar ~
5767 \SpecialChar ~
5717 \SpecialChar ~
5768 \SpecialChar ~
5718 \SpecialChar ~
5769 \SpecialChar ~
5719 \SpecialChar ~
5770 \SpecialChar ~
5720 \SpecialChar ~
5771 \SpecialChar ~
5721 \SpecialChar ~
5772 \SpecialChar ~
5722 \SpecialChar ~
5773 \SpecialChar ~
5723 \SpecialChar ~
5774 \SpecialChar ~
5724 \SpecialChar ~
5775 \SpecialChar ~
5725 \SpecialChar ~
5776 \SpecialChar ~
5726 \SpecialChar ~
5777 \SpecialChar ~
5727 \SpecialChar ~
5778 \SpecialChar ~
5728 \SpecialChar ~
5779 \SpecialChar ~
5729
5780
5730 \color green
5781 \color green
5731 ...>
5782 ...>
5732 \color default
5783 \color default
5733 \SpecialChar ~
5784 \SpecialChar ~
5734 \SpecialChar ~
5785 \SpecialChar ~
5735 \SpecialChar ~
5786 \SpecialChar ~
5736 \SpecialChar ~
5787 \SpecialChar ~
5737 print i,
5788 print i,
5738 \newline
5789 \newline
5739
5790
5740 \begin_inset ERT
5791 \begin_inset ERT
5741 status Collapsed
5792 status Collapsed
5742
5793
5743 \layout Standard
5794 \layout Standard
5744
5795
5745 \backslash
5796 \backslash
5746 hspace*{0mm}
5797 hspace*{0mm}
5747 \end_inset
5798 \end_inset
5748
5799
5749 \SpecialChar ~
5800 \SpecialChar ~
5750 \SpecialChar ~
5801 \SpecialChar ~
5751 \SpecialChar ~
5802 \SpecialChar ~
5752 \SpecialChar ~
5803 \SpecialChar ~
5753 \SpecialChar ~
5804 \SpecialChar ~
5754 \SpecialChar ~
5805 \SpecialChar ~
5755 \SpecialChar ~
5806 \SpecialChar ~
5756 \SpecialChar ~
5807 \SpecialChar ~
5757 \SpecialChar ~
5808 \SpecialChar ~
5758 \SpecialChar ~
5809 \SpecialChar ~
5759 \SpecialChar ~
5810 \SpecialChar ~
5760 \SpecialChar ~
5811 \SpecialChar ~
5761 \SpecialChar ~
5812 \SpecialChar ~
5762 \SpecialChar ~
5813 \SpecialChar ~
5763 \SpecialChar ~
5814 \SpecialChar ~
5764
5815
5765 \color green
5816 \color green
5766 ...>
5817 ...>
5767 \color default
5818 \color default
5768
5819
5769 \newline
5820 \newline
5770 1 2 3
5821 1 2 3
5771 \layout Standard
5822 \layout Standard
5772
5823
5773 The following shows the usage of dynamic expression evaluation:
5824 The following shows the usage of dynamic expression evaluation:
5774 \layout Subsection
5825 \layout Subsection
5775
5826
5776
5827
5777 \begin_inset LatexCommand \label{sec:profiles}
5828 \begin_inset LatexCommand \label{sec:profiles}
5778
5829
5779 \end_inset
5830 \end_inset
5780
5831
5781 IPython profiles
5832 IPython profiles
5782 \layout Standard
5833 \layout Standard
5783
5834
5784 As we already mentioned, IPython supports the
5835 As we already mentioned, IPython supports the
5785 \family typewriter
5836 \family typewriter
5786 -profile
5837 -profile
5787 \family default
5838 \family default
5788 command-line option (see sec.
5839 command-line option (see sec.
5789
5840
5790 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5841 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5791
5842
5792 \end_inset
5843 \end_inset
5793
5844
5794 ).
5845 ).
5795 A profile is nothing more than a particular configuration file like your
5846 A profile is nothing more than a particular configuration file like your
5796 basic
5847 basic
5797 \family typewriter
5848 \family typewriter
5798 ipythonrc
5849 ipythonrc
5799 \family default
5850 \family default
5800 one, but with particular customizations for a specific purpose.
5851 one, but with particular customizations for a specific purpose.
5801 When you start IPython with '
5852 When you start IPython with '
5802 \family typewriter
5853 \family typewriter
5803 ipython -profile <name>
5854 ipython -profile <name>
5804 \family default
5855 \family default
5805 ', it assumes that in your
5856 ', it assumes that in your
5806 \family typewriter
5857 \family typewriter
5807 IPYTHONDIR
5858 IPYTHONDIR
5808 \family default
5859 \family default
5809 there is a file called
5860 there is a file called
5810 \family typewriter
5861 \family typewriter
5811 ipythonrc-<name>
5862 ipythonrc-<name>
5812 \family default
5863 \family default
5813 , and loads it instead of the normal
5864 , and loads it instead of the normal
5814 \family typewriter
5865 \family typewriter
5815 ipythonrc
5866 ipythonrc
5816 \family default
5867 \family default
5817 .
5868 .
5818 \layout Standard
5869 \layout Standard
5819
5870
5820 This system allows you to maintain multiple configurations which load modules,
5871 This system allows you to maintain multiple configurations which load modules,
5821 set options, define functions, etc.
5872 set options, define functions, etc.
5822 suitable for different tasks and activate them in a very simple manner.
5873 suitable for different tasks and activate them in a very simple manner.
5823 In order to avoid having to repeat all of your basic options (common things
5874 In order to avoid having to repeat all of your basic options (common things
5824 that don't change such as your color preferences, for example), any profile
5875 that don't change such as your color preferences, for example), any profile
5825 can include another configuration file.
5876 can include another configuration file.
5826 The most common way to use profiles is then to have each one include your
5877 The most common way to use profiles is then to have each one include your
5827 basic
5878 basic
5828 \family typewriter
5879 \family typewriter
5829 ipythonrc
5880 ipythonrc
5830 \family default
5881 \family default
5831 file as a starting point, and then add further customizations.
5882 file as a starting point, and then add further customizations.
5832 \layout Standard
5883 \layout Standard
5833
5884
5834 In sections
5885 In sections
5835 \begin_inset LatexCommand \ref{sec:syntax-extensions}
5886 \begin_inset LatexCommand \ref{sec:syntax-extensions}
5836
5887
5837 \end_inset
5888 \end_inset
5838
5889
5839 and
5890 and
5840 \begin_inset LatexCommand \ref{sec:Gnuplot}
5891 \begin_inset LatexCommand \ref{sec:Gnuplot}
5841
5892
5842 \end_inset
5893 \end_inset
5843
5894
5844 we discuss some particular profiles which come as part of the standard
5895 we discuss some particular profiles which come as part of the standard
5845 IPython distribution.
5896 IPython distribution.
5846 You may also look in your
5897 You may also look in your
5847 \family typewriter
5898 \family typewriter
5848 IPYTHONDIR
5899 IPYTHONDIR
5849 \family default
5900 \family default
5850 directory, any file whose name begins with
5901 directory, any file whose name begins with
5851 \family typewriter
5902 \family typewriter
5852 ipythonrc-
5903 ipythonrc-
5853 \family default
5904 \family default
5854 is a profile.
5905 is a profile.
5855 You can use those as examples for further customizations to suit your own
5906 You can use those as examples for further customizations to suit your own
5856 needs.
5907 needs.
5857 \layout Section
5908 \layout Section
5858
5909
5859
5910
5860 \begin_inset OptArg
5911 \begin_inset OptArg
5861 collapsed false
5912 collapsed false
5862
5913
5863 \layout Standard
5914 \layout Standard
5864
5915
5865 IPython as default...
5916 IPython as default...
5866 \end_inset
5917 \end_inset
5867
5918
5868 IPython as your default Python environment
5919 IPython as your default Python environment
5869 \layout Standard
5920 \layout Standard
5870
5921
5871 Python honors the environment variable
5922 Python honors the environment variable
5872 \family typewriter
5923 \family typewriter
5873 PYTHONSTARTUP
5924 PYTHONSTARTUP
5874 \family default
5925 \family default
5875 and will execute at startup the file referenced by this variable.
5926 and will execute at startup the file referenced by this variable.
5876 If you put at the end of this file the following two lines of code:
5927 If you put at the end of this file the following two lines of code:
5877 \layout Standard
5928 \layout Standard
5878
5929
5879
5930
5880 \family typewriter
5931 \family typewriter
5881 import IPython
5932 import IPython
5882 \newline
5933 \newline
5883 IPython.Shell.IPShell().mainloop(sys_exit=1)
5934 IPython.Shell.IPShell().mainloop(sys_exit=1)
5884 \layout Standard
5935 \layout Standard
5885
5936
5886 then IPython will be your working environment anytime you start Python.
5937 then IPython will be your working environment anytime you start Python.
5887 The
5938 The
5888 \family typewriter
5939 \family typewriter
5889 sys_exit=1
5940 sys_exit=1
5890 \family default
5941 \family default
5891 is needed to have IPython issue a call to
5942 is needed to have IPython issue a call to
5892 \family typewriter
5943 \family typewriter
5893 sys.exit()
5944 sys.exit()
5894 \family default
5945 \family default
5895 when it finishes, otherwise you'll be back at the normal Python '
5946 when it finishes, otherwise you'll be back at the normal Python '
5896 \family typewriter
5947 \family typewriter
5897 >>>
5948 >>>
5898 \family default
5949 \family default
5899 ' prompt
5950 ' prompt
5900 \begin_inset Foot
5951 \begin_inset Foot
5901 collapsed true
5952 collapsed true
5902
5953
5903 \layout Standard
5954 \layout Standard
5904
5955
5905 Based on an idea by Holger Krekel.
5956 Based on an idea by Holger Krekel.
5906 \end_inset
5957 \end_inset
5907
5958
5908 .
5959 .
5909 \layout Standard
5960 \layout Standard
5910
5961
5911 This is probably useful to developers who manage multiple Python versions
5962 This is probably useful to developers who manage multiple Python versions
5912 and don't want to have correspondingly multiple IPython versions.
5963 and don't want to have correspondingly multiple IPython versions.
5913 Note that in this mode, there is no way to pass IPython any command-line
5964 Note that in this mode, there is no way to pass IPython any command-line
5914 options, as those are trapped first by Python itself.
5965 options, as those are trapped first by Python itself.
5915 \layout Section
5966 \layout Section
5916
5967
5917
5968
5918 \begin_inset LatexCommand \label{sec:embed}
5969 \begin_inset LatexCommand \label{sec:embed}
5919
5970
5920 \end_inset
5971 \end_inset
5921
5972
5922 Embedding IPython
5973 Embedding IPython
5923 \layout Standard
5974 \layout Standard
5924
5975
5925 It is possible to start an IPython instance
5976 It is possible to start an IPython instance
5926 \emph on
5977 \emph on
5927 inside
5978 inside
5928 \emph default
5979 \emph default
5929 your own Python programs.
5980 your own Python programs.
5930 This allows you to evaluate dynamically the state of your code, operate
5981 This allows you to evaluate dynamically the state of your code, operate
5931 with your variables, analyze them, etc.
5982 with your variables, analyze them, etc.
5932 Note however that any changes you make to values while in the shell do
5983 Note however that any changes you make to values while in the shell do
5933
5984
5934 \emph on
5985 \emph on
5935 not
5986 not
5936 \emph default
5987 \emph default
5937 propagate back to the running code, so it is safe to modify your values
5988 propagate back to the running code, so it is safe to modify your values
5938 because you won't break your code in bizarre ways by doing so.
5989 because you won't break your code in bizarre ways by doing so.
5939 \layout Standard
5990 \layout Standard
5940
5991
5941 This feature allows you to easily have a fully functional python environment
5992 This feature allows you to easily have a fully functional python environment
5942 for doing object introspection anywhere in your code with a simple function
5993 for doing object introspection anywhere in your code with a simple function
5943 call.
5994 call.
5944 In some cases a simple print statement is enough, but if you need to do
5995 In some cases a simple print statement is enough, but if you need to do
5945 more detailed analysis of a code fragment this feature can be very valuable.
5996 more detailed analysis of a code fragment this feature can be very valuable.
5946 \layout Standard
5997 \layout Standard
5947
5998
5948 It can also be useful in scientific computing situations where it is common
5999 It can also be useful in scientific computing situations where it is common
5949 to need to do some automatic, computationally intensive part and then stop
6000 to need to do some automatic, computationally intensive part and then stop
5950 to look at data, plots, etc
6001 to look at data, plots, etc
5951 \begin_inset Foot
6002 \begin_inset Foot
5952 collapsed true
6003 collapsed true
5953
6004
5954 \layout Standard
6005 \layout Standard
5955
6006
5956 This functionality was inspired by IDL's combination of the
6007 This functionality was inspired by IDL's combination of the
5957 \family typewriter
6008 \family typewriter
5958 stop
6009 stop
5959 \family default
6010 \family default
5960 keyword and the
6011 keyword and the
5961 \family typewriter
6012 \family typewriter
5962 .continue
6013 .continue
5963 \family default
6014 \family default
5964 executive command, which I have found very useful in the past, and by a
6015 executive command, which I have found very useful in the past, and by a
5965 posting on comp.lang.python by cmkl <cmkleffner-AT-gmx.de> on Dec.
6016 posting on comp.lang.python by cmkl <cmkleffner-AT-gmx.de> on Dec.
5966 06/01 concerning similar uses of pyrepl.
6017 06/01 concerning similar uses of pyrepl.
5967 \end_inset
6018 \end_inset
5968
6019
5969 .
6020 .
5970 Opening an IPython instance will give you full access to your data and
6021 Opening an IPython instance will give you full access to your data and
5971 functions, and you can resume program execution once you are done with
6022 functions, and you can resume program execution once you are done with
5972 the interactive part (perhaps to stop again later, as many times as needed).
6023 the interactive part (perhaps to stop again later, as many times as needed).
5973 \layout Standard
6024 \layout Standard
5974
6025
5975 The following code snippet is the bare minimum you need to include in your
6026 The following code snippet is the bare minimum you need to include in your
5976 Python programs for this to work (detailed examples follow later):
6027 Python programs for this to work (detailed examples follow later):
5977 \layout LyX-Code
6028 \layout LyX-Code
5978
6029
5979 from IPython.Shell import IPShellEmbed
6030 from IPython.Shell import IPShellEmbed
5980 \layout LyX-Code
6031 \layout LyX-Code
5981
6032
5982 ipshell = IPShellEmbed()
6033 ipshell = IPShellEmbed()
5983 \layout LyX-Code
6034 \layout LyX-Code
5984
6035
5985 ipshell() # this call anywhere in your program will start IPython
6036 ipshell() # this call anywhere in your program will start IPython
5986 \layout Standard
6037 \layout Standard
5987
6038
5988 You can run embedded instances even in code which is itself being run at
6039 You can run embedded instances even in code which is itself being run at
5989 the IPython interactive prompt with '
6040 the IPython interactive prompt with '
5990 \family typewriter
6041 \family typewriter
5991 %run\SpecialChar ~
6042 %run\SpecialChar ~
5992 <filename>
6043 <filename>
5993 \family default
6044 \family default
5994 '.
6045 '.
5995 Since it's easy to get lost as to where you are (in your top-level IPython
6046 Since it's easy to get lost as to where you are (in your top-level IPython
5996 or in your embedded one), it's a good idea in such cases to set the in/out
6047 or in your embedded one), it's a good idea in such cases to set the in/out
5997 prompts to something different for the embedded instances.
6048 prompts to something different for the embedded instances.
5998 The code examples below illustrate this.
6049 The code examples below illustrate this.
5999 \layout Standard
6050 \layout Standard
6000
6051
6001 You can also have multiple IPython instances in your program and open them
6052 You can also have multiple IPython instances in your program and open them
6002 separately, for example with different options for data presentation.
6053 separately, for example with different options for data presentation.
6003 If you close and open the same instance multiple times, its prompt counters
6054 If you close and open the same instance multiple times, its prompt counters
6004 simply continue from each execution to the next.
6055 simply continue from each execution to the next.
6005 \layout Standard
6056 \layout Standard
6006
6057
6007 Please look at the docstrings in the
6058 Please look at the docstrings in the
6008 \family typewriter
6059 \family typewriter
6009 Shell.py
6060 Shell.py
6010 \family default
6061 \family default
6011 module for more details on the use of this system.
6062 module for more details on the use of this system.
6012 \layout Standard
6063 \layout Standard
6013
6064
6014 The following sample file illustrating how to use the embedding functionality
6065 The following sample file illustrating how to use the embedding functionality
6015 is provided in the examples directory as
6066 is provided in the examples directory as
6016 \family typewriter
6067 \family typewriter
6017 example-embed.py
6068 example-embed.py
6018 \family default
6069 \family default
6019 .
6070 .
6020 It should be fairly self-explanatory:
6071 It should be fairly self-explanatory:
6021 \layout Standard
6072 \layout Standard
6022
6073
6023
6074
6024 \begin_inset Include \verbatiminput{examples/example-embed.py}
6075 \begin_inset ERT
6025 preview false
6076 status Open
6026
6077
6078 \layout Standard
6079
6080 \backslash
6081 lstinputlisting{examples/example-embed.py}
6027 \end_inset
6082 \end_inset
6028
6083
6029
6084
6030 \layout Standard
6085 \layout Standard
6031
6086
6032 Once you understand how the system functions, you can use the following
6087 Once you understand how the system functions, you can use the following
6033 code fragments in your programs which are ready for cut and paste:
6088 code fragments in your programs which are ready for cut and paste:
6034 \layout Standard
6089 \layout Standard
6035
6090
6036
6091
6037 \begin_inset Include \verbatiminput{examples/example-embed-short.py}
6092 \begin_inset ERT
6038 preview false
6093 status Open
6039
6094
6095 \layout Standard
6096
6097 \backslash
6098 lstinputlisting{examples/example-embed-short.py}
6040 \end_inset
6099 \end_inset
6041
6100
6042
6101
6043 \layout Section
6102 \layout Section
6044
6103
6045
6104
6046 \begin_inset LatexCommand \label{sec:using-pdb}
6105 \begin_inset LatexCommand \label{sec:using-pdb}
6047
6106
6048 \end_inset
6107 \end_inset
6049
6108
6050 Using the Python debugger (
6109 Using the Python debugger (
6051 \family typewriter
6110 \family typewriter
6052 pdb
6111 pdb
6053 \family default
6112 \family default
6054 )
6113 )
6055 \layout Subsection
6114 \layout Subsection
6056
6115
6057 Running entire programs via
6116 Running entire programs via
6058 \family typewriter
6117 \family typewriter
6059 pdb
6118 pdb
6060 \layout Standard
6119 \layout Standard
6061
6120
6062
6121
6063 \family typewriter
6122 \family typewriter
6064 pdb
6123 pdb
6065 \family default
6124 \family default
6066 , the Python debugger, is a powerful interactive debugger which allows you
6125 , the Python debugger, is a powerful interactive debugger which allows you
6067 to step through code, set breakpoints, watch variables, etc.
6126 to step through code, set breakpoints, watch variables, etc.
6068 IPython makes it very easy to start any script under the control of
6127 IPython makes it very easy to start any script under the control of
6069 \family typewriter
6128 \family typewriter
6070 pdb
6129 pdb
6071 \family default
6130 \family default
6072 , regardless of whether you have wrapped it into a
6131 , regardless of whether you have wrapped it into a
6073 \family typewriter
6132 \family typewriter
6074 `main()'
6133 `main()'
6075 \family default
6134 \family default
6076 function or not.
6135 function or not.
6077 For this, simply type
6136 For this, simply type
6078 \family typewriter
6137 \family typewriter
6079 `%run -d myscript'
6138 `%run -d myscript'
6080 \family default
6139 \family default
6081 at an IPython prompt.
6140 at an IPython prompt.
6082 See the
6141 See the
6083 \family typewriter
6142 \family typewriter
6084 %run
6143 %run
6085 \family default
6144 \family default
6086 command's documentation (via
6145 command's documentation (via
6087 \family typewriter
6146 \family typewriter
6088 `%run?'
6147 `%run?'
6089 \family default
6148 \family default
6090 or in Sec.\SpecialChar ~
6149 or in Sec.\SpecialChar ~
6091
6150
6092 \begin_inset LatexCommand \ref{sec:magic}
6151 \begin_inset LatexCommand \ref{sec:magic}
6093
6152
6094 \end_inset
6153 \end_inset
6095
6154
6096 ) for more details, including how to control where
6155 ) for more details, including how to control where
6097 \family typewriter
6156 \family typewriter
6098 pdb
6157 pdb
6099 \family default
6158 \family default
6100 will stop execution first.
6159 will stop execution first.
6101 \layout Standard
6160 \layout Standard
6102
6161
6103 For more information on the use of the
6162 For more information on the use of the
6104 \family typewriter
6163 \family typewriter
6105 pdb
6164 pdb
6106 \family default
6165 \family default
6107 debugger, read the included
6166 debugger, read the included
6108 \family typewriter
6167 \family typewriter
6109 pdb.doc
6168 pdb.doc
6110 \family default
6169 \family default
6111 file (part of the standard Python distribution).
6170 file (part of the standard Python distribution).
6112 On a stock Linux system it is located at
6171 On a stock Linux system it is located at
6113 \family typewriter
6172 \family typewriter
6114 /usr/lib/python2.3/pdb.doc
6173 /usr/lib/python2.3/pdb.doc
6115 \family default
6174 \family default
6116 , but the easiest way to read it is by using the
6175 , but the easiest way to read it is by using the
6117 \family typewriter
6176 \family typewriter
6118 help()
6177 help()
6119 \family default
6178 \family default
6120 function of the
6179 function of the
6121 \family typewriter
6180 \family typewriter
6122 pdb
6181 pdb
6123 \family default
6182 \family default
6124 module as follows (in an IPython prompt):
6183 module as follows (in an IPython prompt):
6125 \layout Standard
6184 \layout Standard
6126
6185
6127
6186
6128 \family typewriter
6187 \family typewriter
6129 In [1]: import pdb
6188 In [1]: import pdb
6130 \newline
6189 \newline
6131 In [2]: pdb.help()
6190 In [2]: pdb.help()
6132 \layout Standard
6191 \layout Standard
6133
6192
6134 This will load the
6193 This will load the
6135 \family typewriter
6194 \family typewriter
6136 pdb.doc
6195 pdb.doc
6137 \family default
6196 \family default
6138 document in a file viewer for you automatically.
6197 document in a file viewer for you automatically.
6139 \layout Subsection
6198 \layout Subsection
6140
6199
6141 Automatic invocation of
6200 Automatic invocation of
6142 \family typewriter
6201 \family typewriter
6143 pdb
6202 pdb
6144 \family default
6203 \family default
6145 on exceptions
6204 on exceptions
6146 \layout Standard
6205 \layout Standard
6147
6206
6148 IPython, if started with the
6207 IPython, if started with the
6149 \family typewriter
6208 \family typewriter
6150 -pdb
6209 -pdb
6151 \family default
6210 \family default
6152 option (or if the option is set in your rc file) can call the Python
6211 option (or if the option is set in your rc file) can call the Python
6153 \family typewriter
6212 \family typewriter
6154 pdb
6213 pdb
6155 \family default
6214 \family default
6156 debugger every time your code triggers an uncaught exception
6215 debugger every time your code triggers an uncaught exception
6157 \begin_inset Foot
6216 \begin_inset Foot
6158 collapsed true
6217 collapsed true
6159
6218
6160 \layout Standard
6219 \layout Standard
6161
6220
6162 Many thanks to Christopher Hart for the request which prompted adding this
6221 Many thanks to Christopher Hart for the request which prompted adding this
6163 feature to IPython.
6222 feature to IPython.
6164 \end_inset
6223 \end_inset
6165
6224
6166 .
6225 .
6167 This feature can also be toggled at any time with the
6226 This feature can also be toggled at any time with the
6168 \family typewriter
6227 \family typewriter
6169 %pdb
6228 %pdb
6170 \family default
6229 \family default
6171 magic command.
6230 magic command.
6172 This can be extremely useful in order to find the origin of subtle bugs,
6231 This can be extremely useful in order to find the origin of subtle bugs,
6173 because
6232 because
6174 \family typewriter
6233 \family typewriter
6175 pdb
6234 pdb
6176 \family default
6235 \family default
6177 opens up at the point in your code which triggered the exception, and while
6236 opens up at the point in your code which triggered the exception, and while
6178 your program is at this point `dead', all the data is still available and
6237 your program is at this point `dead', all the data is still available and
6179 you can walk up and down the stack frame and understand the origin of the
6238 you can walk up and down the stack frame and understand the origin of the
6180 problem.
6239 problem.
6181 \layout Standard
6240 \layout Standard
6182
6241
6183 Furthermore, you can use these debugging facilities both with the embedded
6242 Furthermore, you can use these debugging facilities both with the embedded
6184 IPython mode and without IPython at all.
6243 IPython mode and without IPython at all.
6185 For an embedded shell (see sec.
6244 For an embedded shell (see sec.
6186
6245
6187 \begin_inset LatexCommand \ref{sec:embed}
6246 \begin_inset LatexCommand \ref{sec:embed}
6188
6247
6189 \end_inset
6248 \end_inset
6190
6249
6191 ), simply call the constructor with
6250 ), simply call the constructor with
6192 \family typewriter
6251 \family typewriter
6193 `-pdb'
6252 `-pdb'
6194 \family default
6253 \family default
6195 in the argument string and automatically
6254 in the argument string and automatically
6196 \family typewriter
6255 \family typewriter
6197 pdb
6256 pdb
6198 \family default
6257 \family default
6199 will be called if an uncaught exception is triggered by your code.
6258 will be called if an uncaught exception is triggered by your code.
6200
6259
6201 \layout Standard
6260 \layout Standard
6202
6261
6203 For stand-alone use of the feature in your programs which do not use IPython
6262 For stand-alone use of the feature in your programs which do not use IPython
6204 at all, put the following lines toward the top of your `main' routine:
6263 at all, put the following lines toward the top of your `main' routine:
6205 \layout Standard
6264 \layout Standard
6206 \align left
6265 \align left
6207
6266
6208 \family typewriter
6267 \family typewriter
6209 import sys,IPython.ultraTB
6268 import sys,IPython.ultraTB
6210 \newline
6269 \newline
6211 sys.excepthook = IPython.ultraTB.FormattedTB(mode=`Verbose', color_scheme=`Linux',
6270 sys.excepthook = IPython.ultraTB.FormattedTB(mode=`Verbose', color_scheme=`Linux',
6212 call_pdb=1)
6271 call_pdb=1)
6213 \layout Standard
6272 \layout Standard
6214
6273
6215 The
6274 The
6216 \family typewriter
6275 \family typewriter
6217 mode
6276 mode
6218 \family default
6277 \family default
6219 keyword can be either
6278 keyword can be either
6220 \family typewriter
6279 \family typewriter
6221 `Verbose'
6280 `Verbose'
6222 \family default
6281 \family default
6223 or
6282 or
6224 \family typewriter
6283 \family typewriter
6225 `Plain'
6284 `Plain'
6226 \family default
6285 \family default
6227 , giving either very detailed or normal tracebacks respectively.
6286 , giving either very detailed or normal tracebacks respectively.
6228 The
6287 The
6229 \family typewriter
6288 \family typewriter
6230 color_scheme
6289 color_scheme
6231 \family default
6290 \family default
6232 keyword can be one of
6291 keyword can be one of
6233 \family typewriter
6292 \family typewriter
6234 `NoColor'
6293 `NoColor'
6235 \family default
6294 \family default
6236 ,
6295 ,
6237 \family typewriter
6296 \family typewriter
6238 `Linux'
6297 `Linux'
6239 \family default
6298 \family default
6240 (default) or
6299 (default) or
6241 \family typewriter
6300 \family typewriter
6242 `LightBG'
6301 `LightBG'
6243 \family default
6302 \family default
6244 .
6303 .
6245 These are the same options which can be set in IPython with
6304 These are the same options which can be set in IPython with
6246 \family typewriter
6305 \family typewriter
6247 -colors
6306 -colors
6248 \family default
6307 \family default
6249 and
6308 and
6250 \family typewriter
6309 \family typewriter
6251 -xmode
6310 -xmode
6252 \family default
6311 \family default
6253 .
6312 .
6254 \layout Standard
6313 \layout Standard
6255
6314
6256 This will give any of your programs detailed, colored tracebacks with automatic
6315 This will give any of your programs detailed, colored tracebacks with automatic
6257 invocation of
6316 invocation of
6258 \family typewriter
6317 \family typewriter
6259 pdb
6318 pdb
6260 \family default
6319 \family default
6261 .
6320 .
6262 \layout Section
6321 \layout Section
6263
6322
6264
6323
6265 \begin_inset LatexCommand \label{sec:syntax-extensions}
6324 \begin_inset LatexCommand \label{sec:syntax-extensions}
6266
6325
6267 \end_inset
6326 \end_inset
6268
6327
6269 Extensions for syntax processing
6328 Extensions for syntax processing
6270 \layout Standard
6329 \layout Standard
6271
6330
6272 This isn't for the faint of heart, because the potential for breaking things
6331 This isn't for the faint of heart, because the potential for breaking things
6273 is quite high.
6332 is quite high.
6274 But it can be a very powerful and useful feature.
6333 But it can be a very powerful and useful feature.
6275 In a nutshell, you can redefine the way IPython processes the user input
6334 In a nutshell, you can redefine the way IPython processes the user input
6276 line to accept new, special extensions to the syntax without needing to
6335 line to accept new, special extensions to the syntax without needing to
6277 change any of IPython's own code.
6336 change any of IPython's own code.
6278 \layout Standard
6337 \layout Standard
6279
6338
6280 In the
6339 In the
6281 \family typewriter
6340 \family typewriter
6282 IPython/Extensions
6341 IPython/Extensions
6283 \family default
6342 \family default
6284 directory you will find some examples supplied, which we will briefly describe
6343 directory you will find some examples supplied, which we will briefly describe
6285 now.
6344 now.
6286 These can be used `as is' (and both provide very useful functionality),
6345 These can be used `as is' (and both provide very useful functionality),
6287 or you can use them as a starting point for writing your own extensions.
6346 or you can use them as a starting point for writing your own extensions.
6288 \layout Subsection
6347 \layout Subsection
6289
6348
6290 Pasting of code starting with
6349 Pasting of code starting with
6291 \family typewriter
6350 \family typewriter
6292 `>>>
6351 `>>>
6293 \family default
6352 \family default
6294 ' or
6353 ' or
6295 \family typewriter
6354 \family typewriter
6296 `...
6355 `...
6297
6356
6298 \family default
6357 \family default
6299 '
6358 '
6300 \layout Standard
6359 \layout Standard
6301
6360
6302 In the python tutorial it is common to find code examples which have been
6361 In the python tutorial it is common to find code examples which have been
6303 taken from real python sessions.
6362 taken from real python sessions.
6304 The problem with those is that all the lines begin with either
6363 The problem with those is that all the lines begin with either
6305 \family typewriter
6364 \family typewriter
6306 `>>>
6365 `>>>
6307 \family default
6366 \family default
6308 ' or
6367 ' or
6309 \family typewriter
6368 \family typewriter
6310 `...
6369 `...
6311
6370
6312 \family default
6371 \family default
6313 ', which makes it impossible to paste them all at once.
6372 ', which makes it impossible to paste them all at once.
6314 One must instead do a line by line manual copying, carefully removing the
6373 One must instead do a line by line manual copying, carefully removing the
6315 leading extraneous characters.
6374 leading extraneous characters.
6316 \layout Standard
6375 \layout Standard
6317
6376
6318 This extension identifies those starting characters and removes them from
6377 This extension identifies those starting characters and removes them from
6319 the input automatically, so that one can paste multi-line examples directly
6378 the input automatically, so that one can paste multi-line examples directly
6320 into IPython, saving a lot of time.
6379 into IPython, saving a lot of time.
6321 Please look at the file
6380 Please look at the file
6322 \family typewriter
6381 \family typewriter
6323 InterpreterPasteInput.py
6382 InterpreterPasteInput.py
6324 \family default
6383 \family default
6325 in the
6384 in the
6326 \family typewriter
6385 \family typewriter
6327 IPython/Extensions
6386 IPython/Extensions
6328 \family default
6387 \family default
6329 directory for details on how this is done.
6388 directory for details on how this is done.
6330 \layout Standard
6389 \layout Standard
6331
6390
6332 IPython comes with a special profile enabling this feature, called
6391 IPython comes with a special profile enabling this feature, called
6333 \family typewriter
6392 \family typewriter
6334 tutorial
6393 tutorial
6335 \family default
6394 \family default
6336 \emph on
6395 \emph on
6337 .
6396 .
6338
6397
6339 \emph default
6398 \emph default
6340 Simply start IPython via
6399 Simply start IPython via
6341 \family typewriter
6400 \family typewriter
6342 `ipython\SpecialChar ~
6401 `ipython\SpecialChar ~
6343 -p\SpecialChar ~
6402 -p\SpecialChar ~
6344 tutorial'
6403 tutorial'
6345 \family default
6404 \family default
6346 and the feature will be available.
6405 and the feature will be available.
6347 In a normal IPython session you can activate the feature by importing the
6406 In a normal IPython session you can activate the feature by importing the
6348 corresponding module with:
6407 corresponding module with:
6349 \newline
6408 \newline
6350
6409
6351 \family typewriter
6410 \family typewriter
6352 In [1]: import IPython.Extensions.InterpreterPasteInput
6411 In [1]: import IPython.Extensions.InterpreterPasteInput
6353 \layout Standard
6412 \layout Standard
6354
6413
6355 The following is a 'screenshot' of how things work when this extension is
6414 The following is a 'screenshot' of how things work when this extension is
6356 on, copying an example from the standard tutorial:
6415 on, copying an example from the standard tutorial:
6357 \layout Standard
6416 \layout Standard
6358
6417
6359
6418
6360 \family typewriter
6419 \family typewriter
6361 IPython profile: tutorial
6420 IPython profile: tutorial
6362 \newline
6421 \newline
6363 \SpecialChar ~
6422 \SpecialChar ~
6364
6423
6365 \newline
6424 \newline
6366 *** Pasting of code with ">>>" or "..." has been enabled.
6425 *** Pasting of code with ">>>" or "..." has been enabled.
6367 \newline
6426 \newline
6368 \SpecialChar ~
6427 \SpecialChar ~
6369
6428
6370 \newline
6429 \newline
6371 In [1]: >>> def fib2(n): # return Fibonacci series up to n
6430 In [1]: >>> def fib2(n): # return Fibonacci series up to n
6372 \newline
6431 \newline
6373
6432
6374 \begin_inset ERT
6433 \begin_inset ERT
6375 status Collapsed
6434 status Collapsed
6376
6435
6377 \layout Standard
6436 \layout Standard
6378
6437
6379 \backslash
6438 \backslash
6380 hspace*{0mm}
6439 hspace*{0mm}
6381 \end_inset
6440 \end_inset
6382
6441
6383 \SpecialChar ~
6442 \SpecialChar ~
6384 \SpecialChar ~
6443 \SpecialChar ~
6385 ...: ...\SpecialChar ~
6444 ...: ...\SpecialChar ~
6386 \SpecialChar ~
6445 \SpecialChar ~
6387 \SpecialChar ~
6446 \SpecialChar ~
6388 \SpecialChar ~
6447 \SpecialChar ~
6389 """Return a list containing the Fibonacci series up to n."""
6448 """Return a list containing the Fibonacci series up to n."""
6390 \newline
6449 \newline
6391
6450
6392 \begin_inset ERT
6451 \begin_inset ERT
6393 status Collapsed
6452 status Collapsed
6394
6453
6395 \layout Standard
6454 \layout Standard
6396
6455
6397 \backslash
6456 \backslash
6398 hspace*{0mm}
6457 hspace*{0mm}
6399 \end_inset
6458 \end_inset
6400
6459
6401 \SpecialChar ~
6460 \SpecialChar ~
6402 \SpecialChar ~
6461 \SpecialChar ~
6403 ...: ...\SpecialChar ~
6462 ...: ...\SpecialChar ~
6404 \SpecialChar ~
6463 \SpecialChar ~
6405 \SpecialChar ~
6464 \SpecialChar ~
6406 \SpecialChar ~
6465 \SpecialChar ~
6407 result = []
6466 result = []
6408 \newline
6467 \newline
6409
6468
6410 \begin_inset ERT
6469 \begin_inset ERT
6411 status Collapsed
6470 status Collapsed
6412
6471
6413 \layout Standard
6472 \layout Standard
6414
6473
6415 \backslash
6474 \backslash
6416 hspace*{0mm}
6475 hspace*{0mm}
6417 \end_inset
6476 \end_inset
6418
6477
6419 \SpecialChar ~
6478 \SpecialChar ~
6420 \SpecialChar ~
6479 \SpecialChar ~
6421 ...: ...\SpecialChar ~
6480 ...: ...\SpecialChar ~
6422 \SpecialChar ~
6481 \SpecialChar ~
6423 \SpecialChar ~
6482 \SpecialChar ~
6424 \SpecialChar ~
6483 \SpecialChar ~
6425 a, b = 0, 1
6484 a, b = 0, 1
6426 \newline
6485 \newline
6427
6486
6428 \begin_inset ERT
6487 \begin_inset ERT
6429 status Collapsed
6488 status Collapsed
6430
6489
6431 \layout Standard
6490 \layout Standard
6432
6491
6433 \backslash
6492 \backslash
6434 hspace*{0mm}
6493 hspace*{0mm}
6435 \end_inset
6494 \end_inset
6436
6495
6437 \SpecialChar ~
6496 \SpecialChar ~
6438 \SpecialChar ~
6497 \SpecialChar ~
6439 ...: ...\SpecialChar ~
6498 ...: ...\SpecialChar ~
6440 \SpecialChar ~
6499 \SpecialChar ~
6441 \SpecialChar ~
6500 \SpecialChar ~
6442 \SpecialChar ~
6501 \SpecialChar ~
6443 while b < n:
6502 while b < n:
6444 \newline
6503 \newline
6445
6504
6446 \begin_inset ERT
6505 \begin_inset ERT
6447 status Collapsed
6506 status Collapsed
6448
6507
6449 \layout Standard
6508 \layout Standard
6450
6509
6451 \backslash
6510 \backslash
6452 hspace*{0mm}
6511 hspace*{0mm}
6453 \end_inset
6512 \end_inset
6454
6513
6455 \SpecialChar ~
6514 \SpecialChar ~
6456 \SpecialChar ~
6515 \SpecialChar ~
6457 ...: ...\SpecialChar ~
6516 ...: ...\SpecialChar ~
6458 \SpecialChar ~
6517 \SpecialChar ~
6459 \SpecialChar ~
6518 \SpecialChar ~
6460 \SpecialChar ~
6519 \SpecialChar ~
6461 \SpecialChar ~
6520 \SpecialChar ~
6462 \SpecialChar ~
6521 \SpecialChar ~
6463 \SpecialChar ~
6522 \SpecialChar ~
6464 \SpecialChar ~
6523 \SpecialChar ~
6465 result.append(b)\SpecialChar ~
6524 result.append(b)\SpecialChar ~
6466 \SpecialChar ~
6525 \SpecialChar ~
6467 \SpecialChar ~
6526 \SpecialChar ~
6468 # see below
6527 # see below
6469 \newline
6528 \newline
6470
6529
6471 \begin_inset ERT
6530 \begin_inset ERT
6472 status Collapsed
6531 status Collapsed
6473
6532
6474 \layout Standard
6533 \layout Standard
6475
6534
6476 \backslash
6535 \backslash
6477 hspace*{0mm}
6536 hspace*{0mm}
6478 \end_inset
6537 \end_inset
6479
6538
6480 \SpecialChar ~
6539 \SpecialChar ~
6481 \SpecialChar ~
6540 \SpecialChar ~
6482 ...: ...\SpecialChar ~
6541 ...: ...\SpecialChar ~
6483 \SpecialChar ~
6542 \SpecialChar ~
6484 \SpecialChar ~
6543 \SpecialChar ~
6485 \SpecialChar ~
6544 \SpecialChar ~
6486 \SpecialChar ~
6545 \SpecialChar ~
6487 \SpecialChar ~
6546 \SpecialChar ~
6488 \SpecialChar ~
6547 \SpecialChar ~
6489 \SpecialChar ~
6548 \SpecialChar ~
6490 a, b = b, a+b
6549 a, b = b, a+b
6491 \newline
6550 \newline
6492
6551
6493 \begin_inset ERT
6552 \begin_inset ERT
6494 status Collapsed
6553 status Collapsed
6495
6554
6496 \layout Standard
6555 \layout Standard
6497
6556
6498 \backslash
6557 \backslash
6499 hspace*{0mm}
6558 hspace*{0mm}
6500 \end_inset
6559 \end_inset
6501
6560
6502 \SpecialChar ~
6561 \SpecialChar ~
6503 \SpecialChar ~
6562 \SpecialChar ~
6504 ...: ...\SpecialChar ~
6563 ...: ...\SpecialChar ~
6505 \SpecialChar ~
6564 \SpecialChar ~
6506 \SpecialChar ~
6565 \SpecialChar ~
6507 \SpecialChar ~
6566 \SpecialChar ~
6508 return result
6567 return result
6509 \newline
6568 \newline
6510
6569
6511 \begin_inset ERT
6570 \begin_inset ERT
6512 status Collapsed
6571 status Collapsed
6513
6572
6514 \layout Standard
6573 \layout Standard
6515
6574
6516 \backslash
6575 \backslash
6517 hspace*{0mm}
6576 hspace*{0mm}
6518 \end_inset
6577 \end_inset
6519
6578
6520 \SpecialChar ~
6579 \SpecialChar ~
6521 \SpecialChar ~
6580 \SpecialChar ~
6522 ...:
6581 ...:
6523 \newline
6582 \newline
6524 \SpecialChar ~
6583 \SpecialChar ~
6525
6584
6526 \newline
6585 \newline
6527 In [2]: fib2(10)
6586 In [2]: fib2(10)
6528 \newline
6587 \newline
6529 Out[2]: [1, 1, 2, 3, 5, 8]
6588 Out[2]: [1, 1, 2, 3, 5, 8]
6530 \layout Standard
6589 \layout Standard
6531
6590
6532 Note that as currently written, this extension does
6591 Note that as currently written, this extension does
6533 \emph on
6592 \emph on
6534 not
6593 not
6535 \emph default
6594 \emph default
6536 recognize IPython's prompts for pasting.
6595 recognize IPython's prompts for pasting.
6537 Those are more complicated, since the user can change them very easily,
6596 Those are more complicated, since the user can change them very easily,
6538 they involve numbers and can vary in length.
6597 they involve numbers and can vary in length.
6539 One could however extract all the relevant information from the IPython
6598 One could however extract all the relevant information from the IPython
6540 instance and build an appropriate regular expression.
6599 instance and build an appropriate regular expression.
6541 This is left as an exercise for the reader.
6600 This is left as an exercise for the reader.
6542 \layout Subsection
6601 \layout Subsection
6543
6602
6544 Input of physical quantities with units
6603 Input of physical quantities with units
6545 \layout Standard
6604 \layout Standard
6546
6605
6547 The module
6606 The module
6548 \family typewriter
6607 \family typewriter
6549 PhysicalQInput
6608 PhysicalQInput
6550 \family default
6609 \family default
6551 allows a simplified form of input for physical quantities with units.
6610 allows a simplified form of input for physical quantities with units.
6552 This file is meant to be used in conjunction with the
6611 This file is meant to be used in conjunction with the
6553 \family typewriter
6612 \family typewriter
6554 PhysicalQInteractive
6613 PhysicalQInteractive
6555 \family default
6614 \family default
6556 module (in the same directory) and
6615 module (in the same directory) and
6557 \family typewriter
6616 \family typewriter
6558 Physics.PhysicalQuantities
6617 Physics.PhysicalQuantities
6559 \family default
6618 \family default
6560 from Konrad Hinsen's ScientificPython (
6619 from Konrad Hinsen's ScientificPython (
6561 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/hinsen/scientific.html}
6620 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/hinsen/scientific.html}
6562
6621
6563 \end_inset
6622 \end_inset
6564
6623
6565 ).
6624 ).
6566 \layout Standard
6625 \layout Standard
6567
6626
6568 The
6627 The
6569 \family typewriter
6628 \family typewriter
6570 Physics.PhysicalQuantities
6629 Physics.PhysicalQuantities
6571 \family default
6630 \family default
6572 module defines
6631 module defines
6573 \family typewriter
6632 \family typewriter
6574 PhysicalQuantity
6633 PhysicalQuantity
6575 \family default
6634 \family default
6576 objects, but these must be declared as instances of a class.
6635 objects, but these must be declared as instances of a class.
6577 For example, to define
6636 For example, to define
6578 \family typewriter
6637 \family typewriter
6579 v
6638 v
6580 \family default
6639 \family default
6581 as a velocity of 3\SpecialChar ~
6640 as a velocity of 3\SpecialChar ~
6582 m/s, normally you would write:
6641 m/s, normally you would write:
6583 \family typewriter
6642 \family typewriter
6584
6643
6585 \newline
6644 \newline
6586 In [1]: v = PhysicalQuantity(3,'m/s')
6645 In [1]: v = PhysicalQuantity(3,'m/s')
6587 \layout Standard
6646 \layout Standard
6588
6647
6589 Using the
6648 Using the
6590 \family typewriter
6649 \family typewriter
6591 PhysicalQ_Input
6650 PhysicalQ_Input
6592 \family default
6651 \family default
6593 extension this can be input instead as:
6652 extension this can be input instead as:
6594 \family typewriter
6653 \family typewriter
6595
6654
6596 \newline
6655 \newline
6597 In [1]: v = 3 m/s
6656 In [1]: v = 3 m/s
6598 \family default
6657 \family default
6599
6658
6600 \newline
6659 \newline
6601 which is much more convenient for interactive use (even though it is blatantly
6660 which is much more convenient for interactive use (even though it is blatantly
6602 invalid Python syntax).
6661 invalid Python syntax).
6603 \layout Standard
6662 \layout Standard
6604
6663
6605 The
6664 The
6606 \family typewriter
6665 \family typewriter
6607 physics
6666 physics
6608 \family default
6667 \family default
6609 profile supplied with IPython (enabled via
6668 profile supplied with IPython (enabled via
6610 \family typewriter
6669 \family typewriter
6611 'ipython -p physics'
6670 'ipython -p physics'
6612 \family default
6671 \family default
6613 ) uses these extensions, which you can also activate with:
6672 ) uses these extensions, which you can also activate with:
6614 \layout Standard
6673 \layout Standard
6615
6674
6616
6675
6617 \family typewriter
6676 \family typewriter
6618 from math import * # math MUST be imported BEFORE PhysicalQInteractive
6677 from math import * # math MUST be imported BEFORE PhysicalQInteractive
6619 \newline
6678 \newline
6620 from IPython.Extensions.PhysicalQInteractive import *
6679 from IPython.Extensions.PhysicalQInteractive import *
6621 \newline
6680 \newline
6622 import IPython.Extensions.PhysicalQInput
6681 import IPython.Extensions.PhysicalQInput
6623 \layout Section
6682 \layout Section
6624
6683
6625 IPython as a system shell
6684 IPython as a system shell
6626 \layout Standard
6685 \layout Standard
6627
6686
6628 IPython ships with a special profile called
6687 IPython ships with a special profile called
6629 \family typewriter
6688 \family typewriter
6630 pysh
6689 pysh
6631 \family default
6690 \family default
6632 , which you can activate at the command line as
6691 , which you can activate at the command line as
6633 \family typewriter
6692 \family typewriter
6634 `ipython -p pysh'
6693 `ipython -p pysh'
6635 \family default
6694 \family default
6636 .
6695 .
6637 This loads
6696 This loads
6638 \family typewriter
6697 \family typewriter
6639 InterpreterExec
6698 InterpreterExec
6640 \family default
6699 \family default
6641 , along with some additional facilities and a prompt customized for filesystem
6700 , along with some additional facilities and a prompt customized for filesystem
6642 navigation.
6701 navigation.
6643 \layout Standard
6702 \layout Standard
6644
6703
6645 Note that this does
6704 Note that this does
6646 \emph on
6705 \emph on
6647 not
6706 not
6648 \emph default
6707 \emph default
6649 make IPython a full-fledged system shell.
6708 make IPython a full-fledged system shell.
6650 In particular, it has no job control, so if you type Ctrl-Z (under Unix),
6709 In particular, it has no job control, so if you type Ctrl-Z (under Unix),
6651 you'll suspend pysh itself, not the process you just started.
6710 you'll suspend pysh itself, not the process you just started.
6652
6711
6653 \layout Standard
6712 \layout Standard
6654
6713
6655 What the shell profile allows you to do is to use the convenient and powerful
6714 What the shell profile allows you to do is to use the convenient and powerful
6656 syntax of Python to do quick scripting at the command line.
6715 syntax of Python to do quick scripting at the command line.
6657 Below we describe some of its features.
6716 Below we describe some of its features.
6658 \layout Subsection
6717 \layout Subsection
6659
6718
6660 Aliases
6719 Aliases
6661 \layout Standard
6720 \layout Standard
6662
6721
6663 All of your
6722 All of your
6664 \family typewriter
6723 \family typewriter
6665 $PATH
6724 $PATH
6666 \family default
6725 \family default
6667 has been loaded as IPython aliases, so you should be able to type any normal
6726 has been loaded as IPython aliases, so you should be able to type any normal
6668 system command and have it executed.
6727 system command and have it executed.
6669 See
6728 See
6670 \family typewriter
6729 \family typewriter
6671 %alias?
6730 %alias?
6672 \family default
6731 \family default
6673 and
6732 and
6674 \family typewriter
6733 \family typewriter
6675 %unalias?
6734 %unalias?
6676 \family default
6735 \family default
6677 for details on the alias facilities.
6736 for details on the alias facilities.
6678 See also
6737 See also
6679 \family typewriter
6738 \family typewriter
6680 %rehash?
6739 %rehash?
6681 \family default
6740 \family default
6682 and
6741 and
6683 \family typewriter
6742 \family typewriter
6684 %rehashx?
6743 %rehashx?
6685 \family default
6744 \family default
6686 for details on the mechanism used to load
6745 for details on the mechanism used to load
6687 \family typewriter
6746 \family typewriter
6688 $PATH
6747 $PATH
6689 \family default
6748 \family default
6690 .
6749 .
6691 \layout Subsection
6750 \layout Subsection
6692
6751
6693 Special syntax
6752 Special syntax
6694 \layout Standard
6753 \layout Standard
6695
6754
6696 Any lines which begin with
6755 Any lines which begin with
6697 \family typewriter
6756 \family typewriter
6698 `~'
6757 `~'
6699 \family default
6758 \family default
6700 ,
6759 ,
6701 \family typewriter
6760 \family typewriter
6702 `/'
6761 `/'
6703 \family default
6762 \family default
6704 and
6763 and
6705 \family typewriter
6764 \family typewriter
6706 `.'
6765 `.'
6707 \family default
6766 \family default
6708 will be executed as shell commands instead of as Python code.
6767 will be executed as shell commands instead of as Python code.
6709 The special escapes below are also recognized.
6768 The special escapes below are also recognized.
6710
6769
6711 \family typewriter
6770 \family typewriter
6712 !cmd
6771 !cmd
6713 \family default
6772 \family default
6714 is valid in single or multi-line input, all others are only valid in single-lin
6773 is valid in single or multi-line input, all others are only valid in single-lin
6715 e input:
6774 e input:
6716 \layout Description
6775 \layout Description
6717
6776
6718
6777
6719 \family typewriter
6778 \family typewriter
6720 !cmd
6779 !cmd
6721 \family default
6780 \family default
6722 pass `cmd' directly to the shell
6781 pass `cmd' directly to the shell
6723 \layout Description
6782 \layout Description
6724
6783
6725
6784
6726 \family typewriter
6785 \family typewriter
6727 !!cmd
6786 !!cmd
6728 \family default
6787 \family default
6729 execute `cmd' and return output as a list (split on `
6788 execute `cmd' and return output as a list (split on `
6730 \backslash
6789 \backslash
6731 n')
6790 n')
6732 \layout Description
6791 \layout Description
6733
6792
6734
6793
6735 \family typewriter
6794 \family typewriter
6736 $var=cmd
6795 $var=cmd
6737 \family default
6796 \family default
6738 capture output of cmd into var, as a string
6797 capture output of cmd into var, as a string
6739 \layout Description
6798 \layout Description
6740
6799
6741
6800
6742 \family typewriter
6801 \family typewriter
6743 $$var=cmd
6802 $$var=cmd
6744 \family default
6803 \family default
6745 capture output of cmd into var, as a list (split on `
6804 capture output of cmd into var, as a list (split on `
6746 \backslash
6805 \backslash
6747 n')
6806 n')
6748 \layout Standard
6807 \layout Standard
6749
6808
6750 The
6809 The
6751 \family typewriter
6810 \family typewriter
6752 $
6811 $
6753 \family default
6812 \family default
6754 /
6813 /
6755 \family typewriter
6814 \family typewriter
6756 $$
6815 $$
6757 \family default
6816 \family default
6758 syntaxes make Python variables from system output, which you can later
6817 syntaxes make Python variables from system output, which you can later
6759 use for further scripting.
6818 use for further scripting.
6760 The converse is also possible: when executing an alias or calling to the
6819 The converse is also possible: when executing an alias or calling to the
6761 system via
6820 system via
6762 \family typewriter
6821 \family typewriter
6763 !
6822 !
6764 \family default
6823 \family default
6765 /
6824 /
6766 \family typewriter
6825 \family typewriter
6767 !!
6826 !!
6768 \family default
6827 \family default
6769 , you can expand any python variable or expression by prepending it with
6828 , you can expand any python variable or expression by prepending it with
6770
6829
6771 \family typewriter
6830 \family typewriter
6772 $
6831 $
6773 \family default
6832 \family default
6774 .
6833 .
6775 Full details of the allowed syntax can be found in Python's PEP 215.
6834 Full details of the allowed syntax can be found in Python's PEP 215.
6776 \layout Standard
6835 \layout Standard
6777
6836
6778 A few brief examples will illustrate these (note that the indentation below
6837 A few brief examples will illustrate these (note that the indentation below
6779 may be incorrectly displayed):
6838 may be incorrectly displayed):
6780 \layout Standard
6839 \layout Standard
6781
6840
6782
6841
6783 \family typewriter
6842 \family typewriter
6784 fperez[~/test]|3> !ls *s.py
6843 fperez[~/test]|3> !ls *s.py
6785 \newline
6844 \newline
6786 scopes.py strings.py
6845 scopes.py strings.py
6787 \layout Standard
6846 \layout Standard
6788
6847
6789 ls is an internal alias, so there's no need to use
6848 ls is an internal alias, so there's no need to use
6790 \family typewriter
6849 \family typewriter
6791 !
6850 !
6792 \family default
6851 \family default
6793 :
6852 :
6794 \layout Standard
6853 \layout Standard
6795
6854
6796
6855
6797 \family typewriter
6856 \family typewriter
6798 fperez[~/test]|4> ls *s.py
6857 fperez[~/test]|4> ls *s.py
6799 \newline
6858 \newline
6800 scopes.py* strings.py
6859 scopes.py* strings.py
6801 \layout Standard
6860 \layout Standard
6802
6861
6803 !!ls will return the output into a Python variable:
6862 !!ls will return the output into a Python variable:
6804 \layout Standard
6863 \layout Standard
6805
6864
6806
6865
6807 \family typewriter
6866 \family typewriter
6808 fperez[~/test]|5> !!ls *s.py
6867 fperez[~/test]|5> !!ls *s.py
6809 \newline
6868 \newline
6810
6869
6811 \begin_inset ERT
6870 \begin_inset ERT
6812 status Collapsed
6871 status Collapsed
6813
6872
6814 \layout Standard
6873 \layout Standard
6815
6874
6816 \backslash
6875 \backslash
6817 hspace*{0mm}
6876 hspace*{0mm}
6818 \end_inset
6877 \end_inset
6819
6878
6820 \SpecialChar ~
6879 \SpecialChar ~
6821 \SpecialChar ~
6880 \SpecialChar ~
6822 \SpecialChar ~
6881 \SpecialChar ~
6823 \SpecialChar ~
6882 \SpecialChar ~
6824 \SpecialChar ~
6883 \SpecialChar ~
6825 \SpecialChar ~
6884 \SpecialChar ~
6826 \SpecialChar ~
6885 \SpecialChar ~
6827 \SpecialChar ~
6886 \SpecialChar ~
6828 \SpecialChar ~
6887 \SpecialChar ~
6829 \SpecialChar ~
6888 \SpecialChar ~
6830 \SpecialChar ~
6889 \SpecialChar ~
6831 \SpecialChar ~
6890 \SpecialChar ~
6832 \SpecialChar ~
6891 \SpecialChar ~
6833 \SpecialChar ~
6892 \SpecialChar ~
6834 <5> ['scopes.py', 'strings.py']
6893 <5> ['scopes.py', 'strings.py']
6835 \newline
6894 \newline
6836 fperez[~/test]|6> print _5
6895 fperez[~/test]|6> print _5
6837 \newline
6896 \newline
6838 ['scopes.py', 'strings.py']
6897 ['scopes.py', 'strings.py']
6839 \layout Standard
6898 \layout Standard
6840
6899
6841
6900
6842 \family typewriter
6901 \family typewriter
6843 $
6902 $
6844 \family default
6903 \family default
6845 and
6904 and
6846 \family typewriter
6905 \family typewriter
6847 $$
6906 $$
6848 \family default
6907 \family default
6849 allow direct capture to named variables:
6908 allow direct capture to named variables:
6850 \layout Standard
6909 \layout Standard
6851
6910
6852
6911
6853 \family typewriter
6912 \family typewriter
6854 fperez[~/test]|7> $astr = ls *s.py
6913 fperez[~/test]|7> $astr = ls *s.py
6855 \newline
6914 \newline
6856 fperez[~/test]|8> astr
6915 fperez[~/test]|8> astr
6857 \newline
6916 \newline
6858
6917
6859 \begin_inset ERT
6918 \begin_inset ERT
6860 status Collapsed
6919 status Collapsed
6861
6920
6862 \layout Standard
6921 \layout Standard
6863
6922
6864 \backslash
6923 \backslash
6865 hspace*{0mm}
6924 hspace*{0mm}
6866 \end_inset
6925 \end_inset
6867
6926
6868 \SpecialChar ~
6927 \SpecialChar ~
6869 \SpecialChar ~
6928 \SpecialChar ~
6870 \SpecialChar ~
6929 \SpecialChar ~
6871 \SpecialChar ~
6930 \SpecialChar ~
6872 \SpecialChar ~
6931 \SpecialChar ~
6873 \SpecialChar ~
6932 \SpecialChar ~
6874 \SpecialChar ~
6933 \SpecialChar ~
6875 \SpecialChar ~
6934 \SpecialChar ~
6876 \SpecialChar ~
6935 \SpecialChar ~
6877 \SpecialChar ~
6936 \SpecialChar ~
6878 \SpecialChar ~
6937 \SpecialChar ~
6879 \SpecialChar ~
6938 \SpecialChar ~
6880 \SpecialChar ~
6939 \SpecialChar ~
6881 \SpecialChar ~
6940 \SpecialChar ~
6882 <8> 'scopes.py
6941 <8> 'scopes.py
6883 \backslash
6942 \backslash
6884 nstrings.py'
6943 nstrings.py'
6885 \layout Standard
6944 \layout Standard
6886
6945
6887
6946
6888 \family typewriter
6947 \family typewriter
6889 fperez[~/test]|9> $$alist = ls *s.py
6948 fperez[~/test]|9> $$alist = ls *s.py
6890 \newline
6949 \newline
6891 fperez[~/test]|10> alist
6950 fperez[~/test]|10> alist
6892 \newline
6951 \newline
6893
6952
6894 \begin_inset ERT
6953 \begin_inset ERT
6895 status Collapsed
6954 status Collapsed
6896
6955
6897 \layout Standard
6956 \layout Standard
6898
6957
6899 \backslash
6958 \backslash
6900 hspace*{0mm}
6959 hspace*{0mm}
6901 \end_inset
6960 \end_inset
6902
6961
6903 \SpecialChar ~
6962 \SpecialChar ~
6904 \SpecialChar ~
6963 \SpecialChar ~
6905 \SpecialChar ~
6964 \SpecialChar ~
6906 \SpecialChar ~
6965 \SpecialChar ~
6907 \SpecialChar ~
6966 \SpecialChar ~
6908 \SpecialChar ~
6967 \SpecialChar ~
6909 \SpecialChar ~
6968 \SpecialChar ~
6910 \SpecialChar ~
6969 \SpecialChar ~
6911 \SpecialChar ~
6970 \SpecialChar ~
6912 \SpecialChar ~
6971 \SpecialChar ~
6913 \SpecialChar ~
6972 \SpecialChar ~
6914 \SpecialChar ~
6973 \SpecialChar ~
6915 \SpecialChar ~
6974 \SpecialChar ~
6916 \SpecialChar ~
6975 \SpecialChar ~
6917 <10> ['scopes.py', 'strings.py']
6976 <10> ['scopes.py', 'strings.py']
6918 \layout Standard
6977 \layout Standard
6919
6978
6920 alist is now a normal python list you can loop over.
6979 alist is now a normal python list you can loop over.
6921 Using
6980 Using
6922 \family typewriter
6981 \family typewriter
6923 $
6982 $
6924 \family default
6983 \family default
6925 will expand back the python values when alias calls are made:
6984 will expand back the python values when alias calls are made:
6926 \layout Standard
6985 \layout Standard
6927
6986
6928
6987
6929 \family typewriter
6988 \family typewriter
6930 fperez[~/test]|11> for f in alist:
6989 fperez[~/test]|11> for f in alist:
6931 \newline
6990 \newline
6932
6991
6933 \begin_inset ERT
6992 \begin_inset ERT
6934 status Collapsed
6993 status Collapsed
6935
6994
6936 \layout Standard
6995 \layout Standard
6937
6996
6938 \backslash
6997 \backslash
6939 hspace*{0mm}
6998 hspace*{0mm}
6940 \end_inset
6999 \end_inset
6941
7000
6942 \SpecialChar ~
7001 \SpecialChar ~
6943 \SpecialChar ~
7002 \SpecialChar ~
6944 \SpecialChar ~
7003 \SpecialChar ~
6945 \SpecialChar ~
7004 \SpecialChar ~
6946 \SpecialChar ~
7005 \SpecialChar ~
6947 \SpecialChar ~
7006 \SpecialChar ~
6948 \SpecialChar ~
7007 \SpecialChar ~
6949 \SpecialChar ~
7008 \SpecialChar ~
6950 \SpecialChar ~
7009 \SpecialChar ~
6951 \SpecialChar ~
7010 \SpecialChar ~
6952 \SpecialChar ~
7011 \SpecialChar ~
6953 \SpecialChar ~
7012 \SpecialChar ~
6954 \SpecialChar ~
7013 \SpecialChar ~
6955 \SpecialChar ~
7014 \SpecialChar ~
6956 |..> \SpecialChar ~
7015 |..> \SpecialChar ~
6957 \SpecialChar ~
7016 \SpecialChar ~
6958 \SpecialChar ~
7017 \SpecialChar ~
6959 \SpecialChar ~
7018 \SpecialChar ~
6960 print 'file',f,
7019 print 'file',f,
6961 \newline
7020 \newline
6962
7021
6963 \begin_inset ERT
7022 \begin_inset ERT
6964 status Collapsed
7023 status Collapsed
6965
7024
6966 \layout Standard
7025 \layout Standard
6967
7026
6968 \backslash
7027 \backslash
6969 hspace*{0mm}
7028 hspace*{0mm}
6970 \end_inset
7029 \end_inset
6971
7030
6972 \SpecialChar ~
7031 \SpecialChar ~
6973 \SpecialChar ~
7032 \SpecialChar ~
6974 \SpecialChar ~
7033 \SpecialChar ~
6975 \SpecialChar ~
7034 \SpecialChar ~
6976 \SpecialChar ~
7035 \SpecialChar ~
6977 \SpecialChar ~
7036 \SpecialChar ~
6978 \SpecialChar ~
7037 \SpecialChar ~
6979 \SpecialChar ~
7038 \SpecialChar ~
6980 \SpecialChar ~
7039 \SpecialChar ~
6981 \SpecialChar ~
7040 \SpecialChar ~
6982 \SpecialChar ~
7041 \SpecialChar ~
6983 \SpecialChar ~
7042 \SpecialChar ~
6984 \SpecialChar ~
7043 \SpecialChar ~
6985 \SpecialChar ~
7044 \SpecialChar ~
6986 |..> \SpecialChar ~
7045 |..> \SpecialChar ~
6987 \SpecialChar ~
7046 \SpecialChar ~
6988 \SpecialChar ~
7047 \SpecialChar ~
6989 \SpecialChar ~
7048 \SpecialChar ~
6990 wc -l $f
7049 wc -l $f
6991 \newline
7050 \newline
6992
7051
6993 \begin_inset ERT
7052 \begin_inset ERT
6994 status Collapsed
7053 status Collapsed
6995
7054
6996 \layout Standard
7055 \layout Standard
6997
7056
6998 \backslash
7057 \backslash
6999 hspace*{0mm}
7058 hspace*{0mm}
7000 \end_inset
7059 \end_inset
7001
7060
7002 \SpecialChar ~
7061 \SpecialChar ~
7003 \SpecialChar ~
7062 \SpecialChar ~
7004 \SpecialChar ~
7063 \SpecialChar ~
7005 \SpecialChar ~
7064 \SpecialChar ~
7006 \SpecialChar ~
7065 \SpecialChar ~
7007 \SpecialChar ~
7066 \SpecialChar ~
7008 \SpecialChar ~
7067 \SpecialChar ~
7009 \SpecialChar ~
7068 \SpecialChar ~
7010 \SpecialChar ~
7069 \SpecialChar ~
7011 \SpecialChar ~
7070 \SpecialChar ~
7012 \SpecialChar ~
7071 \SpecialChar ~
7013 \SpecialChar ~
7072 \SpecialChar ~
7014 \SpecialChar ~
7073 \SpecialChar ~
7015 \SpecialChar ~
7074 \SpecialChar ~
7016 |..>
7075 |..>
7017 \newline
7076 \newline
7018 file scopes.py 13 scopes.py
7077 file scopes.py 13 scopes.py
7019 \newline
7078 \newline
7020 file strings.py 4 strings.py
7079 file strings.py 4 strings.py
7021 \layout Standard
7080 \layout Standard
7022
7081
7023 Note that you may need to protect your variables with braces if you want
7082 Note that you may need to protect your variables with braces if you want
7024 to append strings to their names.
7083 to append strings to their names.
7025 To copy all files in alist to
7084 To copy all files in alist to
7026 \family typewriter
7085 \family typewriter
7027 .bak
7086 .bak
7028 \family default
7087 \family default
7029 extensions, you must use:
7088 extensions, you must use:
7030 \layout Standard
7089 \layout Standard
7031
7090
7032
7091
7033 \family typewriter
7092 \family typewriter
7034 fperez[~/test]|12> for f in alist:
7093 fperez[~/test]|12> for f in alist:
7035 \newline
7094 \newline
7036
7095
7037 \begin_inset ERT
7096 \begin_inset ERT
7038 status Collapsed
7097 status Collapsed
7039
7098
7040 \layout Standard
7099 \layout Standard
7041
7100
7042 \backslash
7101 \backslash
7043 hspace*{0mm}
7102 hspace*{0mm}
7044 \end_inset
7103 \end_inset
7045
7104
7046 \SpecialChar ~
7105 \SpecialChar ~
7047 \SpecialChar ~
7106 \SpecialChar ~
7048 \SpecialChar ~
7107 \SpecialChar ~
7049 \SpecialChar ~
7108 \SpecialChar ~
7050 \SpecialChar ~
7109 \SpecialChar ~
7051 \SpecialChar ~
7110 \SpecialChar ~
7052 \SpecialChar ~
7111 \SpecialChar ~
7053 \SpecialChar ~
7112 \SpecialChar ~
7054 \SpecialChar ~
7113 \SpecialChar ~
7055 \SpecialChar ~
7114 \SpecialChar ~
7056 \SpecialChar ~
7115 \SpecialChar ~
7057 \SpecialChar ~
7116 \SpecialChar ~
7058 \SpecialChar ~
7117 \SpecialChar ~
7059 \SpecialChar ~
7118 \SpecialChar ~
7060 |..> \SpecialChar ~
7119 |..> \SpecialChar ~
7061 \SpecialChar ~
7120 \SpecialChar ~
7062 \SpecialChar ~
7121 \SpecialChar ~
7063 \SpecialChar ~
7122 \SpecialChar ~
7064 cp $f ${f}.bak
7123 cp $f ${f}.bak
7065 \layout Standard
7124 \layout Standard
7066
7125
7067 If you try using
7126 If you try using
7068 \family typewriter
7127 \family typewriter
7069 $f.bak
7128 $f.bak
7070 \family default
7129 \family default
7071 , you'll get an AttributeError exception saying that your string object
7130 , you'll get an AttributeError exception saying that your string object
7072 doesn't have a
7131 doesn't have a
7073 \family typewriter
7132 \family typewriter
7074 .bak
7133 .bak
7075 \family default
7134 \family default
7076 attribute.
7135 attribute.
7077 This is because the
7136 This is because the
7078 \family typewriter
7137 \family typewriter
7079 $
7138 $
7080 \family default
7139 \family default
7081 expansion mechanism allows you to expand full Python expressions:
7140 expansion mechanism allows you to expand full Python expressions:
7082 \layout Standard
7141 \layout Standard
7083
7142
7084
7143
7085 \family typewriter
7144 \family typewriter
7086 fperez[~/test]|13> echo "sys.platform is: $sys.platform"
7145 fperez[~/test]|13> echo "sys.platform is: $sys.platform"
7087 \newline
7146 \newline
7088 sys.platform is: linux2
7147 sys.platform is: linux2
7089 \layout Standard
7148 \layout Standard
7090
7149
7091 IPython's input history handling is still active, which allows you to rerun
7150 IPython's input history handling is still active, which allows you to rerun
7092 a single block of multi-line input by simply using exec:
7151 a single block of multi-line input by simply using exec:
7093 \newline
7152 \newline
7094
7153
7095 \family typewriter
7154 \family typewriter
7096 fperez[~/test]|14> $$alist = ls *.eps
7155 fperez[~/test]|14> $$alist = ls *.eps
7097 \newline
7156 \newline
7098 fperez[~/test]|15> exec _i11
7157 fperez[~/test]|15> exec _i11
7099 \newline
7158 \newline
7100 file image2.eps 921 image2.eps
7159 file image2.eps 921 image2.eps
7101 \newline
7160 \newline
7102 file image.eps 921 image.eps
7161 file image.eps 921 image.eps
7103 \layout Standard
7162 \layout Standard
7104
7163
7105 While these are new special-case syntaxes, they are designed to allow very
7164 While these are new special-case syntaxes, they are designed to allow very
7106 efficient use of the shell with minimal typing.
7165 efficient use of the shell with minimal typing.
7107 At an interactive shell prompt, conciseness of expression wins over readability.
7166 At an interactive shell prompt, conciseness of expression wins over readability.
7108 \layout Subsection
7167 \layout Subsection
7109
7168
7110 Useful functions and modules
7169 Useful functions and modules
7111 \layout Standard
7170 \layout Standard
7112
7171
7113 The os, sys and shutil modules from the Python standard library are automaticall
7172 The os, sys and shutil modules from the Python standard library are automaticall
7114 y loaded.
7173 y loaded.
7115 Some additional functions, useful for shell usage, are listed below.
7174 Some additional functions, useful for shell usage, are listed below.
7116 You can request more help about them with `
7175 You can request more help about them with `
7117 \family typewriter
7176 \family typewriter
7118 ?
7177 ?
7119 \family default
7178 \family default
7120 '.
7179 '.
7121 \layout Description
7180 \layout Description
7122
7181
7123
7182
7124 \family typewriter
7183 \family typewriter
7125 shell
7184 shell
7126 \family default
7185 \family default
7127 - execute a command in the underlying system shell
7186 - execute a command in the underlying system shell
7128 \layout Description
7187 \layout Description
7129
7188
7130
7189
7131 \family typewriter
7190 \family typewriter
7132 system
7191 system
7133 \family default
7192 \family default
7134 - like
7193 - like
7135 \family typewriter
7194 \family typewriter
7136 shell()
7195 shell()
7137 \family default
7196 \family default
7138 , but return the exit status of the command
7197 , but return the exit status of the command
7139 \layout Description
7198 \layout Description
7140
7199
7141
7200
7142 \family typewriter
7201 \family typewriter
7143 sout
7202 sout
7144 \family default
7203 \family default
7145 - capture the output of a command as a string
7204 - capture the output of a command as a string
7146 \layout Description
7205 \layout Description
7147
7206
7148
7207
7149 \family typewriter
7208 \family typewriter
7150 lout
7209 lout
7151 \family default
7210 \family default
7152 - capture the output of a command as a list (split on `
7211 - capture the output of a command as a list (split on `
7153 \backslash
7212 \backslash
7154 n')
7213 n')
7155 \layout Description
7214 \layout Description
7156
7215
7157
7216
7158 \family typewriter
7217 \family typewriter
7159 getoutputerror
7218 getoutputerror
7160 \family default
7219 \family default
7161 - capture (output,error) of a shell commandss
7220 - capture (output,error) of a shell commandss
7162 \layout Standard
7221 \layout Standard
7163
7222
7164
7223
7165 \family typewriter
7224 \family typewriter
7166 sout
7225 sout
7167 \family default
7226 \family default
7168 /
7227 /
7169 \family typewriter
7228 \family typewriter
7170 lout
7229 lout
7171 \family default
7230 \family default
7172 are the functional equivalents of
7231 are the functional equivalents of
7173 \family typewriter
7232 \family typewriter
7174 $
7233 $
7175 \family default
7234 \family default
7176 /
7235 /
7177 \family typewriter
7236 \family typewriter
7178 $$
7237 $$
7179 \family default
7238 \family default
7180 .
7239 .
7181 They are provided to allow you to capture system output in the middle of
7240 They are provided to allow you to capture system output in the middle of
7182 true python code, function definitions, etc (where
7241 true python code, function definitions, etc (where
7183 \family typewriter
7242 \family typewriter
7184 $
7243 $
7185 \family default
7244 \family default
7186 and
7245 and
7187 \family typewriter
7246 \family typewriter
7188 $$
7247 $$
7189 \family default
7248 \family default
7190 are invalid).
7249 are invalid).
7191 \layout Subsection
7250 \layout Subsection
7192
7251
7193 Directory management
7252 Directory management
7194 \layout Standard
7253 \layout Standard
7195
7254
7196 Since each command passed by pysh to the underlying system is executed in
7255 Since each command passed by pysh to the underlying system is executed in
7197 a subshell which exits immediately, you can NOT use !cd to navigate the
7256 a subshell which exits immediately, you can NOT use !cd to navigate the
7198 filesystem.
7257 filesystem.
7199 \layout Standard
7258 \layout Standard
7200
7259
7201 Pysh provides its own builtin
7260 Pysh provides its own builtin
7202 \family typewriter
7261 \family typewriter
7203 `%cd
7262 `%cd
7204 \family default
7263 \family default
7205 ' magic command to move in the filesystem (the
7264 ' magic command to move in the filesystem (the
7206 \family typewriter
7265 \family typewriter
7207 %
7266 %
7208 \family default
7267 \family default
7209 is not required with automagic on).
7268 is not required with automagic on).
7210 It also maintains a list of visited directories (use
7269 It also maintains a list of visited directories (use
7211 \family typewriter
7270 \family typewriter
7212 %dhist
7271 %dhist
7213 \family default
7272 \family default
7214 to see it) and allows direct switching to any of them.
7273 to see it) and allows direct switching to any of them.
7215 Type
7274 Type
7216 \family typewriter
7275 \family typewriter
7217 `cd?
7276 `cd?
7218 \family default
7277 \family default
7219 ' for more details.
7278 ' for more details.
7220 \layout Standard
7279 \layout Standard
7221
7280
7222
7281
7223 \family typewriter
7282 \family typewriter
7224 %pushd
7283 %pushd
7225 \family default
7284 \family default
7226 ,
7285 ,
7227 \family typewriter
7286 \family typewriter
7228 %popd
7287 %popd
7229 \family default
7288 \family default
7230 and
7289 and
7231 \family typewriter
7290 \family typewriter
7232 %dirs
7291 %dirs
7233 \family default
7292 \family default
7234 are provided for directory stack handling.
7293 are provided for directory stack handling.
7235 \layout Subsection
7294 \layout Subsection
7236
7295
7237 Prompt customization
7296 Prompt customization
7238 \layout Standard
7297 \layout Standard
7239
7298
7240 The supplied
7299 The supplied
7241 \family typewriter
7300 \family typewriter
7242 ipythonrc-pysh
7301 ipythonrc-pysh
7243 \family default
7302 \family default
7244 profile comes with an example of a very colored and detailed prompt, mainly
7303 profile comes with an example of a very colored and detailed prompt, mainly
7245 to serve as an illustration.
7304 to serve as an illustration.
7246 The valid escape sequences, besides color names, are:
7305 The valid escape sequences, besides color names, are:
7247 \layout Description
7306 \layout Description
7248
7307
7249
7308
7250 \backslash
7309 \backslash
7251 # - Prompt number.
7310 # - Prompt number.
7252 \layout Description
7311 \layout Description
7253
7312
7254
7313
7255 \backslash
7314 \backslash
7256 D - Dots, as many as there are digits in
7315 D - Dots, as many as there are digits in
7257 \backslash
7316 \backslash
7258 # (so they align).
7317 # (so they align).
7259 \layout Description
7318 \layout Description
7260
7319
7261
7320
7262 \backslash
7321 \backslash
7263 w - Current working directory (cwd).
7322 w - Current working directory (cwd).
7264 \layout Description
7323 \layout Description
7265
7324
7266
7325
7267 \backslash
7326 \backslash
7268 W - Basename of current working directory.
7327 W - Basename of current working directory.
7269 \layout Description
7328 \layout Description
7270
7329
7271
7330
7272 \backslash
7331 \backslash
7273 X
7332 X
7274 \emph on
7333 \emph on
7275 N
7334 N
7276 \emph default
7335 \emph default
7277 - Where
7336 - Where
7278 \emph on
7337 \emph on
7279 N
7338 N
7280 \emph default
7339 \emph default
7281 =0..5.
7340 =0..5.
7282 N terms of the cwd, with $HOME written as ~.
7341 N terms of the cwd, with $HOME written as ~.
7283 \layout Description
7342 \layout Description
7284
7343
7285
7344
7286 \backslash
7345 \backslash
7287 Y
7346 Y
7288 \emph on
7347 \emph on
7289 N
7348 N
7290 \emph default
7349 \emph default
7291 - Where
7350 - Where
7292 \emph on
7351 \emph on
7293 N
7352 N
7294 \emph default
7353 \emph default
7295 =0..5.
7354 =0..5.
7296 Like X
7355 Like X
7297 \emph on
7356 \emph on
7298 N
7357 N
7299 \emph default
7358 \emph default
7300 , but if ~ is term
7359 , but if ~ is term
7301 \emph on
7360 \emph on
7302 N
7361 N
7303 \emph default
7362 \emph default
7304 +1 it's also shown.
7363 +1 it's also shown.
7305 \layout Description
7364 \layout Description
7306
7365
7307
7366
7308 \backslash
7367 \backslash
7309 u - Username.
7368 u - Username.
7310 \layout Description
7369 \layout Description
7311
7370
7312
7371
7313 \backslash
7372 \backslash
7314 H - Full hostname.
7373 H - Full hostname.
7315 \layout Description
7374 \layout Description
7316
7375
7317
7376
7318 \backslash
7377 \backslash
7319 h - Hostname up to first '.'
7378 h - Hostname up to first '.'
7320 \layout Description
7379 \layout Description
7321
7380
7322
7381
7323 \backslash
7382 \backslash
7324 $ - Root symbol ($ or #).
7383 $ - Root symbol ($ or #).
7325
7384
7326 \layout Description
7385 \layout Description
7327
7386
7328
7387
7329 \backslash
7388 \backslash
7330 t - Current time, in H:M:S format.
7389 t - Current time, in H:M:S format.
7331 \layout Description
7390 \layout Description
7332
7391
7333
7392
7334 \backslash
7393 \backslash
7335 v - IPython release version.
7394 v - IPython release version.
7336
7395
7337 \layout Description
7396 \layout Description
7338
7397
7339
7398
7340 \backslash
7399 \backslash
7341 n - Newline.
7400 n - Newline.
7342
7401
7343 \layout Description
7402 \layout Description
7344
7403
7345
7404
7346 \backslash
7405 \backslash
7347 r - Carriage return.
7406 r - Carriage return.
7348
7407
7349 \layout Description
7408 \layout Description
7350
7409
7351
7410
7352 \backslash
7411 \backslash
7353
7412
7354 \backslash
7413 \backslash
7355 - An explicitly escaped '
7414 - An explicitly escaped '
7356 \backslash
7415 \backslash
7357 '.
7416 '.
7358 \layout Standard
7417 \layout Standard
7359
7418
7360 You can configure your prompt colors using any ANSI color escape.
7419 You can configure your prompt colors using any ANSI color escape.
7361 Each color escape sets the color for any subsequent text, until another
7420 Each color escape sets the color for any subsequent text, until another
7362 escape comes in and changes things.
7421 escape comes in and changes things.
7363 The valid color escapes are:
7422 The valid color escapes are:
7364 \layout Description
7423 \layout Description
7365
7424
7366
7425
7367 \backslash
7426 \backslash
7368 C_Black
7427 C_Black
7369 \layout Description
7428 \layout Description
7370
7429
7371
7430
7372 \backslash
7431 \backslash
7373 C_Blue
7432 C_Blue
7374 \layout Description
7433 \layout Description
7375
7434
7376
7435
7377 \backslash
7436 \backslash
7378 C_Brown
7437 C_Brown
7379 \layout Description
7438 \layout Description
7380
7439
7381
7440
7382 \backslash
7441 \backslash
7383 C_Cyan
7442 C_Cyan
7384 \layout Description
7443 \layout Description
7385
7444
7386
7445
7387 \backslash
7446 \backslash
7388 C_DarkGray
7447 C_DarkGray
7389 \layout Description
7448 \layout Description
7390
7449
7391
7450
7392 \backslash
7451 \backslash
7393 C_Green
7452 C_Green
7394 \layout Description
7453 \layout Description
7395
7454
7396
7455
7397 \backslash
7456 \backslash
7398 C_LightBlue
7457 C_LightBlue
7399 \layout Description
7458 \layout Description
7400
7459
7401
7460
7402 \backslash
7461 \backslash
7403 C_LightCyan
7462 C_LightCyan
7404 \layout Description
7463 \layout Description
7405
7464
7406
7465
7407 \backslash
7466 \backslash
7408 C_LightGray
7467 C_LightGray
7409 \layout Description
7468 \layout Description
7410
7469
7411
7470
7412 \backslash
7471 \backslash
7413 C_LightGreen
7472 C_LightGreen
7414 \layout Description
7473 \layout Description
7415
7474
7416
7475
7417 \backslash
7476 \backslash
7418 C_LightPurple
7477 C_LightPurple
7419 \layout Description
7478 \layout Description
7420
7479
7421
7480
7422 \backslash
7481 \backslash
7423 C_LightRed
7482 C_LightRed
7424 \layout Description
7483 \layout Description
7425
7484
7426
7485
7427 \backslash
7486 \backslash
7428 C_Purple
7487 C_Purple
7429 \layout Description
7488 \layout Description
7430
7489
7431
7490
7432 \backslash
7491 \backslash
7433 C_Red
7492 C_Red
7434 \layout Description
7493 \layout Description
7435
7494
7436
7495
7437 \backslash
7496 \backslash
7438 C_White
7497 C_White
7439 \layout Description
7498 \layout Description
7440
7499
7441
7500
7442 \backslash
7501 \backslash
7443 C_Yellow
7502 C_Yellow
7444 \layout Description
7503 \layout Description
7445
7504
7446
7505
7447 \backslash
7506 \backslash
7448 C_Normal Stop coloring, defaults to your terminal settings.
7507 C_Normal Stop coloring, defaults to your terminal settings.
7449 \layout Section
7508 \layout Section
7450
7509
7451
7510
7452 \begin_inset LatexCommand \label{sec:Threading-support}
7511 \begin_inset LatexCommand \label{sec:Threading-support}
7453
7512
7454 \end_inset
7513 \end_inset
7455
7514
7456 Threading support
7515 Threading support
7457 \layout Standard
7516 \layout Standard
7458
7517
7459
7518
7460 \series bold
7519 \series bold
7461 WARNING:
7520 WARNING:
7462 \series default
7521 \series default
7463 The threading support is still somewhat experimental, and it has only seen
7522 The threading support is still somewhat experimental, and it has only seen
7464 reasonable testing under Linux.
7523 reasonable testing under Linux.
7465 Threaded code is particularly tricky to debug, and it tends to show extremely
7524 Threaded code is particularly tricky to debug, and it tends to show extremely
7466 platform-dependent behavior.
7525 platform-dependent behavior.
7467 Since I only have access to Linux machines, I will have to rely on user's
7526 Since I only have access to Linux machines, I will have to rely on user's
7468 experiences and assistance for this area of IPython to improve under other
7527 experiences and assistance for this area of IPython to improve under other
7469 platforms.
7528 platforms.
7470 \layout Standard
7529 \layout Standard
7471
7530
7472 IPython, via the
7531 IPython, via the
7473 \family typewriter
7532 \family typewriter
7474 -gthread
7533 -gthread
7475 \family default
7534 \family default
7476 and
7535 and
7477 \family typewriter
7536 \family typewriter
7478 -wthread
7537 -wthread
7479 \family default
7538 \family default
7480 options (described in Sec.\SpecialChar ~
7539 options (described in Sec.\SpecialChar ~
7481
7540
7482 \begin_inset LatexCommand \ref{sec:threading-opts}
7541 \begin_inset LatexCommand \ref{sec:threading-opts}
7483
7542
7484 \end_inset
7543 \end_inset
7485
7544
7486 ), can run in multithreaded mode to support pyGTK and WXPython applications
7545 ), can run in multithreaded mode to support pyGTK and WXPython applications
7487 respectively.
7546 respectively.
7488 Both of these GUI toolkits need to control the python main loop of execution,
7547 Both of these GUI toolkits need to control the python main loop of execution,
7489 so under a normal Python interpreter, starting a pyGTK (or WXPython) applicatio
7548 so under a normal Python interpreter, starting a pyGTK (or WXPython) applicatio
7490 n will immediately freeze the shell.
7549 n will immediately freeze the shell.
7491
7550
7492 \layout Standard
7551 \layout Standard
7493
7552
7494 IPython, with one of these options (you can only use one at a time), separates
7553 IPython, with one of these options (you can only use one at a time), separates
7495 the graphical loop and IPython's code execution run into different threads.
7554 the graphical loop and IPython's code execution run into different threads.
7496 This allows you to test interactively (with
7555 This allows you to test interactively (with
7497 \family typewriter
7556 \family typewriter
7498 %run
7557 %run
7499 \family default
7558 \family default
7500 , for example) your GUI code without blocking.
7559 , for example) your GUI code without blocking.
7501 \layout Subsection
7560 \layout Subsection
7502
7561
7503 Tk issues
7562 Tk issues
7504 \layout Standard
7563 \layout Standard
7505
7564
7506 As indicated in Sec.\SpecialChar ~
7565 As indicated in Sec.\SpecialChar ~
7507
7566
7508 \begin_inset LatexCommand \ref{sec:threading-opts}
7567 \begin_inset LatexCommand \ref{sec:threading-opts}
7509
7568
7510 \end_inset
7569 \end_inset
7511
7570
7512 , a special
7571 , a special
7513 \family typewriter
7572 \family typewriter
7514 -tk
7573 -tk
7515 \family default
7574 \family default
7516 option is provided to try and allow Tk graphical applications to coexist
7575 option is provided to try and allow Tk graphical applications to coexist
7517 interactively with WX or GTK ones.
7576 interactively with WX or GTK ones.
7518 Whether this works at all, however, is very platform and configuration
7577 Whether this works at all, however, is very platform and configuration
7519 dependent.
7578 dependent.
7520 Please experiment with simple test cases before committing to using this
7579 Please experiment with simple test cases before committing to using this
7521 combination of Tk and WX/GTK threading in a production environment.
7580 combination of Tk and WX/GTK threading in a production environment.
7522 \layout Subsection
7581 \layout Subsection
7523
7582
7524 Signals and Threads
7583 Signals and Threads
7525 \layout Standard
7584 \layout Standard
7526
7585
7527 When any of the thread systems (WX or GTK) are active, either directly or
7586 When any of the thread systems (WX or GTK) are active, either directly or
7528 via
7587 via
7529 \family typewriter
7588 \family typewriter
7530 -pylab
7589 -pylab
7531 \family default
7590 \family default
7532 with a threaded backend, it is impossible to interrupt long-running Python
7591 with a threaded backend, it is impossible to interrupt long-running Python
7533 code via
7592 code via
7534 \family typewriter
7593 \family typewriter
7535 Ctrl-C
7594 Ctrl-C
7536 \family default
7595 \family default
7537 .
7596 .
7538 IPython can not pass the KeyboardInterrupt exception (or the underlying
7597 IPython can not pass the KeyboardInterrupt exception (or the underlying
7539
7598
7540 \family typewriter
7599 \family typewriter
7541 SIGINT
7600 SIGINT
7542 \family default
7601 \family default
7543 ) across threads, so any long-running process started from IPython will
7602 ) across threads, so any long-running process started from IPython will
7544 run to completion, or will have to be killed via an external (OS-based)
7603 run to completion, or will have to be killed via an external (OS-based)
7545 mechanism.
7604 mechanism.
7546 \layout Standard
7605 \layout Standard
7547
7606
7548 To the best of my knowledge, this limitation is imposed by the Python interprete
7607 To the best of my knowledge, this limitation is imposed by the Python interprete
7549 r itself, and it comes from the difficulty of writing portable signal/threaded
7608 r itself, and it comes from the difficulty of writing portable signal/threaded
7550 code.
7609 code.
7551 If any user is an expert on this topic and can suggest a better solution,
7610 If any user is an expert on this topic and can suggest a better solution,
7552 I would love to hear about it.
7611 I would love to hear about it.
7553 In the IPython sources, look at the
7612 In the IPython sources, look at the
7554 \family typewriter
7613 \family typewriter
7555 Shell.py
7614 Shell.py
7556 \family default
7615 \family default
7557 module, and in particular at the
7616 module, and in particular at the
7558 \family typewriter
7617 \family typewriter
7559 runcode()
7618 runcode()
7560 \family default
7619 \family default
7561 method.
7620 method.
7562
7621
7563 \layout Subsection
7622 \layout Subsection
7564
7623
7565 I/O pitfalls
7624 I/O pitfalls
7566 \layout Standard
7625 \layout Standard
7567
7626
7568 Be mindful that the Python interpreter switches between threads every
7627 Be mindful that the Python interpreter switches between threads every
7569 \begin_inset Formula $N$
7628 \begin_inset Formula $N$
7570 \end_inset
7629 \end_inset
7571
7630
7572 bytecodes, where the default value as of Python\SpecialChar ~
7631 bytecodes, where the default value as of Python\SpecialChar ~
7573 2.3 is
7632 2.3 is
7574 \begin_inset Formula $N=100.$
7633 \begin_inset Formula $N=100.$
7575 \end_inset
7634 \end_inset
7576
7635
7577 This value can be read by using the
7636 This value can be read by using the
7578 \family typewriter
7637 \family typewriter
7579 sys.getcheckinterval()
7638 sys.getcheckinterval()
7580 \family default
7639 \family default
7581 function, and it can be reset via
7640 function, and it can be reset via
7582 \family typewriter
7641 \family typewriter
7583 sys.setcheckinterval(
7642 sys.setcheckinterval(
7584 \emph on
7643 \emph on
7585 N
7644 N
7586 \emph default
7645 \emph default
7587 )
7646 )
7588 \family default
7647 \family default
7589 .
7648 .
7590 This switching of threads can cause subtly confusing effects if one of
7649 This switching of threads can cause subtly confusing effects if one of
7591 your threads is doing file I/O.
7650 your threads is doing file I/O.
7592 In text mode, most systems only flush file buffers when they encounter
7651 In text mode, most systems only flush file buffers when they encounter
7593 a
7652 a
7594 \family typewriter
7653 \family typewriter
7595 `
7654 `
7596 \backslash
7655 \backslash
7597 n'
7656 n'
7598 \family default
7657 \family default
7599 .
7658 .
7600 An instruction as simple as
7659 An instruction as simple as
7601 \family typewriter
7660 \family typewriter
7602
7661
7603 \newline
7662 \newline
7604 \SpecialChar ~
7663 \SpecialChar ~
7605 \SpecialChar ~
7664 \SpecialChar ~
7606 print >> filehandle,
7665 print >> filehandle,
7607 \begin_inset Quotes eld
7666 \begin_inset Quotes eld
7608 \end_inset
7667 \end_inset
7609
7668
7610 hello world
7669 hello world
7611 \begin_inset Quotes erd
7670 \begin_inset Quotes erd
7612 \end_inset
7671 \end_inset
7613
7672
7614
7673
7615 \family default
7674 \family default
7616
7675
7617 \newline
7676 \newline
7618 actually consists of several bytecodes, so it is possible that the newline
7677 actually consists of several bytecodes, so it is possible that the newline
7619 does not reach your file before the next thread switch.
7678 does not reach your file before the next thread switch.
7620 Similarly, if you are writing to a file in binary mode, the file won't
7679 Similarly, if you are writing to a file in binary mode, the file won't
7621 be flushed until the buffer fills, and your other thread may see apparently
7680 be flushed until the buffer fills, and your other thread may see apparently
7622 truncated files.
7681 truncated files.
7623
7682
7624 \layout Standard
7683 \layout Standard
7625
7684
7626 For this reason, if you are using IPython's thread support and have (for
7685 For this reason, if you are using IPython's thread support and have (for
7627 example) a GUI application which will read data generated by files written
7686 example) a GUI application which will read data generated by files written
7628 to from the IPython thread, the safest approach is to open all of your
7687 to from the IPython thread, the safest approach is to open all of your
7629 files in unbuffered mode (the third argument to the
7688 files in unbuffered mode (the third argument to the
7630 \family typewriter
7689 \family typewriter
7631 file/open
7690 file/open
7632 \family default
7691 \family default
7633 function is the buffering value):
7692 function is the buffering value):
7634 \newline
7693 \newline
7635
7694
7636 \family typewriter
7695 \family typewriter
7637 \SpecialChar ~
7696 \SpecialChar ~
7638 \SpecialChar ~
7697 \SpecialChar ~
7639 filehandle = open(filename,mode,0)
7698 filehandle = open(filename,mode,0)
7640 \layout Standard
7699 \layout Standard
7641
7700
7642 This is obviously a brute force way of avoiding race conditions with the
7701 This is obviously a brute force way of avoiding race conditions with the
7643 file buffering.
7702 file buffering.
7644 If you want to do it cleanly, and you have a resource which is being shared
7703 If you want to do it cleanly, and you have a resource which is being shared
7645 by the interactive IPython loop and your GUI thread, you should really
7704 by the interactive IPython loop and your GUI thread, you should really
7646 handle it with thread locking and syncrhonization properties.
7705 handle it with thread locking and syncrhonization properties.
7647 The Python documentation discusses these.
7706 The Python documentation discusses these.
7648 \layout Section
7707 \layout Section
7649
7708
7650
7709
7710 \begin_inset LatexCommand \label{sec:interactive-demos}
7711
7712 \end_inset
7713
7714 Interactive demos with IPython
7715 \layout Standard
7716
7717 IPython ships with
7718 \layout Standard
7719
7720
7721 \begin_inset ERT
7722 status Open
7723
7724 \layout Standard
7725
7726 \backslash
7727 lstinputlisting{examples/example-demo.py}
7728 \end_inset
7729
7730
7731 \layout Section
7732
7733
7651 \begin_inset LatexCommand \label{sec:matplotlib-support}
7734 \begin_inset LatexCommand \label{sec:matplotlib-support}
7652
7735
7653 \end_inset
7736 \end_inset
7654
7737
7655 Plotting with
7738 Plotting with
7656 \family typewriter
7739 \family typewriter
7657 matplotlib
7740 matplotlib
7658 \family default
7741 \family default
7659
7742
7660 \layout Standard
7743 \layout Standard
7661
7744
7662 The matplotlib library (
7745 The matplotlib library (
7663 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
7746 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
7664
7747
7665 \end_inset
7748 \end_inset
7666
7749
7667 ) provides high quality 2D plotting for Python.
7750 ) provides high quality 2D plotting for Python.
7668 Matplotlib can produce plots on screen using a variety of GUI toolkits,
7751 Matplotlib can produce plots on screen using a variety of GUI toolkits,
7669 including Tk, GTK and WXPython.
7752 including Tk, GTK and WXPython.
7670 It also provides a number of commands useful for scientific computing,
7753 It also provides a number of commands useful for scientific computing,
7671 all with a syntax compatible with that of the popular Matlab program.
7754 all with a syntax compatible with that of the popular Matlab program.
7672 \layout Standard
7755 \layout Standard
7673
7756
7674 IPython accepts the special option
7757 IPython accepts the special option
7675 \family typewriter
7758 \family typewriter
7676 -pylab
7759 -pylab
7677 \family default
7760 \family default
7678 (Sec.\SpecialChar ~
7761 (Sec.\SpecialChar ~
7679
7762
7680 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
7763 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
7681
7764
7682 \end_inset
7765 \end_inset
7683
7766
7684 ).
7767 ).
7685 This configures it to support matplotlib, honoring the settings in the
7768 This configures it to support matplotlib, honoring the settings in the
7686
7769
7687 \family typewriter
7770 \family typewriter
7688 .matplotlibrc
7771 .matplotlibrc
7689 \family default
7772 \family default
7690 file.
7773 file.
7691 IPython will detect the user's choice of matplotlib GUI backend, and automatica
7774 IPython will detect the user's choice of matplotlib GUI backend, and automatica
7692 lly select the proper threading model to prevent blocking.
7775 lly select the proper threading model to prevent blocking.
7693 It also sets matplotlib in interactive mode and modifies
7776 It also sets matplotlib in interactive mode and modifies
7694 \family typewriter
7777 \family typewriter
7695 %run
7778 %run
7696 \family default
7779 \family default
7697 slightly, so that any matplotlib-based script can be executed using
7780 slightly, so that any matplotlib-based script can be executed using
7698 \family typewriter
7781 \family typewriter
7699 %run
7782 %run
7700 \family default
7783 \family default
7701 and the final
7784 and the final
7702 \family typewriter
7785 \family typewriter
7703 show()
7786 show()
7704 \family default
7787 \family default
7705 command does not block the interactive shell.
7788 command does not block the interactive shell.
7706 \layout Standard
7789 \layout Standard
7707
7790
7708 The
7791 The
7709 \family typewriter
7792 \family typewriter
7710 -pylab
7793 -pylab
7711 \family default
7794 \family default
7712 option must be given first in order for IPython to configure its threading
7795 option must be given first in order for IPython to configure its threading
7713 mode.
7796 mode.
7714 However, you can still issue other options afterwards.
7797 However, you can still issue other options afterwards.
7715 This allows you to have a matplotlib-based environment customized with
7798 This allows you to have a matplotlib-based environment customized with
7716 additional modules using the standard IPython profile mechanism (Sec.\SpecialChar ~
7799 additional modules using the standard IPython profile mechanism (Sec.\SpecialChar ~
7717
7800
7718 \begin_inset LatexCommand \ref{sec:profiles}
7801 \begin_inset LatexCommand \ref{sec:profiles}
7719
7802
7720 \end_inset
7803 \end_inset
7721
7804
7722 ): ``
7805 ): ``
7723 \family typewriter
7806 \family typewriter
7724 ipython -pylab -p myprofile
7807 ipython -pylab -p myprofile
7725 \family default
7808 \family default
7726 '' will load the profile defined in
7809 '' will load the profile defined in
7727 \family typewriter
7810 \family typewriter
7728 ipythonrc-myprofile
7811 ipythonrc-myprofile
7729 \family default
7812 \family default
7730 after configuring matplotlib.
7813 after configuring matplotlib.
7731 \layout Section
7814 \layout Section
7732
7815
7733
7816
7734 \begin_inset LatexCommand \label{sec:Gnuplot}
7817 \begin_inset LatexCommand \label{sec:Gnuplot}
7735
7818
7736 \end_inset
7819 \end_inset
7737
7820
7738 Plotting with
7821 Plotting with
7739 \family typewriter
7822 \family typewriter
7740 Gnuplot
7823 Gnuplot
7741 \layout Standard
7824 \layout Standard
7742
7825
7743 Through the magic extension system described in sec.
7826 Through the magic extension system described in sec.
7744
7827
7745 \begin_inset LatexCommand \ref{sec:magic}
7828 \begin_inset LatexCommand \ref{sec:magic}
7746
7829
7747 \end_inset
7830 \end_inset
7748
7831
7749 , IPython incorporates a mechanism for conveniently interfacing with the
7832 , IPython incorporates a mechanism for conveniently interfacing with the
7750 Gnuplot system (
7833 Gnuplot system (
7751 \begin_inset LatexCommand \htmlurl{http://www.gnuplot.info}
7834 \begin_inset LatexCommand \htmlurl{http://www.gnuplot.info}
7752
7835
7753 \end_inset
7836 \end_inset
7754
7837
7755 ).
7838 ).
7756 Gnuplot is a very complete 2D and 3D plotting package available for many
7839 Gnuplot is a very complete 2D and 3D plotting package available for many
7757 operating systems and commonly included in modern Linux distributions.
7840 operating systems and commonly included in modern Linux distributions.
7758
7841
7759 \layout Standard
7842 \layout Standard
7760
7843
7761 Besides having Gnuplot installed, this functionality requires the
7844 Besides having Gnuplot installed, this functionality requires the
7762 \family typewriter
7845 \family typewriter
7763 Gnuplot.py
7846 Gnuplot.py
7764 \family default
7847 \family default
7765 module for interfacing python with Gnuplot.
7848 module for interfacing python with Gnuplot.
7766 It can be downloaded from:
7849 It can be downloaded from:
7767 \begin_inset LatexCommand \htmlurl{http://gnuplot-py.sourceforge.net}
7850 \begin_inset LatexCommand \htmlurl{http://gnuplot-py.sourceforge.net}
7768
7851
7769 \end_inset
7852 \end_inset
7770
7853
7771 .
7854 .
7772 \layout Subsection
7855 \layout Subsection
7773
7856
7774 Proper Gnuplot configuration
7857 Proper Gnuplot configuration
7775 \layout Standard
7858 \layout Standard
7776
7859
7777 As of version 4.0, Gnuplot has excellent mouse and interactive keyboard support.
7860 As of version 4.0, Gnuplot has excellent mouse and interactive keyboard support.
7778 However, as of
7861 However, as of
7779 \family typewriter
7862 \family typewriter
7780 Gnuplot.py
7863 Gnuplot.py
7781 \family default
7864 \family default
7782 version 1.7, a new option was added to communicate between Python and Gnuplot
7865 version 1.7, a new option was added to communicate between Python and Gnuplot
7783 via FIFOs (pipes).
7866 via FIFOs (pipes).
7784 This mechanism, while fast, also breaks the mouse system.
7867 This mechanism, while fast, also breaks the mouse system.
7785 You must therefore set the variable
7868 You must therefore set the variable
7786 \family typewriter
7869 \family typewriter
7787 prefer_fifo_data
7870 prefer_fifo_data
7788 \family default
7871 \family default
7789 to
7872 to
7790 \family typewriter
7873 \family typewriter
7791 0
7874 0
7792 \family default
7875 \family default
7793 in file
7876 in file
7794 \family typewriter
7877 \family typewriter
7795 gp_unix.py
7878 gp_unix.py
7796 \family default
7879 \family default
7797 if you wish to keep the interactive mouse and keyboard features working
7880 if you wish to keep the interactive mouse and keyboard features working
7798 properly (
7881 properly (
7799 \family typewriter
7882 \family typewriter
7800 prefer_inline_data
7883 prefer_inline_data
7801 \family default
7884 \family default
7802 also must be
7885 also must be
7803 \family typewriter
7886 \family typewriter
7804 0
7887 0
7805 \family default
7888 \family default
7806 , but this is the default so unless you've changed it manually you should
7889 , but this is the default so unless you've changed it manually you should
7807 be fine).
7890 be fine).
7808 \layout Standard
7891 \layout Standard
7809
7892
7810 'Out of the box', Gnuplot is configured with a rather poor set of size,
7893 'Out of the box', Gnuplot is configured with a rather poor set of size,
7811 color and linewidth choices which make the graphs fairly hard to read on
7894 color and linewidth choices which make the graphs fairly hard to read on
7812 modern high-resolution displays (although they work fine on old 640x480
7895 modern high-resolution displays (although they work fine on old 640x480
7813 ones).
7896 ones).
7814 Below is a section of my
7897 Below is a section of my
7815 \family typewriter
7898 \family typewriter
7816 .Xdefaults
7899 .Xdefaults
7817 \family default
7900 \family default
7818 file which I use for having a more convenient Gnuplot setup.
7901 file which I use for having a more convenient Gnuplot setup.
7819 Remember to load it by running
7902 Remember to load it by running
7820 \family typewriter
7903 \family typewriter
7821 `xrdb .Xdefaults`
7904 `xrdb .Xdefaults`
7822 \family default
7905 \family default
7823 :
7906 :
7824 \layout Standard
7907 \layout Standard
7825
7908
7826
7909
7827 \family typewriter
7910 \family typewriter
7828 !******************************************************************
7911 !******************************************************************
7829 \newline
7912 \newline
7830 ! gnuplot options
7913 ! gnuplot options
7831 \newline
7914 \newline
7832 ! modify this for a convenient window size
7915 ! modify this for a convenient window size
7833 \newline
7916 \newline
7834 gnuplot*geometry: 780x580
7917 gnuplot*geometry: 780x580
7835 \layout Standard
7918 \layout Standard
7836
7919
7837
7920
7838 \family typewriter
7921 \family typewriter
7839 ! on-screen font (not for PostScript)
7922 ! on-screen font (not for PostScript)
7840 \newline
7923 \newline
7841 gnuplot*font: -misc-fixed-bold-r-normal--15-120-100-100-c-90-iso8859-1
7924 gnuplot*font: -misc-fixed-bold-r-normal--15-120-100-100-c-90-iso8859-1
7842 \layout Standard
7925 \layout Standard
7843
7926
7844
7927
7845 \family typewriter
7928 \family typewriter
7846 ! color options
7929 ! color options
7847 \newline
7930 \newline
7848 gnuplot*background: black
7931 gnuplot*background: black
7849 \newline
7932 \newline
7850 gnuplot*textColor: white
7933 gnuplot*textColor: white
7851 \newline
7934 \newline
7852 gnuplot*borderColor: white
7935 gnuplot*borderColor: white
7853 \newline
7936 \newline
7854 gnuplot*axisColor: white
7937 gnuplot*axisColor: white
7855 \newline
7938 \newline
7856 gnuplot*line1Color: red
7939 gnuplot*line1Color: red
7857 \newline
7940 \newline
7858 gnuplot*line2Color: green
7941 gnuplot*line2Color: green
7859 \newline
7942 \newline
7860 gnuplot*line3Color: blue
7943 gnuplot*line3Color: blue
7861 \newline
7944 \newline
7862 gnuplot*line4Color: magenta
7945 gnuplot*line4Color: magenta
7863 \newline
7946 \newline
7864 gnuplot*line5Color: cyan
7947 gnuplot*line5Color: cyan
7865 \newline
7948 \newline
7866 gnuplot*line6Color: sienna
7949 gnuplot*line6Color: sienna
7867 \newline
7950 \newline
7868 gnuplot*line7Color: orange
7951 gnuplot*line7Color: orange
7869 \newline
7952 \newline
7870 gnuplot*line8Color: coral
7953 gnuplot*line8Color: coral
7871 \layout Standard
7954 \layout Standard
7872
7955
7873
7956
7874 \family typewriter
7957 \family typewriter
7875 ! multiplicative factor for point styles
7958 ! multiplicative factor for point styles
7876 \newline
7959 \newline
7877 gnuplot*pointsize: 2
7960 gnuplot*pointsize: 2
7878 \layout Standard
7961 \layout Standard
7879
7962
7880
7963
7881 \family typewriter
7964 \family typewriter
7882 ! line width options (in pixels)
7965 ! line width options (in pixels)
7883 \newline
7966 \newline
7884 gnuplot*borderWidth: 2
7967 gnuplot*borderWidth: 2
7885 \newline
7968 \newline
7886 gnuplot*axisWidth: 2
7969 gnuplot*axisWidth: 2
7887 \newline
7970 \newline
7888 gnuplot*line1Width: 2
7971 gnuplot*line1Width: 2
7889 \newline
7972 \newline
7890 gnuplot*line2Width: 2
7973 gnuplot*line2Width: 2
7891 \newline
7974 \newline
7892 gnuplot*line3Width: 2
7975 gnuplot*line3Width: 2
7893 \newline
7976 \newline
7894 gnuplot*line4Width: 2
7977 gnuplot*line4Width: 2
7895 \newline
7978 \newline
7896 gnuplot*line5Width: 2
7979 gnuplot*line5Width: 2
7897 \newline
7980 \newline
7898 gnuplot*line6Width: 2
7981 gnuplot*line6Width: 2
7899 \newline
7982 \newline
7900 gnuplot*line7Width: 2
7983 gnuplot*line7Width: 2
7901 \newline
7984 \newline
7902 gnuplot*line8Width: 2
7985 gnuplot*line8Width: 2
7903 \layout Subsection
7986 \layout Subsection
7904
7987
7905 The
7988 The
7906 \family typewriter
7989 \family typewriter
7907 IPython.GnuplotRuntime
7990 IPython.GnuplotRuntime
7908 \family default
7991 \family default
7909 module
7992 module
7910 \layout Standard
7993 \layout Standard
7911
7994
7912 IPython includes a module called
7995 IPython includes a module called
7913 \family typewriter
7996 \family typewriter
7914 Gnuplot2.py
7997 Gnuplot2.py
7915 \family default
7998 \family default
7916 which extends and improves the default
7999 which extends and improves the default
7917 \family typewriter
8000 \family typewriter
7918 Gnuplot
8001 Gnuplot
7919 \family default
8002 \family default
7920 .
8003 .
7921 \family typewriter
8004 \family typewriter
7922 py
8005 py
7923 \family default
8006 \family default
7924 (which it still relies upon).
8007 (which it still relies upon).
7925 For example, the new
8008 For example, the new
7926 \family typewriter
8009 \family typewriter
7927 plot
8010 plot
7928 \family default
8011 \family default
7929 function adds several improvements to the original making it more convenient
8012 function adds several improvements to the original making it more convenient
7930 for interactive use, and
8013 for interactive use, and
7931 \family typewriter
8014 \family typewriter
7932 hardcopy
8015 hardcopy
7933 \family default
8016 \family default
7934 fixes a bug in the original which under some circumstances blocks the creation
8017 fixes a bug in the original which under some circumstances blocks the creation
7935 of PostScript output.
8018 of PostScript output.
7936 \layout Standard
8019 \layout Standard
7937
8020
7938 For scripting use,
8021 For scripting use,
7939 \family typewriter
8022 \family typewriter
7940 GnuplotRuntime.py
8023 GnuplotRuntime.py
7941 \family default
8024 \family default
7942 is provided, which wraps
8025 is provided, which wraps
7943 \family typewriter
8026 \family typewriter
7944 Gnuplot2.py
8027 Gnuplot2.py
7945 \family default
8028 \family default
7946 and creates a series of global aliases.
8029 and creates a series of global aliases.
7947 These make it easy to control Gnuplot plotting jobs through the Python
8030 These make it easy to control Gnuplot plotting jobs through the Python
7948 language.
8031 language.
7949 \layout Standard
8032 \layout Standard
7950
8033
7951 Below is some example code which illustrates how to configure Gnuplot inside
8034 Below is some example code which illustrates how to configure Gnuplot inside
7952 your own programs but have it available for further interactive use through
8035 your own programs but have it available for further interactive use through
7953 an embedded IPython instance.
8036 an embedded IPython instance.
7954 Simply run this file at a system prompt.
8037 Simply run this file at a system prompt.
7955 This file is provided as
8038 This file is provided as
7956 \family typewriter
8039 \family typewriter
7957 example-gnuplot.py
8040 example-gnuplot.py
7958 \family default
8041 \family default
7959 in the examples directory:
8042 in the examples directory:
7960 \layout Standard
8043 \layout Standard
7961
8044
7962
8045
7963 \begin_inset Include \verbatiminput{examples/example-gnuplot.py}
8046 \begin_inset ERT
7964 preview false
8047 status Open
7965
8048
8049 \layout Standard
8050
8051 \backslash
8052 lstinputlisting{examples/example-gnuplot.py}
7966 \end_inset
8053 \end_inset
7967
8054
7968
8055
7969 \layout Subsection
8056 \layout Subsection
7970
8057
7971 The
8058 The
7972 \family typewriter
8059 \family typewriter
7973 numeric
8060 numeric
7974 \family default
8061 \family default
7975 profile: a scientific computing environment
8062 profile: a scientific computing environment
7976 \layout Standard
8063 \layout Standard
7977
8064
7978 The
8065 The
7979 \family typewriter
8066 \family typewriter
7980 numeric
8067 numeric
7981 \family default
8068 \family default
7982 IPython profile, which you can activate with
8069 IPython profile, which you can activate with
7983 \family typewriter
8070 \family typewriter
7984 `ipython -p numeric
8071 `ipython -p numeric
7985 \family default
8072 \family default
7986 ' will automatically load the IPython Gnuplot extensions (plus Numeric and
8073 ' will automatically load the IPython Gnuplot extensions (plus Numeric and
7987 other useful things for numerical computing), contained in the
8074 other useful things for numerical computing), contained in the
7988 \family typewriter
8075 \family typewriter
7989 IPython.GnuplotInteractive
8076 IPython.GnuplotInteractive
7990 \family default
8077 \family default
7991 module.
8078 module.
7992 This will create the globals
8079 This will create the globals
7993 \family typewriter
8080 \family typewriter
7994 Gnuplot
8081 Gnuplot
7995 \family default
8082 \family default
7996 (an alias to the improved Gnuplot2 module),
8083 (an alias to the improved Gnuplot2 module),
7997 \family typewriter
8084 \family typewriter
7998 gp
8085 gp
7999 \family default
8086 \family default
8000 (a Gnuplot active instance), the new magic commands
8087 (a Gnuplot active instance), the new magic commands
8001 \family typewriter
8088 \family typewriter
8002 %gpc
8089 %gpc
8003 \family default
8090 \family default
8004 and
8091 and
8005 \family typewriter
8092 \family typewriter
8006 %gp_set_instance
8093 %gp_set_instance
8007 \family default
8094 \family default
8008 and several other convenient globals.
8095 and several other convenient globals.
8009 Type
8096 Type
8010 \family typewriter
8097 \family typewriter
8011 gphelp()
8098 gphelp()
8012 \family default
8099 \family default
8013 for further details.
8100 for further details.
8014 \layout Standard
8101 \layout Standard
8015
8102
8016 This should turn IPython into a convenient environment for numerical computing,
8103 This should turn IPython into a convenient environment for numerical computing,
8017 with all the functions in the NumPy library and the Gnuplot facilities
8104 with all the functions in the NumPy library and the Gnuplot facilities
8018 for plotting.
8105 for plotting.
8019 Further improvements can be obtained by loading the SciPy libraries for
8106 Further improvements can be obtained by loading the SciPy libraries for
8020 scientific computing, available at
8107 scientific computing, available at
8021 \begin_inset LatexCommand \htmlurl{http://scipy.org}
8108 \begin_inset LatexCommand \htmlurl{http://scipy.org}
8022
8109
8023 \end_inset
8110 \end_inset
8024
8111
8025 .
8112 .
8026 \layout Standard
8113 \layout Standard
8027
8114
8028 If you are in the middle of a working session with numerical objects and
8115 If you are in the middle of a working session with numerical objects and
8029 need to plot them but you didn't start the
8116 need to plot them but you didn't start the
8030 \family typewriter
8117 \family typewriter
8031 numeric
8118 numeric
8032 \family default
8119 \family default
8033 profile, you can load these extensions at any time by typing
8120 profile, you can load these extensions at any time by typing
8034 \newline
8121 \newline
8035
8122
8036 \family typewriter
8123 \family typewriter
8037 from IPython.GnuplotInteractive import *
8124 from IPython.GnuplotInteractive import *
8038 \newline
8125 \newline
8039
8126
8040 \family default
8127 \family default
8041 at the IPython prompt.
8128 at the IPython prompt.
8042 This will allow you to keep your objects intact and start using Gnuplot
8129 This will allow you to keep your objects intact and start using Gnuplot
8043 to view them.
8130 to view them.
8044 \layout Section
8131 \layout Section
8045
8132
8046 Reporting bugs
8133 Reporting bugs
8047 \layout Subsection*
8134 \layout Subsection*
8048
8135
8049 Automatic crash reports
8136 Automatic crash reports
8050 \layout Standard
8137 \layout Standard
8051
8138
8052 Ideally, IPython itself shouldn't crash.
8139 Ideally, IPython itself shouldn't crash.
8053 It will catch exceptions produced by you, but bugs in its internals will
8140 It will catch exceptions produced by you, but bugs in its internals will
8054 still crash it.
8141 still crash it.
8055 \layout Standard
8142 \layout Standard
8056
8143
8057 In such a situation, IPython will leave a file named
8144 In such a situation, IPython will leave a file named
8058 \family typewriter
8145 \family typewriter
8059 IPython_crash_report.txt
8146 IPython_crash_report.txt
8060 \family default
8147 \family default
8061 in your IPYTHONDIR directory (that way if crashes happen several times
8148 in your IPYTHONDIR directory (that way if crashes happen several times
8062 it won't litter many directories, the post-mortem file is always located
8149 it won't litter many directories, the post-mortem file is always located
8063 in the same place and new occurrences just overwrite the previous one).
8150 in the same place and new occurrences just overwrite the previous one).
8064 If you can mail this file to the developers (see sec.
8151 If you can mail this file to the developers (see sec.
8065
8152
8066 \begin_inset LatexCommand \ref{sec:credits}
8153 \begin_inset LatexCommand \ref{sec:credits}
8067
8154
8068 \end_inset
8155 \end_inset
8069
8156
8070 for names and addresses), it will help us
8157 for names and addresses), it will help us
8071 \emph on
8158 \emph on
8072 a lot
8159 a lot
8073 \emph default
8160 \emph default
8074 in understanding the cause of the problem and fixing it sooner.
8161 in understanding the cause of the problem and fixing it sooner.
8075 \layout Subsection*
8162 \layout Subsection*
8076
8163
8077 The bug tracker
8164 The bug tracker
8078 \layout Standard
8165 \layout Standard
8079
8166
8080 IPython also has an online bug-tracker, located at
8167 IPython also has an online bug-tracker, located at
8081 \begin_inset LatexCommand \htmlurl{http://www.scipy.net/roundup/ipython}
8168 \begin_inset LatexCommand \htmlurl{http://www.scipy.net/roundup/ipython}
8082
8169
8083 \end_inset
8170 \end_inset
8084
8171
8085 .
8172 .
8086 In addition to mailing the developers, it would be a good idea to file
8173 In addition to mailing the developers, it would be a good idea to file
8087 a bug report here.
8174 a bug report here.
8088 This will ensure that the issue is properly followed to conclusion.
8175 This will ensure that the issue is properly followed to conclusion.
8089 \layout Standard
8176 \layout Standard
8090
8177
8091 You can also use this bug tracker to file feature requests.
8178 You can also use this bug tracker to file feature requests.
8092 \layout Section
8179 \layout Section
8093
8180
8094 Brief history
8181 Brief history
8095 \layout Subsection
8182 \layout Subsection
8096
8183
8097 Origins
8184 Origins
8098 \layout Standard
8185 \layout Standard
8099
8186
8100 The current IPython system grew out of the following three projects:
8187 The current IPython system grew out of the following three projects:
8101 \layout List
8188 \layout List
8102 \labelwidthstring 00.00.0000
8189 \labelwidthstring 00.00.0000
8103
8190
8104 ipython by Fernando P�rez.
8191 ipython by Fernando P�rez.
8105 I was working on adding Mathematica-type prompts and a flexible configuration
8192 I was working on adding Mathematica-type prompts and a flexible configuration
8106 system (something better than
8193 system (something better than
8107 \family typewriter
8194 \family typewriter
8108 $PYTHONSTARTUP
8195 $PYTHONSTARTUP
8109 \family default
8196 \family default
8110 ) to the standard Python interactive interpreter.
8197 ) to the standard Python interactive interpreter.
8111 \layout List
8198 \layout List
8112 \labelwidthstring 00.00.0000
8199 \labelwidthstring 00.00.0000
8113
8200
8114 IPP by Janko Hauser.
8201 IPP by Janko Hauser.
8115 Very well organized, great usability.
8202 Very well organized, great usability.
8116 Had an old help system.
8203 Had an old help system.
8117 IPP was used as the `container' code into which I added the functionality
8204 IPP was used as the `container' code into which I added the functionality
8118 from ipython and LazyPython.
8205 from ipython and LazyPython.
8119 \layout List
8206 \layout List
8120 \labelwidthstring 00.00.0000
8207 \labelwidthstring 00.00.0000
8121
8208
8122 LazyPython by Nathan Gray.
8209 LazyPython by Nathan Gray.
8123 Simple but
8210 Simple but
8124 \emph on
8211 \emph on
8125 very
8212 very
8126 \emph default
8213 \emph default
8127 powerful.
8214 powerful.
8128 The quick syntax (auto parens, auto quotes) and verbose/colored tracebacks
8215 The quick syntax (auto parens, auto quotes) and verbose/colored tracebacks
8129 were all taken from here.
8216 were all taken from here.
8130 \layout Standard
8217 \layout Standard
8131
8218
8132 When I found out (see sec.
8219 When I found out (see sec.
8133
8220
8134 \begin_inset LatexCommand \ref{figgins}
8221 \begin_inset LatexCommand \ref{figgins}
8135
8222
8136 \end_inset
8223 \end_inset
8137
8224
8138 ) about IPP and LazyPython I tried to join all three into a unified system.
8225 ) about IPP and LazyPython I tried to join all three into a unified system.
8139 I thought this could provide a very nice working environment, both for
8226 I thought this could provide a very nice working environment, both for
8140 regular programming and scientific computing: shell-like features, IDL/Matlab
8227 regular programming and scientific computing: shell-like features, IDL/Matlab
8141 numerics, Mathematica-type prompt history and great object introspection
8228 numerics, Mathematica-type prompt history and great object introspection
8142 and help facilities.
8229 and help facilities.
8143 I think it worked reasonably well, though it was a lot more work than I
8230 I think it worked reasonably well, though it was a lot more work than I
8144 had initially planned.
8231 had initially planned.
8145 \layout Subsection
8232 \layout Subsection
8146
8233
8147 Current status
8234 Current status
8148 \layout Standard
8235 \layout Standard
8149
8236
8150 The above listed features work, and quite well for the most part.
8237 The above listed features work, and quite well for the most part.
8151 But until a major internal restructuring is done (see below), only bug
8238 But until a major internal restructuring is done (see below), only bug
8152 fixing will be done, no other features will be added (unless very minor
8239 fixing will be done, no other features will be added (unless very minor
8153 and well localized in the cleaner parts of the code).
8240 and well localized in the cleaner parts of the code).
8154 \layout Standard
8241 \layout Standard
8155
8242
8156 IPython consists of some 12000 lines of pure python code, of which roughly
8243 IPython consists of some 12000 lines of pure python code, of which roughly
8157 50% are fairly clean.
8244 50% are fairly clean.
8158 The other 50% are fragile, messy code which needs a massive restructuring
8245 The other 50% are fragile, messy code which needs a massive restructuring
8159 before any further major work is done.
8246 before any further major work is done.
8160 Even the messy code is fairly well documented though, and most of the problems
8247 Even the messy code is fairly well documented though, and most of the problems
8161 in the (non-existent) class design are well pointed to by a PyChecker run.
8248 in the (non-existent) class design are well pointed to by a PyChecker run.
8162 So the rewriting work isn't that bad, it will just be time-consuming.
8249 So the rewriting work isn't that bad, it will just be time-consuming.
8163 \layout Subsection
8250 \layout Subsection
8164
8251
8165 Future
8252 Future
8166 \layout Standard
8253 \layout Standard
8167
8254
8168 See the separate
8255 See the separate
8169 \family typewriter
8256 \family typewriter
8170 new_design
8257 new_design
8171 \family default
8258 \family default
8172 document for details.
8259 document for details.
8173 Ultimately, I would like to see IPython become part of the standard Python
8260 Ultimately, I would like to see IPython become part of the standard Python
8174 distribution as a `big brother with batteries' to the standard Python interacti
8261 distribution as a `big brother with batteries' to the standard Python interacti
8175 ve interpreter.
8262 ve interpreter.
8176 But that will never happen with the current state of the code, so all contribut
8263 But that will never happen with the current state of the code, so all contribut
8177 ions are welcome.
8264 ions are welcome.
8178 \layout Section
8265 \layout Section
8179
8266
8180 License
8267 License
8181 \layout Standard
8268 \layout Standard
8182
8269
8183 IPython is released under the terms of the BSD license, whose general form
8270 IPython is released under the terms of the BSD license, whose general form
8184 can be found at:
8271 can be found at:
8185 \begin_inset LatexCommand \htmlurl{http://www.opensource.org/licenses/bsd-license.php}
8272 \begin_inset LatexCommand \htmlurl{http://www.opensource.org/licenses/bsd-license.php}
8186
8273
8187 \end_inset
8274 \end_inset
8188
8275
8189 .
8276 .
8190 The full text of the IPython license is reproduced below:
8277 The full text of the IPython license is reproduced below:
8191 \layout Quote
8278 \layout Quote
8192
8279
8193
8280
8194 \family typewriter
8281 \family typewriter
8195 \size small
8282 \size small
8196 IPython is released under a BSD-type license.
8283 IPython is released under a BSD-type license.
8197 \layout Quote
8284 \layout Quote
8198
8285
8199
8286
8200 \family typewriter
8287 \family typewriter
8201 \size small
8288 \size small
8202 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez <fperez@colorado.edu>.
8289 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez <fperez@colorado.edu>.
8203 \layout Quote
8290 \layout Quote
8204
8291
8205
8292
8206 \family typewriter
8293 \family typewriter
8207 \size small
8294 \size small
8208 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
8295 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
8209 \newline
8296 \newline
8210 Nathaniel Gray <n8gray@caltech.edu>.
8297 Nathaniel Gray <n8gray@caltech.edu>.
8211 \layout Quote
8298 \layout Quote
8212
8299
8213
8300
8214 \family typewriter
8301 \family typewriter
8215 \size small
8302 \size small
8216 All rights reserved.
8303 All rights reserved.
8217 \layout Quote
8304 \layout Quote
8218
8305
8219
8306
8220 \family typewriter
8307 \family typewriter
8221 \size small
8308 \size small
8222 Redistribution and use in source and binary forms, with or without modification,
8309 Redistribution and use in source and binary forms, with or without modification,
8223 are permitted provided that the following conditions are met:
8310 are permitted provided that the following conditions are met:
8224 \layout Quote
8311 \layout Quote
8225
8312
8226
8313
8227 \family typewriter
8314 \family typewriter
8228 \size small
8315 \size small
8229 a.
8316 a.
8230 Redistributions of source code must retain the above copyright notice,
8317 Redistributions of source code must retain the above copyright notice,
8231 this list of conditions and the following disclaimer.
8318 this list of conditions and the following disclaimer.
8232 \layout Quote
8319 \layout Quote
8233
8320
8234
8321
8235 \family typewriter
8322 \family typewriter
8236 \size small
8323 \size small
8237 b.
8324 b.
8238 Redistributions in binary form must reproduce the above copyright notice,
8325 Redistributions in binary form must reproduce the above copyright notice,
8239 this list of conditions and the following disclaimer in the documentation
8326 this list of conditions and the following disclaimer in the documentation
8240 and/or other materials provided with the distribution.
8327 and/or other materials provided with the distribution.
8241 \layout Quote
8328 \layout Quote
8242
8329
8243
8330
8244 \family typewriter
8331 \family typewriter
8245 \size small
8332 \size small
8246 c.
8333 c.
8247 Neither the name of the copyright holders nor the names of any contributors
8334 Neither the name of the copyright holders nor the names of any contributors
8248 to this software may be used to endorse or promote products derived from
8335 to this software may be used to endorse or promote products derived from
8249 this software without specific prior written permission.
8336 this software without specific prior written permission.
8250 \layout Quote
8337 \layout Quote
8251
8338
8252
8339
8253 \family typewriter
8340 \family typewriter
8254 \size small
8341 \size small
8255 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
8342 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
8256 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8343 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8257 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
8344 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
8258 PURPOSE ARE DISCLAIMED.
8345 PURPOSE ARE DISCLAIMED.
8259 IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8346 IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8260 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
8347 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
8261 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
8348 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
8262 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
8349 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
8263 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8350 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8264 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8351 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8265 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8352 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8266
8353
8267 \layout Standard
8354 \layout Standard
8268
8355
8269 Individual authors are the holders of the copyright for their code and are
8356 Individual authors are the holders of the copyright for their code and are
8270 listed in each file.
8357 listed in each file.
8271 \layout Standard
8358 \layout Standard
8272
8359
8273 Some files (
8360 Some files (
8274 \family typewriter
8361 \family typewriter
8275 DPyGetOpt.py
8362 DPyGetOpt.py
8276 \family default
8363 \family default
8277 , for example) may be licensed under different conditions.
8364 , for example) may be licensed under different conditions.
8278 Ultimately each file indicates clearly the conditions under which its author/au
8365 Ultimately each file indicates clearly the conditions under which its author/au
8279 thors have decided to publish the code.
8366 thors have decided to publish the code.
8280 \layout Standard
8367 \layout Standard
8281
8368
8282 Versions of IPython up to and including 0.6.3 were released under the GNU
8369 Versions of IPython up to and including 0.6.3 were released under the GNU
8283 Lesser General Public License (LGPL), available at
8370 Lesser General Public License (LGPL), available at
8284 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/copyleft/lesser.html}
8371 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/copyleft/lesser.html}
8285
8372
8286 \end_inset
8373 \end_inset
8287
8374
8288 .
8375 .
8289 \layout Section
8376 \layout Section
8290
8377
8291
8378
8292 \begin_inset LatexCommand \label{sec:credits}
8379 \begin_inset LatexCommand \label{sec:credits}
8293
8380
8294 \end_inset
8381 \end_inset
8295
8382
8296 Credits
8383 Credits
8297 \layout Standard
8384 \layout Standard
8298
8385
8299 IPython is mainly developed by Fernando P�rez
8386 IPython is mainly developed by Fernando P�rez
8300 \family typewriter
8387 \family typewriter
8301 <fperez@colorado.edu>
8388 <fperez@colorado.edu>
8302 \family default
8389 \family default
8303 , but the project was born from mixing in Fernando's code with the IPP project
8390 , but the project was born from mixing in Fernando's code with the IPP project
8304 by Janko Hauser
8391 by Janko Hauser
8305 \family typewriter
8392 \family typewriter
8306 <jhauser-AT-zscout.de>
8393 <jhauser-AT-zscout.de>
8307 \family default
8394 \family default
8308 and LazyPython by Nathan Gray
8395 and LazyPython by Nathan Gray
8309 \family typewriter
8396 \family typewriter
8310 <n8gray-AT-caltech.edu>
8397 <n8gray-AT-caltech.edu>
8311 \family default
8398 \family default
8312 .
8399 .
8313 For all IPython-related requests, please contact Fernando.
8400 For all IPython-related requests, please contact Fernando.
8314 User or development help should be requested via the IPython mailing lists:
8401
8402 \layout Standard
8403
8404 As of late 2005, the following developers have joined the core team:
8405 \layout List
8406 \labelwidthstring 00.00.0000
8407
8408 Robert\SpecialChar ~
8409 Kern
8410 \family typewriter
8411 <rkern-AT-enthought.com>
8412 \family default
8413 : co-mentored the 2005 Google Summer of Code project to develop python interacti
8414 ve notebooks (XML documents) and graphical interface.
8415 This project was awarded to the students Tzanko Matev
8416 \family typewriter
8417 <tsanko-AT-gmail.com>
8418 \family default
8419 and Toni Alatalo
8420 \family typewriter
8421 <antont-AT-an.org>
8422 \layout List
8423 \labelwidthstring 00.00.0000
8424
8425 Brian\SpecialChar ~
8426 Granger
8427 \family typewriter
8428 <bgranger-AT-scu.edu>
8429 \family default
8430 : extending IPython to allow support for interactive parallel computing.
8431 \layout Standard
8432
8433 User or development help should be requested via the IPython mailing lists:
8315 \layout Description
8434 \layout Description
8316
8435
8317 User\SpecialChar ~
8436 User\SpecialChar ~
8318 list:
8437 list:
8319 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-user}
8438 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-user}
8320
8439
8321 \end_inset
8440 \end_inset
8322
8441
8323
8442
8324 \layout Description
8443 \layout Description
8325
8444
8326 Developer's\SpecialChar ~
8445 Developer's\SpecialChar ~
8327 list:
8446 list:
8328 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-dev}
8447 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-dev}
8329
8448
8330 \end_inset
8449 \end_inset
8331
8450
8332
8451
8333 \layout Standard
8452 \layout Standard
8334
8453
8335 The IPython project is also very grateful to
8454 The IPython project is also very grateful to
8336 \begin_inset Foot
8455 \begin_inset Foot
8337 collapsed true
8456 collapsed true
8338
8457
8339 \layout Standard
8458 \layout Standard
8340
8459
8341 I've mangled email addresses to reduce spam, since the IPython manuals can
8460 I've mangled email addresses to reduce spam, since the IPython manuals can
8342 be accessed online.
8461 be accessed online.
8343 \end_inset
8462 \end_inset
8344
8463
8345 :
8464 :
8346 \layout Standard
8465 \layout Standard
8347
8466
8348 Bill Bumgarner
8467 Bill Bumgarner
8349 \family typewriter
8468 \family typewriter
8350 <bbum-AT-friday.com>
8469 <bbum-AT-friday.com>
8351 \family default
8470 \family default
8352 : for providing the DPyGetOpt module which gives very powerful and convenient
8471 : for providing the DPyGetOpt module which gives very powerful and convenient
8353 handling of command-line options (light years ahead of what Python 2.1.1's
8472 handling of command-line options (light years ahead of what Python 2.1.1's
8354 getopt module does).
8473 getopt module does).
8355 \layout Standard
8474 \layout Standard
8356
8475
8357 Ka-Ping Yee
8476 Ka-Ping Yee
8358 \family typewriter
8477 \family typewriter
8359 <ping-AT-lfw.org>
8478 <ping-AT-lfw.org>
8360 \family default
8479 \family default
8361 : for providing the Itpl module for convenient and powerful string interpolation
8480 : for providing the Itpl module for convenient and powerful string interpolation
8362 with a much nicer syntax than formatting through the '%' operator.
8481 with a much nicer syntax than formatting through the '%' operator.
8363 \layout Standard
8482 \layout Standard
8364
8483
8365 Arnd B�cker
8484 Arnd B�cker
8366 \family typewriter
8485 \family typewriter
8367 <baecker-AT-physik.tu-dresden.de>
8486 <baecker-AT-physik.tu-dresden.de>
8368 \family default
8487 \family default
8369 : for his many very useful suggestions and comments, and lots of help with
8488 : for his many very useful suggestions and comments, and lots of help with
8370 testing and documentation checking.
8489 testing and documentation checking.
8371 Many of IPython's newer features are a result of discussions with him (bugs
8490 Many of IPython's newer features are a result of discussions with him (bugs
8372 are still my fault, not his).
8491 are still my fault, not his).
8373 \layout Standard
8492 \layout Standard
8374
8493
8375 Obviously Guido van\SpecialChar ~
8494 Obviously Guido van\SpecialChar ~
8376 Rossum and the whole Python development team, that goes
8495 Rossum and the whole Python development team, that goes
8377 without saying.
8496 without saying.
8378 \layout Standard
8497 \layout Standard
8379
8498
8380 IPython's website is generously hosted at
8499 IPython's website is generously hosted at
8381 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
8500 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
8382
8501
8383 \end_inset
8502 \end_inset
8384
8503
8385 by Enthought (
8504 by Enthought (
8386 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
8505 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
8387
8506
8388 \end_inset
8507 \end_inset
8389
8508
8390 ).
8509 ).
8391 I am very grateful to them and all of the SciPy team for their contribution.
8510 I am very grateful to them and all of the SciPy team for their contribution.
8392 \layout Standard
8511 \layout Standard
8393
8512
8394
8513
8395 \begin_inset LatexCommand \label{figgins}
8514 \begin_inset LatexCommand \label{figgins}
8396
8515
8397 \end_inset
8516 \end_inset
8398
8517
8399 Fernando would also like to thank Stephen Figgins
8518 Fernando would also like to thank Stephen Figgins
8400 \family typewriter
8519 \family typewriter
8401 <fig-AT-monitor.net>
8520 <fig-AT-monitor.net>
8402 \family default
8521 \family default
8403 , an O'Reilly Python editor.
8522 , an O'Reilly Python editor.
8404 His Oct/11/2001 article about IPP and LazyPython, was what got this project
8523 His Oct/11/2001 article about IPP and LazyPython, was what got this project
8405 started.
8524 started.
8406 You can read it at:
8525 You can read it at:
8407 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html}
8526 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html}
8408
8527
8409 \end_inset
8528 \end_inset
8410
8529
8411 .
8530 .
8412 \layout Standard
8531 \layout Standard
8413
8532
8414 And last but not least, all the kind IPython users who have emailed new
8533 And last but not least, all the kind IPython users who have emailed new
8415 code, bug reports, fixes, comments and ideas.
8534 code, bug reports, fixes, comments and ideas.
8416 A brief list follows, please let me know if I have ommitted your name by
8535 A brief list follows, please let me know if I have ommitted your name by
8417 accident:
8536 accident:
8418 \layout List
8537 \layout List
8419 \labelwidthstring 00.00.0000
8538 \labelwidthstring 00.00.0000
8420
8539
8421 Jack\SpecialChar ~
8540 Jack\SpecialChar ~
8422 Moffit
8541 Moffit
8423 \family typewriter
8542 \family typewriter
8424 <jack-AT-xiph.org>
8543 <jack-AT-xiph.org>
8425 \family default
8544 \family default
8426 Bug fixes, including the infamous color problem.
8545 Bug fixes, including the infamous color problem.
8427 This bug alone caused many lost hours and frustration, many thanks to him
8546 This bug alone caused many lost hours and frustration, many thanks to him
8428 for the fix.
8547 for the fix.
8429 I've always been a fan of Ogg & friends, now I have one more reason to
8548 I've always been a fan of Ogg & friends, now I have one more reason to
8430 like these folks.
8549 like these folks.
8431 \newline
8550 \newline
8432 Jack is also contributing with Debian packaging and many other things.
8551 Jack is also contributing with Debian packaging and many other things.
8433 \layout List
8552 \layout List
8434 \labelwidthstring 00.00.0000
8553 \labelwidthstring 00.00.0000
8435
8554
8436 Alexander\SpecialChar ~
8555 Alexander\SpecialChar ~
8437 Schmolck
8556 Schmolck
8438 \family typewriter
8557 \family typewriter
8439 <a.schmolck-AT-gmx.net>
8558 <a.schmolck-AT-gmx.net>
8440 \family default
8559 \family default
8441 Emacs work, bug reports, bug fixes, ideas, lots more.
8560 Emacs work, bug reports, bug fixes, ideas, lots more.
8442 The ipython.el mode for (X)Emacs is Alex's code, providing full support
8561 The ipython.el mode for (X)Emacs is Alex's code, providing full support
8443 for IPython under (X)Emacs.
8562 for IPython under (X)Emacs.
8444 \layout List
8563 \layout List
8445 \labelwidthstring 00.00.0000
8564 \labelwidthstring 00.00.0000
8446
8565
8447 Andrea\SpecialChar ~
8566 Andrea\SpecialChar ~
8448 Riciputi
8567 Riciputi
8449 \family typewriter
8568 \family typewriter
8450 <andrea.riciputi-AT-libero.it>
8569 <andrea.riciputi-AT-libero.it>
8451 \family default
8570 \family default
8452 Mac OSX information, Fink package management.
8571 Mac OSX information, Fink package management.
8453 \layout List
8572 \layout List
8454 \labelwidthstring 00.00.0000
8573 \labelwidthstring 00.00.0000
8455
8574
8456 Gary\SpecialChar ~
8575 Gary\SpecialChar ~
8457 Bishop
8576 Bishop
8458 \family typewriter
8577 \family typewriter
8459 <gb-AT-cs.unc.edu>
8578 <gb-AT-cs.unc.edu>
8460 \family default
8579 \family default
8461 Bug reports, and patches to work around the exception handling idiosyncracies
8580 Bug reports, and patches to work around the exception handling idiosyncracies
8462 of WxPython.
8581 of WxPython.
8463 Readline and color support for Windows.
8582 Readline and color support for Windows.
8464 \layout List
8583 \layout List
8465 \labelwidthstring 00.00.0000
8584 \labelwidthstring 00.00.0000
8466
8585
8467 Jeffrey\SpecialChar ~
8586 Jeffrey\SpecialChar ~
8468 Collins
8587 Collins
8469 \family typewriter
8588 \family typewriter
8470 <Jeff.Collins-AT-vexcel.com>
8589 <Jeff.Collins-AT-vexcel.com>
8471 \family default
8590 \family default
8472 Bug reports.
8591 Bug reports.
8473 Much improved readline support, including fixes for Python 2.3.
8592 Much improved readline support, including fixes for Python 2.3.
8474 \layout List
8593 \layout List
8475 \labelwidthstring 00.00.0000
8594 \labelwidthstring 00.00.0000
8476
8595
8477 Dryice\SpecialChar ~
8596 Dryice\SpecialChar ~
8478 Liu
8597 Liu
8479 \family typewriter
8598 \family typewriter
8480 <dryice-AT-liu.com.cn>
8599 <dryice-AT-liu.com.cn>
8481 \family default
8600 \family default
8482 FreeBSD port.
8601 FreeBSD port.
8483 \layout List
8602 \layout List
8484 \labelwidthstring 00.00.0000
8603 \labelwidthstring 00.00.0000
8485
8604
8486 Mike\SpecialChar ~
8605 Mike\SpecialChar ~
8487 Heeter
8606 Heeter
8488 \family typewriter
8607 \family typewriter
8489 <korora-AT-SDF.LONESTAR.ORG>
8608 <korora-AT-SDF.LONESTAR.ORG>
8490 \layout List
8609 \layout List
8491 \labelwidthstring 00.00.0000
8610 \labelwidthstring 00.00.0000
8492
8611
8493 Christopher\SpecialChar ~
8612 Christopher\SpecialChar ~
8494 Hart
8613 Hart
8495 \family typewriter
8614 \family typewriter
8496 <hart-AT-caltech.edu>
8615 <hart-AT-caltech.edu>
8497 \family default
8616 \family default
8498 PDB integration.
8617 PDB integration.
8499 \layout List
8618 \layout List
8500 \labelwidthstring 00.00.0000
8619 \labelwidthstring 00.00.0000
8501
8620
8502 Milan\SpecialChar ~
8621 Milan\SpecialChar ~
8503 Zamazal
8622 Zamazal
8504 \family typewriter
8623 \family typewriter
8505 <pdm-AT-zamazal.org>
8624 <pdm-AT-zamazal.org>
8506 \family default
8625 \family default
8507 Emacs info.
8626 Emacs info.
8508 \layout List
8627 \layout List
8509 \labelwidthstring 00.00.0000
8628 \labelwidthstring 00.00.0000
8510
8629
8511 Philip\SpecialChar ~
8630 Philip\SpecialChar ~
8512 Hisley
8631 Hisley
8513 \family typewriter
8632 \family typewriter
8514 <compsys-AT-starpower.net>
8633 <compsys-AT-starpower.net>
8515 \layout List
8634 \layout List
8516 \labelwidthstring 00.00.0000
8635 \labelwidthstring 00.00.0000
8517
8636
8518 Holger\SpecialChar ~
8637 Holger\SpecialChar ~
8519 Krekel
8638 Krekel
8520 \family typewriter
8639 \family typewriter
8521 <pyth-AT-devel.trillke.net>
8640 <pyth-AT-devel.trillke.net>
8522 \family default
8641 \family default
8523 Tab completion, lots more.
8642 Tab completion, lots more.
8524 \layout List
8643 \layout List
8525 \labelwidthstring 00.00.0000
8644 \labelwidthstring 00.00.0000
8526
8645
8527 Robin\SpecialChar ~
8646 Robin\SpecialChar ~
8528 Siebler
8647 Siebler
8529 \family typewriter
8648 \family typewriter
8530 <robinsiebler-AT-starband.net>
8649 <robinsiebler-AT-starband.net>
8531 \layout List
8650 \layout List
8532 \labelwidthstring 00.00.0000
8651 \labelwidthstring 00.00.0000
8533
8652
8534 Ralf\SpecialChar ~
8653 Ralf\SpecialChar ~
8535 Ahlbrink
8654 Ahlbrink
8536 \family typewriter
8655 \family typewriter
8537 <ralf_ahlbrink-AT-web.de>
8656 <ralf_ahlbrink-AT-web.de>
8538 \layout List
8657 \layout List
8539 \labelwidthstring 00.00.0000
8658 \labelwidthstring 00.00.0000
8540
8659
8541 Thorsten\SpecialChar ~
8660 Thorsten\SpecialChar ~
8542 Kampe
8661 Kampe
8543 \family typewriter
8662 \family typewriter
8544 <thorsten-AT-thorstenkampe.de>
8663 <thorsten-AT-thorstenkampe.de>
8545 \layout List
8664 \layout List
8546 \labelwidthstring 00.00.0000
8665 \labelwidthstring 00.00.0000
8547
8666
8548 Fredrik\SpecialChar ~
8667 Fredrik\SpecialChar ~
8549 Kant
8668 Kant
8550 \family typewriter
8669 \family typewriter
8551 <fredrik.kant-AT-front.com>
8670 <fredrik.kant-AT-front.com>
8552 \family default
8671 \family default
8553 Windows setup.
8672 Windows setup.
8554 \layout List
8673 \layout List
8555 \labelwidthstring 00.00.0000
8674 \labelwidthstring 00.00.0000
8556
8675
8557 Syver\SpecialChar ~
8676 Syver\SpecialChar ~
8558 Enstad
8677 Enstad
8559 \family typewriter
8678 \family typewriter
8560 <syver-en-AT-online.no>
8679 <syver-en-AT-online.no>
8561 \family default
8680 \family default
8562 Windows setup.
8681 Windows setup.
8563 \layout List
8682 \layout List
8564 \labelwidthstring 00.00.0000
8683 \labelwidthstring 00.00.0000
8565
8684
8566 Richard
8685 Richard
8567 \family typewriter
8686 \family typewriter
8568 <rxe-AT-renre-europe.com>
8687 <rxe-AT-renre-europe.com>
8569 \family default
8688 \family default
8570 Global embedding.
8689 Global embedding.
8571 \layout List
8690 \layout List
8572 \labelwidthstring 00.00.0000
8691 \labelwidthstring 00.00.0000
8573
8692
8574 Hayden\SpecialChar ~
8693 Hayden\SpecialChar ~
8575 Callow
8694 Callow
8576 \family typewriter
8695 \family typewriter
8577 <h.callow-AT-elec.canterbury.ac.nz>
8696 <h.callow-AT-elec.canterbury.ac.nz>
8578 \family default
8697 \family default
8579 Gnuplot.py 1.6 compatibility.
8698 Gnuplot.py 1.6 compatibility.
8580 \layout List
8699 \layout List
8581 \labelwidthstring 00.00.0000
8700 \labelwidthstring 00.00.0000
8582
8701
8583 Leonardo\SpecialChar ~
8702 Leonardo\SpecialChar ~
8584 Santagada
8703 Santagada
8585 \family typewriter
8704 \family typewriter
8586 <retype-AT-terra.com.br>
8705 <retype-AT-terra.com.br>
8587 \family default
8706 \family default
8588 Fixes for Windows installation.
8707 Fixes for Windows installation.
8589 \layout List
8708 \layout List
8590 \labelwidthstring 00.00.0000
8709 \labelwidthstring 00.00.0000
8591
8710
8592 Christopher\SpecialChar ~
8711 Christopher\SpecialChar ~
8593 Armstrong
8712 Armstrong
8594 \family typewriter
8713 \family typewriter
8595 <radix-AT-twistedmatrix.com>
8714 <radix-AT-twistedmatrix.com>
8596 \family default
8715 \family default
8597 Bugfixes.
8716 Bugfixes.
8598 \layout List
8717 \layout List
8599 \labelwidthstring 00.00.0000
8718 \labelwidthstring 00.00.0000
8600
8719
8601 Francois\SpecialChar ~
8720 Francois\SpecialChar ~
8602 Pinard
8721 Pinard
8603 \family typewriter
8722 \family typewriter
8604 <pinard-AT-iro.umontreal.ca>
8723 <pinard-AT-iro.umontreal.ca>
8605 \family default
8724 \family default
8606 Code and documentation fixes.
8725 Code and documentation fixes.
8607 \layout List
8726 \layout List
8608 \labelwidthstring 00.00.0000
8727 \labelwidthstring 00.00.0000
8609
8728
8610 Cory\SpecialChar ~
8729 Cory\SpecialChar ~
8611 Dodt
8730 Dodt
8612 \family typewriter
8731 \family typewriter
8613 <cdodt-AT-fcoe.k12.ca.us>
8732 <cdodt-AT-fcoe.k12.ca.us>
8614 \family default
8733 \family default
8615 Bug reports and Windows ideas.
8734 Bug reports and Windows ideas.
8616 Patches for Windows installer.
8735 Patches for Windows installer.
8617 \layout List
8736 \layout List
8618 \labelwidthstring 00.00.0000
8737 \labelwidthstring 00.00.0000
8619
8738
8620 Olivier\SpecialChar ~
8739 Olivier\SpecialChar ~
8621 Aubert
8740 Aubert
8622 \family typewriter
8741 \family typewriter
8623 <oaubert-AT-bat710.univ-lyon1.fr>
8742 <oaubert-AT-bat710.univ-lyon1.fr>
8624 \family default
8743 \family default
8625 New magics.
8744 New magics.
8626 \layout List
8745 \layout List
8627 \labelwidthstring 00.00.0000
8746 \labelwidthstring 00.00.0000
8628
8747
8629 King\SpecialChar ~
8748 King\SpecialChar ~
8630 C.\SpecialChar ~
8749 C.\SpecialChar ~
8631 Shu
8750 Shu
8632 \family typewriter
8751 \family typewriter
8633 <kingshu-AT-myrealbox.com>
8752 <kingshu-AT-myrealbox.com>
8634 \family default
8753 \family default
8635 Autoindent patch.
8754 Autoindent patch.
8636 \layout List
8755 \layout List
8637 \labelwidthstring 00.00.0000
8756 \labelwidthstring 00.00.0000
8638
8757
8639 Chris\SpecialChar ~
8758 Chris\SpecialChar ~
8640 Drexler
8759 Drexler
8641 \family typewriter
8760 \family typewriter
8642 <chris-AT-ac-drexler.de>
8761 <chris-AT-ac-drexler.de>
8643 \family default
8762 \family default
8644 Readline packages for Win32/CygWin.
8763 Readline packages for Win32/CygWin.
8645 \layout List
8764 \layout List
8646 \labelwidthstring 00.00.0000
8765 \labelwidthstring 00.00.0000
8647
8766
8648 Gustavo\SpecialChar ~
8767 Gustavo\SpecialChar ~
8649 C�rdova\SpecialChar ~
8768 C�rdova\SpecialChar ~
8650 Avila
8769 Avila
8651 \family typewriter
8770 \family typewriter
8652 <gcordova-AT-sismex.com>
8771 <gcordova-AT-sismex.com>
8653 \family default
8772 \family default
8654 EvalDict code for nice, lightweight string interpolation.
8773 EvalDict code for nice, lightweight string interpolation.
8655 \layout List
8774 \layout List
8656 \labelwidthstring 00.00.0000
8775 \labelwidthstring 00.00.0000
8657
8776
8658 Kasper\SpecialChar ~
8777 Kasper\SpecialChar ~
8659 Souren
8778 Souren
8660 \family typewriter
8779 \family typewriter
8661 <Kasper.Souren-AT-ircam.fr>
8780 <Kasper.Souren-AT-ircam.fr>
8662 \family default
8781 \family default
8663 Bug reports, ideas.
8782 Bug reports, ideas.
8664 \layout List
8783 \layout List
8665 \labelwidthstring 00.00.0000
8784 \labelwidthstring 00.00.0000
8666
8785
8667 Gever\SpecialChar ~
8786 Gever\SpecialChar ~
8668 Tulley
8787 Tulley
8669 \family typewriter
8788 \family typewriter
8670 <gever-AT-helium.com>
8789 <gever-AT-helium.com>
8671 \family default
8790 \family default
8672 Code contributions.
8791 Code contributions.
8673 \layout List
8792 \layout List
8674 \labelwidthstring 00.00.0000
8793 \labelwidthstring 00.00.0000
8675
8794
8676 Ralf\SpecialChar ~
8795 Ralf\SpecialChar ~
8677 Schmitt
8796 Schmitt
8678 \family typewriter
8797 \family typewriter
8679 <ralf-AT-brainbot.com>
8798 <ralf-AT-brainbot.com>
8680 \family default
8799 \family default
8681 Bug reports & fixes.
8800 Bug reports & fixes.
8682 \layout List
8801 \layout List
8683 \labelwidthstring 00.00.0000
8802 \labelwidthstring 00.00.0000
8684
8803
8685 Oliver\SpecialChar ~
8804 Oliver\SpecialChar ~
8686 Sander
8805 Sander
8687 \family typewriter
8806 \family typewriter
8688 <osander-AT-gmx.de>
8807 <osander-AT-gmx.de>
8689 \family default
8808 \family default
8690 Bug reports.
8809 Bug reports.
8691 \layout List
8810 \layout List
8692 \labelwidthstring 00.00.0000
8811 \labelwidthstring 00.00.0000
8693
8812
8694 Rod\SpecialChar ~
8813 Rod\SpecialChar ~
8695 Holland
8814 Holland
8696 \family typewriter
8815 \family typewriter
8697 <rhh-AT-structurelabs.com>
8816 <rhh-AT-structurelabs.com>
8698 \family default
8817 \family default
8699 Bug reports and fixes to logging module.
8818 Bug reports and fixes to logging module.
8700 \layout List
8819 \layout List
8701 \labelwidthstring 00.00.0000
8820 \labelwidthstring 00.00.0000
8702
8821
8703 Daniel\SpecialChar ~
8822 Daniel\SpecialChar ~
8704 'Dang'\SpecialChar ~
8823 'Dang'\SpecialChar ~
8705 Griffith
8824 Griffith
8706 \family typewriter
8825 \family typewriter
8707 <pythondev-dang-AT-lazytwinacres.net>
8826 <pythondev-dang-AT-lazytwinacres.net>
8708 \family default
8827 \family default
8709 Fixes, enhancement suggestions for system shell use.
8828 Fixes, enhancement suggestions for system shell use.
8710 \layout List
8829 \layout List
8711 \labelwidthstring 00.00.0000
8830 \labelwidthstring 00.00.0000
8712
8831
8713 Viktor\SpecialChar ~
8832 Viktor\SpecialChar ~
8714 Ransmayr
8833 Ransmayr
8715 \family typewriter
8834 \family typewriter
8716 <viktor.ransmayr-AT-t-online.de>
8835 <viktor.ransmayr-AT-t-online.de>
8717 \family default
8836 \family default
8718 Tests and reports on Windows installation issues.
8837 Tests and reports on Windows installation issues.
8719 Contributed a true Windows binary installer.
8838 Contributed a true Windows binary installer.
8720 \layout List
8839 \layout List
8721 \labelwidthstring 00.00.0000
8840 \labelwidthstring 00.00.0000
8722
8841
8723 Mike\SpecialChar ~
8842 Mike\SpecialChar ~
8724 Salib
8843 Salib
8725 \family typewriter
8844 \family typewriter
8726 <msalib-AT-mit.edu>
8845 <msalib-AT-mit.edu>
8727 \family default
8846 \family default
8728 Help fixing a subtle bug related to traceback printing.
8847 Help fixing a subtle bug related to traceback printing.
8729 \layout List
8848 \layout List
8730 \labelwidthstring 00.00.0000
8849 \labelwidthstring 00.00.0000
8731
8850
8732 W.J.\SpecialChar ~
8851 W.J.\SpecialChar ~
8733 van\SpecialChar ~
8852 van\SpecialChar ~
8734 der\SpecialChar ~
8853 der\SpecialChar ~
8735 Laan
8854 Laan
8736 \family typewriter
8855 \family typewriter
8737 <gnufnork-AT-hetdigitalegat.nl>
8856 <gnufnork-AT-hetdigitalegat.nl>
8738 \family default
8857 \family default
8739 Bash-like prompt specials.
8858 Bash-like prompt specials.
8740 \layout List
8859 \layout List
8741 \labelwidthstring 00.00.0000
8860 \labelwidthstring 00.00.0000
8742
8861
8743 Ville\SpecialChar ~
8862 Ville\SpecialChar ~
8744 Vainio
8863 Vainio
8745 \family typewriter
8864 \family typewriter
8746 <vivainio-AT-kolumbus.fi>
8865 <vivainio-AT-kolumbus.fi>
8747 \family default
8866 \family default
8748 Bugfixes and suggestions.
8867 Bugfixes and suggestions.
8749 Excellent patches for many new features.
8868 Excellent patches for many new features.
8750 \layout List
8869 \layout List
8751 \labelwidthstring 00.00.0000
8870 \labelwidthstring 00.00.0000
8752
8871
8753 Antoon\SpecialChar ~
8872 Antoon\SpecialChar ~
8754 Pardon
8873 Pardon
8755 \family typewriter
8874 \family typewriter
8756 <Antoon.Pardon-AT-rece.vub.ac.be>
8875 <Antoon.Pardon-AT-rece.vub.ac.be>
8757 \family default
8876 \family default
8758 Critical fix for the multithreaded IPython.
8877 Critical fix for the multithreaded IPython.
8759 \layout List
8878 \layout List
8760 \labelwidthstring 00.00.0000
8879 \labelwidthstring 00.00.0000
8761
8880
8762 John\SpecialChar ~
8881 John\SpecialChar ~
8763 Hunter
8882 Hunter
8764 \family typewriter
8883 \family typewriter
8765 <jdhunter-AT-nitace.bsd.uchicago.edu>
8884 <jdhunter-AT-nitace.bsd.uchicago.edu>
8766 \family default
8885 \family default
8767 Matplotlib author, helped with all the development of support for matplotlib
8886 Matplotlib author, helped with all the development of support for matplotlib
8768 in IPyhton, including making necessary changes to matplotlib itself.
8887 in IPyhton, including making necessary changes to matplotlib itself.
8769 \layout List
8888 \layout List
8770 \labelwidthstring 00.00.0000
8889 \labelwidthstring 00.00.0000
8771
8890
8772 Matthew\SpecialChar ~
8891 Matthew\SpecialChar ~
8773 Arnison
8892 Arnison
8774 \family typewriter
8893 \family typewriter
8775 <maffew-AT-cat.org.au>
8894 <maffew-AT-cat.org.au>
8776 \family default
8895 \family default
8777 Bug reports, `
8896 Bug reports, `
8778 \family typewriter
8897 \family typewriter
8779 %run -d
8898 %run -d
8780 \family default
8899 \family default
8781 ' idea.
8900 ' idea.
8782 \layout List
8901 \layout List
8783 \labelwidthstring 00.00.0000
8902 \labelwidthstring 00.00.0000
8784
8903
8785 Prabhu\SpecialChar ~
8904 Prabhu\SpecialChar ~
8786 Ramachandran
8905 Ramachandran
8787 \family typewriter
8906 \family typewriter
8788 <prabhu_r-AT-users.sourceforge.net>
8907 <prabhu_r-AT-users.sourceforge.net>
8789 \family default
8908 \family default
8790 Help with (X)Emacs support, threading patches, ideas...
8909 Help with (X)Emacs support, threading patches, ideas...
8791 \layout List
8910 \layout List
8792 \labelwidthstring 00.00.0000
8911 \labelwidthstring 00.00.0000
8793
8912
8794 Norbert\SpecialChar ~
8913 Norbert\SpecialChar ~
8795 Tretkowski
8914 Tretkowski
8796 \family typewriter
8915 \family typewriter
8797 <tretkowski-AT-inittab.de>
8916 <tretkowski-AT-inittab.de>
8798 \family default
8917 \family default
8799 help with Debian packaging and distribution.
8918 help with Debian packaging and distribution.
8800 \layout List
8919 \layout List
8801 \labelwidthstring 00.00.0000
8920 \labelwidthstring 00.00.0000
8802
8921
8803 Robert\SpecialChar ~
8804 Kern
8805 \family typewriter
8806 <rkern-AT-ucsd.edu>
8807 \family default
8808 help with OSX issues, much help in general with various Python topics,
8809 especially related to scientific computing.
8810 \layout List
8811 \labelwidthstring 00.00.0000
8812
8813 George\SpecialChar ~
8922 George\SpecialChar ~
8814 Sakkis <
8923 Sakkis <
8815 \family typewriter
8924 \family typewriter
8816 gsakkis-AT-eden.rutgers.edu>
8925 gsakkis-AT-eden.rutgers.edu>
8817 \family default
8926 \family default
8818 New matcher for tab-completing named arguments of user-defined functions.
8927 New matcher for tab-completing named arguments of user-defined functions.
8819 \the_end
8928 \the_end
General Comments 0
You need to be logged in to leave comments. Login now