[Tutor] python qn

Danny Yoo dyoo at hashcollision.org
Thu Sep 11 19:10:39 CEST 2014


On Thu, Sep 11, 2014 at 8:08 AM, Carmel O'Shannessy <carmelos at umich.edu> wrote:
>
> Hello,
>
> times  =  ['50.319468', '50.319468', 't1']
>
> I want to convert  [0:2] to floats.
>
> I tried:
>
> float.times = [float(i) for i in times[:2]]

Hi Carmel,

Do you intend to have a variable named "float.times" here on the left
hand side of the assignment?

If so, try a different name.  What's happening is not variable
assignment, but member assignment.  The above statement is saying:

    Take the "float" type, and set its "times" attribute to the right hand side.

And that's almost certainly not what you want to do.


More information about the Tutor mailing list