Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Raw strings to normal strings conversion?

Reply
Thread Tools

Raw strings to normal strings conversion?

 
 
Nagarajan
Guest
Posts: n/a
 
      08-23-2007
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?

 
Reply With Quote
 
 
 
 
James Stroud
Guest
Posts: n/a
 
      08-23-2007
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
 
Reply With Quote
 
 
 
 
Nagarajan
Guest
Posts: n/a
 
      08-23-2007
On Aug 23, 1:21 pm, James Stroud <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      08-23-2007
On Thu, 23 Aug 2007 09:21:40 +0000, Nagarajan wrote:

> On Aug 23, 1:21 pm, James Stroud <(E-Mail Removed)> wrote:
>> 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
 
Reply With Quote
 
Nagarajan
Guest
Posts: n/a
 
      08-23-2007
On Aug 23, 2:42 pm, Marc 'BlackJack' Rintsch <(E-Mail Removed)> wrote:
> On Thu, 23 Aug 2007 09:21:40 +0000, Nagarajan wrote:
> > On Aug 23, 1:21 pm, James Stroud <(E-Mail Removed)> wrote:
> >> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
xmlrpclib and binary data as normal parameter strings Rune Froysa Python 3 04-20-2005 09:19 AM
[Maxxum 7D] Dimage RAW Viewer v. Adobe Raw Plugin Alan Browne Digital Photography 3 03-12-2005 04:17 AM
Adobe PS RAW convertor vs Nikon RAW convertor Vlad Gunko Digital Photography 8 01-25-2005 07:43 PM
How raw is RAW format? Editor www.nutritionsoftware.org Digital Photography 4 12-22-2003 07:33 PM



Advertisments