View Single Post
Old 07-20-2015, 01:35 PM   #3
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Code:
r'''<p>''''
Four single-quotes in a row -- the first three terminated the string literal, the last one began a new string literal.
You would need to escape it, but as you may have noticed, the backslash stays in the string. This only happens because you are using a raw string literal -- using
Code:
html = re.sub('''<p>' ''', '''<p>\'''', html)
works as expected.
Raw string literals are useful for strings in which you expect to have literal backslashes. That does not apply here.

Double-quotes work too, of course.

If you need to use both single- and double-quotes, make sure to escape whatever your delimiter is.

Last edited by eschwartz; 07-20-2015 at 01:46 PM.
eschwartz is offline   Reply With Quote