jjzjj

Callable

全部标签

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

python - 类型错误 : 'module' object is not callable for python object

我的代码中出现以下错误。我正在尝试制作迷宫解算器,但收到一条错误消息:Traceback(mostrecentcalllast):File"./parseMaze.py",line29,inm=maze()TypeError:'module'objectisnotcallable我正在尝试创建一个名为m的maze对象,但显然我做错了什么。我在parseMaze.py中写了这些行#!/user/bin/envpythonimportsysimportcellimportmazeimportarray#openfileandparsecharacterswithopen(sys.argv[

python - 如何在 Django 1.9 中传递 callable

嗨,我是Python和Django的新手,我关注djangoworkshop指导。我刚刚安装了Python3.5和Django1.9并收到很多错误消息......刚才我发现了很多文档,但现在卡住了。我想添加View,所以我在urls.py中添加了以下代码:fromdjango.conf.urlsimportinclude,url#Uncommentthenexttwolinestoenabletheadmin:fromdjango.contribimportadminadmin.autodiscover()urlpatterns=[#Uncommenttheadmin/doclineb

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

我正在尝试在以下等式中使用数组中的值:forxinrange(len(prof)):PB=2.25*(1-math.pow(math.e,(-3.7(prof[x])/2.25)))*(math.e,(0/2.25)))当我运行时,我收到以下错误:Traceback(mostrecentcalllast):File"C:/Users/cwpapine/Desktop/1mPro_Chlavg",line240,inPB=float(2.25*(1-math.pow(math.e,(-3.7(prof[x])/2.25)))*(math.e,(0/2.25)))TypeError:'fl

python - BeautifulSoup - 类型错误 : 'NoneType' object is not callable

我需要使我的代码向后兼容python2.6和BeautifulSoup3。我的代码是使用python2.7编写的,在本例中使用的是BS4。但是当我尝试在squeezy服务器上运行它时,我得到了这个错误(它有python2.6和bs3):try:frombs4importBeautifulSoupexceptImportError:fromBeautifulSoupimportBeautifulSoupgmp=open(fname,'r')soup=BeautifulSoup(gmp)p=soup.body.div.find_all('p')p=soup.body.div.find_al

python - 默认字典 : first argument must be callable or None

我运行了以下代码:fromcollectionsimportdefaultdictlst=list(range(0,5))d=defaultdict(lst)我得到了这个错误:TypeError:firstargumentmustbecallableorNone请帮忙 最佳答案 对于defaultdict,默认值通常不是真正的值,它是一个工厂:一个方法产生新的值(value)。您可以使用生成列表的lambda表达式解决此问题:lst=lambda:list(range(0,5))d=defaultdict(lst)这也是一个好主意,

python - 类型错误 : 'bool' object is not callable g. user.is_authenticated()

这个问题在这里已经有了答案:Flask-LoginraisesTypeError:'bool'objectisnotcallablewhentryingtooverrideis_activeproperty(2个答案)关闭7年前。我正在尝试在我的Flask应用程序中执行此操作。但是我收到这样的错误TypeError:'bool'objectisnotcallable.对应的代码如下:@app.before_requestdefbefore_request():g.user=current_userifg.user.is_authenticated():g.search_form=Non

python - 类型错误 : 'int' object is not callable, ,, len()

我写了一个程序来玩刽子手---它还没有完成,但由于某种原因它给了我一个错误...importturtlen=Falsey=Truelist=()print("welcometothehangman!youwordis?")word=raw_input()len=len(word)forxinrange(70):printprint"_"*lenwhilen==False:whiley==True:print"insertaletter:"p=raw_input()leenghthp=len(p)ifleengthp!=1:print"youdidntgivemealetter!!!"e

python - is_authenticated() 引发 TypeError TypeError : 'bool' object is not callable

这个问题在这里已经有了答案:Flask-LoginraisesTypeError:'bool'objectisnotcallablewhentryingtooverrideis_activeproperty(2个答案)关闭7年前。我尝试在View中使用is_authenticated(),但收到错误“TypeError:'bool'objectisnotcallable”。为什么会出现此错误以及如何解决?@auth.before_app_requestdefbefore_request():ifcurrent_user.is_authenticated()\andnotcurrent_

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

我有一个这样定义的生成器:deflengths(x):fork,vinx.items():yieldv['time_length']它有效,调用它foriinlengths(x):printi产生:360012003600300哪些是正确的数字。但是,当我这样调用它时:somefun(lengths(x))其中somefun()定义为:defsomefun(lengths):forlengthinlengths():#我收到此错误消息:TypeError:'generator'objectisnotcallable我误会了什么? 最佳答案