Oct-05-2019, 09:14 AM
(This post was last modified: Oct-05-2019, 09:14 AM by Gribouillis.)
I think a good reason for
This may perhaps avoid such software errors. I don't think it's likely to change in the specification of the python language.
Note that nothing prevents you from defining
int('4.5')
to raise an exception is that unicode strings appear in the interaction with human users, for examplenp = int(input("How many persons are in the room? "))By default, an answer such as 4.5 raises an exception and it seems to me the most consistent thing to do in the general case. It means that if you want your program to be tolerant to inaccuracies in numerical values, you need to implement it explicitly.
This may perhaps avoid such software errors. I don't think it's likely to change in the specification of the python language.
Note that nothing prevents you from defining
def int2(data): try: return int(data) except ValueError: return int(float(data))