Modify Incoming Data from Dataset Tag and Write Modified Values Back to Same Tag

I'm working on a program that pings an IP device and modifies a boolean value based on the result within a gateway timer script. I am well aware that Datasets and Pydatasets cannot be modified without creating an entirely new dataset, so I have converted these values to a dictionary of lists shown below:

event = system.dataset.toPyDataSet(system.tag.read("[default]Tyler/Guardian/Line2Devices").value)
row = 0
col = 0
newdict = {}
for row in range(event.getRowCount()):
	newdict[row] = [str(event[row][0]), str(event[row][1]), event[row][2]]
	row = row + 1
row =0
for row in range(event.getRowCount()):
	x = newdict.get(row)
	
	ip = x[1]
	result =  ping.ping(ip)
	x[2] = result
	newdict[row] = x

print(newdict)

After the print() executes, here is the result in the console (for security reasons, I have blocked the IP addresses, but I can verify they are showing up as expected):

The reason I chose to use a dataset tag is that I want the column and row sizes to be dynamic in that if we decide to add other devices(rows) or new data pertaining to each device(columns), that the script could remain unchanged. I am having difficulty finding a method to write this dictionary of lists back to the dataset tag after the values are modified. I tried this code snippet following the one above(I apologize in advance for the redundancy within):

row = 0
col = 0
for row in range(event.getRowCount()):
	row = []
	for col in range(event.getColumnCount()):
		row.append(col)
	datawrite.append(row)
headers = ["Name", "IP", "Online"]
ds = system.dataset.toDataSet(headers,datawrite)
last = system.dataset.toPyDataSet(ds)
system.tag.write("[default]Tyler/Guardian/Line2Devices", last)

Unfortunately, this simply wrote the memory addresses of the values to the tag instead of the values themselves.

Thank you in advance for any insight you might be able to give.

In this particular instance, you don't need to make a dictionary out of it. You can process each row directly.

EDIT: To clarify, a row is processed and then written to a row constructing the new dataset. Words mean things. :wink:

Consider using system.tag.readBlocking and system.tag.writeBlocking, as system.tag.read() and system.tag.write() are deprecated.

tagName = "[default]Tyler/Guardian/Line2Devices"

event = system.dataset.toPyDataSet(system.tag.readBlocking([tagName])[0].value
headers = list(event.getColumnNames())
dataOut = []

for row in event:
	ip = str(row[1])
	result = ping.ping(ip)
	dataOut.append = [str(row[0]), row[1], result]

system.tag.writeBlocking([tagName],[system.dataset.toDataSet(headers, dataOut)])

Hmm.

and Write Modified Values Back to Same Tag

Don't do this. Write the results to another tag. Data should flow in one direction, except where users make changes.