Found the problem! Was Re: float does not parse '0.000000E+00'

Paolo Redaelli redaelli at inc.it
Sun Jun 4 06:11:57 EDT 2000


I found the problem. It's related to lists; it seems to me that python
does not allow smoothly things like:
numbers = [n,m] =  map(int, numbers)

Gareth McCaughan wrote:
> I tried running this. It didn't work, but not for reasons
[...]
> there were no variables called xx,yy. I replaced them with x and y.
oops.. I tried catching the exceptions in that version. It wasn't the
one that fails on float.

> 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.
Thanks for the tip!!!!

> 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
> 
No. it runs smoothly. 

> 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?
LCASE.001 is the only file parsed.

> 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.
...well... that's becuase I'm not a native english speaker and often I
misspell words... 8-)

-- 
 ______________________________
/        Paolo Redaelli        \
|        redaelli at inc.it       |
| http://gnupaghe.netpedia.net |
\------------------------------/
-------------- next part --------------
 1
 4 3
      1  0.000000E+00  0.000000E+00
      2  0.000000E+00  0.300000E+03
      3  0.500000E+03  0.300000E+03
      4  0.500000E+03  0.000000E+00
      1     1     2
      2     2     3
      3     3     4
      1  0.300000E+03  0.000000E+00  0.100000E+01
  0.000000E+00 0.000000E+00 0.000000E+00 0.250000E+04 -.146922E+03 0.652654E+04
  0.150000E+02 0.478073E-01 -.395235E-04 0.250000E+04 -.146922E+03 0.668798E+04
  0.300000E+02 0.956146E-01 -.174419E-03 0.250000E+04 -.146922E+03 0.720229E+04
  0.450000E+02 0.143422E+00 -.429172E-03 0.250000E+04 -.146922E+03 0.806948E+04
  0.600000E+02 0.191229E+00 -.828271E-03 0.250000E+04 -.146922E+03 0.928954E+04
  0.750000E+02 0.239036E+00 -.139620E-02 0.250000E+04 -.146922E+03 0.108625E+05
  0.900000E+02 0.286844E+00 -.215745E-02 0.250000E+04 -.146922E+03 0.127883E+05
  0.105000E+03 0.334651E+00 -.313651E-02 0.250000E+04 -.146922E+03 0.150670E+05
  0.120000E+03 0.382458E+00 -.435786E-02 0.250000E+04 -.146922E+03 0.176985E+05
  0.135000E+03 0.430266E+00 -.584599E-02 0.250000E+04 -.146922E+03 0.206830E+05
  0.150000E+03 0.478073E+00 -.762539E-02 0.250000E+04 -.146922E+03 0.240203E+05
  0.165000E+03 0.525880E+00 -.972055E-02 0.250000E+04 -.146922E+03 0.277105E+05
  0.180000E+03 0.573687E+00 -.121559E-01 0.250000E+04 -.146922E+03 0.317535E+05
  0.195000E+03 0.621495E+00 -.149561E-01 0.250000E+04 -.146922E+03 0.361495E+05
  0.210000E+03 0.669302E+00 -.181454E-01 0.250000E+04 -.146922E+03 0.408983E+05
  0.225000E+03 0.717109E+00 -.217484E-01 0.250000E+04 -.146922E+03 0.460000E+05
  0.240000E+03 0.764916E+00 -.257897E-01 0.250000E+04 -.146922E+03 0.514546E+05
  0.255000E+03 0.812724E+00 -.302936E-01 0.250000E+04 -.146922E+03 0.572620E+05
  0.270000E+03 0.860531E+00 -.352846E-01 0.250000E+04 -.146922E+03 0.634223E+05
  0.285000E+03 0.908338E+00 -.407874E-01 0.250000E+04 -.146922E+03 0.699355E+05
  0.300000E+03 0.956146E+00 -.468262E-01 0.250000E+04 -.146922E+03 0.768016E+05
      2  0.500000E+03  0.100000E+01  0.000000E+00
  0.000000E+00 -.956146E+00 0.105359E+06 0.000000E+00 -.810241E-12 0.118531E+15
  0.250000E+02 -.956146E+00 0.354593E+09 0.000000E+00 -.250000E+03 0.118531E+15
  0.500000E+02 -.956146E+00 0.553234E+09 0.000000E+00 -.500000E+03 0.118531E+15
  0.750000E+02 -.956146E+00 0.615784E+09 0.000000E+00 -.750000E+03 0.118531E+15
  0.100000E+03 -.956146E+00 0.561998E+09 0.000000E+00 -.100000E+04 0.118531E+15
  0.125000E+03 -.956146E+00 0.411631E+09 0.000000E+00 -.125000E+04 0.118531E+15
  0.150000E+03 -.956146E+00 0.184438E+09 0.000000E+00 -.150000E+04 0.118531E+15
  0.175000E+03 -.956146E+00 -.998256E+08 0.000000E+00 -.175000E+04 0.118531E+15
  0.200000E+03 -.956146E+00 -.421405E+09 0.000000E+00 -.200000E+04 0.118531E+15
  0.225000E+03 -.956146E+00 -.760544E+09 0.000000E+00 -.225000E+04 0.118531E+15
  0.250000E+03 -.956146E+00 -.109749E+10 0.000000E+00 -.250000E+04 0.118531E+15
  0.275000E+03 -.956146E+00 -.141248E+10 0.000000E+00 -.275000E+04 0.118531E+15
  0.300000E+03 -.956146E+00 -.168578E+10 0.000000E+00 -.300000E+04 0.118531E+15
  0.325000E+03 -.956146E+00 -.189761E+10 0.000000E+00 -.325000E+04 0.118531E+15
  0.350000E+03 -.956146E+00 -.202822E+10 0.000000E+00 -.350000E+04 0.118531E+15
  0.375000E+03 -.956146E+00 -.205787E+10 0.000000E+00 -.375000E+04 0.118531E+15
  0.400000E+03 -.956146E+00 -.196678E+10 0.000000E+00 -.400000E+04 0.118531E+15
  0.425000E+03 -.956146E+00 -.173522E+10 0.000000E+00 -.425000E+04 0.118531E+15
  0.450000E+03 -.956146E+00 -.134343E+10 0.000000E+00 -.450000E+04 0.118531E+15
  0.475000E+03 -.956146E+00 -.771639E+09 0.000000E+00 -.475000E+04 0.118531E+15
  0.500000E+03 -.956146E+00 -.105359E+06 0.000000E+00 -.500000E+04 0.118531E+15
      3  0.300000E+03  0.000000E+00  -.100000E+01
  0.000000E+00 0.000000E+00 -.129038E+07 0.000000E+00 0.000000E+00 0.000000E+00
  0.150000E+02 0.000000E+00 -.156394E+10 0.000000E+00 0.000000E+00 0.161438E+03
  0.300000E+02 0.000000E+00 -.243946E+10 0.000000E+00 0.000000E+00 0.675750E+03
  0.450000E+02 0.000000E+00 -.271495E+10 0.000000E+00 0.000000E+00 0.154294E+04
  0.600000E+02 0.000000E+00 -.247753E+10 0.000000E+00 0.000000E+00 0.276300E+04
  0.750000E+02 0.000000E+00 -.181429E+10 0.000000E+00 0.000000E+00 0.433594E+04
  0.900000E+02 0.000000E+00 -.812342E+09 0.000000E+00 0.000000E+00 0.626175E+04
  0.105000E+03 0.000000E+00 0.441215E+09 0.000000E+00 0.000000E+00 0.854044E+04
  0.120000E+03 0.000000E+00 0.185928E+10 0.000000E+00 0.000000E+00 0.111720E+05
  0.135000E+03 0.000000E+00 0.335473E+10 0.000000E+00 0.000000E+00 0.141564E+05
  0.150000E+03 0.000000E+00 0.484049E+10 0.000000E+00 0.000000E+00 0.174938E+05
  0.165000E+03 0.000000E+00 0.622943E+10 0.000000E+00 0.000000E+00 0.211839E+05
  0.180000E+03 0.000000E+00 0.743446E+10 0.000000E+00 0.000000E+00 0.252270E+05
  0.195000E+03 0.000000E+00 0.836847E+10 0.000000E+00 0.000000E+00 0.296229E+05
  0.210000E+03 0.000000E+00 0.894436E+10 0.000000E+00 0.000000E+00 0.343718E+05
  0.225000E+03 0.000000E+00 0.907502E+10 0.000000E+00 0.000000E+00 0.394735E+05
  0.240000E+03 0.000000E+00 0.867335E+10 0.000000E+00 0.000000E+00 0.449280E+05
  0.255000E+03 0.000000E+00 0.765225E+10 0.000000E+00 0.000000E+00 0.507355E+05
  0.270000E+03 0.000000E+00 0.592461E+10 0.000000E+00 0.000000E+00 0.568958E+05
  0.285000E+03 0.000000E+00 0.340332E+10 0.000000E+00 0.000000E+00 0.634090E+05
  0.300000E+03 0.000000E+00 0.129038E+07 0.000000E+00 0.000000E+00 0.702750E+05
