diff --git a/IPython/frontend/qt/console/ipython_widget.py b/IPython/frontend/qt/console/ipython_widget.py index 29b796a..e7c0c85 100644 --- a/IPython/frontend/qt/console/ipython_widget.py +++ b/IPython/frontend/qt/console/ipython_widget.py @@ -253,6 +253,17 @@ class IPythonWidget(FrontendWidget): if sys.platform == 'win32': path = os.path.normpath(path).replace('\\', '/') + # Perhaps we should not be using %run directly, but while we + # are, it is necessary to quote filenames containing spaces. + if ' ' in path: + if '"' not in path: + path = '"%s"' % path + elif "'" not in path: + path = "'%s'" % path + else: + raise ValueError("Can't run filename containing both single " + "and double quotes: %s" % path) + self.execute('%%run %s' % path, hidden=hidden) #---------------------------------------------------------------------------