Trying to split into a dictionary:
output = "Port WWN : 10:00:00:00:xx:xx:xx:01\n"
"Node WWN : 20:00:00:00:xx:xx:xx:01\n"
tried:
d = dict(x.split(": ") for x in output.split("\n"))
print(d)
expected output = {Port WWN : 10:00:00:00:xx:xx:xx:01, Node WWN : 20:00:00:00:xx:xx:xx:01}
getting error:
File "/Users/mike/PycharmProject/pyTest/venv/scratch.py", line 6, in
d = dict(x.split("=") for x in output.split("\n"))
ValueError: dictionary update sequence element #0 has length 1; 2 is required
>Solution :
i think it will solve your issue:
output = "Port WWN : 10:00:00:00:xx:xx:xx:01\nNode WWN : 20:00:00:00:xx:xx:xx:01\n"
d = dict(x.split(": ") for x in output.strip().split("\n"))
print(d)
