Every line of 'str to int in python 3' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
75 def to_int(value): 76 return int(value)
58 def to_int(input): 59 try: 60 return int(input) 61 except ValueError: 62 raise Exception ('Input is not an integer')
62 def str_to_int(x): 63 try: 64 return int(str_to_float(x)) 65 except: # noqa E722 66 return x
375 def str_to_int(value, err_msg=None): 376 """ 377 Converts str to int if str represents a valid int 378 :param value: 379 :type: str, int, or None 380 :param err_msg: A optional error message to use 381 :type: str 382 :returns: 383 :type: int or None 384 """ 385 if is_str_unicode(value): 386 try: 387 a = int(value) 388 if value.isalpha(): # (ie. NaN or Infinity) 389 raise ValueError(err_msg) 390 else: 391 return a 392 except ValueError: 393 raise ValueError(err_msg) 394 elif isinstance(value, int): 395 return int(value) 396 elif value is None: 397 return None 398 else: 399 raise ValueError("str_to_int: Input value must be a string, int, or " 400 "None. Value was %s." % value)
226 def _bytes_to_int(b): 227 return int(codecs.encode(b, "hex"), 16)
81 def integer_from_Intel2(int_string): 82 # return first integer decoded from 2-byte-intel-format string 83 # jjk 04/25/96 84 return integer_from_Intel(int_string[:2])
40 def is_int(s: str) -> bool: 41 try: 42 int(s) 43 return True 44 except ValueError: 45 return False
336 def _convert_stringval(value): 337 """Converts a value to, hopefully, a more appropriate Python object.""" 338 value = six.text_type(value) 339 try: 340 value = int(value) 341 except (ValueError, TypeError): 342 pass 343 344 return value
20 def _to_int(value): 21 if value is None: 22 return 0 23 return int(value)
14 def _force_int(a_string): 15 """Return the string as an int. If it can't be made into an int, return 0.""" 16 try: 17 an_int = int(a_string) 18 except (ValueError, TypeError): 19 an_int = 0 20 21 return an_int