类内字典用法,名称未定义

时间:2018-12-08 18:28:14

标签: python python-3.x class dictionary global

所以我当时正在做一个学校项目,但是我似乎无法弄清为什么它说“ resultsByClassNameDic”的名称未定义

class Results ():

    ## Class that contains all kinds of things for handling grades (all classnames are in the dic below)

    # Variables
    resultsByClassNameDic = {"backend" : 0, "frontend" : 0, "database" : 0, "office" : 0, "english" : 0, "dutch" : 0, "calculus" : 0, "SLB" : 0, "L&B" : 0}

    # Functions
    def getGrade(className):

        ## Will return the grade for a certain class

        global resultsByClassNameDic

        grade = resultsByClassNameDic.get(className)

        return grade

def main ():

    ## Main Program 

    a = Results.getGrade("backend")
    print(a)


    return 0

### Main Program ###
if (__name__ == "__main__"):

    if (debugMode):

        doctest.testmod()

    main()

0 个答案:

没有答案