Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'syntax': 0.04; '-*-': 0.07; 'continuation': 0.07; 'skip:u 30': 0.07; 'string': 0.09; 'properly.': 0.09; 'throws': 0.09; 'true)': 0.09; 'codec': 0.16; 'exited': 0.16; 'fine.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:Problem': 0.16; 'subject:UTF': 0.16; 'wrote:': 0.18; 'trying': 0.19; "skip:' 30": 0.19; 'example': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'byte': 0.24; 'bytes': 0.24; "shouldn't": 0.24; 'text.': 0.24; 'unicode': 0.24; 'question': 0.24; 'skip:" 40': 0.26; 'code:': 0.26; 'header:In- Reply-To:1': 0.27; 'characters': 0.30; 'prints': 0.31; 'file': 0.32; 'text': 0.33; '(most': 0.33; 'skip:# 10': 0.33; 'problem': 0.35; "can't": 0.35; 'display': 0.35; 'received:84': 0.35; 'i.e.': 0.36; 'marks': 0.36; 'hi,': 0.36; 'error.': 0.37; 'to:addr:python- list': 0.38; 'skip:- 10': 0.38; 'recent': 0.39; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'skip:u 10': 0.60; 'email addr:gmail.com': 0.63; 'here': 0.66; 'header :Reply-To:1': 0.67; 'invalid': 0.68; 'press': 0.70; 'reply-to:no real name:2**0': 0.71; '8bit%:100': 0.72; 'analysis': 0.75; '8bit%:77': 0.84; 'reply-to:addr:python.org': 0.84; 'skip:\xef 10': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=RZapVTdv c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=K2DDQYBT4xIA:10 a=26ZNp2QZd94A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=Mx5Ya_LKPEMA:10 a=pGLkceISAAAA:8 a=icRjiP0AgDGLxuLN6JIA:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 X-AUTH: mrabarnett:2500 Date: Sat, 29 Jun 2013 17:12:59 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: python-list@python.org Subject: Re: MeCab UTF-8 Decoding Problem References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372522376 news.xs4all.nl 15963 [2001:888:2000:d::a6]:34409 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49432 On 29/06/2013 12:29, fobos3@gmail.com wrote: > Hi, > > I am trying to use a program called MeCab, which does syntax analysis on Japanese text. The problem I am having is that it returns a byte string and if I try to print it, it prints question marks for almost all characters. However, if I try to use .decide, it throws an error. Here is my code: > > #!/usr/bin/python > # -*- coding:utf-8 -*- > > import MeCab > tagger = MeCab.Tagger("-Owakati") This is a bytestring. Are you sure it shouldn't be a Unicode string instead, i.e. u'MeCabで遊んでみよう!'? > text = 'MeCabで遊んでみよう!' > > result = tagger.parse(text) > print result > > result = result.decode('utf-8') > print result > > And here is the output: > > MeCab �� �� ��んで�� �� ��う! > > Traceback (most recent call last): > File "test.py", line 11, in > result = result.decode('utf-8') > File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode > return codecs.utf_8_decode(input, errors, True) > UnicodeDecodeError: 'utf8' codec can't decode bytes in position 6-7: invalid continuation byte > > > ------------------ > (program exited with code: 1) > Press return to continue > > Also my terminal is able to display Japanese characters properly. For example print '日本語' works perfectly fine. > > Any ideas? >