【问题标题】:AttributeError 'Nonetype' object has no attribute. But i check for NonetypeAttributeError 'Nonetype' 对象没有属性。但我检查 Nonetype
【发布时间】: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


【解决方案1】:

试试这个。

Clist out of the list comprehension is not None But some of the values inside fragment in None,这就是你得到这个错误的原因。

您需要像下面一样添加if clist is not None inside list comprehension

result = [[name, clist.rstrip()] for name, clist in zip(
            fragments[::group_count+1],
            fragments[group_count::group_count+1]
        ) if clist is not None]

【讨论】:

  • 如果您有任何其他错误,请在评论中告诉我。
【解决方案2】:

最后调用的模块:npc_invite_situation_drama_node.py 上次调用的函数:_get_zone_id 错误信息:(AttributeError: 'NoneType' object has no attribute 'vacation_or_home_zone_id'),CategoryID: npc_invite_situation_drama_node:230

【讨论】:

    猜你喜欢
    • 2019-01-01
    • 2021-12-26
    • 2019-07-23
    • 2018-05-13
    • 2020-09-07
    • 2017-05-03
    • 2023-03-16
    • 2018-07-14
    • 2013-06-16
    相关资源
    最近更新 更多