Division exception in MYSQL or Python

Gunel :

I would like to automate the division by 0. Some of variable extracted from db might equal 0 and division would give an error. Should I make an exception In DB or in python code?

Mehrdad Pedramfar :

This is better:

for b in varb:
    try:
        v = 1/b # or any code that raises division by zero
        print(v)
    except ZeroDivisionError:
        print(0)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=21781&siteId=1