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赋给多个值时. [案例] 定义了如下的 ...
随机推荐
- React-Native基础_4.View组件
View组件 对应ios 的UIView android 中的view 使用要先导入View import { View } from 'react-native'; 使用就是View标签,可以添加S ...
- HDU2896 病毒侵袭 【AC自动机】
HDU2896 病毒侵袭 Problem Description 当太阳的光辉逐渐被月亮遮蔽,世界失去了光明,大地迎来最黑暗的时刻....在这样的时刻,人们却异常兴奋--我们能在有生之年看到500年一 ...
- Machine Schedule(二分图匹配之最小覆盖点,匈牙利算法)
个人心得:二分图啥的一点都不知道,上网借鉴了下,请参考http://blog.csdn.net/thundermrbird/article/details/52231639 加上自己的了解,二分图就是 ...
- REST服务开发实战【转】
原文:http://kb.cnblogs.com/page/91827/ REST介绍 如果要说什么是REST的话,那最好先从Web(万维网)说起. 什么是Web呢?读者可以查看维基百科的词条(htt ...
- python: delete the duplicates in a list
下面有几种做法, 其中3之简洁令人惊讶. 1, >>> t = [1, 2, 3, 1, 2, 5, 6, 7, 8] >>> t [1, 2, 3, 1, 2, ...
- unity导入3dsMax源文件.max
https://blog.csdn.net/qq_28002559/article/details/53693621 首先unity导入3dsMax文件为什么要使用.max而不用.fbx,因为我不是做 ...
- Oracle之 等待事件log file sync + log file parallel write (awr优化)
这是3月份某客户的情况,原因是server硬件故障后进行更换之后,业务翻译偶尔出现提交缓慢的情况.我们先来看下awr的情况. 我们能够看到,该系统的load profile信息事实上并不高,每秒才21 ...
- bzoj 2406 矩阵——有源汇上下界可行流
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2406 二分答案.把 b 的 n 个行作为一排, m 个列作为一排,每行和每列之间连上下界为 ...
- Zookeeper的shell操作
一.客户端连接服务器 zkCli.sh start 二.命令操作 进入到客户端操作行,键入help 查看zookeeper命令列表 常用命令 1) 查看节点列表:ls 路径 2) 创建节点:creat ...
- cocos2d
http://www.jetbrains.com/webstorm/download/index.html 运行又有下面错误 Fatal signal 11 (SIGSEGV) at 0x000000 ...