re quiz

Peter Otten __peter__ at web.de
Thu Jun 12 08:12:31 EDT 2008


David C. Ullrich wrote:

> (Or is there a function somewhere that will convert
> r"\remark{Hint}" to r"\\remark{Hint}" for me, and
> do the same for precisely the escpapes referred to
> in the "and so forth"?)

I think you just have to escape the backslash:

re.sub(pattern, replacement_string.replace("\\", "\\\\"), s)

Anyway here's the list of troublemakers:

>>> def means_trouble(c):
...     try:
...             return re.sub("x", "\\" + c, "x") != "\\" + c
...     except:
...             return True
...
>>> [c for c in map(chr, range(256)) if means_trouble(c)]
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\\', 'a', 'b', 'f', 'g', 'n', 'r', 't', 'v']


Peter 




More information about the Python-list mailing list