float does not parse '0.000000E+00'

Gareth McCaughan Gareth.McCaughan at pobox.com
Sat Jun 3 19:29:12 EDT 2000


Paolo Redaelli wrote:

> Oh, well. It seems I'm missing an obvious thing.
> I post here my program and the data that caused the problem

I tried running this. It didn't work, but not for reasons
connected with float(). First of all, it complained (after,
so far as I can tell, successfully parsing two floats --
so actually it looks like it's already got past the point
at which it failed for you) at "Node(node,xx,yy)" because
there were no variables called xx,yy. I replaced them with x and y.

Then it complained at an assignment to load_case.nodes[node]
with an out-of-range error. I made it set loadcase.nodes.size
and loadcase.rods.size after it had got loadcase.nodes_n and
loadcase.rods_n.

Then it complained at an assignment to load_case.rods[rod_n].
I fixed the preceding line so that it assigned the result
of map(int, [rod_n, etc]) to the obvious thing instead of
throwing it away.

At that point it made it through the creation of the Telaio
object without complaining.

                       *  *  *

The output you quoted doesn't look complete. It has a
traceback but doesn't say what kind of exception was
raised. Could you post the whole message?

I wonder whether your file might contain some funny
characters (though I'd have thought they'd show up if
so). Try adding, after that diagnostic "print", another
line that says

    print map(ord, x)

and see if there are any values in the list it prints
outside the range 32..126. Or change the print line
to
  print "x(%s)=%s y(%s)=%s" % (type(x),`x`,type(y),`y`)
for more readable output that should give the same
information: look for unexpected escapes in the output.

                          *

Does the following program produce a similar error for you?

for line in open("LCASE.001").readlines():
  for item in string.split(line):
    print "About to try parsing:", item
    x = float(item)
    print "Result is:", x

                          *

Is the LCASE.001 file you posted the only LCASE* file
in the relevant directory, or might it actually have been
during the parsing of a *different* file that it fell over?

                       *  *  *

Something else I happened to spot: you have "lenght"
instead of "length" in a few places. Shouldn't make
any difference to the running of the program, though.

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
sig under construction



More information about the Python-list mailing list