Skip to content
This repository

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

Merged
merged 2 commits into from over 2 years ago

2 participants

Jonathan March Evan Patterson
Jonathan March
Collaborator

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

Evan Patterson
Collaborator

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.

Evan Patterson epatters merged commit af8cee0 into from September 07, 2011
Evan Patterson epatters closed this September 07, 2011
Brian E. Granger ellisonbg referenced this pull request from a commit January 10, 2012
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

Showing 2 unique commits by 2 authors.

Sep 05, 2011
Jonathan March BUG: Improve hack. Issue #755. execute_file fails if filename has spaces 3ccb8ee
Jonathan March BUG: Do need to quote some quotes in %run, so quote them all.
(Still do not support both single and double quotes in the same filename.)
03159d0
This page is out of date. Refresh to see the latest.
12  IPython/frontend/qt/console/ipython_widget.py
@@ -253,6 +253,18 @@ def execute_file(self, path, hidden=False):
253 253
         if sys.platform == 'win32':
254 254
             path = os.path.normpath(path).replace('\\', '/')
255 255
 
  256
+        # Perhaps we should not be using %run directly, but while we
  257
+        # are, it is necessary to quote filenames containing spaces or quotes.
  258
+        # Escaping quotes in filename in %run seems tricky and inconsistent,
  259
+        # so not trying it at present.
  260
+        if '"' in path:
  261
+            if "'" in path:
  262
+                raise ValueError("Can't run filename containing both single "
  263
+                                 "and double quotes: %s" % path)
  264
+            path = "'%s'" % path
  265
+        elif ' ' in path or "'" in path:
  266
+            path = '"%s"' % path
  267
+
256 268
         self.execute('%%run %s' % path, hidden=hidden)
257 269
 
258 270
     #---------------------------------------------------------------------------
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.