TypeError: 'TestCase' object is not iterable
这个异常呢其实是因为我对list没有足够熟悉
我一开始很疑惑,明明已经正确返回testcase对象了呀,为啥会报TypeError: 'TestCase' object is not iterable这个错误 呢?
分析:
这个错误的意思是说TestCase这个对象是不可迭代的(注意到了吗,是TestCase,而不是testcase)
看print(testcase)输出的结果:
<TestCase.获取房源状态>
再看看是哪里调用了testcase对象,在runTest(testcase)函数中
使用for i in testcase 循环读出testcase对象当中的内容
首先testcase = runProject("all")会返回一个列表
我原本想是通过这句代码只取前2条数据,我以为这句代码执行后testcase = runProject("all")[2],testcase对象仍然是一个列表,但实际上这样写是只取了testcase列表中下标为2的元素,而不是testcase这个列表前2个元素了
正确的写法应该是这样的
testcase = runProject("all")[:2]
举个小例子说明一下:
for循环迭代一个列表--正常执行
In [2]: a=["a","b",123] In [4]: for i in a:
...: print(i)
...:
a
b
123
for循环迭代a[:2](a[:2]仍然是一个列表对象)--正常执行
In [8]: a[:2]
Out[8]: ['a', 'b']
In [6]: for i in a[:2]:
...: print(i)
...:
a
b
for循环迭代a[2](a[2]表示列表中下标为2的元素,该元素是数字123,该对象是不可迭代的)--报错了TypeError: 'int' object is not iterable
In [9]: a[2]
Out[9]: 123
In [7]: for i in a[2]:
...: print(i)
...:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-879d94b1fc77> in <module>
----> 1 for i in a[2]:
2 print(i)
3 TypeError: 'int' object is not iterable
顺例复习一下:
python中可以迭代的对象包括:字符串,列表,元组,字典,文件
TypeError: 'TestCase' object is not iterable的更多相关文章
- TypeError: 'ExcelData' object is not iterable
今天写了个测试的代码,结果在执行test_register.py文件在调用readexcle.py的时候一直报错TypeError: 'ExcelData' object is not iterabl ...
- python TypeError: 'NoneType' object is not iterable
list(set(map(lambda tp_id : tp_id if not ('#' in tp_id) and len(tp_id.strip().replace('\n', '')) > ...
- python"TypeError: 'NoneType' object is not iterable"错误解析
尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225 [解析] 一般是函数返回值为None,并被赋给了多个变量. 实例 ...
- Python : TypeError: 'int' object is not iterable
用循环依次对list中的每个名字打印出 Hello, xxx! -------------------------------------------------------- L = ['Bart' ...
- append导致TypeError: 'NoneType' object is not iterable
a=[1,2,3] a.append(4) a Out[4]: [1, 2, 3, 4] a=a.append(5) print(a) None a =[1,2,3] print(a.append(4 ...
- python框架Scrapy报错TypeError: 'float' object is not iterable解决
原因是:Twisted版本高了. 解决办法: 只要把Twisted库降级到16.6.0即可: pip3 install Twisted== 注:Twisted16..0安装后,会自动卸载高版本的Twi ...
- selenium报错TypeError: 'FirefoxWebElement' object is not iterable
报错原因element少了s定位一组元素的方法与定位单个元素的方法类似,唯一的区别是在单词element后面多了一个s表示复数. 改为 返回结果为
- 'NoneType' object is not iterable
"TypeError: 'NoneType' object is not iterable" 一般是返回值为None同时赋值给了多个变量
- Python问题:'Nonetype' object is not iterable
参考链接:http://blog.csdn.net/dataspark/article/details/9953225 [解析] 这个错误提示一般发生在将None赋给多个值时. [案例] 定义了如下的 ...
随机推荐
- 华为OJ2011-最长公共子串
一.题目描述 描述: 计算两个字符串的最大公共子串(Longest Common Substring)的长度,字符区分大小写. 输入: 输入两个字符串 输出: 输出一个整数 样例输入: asdfas ...
- oracle initialization or shutdown in progress 问题解决
今天登录oracle时遇到oracle initialization or shutdown in progress 这个错误提示,在网上搜了下,试了非常多方法,最后结合几种方法结合,成功攻克了问题! ...
- Azure Pack演示样例缩放部署架构
- Android仿微信朋友圈图片查看器
转载请注明出处:http://blog.csdn.net/allen315410/article/details/40264551 看博文之前,希望大家先打开自己的微信点到朋友圈中去,细致观察是不是发 ...
- 关于appcompat_v7的说明
http://blog.csdn.net/crazykbc/article/details/21553699 问题描述: 使用eclipse创建一个Android项目时,发现project列表中会多创 ...
- 洛谷 P1979 [ NOIP 2013 ] 华容道 —— bfs + 最短路
题目:https://www.luogu.org/problemnew/show/P1979 真是一道好题... 首先考虑暴力做法,应该是设 f[i][j][x][y] 记录指定棋子和空格的位置,然后 ...
- 30. extjs getEl方法 怎么用
转自:https://blog.csdn.net/evilcry2012/article/details/50586861 2014-10-27 11:57 提问者采纳 getEl = compo ...
- 【WIP】数据结构与算法入门
创建: 2017/12/25
- 人脸识别(初学篇)-VS2015+opencv3.2的配置
初学人脸识别,感觉安装也是一个很大的麻烦. 写在这里记录一下吧 一:先安装好我们需要的软件 首先安装Vs2015,在官网或者csdn搜一下应该找的到. 安装步骤没有太多讲究. 点击exe文件,我选择的 ...
- 一个简陋的个人小项目,也是个人第一个真正意义上的独立项目——Graph
由来 我最早接触到图这个概念是在大二的离散数学当中图论相关的内容,当时是以著名的哥尼斯堡七桥问题引出图论的概念,现在依然记忆犹新(不过只是记得这个名字,具体的解题思路我重新温习了一下才想起来),当时也 ...