Just add the python array to the json data
test.py
#!/env/python
import json
def addJson(list):
# state data to json
json = {
"parameter": list,
}
return json
l = list(range(0))
for i in range(25):
l.append(i)
data = addJson(l)
print(data)
$ python test.py
{'parameter': [0]}
{'parameter': [0, 1]}
{'parameter': [0, 1, 2]}
{'parameter': [0, 1, 2, 3]}
{'parameter': [0, 1, 2, 3, 4]}
{'parameter': [0, 1, 2, 3, 4, 5]}
{'parameter': [0, 1, 2, 3, 4, 5, 6]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]}
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]}
that's all
Extract only the latest value
test.py
#!/env/python
import json
def addJson(list):
# state data to json
json = {
"parameter": list,
}
return json
l = list(range(0))
print(len(l))
for i in range(25):
l.append(i)
data = addJson(l)
print(data)
data_length = len(l)
if data_length <= 0:
Latest_Value = "none"
else:
Latest_Value = str(l[data_length - 1])
print("Latest_Value : " + Latest_Value)
Execution result
$ python test4.py
{'parameter': [0]}
Latest_Value : 0
{'parameter': [0, 1]}
Latest_Value : 1
{'parameter': [0, 1, 2]}
Latest_Value : 2
{'parameter': [0, 1, 2, 3]}
Latest_Value : 3
{'parameter': [0, 1, 2, 3, 4]}
Latest_Value : 4
{'parameter': [0, 1, 2, 3, 4, 5]}
Latest_Value : 5
{'parameter': [0, 1, 2, 3, 4, 5, 6]}
Latest_Value : 6
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7]}
Latest_Value : 7
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8]}
Latest_Value : 8
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
Latest_Value : 9
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}
Latest_Value : 10
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]}
Latest_Value : 11
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]}
Latest_Value : 12
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]}
Latest_Value : 13
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]}
Latest_Value : 14
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]}
Latest_Value : 15
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]}
Latest_Value : 16
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]}
Latest_Value : 17
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]}
Latest_Value : 18
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]}
Latest_Value : 19
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]}
Latest_Value : 20
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]}
Latest_Value : 21
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]}
Latest_Value : 22
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]}
Latest_Value : 23
{'parameter': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]}
Latest_Value : 24
Recommended Posts