如何修复错误:'范围'对象在python3.6中不可调用 [英] How to fix the error :'range' object is not callable in python3.6

查看:66
本文介绍了如何修复错误:'范围'对象在python3.6中不可调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:

list_var = ['rh','temp','tl','Tt','DPD','PAR']
for L in range(1, len(list_var)):
     for subset in itertools.combinations(list_var, L):
          f = 'inf ~ {} + C(area)'.format(' * '.join(list(subset)))

即使我将len(list_var)更改为数字,也会出现

错误'range' object is not callable. 您能找出问题并解决吗? 预先谢谢你!

error 'range' object is not callable jumped up even I changed len(list_var) into a number. Can you identify the problem and fix it? Thank you in advance!!!

推荐答案

range名称分配给range实例对象时,我可以重现此问题:

I can reproduce the issue when assigning the range name to a range instanciated object:

>>> range = range(10)
>>> range(1)
Traceback (most recent call last):
  File "<string>", line 301, in runcode
  File "<interactive input>", line 1, in <module>
TypeError: 'range' object is not callable

您可能在代码的前面重新分配了名称,从而触发了此确切错误.

you probably reassigned the name earlier in your code, triggering this exact error.

快速&肮脏的解决方法是:

A quick & dirty fix is:

del range

这篇关于如何修复错误:'范围'对象在python3.6中不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