小编Mik*_*ike的帖子

AttributeError:'dict'对象没有属性

我是python的新手,无法找到答案.参考消息末尾的代码,我可以知道下面一行中的"for item,total in totals.items()"部分是什么意思?

rankings = [(total/simSums[item], item) for item, total in totals.items()]
Run Code Online (Sandbox Code Playgroud)

此外,代码失败并说

# Return the Pearson correlation coefficient for p1 and p2
def sim_person(prefs, p1, p2):
    # Get the list of shared_items
    si={}
    for item in prefs[p1]:
        if item in prefs[p2]:si[item]=1

    # Find the number of elements 
    n=len(si)

    # if they have no ratings in common, return 0
    if n==0: return 0

    # Add up all the preferences
    sum1 = sum([prefs[p1][it] for it in si])
    sum2 = sum([prefs[p2][it] …
Run Code Online (Sandbox Code Playgroud)

python

22
推荐指数
3
解决办法
13万
查看次数

Python 3默认编码cp1252

我最近在sony vaio windows 10系统上使用anaconda 4.1.1 python 3.5.2安装从Biopython模块解码句柄(错误映射0x81,0x8D)时遇到了一些问题

经过一些研究,似乎问题可能是默认的解码编解码器是cp1252.我运行下面的代码,发现确实默认编解码器设置为cp1252.

但是,有几篇文章建议python 3应该将默认编解码器设置为utf8.那是对的吗?如果是这样,为什么我的cp1252,我该如何解决这个问题呢? import locale os_encoding = locale.getpreferredencoding()

python character-encoding

10
推荐指数
1
解决办法
7014
查看次数

标签 统计

python ×2

character-encoding ×1