了解Pylint E1101:实例没有替换成员

时间:2018-03-02 13:41:43

标签: python methods error-handling pylint

我正在编写一个返回两个字符串之间的对数的函数。我想避免假对,所以每当有一对时,我用垃圾代替字母。但是我看到了Pylint E1101错误,我不确定这意味着什么或如何解决它。

代码在这里:

s1 = 'abca'
s2 = 'xyzbac'

def function(s1, s2):
    t1 = list(s1)
    t2 = list(s2)
    total = 0
    print (t1)
    print (t2)
    for i in t1:
        for j in t2:
            print (i, j)
            if i == j:
                total += 1
                t1.replace(i, 1)
                t2.replace(j, 2)
    return total
print (total)

1 个答案:

答案 0 :(得分:1)

替换列表中的元素:

t1[t1.index(i)]= 1 # instead of this t1.replace(i, 1)
t2[t2.index(j)]= 2 # instead of this t2.replace(j, 2)

您无法通过replace方法替换列表。替换上面列表中的元素代码是解决这个问题的一种方法。