こんにちは、私は次のコードを持っています:python 2.7.12、出力にうまく機能しているpython3を使用して次の問題を回避するにはどうすればよいですか?
from __future__ import print_function
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import pandas as pd
import re
import threading
import pickle
import sqlite3
#from treetagger import TreeTagger
conn = sqlite3.connect('Telcel.db')
cursor = conn.cursor()
cursor.execute('select id_comment from Tweets')
id_comment = [i for i in cursor]
cursor.execute('select id_author from Tweets')
id_author = [i for i in cursor]
cursor.execute('select comment_message from Tweets')
comment_message = [i[0].encode('utf-8').decode('latin-1') for i in cursor]
cursor.execute('select comment_published from Tweets')
comment_published = [i for i in cursor]
:しかし
~/data$ python DBtoList.py
8003
8003
8003
8003
私は次のようにのpython3を使用して同じコードを実行したときに、私が得ました:
~/data$ python3 DBtoList.py
Traceback (most recent call last):
File "DBtoList.py", line 21, in <module>
comment_message = [i[0].encode('utf-8').decode('latin-1') for i in cursor]
File "DBtoList.py", line 21, in <listcomp>
comment_message = [i[0].encode('utf-8').decode('latin-1') for i in cursor]
sqlite3.OperationalError: Could not decode to UTF-8 column 'comment_message' with text 'dancing music ������'
私はこのラインで検索し、私が見つかりました:
"dancing music "
私はコードのpython 2で働いている理由、PythonのPythonの3.5.2は、この行でこの文字を解読することはできないようです確認していない:
comment_message = [i[0].encode('utf-8').decode('latin-1') for i in cursor]
ので、私は提案を感謝したいと思いますこの問題を解決するには、サポートに感謝します。
私は本当にサポートしていただきありがとうございます私はすべての側面を確認します – neo33