backslash woes........
Roman Suzi
rnd at onego.ru
Tue Jul 10 06:36:58 EDT 2001
On Tue, 10 Jul 2001, Martin Franklin wrote:
> Hi all,
>
>
> I am having trouble with windows path names (i'm a UNIX'ite)
> I want to replace the common prefix of a list of file names
> with a relative stub (./) I have this...
>
> def _removePrefix(self, fullfile):
> print r'%s' %fullfile
what about
re.escape(fullfile)
re.escape(os.sep)
? Does it cure the situation?
> filename=re.sub(r'%s' %self.prefix, r'%s' %os.sep, r'%s' %fullfile)
> print filename
> return filename
>
>
> Where fullfile is the - full filename...
> and self.prefix is the os.commonprefix()
>
>
> Currently I get an error:-
>
> traceback (most recent call last):
> File "c:\python21\lib\lib-tk\Tkinter.py", line 1285, in __call__
> return apply(self.func, args)
> File "r:\src\python\squeeze\dev\makesqueeze.py", line 161, in Finish
> Squeeze(platFileList, open(filename, 'w'), self.prefix_or_path.get(),
> config)
> File "r:\src\python\squeeze\dev\Squeeze.py", line 58, in __init__
> self._apply(file)
> File "r:\src\python\squeeze\dev\Squeeze.py", line 137, in _apply
> file = self._removePrefix(fullfile)
> File "r:\src\python\squeeze\dev\Squeeze.py", line 151, in _removePrefix
> filename=re.sub(r'%s' %self.prefix, r'%s' %os.sep, r'%s' %fullfile)
> File "c:\python21\lib\sre.py", line 63, in sub
> return _compile(pattern, 0).sub(repl, string, count)
> File "c:\python21\lib\sre.py", line 136, in _compile
> raise error, v # invalid expression
> error: bogus escape: '\\x'
>
>
> I don't understand this as I am (trying) to use raw strings everywhere.....
> (that's what the DOC's told me to do...)
>
>
> 'Course on UNIX it all works perfectly well with or without the raw strings;-)
>
>
>
>
> Hope _you_ can help
>
> Martin
>
Sincerely yours, Roman A.Suzi
--
- Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
More information about the Python-list
mailing list