Substitution with Hash Values

Steve Holden sholden at holdenweb.com
Sat Apr 20 12:08:31 EDT 2002


"holger krekel" <pyth at devel.trillke.net> wrote ...
> On Sat, Apr 20, 2002 at 02:41:53AM -0000, Jon Ribbens wrote:
> > In article <mailman.1019254077.7316.python-list at python.org>, holger
krekel wrote:
> > > re.sub('\{\{(.*?)\}\}',lambda x: dict[x.group(1)], str)
> >
> > Need a raw string there, i.e.
> >
> >   r"\{\{(.*?)\}\}"
>
> yes, i am sometimes confused by 'raw strings' and 'strings'.
> Could you help by saying why exactly it is needed here?
>
In raw string literals the backspaces are treated almost the same as other
characters, making it easier to generate strings whose values *contain*
backspaces, often needed in regular expressions.

>>> print "this is\na string"
this is
a string
>>> print r"this is\na string"
this is\na string

regards
 Steve







More information about the Python-list mailing list