convert string to raw string?

Terry Reedy tjreedy at udel.edu
Mon Dec 6 09:41:55 CET 2004


"Phd" <pyjunk at shaw.ca> wrote in message 
news:39Usd.439257$nl.135440 at pd7tw3no...
> Hi,
>
> I'm writing a regex related program that lets the user supplies the regex 
> definition. Is there an easy way to convert a string into a raw string?

There ain't no such thing as raw strings.  Just 'raw' string *literals*, 
where 'raw' denotes a mode for converting the literal in the code (which is 
*not* a Python string) into a Python string.

Perhaps what you want is something like eval("r'%s'" % (raw_input(),)), 
assuming no ' or " in user input.

Terry J. Reedy






More information about the Python-list mailing list