Search code examples
pythonpython-2.7levenshtein-distance

Levenshtein module in python doesn't work


I installed the module python-Levenshtein-0.11.2. I think the setup succeeded (when I type help('modules'), I see "Levenshtein" module in the list).

But when I tried the "distance" function, I got this error: "NameError: name 'distance' is not defined".

I can't understand why the distance function doesn't work.


Solution

  • You're not forgetting to use the module namespace are you?

    Calls should look something like this:

    import Levenshtein
    lev_dist = Levenshtein.distance(args)
    

    Alternatively, you can make distance() accessible without the module. bit by doing:

    from Levenshtein import distance
    lev_dist = distance(args)