Skip to main content
 首页 » 编程设计

Python 错误 : 'dict' object is not callable

2025年05月04日13bluestorm

<分区>

我正在尝试加载我的数据,以便将其存储在字典中。但是我收到了这个错误:

  self.user_rating(mid, {} )   #Dictionary of dictionaries = urating 
  TypeError: 'dict' object is not callable 

这是这个特定方法的代码。

def load_r(self,file): 
            f = open(file) 
            for line in f: 
                    line = line.rstrip() 
                    components = line.split("::") 
                    uid = components[0] 
                    mid = components[1] 
                    urating = components[2] 
            self.user_rating(mid, {} )  ###Line of interest    
            f.close() 

字典应该是这样的

目标:dictionary[mid, dictionary2[uid, urating]] 如 dictionary[key, dictionary2[key, value]]

我是否应该将 self.user_rating 行设置为等于某个值?谢谢!


编辑(更新):当我尝试打电话时

self.mdb.set_user_m_rating(41, 787, 2) 

我在行中得到一个错误

self.user_rating[mid][uid] = rating 

这是在将行更改为 self.user_rating[mid] = {} 之后 但后来在另一种方法中调用了 self.user_rating[mid][uid]=rating。