Python 拆分字符串时的AttributeError
我有一个Python 拆分字符串时的AttributeError,python,python-2.7,mcafee,Python,Python 2.7,Mcafee,我有一个dict对象,我试图在其中解析并只捕获字符串的一部分 我使用的是McAfee EPO Python API,可以获取查询结果,但我认为这与这个问题无关 以下是对象中的字符串(类似内容的多行)。我要做的是从这个字符串中提取'WORKSTATION001'文本 {u'EPOLeafNode.NodeName': u'WORKSTATION001'} 以下是我使用的代码: for system in epoSystems: computerName = system.rstrip()
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”对象没有属性“rstrip”
关于如何抓住那根绳子有什么想法吗?谢谢你的快速回复。通过系统[u'EPOLeafNode.NodeName']引用实现了这一点 更新(工作)代码:
我不认为你有一个字符串——你有一个字典,其中你想要的强项是一个值。使用相应的键访问它:
system[u'epoliftnode.NodeName']
。您没有字符串“{u'epoliftnode.NodeName':u'WORKSTATION001'}”
,您只有字典{u'epoliftnode.NodeName':u'WORKSTATION001'}
。所以只要做system[u'epoliftnode.NodeName']
,或者system.values()[0]
,或者别的什么就行了。我认为错误信息非常清楚-system
不是字符串,你不明白什么部分?
for system in epoSystems:
computerName = system[u'EPOLeafNode.NodeName']
print computerName