了解 Pylint E1101:实例没有替换成员
Understanding Pylint E1101: Instance has no replace member
我正在编写一个函数,return 两个字符串之间的对数。我想避免错误的配对,所以只要有一对,我就会用垃圾替换字母。但是我看到了 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)
替换列表中的元素:
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
方法替换列表。替换上面代码列表中的元素是解决此问题的一种方法。
我正在编写一个函数,return 两个字符串之间的对数。我想避免错误的配对,所以只要有一对,我就会用垃圾替换字母。但是我看到了 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)
替换列表中的元素:
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
方法替换列表。替换上面代码列表中的元素是解决此问题的一种方法。