##// END OF EJS Templates
change default extension to .ipy for %save -r
Matthias BUSSONNIER -
Show More
@@ -61,19 +61,24 b' class CodeMagics(Magics):'
61 61 then saves the lines to the filename you specify.
62 62
63 63 It adds a '.py' extension to the file if you don't do so yourself, and
64 it asks for confirmation before overwriting existing files."""
64 it asks for confirmation before overwriting existing files.
65
66 If `-r` option is used, the default extension is `.ipy`.
67 """
65 68
66 69 opts,args = self.parse_options(parameter_s,'r',mode='list')
70 raw = 'r' in opts
71 ext = u'.ipy' if raw else u'.py'
67 72 fname, codefrom = unquote_filename(args[0]), " ".join(args[1:])
68 if not fname.endswith('.py'):
69 fname += '.py'
73 if not (fname.endswith(u'.py') or fname.endswith(u'.ipy')):
74 fname += ext
70 75 if os.path.isfile(fname):
71 76 overwrite = self.shell.ask_yes_no('File `%s` exists. Overwrite (y/[N])? ' % fname, default='n')
72 77 if not overwrite :
73 78 print 'Operation cancelled.'
74 79 return
75 80 try:
76 cmds = self.shell.find_user_code(codefrom, 'r' in opts)
81 cmds = self.shell.find_user_code(codefrom,raw)
77 82 except (TypeError, ValueError) as e:
78 83 print e.args[0]
79 84 return
General Comments 0
You need to be logged in to leave comments. Login now