As an example:
def some_method():
errors = []
resp1 = func1(..., errors)
resp2 = func2(..., errors)
if errors:
print(f"Overall errors encountered: {errors}")
else:
print(f"Output={resp1+resp2}")
def func1(..., errors):
# Do some processing
if success:
return response
else:
errors.append("Error occurred in func2")
return
def func1(..., errors):
# Do some processing
if success:
return response
else:
errors.append("Error occurred in func2")
return
Should I rather initialize a local variable and return it so we get a tuple from the called functions 1 and 2. And then in some_method
we extend the errors list.
What is a more pythonic way? And is passing lists a bad practice? Here it works in my favour because to each method, the errors list is passed as a reference so the original list gets appended to in each function called.