http://openlook.org/blog/1159 에서 가져온 것을 해석하는 중

중간의 일부를 바꾸어서 내가 읽어오고자 하는 곳에 맞게 변경

def safeunicode(s):
    s = str(s).decode('utf-8')
    try:
        return s.encode('euc-kr').decode('cp949')
    except UnicodeDecodeError:
        return s

위에서 encode('latin-1')으로 되어 있는 것을 encode('euc-kr')으로 바꾸었더니 최소한 pyScripter에서는 한글 출력이 잘 되고 있다.

Test용 스크립트
from kaistfood import *
menu = getmenu(u'동측')
print ', '.join(menu[0])
menu = getmenu(u'서측')
print ', '.join(menu[0])

결과
모닝빵, 딸기잼, 크림스프, 양배추샐러드, 사우전, 토마토, 쌀밥, 두부된장국, 양송이야채볶음, 부추무침, 배추김치
쌀밥, 쇠고기무국, 계란찜, 시금치나물, 알타리김치

한글 처리시 주의사항: pyScripter에서 Edit > File Format > UTF-8 로 해줘야 에러가 생기지 않는다

Posted by trigger
,