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赋给多个值时. [案例] 定义了如下的 ...
随机推荐
- BASE理论
BASE是Basiclly Available(基本可用),Soft state(软状态),Eventually consistent(最终一致性)三个短语的缩写. BASE是对CAP中一致性和可用性 ...
- JSON Schema(模式)
JSON Schema指的是数据交换中的一种虚拟的“合同”. JSON验证器负责验证语法错误,JSON Schema负责提供一致性检验. JSON Schema是数据接收方额第一道防线,也是数据发送方 ...
- [置顶]
如何用PYTHON代码写出音乐
如何用PYTHON代码写出音乐 什么是MIDI 博主本人虽然五音不全,而且唱歌还很难听,但是还是非常喜欢听歌的.我一直在做这样的尝试,就是通过人工智能算法实现机器自动的作词和编曲(在这里预告下,通过深 ...
- 新浪云使用smarty模板的方法
在部署到sina app engine(sae)上时出现了问题,因为sae作为云计算平台式无法进行文件读写操作的,所以Smarty中输出的缓存文件就无法实现. 错误信息:“SAE_Fatal_erro ...
- 機器學習基石 机器学习基石(Machine Learning Foundations) 作业2 第10题 解答
由于前面分享的几篇博客已经把其他题的解决方法给出了链接,而这道题并没有,于是这里分享一下: 原题: 这题说白了就是求一个二维平面上的数据用决策树来分开,这就是说平面上的点只能画横竖两个线就要把所有的点 ...
- [IC]Lithograph(2)光刻技术的分辨率与分辨率增强技术
接上一篇介绍IC制造的基本过程,光刻的基本过程.这篇文章继续介绍光刻过程中的一些概念. 该系列文章的目录如下: [IC]Lithograph(0)半导体制造的基本过程 [IC]Lithograph(1 ...
- 每天一个linux命令(目录文件操作):【转载】linux文件属性详解
Linux 文件或目录的属性主要包括:文件或目录的节点.种类.权限模式.链接数量.所归属的用户和用户组.最近访问或修改的时间等内容.具体情况如下: 命令: ls -lih 输出: [root@loc ...
- HDU2222 Keywords Search 【AC自动机】
HDU2222 Keywords Search Problem Description In the modern time, Search engine came into the life of ...
- BZOJ1690 Usaco2007 Dec 奶牛的旅行 【01分数规划】
BZOJ1690 Usaco2007 Dec 奶牛的旅行 题目描述 作为对奶牛们辛勤工作的回报,Farmer John决定带她们去附近的大城市玩一天.旅行的前夜,奶牛们在兴奋地讨论如何最好地享受这难得 ...
- C# 导出图片到Word (通过XML实现)
private void ExportDataToWord(string content) { StringBuilder sbMain = new StringBuilder(); #region ...