It appears that you&#39;ve defined &quot;levenshtein_automata&quot; as a method on your DFA class, but you did not reference the class instance in your call by prefixing &quot;self&quot;. Instead, you&#39;re trying to call a globally defined function named &quot;levenshtein_automata&quot; -- which because it is not defined, is throwing a NameError.<div>
<br></div><div>Try changing line 145 to the below and see if that resolves the issue:</div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">    lev = self.levenshtein_automata(word, k).to_dfa()  ######### line 145 ##########</span></div>