r'\' - python parser bug?
Fuzzyman
michael at foord.net
Mon Jun 7 05:08:37 EDT 2004
Per Erik Stendahl <berra at psyket.com> wrote in message news:<mailman.403.1085747267.6949.python-list at python.org>...
> Fuzzyman wrote:
>
> [snip]
>
> > Yeah.. that's not an annoying feature.... I mean no-one would ever
> > want to use strings to hold Windows pathnames in......
>
> So I guess I'm not the only one who tries to use a special class for
> paths as much as possible then? ;-)
>
> Working with pathnames as strings is painful, IMHO. Using objects makes
> it much clearer, for me anyway.
>
> path = Path(r'C:\documents\my\file.txt')
> if path.isfile():
> shutil.copyfile(path.get(), ....)
> print path.dir()
> other_path = path.parent() / 'subdir' / 'otherfile' + '.txt'
> ...
>
>
> Regards,
>
> Per Erik Stendahl
*However* - more seriously - if you create a command line tool, then
python *wrongly* handles pathnames.
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*....
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'.....
Regards,
Fuzzyman
http://www.voidspace.org.uk/atlantibots/pythonutils.html
More information about the Python-list
mailing list