4 ms·
This is besides the point, but is this actually valid Python? if not account.allow_negative: if (balance.available_ignoring_collateral if ignore_co
by russellbeattie 3y ago
This is besides the point, but is this actually valid Python?
if not account.allow_negative:
if (balance.available_ignoring_collateral if ignore_collateral else balance.available) < 0:
raise BadRequest('Account does not have enough balances')
Not sure what's going on inside that second if statement.
- vba616 3y agoI think it is? I don't have much python experience, but I think that inner expression is equivalent to ignore_collateral ? balance.available_ignoring_collateral : balance.available Personally I would agree that it would be clearer if the syntax was more differentiated between a conditional expression and a statement.
- a_e_k 3y agoYes, that's Python's ternary. https://docs.python.org/3/reference/expressions.html#conditional-expressions https://docs.python.org/3/reference/expressions.html#conditi...
- o11c 3y agoPython's (T if C else F) is most languages' (C ? T : F)
- EdwardDiego 3y agoPython ternary.