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

python – 如何在lxml中为属性添加命名空间【代码】

我正在尝试使用python和lxml创建一个看起来像这样的xml条目:<resource href="Unit 4.html" adlcp:scormtype="sco">我正在使用python和lxml.我在使用adlcp:scormtype属性时遇到问题.我是xml的新手,所以如果我错了请纠正我. adlcp是一个名称空间,scormtype是在adlcp名称空间中定义的属性,对吧?我甚至不确定这是否是正确的问题但是…我的问题是,如何使用lxml从非默认命名空间向元素添加属性?如果这是一个微不足道的问题,我会提前道...

python – NetworkX中的AttributeError,模块没有max_clique属性【代码】

喜欢在标题中说我有一个属性错误.这是我的代码:from sympy import * import numpy as np import networkx as nxG=nx.Graph() with open ("testing.txt", "r") as myfile:Matrice=eval(myfile.readline())Matnum = np.array(np.array(Matrice))Matnum = Matnum.astype(np.int, copy=False)G.add_node(Matnum.shape[1])for i in range(0,Matnum.shape[1]):for j in range(i+1,Matnum.shape[1]):if Matnum[i,j] == 1:G.add_edge(i,j)...

python – 什么会导致WordNetCorpusReader没有属性LazyCorpusLoader?【代码】

我有一个简短的函数,通过将它与Natural Language Toolkit中的WordNet语料库进行比较来检查单词是否是真正的单词.我从一个验证txt文件的线程调用此函数.当我运行我的代码时,第一次调用该函数时,它会抛出带有消息的AttributeError"'WordNetCorpusReader' object has no attribute '_LazyCorpusLoader__args'"当我暂停执行时,同一行代码不会引发错误,因此我假设在我第一次调用时尚未加载语料库导致错误. 我已经尝试使用nltk.wordnet.e...

python – AttributeError:’NoneType’对象没有属性’append’【代码】

我有一个奇怪的问题,python将列表作为参数传递给函数.这是代码:def foobar(depth, top, bottom, n=len(listTop)):print dir(top)print top.append("hi")if depth > 0:exit()foobar(depth+1, top.append(listTop[i]), bottom.append(listBottom[i]))top = bottom = [] foobar(0, top, bottom)它说“AttributeError:’NoneType’对象没有属性’append’”,因为在foobar中top是None,尽管dir(top)打印了一个类型列表的完整属性和方法...

导入Pandas会产生错误AttributeError:模块’pandas’在iPython Notebook中没有属性’core’【代码】

我正在通过Anaconda Navigator应用程序(版本1.1.0)运行iPython笔记本.当我想导入大熊猫时,它给了我一个奇怪的错误.我认为Anaconda应用程序包括熊猫包?--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-4-af55e7023913> in <module>() ----> 1 import pandas as pd/Users/bertcarremans/anaconda/lib/p...

python – 如何按属性值对对象的字典进行排序?【代码】

