[IPython-user] More Windows questions part 2 - \/ characters revisited

Fernando Perez Fernando.Perez at colorado.edu
Fri Aug 12 08:30:08 CDT 2005

Ville Vainio wrote:
> A little blast from the past:
> On 6/22/05, Jerry McRae <qrs0xyc02 at sneakemail.com> wrote:
>>#3. And while I agree \ as an escape character is necessary, IPython is
>>a command interpreter.  I think IPython should be reading raw strings
>>as its commands.  I know I will have to live with using \ when
> There was a disagreement about this a while ago, but there is a
> compromise that should at least be considered: when prefixed with !,
> ipython should definitely escape the backslashes when converting the
> command:
> [C:\]|12> !dir c:\
> --------------------------------------------------------
>    File "<console>", line 1
>      __IP.system("dir c:\")
>                           ^
> SyntaxError: EOL while scanning single-quoted string
> Or perhaps more correctly convert it to __IP.system(r"dir c:\")
> (i.e. raw string)

Mmh.  I actually think I disagree, and rather that you discovered a bug.  In 
Python, a trailing backslash is used to indicate line continuations:

In [1]: 5+\
    ...: 3
Out[1]: 8

But magics and ! short-circuit this mechanism and try to evaluate immediately:

In [2]: cd \
    File "<console>", line 1
      ipmagic("cd \")
SyntaxError: EOL while scanning single-quoted string

hence the error.  I would argue that what's broken is that line-continuations 
are not being honored by magics/! as they should, which is inconsistent with 
the rest of python and the behavior of normal shells.

So I think the right fix would be to change !/% to honor line continuation 
marks like the rest of the language, so that you could input

In[1]: !my very long command with\
   ...: a lot of arguments\
   ...: and still more

And get proper execution.



More information about the IPython-user mailing list