3 ms·
Oh fun. Just what Python needs more of, this... try: value = int(value_to_parse) except ValueError: import sys __old_int_max_s
by mywittyname 4y ago
Oh fun. Just what Python needs more of, this...
try:
value = int(value_to_parse)
except ValueError:
import sys
__old_int_max_str_digits = sys.get_int_max_str_digits()
sys.set_int_max_str_digits(0)
value = int(value_to_parse)
sys.set_int_max_str_digits(__old_int_max_str_digits)
Or maybe just this:
class UnboundedIntParsing:
def __enter__(self):
self.__old_int_max_str_digits = sys.get_int_max_str_digits()
return self
def __exit__(self, *args):
sys.set_int_max_str_digits(self.__old_int_max_str_digits)
with UnboundedIntParsing as uip:
value = int(str_value)
- dmurray 4y agoNeeds to be made thread safe!
- sidewndr46 4y agoYeah, I like the context manager version of this. That way it's maintainable!