質問するログイン新規登録

回答編集履歴

4

誤植の修正

2017/07/17 15:03

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -26,7 +26,7 @@
26
26
  さらに、updateメソッドの[使い方](http://qiita.com/HirofumiYashima/items/dd8cf18cd4a3e3c3c6db#%E8%BE%9E%E6%9B%B8%E5%9E%8B%E3%82%AF%E3%83%A9%E3%82%B9%E3%81%AE-update%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89%E3%82%92%E4%BD%BF%E3%81%86)。
27
27
  > dict['氏名'].update({'追加科目名1' : '点数', '追加科目名2' : '新点数'})
28
28
 
29
- updataメソッドの引数は辞書型なのですね。
29
+ updateメソッドの引数は辞書型なのですね。
30
30
 
31
31
  ---
32
32
  **結局なんでエラーが生じているのか**

3

良さげなサイトを発見

2017/07/17 15:03

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -71,4 +71,7 @@
71
71
  """
72
72
  ```
73
73
 
74
- うん、予想通り。
74
+ うん、予想通り。
75
+
76
+ ---
77
+ [色んな引数の与え方がある](http://st-president-program.seesaa.net/article/420910487.html)んですね。

2

実験追記

2017/07/17 14:15

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -46,4 +46,29 @@
46
46
  return template('index', {'row': row})
47
47
  ```
48
48
 
49
+ 実験してみました
49
- -
50
+ ---
51
+ ```Python
52
+ def func(*args, **kwargs):
53
+ for dictarg in args:
54
+ kwargs.update(dictarg)
55
+
56
+ print(kwargs)
57
+
58
+ tmplist = list(range(4))
59
+ func(a=tmplist)
60
+ func({'b': tmplist})
61
+ func(tmplist)
62
+ """ 実行結果
63
+ {'a': [0, 1, 2, 3]}
64
+ {'b': [0, 1, 2, 3]}
65
+ Traceback (most recent call last):
66
+ File "tmptest.py", line 10, in <module>
67
+ func(tmplist)
68
+ File "tmptest.py", line 3, in func
69
+ kwargs.update(dictarg)
70
+ TypeError: cannot convert dictionary update sequence element #0 to a sequence
71
+ """
72
+ ```
73
+
74
+ うん、予想通り。

1

--

2017/07/17 14:08

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -44,4 +44,6 @@
44
44
  試しに、次のようにしたら動きませんか?
45
45
  ```Python
46
46
  return template('index', {'row': row})
47
- ```
47
+ ```
48
+
49
+ -