首页 > 解决方案 > 拆分字符串时出现AttributeError

问题描述

我有一个dict对象,我试图在其中解析并仅捕获字符串的一部分。

我正在使用 McAfee EPO Python API,可以获取查询结果,但我认为这与这个问题无关。

这是对象中的字符串(多行类似内容)。我'WORKSTATION001'要从这个字符串中提取文本。

{u'EPOLeafNode.NodeName': u'WORKSTATION001'}

这是我正在使用的代码:

for system in epoSystems:
    computerName = system.rstrip().split('u')
    print computerName

这导致:

    computerName = system.rstrip().split('u')
AttributeError: 'dict' object has no attribute 'rstrip'

关于如何抓住那个字符串的任何想法?

标签: pythonpython-2.7mcafee

解决方案


感谢您的快速回复。通过 system[u'EPOLeafNode.NodeName'] 引用就可以了。

更新(工作)代码:

for system in epoSystems:
    computerName = system[u'EPOLeafNode.NodeName']
    print computerName

推荐阅读