python - Invalid literal for float -
i having hardest time figuring out why scientific notation string passing float() function not work:
time = [] watbalr = [] area = np.empty([1,len(time)]) volume = np.empty([1,len(time)]) searchfile = open("c:\gradschool\research\caselton\hydrus2d3d\h3d2_profile1v3\balance.out", "r") line in searchfile: if "time" in line: time.append(re.sub("[^0-9.]", "", line)) elif "watbalr" in line: watbalr.append(re.sub("[^0-9.]", "", line)) elif "area" in line: area0 = re.sub("[^0-9.\+]", "", line) print repr(area0[:-10]) area0 = float(area0[:-10].replace("'", "")) area = numpy.append(area, area0) elif "volume" in line: volume0 = re.sub("[^0-9.\+]", "", line) volume0 = float(volume0[:-10].replace("'", "")) volume = numpy.append(volume, volume0) searchfile.close() --------------------------------------------------------------------------- valueerror traceback (most recent call last) <ipython-input-80-341de12bbc94> in <module>() 13 area0 = re.sub("[^0-9.\+]", "", line) 14 print repr(area0[:-10]) ---> 15 area0 = float(area0[:-10].replace("'", "")) 16 area = numpy.append(area, area0) 17 elif "volume" in line: valueerror: invalid literal float(): 0.55077+03
however, following works:
float(0.55077+03) 3.55077
if put quotes around argument, same invalid literal comes up, tried remove quotes string , cannot seem so.
0.55077+03
0.55077
added 03
. need e
scientific notation:
0.55077e+03
Comments
Post a Comment