There is a view code
try: a = 3 / x except ZeroDivisionError: pass try: b = 3 / y except ZeroDivisionError: pass try: c = 3 / z except ZeroDivisionError: pass those. an error in one calculation should not interfere with the rest. In VBA, it would be possible to set the On Error Resume Next command before calculations. Is it possible to make this code somehow easier in python?
Or is it generally better to use conditional operators instead of exceptions?
UPD
During the discussion, it turned out that the real task still affects the answer. I use openpyxl .
try: _ = ws.cell(row=i, column=required_columns.pp, value=pp) except ValueError: pass try: _ = ws.cell(row=i, column=required_columns.sum, value=sum) except ValueError: pass where required_columns is a namedtuple containing the numbers of the columns to which the data is output. If the column is not needed, then its value is 0, and this try just skips it. The return value is not used anywhere.
Nonewill fall into a):a = 3 / x if x else None- insolortryplace underexcept? Then generally it will not be what is needed. - Edward Izmalkov