convert string to raw string?

Duncan Booth duncan.booth at invalid.invalid
Mon Dec 6 09:55:57 CET 2004


Phd wrote:
> 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?

A raw string is a feature of the syntax of Python. Python gives you several 
ways to write strings: single quoted, double quoted, triple single, triple 
double, and raw versions of these. Once parsed from the source all of these 
simply become objects of type 'str'.

The unicode modifier on a string does produce a different type of object 
internally (type 'unicode'), but the raw modifier does not.

So, perhaps you would like to clarify what you really want to do? Perhaps 
give an example?

If you are getting input from the user, then unless you are doing some 
processing on it to interpret escape sequences the chances are you already 
have what you need to use as a regular expression. If you *are* 
interpreting escape sequences then the answer is you need to not do that 
since the operation isn't really reversible.




More information about the Python-list mailing list