shadows name from outer scope
这种警告是函数内部的名称与外部名称重复了,看下面例子
def cleanword(word):
# Return word in lower case stripped of whitespace
return word.strip().lower()
for word in datafile:
word = cleanword(word)
if len(word) <= 6:
continue
print(word)
在for循环里word与函数cleanword里重复了,解决办法就是将for循环中word修改一下
def cleanword(word):
# Return word in lower case stripped of whitespace
return word.strip().lower()
for words in datafile:
words = cleanword(words)
if len(words) <= 6:
continue
print(words)