473,895 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7520
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.uc la.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.uc la.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.net wrote:
On Thu, 23 Aug 2007 09:21:40 +0000, Nagarajan wrote:
On Aug 23, 1:21 pm, James Stroud <jstr...@mbi.uc la.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
3162
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 returned as "t" or "f". All other types, including arrays are | returned as strings formatted in the same default PostgreSQL manner | that you would see in the psql program.
6
3182
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 similar.
17
7413
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 interchangeable in all circumstances (as long as they're paired) so there's no overloading to muddy the language. Of course there could be some interesting problems with current code that doesn't make a distinction, but it would be dead easy to fix...
2
3111
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', 'replace') and of course I get an error like: Traceback (most recent call last): File "<stdin>", line 1, in ?
8
3881
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 = CreateObject("WScript.Shell") strCategoryList = objWSHShell.RegRead_ ("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Categories\MasterList")
4
1415
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 that seem to deal with the syntax/character types that am I using. Below is a segment of my code which is intended to convert an integer to an array of ASCII digits: > > char * inttoascii(int val)
7
1691
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 exposed the DA layer through a we service and store the connection string in the web.config file. Any recommendations? Thanks.
5
6813
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. Thanx
1
2453
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 the case statement that causes the trouble.. i could post the whole procedure but there is no point. similar case statements as the following one exisst in the procedure that save in the same memory segment (but at dif offest) floats, Q_UINT8 and...
0
9836
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10473
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9651
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5865
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4693
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4288
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.