我试图从库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')发布于 2019-03-12 04:46:18
将导入更改为:
from fuzzywuzzy as fuzz
from fuzzywuzzy import process发布于 2019-03-12 04:48:36
ratio是fuzzywuzzy.fuzz的一种方法。使用:
from fuzzywuzzy import fuzz然后,您可以使用:
fuzz.ratio('Lord of the Rings', 'The Lord of the Rings')发布于 2019-03-12 04:44:59
如果您检查here,您可以看到您没有正确地导入fuzzywuzzy。
您应该使用from fuzzywuzzy import fuzz而不是import fuzzywuzzy as fuzz
基本上,有两种方法可以做到这一点。任一:
import fuzzywuzzy as <something>
<something>.fuzz.ratio(...)或者来自fuzzywuzzy import fuzz fuzz.ratio(...)
https://stackoverflow.com/questions/55110089
复制相似问题