Ask coding questions

← Back to all posts
Help required.
FriendlyGooseMan

Hey so I have an issue with my saving system. Not really the saving system but the loading system it says that it cannot convert my string-list (as in "[0,0,0,0]") Back to a normal list. and it cant be decompressed For some reason. I have been working on this and looking up solutions very hard but I am quite lost in how I should do this.

What I want it to do is convert what is in the save file back to the original list it was

To use my project run it and then type quit and push enter which will attempt to save the project (and then load it for testing) and you will get the error I am having.

Thanks in advance - FriendlyGooseMan

Answered by InvisibleOne [earned 5 cycles]
View Answer
Voters
FriendlyGooseMan
Comments
hotnewtop
InvisibleOne

You can convert a string list to a list like this:

Output:

Just be careful using eval() because it will execute any command given. And if someone managed to put something like import os;os.system('rm -rf') into it, it would delete your files.
If you are controlling the input however it should be fine.
Other then this there are a few other techniques you can try, such as using ast or json.

MrVoo

Since a string is always made into a list the same way no matter what, you can't do it like that :( You have to find a way to change it back yourself

FriendlyGooseMan

@MrVoo aww. can you point me in the right direction on how I would do this

MrVoo

@FriendlyGooseMan InvisibleOne's strategy looks like it could work :P