Storing a python list as a scene variable What is the best practice way to store a python list defined in an addon as a scene variable in Blender?  

Using

global mylist


doesn't work because the variable is not a Blender-specific type and therefore not saved after a button click operation completes.  I would like the list to exist in the Blender environment so that I can access it from future function calls.

My current solution is to use Blender Collection Properties, with my own wrapper functions, but this seems kind of excessive:

bpy.types.Object.CP_list = bpy.props.CollectionProperty(type=bpy.types.PropertyGroup)

def CollectionProperty2list(CP, numerical = False):
    new_list = []
    if (numerical):
        for elt in CP:
            new_list.append(float(elt.name))
    else:
        for elt in CP:
            new_list.append(elt.name)
    return (new_list)

def list2CollectionProperty(mylist, CP):
    CP.clear()
    for elt in mylist:
        CP.add().name = str(elt)  # stores string for numerical or string input
    return()


storing:

list2CollectionProperty(py_list, obj.CP_list)


retreiving:

py_list = CollectionProperty2list(obj.CP_list)
Storing a list as an ID property

# assign a list
&gt;&gt;&gt; C.scene["mylist"] = [1, 1, 1, 1, 1, 1]
&gt;&gt;&gt; C.scene['mylist']
&lt;bpy id property array [6]&gt;
# save file, reopen
&gt;&gt;&gt; C.scene['mylist'].to_list()
[1, 1, 1, 1, 1, 1]


This will work for lists where all items are of the same type: strings, ints,  floats or booleans (booleans as ints).

Could try using your methods above as getters / setters  ... but I don't think get is available for bpy.props.CollectionProperty.