草庐IT

invoke_callable

全部标签

python - 类型错误 : the first argument must be callable

我正在使用python和schedulelib创建一个类似cron的作业classMyClass:deflocal(self,command):#returnsubprocess.call(command,shell=True)print"local"defsched_local(self,script_path,cron_definition):importscheduleimporttime#job=self.local(script_path)schedule.every(1).minutes.do(self.local(script_path))whileTrue:schedu

python - 为什么使用sum()函数会出现 'int' object is not callable错误?

这个问题在这里已经有了答案:TypeError:'int'objectisnotcallable(10个答案)关闭3年前。我想弄清楚为什么在范围内使用求和函数时会出错。代码如下:data1=range(0,1000,3)data2=range(0,1000,5)data3=list(set(data1+data2))#makesnewlistwithoutduplicatestotal=sum(data3)#calculatesumofdata3list'selementsprinttotal这里是错误:line8,intotal2=sum(data3)TypeError:'int'o

python - asyncio 的 call_later raises 'generator' object is not callable with coroutine object

我有一些使用call_later使用Python3.4的asyncio制作的简单代码。代码应该打印,等待10秒,然后再次打印(但是在应该执行end()时引发TypeError,见下文):importasyncio@asyncio.coroutinedefbegin():print("Startingtowait.")asyncio.get_event_loop().call_later(10,end())@asyncio.coroutinedefend():print("completed")if__name__=="__main__":try:loop=asyncio.get_eve

Python 奇怪错误 : "TypeError: ' NoneType' object is not callable"

我正在实现一个简单的类来表示二维向量。以下是相关部分:classVector:def__init__(self,x,y):self.vec_repr=x,ydef__add__(self,other):new_x=self.x+other.xnew_y=self.y+other.yreturnVector(new_x,new_y)def__getattr__(self,name):ifname=="x":returnself.vec_repr[0]elifname=="y":returnself.vec_repr[1]稍后,我有类似的东西:a=Vector(1,1)b=Vector(2

python - 类型错误 : 'module' object is not callable when importing glob in Eclipse

我正在使用EclipseKepler(2013)和python3.3.2并运行一个简单的导入importgloba=glob.glob('*')print(a)给出一个:TypeError:'module'objectisnotcallable如果我在Idle中运行相同的代码,情况就不同了。我知道我错过了一些东西。感谢任何帮助。 最佳答案 对我有用的是我将文件顶部的importglob更改为fromglobimportglob。 关于python-类型错误:'module'objecti

python - 蝗虫 : How to invoke the test through an API

我想通过API调用Locust负载测试,以便能够从CI工具开始测试。我没有看到很多关于这种情况的文档,locustAPI中没有“Runner”或类似的类文档。我检查了在Windows中安装后可用的“locust”命令。它是一个.exe,所以不确定它的作用以及它如何实际启动测试所以,具体的问题是,是否有一个接口(interface)可以从另一个Python程序开始测试 最佳答案 目前,除命令行界面外,没有记录在案的用于控制蝗虫的API。CLI可用于开始运行负载测试,但目前无法在没有WebUI的情况下运行分布式Locust。您也可以将W

python - Flask-Login 引发 TypeError : 'bool' object is not callable when trying to override is_active property

我想修改Flask-Login中的is_active,这样用户就不会一直处于事件状态。默认值始终返回True,但我将其更改为返回banned列的值。根据文档,is_active应该是一个属性。但是,内部Flask-Login代码引发:TypeError:'bool'objectisnotcallable尝试使用is_active时。如何正确使用is_active来停用某些用户?classUser(UserMixin,db.Model):id=db.Column(db.Integer,primary_key=True)banned=db.Column(db.Boolean,default

python - Django 错误 : 'unicode' object is not callable

我试图从django网站上学习django教程,但我遇到了一些问题:我必须将我的__unicode__方法添加到我的模型类中,但是每当我尝试返回该模型的对象我收到以下错误:in__unicode__returnself.question()TypeError:'unicode'objectisnotcallable我是python的新手,也是django的新手,我真的看不出我在这里错过了什么,如果有人能指出,我将不胜感激。一些代码:我的模型.py:#Thecodeisstraightforward.Eachmodelisrepresentedbyaclassthatsubclasses

python - "TypeError: ' 模块 ' object is not callable"尝试使用 pprint

这个问题在这里已经有了答案:Python:ModuleErrorwithpprint,noerrorwithprint(1个回答)关闭4个月前。我试过这段代码来漂亮地打印一个dict:importpprintpprint({})这会引发以下错误:Traceback(mostrecentcalllast):File"temp.py",line3,inpprint({})TypeError:'module'objectisnotcallable为什么它不可调用?

python - 类型错误 : 'datetime.datetime' object is not callable

我有一些Python代码在两个开始日期之间的所有日子里进行迭代。开始日期始终为11月1日,结束日期始终为5月31日。但是,代码会迭代多年。我的代码是这样的:importtimefromdatetimeimportdatetimefromdatetimeimportdate,timedeltaastdlist1=[2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013]list2=[2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,20