(Jan-24-2022, 02:14 PM)wardancer84 Wrote: what puzzles me all time time with this kind of stuff...how to get rid of all those square brakets in the output as this
looks not right.
No it does not look right. When I see
[['aixacodbt']]
I interpret it as a string in a list in a list. It needs unwrapping.
a = [['aixacodbt']]
b = a[0][0]
b
'aixacodbt'
print(b)
aixacodbt
You could unwrap these data before adding them to the tuple, but why are they wrapped in the first place? You should attack the problem at the source.
results = defaultdict(list) # This designates the values to be lists
...
for key in sudo_obj.host_aliases:
host_alias_list = []
host_alias_list.append((key, sudo_obj.host_aliases[key])) # host_alias_list is a list. Why double parentheses?? This would make a tuple of the contents of the list. Not useful in this stage.
results['hostalias'].append(host_alias_list) # Here you append the list to the list
You should add print statements to test what exactly happens in these steps. I have the impression it would be sufficient to do this:
for key in sudo_obj.host_aliases:
results['hostalias'].append(sudo_obj.host_aliases[key])
I also tried to understand the sudoers object so I followed your link to
python-sudoers but the examples all start with "from pysudoers import Sudoers" while you are doing: "from SudoersLib import *". I find no manuals on the usage of SudoersLib so I can't help with that.