AttributeError: 'NoneType' object has no attribute 'strip'
程序员文章站
2022-03-26 23:17:23
...
删除None或者空字符串时出错
def is_not_empty(s):
return len(s.strip()) > 0
print(list(filter(is_not_empty, ['hahah', 'jiayou', 'keyide', ' ', None, 'none'])))
解决办法:
# 删除None或者空字符串
def is_not_empty(s):
return s and len(s.strip()) > 0
print(list(filter(is_not_empty, ['hahah', 'jiayou', 'keyide', ' ', None, 'none'])))
结果为:
[‘hahah’, ‘jiayou’, ‘keyide’, ‘none’]
上一篇: 上海本地人去的小吃街 你去的是这几条街吗
下一篇: Java辗除法求两个自然数的最大公因数
推荐阅读
-
AttributeError: module ‘community‘ has no attribute ‘best_partition‘ 问题解决方法
-
【python】解决AttributeError: module ‘scipy.misc‘ has no attribute ‘toimage‘问题
-
【Tensorflow】Linux下Tensorflow报错:AttributeError: module ‘tensorflow‘ has no attribute ‘xxxx‘
-
AttributeError: 'module' object has no attribute 'main'
-
AttributeError: module 'sklearn' has no attribute 'linear_model'
-
解决Keras报错AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
-
解决'DataFrame' object has no attribute 'sort'
-
‘MyObject‘ object has no attribute ‘***‘
-
AttributeError: ‘NoneType‘ object has no attribute ‘origin‘解决办法
-
AttributeError: ‘set‘ object has no attribute ‘append‘解决办法