且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取AttributeError:< class>没有属性< method>

更新时间:2022-11-30 11:40:01

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

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. :)