473,405 Members | 2,310 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,405 software developers and data experts.

How to read strings cantaining escape character from a file and useit as escape sequences?

How to read strings cantaining escape character from a file and use it
as escape sequences?

for example, a file 'unicodes.txt' has contents:

\u0050\u0079\u0074\u0068\u006f\u006e

Now,
>>file = open('unicodes.txt')
line = file.readline()
line
'\\u0050\\u0079\\u0074\\u0068\\u006f\\u006e\n'
>>print line
\u0050\u0079\u0074\u0068\u006f\u006e

But I want to get a string:

"\u0050\u0079\u0074\u0068\u006f\u006e"

How do you make it?

Dec 1 '07 #1
3 6465
slomo <sl*****@gmail.comwrote:
>>>print line
\u0050\u0079\u0074\u0068\u006f\u006e

But I want to get a string:

"\u0050\u0079\u0074\u0068\u006f\u006e"

How do you make it?
line.decode('unicode-escape')
Dec 1 '07 #2
WOW! Great! Thanks, Duncan.
On 12¿ù2ÀÏ, ¿ÀÀü12½Ã33ºÐ, Duncan Booth <duncan.bo...@invalid.invalidwrote:
slomo <slim...@gmail.comwrote:
>>print line
\u0050\u0079\u0074\u0068\u006f\u006e
But I want to get a string:
"\u0050\u0079\u0074\u0068\u006f\u006e"
How do you make it?

line.decode('unicode-escape')
Dec 1 '07 #3
John Machin wrote:
Amazing what you can find in obscure corners of the obscure docs!
BTW, how many folks know what "bijective" means ?
Everyone that can read and is smart enough to enter "bijective" into
Wikipedia search.

Regards,
Björn

--
BOFH excuse #25:

Decreasing electron flux

Dec 2 '07 #4

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

Similar topics

6
by: Paul Watson | last post by:
How can I get the escapes from a command line parameter interpreted? The user provides a string on the command line. The string might contain traditional escapes such as \t, \n, etc. It might...
16
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
6
by: los | last post by:
Hi, I've created a web application using struts. I am trying to solve an issue where in one of the forms where I want to allow the values inserted to be special characters from other languages,...
6
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being...
8
by: collinm | last post by:
hi we use linux and c language under bash i do echo -e \\000\\000\\000\\000\000\\001Z00\\002AA LINUX \\004 >/dev/ttyS2 that send command to a led display (alpha sign communication)
2
by: junky_fellow | last post by:
N869 " Each of these escape sequences shall produce a unique implementation-defined value which can be stored in a single char object. The external representations in a text file need not be...
15
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
4
by: JJ | last post by:
Is there a way of checking that a line with escape sequences in it, has no strings in it (apart from the escape sequences)? i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it a...
11
by: globalrev | last post by:
http://www.pygame.org/docs/ref/mixer.html import pygame #pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=3072) //it complained abiout words= so i guess its only the nbrs...
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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,...
0
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...

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.