From 2de5ccaeef352ed8611d38e4f40905e8c58301ca 2011-03-13 12:51:48 From: Thomas Kluyver Date: 2011-03-13 12:51:48 Subject: [PATCH] Reinstate newlines in %save and %macro, first part of issue 245. --- diff --git a/IPython/core/macro.py b/IPython/core/macro.py index 02857ea..6f1f458 100644 --- a/IPython/core/macro.py +++ b/IPython/core/macro.py @@ -21,7 +21,7 @@ class Macro(IPyAutocall): def __init__(self,data): """store the macro value, as a single string which can be executed""" - self.value = ''.join(data).rstrip()+'\n' + self.value = '\n'.join(data).rstrip()+'\n' def __str__(self): return self.value diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 4fc67be..5a0e22c 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -200,7 +200,7 @@ python-profiler package from non-free.""") else: ini = int(chunk) fin = ini+1 - cmds.append(''.join(hist[ini:fin])) + cmds.append('\n'.join(hist[ini:fin])) return cmds def arg_err(self,func): @@ -2079,10 +2079,9 @@ Currently the magic system has the following functions:\n""" if ans.lower() not in ['y','yes']: print 'Operation cancelled.' return - cmds = ''.join(self.extract_input_slices(ranges,opts.has_key('r'))) - f = file(fname,'w') - f.write(cmds) - f.close() + cmds = '\n'.join(self.extract_input_slices(ranges,opts.has_key('r'))) + with open(fname,'w') as f: + f.write(cmds) print 'The following commands were written to file `%s`:' % fname print cmds