获取AttributeError:< class>没有属性< method> [英] Getting an AttributeError: <class> has no attribute <method>

查看:80
本文介绍了获取AttributeError:< class>没有属性< method>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在模块mod1中的类中创建一个方法,并按如下方式调用它:

I am creating a method in a class in a module mod1 and calling it as follows:

class blahblah:
   def foobar(self, bvar, **dvar)
       ////
       return dvar

并将其称为:

obj1 = mod1.blahblah()
dvar1 = obj1.foobar(True, **somedictionary)

它抛出一个Attribute error: blahblah has no attribute named foobar

能帮我吗?预先感谢

推荐答案

您描述的错误类型可能仅由缩进不匹配引起.如果该方法位于班级的最底层,则将其在班级中稍稍向上移动,问题就会变得很明显.

The type of error you describe can be caused simply by mismatched indentation. If the method is at the very bottom of your class, move it up in the class a bit and the problem will become apparent.

当python解释器遇到缩进不匹配的缩进时(例如说您开始使用带有空格缩进的文件底部的制表符),解释器将不会总是抛出错误;它可以简单地忽略文件的其余部分.我是在今天更新旧代码时遇到这个问题的,原来的作者使用了不同的空白字符(恰好与我的Geany标签匹配),这使我陷入循环的时间比我想承认的要长得多. :)

When python interpreters run into mismatched indents (like say you started using tabs at the bottom of a file that was indented with spaces), the interpreter will not always throw an error; it can simply ignore the rest of the file. I ran into this just today while updating some old code where the original author used different whitespace chars (that happened to match my Geany tabs), and it threw me for a loop for a lot longer than I'd like to admit. :)

这篇关于获取AttributeError:< class>没有属性< method>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