-------------- next part --------------
#!/usr/bin/env python

import glob # to look for all LCASE.* files
from string import * ## to process informations
from math import * ## we need almost everything from math....

class Telaio:
    def __init__(self):
        ## Loading all the load cases 
        ## Looking for all LCASE.xxx files
        self.filelist = glob.glob("LCASE*")
        self.load_cases = [None] * len(self.filelist) 
        
        for filename in self.filelist:
            print "Processing %s" % [filename]
            file = open(filename)
            case_n = int( split(filename,".")[1] )
            print "Case",case_n
            ## Reading the trailing 1
            file.readline()
            ## read nodes and rods numbers
            number_list = split( file.readline() )
            numbers = map(int, number_list)
            nodes_n = numbers[0]
            rods_n  = numbers[1]
            print numbers,"numbers type", map(type,numbers)
            ##print  "nodes: %i, rods: %i" % [numbers]
            for node_i in range(0,nodes_n):
                [node, x, y] = split( file.readline() )
                node = int(node);
                print "Trying to parsa '%s' '%s' '%s'" % (node,x,y)
                #print "Looking for strange characters:",map(ord,x)
                x = float(x)
                y = float(y) 
                print "Parsed to '%s' '%s' '%s'" % (node,x,y)
                ## Note: node_i is NOT used!
        ## End reading files.
        
if __name__ == '__main__':
    t = Telaio()




More information about the Python-list mailing list