-1

I am trying to using google translator and translate it is happening when I choosing the output language English or Hindi but when select odia.

from google_trans_new import google_translator  

translator = google_translator()
  
translate_text = translator.translate('สวัสดีจีน',lang_tgt='or')  

file = open ('samp.txt','w')

file.write(translate_text)

file.close()

print(translate_text)

Output

eturn codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-6: character maps to <undefined>

How to solve this

1 Answers1

0

you have to set encoding to utf-8 for open like this

file = open('samp.txt','w',encoding='utf-8')

You can read more about encoding here, error for you program is wrong coding which is system dependent for open. When you are running the code on Linux there will be no error. But, when running on Windows you need to explicitly mention the encoding parameter.

Kabilan Mohanraj
  • 1,856
  • 1
  • 7
  • 17
gaurav
  • 1,281
  • 1
  • 13
  • 25