【在python中检查数据描述符属性】教程文章相关的互联网学习教程文章

Python类失去了属性【代码】

我有一个奇怪的python问题.在我的gtk python应用程序的执行过程中,我的一些类对象神秘地丢失属性,导致程序的某些功能中断. 很难理解为什么会发生这种情况 – 我从不故意删除属性,并且有问题的类继承自我自己编写的类(而不是其他类). 我可以通过重复执行某个操作来触发问题(例如,生成多次调用add_card方法 – 通过疯狂点击或打开文件,导致add_card被调用大约20次) 我真的很茫然,我希望我能提供更多有用的信息给你. 什么可能导致pyth...

虚拟环境中的Opencv3和Python 2.7 – AttributeError:’module’对象没有属性’createLBPHFaceRecognizer’【代码】

我有一个opencv 3的python函数.它在没有虚拟环境的情况下工作.我还在venvv上安装了opencv:pyimagesearch.我试图在venv上运行该python函数,然后它给出一个错误:AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'没有在终端的venv:gkhan@Gkan ~/Masaüstü/face_recognizer $python face_recognizer.py Yol :./sinif/114.jpg. 114 Yuz Tanindi 12与终端的venv:gkhan@Gkan ~/Masaüstü/face_recognizer ...

python – AttributeError’tuple’对象没有属性’get’【代码】

我有一个Django应用程序.但我不能错过一段时间我一直在努力的错误.Exception Value: 'tuple' object has no attribute 'get'Exception Location: /Library/Python/2.7/site-packages/django/middleware/clickjacking.py in process_response, line 30这是django为我提供的追溯.Traceback: File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response 201. response = middleware_met...

python – 装饰类以监视属性更改【代码】

我想让课程在其中一个属性发生变化时自动向订阅者发送通知.所以,如果我写这个代码:@ChangeMonitor class ChangingClass(object):def __init__(self, x):self.x = xchanger = ChangingClass(5) print("Going to change x.") changer.x = 6 print("Going to not change x.") changer.x = 6 print("End of program")输出将是:Going to change x Old x = 5, new x = 6 Going to not change x. End of program.我的问题是如何实现Chan...

python – 如何在django模板中使用href属性【代码】

当我尝试使用/ appname / index /中的Django模板中的链接来获取/ appname / detail / ###时,我转而使用/ appname / index / detail / ###这不是我的意思试图让我的应用程序无法在urlconf中找到它当然. 首先是详细信息页面的urls.py行url(r'detail/(?P<jobID>\d+)/$', 'appname.views.detail')另外,根urlconfurlpatterns = patterns('', url(r'^appname/', include('appname.urls')),url(r'^admin/', include(admin.site.urls)), )接...

python – AttributeError:’_ NamespacePath’对象没有属性’sort’【代码】

我下载了anaconda,当尝试使用cmd启动jupyter笔记本时,错误显示为AttributeError:’_ NamespacePath’对象没有属性’sort’.我通过在windows os中的cmd中键入jupyter notebook来启动jypyter.谢谢你解决我的错误解决方法:我建议你试试这个:pip install --upgrade pip setuptools基于https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2990.

python – 在django视图中访问表单字段作为属性【代码】

根据Django教程,您应该使用cleaning_data字典访问表单字段.我想知道为什么我不能直接访问表单的属性?我的表单验证很好,但是当我尝试访问它时,Django抱怨该对象没有该属性.我在下面添加了一些代码,希望能帮助诊断问题. 形成:class CustomForm(forms.Form):description = forms.CharField(widget = forms.TextInput(attrs = {'placeholder' : 'enter some text'}), label = "My form")视图:def process_form(request):if request....

python – 将具有属性和边缘的节点从DataFrame加载到NetworkX【代码】

我是使用Python处理图形的新手:NetworkX.到现在为止我使用过Gephi.标准步骤(但不是唯一可行的)是: >从表格/电子表格加载节点信息;其中一列应该是ID,其余的是关于节点的元数据(节点是人,因此性别,组…通常用于着色).喜欢:id;NormalizedName;Gender per1;Jesús;male per2;Abraham;male per3;Isaac;male per4;Jacob;male per5;Judá;male per6;Tamar;female ...>然后从表/电子表格加载边缘,使用与节点电子表格的列ID中的节点相同的名...

