jjzjj

NoneType

全部标签

python - Flask - 'NoneType' 对象不可调用

我正在开发我的第一个Flask应用程序。直接从this中取出一些代码,我试图确保用户的cookie中存在一个值。defafter_this_request(f):ifnothasattr(g,'after_request_callbacks'):g.after_request_callbacks=[]g.after_request_callbacks.append(f)returnf@app.after_requestdefcall_after_request_callbacks(response):forcallbackingetattr(g,'after_request_callb

python - 为什么我在 Python 'cannot import name NoneType' 中收到错误消息?

我正在尝试将一些代码从2转换为3以及以下简单脚本importtypesfromtypesimportNoneType结果ImportError:cannotimportnameNoneType如何将上面的2转换为3? 最佳答案 types模块中不再有NoneType引用。您应该直接使用None检查身份,即objisNone。如果您确实需要NoneType,另一种方法是使用:NoneType=type(None)这实际上与之前定义的types.NoneType完全相同,在November28th,2007上被删除之前.作为旁注,您无需

python - Matplotlib 子图图 - savefig() 不会输出 PDF。 "NoneType"错误

以下是我正在编写的代码的精简版本,用于制作包含多个子图的图形。问题出现在最后一行,fig.savefig("foo"+".pdf",format='pdf')。我收到以下错误:AttributeError:"'NoneType'objecthasnoattribute'print_figure'"谁能告诉我这是怎么回事?谢谢!importmatplotlib.pyplotaspltfrompdbimportset_traceasstimportnumpyasnpTime=np.array([0,1,2,3,4])Load=np.array([1,2,3,4,5])Cell=np.arr

python - 从列表中删除项目会导致列表变为 NoneType

这个问题在这里已经有了答案:Whydotheselistoperations(methods:clear/extend/reverse/append/sort/remove)returnNone,ratherthantheresultinglist?(5个答案)关闭2个月前。我想我忽略了一个简单的解决方案。这比复杂的要好,对吧?简单地说:var=['p','s','c','x','d'].remove('d')使var成为None类型。这是怎么回事?

python - 如何使用 Requests 和 JSON 打印变量

我一直在编写一个从在线API提取信息的应用程序,我需要一些帮助。我用的是requests,我现在的代码如下myData=requests.get('theapiwebsitehere.com/thispartisworking')myRealData=myData.json()x=myRealData['data']['playerStatSummaries']['playerStatSummarySet']['maxRating']printx然后我得到这个错误myRealData=myData.json()TypeError:'NoneType'objectisnotcallabl

python - 'NoneType' 对象在 scrapy\twisted\openssl 中没有属性 '_app_data'

在使用scrapy进行抓取的过程中,我的日志中时不时出现一个错误。它似乎不在我的代码中的任何地方,看起来像是twisted\openssl中的东西。知道是什么原因造成的以及如何摆脱它吗?此处的堆栈跟踪:[Launcher,27487/stderr]Errorduringinfo_callbackTraceback(mostrecentcalllast):File"/opt/webapps/link_crawler/lib/python2.7/site-packages/twisted/protocols/tls.py",line415,indataReceivedself._write

python - 将 NoneType 分配给 Dict

我试图将None分配给字典中的一个键,但我得到了一个TypeError:self._rooms[g[0]]=NoneTypeError:'NoneType'objectdoesnotsupportitemassignment我的代码在这里:r=open(filename,'rU')forlineinr:g=line.strip().split(',')iflen(g)>1:r1=g[0]h=Guest(g[1],str2date(g[2]),str2date(g[3]))self._rooms.set_guest(r1,h)else:self._rooms[g[0]]=Noner.cl

python - Django: AttributeError: 'NoneType' 对象没有属性 'split'

我正在尝试使用Django构建一个静态站点生成器(因为它足智多谋),现在我的问题是处理应该将我的静态站点内容构建到目录中的Django命令。显然我的“NoneType”对象没有属性“split”,但我不知道那个“NoneType”对象是什么。(thisSite)C:\Users\Jaysp_000\thisSite\PROJECTx>pythonprototype.pybuildTraceback(mostrecentcalllast):File"prototype.py",line31,inexecute_from_command_line(sys.argv)File"C:\User

python - “NoneType”对象不可订阅?

list1=["name1","info1",10]list2=["name2","info2",30]list3=["name3","info3",50]MASTERLIST=[list1,list2,list3]defprinter(lst):print("AvailableLists:")forxinrange(len(lst)):print(lst[x])[0]当我尝试运行时,此代码返回“'NoneType'对象不可订阅”错误printer(MASTERLIST)我做错了什么? 最佳答案 print()函数返回None。您正

python - 无法在 Python 中反转列表,获取 "Nonetype"作为列表

这个问题在这里已经有了答案:Whydotheselistoperations(methods:clear/extend/reverse/append/sort/remove)returnNone,ratherthantheresultinglist?(5个答案)关闭3个月前。我有一个.py文件获取一个列表,找到最小的数字,将其放入一个新数组,从第一个数组中删除最小的数字,并重复直到原始数组返回不包含更多项目:defqSort(lsort):listlength=len(lsort)sortedlist=list()iflistlength==0:returnlsortelse:whil