int(digits) == 123456 , which is a true ish value. So conv_d = digits != None . Because digits not None , conv_d set to true.
You probably wanted to:
conv_d = int(digits) if digits is not None else None
Remember that a string containing something other than a number throws an exception! If you prefer 0 or None for these values, write a small function:
def toint(s): try: return int(s) except (ValueError, TypeError): return None
source share