Forgive me for asking a beginner to Python, but how to correctly get data from properties?
After the “=” , it is necessary to insert from the property own[“pos”], three digits separated by commas - 1, 1, 3
Thank you for attention.
own.localPosition = own["pos"].split(',')
should do it.
AttributeError: one or more of the items in the sequence was not a float
I found a solution:
pos = ([float(i) for i in own.get("pos", "1, 1, 1").split(", ")]) own.localPosition = pos
I thank Nicholas_A for the answer.
own.localPosition = [float(i) for i in own["pos"].split(',')]
This is an XY problem. We can solve the question you ask, but we know nothing of what you are trying to do.
Or simply try:
from ast import literal eval # own["prop"] == "1.0, 2.0, 3.0" # prop_processed = list( literal_eval( own["prop"] ) ) # prop_processed == [ 1.0, 2.0, 3.0 ] #
The ast.literal_eval can save your life when using strings-to-literal processing.
I tried to get the coordinates from the “pos” property for own.localPosition - everything is obvious.
The console gave an error, and I found a solution to this question.
I thank you for a more competent solution to this question - your code is more correct and easier.
solved in the answer #5
OK man, you’re a mega brain! I still have now found the use of your script, it’s called - I have seen :yes:. Just how add to this -" True"?
thanks for help.