2 Replies - 933 Views - Last Post: 18 March 2012 - 09:54 AM Rate Topic: -----

#1 mridulpv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 05-September 10

Unicode to text file

Posted 18 March 2012 - 02:14 AM

I want to make text file from Unicode in 'Malayalam' language.
Unicode of first alphabet in Malayalam is 0D05 (hex)
s = u'\x0d05\n'
sutf8 = s.encode('UTF-8')
open('text.txt', 'w').write(sutf8)



it read only first two digit that is 0d
and in the file text.txt first line is blank and second line contain 05

replace 0d05 by 76 (the Unicode of English alphabet 'v' is 0076 (hex)) then the out put file contain letter 'v'
s = u'\x76\n'
sutf8 = s.encode('UTF-8')
open('text.txt', 'w').write(sutf8)



Is This A Good Question/Topic? 0
  • +

Replies To: Unicode to text file

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: Unicode to text file

Posted 18 March 2012 - 05:42 AM

Are you on Windows? In that case you will need to open the file in binary mode:
open('text.txt', 'wb')


Was This Post Helpful? 0
  • +
  • -

#3 mridulpv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 05-September 10

Re: Unicode to text file

Posted 18 March 2012 - 09:54 AM

got it!

\x is replaced by \u
\u is used for 4 digit

s = u'\u0d05\n'
sutf8 = s.encode('UTF-8')
open('text.txt', 'w').write(sutf8)



now i can convert Unicode to Malayalam alphabets.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1