私はいくつかのpython 2.5コードを理解しようとしていますが、このパターンに出くわしました:
def __init__(self, matrix, top_buttons, side_buttons, config_button):
raise isinstance(matrix, ButtonMatrixElement) or AssertionError
raise matrix.width() == 8 and matrix.height() == 8 or AssertionError
raise isinstance(top_buttons, tuple) or AssertionError
raise len(top_buttons) == 8 or AssertionError
raise isinstance(side_buttons, tuple) or AssertionError
raise len(side_buttons) == 8 or AssertionError
raise isinstance(config_button, ButtonElement) or AssertionError
次のような単純な条件ステートメントを使用して、シェルでこれをテストしてみました。
>>> str = 'hello'
>>> raise len(str) == 5 or AssertionError
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
raise len(str) == 5 or AssertionError
TypeError: exceptions must be classes, instances, or strings (deprecated), not bool
したがって、このテストから判断すると、少なくとも私が試した方法では、ブール値のステートメントを上げることはできません。では、条件式を発生させるとはどういう意味ですか?関数では__init__
機能するのに、テスト コードでは機能しないのはなぜですか?