r'\' - python parser bug?

Duncan Booth me at privacy.net
Mon Jun 7 05:52:58 EDT 2004


michael at foord.net (Fuzzyman) wrote in 
news:8089854e.0406070108.72739647 at posting.google.com:

> I've written a command line tool called filestruct that compares a
> file structure to a previous state and records the changes (for
> remotely syncing directories - you only have to transfer the changes
> and then  filestruct will make the changes). If you give it a windows
> path ending in \" then python interprets it *wrongly*....

Not that you ever need to give a well written script a path ending in \"? 
Why not just give it the directory without the spurious path separator?

> 
> e.g.
> D:\Python Projects\directory change >>> filestruct.py compare
> "D:\Python Projects\" b:\test.txt b:\test.zip
> filestruct needs at least three arguments when run from the command
> line. See :
> filestruct.py ?
> 
> The python interpreter assumes that the entirely valid windows path
> supplied at the command line actually contains an escaped quote..... I
> may have to write a new command line parser to correct this python
> 'feature'.....
> 
Python here seems to be in complete agreement with Microft, or at least 
with their C compiler (not entirely suprising since that's what Python 
uses). The quote is indeed escaped:

C:\temp>type t.c
#include <stdio.h>

int main(int argc, char **argv)
{
    int i;
    for (i = 0; i < argc; i++)
    {
        printf("arg %d= %s\n", i, argv[i]);
    }
}

C:\temp>t "c:\Program Files\" c:\temp
arg 0= t
arg 1= c:\Program Files" c:\temp

C:\temp>




More information about the Python-list mailing list