By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,640 Members | 1,108 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,640 IT Pros & Developers. It's quick & easy.

Raw strings to normal strings conversion?

P: n/a
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
Share this Question
Share on Google+
4 Replies

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.