473,396 Members | 1,813 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,396 software developers and data experts.

Translate escaped characters in a string

-
Hi

I have an application that reads the arguments sent to the script. If
an user enters a text like "Line 1\nLine2" (\n is slash+n, and not
LF), I would like to use \n and other supported escape sequences when
I write the text to a file.

Is there a way to do this, other than writing my own parser?
Jul 18 '05 #1
2 1522
On 2 Apr 2004 15:57:59 -0800, - wrote:
(\n is slash+n, and not LF)
No, "\n" is backslash + n. Slash + n would be "/n".
I would like to use \n and other supported escape sequences when I
write the text to a file.


Once you know the proper name for the character you're talking about,
you can find modules like this one:

<http://www.crazy-compilers.com/py-lib/shellwords.html>

which may be helpful.

--
\ "The best is the enemy of the good." -- Voltaire |
`\ |
_o__) |
Ben Finney <http://bignose.squidly.org/>
Jul 18 '05 #2
> I have an application that reads the arguments sent to the script. If
an user enters a text like "Line 1\nLine2" (\n is slash+n, and not
LF), I would like to use \n and other supported escape sequences when
I write the text to a file.

Is there a way to do this, other than writing my own parser?


I know there's an easier way to do it, but the below works...
import encodings
print encodings.codecs.escape_decode('hello\\nworld')[0] hello
world


If the stings are escaped normally, the above will produce what you want.

- Josiah
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
2
by: Vance Kessler | last post by:
We are trying write a new ASP.NET page to work with an existing stateless ASP application. The ASP application creates a cookie and of course stores the cookie values as escaped strings (using the...
0
by: DaveS | last post by:
I have a web service that returns one parameter which is defined as a string. In this string is returned an XML document (due to the fact that I have a large amount of data to pass back to the...
13
by: Oxns | last post by:
Hi, Can anyone point me at the class to convert a string so that it displays escaped chars as \r, \n etc. please Its done in the 2005 debugger so I hope its available as a class ??. Thanks...
3
by: metaperl | last post by:
I downloaded a file which has a space in the filename. I want to run a shell unzip on it, but it fails in my current code: syscmd = "cd %s ; unzip %s" % (self.storage.input, file.basename())...
12
by: Torsten Bronger | last post by:
Hallchen! I need some help with finding matches in a string that has some characters which are marked as escaped (in a separate list of indices). Escaped means that they must not be part of...
1
by: bwilcoxis | last post by:
I have an externally generated xml file that correctly escaping characters such as apostrophes and quotes and rendering them as &amp;#8217; and &amp;#39; the xml file has the following...
9
by: Michael Goerz | last post by:
Hi, I am writing unicode stings into a special text file that requires to have non-ascii characters as as octal-escaped UTF-8 codes. For example, the letter "Í" (latin capital I with acute,...
0
by: hash4sp | last post by:
Hello ! I have a problem with the escaped charactes which I am sending to an aspx page. This is javascript escaped characters %u0646%u062A%u0627%u0626%u062C%20%u0627%u0644%u062 8%u062D%u062B ...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
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...
0
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...

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.