Show More
@@ -29,7 +29,6 b' from IPython.core.macro import Macro' | |||
|
29 | 29 | from IPython.core.magic import Magics, magics_class, line_magic |
|
30 | 30 | from IPython.core.oinspect import find_file, find_source_lines |
|
31 | 31 | from IPython.testing.skipdoctest import skip_doctest |
|
32 | from IPython.utils import py3compat | |
|
33 | 32 | from IPython.utils.contexts import preserve_keys |
|
34 | 33 | from IPython.utils.path import get_py_filename |
|
35 | 34 | from warnings import warn |
@@ -214,9 +213,9 b' class CodeMagics(Magics):' | |||
|
214 | 213 | force = 'f' in opts |
|
215 | 214 | append = 'a' in opts |
|
216 | 215 | mode = 'a' if append else 'w' |
|
217 |
ext = |
|
|
216 | ext = '.ipy' if raw else '.py' | |
|
218 | 217 | fname, codefrom = args[0], " ".join(args[1:]) |
|
219 |
if not fname.endswith(( |
|
|
218 | if not fname.endswith(('.py','.ipy')): | |
|
220 | 219 | fname += ext |
|
221 | 220 | file_exists = os.path.isfile(fname) |
|
222 | 221 | if file_exists and not force and not append: |
@@ -233,14 +232,13 b' class CodeMagics(Magics):' | |||
|
233 | 232 | except (TypeError, ValueError) as e: |
|
234 | 233 | print(e.args[0]) |
|
235 | 234 | return |
|
236 | out = py3compat.cast_unicode(cmds) | |
|
237 | 235 | with io.open(fname, mode, encoding="utf-8") as f: |
|
238 | 236 | if not file_exists or not append: |
|
239 |
f.write( |
|
|
240 |
f.write( |
|
|
237 | f.write("# coding: utf-8\n") | |
|
238 | f.write(cmds) | |
|
241 | 239 | # make sure we end on a newline |
|
242 |
if not |
|
|
243 |
f.write( |
|
|
240 | if not cmds.endswith('\n'): | |
|
241 | f.write('\n') | |
|
244 | 242 | print('The following commands were written to file `%s`:' % fname) |
|
245 | 243 | print(cmds) |
|
246 | 244 |
General Comments 0
You need to be logged in to leave comments.
Login now