Sunday, 15 May 2011

file - Invalid Literal for float():['1' error in python -



file - Invalid Literal for float():['1' error in python -

code

in range(num): # j in range(4): lines = outf1.readline() brr[i]= list(map(float, lines.split()))

this input dataset

['1', '1.52101', '13.64', '4.49', '1.1', '71.78', '0.06', '8.75', '0', '0', '1'] ['2', '1.51761', '13.89', '3.6', '1.36', '72.73', '0.48', '7.83', '0', '0', '1'] ['3', '1.51618', '13.53', '3.55', '1.54', '72.99', '0.39', '7.78', '0', '0', '1']

i working som algorithm. have file containing float values having 4 or 5 decimal values. need retrieve these values , store array.

ast.literal_eval() should trick:

in [12]: line = "['1', '1.52101', '13.64', '4.49', '1.1', '71.78', '0.06', '8.75', '0', '0', '1']" in [13]: map(float, ast.literal_eval(line)) out[13]: [1.0, 1.52101, 13.64, 4.49, 1.1, 71.78, 0.06, 8.75, 0.0, 0.0, 1.0]

python file som uci

No comments:

Post a Comment