I am trying to turn my unicode into a float but I dont know why i cant convert it. I have already tried to use .strip() but thats isnt working so I'm not sure what else I can do.
It makes it faster/easier for others to test your code and provide solutions. You can edit your post by clicking the edit icon (pencil icon) on the bottom right of your post.
Moving on from that, it appears that some of your values are returning blank strings? Add something to catch when the values are blank strings and either supply a default value or null.
its weird because if i put print tolerance_value , there is a value 0.0035. and that is a unicode because when I do print type(tolerance_value) is says unicode
You really shouldn't be using the tolerance_value variable as two different data types. Use a different variable name for either float or string, and see if that shows any other buggy assumptions.
If you put a print on line 25, that's the result you get?
If i'm not mistaken, if you look at my badly edited screenshot, it seems that your fourth and fifth print statements are printing empty lines because the value is empty and the next line is trying to convert nothing into a Float
Try this, for performances, but mostly for sanity:
t_stamp = system.date.now()
path = "[default]T2_Renishaw/RESDATA_Table_Results"
data = system.tag.readBlocking([path])[0].value
part_number = data[0][7]
for row in data:
feature_value = row[0]
type_value = row[1]
actual_value = row[2]
nominal_value = row[3]
tolerance_value = float(row[4])
if feature_value != " " and actual_value != " " and type_value != " ":
params2 = {"t_stamp":t_stamp,
"part_number":part_number,
"feature_name":feature_value,
"actual":actual_value,
"feature_type":type_value,
"tolerance":tolerance_value}
system.db.runNamedQuery("Renishaw Tops 2 Insert Feature and Actual Values", params2)
This is strictly equivalent to your inital code, so it won't fix the issue, but it's a saner base to work on.
Is the tag you're reading from a database tag ?
If that's the case, any reason you're not just pulling data from the db directly instead of going through an intermediary tag ?