Reputation: 7900
There are lots of repetitions in my code like this block:
if err:
print('Could not parse text!')
print('Error code={}'.format(err.code))
print('Error message={}'.format(err.message))
return err.code
I want to make it look nicer, maybe in just one line of code.
So I want to order the compiler to do this in one line:
if there is an error, print necessary information and return error code, otherwise continue execution.
Something like this:
def error_output(err, text):
print(text)
print('Error code={}'.format(err.code))
print('Error message={}'.format(err.message))
return err.code
return_if(err, error_output, 'Parse error')
Tried this:
return error_output(err,'parse error') if err else continue
But of course it's not possible to use continue
like this.
Upvotes: 1
Views: 639
Reputation: 85492
How about:
if err: return error_output(err, 'parse error')
# more code here
Upvotes: 3