On 09/14/2012 12:30 AM, Eric Bennett wrote:
> Actually it's a bit of a hindrance. In Perl I can call the int function on anything and get a sensible answer. In python if you call int on a string that contains a floating point number the default behavior is that it will crash:
The sensible answer you describe may be considered a buggy behavior. If
you use int() converter in your code, my guess is that you anticipate it
will be processing a bunch of strings that are expected to represent
integers. If you have a string and you want it to be converted to
integer even if it actually looks like a float, you can do this
number = int(float(example_string))
or this
import math
number = math.floor(float(example_string))
or perhaps this (more sensible)
number = round(float(example_string))
I wonder what situation you have in mind when forcing non-integer string
data to become integers with a slightly shorter expression gives an
advantage. On a broader point, I am sure that perl-bashers can come up
with examples of said language behavior they may want to ridicule.
Different computer languages will exhibit different behavior because
they are, well, different.
> That's brain dead. IMHO of course.
Name-calling is not an argument. It's not quite Godwin's rule, but still.
Cheers,
Ed.
|