社区
脚本语言
帖子详情
'int' object has no attribute '__getitem__'
H1dden
2018-04-12 10:53:12
小白最近正在学Python 数据挖掘入门与实践一书,在书的1.3章节亲和性分析中遇到一个问题,久久不能解决:
原书第9页第11行: if sample[premise]==0: continue 代码运行时提示这行报错,错误类型如标题。
百度上查了好久,感觉没有给sample这个类定义getitem,具体操作应该怎么做?拜托大家了。
...全文
1850
1
打赏
收藏
'int' object has no attribute '__getitem__'
小白最近正在学Python 数据挖掘入门与实践一书,在书的1.3章节亲和性分析中遇到一个问题,久久不能解决: 原书第9页第11行: if sample[premise]==0: continue 代码运行时提示这行报错,错误类型如标题。 百度上查了好久,感觉没有给sample这个类定义getitem,具体操作应该怎么做?拜托大家了。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
H1dden
2018-04-12
打赏
举报
回复
https://blog.csdn.net/www_buzhidao/article/details/71142730相关帖子中附有代码详述过程
Spark Reduce TypeError: '
int
'
object
has no
attribute
'__get
item
__
在使用Reduce这个函数需要特别注意的一点是,reduce必须要求输入与输出是相同类型,例如: >>> rddx = sc.parallelize([('a',1),('b',2),('c',5)])>>> rddx.reduce(lambda x,y:x[1]+y[1]) #报错 TypeError: '
int
'
object
has no
attribute
'__get
item
Python 中的 TypeError: '
int
'
object
has no
attribute
'get
item
' 错误
TypeError: '
int
'
object
has no
attribute
'get
item
' 表示你正在尝试对一个整数执行 [] 操作(这实际上是调用 __get
item
__ 方法),但整数类型不支持这种操作。if isinstance(x, (list, dict, str)): # 检查是否为可索引类型。确保在你使用 [] 操作符的地方,变量确实是字典、列表、字符串等支持索引操作的类型。pr
int
(key['a']) # 错误:key是字符串,不是字典。pr
int
("变量不是可索引类型")
TypeError: 'NoneType'
object
has no
attribute
'__get
item
__'
Buildbot版本:(0.8.10) Bug:TypeError: 'NoneType'
object
has no
attribute
'__get
item
__' 参考页面:http://trac.buildbot.net/ticket/3107?cversion=0&cnum_hist=3 修改文件slaves.py中出错部分的代码为 1 ...
在python中使用遍历循环求素数_python计算循环素数的问题
importmathcount=0defisPrime(n):forjinrange(2,
int
(math.sqrt(n))+1):ifn%j==0:returnFalsereturnTruedefisLoop(x):x=str(x)flag=Truecycle=[]foriinrange(1,len(x)+1):strt=str[(i-...import mathcount=0def isPri...
Python常见报错
1.IndexError: tuple index out of range 错误的原因是元组索引越界,因为后面format中的内容出现了赋值操作 2.TypeError: ‘
int
’
object
has no
attribute
‘get
item
’ 会出现报错: 在python2中,input输入数字得到的就是
int
类型的数字,数字是不可以做下标取值,而python3中input输入都为字符串,而字符串可以下标索引 3.SyntaxError: ‘break’ outside loop 原因:bre
脚本语言
37,738
社区成员
34,211
社区内容
发帖
与我相关
我的任务
脚本语言
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
复制链接
扫一扫
分享
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
试试用AI创作助手写篇文章吧
+ 用AI写文章