TypeError: 'ExcelData' object is not iterable
今天写了个测试的代码,结果在执行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的更多相关文章
- 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', '')) > ...
- TypeError: 'TestCase' object is not iterable
这个异常呢其实是因为我对list没有足够熟悉 我一开始很疑惑,明明已经正确返回testcase对象了呀,为啥会报TypeError: 'TestCase' object is not iterable ...
- 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赋给多个值时. [案例] 定义了如下的 ...
随机推荐
- Win10 64位系统ADO方式操作数据库失败解决方法
VC操作Access数据库一般通过ODBC.ADO.DAO等方式,但在我的Win10 64位操作系统中,通过ADO方式操作数据库会失败,无法读取数据.解决方法:1.首先确保Win10操作系统ado目录 ...
- windows客户端远程访问linux下mysql方法
windows客户端远程访问linux下mysql方法 1. 改表法.可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 &q ...
- HDU1520 Anniversary party 树形DP基础
There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The Un ...
- CF1130D Toy Train
D Toy Train 开始时,对于一个点 \(x\) ,若没有糖果需要运走,则不考虑; 否则,若点上有 \(k\) 颗糖果需要运走,火车每次只能搭上 \(1\) 个,显然经过这个点至少 \(k\) ...
- LintCode题解
JAVA代码:https://github.com/tw1996/LintCode 持续更新
- L2-017. 人以群分
社交网络中我们给每个人定义了一个“活跃度”,现希望根据这个指标把人群分为两大类,即外向型(outgoing,即活跃度高的)和内向型(introverted,即活跃度低的).要求两类人群的规模尽可能接近 ...
- 《DSP using MATLAB》示例Example7.9
代码: wp = 0.2*pi; ws = 0.3*pi; As = 50; tr_width = ws - wp; M = ceil((As-7.95)/(2.285*tr_width) + 1 ) ...
- ballerina 学习十 streams
ballerina 的streams 使用的是siddhi complex event processing 引擎处理,可以包含的语法有 projection filtering windows jo ...
- Kafka之sync、async以及oneway
kafka有同步(sync).异步(async)以及oneway这三种发送方式,某些概念上区分也可以分为同步和异步两种,同步和异步的发送方式通过“producer.type”参数指定,而oneway由 ...
- qing-automation简单入门介绍
1.相关文档:http://www.51testing.com/html/50/category-catid-250.html 2.进行Qing automation相关操作之前,必须安装好jdk跟a ...