re quiz
David C. Ullrich
dullrich at sprynet.com
Thu Jun 12 10:13:11 EDT 2008
On Thu, 12 Jun 2008 14:12:31 +0200, Peter Otten <__peter__ at web.de>
wrote:
>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:
Heh - I shoulda thought of that, determining which
ones cause trouble by checking to see which ones
cause trouble. Thanks.
>>>> 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
David C. Ullrich
More information about the Python-list
mailing list