[Tutor] Using if statement with csv file

Danny Yoo dyoo at hashcollision.org
Tue Jan 27 19:28:11 CET 2015


>
> In your code, you are comparing a string (an element of your CSV row)
> with a number.


Whoops, forgot to include recommendations. You probably do not want to
have comparisons of mixed type.  As we have found, the result we get
back is arbitrary and capricous.  Rather, we probably want to compare
two numbers.

To interpret a string as a number, use the int() or float() functions.

############################
>>> '10' > 10
True
>>> int('10') > 10
False
############################

References:

    https://docs.python.org/2/library/functions.html#int
    https://docs.python.org/2/library/functions.html#float


More information about the Tutor mailing list