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

Fri Aug 12 13:02:13 CDT 2005

Ville Vainio wrote:
>>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.
>
>
> I think that magics, ! and aliases are not "normal python" (remember
> having to use Itpl there etc.) and hence can ignore the convention. As
> far as the normal shells go, how often is \ really used? I always keep
> adding stuff to the same line which works just as well, as there is no
> need to keep the lines "pretty".
>
> The case where being able to use single \ (as opposed \\) in filenames
> is critical is the one where you are copy-pasting long filenames like
> \myfiles\blah\foo\bar.txt to the command line. I've found myself
> starting a normal cmd.exe session for such situations which is a
> hassle.

OK, let's play a little with the options to see where this gets us.  I'll need
some testing help from you, since I can't test any of this here (*nix boxes
don't recognize c:\ as a path).  In iplib.py, fn handle_shell_escape, please
change:

line_out = '%s%s.system("%s")' % (pre,self.name,cmd)

to

line_out = ('%s%s.system(' % (pre,self.name)) + repr(cmd) + ')'

and likewise

line_out = '%s.system("%s")' % (self.name,cmd)

to

line_out = ('%s.system(' % self.name) + repr(cmd)+ ')'

Another possibility is to instead change them to:

line_out = '%s%s.system(r"%s")' % (pre,self.name,cmd)
and
line_out = '%s.system(r"%s")' % (self.name,cmd)

I'm curious as to how these two different approaches work (I'm having a hard
time guessing how the layers of \ escaping will interact, and I can't really
test it here easily).  Let me know what you get from this (or if you see that
the real solution is different).  After knowing that something can be made to
work, we'll see how far to take it.

> If using raw strings is unthinkable in aliases and magics (which I
> believe should not be the case), at least do it for !-constructs.
> OTOH, didn't someone submit a patch a while ago for this kind of "raw"
> commands?

I don't recall such a patch.

Cheers,

f