Making a string raw

Greg Krohn infinitystwin.SPAM at
Tue Dec 4 23:13:22 CET 2001

"Rune Nesheim" <rune at> wrote in message
news:59333ea6.0112041014.7908e9ab at
> Could any of you lot tell me how to convert a string stored in
> avariable to a raw string?
> I know I create a raw string this way:
> spam = R'hello'
> But if I don't know what the string is going to contain, for example
> if I fetch from a Tkinter text-box to the variable 'eggs' and want to
> convert 'eggs' into a raw string.

If those other posters misinterpereted your question and you have a string
with embedded newlines, backslashes, etc. and you want them represented as
\n, \\, etc., try this:

>>> spam = 'spam\tand\\eggs'
>>> print spam
spam    and\eggs
>>> spam = `spam`
>>> print spam

I don't know the name of that character, but it's right above Tab on my


More information about the Python-list mailing list