草庐IT

save_callable

全部标签

python 3 : Making a str object callable

我有一个接受用户输入的Python程序。我将用户输入存储在一个名为“userInput”的字符串变量中。我希望能够调用用户输入的字符串...userInput=input("Enteracommand:")userInput()由此,我得到错误:TypeError:'str'objectisnotcallable目前,我的程序正在做这样的事情:userInput=input("Enteracommand:")ifuserInput=='example_command':example_command()defexample_command():print('HelloWorld!')显

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 - Q设置(): How to save to current working directory

对于可以直接从闪存/笔/USB/jump/拇指驱动器运行的应用程序,为了从一台机器移动到另一台机器的便携性,将用户设置存储在内存棒上是有意义的程序运行的目录(而不是每台机器的Windows/Mac/Linux用户或系统目录)。QSettings()很方便,但是,可以告诉它使用当前工作目录吗?这是一个小示例程序,它使用QSettings()来保持其屏幕位置在运行之间:fromPySideimportQtGui,QtCorefromPySide.QtGuiimportQTabWidget,QApplicationfromPySide.QtCoreimportQSettingsclassAb

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 - Django - TypeError - save() 得到了一个意外的关键字参数 'force_insert'

我是Django的新手,我无法弄清楚这个错误。请帮忙。它给出了TypeError-save()得到了一个意外的关键字参数“force_insert”。我测试了下面的代码,他们能够保存新用户注册,但现在它不会再保存了...这是我认为有问题的views.py的一部分:fromdjango.shortcutsimportrender,redirectfromdjango.contrib.auth.formsimportUserCreationFormfromdjango.contribimportmessagesfromdjango.contrib.auth.decoratorsimport

python - 将参数传递给自定义 save() 方法

如何将参数传递给我的自定义保存方法,同时保留适当的*args、**kwargs以传递给super方法?我正在尝试类似的东西:form.save(my_value)和defsave(self,my_value=None,*args,**kwargs):super(MyModel,self).save(*args,**kwargs)printmy_value但这似乎行不通。我做错了什么?编辑:我找到了这个示例(请参阅最后一条消息,用于传递“重新排序”):http://groups.google.com/group/django-users/browse_thread/thread/b285

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