Skip to content


qtconsole ipython widget's execute_file fails if filename contains spaces or quotes #762

merged 2 commits into from

2 participants


Issue #755. Yet another patchwork path hack. Tested on Windows XP and OSX.


Using %run to execute a file seems like the only reasonable thing to do. It's a shame that escaping the quotes doesn't work better, but what can you do?

Anyway, thanks for the fix.

@epatters epatters merged commit af8cee0 into ipython:master
@ellisonbg ellisonbg referenced this pull request
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 5, 2011
  1. @jdmarch
  2. @jdmarch

    BUG: Do need to quote some quotes in %run, so quote them all.

    jdmarch committed
    (Still do not support both single and double quotes in the same filename.)
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 0 deletions.
  1. +12 −0 IPython/frontend/qt/console/
12 IPython/frontend/qt/console/
@@ -253,6 +253,18 @@ def execute_file(self, path, hidden=False):
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 or quotes.
+ # Escaping quotes in filename in %run seems tricky and inconsistent,
+ # so not trying it at present.
+ if '"' in path:
+ if "'" in path:
+ raise ValueError("Can't run filename containing both single "
+ "and double quotes: %s" % path)
+ path = "'%s'" % path
+ elif ' ' in path or "'" in path:
+ path = '"%s"' % path
self.execute('%%run %s' % path, hidden=hidden)
Something went wrong with that request. Please try again.