Create a C array from a Python> Excel sheet

Operating environment


ideone (Python 3.5)

C test data

--Operation test data is in csv format --I want to format it like {0, 3, 0}, {100, 3, 0}, ... --I want to use it with the embedded C source

It takes time to manually create the above format.

Python script

Note: ** As of April 18, 2018, ideone errors occur frequently **

https://ideone.com/yN0wSe

# change [NUM_COLUMN]
NUM_COLUMN = 3
# paste from Excel sheet
data="""0	3	0
100	3	0
200	3	0
300	3	0
400	3	0
500	3	0
"""

for aline in data.split('\n'):
    elem = aline.split('\t')
    if len(elem) < NUM_COLUMN:
        break
    print("{%s,%s,%s}," % (elem[0], elem[1], elem[2]), end='')

run


{0,3,0},{100,3,0},{200,3,0},{300,3,0},{400,3,0},{500,3,0},

Recommended Posts

Create a C array from a Python> Excel sheet
Create a python numpy array
Create a deb file from a python package
Create a dataframe from excel using pandas
Run a Python script from a C # GUI application
Create a Python module
Create a New Todoist Task from Python Script
Run python from excel
[Python] [Excel] Operate an Excel sheet from Python using openpyxl (using a test sheet as an example)
Create a decision tree from 0 with Python (1. Overview)
Call a Python script from Embedded Python in C ++ / C ++
Create a datetime object from a string in Python (Python 3.3)
Create a Python environment
Run a python script from excel (using xlwings)
Python points from the perspective of a C programmer
[python] Create a date array with arbitrary increments with np.arange
Python script to create a JSON file from a CSV file
[Python] How to call a c function from python (ctypes)
How to create a kubernetes pod from python code
Create a Wox plugin (Python)
Create a function in Python
Create a dictionary in Python
Create a directory with python
How to slice a block multiple array from a multiple array in Python
Python: Create a dictionary from a list of keys and values
Call a Python function from p5.js.
Solve ABC163 A ~ C with Python
Call C from Python with DragonFFI
Create Awaitable with Python / C API
Touch a Python object from Elixir
ABC127 A, B, C Explanation (python)
Create a python GUI using tkinter
Create a DI Container in Python
Create folders from '01' to '12' with python
Create a pandas Dataframe from a string.
Create a Python environment on Mac (2017/4)
ABC166 in Python A ~ C problem
Call popcount from Ruby / Python / C #
Create a virtual environment with Python!
Create an Excel file with Python3
Create a binary file in Python
Python cheat sheet (for C ++ experienced)
python / Make a dict from a list.
Solve ABC168 A ~ C with Python
Solve ABC036 A ~ C in Python
Create a python environment on centos
Tips for calling Python from C
Execute Python code from C # GUI
Solve ABC162 A ~ C with Python
Create a Python general-purpose decorator framework
Run Python scripts synchronously from C #
Solve ABC167 A ~ C with Python
Create a Kubernetes Operator in Python
ABC128 A, B, C commentary (python)
Solve ABC158 A ~ C with Python
ABC126 A, B, C Explanation (python)
5 Ways to Create a Python Chatbot
Solve ABC037 A ~ C in Python
Create a random string in Python
Call C / C ++ from Python on Mac
Create a C wrapper using Boost.Python