Hm... what if all elements of the 3 lists are packed into one dict?
The single quotes are invalid for use in JSON.
I look more like Python Code.
You could use
(Mar-10-2022, 11:09 AM)ilknurg Wrote: [{'Manufacturer': 'VMware, Inc.', 'Model': 'VMware7,1', 'Name': 'DC01'}]
[{'Index': '1', 'IPAddress': ['192.168.1.240,fe80::350e:d28d:14a5:5cbb']}]
[{'Name': 'DC01', 'UserName': None}]
The single quotes are invalid for use in JSON.
I look more like Python Code.
You could use
ast.literal_eval
, which is safe.from ipaddress import ip_address from ast import literal_eval def parse(file): result = {} with open("data.txt") as fd: for line in fd: # skipping empty lines with only # whitespace if not line.strip(): continue for element in literal_eval(line): result |= element # example to change existing data on result # list contains 1 str with many ip addresses # the addresses are splitted by a comma if "IPAddress" in result: ip_addresses = [] # get the list from IPAddresses # and take the first element (there is only one) # then split this str by comma for ip in result["IPAddress"][0].split(","): # creating a IPv4Address or IPv6Address instance from # the str of the ip address. Not required ip_addresses.append(ip_address(ip)) # to append only the str # ip_address.append(ip) # assign the ip_addresses result["IPAddress"] = ip_addresses return result
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!