TypeError: 'list' object cannot be interpreted as an integer

TypeError: ‘list‘ object cannot be interpreted as an integer

类型错误,不能将list对象转换为一个整数.

错误代码,例如如下例子:

  1. args = [3,6]
  2. print(list(range(args)))

range函数本应该需求,一个整数,或者一对范围,或者三个整数类型,才能构造一个iterable,这里直接将args这个列表传递给它是不行的,需要通过解压缩机制,更正后代码为:

  1. args = [3,6]
  2. print(list(range(*args)))  # call with arguments unpacked from a list

使用*args对列表进行解压缩,后传递给range构造一个itetable.

TypeError: 'list' object cannot be interpreted as an integer

原文地址:https://www.cnblogs.com/wawawawa-briefnote/p/8908787.html

时间: 2024-10-10 20:26:30

TypeError: 'list' object cannot be interpreted as an integer的相关文章

ImportError: cannot import name 'izip & TypeError: 'float' object cannot be interpreted as an integer

ImportError: cannot import name 'izip' 参考:https://codereview.stackexchange.com/questions/26271/import-izip-for-different-versions-of-python A common idiom that I use for Python2-Python3 compatibility is: gedit mtcnn_detector.py try: from itertools im

用random.randint函数时 报错 'str' object cannot be interpreted as an integer问题

range()仅将int值用作参数.所以会报错. 原: n=input("輸入") 解决方法: 1.eval() n=eval(input("輸入")) 2.用int() n=int(input("輸入")) 用random.randint函数时 报错 'str' object cannot be interpreted as an integer问题 原文地址:https://www.cnblogs.com/claudia529/p/12078

TypeError:'dict' object is not callable

TypeError:'dict' object is not callable 出现这种错误有两种可能: 1. 代码里重新定义了dict,比如 dict= {...},这时调用的是代码里定义的dict而不是python内置类型 2. 取字典内容时用了()而不是[].比如sdict("content_id"),应该是sdict["content_id"] TypeError:'dict' object is not callable

python框架Scrapy报错TypeError: 'float' object is not iterable解决

原因是:Twisted版本高了. 解决办法: 只要把Twisted库降级到16.6.0即可: 1 pip3 install Twisted==16.6.0 2 3 注:Twisted16.6.0安装后,会自动卸载高版本的Twisted python框架Scrapy报错TypeError: 'float' object is not iterable解决

TypeError: 'NoneType' object has no attribute '__getitem__'

Buildbot版本:(0.8.10) Bug:TypeError: 'NoneType' object has no attribute '__getitem__' 参考页面:http://trac.buildbot.net/ticket/3107?cversion=0&cnum_hist=3 修改文件slaves.py中出错部分的代码为 1 try: 2 max_builds = int(request.args.get('numbuilds', ['10'])[0]) 3 except (

python TypeError: 'builtin_function_or_method' object is not iterable keys

statinfo = os.stat( OneFilePath ) if AllFiles.has_key( statinfo.st_size ): OneKey = AllFiles[ statinfo.st_size ] OneKey.append( OneFilePath ) AllFiles[ statinfo.st_size ] = OneKey else: if statinfo.st_size > MinSize: # print statinfo.st_size AllFiles

TypeError: 'str' object is not callable

Python报错TypeError: 'str' object is not callable TypeError: 'str' object is not callable

django TypeError: 'module' object is not callable

原因:导入模块时直接把模块当函数使用 1 from rest_framework import reverse #import reverse module 2 3 4 5 @api_view(("GET",)) 6 def api_root(request, format=None): 7 return Response({ 8 "user": reverse("user-list", request=request, fromat=forma

TypeError: 'range' object doesn't support item deletion

python 是个逐步迭代开发的过程,他不是向下兼容的,更不是向上兼容,版本不一致,好端端的程序就是不能运行了. 下面是在python 2中能运行,在Python 3中不能运行的代码.其实也很简单.但是这些边边角角的东西着实让人头疼. >>> a=range(10)>>> arange(0, 10)>>> del[a[1]]Traceback (most recent call last):  File "<pyshell#6>&