网上找不到,也许是大家都不用,个人遇到了,所以记录下解决方案
seq = difflib.SequenceMatcher(None)
seq是一个类,计算结果会存起来
当使用单例模式时,上一次计算结果会影响本次计算结果
重置为:
seq.fullbcount = None
代码:
import difflib
seq = difflib.SequenceMatcher(None)
str1 = "0603 5%"
def test():
str1 = "0603 5%"
str2 = "0603 5% 6.1x2.6"
seq.a = str1
seq.b = str2
print(round(seq.quick_ratio(), 3), seq.a, seq.b)
seq.b = "asdg d ef w5 121 51f35s"
print(round(seq.quick_ratio(), 3), seq.a, seq.b)
seq.fullbcount = None
seq.b = "asdg d ef w5 121 51f35s"
print(round(seq.quick_ratio(), 3), seq.a, seq.b)
test()
输出
0.636 0603 5% 0603 5% 6.1x2.6
0.467 0603 5% asdg d ef w5 121 51f35s
0.2 0603 5% asdg d ef w5 121 51f35s
标签:ratio,seq,0603,5%,计算结果,quick,python3
From: https://www.cnblogs.com/zaxl932946/p/16813089.html