Friday, February 1, 2019

[python][resolved] expected string or bytes-like object

Error message:
TypeError: expected string or bytes-like object
Example with error code:
num_list = re.findall(r"[-+]?\d*\.\d+|\d+", txt)
return int(num_list[0])
You can convert the argument as str if you want use int function:
num_list = re.findall(r"[-+]?\d*\.\d+|\d+", txt)
return int(str(num_list[0]))
Reference:
https://stackoverflow.com/questions/43727583/re-sub-erroring-with-expected-string-or-bytes-like-object

No comments :

Post a Comment