1 Replies - 243 Views - Last Post: 28 October 2013 - 10:43 PM Rate Topic: *---- 1 Votes

#1 dhanya.lk2011  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-October 13

Malayalam output is not written in output file in python3 in windows

Posted 23 October 2013 - 09:24 AM

fw = codecs.open('outputfile.txt','wb',encoding='utf-8')


--------------------------------------------------


if((unidata[i]==U'\u0d46' and unidata[i-1]==U'\u0d28') and (unidata[i+1]==U'\u0d24') and (unidata[i+2]==U'\u0d4d')):
                                        print ('code 1')
                                        if(var==1):
                                            x=unidata[0:i-1]+U'\u0d7b'+ ' + '+U'\u0d0e'+unidata[i+1:len(unidata)]
                                            first_word=unidata[0:i-1]+U'\u0d7b'
                                            sec_word=U'\u0d0e'+unidata[i+1:len(unidata)]
 fw.write('\t')
                fw.write(str(first_word.encode('UTF-8')))
                fw.write('\t')
   
                fw.write('\n')




output is correctly got in terminal.but its not printed in outputfile...still there is no er
or is displaying.

help me to resolve

This post has been edited by modi123_1: 23 October 2013 - 09:25 AM
Reason for edit:: please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Malayalam output is not written in output file in python3 in windows

#2 witeboy724  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 29
  • Joined: 21-June 12

Re: Malayalam output is not written in output file in python3 in windows

Posted 28 October 2013 - 10:43 PM

There's more than one way to write a unicode file in Python, and using codecs.open() is the best way to avoid (often hidden) errors. When you codecs.open with a 'utf-8' argument, it expects unicode and will encode everything you output as such.

Meaning if you are using codecs.open to write your file, don't call text.encode('UTF-8') yourself in line 14. This is what you would use if you were doing a normal open() rather than a codecs.open.

At least that's what I got from this exchange: Stack Overflow - Writing Unicode to Text File
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1