##// END OF EJS Templates
always add a newline upon %save
Dominik Dabrowski -
Show More
@@ -61,8 +61,7 b' class CodeMagics(Magics):'
61 -f: force overwrite. If file exists, %save will prompt for overwrite
61 -f: force overwrite. If file exists, %save will prompt for overwrite
62 unless -f is given.
62 unless -f is given.
63
63
64 -a: append to file. Open file in append mode and end every write
64 -a: open file in append mode.
65 on a newline.
66
65
67 This function uses the same syntax as %history for input ranges,
66 This function uses the same syntax as %history for input ranges,
68 then saves the lines to the filename you specify.
67 then saves the lines to the filename you specify.
@@ -98,14 +97,12 b' class CodeMagics(Magics):'
98 return
97 return
99 out = py3compat.cast_unicode(cmds)
98 out = py3compat.cast_unicode(cmds)
100 with io.open(fname, mode, encoding="utf-8") as f:
99 with io.open(fname, mode, encoding="utf-8") as f:
101 if append:
100 if not append:
102 f.write(out)
103 # make sure we end on a newline
104 if not out.endswith(u'\n'):
105 f.write(u'\n')
106 else:
107 f.write(u"# coding: utf-8\n")
101 f.write(u"# coding: utf-8\n")
108 f.write(out)
102 f.write(out)
103 # make sure we end on a newline
104 if not out.endswith(u'\n'):
105 f.write(u'\n')
109 print 'The following commands were written to file `%s`:' % fname
106 print 'The following commands were written to file `%s`:' % fname
110 print cmds
107 print cmds
111
108
General Comments 0
You need to be logged in to leave comments. Login now