草庐IT

rel-attribute

全部标签

python - 属性错误 : 'module' object has no attribute 'xfeatures2d' [Python/OpenCV 2. 4]

这一行:sift=cv2.xfeatures2d.SIFT_create()返回错误:Traceback(mostrecentcalllast):File"C:/Python27/openCVskrypty/GUI/SOLUTION2.py",line11,insift=cv2.xfeatures2d.SIFT_create()AttributeError:'module'objecthasnoattribute'xfeatures2d'我阅读了一些有关此错误的信息,它出现在OpenCV3.0版中。这很奇怪,因为我有2.4.11版本。我检查了dir(cv2),但没有xfeatures2

python - 诅咒返回 AttributeError : 'module' object has no attribute 'initscr'

我正在关注CursesprogrammingHowToonthePythonsite,但我遇到了一个相当奇怪的问题。我的代码目前非常短,实际上没有做任何事情因为这个错误,我无法继续前进。这是我的代码:importcurses#fromcursesimportwrapperstdscr=curses.initscr()curses.noecho()curses.cbreak()stdscr.keypad(True)defmain(stdscr):begin_x=20;begin_y=7height=5;width=40win=curses.newwin(height,width,begi

python 3 : AttributeError: 'module' object has no attribute '__path__' using urllib in terminal

我的代码在PyCharm中运行完美,但我在尝试在终端中打开它时收到错误消息。我的代码有什么问题,或者我哪里出错了?importurllib.requestwithurllib.request.urlopen('http://python.org/')asresponse:html=response.read()print(html)终端输出:λpythonDesktop\url1.pyTraceback(mostrecentcalllast):File"",line2218,in_find_and_load_unlockedAttributeError:'module'objectha

python - pyspark 错误 : AttributeError: 'SparkSession' object has no attribute 'parallelize'

我在Jupyternotebook上使用pyspark。以下是Spark的设置方式:importfindsparkfindspark.init(spark_home='/home/edamame/spark/spark-2.0.0-bin-spark-2.0.0-bin-hadoop2.6-hive',python_path='python2.7')importpysparkfrompyspark.sqlimport*sc=pyspark.sql.SparkSession.builder.master("yarn-client").config("spark.executor.memo

python - Django ORM : Filter by extra attribute

我想通过连接的字符串过滤一些数据库对象。正常的SQL查询是:SELECTconcat(firstName,'',name)FROMpersonWHERECONCAT(firstName,'',name)LIKE"a%";在模型中,我创建了一个名为PersonObjects的管理器:classPersonObjects(Manager):attrs={'fullName':"CONCAT(firstName,'',name)"}defget_query_set(self):returnsuper(PersonObjects,self).get_query_set().extra(sele

python - matplotlib.pyplot.imshow : removing white space within plots when using attributes "sharex" and "sharey"

我遇到了一个类似于here上发布的问题.不同之处在于,当我绘制两个通过sharex和sharey属性共享轴的子图时,我在绘图区域内得到不需要的空白。即使在设置autoscale(False)之后,空白仍然存在。例如,使用与上述帖子的答案中类似的代码:importmatplotlib.pyplotaspltimportnumpyasnpfig=plt.figure()ax=fig.add_subplot(2,1,1)ax.imshow(np.random.random((10,10)))ax.autoscale(False)ax2=fig.add_subplot(2,1,2,sharex

python - 属性错误 : 'FreqDist' object has no attribute 'inc'

我是Python和NLTK的初学者。我正在尝试运行教程中的以下代码:fromnltk.corpusimportgutenbergfromnltkimportFreqDistfd=FreqDist()forwordingutenberg.words('austen-sense.txt'):fd.inc(word)如果我运行它,我会收到以下错误:AttributeError:'FreqDist'objecthasnoattribute'inc'知道我做错了什么吗? 最佳答案 你应该这样做:fd[word]+=1但通常FreqDist是这

Python 元类 : Why isn't __setattr__ called for attributes set during class definition?

我有以下python代码:classFooMeta(type):def__setattr__(self,name,value):printname,valuereturnsuper(FooMeta,self).__setattr__(name,value)classFoo(object):__metaclass__=FooMetaFOO=123defa(self):pass我希望元类的__setattr__被FOO和a调用。但是,它根本没有被调用。当我在定义类后将某些内容分配给Foo.whatever时,方法被调用。这种行为的原因是什么?有没有办法拦截在创建类期间发生的分配?在__ne

python - 属性错误 : 'NoneType' object has no attribute 'format'

print("HelloWorld")print("{}World").format(Hello)我正在开发我的第一个“HelloWorld”程序,我可以通过使用print函数和一个简单的字符串文本来让它工作,但是当我尝试使用.format时,它给出了我的错误:AttributeError:'NoneType'objecthasnoattribute'format'这是说我需要为.format初始化一个变量还是我遗漏了什么? 最佳答案 你的括号错了print("HelloWorld")print("{}World".format('

python - 遍历 pandas 数据帧并更新值 - AttributeError : can't set attribute

我正在尝试遍历pandas数据框并在满足条件时更新值,但出现错误。forline,rowinenumerate(df.itertuples(),1):ifrow.Qty:ifrow.Qty==1androw.Price==10:row.Buy=1AttributeError:can'tsetattribute 最佳答案 首先在pandas中迭代是可能的,但非常慢,因此使用了另一种矢量化解决方案。我想你可以使用iterrows如果你需要迭代:foridx,rowindf.iterrows():ifdf.loc[idx,'Qty']==