我想以属性排序方式迭代对象字典import operatorclass Student:def __init__(self, name, grade, age):self.name = nameself.grade = gradeself.age = agestudi1 = Student('john', 'A', 15) studi2 = Student('dave', 'B', 10) studi3 = Student('jane', 'B', 12)student_Dict = {} student_Dict[studi1.name] = studi1 student_Dict[studi2.name] = studi2 student_Dict[studi3.name] = studi3for key in (sorted(student_Dict, ...

试图用Python解析JSON. ValueError:期望属性名称【代码】

参见英文答案 > Single vs double quotes in JSON 8个我试图将JSON对象解析为Python dict.我以前从未这样做过.当我搜索这个特定错误时,(第一个char有什么问题?),其他帖子说加载的字符串实际上不是JSON字符串.不过,我很确定这是. 在这种情况下,eval()工作正常,但我想知道是否有更合适的方法? 注意:此字符串直接来自Twitter,通过ptt工具.>>> import json >>> line = '{u\'follow_request_sent...

python – WTForms支持输入readonly属性?【代码】

Here they say it’s not supported out of the box. 你知道一种使HTML输入表单字段使用WTForms的’readonly’属性的方法吗?解决方法:我假设你在谈论<输入readonly> HTML / XHTML中的属性,这不是您链接的讨论主题. (链接的线程是关于如何忽略传递的表单输入的低级问题) 设置readonly属性(实际上是字段上的任何属性)的方法是在模板中作为keyword-arg.如果使用Jinja,这看起来像(html5):{{ form.myfield(readonly=true) }}对于XHTML...

python – 访问类的多处理代理的属性【代码】

我有一个类,我想以只读的方式与池中的子进程共享,所以我准备了一个类的代理,但它没有用.以下是我的问题的简化示例.from multiprocessing.managers import BaseManagerclass TestClass:def __init__(self, a):self.a = adef b(self):print self.aclass MyManager(BaseManager): passMyManager.register('test', TestClass)if __name__ == '__main__':manager = MyManager()manager.start()t = TestClass(1)print t.amt = manager.te...

python – 我试图只打印一定数量的Pi,它返回错误“十进制没有属性:__ getitem__【代码】

def pi():prompt=">>> "print "\nWARNING: Pi may take some time to be calculated and may not always be correct beyond 100 digits."print "\nShow Pi to what digit?"n=raw_input(prompt)from decimal import Decimal, localcontextwith localcontext() as ctx:ctx.prec = 10000pi = Decimal(0) for k in range(350): pi += (Decimal(4)/(Decimal(8)*k+1) - Decimal(2)/(Decimal(8)*k+4) - Decimal(1)/(Decimal(8)*k+5) - Dec...

Python属性getter和setter decorator不可调用【代码】

我正在做类似以下的事情class Parrot(object):def __init__(self):self.__voltage = 100000@propertydef voltage(self):"""Get the current voltage."""return self.__voltage然而,它将电压属性视为int,所以当我这样打电话时p = Parrot() print(p.voltage())我明白了TypeError: 'int' object is not callable我试过用一个和两个强调来破坏电压属性名称.解决方法:getter的重点是它返回值而不被调用. p.voltage返回整数对象,因此运行...

如何动态组合和访问Python中的类属性?【代码】

参见英文答案 > How to access object attribute given string corresponding to name of that attribute 2个我有一个Python类,其属性名为:date1,date2,date3等. 在运行时,我有一个变量i,它是一个整数. 我想要做的是根据i的值在运行时访问适当的日期属性. 例如, 如果我== 1,我想访问myobject.date1 如果我== 2,我想访问myobject.date2 我想为类而不是属性做类似的事情. 例如,我有一堆类:MyCl...

python – 动态创建类属性【代码】

我需要从DEFAULTS字典动态创建类属性.defaults = {'default_value1':True,'default_value2':True,'default_value3':True, }class Settings(object):default_value1 = some_complex_init_function(defaults[default_value1], ...)default_value2 = some_complex_init_function(defaults[default_value2], ...)default_value3 = some_complex_init_function(defaults[default_value3], ...)我也可以通过某事来实现这个目标.像__init_...

python – matplotlib和subplots属性【代码】

我正在向画布添加一个matplotlib图形,以便我可以在我的应用程序中将它与pyqt集成.我在四处寻找并使用plt.add_subplot(111)似乎是要走的路(?)但是我不能在子画中添加任何属性,因为我可能会使用“普通”的情节 图设置self.figure1 = plt.figure() self.canvas1 = FigureCanvas(self.figure1) self.graphtoolbar1 = NavigationToolbar(self.canvas1, frameGraph1)hboxlayout = qt.QVBoxLayout()hboxlayout.addWidget(self.graphtoolb...

python – AttributeError:type object’numpy.ndarray’没有属性’__array_function__’【代码】

我将numpy升级到最新版本,现在我在导入numpy时遇到以下错误:AttributeError: type object ‘numpy.ndarray’ has no attribute‘array_function‘我正在使用numpy版本1.16.解决方法:使用卸载所有Numpy安装pip uninstall numpy对于python3pip3 uninstall numpy您可能需要多次运行uninstall命令,因为可能会安装几个版本的numpy.然后跑pip install numpy