Learning Python and a little bit stuck.
I\'m trying to set a variable to equal int(stringToInt) or if the string is empty set to None.
int(stringToInt)
None
Here are some options:
Catch the exception and handle it:
try: variable = int(stringToInt) except ValueError, e: variable = None
It's not really that exceptional, account for it:
variable = None if not stringToInt.isdigit(): variable = int(stringtoInt)