【python – Google App Engine – NDB – 在多个记录上设置属性值】教程文章相关的互联网学习教程文章

Python – Kivy:AttributeError:’super’对象在尝试获取self.ids时没有属性’__getattr__’【代码】

我为一种android锁定的东西编写了一个代码,每当我尝试使用id获取特定的ClickableImage时,它会引发以下错误:AttributeError: 'super' object has no attribute '__getattr__'我花了好几个小时试图寻找这个问题的解决方案,我看着其他人有同样的问题,人们告诉他们要更改构建器的站点,因为需要先调用它来获取ids属性或其他东西像那样,但每次我移动构建器时,都会引发错误“class not defined”.有线索吗? 这是我的代码:from kivy.app...

python – AttributeError列表对象没有属性添加【代码】

Python对我来说是新的,我正在使用python做一些机器学习代码.我的情况是我正在从我的sql读取数据并试图给这个数据一个形状,所以我可以用它来进行MLP训练. 我的代码如下:connection = mysql.connector.connect(host='localhost', port=3306, user='root', passwd='mysql', db='medicalgame')cur = connection.cursor() query = "" cur.execute(query) # X_train will be a list of list and later we'll convert it to a numpy ndar...

在cdef类中混合使用cdef和常规python属性【代码】

我正在学习Cython,现在正在尝试它.我尝试了基本的cdef类示例程序,它完美地运行. 现在我要做的是在cdef类类型中混合使用cdef和非cdef混合属性,就像这样cdef class Context:cdef public int byteIndex, bitIndexdef __init__(self, msg = "", msg_len = 0):self.msg = msg self.msg_len = msg_len self.byteIndex = 0self.bitIndex = 7但是一旦我实例化对象我就会收到错误 ! AttributeError:’c_asnbase.Context’对象没有属性’ms...

python – AES会话密钥的RSA解密失败,出现’AttributeError:’bytes’对象没有属性’n’【代码】

我正在使用Python 3.6上的PyCryptodome实现公钥加密.当我尝试创建对称加密密钥并加密/解密变量时,一切正常.但是,在我介绍RSA(和PKCS1_OAEP)的那一刻,这一切都在下Go – session_key加密很好但是当我尝试解密时,我收到以下错误:Traceback (most recent call last):File "enctest.py", line 109, in <module>deckey = decrypt_val(enckey)File "enctest.py", line 77, in decrypt_valsession_key = cipher.decrypt(ciphertext)File...

python – AttributeError:即使在安装opencv-contrib之后,’module’对象也没有属性’face’错误【代码】

我试图使用Python,OpenCv2和LBPH实现面部识别(从HERE下载) 我的python版本是2.7.14PIP版本是9.0.3和OpenCV版本是3.4.0 我的代码是import cv2 import numpy as np import NameFind# --- import the Haar cascades for face and eye ditection face_cascade = cv2.CascadeClassifier('Haar/haarcascade_frontalcatface.xml') eye_cascade = cv2.CascadeClassifier('Haar/haarcascade_eye.xml') spec_cascade = cv2.CascadeClassifier...

如何在直接调用时使python对象返回属性数据【代码】

所以我想在Python中使用这样的东西:class Person:def __init__(self, name, age):self.name = nameself.age = agedef __repr__(self):return self.name, self.agep = Person('A', 20)然后希望直接调用对象p来获取元组(self.name,self.age) 但正如您在运行此程序时所看到的那样,您会遇到问题:TypeError: __repr__ returned non-string (type tuple)怎么会有这种行为? 谢谢! 注意:问题不是特定于元组数据类型;它可以是任何东西,...

具有基于属性的随机访问的对象集合的Python数据结构【代码】

我需要一组对象,这些对象可以通过每个对象共有的某个(唯一)属性进行查找.现在我正在使用一个dicitionary将字典键分配给属性.这是我现在拥有的一个例子:class Item():def __init__(self, uniq_key, title=None):self.key = uniq_keyself.title = titleitem_instance_1 = Item("unique_key1", title="foo") item_instance_2 = Item("unique_key3", title="foo") item_instance_3 = Item("unique_key2", title="foo")item_collection...

