|
From: Jeff E. <jem...@fr...> - 2015-08-08 21:17:50
|
I suggest, this to see if there is whitespace in your Amount string:
Amount=x[0]
try:
x=float(Amount)
except ValueError:
print repr(Amount)
You might need strip() after split()
I can't tell what you are trying to accomplish by this, but it's not doing you any good getting to a parsable string.
ltrg = ';'.join(valueList[12:13])
On 8/8/2015 12:33 PM, Peter O'Reilly wrote:
> I am reading from a file and convert a columns from a list value to a string.
>
> Then I try and convert from a str to a float, but get this error.
> x=float(Amount)
> ValueError: invalid literal for __float__:
>
> If I copy the value from the file and assign it to the str variable(Amount), the float function works as expected.
>
> It seems like it might be some type of encoding issue, anyone else have a similar problem? This is the code.
>
> while (lsrc):
> valueList = lsrc.split(';')
> ltrg = ';'.join(valueList[12:13])
> x=ltrg.strip().split('\r\n')
> Amount=x[0]
> x=float(Amount)
>
> Thanks,
> PR
>
>
> ------------------------------------------------------------------------------
>
>
> _______________________________________________
> Jython-users mailing list
> Jyt...@li...
> https://lists.sourceforge.net/lists/listinfo/jython-users
|