python – QuerySet,Object没有属性id – Django【代码】

我正在尝试获取django中某个对象的id,但我不断收到以下错误异常值:QuerySet;对象没有属性ID.我在views.py中的功能@csrf_exempt def check_question_answered(request):userID = request.POST['userID']markerID = request.POST['markerID']title=request.POST['question']m = Marker.objects.get(id=markerID)u = App_User.objects.get(id=userID) print userIDprint markerIDprint title# userID='1'# markerID='1'# title='He...

在python单元测试中模拟类属性的更好方法【代码】

我有一个基类,它定义了一个类属性和一些依赖它的子类,例如:class Base(object):assignment = dict(a=1, b=2, c=3)我想用不同的作业对这个类进行单元测试,例如空字典,单项等.当然,这是非常简化的,不是重构我的类或测试的问题 我得到的(pytest)测试,最终,工作是from .base import Basedef test_empty(self):with mock.patch("base.Base.assignment") as a:a.__get__ = mock.Mock(return_value={})assert len(Base().assignment.valu...

Python Selenium获取所有“href”属性【代码】

如何在this page上获得这个“h2”标题的所有“href”属性?<h2 class="entry-title"> <a href="http://www.allitebooks.com/deep-learning-with-python-2/" rel="bookmark">Deep Learning with Python</a> </h2>我试过的没有获得href,是:title = driver.find_elements_by_class_name('entry-title') title[0].get_attribute('href')这没有得到“a”标签的链接.如果我在“a”标签上找到所有元素,它将返回页面上的每个href(这不是我...

python – matplotlib弹出窗口中的错误(AttributeError:’NoneType’对象没有属性’set_canvas’)【代码】

我试图在弹出窗口中绘制图形.它弹出来了.但是有一个错误.import tkinter as tk window = tk.Tk() window.configure(background='white')label_1 = tk.Label(window, text="Conpyright 123456789123456798", anchor=tk.S) label_1.pack()ws = window.winfo_screenwidth() hs = window.winfo_screenheight() w = 980 # width for the Tk root h = 600 # height for the Tk root x = (ws / 2) - (w / 2) y = (hs / 2) - (h / 2)wind...

python – OpenCV:AttributeError:模块’cv2’没有属性’face’【代码】

我正在这些版本上使用Python和OpenCV创建一个人脸识别系统: > Python 3.6.2 :: Anaconda自定义(64位)> Anaconda 4.3.23> OpenCV 3.3.0 当我尝试训练面部识别器时:face_recognizer = cv2.face.createLBPHFaceRecognizer()我收到此错误:AttributeError: module ‘cv2’ has no attribute ‘face’更新: 我试过这样做:pip install opencv_python?3.3.0+contrib?cp36?cp36m?win_amd64.whl也:conda install -c menpo opencv3=3.3....

使用Python中的Twill打开一个链接:“’module’对象没有属性’Popen’”是什么?【代码】

我已经在我的计算机上下载并安装了Python 2.5.4(我的操作系统是Windows XP),下载了“Goggle App Engine Software Development Kit”并在Python中创建了我的第一个应用程序,这是一个名为helloworld的目录,其中包含一个同名的小python文件(helloworld.py).以下是该小文件的内容:print 'Content-Type: text/plain' print '' print 'Hello, world!' 每当我在“Goggle App Engine Software Development Kit”的计算机上本地运行这个应用...

python – AttributeError:’module’对象没有属性’Firefox’【代码】

我正在尝试使用selenium webdriver来生成Firefox的一个实例.在过去,我能够在安装geckodriver并确保它在我的PATH中之后执行此操作.然而,我转而使用phantomjs大约一年,而且最近才决定再给Firefox一个旋转.不幸的是,现在当我尝试实例化webdriver.Firefox对象时,我得到一个AttributeError,说该对象没有这样的属性叫做“Firefox”.我不确定是什么改变导致这个错误. 下面是一个shell会话,用于显示我正在使用的环境以及错误的性质:~$whic...