Search code examples
pythonipythonwildcardargparseglob

Disabling wildcard expansion in IPython?


Does anyone know of a way to disable wildcard expansion in IPython?

For instance, with Python 3 / IPython 2.1.0, it would be nice to be able to %run or %debug a script using something like the following:

%run script.py "files1*.txt" "files2*.txt"

Running the same command outside of IPython will work just fine, however, IPython automatically expands the wildcard expressions, even when they are surrounded in quotes, thus results in one long list of input arguments.

It would be nice to be able to debug in IPython, but this makes it difficult in this particular scenario. Any idea if it's possible to disable the wildcard expansion?


Solution

  • The inline ? documentation for %run says:

    Arguments are expanded using shell-like glob match. Patterns '*', '?', '[seq]' and '[!seq]' can be used. Additionally, tilde '~' will be expanded into user's home directory. Unlike real shells, quotation does not suppress expansions. Use two back slashes (e.g. \\*) to suppress expansions. To completely disable these expansions, you can use -G flag.

    So, either use the -G flag, or double-backslash-escape the *

    You can see the same docs (formatted differently) online with the full docs on the run magic.