On Wed, Aug 10, 2011 at 3:16 PM, Shwinn Ricci <arm...@gmail.com> wrote:

> I am reading values from excel using xlrd and using a variable to store
> them in (as part of a loop), as such:
>
>  position = sheet.cell(j, i).value
>
> however, I want to convert position to a floating point number, as the
> actual cell value is in the form of X.XXX (where X = digits). When I try
> float(position) I get a ValueError saying that the string could not be
> converted to a float. What am I doing wrong?
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


Have you tried printing the value to see what position actually holds?

If it has an apostrophe or something or something, you're not going to be
able to convert.

Also, as always, you should post the entire trace.

It could be helpful here, for example:

>>> x = '1. 1 '
>>> float(x)

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    float(x)
ValueError: invalid literal for float(): 1. 1
>>>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to