【问题标题】:My None check is not working keep getting "NoneType object has no attribute XXX"我的无检查不起作用不断收到“NoneType 对象没有属性 XXX”
【发布时间】:2015-06-26 12:31:58
【问题描述】:

我以前遇到过这个错误。这通常意味着我正在尝试对空对象使用和方法。所以我投入了支票,但支票似乎不起作用。这是我的代码:

    possiblechildSet= MXServer.getMXServer().getMboSet("ASSETANCESTOR", userinfo)
    possiblechildSet.setWhere("ANCESTOR='" mbo.getString("ASSETNUM") "' and ASSETNUM !='" mbo.getString("ASSETNUM") "'")
    if (possiblechildSet.count() <> 0) or (possiblechildSet.count() is not None) :
        childSet= mbo.getMboSet("ASSETMISSINGCHILD")
        if childSet.count() is not None:
            childMbo = childSet.getMbo(0)
            childassetnum = childMbo.getString('ASSETNUM') //error

当我尝试使用 getString 方法时出现错误。这是有效的。我之前在多个脚本中使用过这种方式。我只是不明白它是如何通过我的支票的。 任何帮助将不胜感激。 谢谢 想

【问题讨论】:

  • 您收到的实际属性错误是什么?
  • 感谢您的回复。我得到的错误是 AttributeError: 'NoneType' object has no attribute 'getString' in

标签: python jython maximo


【解决方案1】:

勾选下一行:

childMbo = childSet.getMbo(0)
if childMbo is not None:
    childassetnum = childMbo.getString('ASSETNUM') 

【讨论】:

  • 成功了,谢谢!如果您有时间,您介意解释一下为什么以前没有发生吗?
  • 检查您需要的确切内容总是更好:在这里您想知道 childMbo 是否为 None,因此对此进行测试。我不知道为什么“childSet.count() is not None”不起作用,也许它返回 0,也许是 childSet.count() 和 childSet.getMbo(0) 不相关的特殊情况。
猜你喜欢
  • 1970-01-01
  • 2022-07-17
  • 2016-11-25
  • 2022-08-20
  • 1970-01-01
  • 2021-11-16
  • 2020-08-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多