python – 类定义中的属性赋值顺序【代码】

我想以这种方式定义一个类:class List(Base):hp = Column(int,...)name = Column(str,...)这个类代表一个列表,我可以定义/修改/编码Base和Column类.有一种方法可以知道我定义属性hp / names的顺序吗?例如,我想定义一个可以执行此操作的方法:l = List() l.show() [(hp,16),(name,roger)] # in this order解决方法:在内部,属性定义存储在字典中,字典不保留元素的顺序.您可以更改Base类中的属性处理,或者存储创建顺序,如下所示:cl...

Python笔记_第四篇_高阶编程_实例化方法、静态方法、类方法和属性方法概念的解析。【代码】

1.先叙述静态方法:我们知道Python调用类的方法的时候都要进行一个实例化的处理。在面向对象中,一把存在静态类,静态方法,动态类、动态方法等乱七八糟的这么一些叫法。其实这些东西看起来抽象,但是很好理解。这里面有一个难点就是静态方法的理解,我们先叙述这个概念。比如在C#语言中,我们一般在在一个类前面加上类似于staci这样的关键字public 类名{static void 方法(){}}一般这个时候方法可以直接用“类名.方法名”的方式直接...

Python set属性等于另一个属性【代码】

是否可以将类属性定位到同一对象的另一个属性,并具有更新目标值的功能?class MyObject(object):def __init__(self):self.var_1 = 1self.var_2 = 2self.var_3 = 3self.current_var = self.var_1def update_var(self, value):self.current_var = ...预期结果:>>> x = MyObject() >>> x.update_var(10) >>> x.var_1 10 >>> x.current_var = x.var_2 >>> x.update_var(5) >>> x.var_2 5解决方法:我建议使current_var成为一个属性,作为...

python – 如何访问与保留关键字同名的属性?【代码】

我正在调用一个API,它返回一个具有许多属性的AttributeDict,例如to和from. 要访问这些属性,我使用点表示法.例如,我使用object.to并且工作正常. 当我尝试使用object.from时,我收到一条错误,指出SyntaxError:invalid syntax.我认为这是因为from is a keyword in Python. 如果是这种情况,是否可以通过点访问?现在,我正在使用对象[“from”],它正在工作,但与我的其余代码不匹配.解决方法:虽然可以使用getattr来访问这些属性:val = g...

python – 记录类属性【代码】

以下示例摘自“Dive into python”一书.class MP3FileInfo(FileInfo):"store ID3v1.0 MP3 tags"tagDataMap = ...此示例显示记录MP3FileInfo,但如何向MP3FileInfo添加帮助. tagDataMap解决方法:将其更改为属性方法.

python – AttributeError:’search’对象在django项目中没有属性’status_code’【代码】

我正在使用测试服务器测试django项目,因为它给出了以下异常Traceback (most recent call last): File “/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py”, line 280, in runself.result = application(self.environ, self.start_response) File “/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py”, line 674, in >callreturn self.application(environ, start_response) File “/usr/lib/pymodule...

python – Django:’module’对象没有属性’index’【代码】

我过去几天一直在努力学习Django,但最近我偶然发现了一个我似乎无法修复的问题.在完成Django自己编写第一个应用程序的教程后,我决定再次完成它.只有现在我会更换所有内容以满足我正在构建的原始应用程序的要求. 所以,一切顺利,直到我得到第3部分.当我尝试加载http:// localhost:8000 / lru /我收到以下错误消息:AttributeError at /lru/ 'module' object has no attribute 'index'追溯:Internal Server Error: /favicon.ico Tr...

Python类中的类属性阴影【代码】

参见英文答案 > Python class attributes and their initialization 3个我正在学习this和this来理解类属性.但与以下代码片段的输出混淆.class A:aliases = Nonename = Nonedef __init__(self,name):self.name = nameself.aliases = set([name])def add_aliases(self,a):self.aliases.add(a)def __repr__(self):return str(self.name) + str(self.aliases)arr = [] for i in range(3):arr.appen...