471,334 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,334 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 5797
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,
Bjrn

--
BOFH excuse #25:

Decreasing electron flux

Dec 2 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Paul Watson | last post: by
16 posts views Thread by Paul Prescod | last post: by
8 posts views Thread by collinm | last post: by
2 posts views Thread by junky_fellow | last post: by
15 posts views Thread by pkaeowic | last post: by
4 posts views Thread by JJ | last post: by
11 posts views Thread by globalrev | last post: by
reply views Thread by rosydwin | last post: by

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.