MeCabを利用して、「私はペンを持っています」から表層文字列を出力したいのですが、下記のようにエラーになってしまいます。
「Traceback (most recent call last):
File "test.py", line 8, in <module>
print(result.surface)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udc92' in position 2: surrogates not allowed」
コードは以下の通りです。
実行はVSCODEのターミナルから「python test.py」と打って実行しております。
import MeCab t = MeCab.Tagger() result = t.parseToNode('私はペンを持っています。') while result: f = result.feature p = f.split(',')[0] print(result.surface) result = result.next
解決策が分からず、ご教示いただけると幸いです。🙇
OS:Mac
環境:venv
エディタ:VScode
まだ回答がついていません
会員登録して回答してみよう