调用python类时出错

时间:2017-01-24 12:03:45

标签: python python-3.x class

我在调用python类实例时遇到错误。 我在我的sublime中编写了以下代码,但是当我运行它时,我收到以下错误。

  

Traceback(最近一次调用最后一次):文件“/root/dog.py”,第17行,in          print(my_dog.age)AttributeError:Dog实例没有属性'age'[以0.0s结尾,退出代码为1]

class Dog():

    def _init_(self, name, age):
        self.name = name 
        self.age = age

    def sit(self):
        print(self.name.title() + "is not sitting.")

    def roll_over(self):
        print(self.name.title() + "rolled over")

my_dog = Dog('Willie', 6)
print("My dog's name is " + my_dog.name.title() + ".")
print("My dog is " + str(my_dog.age) + "years old.")
my_dog.sit()
my_dog.roll_over()
print(my_dog.age)

1 个答案:

答案 0 :(得分:2)

您需要使用(function( $ ){ $.fn.nextElementInDom = function(selector, options) { var defaults = { stopAt : 'body' }; options = $.extend(defaults, options); var parent = $(this).parent(); var found = parent.find(selector + ":first"); switch(true){ case (found.length > 0): return found; case (parent.length === 0 || parent.is(options.stopAt)): return $([]); default: return parent.nextElementInDom(selector); } }; })( jQuery ); 方法使用两个下划线。