AttributeError:模块“ fuzzywuzzy”没有属性“ ratio”

时间:2019-03-11 20:41:53

标签: python fuzzywuzzy

我正在尝试从库Fuzzywuzzy调用ratio()函数以匹配两个字符串并得到以下错误消息:

AttributeError: module 'fuzzywuzzy' has no attribute 'ratio'

版本是否已更改?我试图在fuzz中寻找其他功能以查看其是否存在,但无法找到它。

import fuzzywuzzy as fuzz
from fuzzywuzzy import process
import Levenshtein
fuzz.ratio('Lord of the Rings', 'The Lord of the Rings')

3 个答案:

答案 0 :(得分:1)

task2_retry_handler = PythonOperator( dag=my_dag, task_id="task2_retry_handler", python_callable=my_task2_retry_handler, .., trigger_rule=TriggerRule.ALL_SUCCESS ) [task1_error_handler_status_check, task2_dummy_error_handler] >> task2_retry_handler fuzzywuzzy.fuzz的一种方法。使用:

var txtBox = "<input type='text' id='txtNum[]' />"
for(var i = 0; i<=names.length;i++)//retrieve names from the array
    {
        html += "<tr id='row" + i +"'><td style='border:1px solid black;'>"+names[i]+"</td>";
        for(var j=1;j<=2;j++)//amount of textboxes need to be created
        {
            html+= "<td style='border:1px solid black;'>"+txtBox+"</td>";
        }
        for(var k=1;k<=1;k++)//amount of textboxes need to be created
        {
            html+= "<td style='border:1px solid black;'>"+txtBox+"</td>";
        }
        html += "</tr>";        
    }

然后您可以使用:

ratio

答案 1 :(得分:0)

将导入更改为:

from fuzzywuzzy as fuzz
from fuzzywuzzy import process

答案 2 :(得分:0)

位于https://github.com/seatgeek/fuzzywuzzy的自述文件指出,使用fuzzywuzzy的方式是:

from fuzzywuzzy import fuzz
from fuzzywuzzy import process

您完成操作的方式(import fuzzy-wuzzy as fuzz)意味着您将需要呼叫层次结构中的另一个级别fuzz.fuzz.blah,而不仅仅是fuzz.blah

所以答案是要么使用该额外级别,要么以文档记录的方式导入它。