0

I have a dict object in which I'm trying to parse out and capture only a part of the string.

I'm using McAfee EPO Python API's and can grab results of a query, but I don't think that is relevant to this question.

Here is the strings in the objects (multiple lines of similar content). What I'm after is extracting the 'WORKSTATION001' text from this string.

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

Here's the code I'm using:

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

This results in:

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

Any ideas on how to grab just that string?

martineau
  • 119,623
  • 25
  • 170
  • 301
Rob G
  • 11
  • 1
  • 1
    I don't think you have a string -- you have a dictionary in which the strong you want is a value. Access it with its corresponding key: `system[u'EPOLeafNode.NodeName']`. – Linuxios Jun 06 '18 at 20:32
  • 1
    You don't have the string `"{u'EPOLeafNode.NodeName': u'WORKSTATION001'}"`, you just have the dictionary `{u'EPOLeafNode.NodeName': u'WORKSTATION001'}`. So just do `system[u'EPOLeafNode.NodeName']`, or `system.values()[0]`, or whatever. – abarnert Jun 06 '18 at 20:33
  • I think the error message is pretty clear—`system` isn't a string—what part don't you understand? – martineau Jun 06 '18 at 20:40

1 Answers1

0

Thanks for the quick responses. Referencing via system[u'EPOLeafNode.NodeName'] did the trick.

Updated (working) code:

for system in epoSystems:
    computerName = system[u'EPOLeafNode.NodeName']
    print computerName
Rob G
  • 11
  • 1