簡體   English   中英

python:unicodeEncodeError:'charpmap'編解碼器無法編碼字符'\\ u2026'

[英]python : unicodeEncodeError: 'charpmap' codec can't encode character '\u2026'

我嘗試分析從高音揚聲器獲得的一些鳴叫,但是,如果您有任何想法,似​​乎似乎存在編碼問題。

import json

#Next we will read the data in into an array that we call tweets.
tweets_data_path = 'C:/Python34/TESTS/twitter_data.txt'

tweets_data = []
tweets_file = open(tweets_data_path, "r")


for line in tweets_file:
    try:
        tweet = json.loads(line)
        tweets_data.append(tweet)
    except:
        continue

print(len(tweets_data))#412 tweets
print(tweet)

我弄錯了:在編碼返回編解碼器中的文件“ C:\\ Python34 \\ lib \\ encodings \\ cp850.py”,第19行。charmap_encode(input,self.errors,encoding_map)[0] unicodeEncodeError:'charpmap'編解碼器可以' t在位置1345編碼字符'\\ u2026':字符映射到未定義

在工作中,我沒有收到錯誤,但是我有python 3.3,它會有所作為嗎?

- - -編輯

@MarkRamson的評論回答了我的問題

打開文件時應指定編碼:

tweets_file = open(tweets_data_path, "r", encoding="utf-8-sig")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM