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赋给多个值时. [案例] 定义了如下的 ...
随机推荐
- 基于tensorflow的增强学习
可以通过下面的连接查看这个项目工程: https://github.com/reinforceio/tensorforce 通过这遍文章来了这个项目的使用: https://reinforce.io/ ...
- Linux 去重 先sort再uniq
从uniq命令的帮助信息中可以看到,该命令只过滤相邻的重复行. 如果要去掉所有重复行,需要先排序,或者使用uniq -u $ uniq --h Usage: uniq [OPTION]... [INP ...
- 如何从github下载项目的源代码,包含git客户端,直接下载,vs下载
有好多小伙伴可能刚刚接触github,还不知道如果和github下载项目,此处写个博客统一的声明.从多种方式下载源代码,加深对git的理解. 首先先解释下git的含义,git是一个源代码的管理工具,通 ...
- BZOJ1229 USACO2008 Nov toy 玩具 【三分+贪心】*
BZOJ1229 USACO2008 Nov toy 玩具 Description 玩具 [Chen Hu, 2006] Bessie的生日快到了, 她希望用D (1 <= D <= 10 ...
- BZOJ1026 SCOI2009 windy数 【数位DP】
BZOJ1026 SCOI2009 windy数 Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B ...
- Hadoop内幕
http://www.itxm.net/a/dashuju/2016/0610/279.html
- codechef Far Graphs
codechef Far Graphs https://www.codechef.com/problems/TBGRAPH 题意 : 给一个简单无向图,要求构造一个序列\(a\),长度为\(n\),极 ...
- 【spring源码学习】spring集成orm数据框架
[一]简易的数据源配置 (1)配置文件 <!--springJdbcTemplemate数据操作配置信息 --> <bean id="driver" class= ...
- html页面设置一个跟随鼠标移动的DIV(jQuery实现)
说明业务:鼠标放到某个标签上,显示一个div,并跟随鼠标移动 html页面(直接放body里面): <a href="#" id="'+data[i].refund ...
- 使用 commander && inquirer 构建专业的node cli
备注: 比较简单就是使用nodejs 的两个类库帮助我们进行开发而已,具体的使用参考类库文档 1. 项目初始化 a. 安装依赖 yarn init -y yarn add commander in ...