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