[IPython-user] More Windows questions part 2 - \/ characters revisited
vivainio at gmail.com
Wed Jun 22 12:18:36 CDT 2005
On 6/22/05, Jerry McRae <qrs0xyc02 at sneakemail.com> wrote:
> I think we are talking apples and apricots here. ;)
> SOMETIMES Windoze will convert / to \, as in the cd command, but very
> seldom. And if you try to use / in the cd command (in cmd.exe) ,
> autocomplete does NOT work.
The conversion doesn't actually take place - all the windows system
calls accept / as path separator, just as with python. As I said
previously, the problem are programs that on seeing / think a-ha, a
command line switch starts.
> #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
> executing DOS (cmd.exe) commands, but I see no reason to escape
> anything except strings. "\" is not a valid token or operator and has
Ok, now I have to backtrack a bit. IIRC (it's been almost a year), the
backslashes were not necessary is python escape character after all,
but as escape characters for allowing weird stuff in filenames, such
as space, [, etc. You could try removing the support for backslash
escaping by hacking the completer to surround the string to be
expanded with quotes if there are spaces or whatnot in the
file/directory name (which is what cmd.exe does). And only support \"
for escaping a quote. The code is well localized within the completer
part, so you should take a look.
> Leading me to the third domain (#1). One cannot use the format you
> mentioned with DOS commands. !type \\tmp/a/b/c.txt will NOT work.
Really? You tried it? It worked with some commands at least. What
error did you get? I'm on my home linux machine ATM...
> None of this matters in the Python command line, or if you don't often
> execute windows commands, but that is SO POWERFUL when combined with
> IPython's other features that I rarely ever use the CMD prompt
> anymore. (Oh, unless you use a real operating system, then you
> probably wish IPython could replace all the features of your shell)
Actually, I use ipython as cmd.exe replacement all the time. I just
don't use any DOS commands because I'm using unxutils which allows me
to use all the familiar unix command line tools.
> Proposal #1: input to IPython should be RAW strings, leaving the
> escape character '\' to be interpreted within the strings
> that are parsed and the strings passed as is if calling
Actually, the \ won't need to be interpreted even then because the
execution of the actual contained python code does the interpretation.
> Proposal #2: change the character used for autocomplete when a
> directory name is found from '/' to os.sep.
> Drawbacks: None. Will have absolutely no effect for Linux users.
> Benefits: easier path autocompletion for Windoze users.
> Effort: should be one line change.
It's going to be much more work, since you have to hack the completer
as I explained above. It's not an overwhelming effort of course, but
the readline can be a harsh mistress so you might need to poke it a
bit more than you would normally think :-).
I'd still oppose the idea of forcing the use of os.sep for completion,
because some of the commands I invoke don't support \ at all (they
think it's a quote). It would need to be configurable, at least.
> My intentions are that these proposals sane, reasonable, simple, and
> have no effect on Linux users and are worthy of consideration.
Yeah, the consideration is never a problem, it's the fact that code
needs to be written :-). Back then I chose the backslash as the escape
for spaces in filenames because that's how bash does it and it seemed
easyish to implement, but using quotes isn't bad either. The patch
doesn't need to come from a windows user BTW, because quotes will work
w/ Linux commands as well. So if it's tested and works on Linux, it
will work in Windows as well.
So go ahead and go poke the code; it's in iplib.py, method signature
is "file_matches(self,text)". I might be able to help if you have any
questions, though I've probably repressed most memories regarding the
gory details of readline ;-).
More information about the IPython-user