import string


def less_dangerous_eval(equation):
    """
    Restrict expression that can be evaluated
    Thanks to https://stackoverflow.com/questions/19959333/convert-a-string-equation-to-an-integer-answer/19959928#19959928
    :param equation:
    :return:
    """
    # eval will run whatever it is given, even code, so it is dangerous to expose it to unsanitised input
    if not set(equation).intersection(string.ascii_letters + '{}[]_;\n'):
        return eval(equation)
    else:
        print("illegal character")
        return None