今天写了个测试的代码,结果在执行test_register.py文件在调用readexcle.py的时候一直报错TypeError: 'ExcelData' object is not iterable,最后发现是test_register.py模块调用readexcle.py模块时,忘记调用方法了,导致返回值有误,折腾了半天,是个教训. 下面是readexcle.py模块(读取excle内的数据并返回读取到的数据): import xlrd class ExcelData(): def __i…
list(set(map(lambda tp_id : tp_id if not ('#' in tp_id) and len(tp_id.strip().replace('\n', '')) > 0else None, open('tp_list.txt').readlines()).sort())) 为了练习map,想着把一个循环写成一行代码. 结构跑程序时出了一个问题:TypeError: 'NoneType' object is not iterable. 找了半天错误(写成一行代码在这…
尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225 [解析] 一般是函数返回值为None,并被赋给了多个变量. 实例看下: c=0def test(): if c == 1: a = b = 1 return a, b a, b = test() 使用 a, b = test()调用时,就会报错:TypeError: 'NoneType' object is not iterable 在Python判断语句中,当…
用循环依次对list中的每个名字打印出 Hello, xxx! -------------------------------------------------------- L = ['Bart', 'Lisa', 'Adam']x = len(L) for i in range(x): print('Hello,', L[i]) -------------------------------------------------------- 此处,若直接使用 for i in x 时,…
参考链接:http://blog.csdn.net/dataspark/article/details/9953225 [解析] 这个错误提示一般发生在将None赋给多个值时. [案例] 定义了如下的函数 def test(): if value == 1: a = b = 1 return a,b value = 0 a,b = test() 执行这段测试程序会报错:"TypeError: 'NoneType' object is not iterable" 这里是没有考虑到else…
一:报错:TypeError: list indices must be integers, not dict for i in range(0,len(test_data)): suite.addTest(TestCaselogin("test_api",test_data[i][*arg])) 解决方法:是参数表示不正确的原因:test_data[i][*arg] 应该表示为item[*arg] 二:报错:'int' object is not iterable for i i…
http://www.itblah.com/django-error-manyrelatedmanager-object-iterable/ Django: Error: ‘ManyRelatedManager’ object is not iterable While trying to iterate through a list of objects in a Django template, I came across this error: “Caught an exception w…
id = int(request.POST('id')) Error message: TypeError: 'QueryDict' object is not callable Error reseaon: request.POST is a QueryDict dictionary lookup syntax instead: id = int(request.POST['id'])…
Traceback (most recent call last): File "myfirstpython.py", line 39, in <module> print("params list:",str(sys.argv))TypeError: 'str' object is not callable str()是系统的方法,不能在用它的时候,同时自定义一个叫做str的变量,这样就会引起冲突. 检查一下自己的代码是不是也有类似的错误.…
vectorsum.py#!/usr/bin/env/pythonimport sysfrom datetime import datetimeimport numpy as np # def numpysum(n):# a = np.arange(n) ** 2# b = np.arange(n) ** 3# c = a + b# return c def pythonsum(n): a = range(n) b = range(n) c = [] for i in range(len(a))…
TypeError: 'int' object is not callable 这个错误的原因很简单 看下面的程序: def loss(a,b): return a-b loss = 0 loss = loss(5,2)+1 错误定位: loss = loss(5,2)+1TypeError: 'int' object is not callable 原因: 函数名loss 变量名loss 重合!!! 以此类推到其他类型的错误…
TypeError: 'range' object does not support item assignment I was looking at some python 2.x code and attempted to translate it to py 3.x but I'm stuck on this section. Could anyone clarify what is wrong? import random emails = { "x": "[REDA…
目前stackoverflow找到两种情况的解决办法: 1.TypeError: 'type' object is not subscriptable when indexing in to a dictionary I have multiple files that I need to load so I'm using a dict to shorten things. When I run I get a "TypeError: 'type' object is not subscrip…