小编Rab*_*ter的帖子

必须使用instance作为第一个参数调用unbound方法 - python

我一直收到错误: TypeError: unbound method get_num_students() must be called with Student instance as first argument (got nothing instead)

这是代码:

class Student(object):
    num_students = 0
    num_grad_2013 = 0

    def __init__(self, first_name, last_name, id_num, yr_of_grad, counselor):
        self = self
        self.first_name = first_name
        self.last_name = last_name
        self.id_num = int(id_num)
        self.yr_of_grad = int(yr_of_grad)
        self.counselor = counselor

    def to_string(first_name, last_name, id_num, yr_of_grad, counselor):
        print first_name
        print last_name
        print id_num
        print yr_of_grad
        print counselor


    def move():
        num_students -= 1
        if yr_of_grad == 12:
            num_grad_2013 -= 1
        else: …
Run Code Online (Sandbox Code Playgroud)

python class function typeerror python-2.7

15
推荐指数
1
解决办法
5万
查看次数

标签 统计

class ×1

function ×1

python ×1

python-2.7 ×1

typeerror ×1