回答編集履歴

3

コード変更

2022/10/05 08:51

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -11,7 +11,7 @@
11
11
  File "<stdin>", line 1, in <module>
12
12
  TypeError: writerows() takes exactly one argument (3 given)
13
13
  >>> csv.writer(open('t.csv', 'w')).writerows([[1, 2, 3]])
14
- >>> print(open('t.csv').read())
14
+ >>> open('t.csv').read()
15
- 1,2,3
15
+ '1,2,3\n'
16
16
  ```
17
17
 

2

コード追記

2022/10/05 08:48

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -3,3 +3,15 @@
3
3
  「writerows()はひとつ(one)の引数(argument)しかとりません (なのに3つ与えられとる)」
4
4
 
5
5
  ということは、`writerows([[1, 2, 3]])` のように書くべきところを `writerows(1, 2, 3)` とか書いているのでは?
6
+
7
+ ```py
8
+ >>> import csv
9
+ >>> csv.writer(open('t.csv', 'w')).writerows(1, 2, 3)
10
+ Traceback (most recent call last):
11
+ File "<stdin>", line 1, in <module>
12
+ TypeError: writerows() takes exactly one argument (3 given)
13
+ >>> csv.writer(open('t.csv', 'w')).writerows([[1, 2, 3]])
14
+ >>> print(open('t.csv').read())
15
+ 1,2,3
16
+ ```
17
+

1

修正

2022/10/05 08:46

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  「writerows()はひとつ(one)の引数(argument)しかとりません (なのに3つ与えられとる)」
4
4
 
5
- ということは、`writerows([1, 2, 3])` 書くべきところを `writerows(1, 2, 3)` と書いているのでは?
5
+ ということは、`writerows([[1, 2, 3]])` のように書くべきところを `writerows(1, 2, 3)` と書いているのでは?