回答編集履歴

3

エラー原因について説明追記

2020/05/08 12:47

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -74,4 +74,24 @@
74
74
 
75
75
  w.writerow([note.start, note.end, note.pitch, note.velocity])
76
76
 
77
+
78
+
79
+ # XXX: w.writerows(notes) がエラー原因。理由は先述の通りデータの変換が必要
80
+
81
+
82
+
83
+ # with open() ~では、
84
+
85
+ # インデントで表現されたブロックの終端でファイルが閉じます。
86
+
87
+ # ブロックの終端は、下の for 文でインデントがwith~と同じ位置に戻る箇所。
88
+
89
+
90
+
91
+ for note in notes:
92
+
93
+ # ここでの w.writerow は、ファイルが閉じられてるので無効。
94
+
95
+ print(note)
96
+
77
97
  ```

2

w.writerow を呼び出す位置の確認用コードを追記

2020/05/08 12:47

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -53,3 +53,25 @@
53
53
  w.writerows(map(attrgetter("start", "end", "pitch", "velocity"), notes))
54
54
 
55
55
  ```
56
+
57
+
58
+
59
+
60
+
61
+ ----
62
+
63
+ 追記: 実行確認はしてないのでコピペの際は注意。w.writenow の追加位置確認用です。
64
+
65
+
66
+
67
+ ```python
68
+
69
+ with open("new.csv", "w", newline="") as f:
70
+
71
+ w = csv.writer(f)
72
+
73
+ for note in notes:
74
+
75
+ w.writerow([note.start, note.end, note.pitch, note.velocity])
76
+
77
+ ```

1

誤字修正

2020/05/08 12:34

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -1,4 +1,4 @@
1
- notes の中身は確認してませんが、csv.writerows の使い方は
1
+ notes の中身は確認してませんが、writerows の使い方は
2
2
 
3
3
 
4
4