How can I store and retrieve a custom list in a blend file? I am trying to create a script that will allow me to generate a list and store it in the blend file. The list starts out blank and then strings get added to the list, resulting in:
[&quot;test1&quot;,&quot;test2&quot;,&quot;test3&quot;]
I create a PropertyGroup Class for the enum, define a new scene property as a CollectionProperty type with access to that enum Class, before appending a new item into the enum:
import bpy

class item_set(bpy.types.PropertyGroup):
    myItems = []
    enums = bpy.props.EnumProperty(name=&quot;My Items&quot;, items=myItems)
bpy.utils.register_class(item_set)

bpy.types.Scene.myItemSet = bpy.props.CollectionProperty(type=item_set)    

newItem = bpy.context.scene.myItemSet.add()
newItem.myItems.append(&quot;test&quot;)



I need to be able to add items to the list, save the blend file, re-open the file, run the script again and retrieve the list from the scene.
However, the documentation states:

One thing to keep in mind is that after saving and reloading your blend-file, your new property will have disappeared...



...To make the values you assigned in a previous session available again, you need to redefine the property. So after reopening the blend-file you need to rerun:
bpy.types.Object.myProperty = bpy.props.StringProperty()


I can do the appending into and retrieval of the property values absolutely fine upon an initial run, but as the documentation states, the property is unavailable when trying to view it's contents on a reload of the file (after having run the script, saved and re-opened the file), but I am unsure how to redefine it without clearing all it's values.
If I redefined the scene property, it would presumably also need the enum Class to be available, which would currently set myItems back to [] (empty).
Do I need to change the way I am initially setting the items in the class or am I on entirely the wrong track with all of this? All I need to do is store a list in the blend file, so if there is a better way please let me know.
Thanks.
(I would hope, eventually, to be able to store sub lists [[&quot;a&quot;,&quot;b&quot;],[&quot;c&quot;,&quot;d&quot;],[&quot;e&quot;,&quot;f&quot;]], I'm just trying to get normal lists to work first.)
Part of the confusion with my question came from the fact I presumed that defining an EnumProperty was the correct, and only, way to store a list.

What I didn't quite understand was that the CollectionProperty itself would act like a list. I can have much the same code as I had before, minus the enum:

class customPropertiesGroup(bpy.types.PropertyGroup):
    customString = bpy.props.StringProperty()
bpy.utils.register_class(customPropertiesGroup)

bpy.types.Scene.customLists = bpy.props.CollectionProperty(type=customPropertiesGroup)


And every time I want to add a new item I do:

newCustomItem = bpy.context.scene.customLists.add()
newCustomItem.customString = "test1"
newCustomItem = bpy.context.scene.customLists.add()
newCustomItem.customString = "test2"
etc..


I can then access each custom item with:

bpy.context.scene.customLists[0].customString
bpy.context.scene.customLists[1].customString


If I want nested lists I can simply have the PropertyGroup Class' property as another CollectionProperty:

class subcustomPropertiesGroup(bpy.types.PropertyGroup):
    customString = bpy.props.StringProperty()
bpy.utils.register_class(subcustomPropertiesGroup)

class customPropertiesGroup(bpy.types.PropertyGroup):
    subLists = bpy.props.CollectionProperty(type=subcustomPropertiesGroup)    
bpy.utils.register_class(customPropertiesGroup)

bpy.types.Scene.customLists = bpy.props.CollectionProperty(type=customPropertiesGroup)

newcustomList = bpy.context.scene.customLists.add()
newcustomList.name= "List 1"
newSubList = bpy.context.scene.customLists["List 1"].subLists.add()
newSubList.name = "Sub List 1"
newSubList.customString = "String 1"


This allows me to have an arrangement where I can access lists and sublists like so:

bpy.context.scene.customLists['List 1'].subList['Sub List 1'].customString


I can add or remove items (with customLists.remove(index)) and print them out like I would a normal python list:

for customList in bpy.context.scene.customLists:

    print("List: "+customList.name)

    for subList in customList.subLists:

        print("Sub List: "+subList.name)
        print("Custom property: "+subList.customString)


And because I am not clearing the list each time I define it (as I was in the question) the properties become available again after reloading the file and re-running the code.