tags:

views:

1025

answers:

4

Hi all. I am running a code to select chunks from a big file. I am getting some strange error that is

"Invalid literal for float(): E-135"

Does anybody know how to fix this? Thanks in advance.

Actually this is the statement that is giving me error

float (line_temp[line(line_temp)-1])

This statement produces error line_temp is a string 'line' is any line in an open and file also a string.

+5  A: 

You need a number in front of the E to make it a valid string representation of a float number

>>> float('1E-135')
1e-135
>>> float('E-135')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): E-135

In fact, which number is E-135 supposed to represent? 1x10^-135?

Valid literal forms for floats are here.

Vinko Vrsalovic
kindly check the question again
+1  A: 

Looks like you are trying to convert a string to a float. If the string is E-135, the it is indeed an invalid value to be converted to a float. Perhaps you are chopping off a digit in the beginning of the string and it really ought to be something like 1E-135? That would be a valid float,

scrible
kindly check the question here
kindly check the question again
+1  A: 

May I suggest you replace

float(x-y)

with

float(x) - float(y)
krawyoti
No actually i need that output in that form like 1e-35. it has to be this way or e-35.
+1  A: 

Ronald, kindly check the answers again. They are right. What you are doing is: float(EXPRESSION), where the result of EXPRESSION is E-135. E-135 is not valid input into the float() function. I have no idea what the "line_temp[line(line_temp)-1]" does, but it returns incorrect data for the float() function.

ondra