python - Could not convert string to float: ...Sometimes -


i'm having strange things happen when converting strings floats in loop.

so when use following code writes:

[1468436874000, 0.00254071495719], [1468528803000, 0.00341349353996], [1468688596000, 0.000853373384991], [1468871365000, 0.00256012015497], 

it stops short, there should 30 lines more , wrong calculations.

the function is:

def main():  minprice = pricelist('min') maxprice = pricelist('max') avgprice = pricelist('avg') avgsqft = sqftlist() datelist = getdates() index = fileparser()  open('/home/andrew/desktop/index3.htm', 'w') file:      file.writelines(data[:index[0]])      date, minprice, maxprice in zip(datelist, minprice, maxprice):         file.writelines('[%s, %s, %s],\n' % (date, minprice, maxprice))      file.writelines(data[index[1]:index[2]])      date, avgprice in zip(datelist, avgprice):         file.writelines('[%s, %s],\n' % (date, avgprice))      file.writelines(data[index[3]:index[4]])      date, avgprice, avgsqft in zip(datelist, avgprice, avgsqft):         file.writelines('[%s, %s],\n' % (date, ((float(avgprice))/(float(avgsqft)))))      file.writelines(data[index[5]:])     file.close() 

the error is:

file.writelines('[%s, %s],\n' % (date, ((float(avgprice))/(float(avgsqft))))) valueerror: not convert string float: . 

oddly, when comment out other loops before it, result is:

[1468436874000, 2.82644376127], [1468528803000, 2.86702735915], [1468688596000, 2.8546107764], [1468871365000, 2.8546107764], [1468871996000, 2.8546107764], [1468919656000, 2.85383420662], [1469004050000, 2.85189704903], [1469116491000, 2.87361540168], [1469189815000, 2.86059636119], [1469276601000, 2.83694745621], [1469367041000, 2.83903252711], [1469547497000, 2.83848688853], [1469649630000, 2.83803033196], [1469736031000, 2.82327110329], [1469790030000, 2.82650020338], [1469876430000, 2.96552660866], [1470022624000, 2.93407180385], 

moreover, when use enumerate instead of zip (and make appropriate changes), works. i've examined both lists @ fifth item unusual because that's it's getting hung up, there nothing odd there in either list. since work fine enumerate i'll now. i'm new python/programming in general , want understand causing this.

update should have included first time.

#     file.writelines(data[:index[0]+1]) #     date, minprice, maxprice in zip(datelist, minprice, maxprice): #         file.writelines('[%s, %s, %s],\n' % (date, minprice, maxprice)) #     file.writelines(data[index[1]:index[2]+1]) #     date, avgprice in zip(datelist, avgprice): #         file.writelines('[%s, %s],\n' % (date, avgprice)) #     file.writelines(data[index[3]:index[4]+1]) #     time.sleep(1) date, avgprice, avgsqft in zip(datelist, avgprice, avgsqft):     # file.writelines(     print'[%s, %s],\n' % (date, ((float(avgprice))/(float(avgsqft))))     # file.writelines(data[index[5]:])     # file.close() 

prints... (correctly)

[1468436874000, 2.82644376127],  [1468528803000, 2.86702735915],  [1468688596000, 2.8546107764],  [1468871365000, 2.8546107764],  [1468871996000, 2.8546107764],  [1468919656000, 2.85383420662],  etc... 

debug printing values of avgprice , avgsqft in code. getting string it's value can not converted float


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -