未定义全局函数

时间:2015-11-10 15:22:00

标签: python global

我在定义模块时遇到此错误。我正在尝试通过动态编程方法编写一个编辑距离问题的程序。

这是我被卡住的模块:

def cost(i,j,M,w,text,pattern,compare): #Defining the cost functions or can say recurrence formula
    M[0,j]=0
    text1=list(text)
    pattern1=list(pattern)

    for i in range(1,m+1):
        for j in range(1,n+1):
            insertions = M[i-1,j]+1
            deletions = M[i,j-1]+1
            matches=M[i-1,j-1]


    if text1[i]==patttern1[j]:
        matches = matches+1
        return matches
    else :
        return matches 

,错误是:

  

Traceback(最近一次调用最后一次):文件   “/Users/sayaneshome/Documents/plschk.py”,202行,in     fill(M,w,text,max)#Filling矩阵M,带分数文件   “/Users/sayaneshome/Documents/plschk.py”,第117行,填充c =   成本(i,j,M,w,文本,模式,比较)文件   “/Users/sayaneshome/Documents/plschk.py”,第95行,成本如果   text1 [i] == patttern1 [j]:NameError:全局名称'patttern1'不是   定义

1 个答案:

答案 0 :(得分:0)

您的patttern1有三个t。删除一个以获取pattern1