Raw strings to normal strings conversion?

N

Nagarajan

Is there a way by which I could obtain normal string form of a raw
string.
XML CDATA is returned as raw string. But I need the string to actually
escape special chars.

Any idea?
 
J

James Stroud

Nagarajan said:
Is there a way by which I could obtain normal string form of a raw
string.
XML CDATA is returned as raw string. But I need the string to actually
escape special chars.

Any idea?

This doesn't seem clear. Perhaps an example of what you get and what you
want it converted to.

In the meantime, see if urllib.unquote() doesn't do what you need.

James
 
N

Nagarajan

This doesn't seem clear. Perhaps an example of what you get and what you
want it converted to.

Here is an example:a\nb

Now I need this newstr to actually interpret '\n', in other words, to
behave like a normal string.
In the meantime, see if urllib.unquote() doesn't do what you need.

James

And yes, unquote doesn't help.
 
M

Marc 'BlackJack' Rintsch

Here is an example:
a\nb

Now I need this newstr to actually interpret '\n', in other words, to
behave like a normal string.

So you get a string with Newlines as two character sequence \n. You don't
get "raw" strings. That is a concept in Python source code. When the
program is running there is no such distinction between "raw" and "normal"
strings. Here's a solution:

In [87]: print r'a\nb'
a\nb

In [88]: print r'a\nb'.decode('string-escape')
a
b

Ciao,
Marc 'BlackJack' Rintsch
 
N

Nagarajan

Here is an example:

Now I need this newstr to actually interpret '\n', in other words, to
behave like a normal string.

So you get a string with Newlines as two character sequence \n. You don't
get "raw" strings. That is a concept in Python source code. When the
program is running there is no such distinction between "raw" and "normal"
strings. Here's a solution:

In [87]: print r'a\nb'
a\nb

In [88]: print r'a\nb'.decode('string-escape')
a
b

Ciao,
Marc 'BlackJack' Rintsch

Thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top