2013. 9. 10.

Load non utf-8 file and display QTextEdit at pyhon



1) declare coding

    # -*- coding: utf-8 -*-

2) load file  ( let's asume file is  'euc-kr')
   
     fileData = f.read()  # read from file


3) decode  to unicode
    unicodedata = unicode(fileData,"euc-kr")

4) encode 'utf-8'

    utf8data = unicodedata.encode("utf-8")

5) set text
    editor.setPlainText(utf8data)  # editor is QTextEdit


** summary ** : converting flow

    EUC-KR --->   UNICODE --> UTF-8

Enhanced by Zemanta

댓글 없음:

댓글 쓰기