##// 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 then saves the lines to the filename you specify.
61 then saves the lines to the filename you specify.
62
62
63 It adds a '.py' extension to the file if you don't do so yourself, and
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 opts,args = self.parse_options(parameter_s,'r',mode='list')
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 fname, codefrom = unquote_filename(args[0]), " ".join(args[1:])
72 fname, codefrom = unquote_filename(args[0]), " ".join(args[1:])
68 if not fname.endswith('.py'):
73 if not (fname.endswith(u'.py') or fname.endswith(u'.ipy')):
69 fname += '.py'
74 fname += ext
70 if os.path.isfile(fname):
75 if os.path.isfile(fname):
71 overwrite = self.shell.ask_yes_no('File `%s` exists. Overwrite (y/[N])? ' % fname, default='n')
76 overwrite = self.shell.ask_yes_no('File `%s` exists. Overwrite (y/[N])? ' % fname, default='n')
72 if not overwrite :
77 if not overwrite :
73 print 'Operation cancelled.'
78 print 'Operation cancelled.'
74 return
79 return
75 try:
80 try:
76 cmds = self.shell.find_user_code(codefrom, 'r' in opts)
81 cmds = self.shell.find_user_code(codefrom,raw)
77 except (TypeError, ValueError) as e:
82 except (TypeError, ValueError) as e:
78 print e.args[0]
83 print e.args[0]
79 return
84 return
General Comments 0
You need to be logged in to leave comments. Login now