1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python > ExcelのシートからCの配列を作る

Posted at
動作環境
ideone (Python 3.5)

Cのテスト用データ

  • 動作テスト用データがcsv形式である
  • {0, 3, 0}, {100, 3, 0},...のような形式にしたい
  • 組込みCのソースにて使いたい

手作業で上記のフォーマットを作っていくと時間がかかる。

Pythonスクリプト

Note: 2018年4月18日現在、ideoneのエラーが頻発する

# 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},
1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?