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