Basically what I am trying to do is take an input (see below) and convert the format to the following output (see below). The output being a list of dictionaries. I have been playing with .split() and .strip() but I still having issues in separating the IP address with the room number. (see my code below)
input:
"bromine ";" 00:23:AE:90:FA:C6 ";" 144.38.198.130";151 #(this is just one line in the file, there are several lines with this exact format)
output:
[{'ip': '144.38.198.130', 'mac': '00:23:AE:90:FA:C6', 'name': 'bromine', 'room': '151'}] #(again this would be just one of the lines)
My code:
import sys
my_list = []
file = sys.stdin
for line in file:
# d = {}
line = line.strip('"')
line = line.split()
name = line[0]
macAddress = line[2]
ipAddress = line[4]
#roomNum = [?]
d={'ip': ipAddress, 'mac': macAddress, 'name': name, 'room': None}
my_list.append(d)
#print line
print d
This is the output I'm getting: {'ip': '144.38.196.157";119', 'mac': '00:23:AE:90:FB:5B', 'name': 'tellurium', 'room': None}
Close but no cigar, trying to separate the 119