473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 7480
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stefan Weiss | last post by:
Hi. The manual for pg_fetch_result() reads: | All forms of integer types are returned as integer values. All | forms of float, and real types are returned as float values. Boolean | is...
6
by: Desmond | last post by:
Can someone please tell me how to concatanate to strings like this please $name = $_POST; $from = $_POST; $headers = "From: $name $from\r\n"; i beleve in C there is a strcat() is this...
17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
2
by: Bill Janssen | last post by:
I've encountered an issue dealing with strings read from files. I read a line from a file, then try to print it out as an ASCII string: line = fp.readline() print line.encode('US-ASCII',...
8
by: Alphaboomer | last post by:
I'm using the following code to retrieve a list of all the Categories used by Microsoft Outlook: sub test() Dim objWSHShell As Object Dim strCategoryList As Variant Set objWSHShell =...
4
by: Lafer | last post by:
Hello, I am attempting to write a terminal interface program using PowerPC Assembly/C, where I am using an integer-to-ASCII conversion algorithm. Unfortunately, I have run into some difficulties...
7
by: Gary Brizard | last post by:
OK. For an n-tier architecture, where is the best place to store the connection string for the DA layer? I don't want to use the reg. Can't use a app.config for a dll. For other projects I...
5
by: tilmann | last post by:
Is there a possibility to concert a string, which is in a column defined as 'FOR BIT DATA', in a normal string, so that i can use the normal string functions? I'm using DB2 V7.2 on z/OS. ...
1
by: nass | last post by:
hello everyone.. i am not sure what is wrong - never liked strings anyway! my problem is that i am trying to save a QCstring in a shared memory segment and i get a segmentation fault.. here is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.