From 81eff6a8fca3b3bde64136af8b6a42633e67e36b 2012-06-01 12:02:36 From: Matthias BUSSONNIER Date: 2012-06-01 12:02:36 Subject: [PATCH] change default extension to .ipy for %save -r --- diff --git a/IPython/core/magics/code.py b/IPython/core/magics/code.py index 6679abb..b119993 100644 --- a/IPython/core/magics/code.py +++ b/IPython/core/magics/code.py @@ -61,19 +61,24 @@ class CodeMagics(Magics): then saves the lines to the filename you specify. It adds a '.py' extension to the file if you don't do so yourself, and - it asks for confirmation before overwriting existing files.""" + it asks for confirmation before overwriting existing files. + + If `-r` option is used, the default extension is `.ipy`. + """ opts,args = self.parse_options(parameter_s,'r',mode='list') + raw = 'r' in opts + ext = u'.ipy' if raw else u'.py' fname, codefrom = unquote_filename(args[0]), " ".join(args[1:]) - if not fname.endswith('.py'): - fname += '.py' + if not (fname.endswith(u'.py') or fname.endswith(u'.ipy')): + fname += ext if os.path.isfile(fname): overwrite = self.shell.ask_yes_no('File `%s` exists. Overwrite (y/[N])? ' % fname, default='n') if not overwrite : print 'Operation cancelled.' return try: - cmds = self.shell.find_user_code(codefrom, 'r' in opts) + cmds = self.shell.find_user_code(codefrom,raw) except (TypeError, ValueError) as e: print e.args[0] return