今天写了个测试的代码,结果在执行test_register.py文件在调用readexcle.py的时候一直报错TypeError: 'ExcelData' object is not iterable,最后发现是test_register.py模块调用readexcle.py模块时,忘记调用方法了,导致返回值有误,折腾了半天,是个教训。

下面是readexcle.py模块(读取excle内的数据并返回读取到的数据):

 import xlrd

 class ExcelData():
def __init__(self,data_path,sheetname):
self.data_path = data_path # excle表格路径
self.sheetname = sheetname # excle表格内sheet
self.data = xlrd.open_workbook(self.data_path) # 打开excle表格
self.table = self.data.sheet_by_name(self.sheetname) # 切换到相应sheet
self.keys = self.table.row_values(0) # 第一行作为key值
self.rowNum = self.table.nrows # 获取表格行数
self.colNum = self.table.ncols # 获取表格列数
# print(self.rowNum)
# print(self.colNum) def readExcle(self):
if self.rowNum<2:
print("excle内数据行数小于2")
else:
L = []
for i in range(1,self.rowNum):
sheet_data = {}
for j in range(self.colNum):
sheet_data[self.keys[j]] = self.table.row_values(i)[j]
L.append(sheet_data)
#print(type(L))
return L if __name__ == '__main__':
data_path = "F:\\KEJINSUO_interface\\Case\\interface_data.xlsx"
sheetname = "注册"
get_data = ExcelData(data_path,sheetname)
print(get_data.readExcle())

下面是test_register.py模块(调用readexcle.py模块,使用readexcle.py返回值做参数):

 import requests
import json
import unittest
from readexcle import ExcelData class Regist(unittest.TestCase):
def setUp(self):
self.headers = {"Content-Type":"application/json"}
self.data_path = "F:\\KEJINSUO_interface\\Case\\interface_data.xlsx"
self.sheetname = "注册"
self.shuju = ExcelData(self.data_path,self.sheetname).readExcle() #错误在此行,未调用readExcle方法 def test_regist(self):
for a in self.shuju:
self.url = "http://test.jkkjs.cn:44444/api/register/createUser"
self.pars = {"data": {
"mobile":a['mobile'],
"password": a['password'],
"verifyCode":a['verifyCode']
}
}
self.par_json = json.dumps(self.pars)
res = requests.post(self.url,data=self.par_json,headers=self.headers)
#根据返回数据判断登录结果
if "注册成功" in res.text:
print("注册成功")
elif "手机号码已注册" in res.text:
print("手机号码已注册")
elif "参数错误" in res.text:
print("提交参数错误")

TypeError: 'ExcelData' object is not iterable的更多相关文章

  1. 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', '')) > ...

  2. TypeError: 'TestCase' object is not iterable

    这个异常呢其实是因为我对list没有足够熟悉 我一开始很疑惑,明明已经正确返回testcase对象了呀,为啥会报TypeError: 'TestCase' object is not iterable ...

  3. python"TypeError: 'NoneType' object is not iterable"错误解析

    尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225 [解析] 一般是函数返回值为None,并被赋给了多个变量. 实例 ...

  4. Python : TypeError: 'int' object is not iterable

    用循环依次对list中的每个名字打印出 Hello, xxx! -------------------------------------------------------- L = ['Bart' ...

  5. 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 ...

  6. python框架Scrapy报错TypeError: 'float' object is not iterable解决

    原因是:Twisted版本高了. 解决办法: 只要把Twisted库降级到16.6.0即可: pip3 install Twisted== 注:Twisted16..0安装后,会自动卸载高版本的Twi ...

  7. selenium报错TypeError: 'FirefoxWebElement' object is not iterable

    报错原因element少了s定位一组元素的方法与定位单个元素的方法类似,唯一的区别是在单词element后面多了一个s表示复数. 改为 返回结果为

  8. 'NoneType' object is not iterable

    "TypeError: 'NoneType' object is not iterable" 一般是返回值为None同时赋值给了多个变量

  9. Python问题:'Nonetype' object is not iterable

    参考链接:http://blog.csdn.net/dataspark/article/details/9953225 [解析] 这个错误提示一般发生在将None赋给多个值时. [案例] 定义了如下的 ...

随机推荐

  1. HDU 3378

    http://acm.hdu.edu.cn/showproblem.php?pid=3378 规则去玩三国杀就理解了 纯模拟 注意的点:有已经分出胜负但还在杀的情况出现,所以要每次杀操作前判断是否分出 ...

  2. Java基础部分全套教程.

    这是我自己早前听课时整理的java基础全套知识,使用于初学者,也可以适用于中级的程序员,我做成了chm文档的类型,你们可以下载 笔记是比较系统全面,可以抵得上市场上90%的学习资料.讨厌那些随便乱写的 ...

  3. JAVA多线程----用--取钱问题2

    在该示例代码中,TestAccount类是测试类,主要实现创建帐户Account类的对象,以及启动学生线程StudentThread和启动家长线程GenearchThread.在StudentThre ...

  4. Struts标签库详解,非常好的Struts标签详解

    Struts提供了五个标签库,即:HTML.Bean.Logic.Template和Nested. HTML 标签:         用来创建能够和Struts 框架和其他相应的HTML 标签交互的H ...

  5. 大规模向量相似度计算方法(Google在07年发表的文章)

    转载请注明出处:http://www.cnblogs.com/zz-boy/p/3648878.html 更多精彩文章在:http://www.cnblogs.com/zz-boy/ 最近看了Goog ...

  6. 用eclipse打包可执行的jar(含第三方jar包)

    在eclipse中的解决方式如下: 在工程目录下(与src同层)建立lib目录,将第三方Jar包放到这个目录里(copy,paste即可)[如果直接引用本地的jar,一旦换电脑就呵呵了...] 右击工 ...

  7. WPF 程序无法触摸操作?我们一起来找原因和解决方法!

    WPF 自诞生以来就带着微软先生的傲慢.微软说 WPF 支持触摸,于是 WPF 就真的支持触摸了.对,我说的是"支持触摸",那种摸上去能点能动的:偶尔还能带点儿多指的炫酷效果.但是 ...

  8. objectForKey与valueForKey在NSDictionary中的差异

    从 NSDictionary 取值的时候有两个方法,objectForKey: 和 valueForKey:,这两个方法具体有什么不同呢? 先从 NSDictionary 文档中来看这两个方法的定义: ...

  9. sentry docker-compsoe 安装以及简单使用

    1. 准备环境 docker docker-compose     2. 安装 a. docker-compose git clone git clone https://github.com/get ...

  10. Clair:CoreOS发布的开源容器漏洞分析工具

    Clair为何而生:提升安全 软件世界里,安全漏洞会一直存在.好的安全实践意味着要对可能出现的事故未雨绸缪 - 即尽早发现不安全的软件包,并准备好快速进行升级.而Clair就是设计来帮助你找出容器中可 ...