【发布时间】:2022-07-17 02:21:09
【问题描述】:
我收到AttributeError: 'NoneType' object has no attribute 'rstrip'
所以我添加了if clist is not None: 但我一直收到同样的错误。为什么?
if clist is not None:
result = [
[name, clist.rstrip()]
for name, clist in zip(
fragments[::group_count+1],
fragments[group_count::group_count+1]
)
]
完整的追溯
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [85], in <module>
120 fragments = fragments[1:]
121 if clist is not None:
--> 122 result = [
123 [name, clist.rstrip()]
124 for name, clist in zip(
125 fragments[::group_count+1],
126 fragments[group_count::group_count+1]
127 )
128 ]
Input In [85], in <listcomp>(.0)
120 fragments = fragments[1:]
121 if clist is not None:
122 result = [
--> 123 [name, clist.rstrip()]
124 for name, clist in zip(
125 fragments[::group_count+1],
126 fragments[group_count::group_count+1]
127 )
128 ]
AttributeError: 'NoneType' object has no attribute 'rstrip'
【问题讨论】:
-
不是clist。片段的元素之一必须是无。
标签: python list-comprehension nonetype