草庐IT

Object-C

全部标签

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 - 属性错误 : 'module' object has no attribute 'PROTOCOL_TLSv1_2' with Python 2. 7.11

我在为mac上的python安装获取tlsv1.2支持时遇到问题。这是我的openssl版本:opensslversionOpenSSL1.0.2h3May2016这是我的python版本:python--versionPython2.7.11这就是我正在测试的方式:>>>importssl>>>ssl.PROTOCOL_TLSv1_2Traceback(mostrecentcalllast):File"",line1,inAttributeError:'module'objecthasnoattribute'PROTOCOL_TLSv1_2'正在阅读:https://docs.pyt

json - 类型错误 : <object> is not JSON serializable

我试图在Django中使用json.dumps()将对象编码为json,但是当我传入python对象时,它会引发此错误。TypeError:isnotJSONserializable我假设即使JSON只能对某些数据类型进行编码,但其中一种数据类型是对象。我在StackOverflow上阅读了另一个问题,解决这个问题的一个好方法是使用.__dict__从对象中创建一个字典我试过了,它说我的新字典中的一个键,_state不可序列化。我不确定这个_state键是从哪里来的,我想知道是否有一种方法可以将我的对象转换成没有那个额外字段的字典,这样我就可以将它编码成JSON?型号:classOrg

python - NumPy C API : Link several object files

我正在使用numpy的CAPI编写一些用于矩阵计算的函数。今天我想将我的函数的某些部分移动到一个单独的.c文件中,并使用一个header来声明它们。现在我遇到了一个与numpy的import_array函数有关的奇怪问题。我试图尽可能地简化问题。首先是工作程序:mytest.c#include"mytest.h"PyObject*my_sub_function(){npy_intpdims[2]={2,2};doubledata[]={0.1,0.2,0.3,0.4};PyArrayObject*matrix=(PyArrayObject*)PyArray_SimpleNew(2,di

python - 类型错误 : 'set' object does not support indexing

我刚刚在Python3.5中做了一些随机的事情。在15分钟的空闲时间里,我想到了这个:a={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}len_a=len(a)list=list(range(0,len_a))message=""wordlist=[chforchinmessage]len_wl=len(wordlist)forxinlist:print(a[x])但那种随机成功的满足感并没有让我失望。相反,失败的感觉确实:

python - 属性错误 : 'Client' object has no attribute 'send_message' (Discord Bot)

出于某种原因,send_message在我的Discord机器人上无法正常工作,而且我无法找到修复它的方法。importasyncioimportdiscordclient=discord.Client()@client.async_eventasyncdefon_message(message):author=message.authorifmessage.content.startswith('!test'):print('on_message!test')awaittest(author,message)asyncdeftest(author,message):print('in

python - 属性错误 : 'datetime.datetime' object has no attribute 'timestamp'

请帮忙-我不断收到以下回溯错误:当前运行Python2.0我正在尝试利用Python的Plotly库来显示说明比特币价格的信息图。我尝试在代码顶部导入日期时间,但这似乎无法解决问题。Traceback(mostrecentcalllast):File"project_one.py",line165,incrypto_price_df=get_crypto_data(coinpair)File"project_one.py",line155,inget_crypto_datajson_url=base_polo_url.format(poloniex_pair,start_date.ti

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 - 属性错误 : 'InstrumentedList' object has no attribute

我有这些表格:classThing(Base):__tablename__='thing'id=Column(Integer,primary_key=True)classUser(Base):__tablename__='user'id=Column(Integer,primary_key=True)classVoteinfo(Base):__tablename__='voteinfo'thing_id=Column(Integer,ForeignKey('thing.id'),primary_key=True)thing=relationship('Thing',backref='v