Permalink
Browse files

Reinstate newlines in %save and %macro, first part of issue 245.

  • Loading branch information...
1 parent 2ccc90d commit cf5ffcf5e770b8ee2abf0dbf32d95f0fbe2e6082 @takluyver committed Jan 13, 2011
Showing with 5 additions and 6 deletions.
  1. +1 −1 IPython/core/macro.py
  2. +4 −5 IPython/core/magic.py
View
@@ -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
View
@@ -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

0 comments on commit cf5ffcf

Please sign in to comment.