Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Recover an array of integer saved as a string

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading