test関数のif a == 0:がtrueの時だけtest3関数の中でtest2関数を動かすことはできますでしょうか?(test関数のprintの下にtest2関数を入れる以外で探しております。test3関数の中でtest関数の後にtest2関数をif a==0:がtrueの時だけ動作させたいです。)
ご存知の方おられましたらご教示お願いいたします。
python
1a = 1 2def test(): 3 if a == 0: 4 print(location(), a) 5 6def test2(): 7 print(location(), a) 8 9def test3(): 10 test() 11 test2() 12 13test3()
理由としましては、test4, test5と今後関数が増えていく予定なので、下記のような運用ができればより管理がしやすくなるからです。
test関数は共通で、実際にはコードがもっと長いです。
python
1def test3_2(): 2 test() 3 test4()
python
1def test3_3(): 2 test() 3 test5()
python
1from collections.abc import Callable 2a = 0 3 4def test(callback): 5 assert isinstance(callback, Callable), f"`callback` is not Callable, 6 if a == 0: 7 print(location(), a) 8 callback() 9 10def test2(): 11 print(location()) 12 13def test3_2(): 14 print(location()) 15 test(test2) 16 17test3_2()
zsh
1SyntaxError: unterminated string literal (detected at line 135)
回答4件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。