Append() method in Python Idle works but not in Python Script in Dynamo

Hello.
I wrote some python code, works well but at the end of it append() method dosent work. I didn’t know why so I tried same code inside python IDLE and its works fine. Any Ideas? Thanks in advance. Revit 2022 Python 3

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

import copy
import random
from copy import deepcopy

a = IN[0]

def find(a):

    x1 = deepcopy(a)
    y1 = deepcopy(a)
    z1 = deepcopy(a)
    x2 = deepcopy(a)
    y2 = deepcopy(a)

    for sub in x1:
        sub[0] = sub[0] + 1

    for sub in x2:
        sub[0] = sub[0] - 1

    for sub in y1:
        sub[1] = sub[1] + 1
    
    for sub in y2:
        sub[1] = sub[1] - 1
   
    for sub in z1:
        sub[2] = sub[2] +1

    final =[a,x1,x2,y1,y2,z1]
    final2 = sum(final, [])

    [list(i) for i in set(map(tuple, final2))]

    my_list = ([x for x in final2 if x not in a])
    selected = random.choice(my_list)
    return selected
   
OUT = a.append(find(a))

I suppose you are trying to append an item to a list.

Maybe a isn´t recognized as a list. Try to replace

a = IN[0]

with:

a = [IN[0]]

2 Likes

Hey thanks for reply. It was given as a list, screen below. Everything works in dynamo python script besides append.

Do it like that:

z = []

z.append(find(a))
a = z
OUT = a
1 Like

Append works that way but it not was a point of the script. I want to add item generated by funcion “find” to the given list. But it worked that way : (screen below) i really dont know why. :slight_smile: Thanks for helping.
12121

First of all I highly recommend not using the same variable names in defined functions as your main block of code. It makes things confusing. On top of that you absolutely should not use an existing variable name when you call your function. I believe that is what @Deniz_Maral was trying to explain - use different variable names.

2 Likes

Exactly!

1 Like