469,588 Members | 2,875 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,588 developers. It's quick & easy.

Raw strings to normal strings conversion?

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?

Aug 23 '07 #1
4 6915
Nagarajan wrote:
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
Aug 23 '07 #2
On Aug 23, 1:21 pm, James Stroud <jstr...@mbi.ucla.eduwrote:
Nagarajan wrote:
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.
Here is an example:
>rawstr = r'a\nb'
print rawstr
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.

Aug 23 '07 #3
On Thu, 23 Aug 2007 09:21:40 +0000, Nagarajan wrote:
On Aug 23, 1:21 pm, James Stroud <jstr...@mbi.ucla.eduwrote:
>Nagarajan wrote:
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.

Here is an example:
>>rawstr = r'a\nb'
print rawstr
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
Aug 23 '07 #4
On Aug 23, 2:42 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Thu, 23 Aug 2007 09:21:40 +0000, Nagarajan wrote:
On Aug 23, 1:21 pm, James Stroud <jstr...@mbi.ucla.eduwrote:
Nagarajan wrote:
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.
Here is an example:
>rawstr = r'a\nb'
print rawstr
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
Thanks a lot.

Aug 23 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Stefan Weiss | last post: by
6 posts views Thread by Desmond | last post: by
17 posts views Thread by Gordon Airport | last post: by
2 posts views Thread by Bill Janssen | last post: by
4 posts views Thread by Lafer | last post: by
7 posts views Thread by Gary Brizard | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.