python对象属性相加报错

passself 2018-01-07 05:20:00
比如我声明一个class

class SortMovie(object):
"""docstring for SortMovie"""
#count = Integer('count')
def __init__(self, category,location,count):
#super(SortMovie, self).__init__()
self.category = category
self.location = location
self.count = count + 0
def printDetail(self):
print (self.category,self.location,self.count)


计算一下总和,count

firstSortTotalCount = 0
for sortMovie in firstSortMovies:
#print(type(sortMovies.count))
firstSortTotalCount = firstSortTotalCount + sortMovies.count


把对象添加到list中的时候

firstSortMovies.append(SortMovie("喜剧","大陆",len(temp_movies)))

报错,啥情况
TypeError: unsupported operand type(s) for +: 'int' and 'builtin_function_or_method'
...全文
327 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
passself 2018-01-08
  • 打赏
  • 举报
回复
firstSortTotalCount = firstSortTotalCount + sortMovie.count() TypeError: count() takes 0 positional arguments but 1 was given 这个是啥意思
oyljerry 2018-01-07
  • 打赏
  • 举报
回复
引用 2 楼 passself的回复:
TabError: inconsistent use of tabs and spaces in indentation 报错了呢
代码对齐格式问题。最好都用空格对齐
passself 2018-01-07
  • 打赏
  • 举报
回复
TabError: inconsistent use of tabs and spaces in indentation 报错了呢
zhouliang0806 2018-01-07
  • 打赏
  • 举报
回复
需要定义count属性方法:

@property
def count():
    return self.count

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