Does anybody have a quickie for converting an unsafe string to an int?
int
The string typically comes back as: \'234\\r\\n\' or something like
\'234\\r\\n\'
You could just:
def to_int(unsafe_string): return int(unsafe_string.strip())
But it will throw a ValueError if the stripped unsafe_string is not a valid number. You can of course catch the ValueError and do what you like with it.
ValueError
unsafe_string