python - 拆分字符串时出现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'
关于如何抓住那个字符串的任何想法?
解决方案
感谢您的快速回复。通过 system[u'EPOLeafNode.NodeName'] 引用就可以了。
更新(工作)代码:
for system in epoSystems:
computerName = system[u'EPOLeafNode.NodeName']
print computerName
推荐阅读
- mongodb - mongodb查询并返回特定集合
- python - 当内核过多或多于一台机器时,Dataflow 无法获取对 BigQuery 表的引用
- swift - 在不初始化变量的情况下执行 n 次代码行
- java - 无法在类外访问正确的类对象
- scala - Spark 任务不可序列化/没有为 3rd 方 Jar 定义类
- mysql - 如何在 INNER JOIN 语句中获取 MAX 日期
- ios - 类型“UIImage”没有成员“radialGradientImage”
- javascript - 在指定位置替换部分字符串
- ios - 如果 subscribeOn 背景,RxSwift TestScheduler 不起作用
- c# - 如何从强名称程序集中加载 ResourceDictionary?