Home > Software engineering >  Recover an array of integer saved as a string
Recover an array of integer saved as a string

Time:10-07

This is an example array i stored in a string property: [12, 15, 75, 60]

When i tried to retrieve it and access the index number, it included every character that denotes the array, for example if i ask for array[0], it gives me '[', instead of '12', array[3] gives me ',' array[6] gives me '5' and so on.

How can blender Python read the string like it does with array?

I tried enclosing things in int(), it throws a message "string indices must be integers" or "invalid literal for int() with base 10

Thank for your advance response! I didn't include any code snippet as this problem is simple enough to understand, thanks, more power

CodePudding user response:

If you want a string array let's convert it this way.

a = '[12, 15, 75, 60]'
b = a[1:len(a)-1].split(",")

print(b[0])

If you want a int array let's convert it this way.

a = '[12, 15, 75, 60]'
b = list(map(int, a[1:len(a)-1].split(",")))

print(b[0])
  • Related