Just add the python array to the json data

Just add the python array to the json data

code

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)

Execution result

$ 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

Postscript

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

Just add the python array to the json data
Convert Excel data to JSON with python
[pepper] Pass the JSON data obtained by python request to the tablet.
[Introduction to Python] How to handle JSON format data
Speed: Add element to end of Python array
Just add the driver to the shape key with blender
Write data to KINTONE using the Python requests module
Read json data with python
[Python] It might be useful to list the data frames
Various ways to calculate the similarity between data in python
Build a Python environment and transfer data to the server
[Introduction to Python] How to get data with the listdir function
Pass OpenCV data from the original C ++ library to Python
[Python] How to FFT mp3 data
Leave the troublesome processing to Python
Subscript access to python numpy array
[Introduction to Python] How to parse JSON
Add Python 2.7 Japanese documentation to Dash.app
In the python command python points to python3.8
How to get the Python version
[Python] How to import the library
[Python] How to swap array values
Python logging and dump to json
Add TRACE log level to Python ...?
[Python] Change the alphabet to numbers
Links to people who are just starting data analysis with python
[Python] How to store a csv file as one-dimensional array data
Try to solve the shortest path with Python + NetworkX + social data
We have extended the Python Proxy, which runs Proxy in just 200 lines, to add access denial functionality.
Data input / output in Python (CSV, JSON)
Add syntax highlighting for the Kv language to Spyder in the Python IDE
[Introduction to Python3, Day 17] Chapter 8 Data Destinations (8.1-8.2.5)
Add a Python data source with Redash
Python: Reading JSON data from web API
[Introduction to Python3, Day 17] Chapter 8 Data Destinations (8.3-8.3.6.1)
[Python] Round up with just the operator
[Python] Three methods to compare the list of one-dimensional array and the list of two-dimensional array and extract only the matching values [json]
Add 95% confidence intervals on both sides to the diagram with Python / Matplotlib
Try to image the elevation data of the Geographical Survey Institute with Python
[Introduction to Python3 Day 19] Chapter 8 Data Destinations (8.4-8.5)
Convert FX 1-minute data to 5-minute data with Python
In Jupyter, add IPerl to the kernel.
[Introduction to Python3 Day 18] Chapter 8 Data Destinations (8.3.6.2 to 8.3.6.3)
Send and receive image data as JSON over the network with Python
Python amateurs try to summarize the list ①
Just migrate the Discord.py 0.X echobot to 1.X
Python #JSON
Convert array (struct) to json with golang
[Python] Add total rows to Pandas DataFrame
How to use "deque" for Python data
Add Gaussian noise to images with python2.7
How to add python module to anaconda environment
Compress python data and write to sqlite
Add a Python virtual environment to VSCode
[Python] Add comments to standard input files
[Introduction to Data Scientists] Basics of Python ♬
The road to compiling to Python 3 with Thrift
Get the key for the second layer migration of JSON data in python
How to sort by specifying a column in the Python Numpy array.
[Python] Combine all the elements in the array
I made a function to see the movement of a two-dimensional array (Python)