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
Use the fact that it generates an exception:
try: variable = int(stringToInt) except ValueError: variable = None
This has the pleasant side-effect of binding variable to None for other common errors: stringToInt='ZZTop', for example.
variable
stringToInt='ZZTop'