'SyntaxError: cannot assign to list comprehension?

My code:

def function():
    resources, bufferViews, accessors = parse_gltf(fname)

    display(resources)

    display(bufferViews)

    display(accessors)

    ds = []
    idx_vertex = -1
    idx_normals = -1
    idx_textures = -1
    idx_meshes = -1

    for j in range(len(accessors)):
        accessor = accessors[j]

        if accessor.min:
            idx_vertex = j

        d = parse_accessor(accessor, resources, bufferViews)
        ds.append(d)

        if d.shape[1] == 3:
            idx_normals = j

        if d.shape[1] == 2:
            idx_textures = j

        if d.shape[1] == 1:
            idx_meshes = j

    return idx_vertex, idx_normals, idx_textures, idx_meshes, [e.shape for e in ds]

if __name__ == "main":
    idx_vertex, idx_normals, idx_textures, idx_meshes, [e.shape for e in ds] = function()
    display(ds[idx_vertex])

Basically, I want to be able to return the values idx_vertex, idx_normals, idx_textures, idx_meshes and be able to assign them in the ds array. However, I get "SyntaxError: cannot assign to list comprehension" when I try to achieve this. Does anyone know what I am doing wrong?



Solution 1:[1]

You need to store the list comprehension in a variable in your start routine:

if __name__ == "__main__":
    idx_vertex, idx_normals, idx_textures, idx_meshes, shape_list = function()
    display(ds[idx_vertex])

Your function function is already returning the list [e.shape for e in ds]

LE: Edited according to MattDMO's comment

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1