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

sha*_*arp 4 python fuzzywuzzy

我试图从 fuzzywuzzy 库中调用ratio()函数来匹配两个字符串并收到以下错误消息:

AttributeError: module 'fuzzywuzzy' has no attribute 'ratio'
Run Code Online (Sandbox Code Playgroud)

版本有变化吗?我试图在 fuzz 中寻找其他函数来查看它是否存在,但我无法找到它。

import fuzzywuzzy as fuzz
from fuzzywuzzy import process
import Levenshtein
fuzz.ratio('Lord of the Rings', 'The Lord of the Rings')
Run Code Online (Sandbox Code Playgroud)

Jab*_*Jab 5

ratio是 的一种方法fuzzywuzzy.fuzz。使用:

from fuzzywuzzy import fuzz
Run Code Online (Sandbox Code Playgroud)

然后你可以使用:

fuzz.ratio('Lord of the Rings', 'The Lord of the Rings')
Run Code Online (Sandbox Code Playgroud)