Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: ulkir
Added: May 1, 2020 1:42 PM
Views: 125
  1. # -*- encoding: utf-8 -*-
  2.  
  3. # converting a unknown formatting file in utf-8
  4.  
  5. import codecs
  6. import commands
  7.  
  8. file_location = "jumper.sub"
  9. file_encoding = commands.getoutput('file -b --mime-encoding %s' % file_location)
  10.  
  11. file_stream = codecs.open(file_location, 'r', file_encoding)
  12. file_output = codecs.open(file_location+"b", 'w', 'utf-8')
  13.  
  14. for l in file_stream:
  15.     file_output.write(l)
  16.  
  17. file_stream.close()
  18. file_output.close()