diff --git a/IPython/core/macro.py b/IPython/core/macro.py index 02857ea31d7..6f1f45885ad 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 12df58c5531..fde0420da9e 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -200,7 +200,7 @@ def extract_input_slices(self,slices,raw=False): 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): @@ -2013,10 +2013,9 @@ def magic_save(self,parameter_s = ''): 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