String to vector

Hi,

Im trying to convert a string that has the position of an object and looks like this “vector((1.0,1.0,1.0))” into an actual vector(or float) position?

Or how can i get the vector position of the object to look like this when i use the print command ? [1.0,1.0,1.0]

How could this be done in blender 2.55?

Thanks in advance

this is not really a blender problem but more a python problem:
you can evaluate a string using the eval() function, however evaluating “vector((1.0,1.0,1.0))” would probably rease an error because this is not correct coding.
this should work:

string = "[1.0,1.0,1.0]"
vector = eval(string)

if you are for some reason stuck with the string “vector((1.0,1.0,1.0))”, you should modify the string first:

string = "vector((1.0,1.0,1.0))"
newstring = "[" + string[8:len(string)-2] + "]"
vector = eval(newstring)

i didn`t test the code so there could be some bug in it but the principle should work
hope that helps

To convert the vector to a list you can do:

print(list(vector))
# or
print(vector[:])

Thanks for the solutions…both of them really helped :slight_smile: