By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,922 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,922 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.