Reputation: 83
I have a ParseResults object, which looks like this when I dump it:
[[['FM4', '230', '30', '680']]]
[0]:
[['FM4', '230', '30', '680']]
[0]:
['FM4', '230', '30', '680']
- FormNumber: 'FM4'
- BookNum: '680'
- PageNum: '230'
- BookmarkNum: '30'
I can't seem to access the results by the name.
For example: results.FormNumber
Or,
for i in results:
print("i dict", dict(i))
results in:
('i dict', {})
If I print :
print("i list", list(i))
I get :
('i list', [(['FM4', '230', '30', '680'], {'BookmarkNum': ['30'], 'BookNum':
['680'], FormNumber: ['FM4'], 'PageNum': ['230']})])
How can I access the dictionary object by name? Thanks in advance
Upvotes: 1
Views: 41
Reputation: 83
Upon further review of my grammar, I realized I was using a Group, which resulted in creating a list and not a dictionary.
After removing the group, this: ('i list', [(['FM4', '230', '30', '680'], {'BookmarkNum': ['30'], 'BookNum': ['680'], FormNumber: ['FM4'], 'PageNum': ['230']})])
Becomes this: ('i list', [(['FM4', '230', '30', '680'], {'BookmarkNum': '30', 'BookNum': '680', FormNumber: 'FM4', 'PageNum': '230'})])
And, then I was able to use the dictionary by name
Thanks
Upvotes: 1