Last active
April 17, 2019 14:56
-
-
Save shihochan/1aaf46f3d94c438379d0e0554a75f298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
# 書き込み用ファイルオープン | |
wf = open('mult99-1.csv', 'w') | |
writer = csv.writer(wf, lineterminator='\n') | |
# 例として 1x1 ~ 3x3 までを想定 | |
for i in range(1, 4): | |
for j in range(1, 4): | |
file = '{0}x{1}.dat'.format(i, j) | |
# 読み込み用ファイルオープン | |
rf = open(file, 'r') | |
reader = csv.reader(rf) | |
list1 = [] | |
for row in reader: | |
# 例:'N1:3\n' => ['N1', '3\n'] | |
list2 = row[0].split(':') | |
# 改行を取り除いてリストに追加 | |
list1.append(list2[1].rstrip('\n')) | |
# 例:['3', '2', '6'] | |
writer.writerow(list1) | |
rf.close() | |
wf.close |
入力ファイル: 1x1.dat
N1:1
N2:1
ANS:1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果