unbound method must be called with instance as first argument - python

前端 未结 3 660
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 05:51

I keep on receiving the error: TypeError: unbound method get_num_students() must be called with Student instance as first argument (got nothing instead)

Her

3条回答
  •  面向向阳花
    2021-02-04 06:35

    When you define an instance method, put a self as the method's first argument, and when you use it, add self. in front of your instance variable.

    Like:

    def get_num_students(self):
        print "There are %s students in this school." % (self.num_students)
    

提交回复
热议问题