回答編集履歴

1

修正

2020/06/26 00:19

投稿

LouiS0616
LouiS0616

スコア35668

test CHANGED
@@ -10,8 +10,6 @@
10
10
 
11
11
  def spam1():
12
12
 
13
- print('spam')
14
-
15
13
  try:
16
14
 
17
15
  print('try')
@@ -22,17 +20,11 @@
22
20
 
23
21
  print('finally')
24
22
 
25
-
26
-
27
- print('return')
28
-
29
23
 
30
24
 
31
25
  @contextmanager
32
26
 
33
27
  def spam2():
34
-
35
- print('spam')
36
28
 
37
29
  print('try')
38
30
 
@@ -40,49 +32,41 @@
40
32
 
41
33
  print('finally')
42
34
 
43
- print('return')
35
+
44
36
 
45
37
 
46
38
 
47
- print('-'*48)
39
+ for spam in [spam1, spam2]:
48
40
 
49
- try:
41
+ print('-'*48)
50
42
 
51
- with spam1():
43
+ try:
52
44
 
53
- raise Exception
45
+ with spam():
54
46
 
55
- except Exception:
47
+ print('with')
56
48
 
57
- print('exception')
49
+ raise Exception
58
50
 
59
-
51
+ except Exception:
60
52
 
61
- print('-'*48)
53
+ print('exception')
62
54
 
63
- try:
64
55
 
65
- with spam2():
66
-
67
- raise Exception
68
-
69
- except Exception:
70
-
71
- print('exception')
72
56
 
73
57
  ```
74
58
 
75
59
 
76
60
 
77
- **実行結果** [Wandbox](https://wandbox.org/permlink/p9FeinaOmPsQ1hX1)
61
+ **実行結果** [Wandbox](https://wandbox.org/permlink/HLq8S1n1RIzmt0bV)
78
62
 
79
63
  ```
80
64
 
81
65
  ------------------------------------------------
82
66
 
83
- spam
67
+ try
84
68
 
85
- try
69
+ with
86
70
 
87
71
  finally
88
72
 
@@ -90,9 +74,9 @@
90
74
 
91
75
  ------------------------------------------------
92
76
 
93
- spam
77
+ try
94
78
 
95
- try
79
+ with
96
80
 
97
81
  exception
98
82