top_100 是一个 mongodb 集合:
以下代码:
x=[]
thread=[]
for doc in top_100.find():
x.append(doc['_id'])
db = Connection().test
top_100 = db.top_100_thread
thread = [a["thread"] for a in x]
for doc in thread:
print doc
给出了这个错误:
Traceback (most recent call last):
File "C:\Users\chatterjees\workspace\de.vogella.python.first\src\top_100_thread.py", line 21, in <module>
print doc
File "C:\Python27\lib\encodings\cp1252.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u03b9' in position 10: character maps to <undefined>
发生什么事了?
最佳答案
这是因为您的文档包含一些 unicode 数据。 您需要正确输出unicode数据 而不是直接打印出来。 看: python 3.0, how to make print() output unicode?
关于python - 字典数据提取问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10105796/