Making a string raw
Greg Krohn
infinitystwin.SPAM at IS.BAD.yahoo.com
Tue Dec 4 17:13:22 EST 2001
"Rune Nesheim" <rune at nesheim.net> wrote in message
news:59333ea6.0112041014.7908e9ab at posting.google.com...
> 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
'spam\tand\\eggs'
I don't know the name of that character, but it's right above Tab on my
keyboard.
HTH,
greg
More information about the Python-list
mailing list