In Ruby an empty array returns a nil if the first element is accessed:
2.1.2 :005 > arr = []
=> []
2.1.2 :006 > arr.first
=> nil
2.1.2 :007 > arr[0]
=> nil
I know Python lists are not exactly the same as Ruby arrays, but if you try the equivalent action, you get an error:
>>> l = []
>>> l[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
How can I instead of an error get a False or None value?
Ideally I'd like an assignment like this to resolve to None / False if the function call returns nothing, but with an inline check rather than a if block.
tp_journal = self.pool.get('account.journal').browse(cr, uid, tp_ids, context=context)[0]
try ... exceptclause.((expression) or [None])[0]would be a simple hack to achieve that.